1 // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
3 * Copyright (c) 2018 Microsemi Corporation
7 #include <linux/bitops.h>
8 #include <linux/delay.h>
10 #include "mscc_xfer.h"
12 #define QS_XTR_FLUSH_FLUSH GENMASK(1, 0)
13 #define QS_INJ_CTRL_GAP_SIZE(x) ((x) << 21)
14 #define QS_INJ_CTRL_EOF BIT(19)
15 #define QS_INJ_CTRL_SOF BIT(18)
16 #define QS_INJ_CTRL_VLD_BYTES(x) ((x) << 16)
18 #define XTR_EOF_0 ntohl(0x80000000u)
19 #define XTR_EOF_1 ntohl(0x80000001u)
20 #define XTR_EOF_2 ntohl(0x80000002u)
21 #define XTR_EOF_3 ntohl(0x80000003u)
22 #define XTR_PRUNED ntohl(0x80000004u)
23 #define XTR_ABORT ntohl(0x80000005u)
24 #define XTR_ESCAPE ntohl(0x80000006u)
25 #define XTR_NOT_READY ntohl(0x80000007u)
27 #define BUF_CELL_SZ 60
28 #define XTR_VALID_BYTES(x) (4 - ((x) & 3))
30 int mscc_send(void __iomem *regs, const unsigned long *mscc_qs_offset,
31 u32 *ifh, size_t ifh_len, u32 *buff, size_t buff_len)
33 int i, count = (buff_len + 3) / 4, last = buff_len % 4;
35 writel(QS_INJ_CTRL_GAP_SIZE(1) | QS_INJ_CTRL_SOF,
36 regs + mscc_qs_offset[MSCC_QS_INJ_CTRL]);
38 for (i = 0; i < ifh_len; i++)
39 writel(ifh[i], regs + mscc_qs_offset[MSCC_QS_INJ_WR]);
41 for (i = 0; i < count; i++)
42 writel(buff[i], regs + mscc_qs_offset[MSCC_QS_INJ_WR]);
45 while (i < (BUF_CELL_SZ / 4)) {
46 writel(0, regs + mscc_qs_offset[MSCC_QS_INJ_WR]);
50 /* Indicate EOF and valid bytes in last word */
51 writel(QS_INJ_CTRL_GAP_SIZE(1) |
52 QS_INJ_CTRL_VLD_BYTES(buff_len < BUF_CELL_SZ ? 0 : last) |
53 QS_INJ_CTRL_EOF, regs + mscc_qs_offset[MSCC_QS_INJ_CTRL]);
56 writel(0, regs + mscc_qs_offset[MSCC_QS_INJ_WR]);
61 int mscc_recv(void __iomem *regs, const unsigned long *mscc_qs_offset,
62 u32 *rxbuf, size_t ifh_len, bool byte_swap)
64 u8 grp = 0; /* Recv everything on CPU group 0 */
66 bool eof_flag = false, pruned_flag = false, abort_flag = false;
68 if (!(readl(regs + mscc_qs_offset[MSCC_QS_XTR_DATA_PRESENT]) &
73 for (i = 0; i < ifh_len; i++)
74 readl(regs + mscc_qs_offset[MSCC_QS_XTR_RD]);
77 u32 val = readl(regs + mscc_qs_offset[MSCC_QS_XTR_RD]);
85 debug("%d NOT_READY...?\n", byte_cnt);
88 *rxbuf = readl(regs + mscc_qs_offset[MSCC_QS_XTR_RD]);
97 byte_cnt += XTR_VALID_BYTES(val);
98 *rxbuf = readl(regs + mscc_qs_offset[MSCC_QS_XTR_RD]);
103 /* But get the last 4 bytes as well */
109 *rxbuf = readl(regs + mscc_qs_offset[MSCC_QS_XTR_RD]);
121 if (abort_flag || pruned_flag || !eof_flag) {
122 debug("Discarded frame: abort:%d pruned:%d eof:%d\n",
123 abort_flag, pruned_flag, eof_flag);
130 void mscc_flush(void __iomem *regs, const unsigned long *mscc_qs_offset)
132 /* All Queues flush */
133 setbits_le32(regs + mscc_qs_offset[MSCC_QS_XTR_FLUSH],
139 /* All Queues normal */
140 clrbits_le32(regs + mscc_qs_offset[MSCC_QS_XTR_FLUSH],