xref: /openbmc/linux/drivers/net/ethernet/broadcom/asp2/bcmasp.h (revision 5804c19b80bf625c6a9925317f845e497434d6d3)
1490cb412SJustin Chen /* SPDX-License-Identifier: GPL-2.0 */
2490cb412SJustin Chen #ifndef __BCMASP_H
3490cb412SJustin Chen #define __BCMASP_H
4490cb412SJustin Chen 
5490cb412SJustin Chen #include <linux/netdevice.h>
6490cb412SJustin Chen #include <linux/phy.h>
7490cb412SJustin Chen #include <linux/io-64-nonatomic-hi-lo.h>
8490cb412SJustin Chen #include <uapi/linux/ethtool.h>
9490cb412SJustin Chen 
10490cb412SJustin Chen #define ASP_INTR2_OFFSET			0x1000
11490cb412SJustin Chen #define  ASP_INTR2_STATUS			0x0
12490cb412SJustin Chen #define  ASP_INTR2_SET				0x4
13490cb412SJustin Chen #define  ASP_INTR2_CLEAR			0x8
14490cb412SJustin Chen #define  ASP_INTR2_MASK_STATUS			0xc
15490cb412SJustin Chen #define  ASP_INTR2_MASK_SET			0x10
16490cb412SJustin Chen #define  ASP_INTR2_MASK_CLEAR			0x14
17490cb412SJustin Chen 
18490cb412SJustin Chen #define ASP_INTR2_RX_ECH(intr)			BIT(intr)
19490cb412SJustin Chen #define ASP_INTR2_TX_DESC(intr)			BIT((intr) + 14)
20490cb412SJustin Chen #define ASP_INTR2_UMC0_WAKE			BIT(22)
21490cb412SJustin Chen #define ASP_INTR2_UMC1_WAKE			BIT(28)
22490cb412SJustin Chen 
23490cb412SJustin Chen #define ASP_WAKEUP_INTR2_OFFSET			0x1200
24490cb412SJustin Chen #define  ASP_WAKEUP_INTR2_STATUS		0x0
25490cb412SJustin Chen #define  ASP_WAKEUP_INTR2_SET			0x4
26490cb412SJustin Chen #define  ASP_WAKEUP_INTR2_CLEAR			0x8
27490cb412SJustin Chen #define  ASP_WAKEUP_INTR2_MASK_STATUS		0xc
28490cb412SJustin Chen #define  ASP_WAKEUP_INTR2_MASK_SET		0x10
29490cb412SJustin Chen #define  ASP_WAKEUP_INTR2_MASK_CLEAR		0x14
30490cb412SJustin Chen #define ASP_WAKEUP_INTR2_MPD_0			BIT(0)
31490cb412SJustin Chen #define ASP_WAKEUP_INTR2_MPD_1			BIT(1)
32490cb412SJustin Chen #define ASP_WAKEUP_INTR2_FILT_0			BIT(2)
33490cb412SJustin Chen #define ASP_WAKEUP_INTR2_FILT_1			BIT(3)
34490cb412SJustin Chen #define ASP_WAKEUP_INTR2_FW			BIT(4)
35490cb412SJustin Chen 
36490cb412SJustin Chen #define ASP_TX_ANALYTICS_OFFSET			0x4c000
37490cb412SJustin Chen #define  ASP_TX_ANALYTICS_CTRL			0x0
38490cb412SJustin Chen 
39490cb412SJustin Chen #define ASP_RX_ANALYTICS_OFFSET			0x98000
40490cb412SJustin Chen #define  ASP_RX_ANALYTICS_CTRL			0x0
41490cb412SJustin Chen 
42490cb412SJustin Chen #define ASP_RX_CTRL_OFFSET			0x9f000
43490cb412SJustin Chen #define ASP_RX_CTRL_UMAC_0_FRAME_COUNT		0x8
44490cb412SJustin Chen #define ASP_RX_CTRL_UMAC_1_FRAME_COUNT		0xc
45490cb412SJustin Chen #define ASP_RX_CTRL_FB_0_FRAME_COUNT		0x14
46490cb412SJustin Chen #define ASP_RX_CTRL_FB_1_FRAME_COUNT		0x18
47490cb412SJustin Chen #define ASP_RX_CTRL_FB_8_FRAME_COUNT		0x1c
48490cb412SJustin Chen /* asp2.1 diverges offsets here */
49490cb412SJustin Chen /* ASP2.0 */
50490cb412SJustin Chen #define ASP_RX_CTRL_FB_OUT_FRAME_COUNT		0x20
51490cb412SJustin Chen #define ASP_RX_CTRL_FB_FILT_OUT_FRAME_COUNT	0x24
52490cb412SJustin Chen #define ASP_RX_CTRL_FLUSH			0x28
53490cb412SJustin Chen #define  ASP_CTRL_UMAC0_FLUSH_MASK		(BIT(0) | BIT(12))
54490cb412SJustin Chen #define  ASP_CTRL_UMAC1_FLUSH_MASK		(BIT(1) | BIT(13))
55490cb412SJustin Chen #define  ASP_CTRL_SPB_FLUSH_MASK		(BIT(8) | BIT(20))
56490cb412SJustin Chen #define ASP_RX_CTRL_FB_RX_FIFO_DEPTH		0x30
57490cb412SJustin Chen /* ASP2.1 */
58490cb412SJustin Chen #define ASP_RX_CTRL_FB_9_FRAME_COUNT_2_1	0x20
59490cb412SJustin Chen #define ASP_RX_CTRL_FB_10_FRAME_COUNT_2_1	0x24
60490cb412SJustin Chen #define ASP_RX_CTRL_FB_OUT_FRAME_COUNT_2_1	0x28
61490cb412SJustin Chen #define ASP_RX_CTRL_FB_FILT_OUT_FRAME_COUNT_2_1	0x2c
62490cb412SJustin Chen #define ASP_RX_CTRL_FLUSH_2_1			0x30
63490cb412SJustin Chen #define ASP_RX_CTRL_FB_RX_FIFO_DEPTH_2_1	0x38
64490cb412SJustin Chen 
65490cb412SJustin Chen #define ASP_RX_FILTER_OFFSET			0x80000
66490cb412SJustin Chen #define  ASP_RX_FILTER_BLK_CTRL			0x0
67490cb412SJustin Chen #define   ASP_RX_FILTER_OPUT_EN			BIT(0)
68490cb412SJustin Chen #define   ASP_RX_FILTER_MDA_EN			BIT(1)
69490cb412SJustin Chen #define   ASP_RX_FILTER_LNR_MD			BIT(2)
70490cb412SJustin Chen #define   ASP_RX_FILTER_GEN_WK_EN		BIT(3)
71490cb412SJustin Chen #define   ASP_RX_FILTER_GEN_WK_CLR		BIT(4)
72490cb412SJustin Chen #define   ASP_RX_FILTER_NT_FLT_EN		BIT(5)
73490cb412SJustin Chen #define  ASP_RX_FILTER_MDA_CFG(sel)		(((sel) * 0x14) + 0x100)
74490cb412SJustin Chen #define   ASP_RX_FILTER_MDA_CFG_EN_SHIFT	8
75490cb412SJustin Chen #define   ASP_RX_FILTER_MDA_CFG_UMC_SEL(sel)	((sel) > 1 ? BIT(17) : \
76490cb412SJustin Chen 						 BIT((sel) + 9))
77490cb412SJustin Chen #define  ASP_RX_FILTER_MDA_PAT_H(sel)		(((sel) * 0x14) + 0x104)
78490cb412SJustin Chen #define  ASP_RX_FILTER_MDA_PAT_L(sel)		(((sel) * 0x14) + 0x108)
79490cb412SJustin Chen #define  ASP_RX_FILTER_MDA_MSK_H(sel)		(((sel) * 0x14) + 0x10c)
80490cb412SJustin Chen #define  ASP_RX_FILTER_MDA_MSK_L(sel)		(((sel) * 0x14) + 0x110)
81490cb412SJustin Chen #define  ASP_RX_FILTER_MDA_CFG(sel)		(((sel) * 0x14) + 0x100)
82490cb412SJustin Chen #define  ASP_RX_FILTER_MDA_PAT_H(sel)		(((sel) * 0x14) + 0x104)
83490cb412SJustin Chen #define  ASP_RX_FILTER_MDA_PAT_L(sel)		(((sel) * 0x14) + 0x108)
84490cb412SJustin Chen #define  ASP_RX_FILTER_MDA_MSK_H(sel)		(((sel) * 0x14) + 0x10c)
85490cb412SJustin Chen #define  ASP_RX_FILTER_MDA_MSK_L(sel)		(((sel) * 0x14) + 0x110)
86490cb412SJustin Chen #define  ASP_RX_FILTER_NET_CFG(sel)		(((sel) * 0xa04) + 0x400)
87490cb412SJustin Chen #define   ASP_RX_FILTER_NET_CFG_CH(sel)		((sel) << 0)
88490cb412SJustin Chen #define   ASP_RX_FILTER_NET_CFG_EN		BIT(9)
89490cb412SJustin Chen #define   ASP_RX_FILTER_NET_CFG_L2_EN		BIT(10)
90490cb412SJustin Chen #define   ASP_RX_FILTER_NET_CFG_L3_EN		BIT(11)
91490cb412SJustin Chen #define   ASP_RX_FILTER_NET_CFG_L4_EN		BIT(12)
92490cb412SJustin Chen #define   ASP_RX_FILTER_NET_CFG_L3_FRM(sel)	((sel) << 13)
93490cb412SJustin Chen #define   ASP_RX_FILTER_NET_CFG_L4_FRM(sel)	((sel) << 15)
94490cb412SJustin Chen #define   ASP_RX_FILTER_NET_CFG_UMC(sel)	BIT((sel) + 19)
95490cb412SJustin Chen #define   ASP_RX_FILTER_NET_CFG_DMA_EN		BIT(27)
96490cb412SJustin Chen 
97490cb412SJustin Chen #define  ASP_RX_FILTER_NET_OFFSET_MAX		32
98490cb412SJustin Chen #define  ASP_RX_FILTER_NET_PAT(sel, block, off) \
99490cb412SJustin Chen 		(((sel) * 0xa04) + ((block) * 0x200) + (off) + 0x600)
100490cb412SJustin Chen #define  ASP_RX_FILTER_NET_MASK(sel, block, off) \
101490cb412SJustin Chen 		(((sel) * 0xa04) + ((block) * 0x200) + (off) + 0x700)
102490cb412SJustin Chen 
103490cb412SJustin Chen #define  ASP_RX_FILTER_NET_OFFSET(sel)		(((sel) * 0xa04) + 0xe00)
104490cb412SJustin Chen #define   ASP_RX_FILTER_NET_OFFSET_L2(val)	((val) << 0)
105490cb412SJustin Chen #define   ASP_RX_FILTER_NET_OFFSET_L3_0(val)	((val) << 8)
106490cb412SJustin Chen #define   ASP_RX_FILTER_NET_OFFSET_L3_1(val)	((val) << 16)
107490cb412SJustin Chen #define   ASP_RX_FILTER_NET_OFFSET_L4(val)	((val) << 24)
108490cb412SJustin Chen 
109c5d511c4SJustin Chen enum asp_rx_net_filter_block {
110c5d511c4SJustin Chen 	ASP_RX_FILTER_NET_L2 = 0,
111c5d511c4SJustin Chen 	ASP_RX_FILTER_NET_L3_0,
112c5d511c4SJustin Chen 	ASP_RX_FILTER_NET_L3_1,
113c5d511c4SJustin Chen 	ASP_RX_FILTER_NET_L4,
114c5d511c4SJustin Chen 	ASP_RX_FILTER_NET_BLOCK_MAX
115c5d511c4SJustin Chen };
116c5d511c4SJustin Chen 
117490cb412SJustin Chen #define ASP_EDPKT_OFFSET			0x9c000
118490cb412SJustin Chen #define  ASP_EDPKT_ENABLE			0x4
119490cb412SJustin Chen #define   ASP_EDPKT_ENABLE_EN			BIT(0)
120490cb412SJustin Chen #define  ASP_EDPKT_HDR_CFG			0xc
121490cb412SJustin Chen #define   ASP_EDPKT_HDR_SZ_SHIFT		2
122490cb412SJustin Chen #define   ASP_EDPKT_HDR_SZ_32			0
123490cb412SJustin Chen #define   ASP_EDPKT_HDR_SZ_64			1
124490cb412SJustin Chen #define   ASP_EDPKT_HDR_SZ_96			2
125490cb412SJustin Chen #define   ASP_EDPKT_HDR_SZ_128			3
126490cb412SJustin Chen #define ASP_EDPKT_BURST_BUF_PSCAL_TOUT		0x10
127490cb412SJustin Chen #define ASP_EDPKT_BURST_BUF_WRITE_TOUT		0x14
128490cb412SJustin Chen #define ASP_EDPKT_BURST_BUF_READ_TOUT		0x18
129490cb412SJustin Chen #define ASP_EDPKT_RX_TS_COUNTER			0x38
130490cb412SJustin Chen #define  ASP_EDPKT_ENDI				0x48
131490cb412SJustin Chen #define   ASP_EDPKT_ENDI_DESC_SHIFT		8
132490cb412SJustin Chen #define   ASP_EDPKT_ENDI_NO_BT_SWP		0
133490cb412SJustin Chen #define   ASP_EDPKT_ENDI_BT_SWP_WD		1
134490cb412SJustin Chen #define ASP_EDPKT_RX_PKT_CNT			0x138
135490cb412SJustin Chen #define ASP_EDPKT_HDR_EXTR_CNT			0x13c
136490cb412SJustin Chen #define ASP_EDPKT_HDR_OUT_CNT			0x140
137490cb412SJustin Chen 
138490cb412SJustin Chen #define ASP_CTRL				0x101000
139490cb412SJustin Chen #define  ASP_CTRL_ASP_SW_INIT			0x04
140490cb412SJustin Chen #define   ASP_CTRL_ASP_SW_INIT_ACPUSS_CORE	BIT(0)
141490cb412SJustin Chen #define   ASP_CTRL_ASP_SW_INIT_ASP_TX		BIT(1)
142490cb412SJustin Chen #define   ASP_CTRL_ASP_SW_INIT_AS_RX		BIT(2)
143490cb412SJustin Chen #define   ASP_CTRL_ASP_SW_INIT_ASP_RGMII_UMAC0	BIT(3)
144490cb412SJustin Chen #define   ASP_CTRL_ASP_SW_INIT_ASP_RGMII_UMAC1	BIT(4)
145490cb412SJustin Chen #define   ASP_CTRL_ASP_SW_INIT_ASP_XMEMIF	BIT(5)
146490cb412SJustin Chen #define  ASP_CTRL_CLOCK_CTRL			0x04
147490cb412SJustin Chen #define   ASP_CTRL_CLOCK_CTRL_ASP_TX_DISABLE	BIT(0)
148490cb412SJustin Chen #define   ASP_CTRL_CLOCK_CTRL_ASP_RX_DISABLE	BIT(1)
149490cb412SJustin Chen #define   ASP_CTRL_CLOCK_CTRL_ASP_RGMII_SHIFT	2
150490cb412SJustin Chen #define   ASP_CTRL_CLOCK_CTRL_ASP_RGMII_MASK	(0x7 << ASP_CTRL_CLOCK_CTRL_ASP_RGMII_SHIFT)
151490cb412SJustin Chen #define   ASP_CTRL_CLOCK_CTRL_ASP_RGMII_DIS(x)	BIT(ASP_CTRL_CLOCK_CTRL_ASP_RGMII_SHIFT + (x))
152490cb412SJustin Chen #define   ASP_CTRL_CLOCK_CTRL_ASP_ALL_DISABLE	GENMASK(4, 0)
153490cb412SJustin Chen #define  ASP_CTRL_CORE_CLOCK_SELECT		0x08
154490cb412SJustin Chen #define   ASP_CTRL_CORE_CLOCK_SELECT_MAIN	BIT(0)
155490cb412SJustin Chen #define  ASP_CTRL_SCRATCH_0			0x0c
156490cb412SJustin Chen 
157490cb412SJustin Chen struct bcmasp_tx_cb {
158490cb412SJustin Chen 	struct sk_buff		*skb;
159490cb412SJustin Chen 	unsigned int		bytes_sent;
160490cb412SJustin Chen 	bool			last;
161490cb412SJustin Chen 
162490cb412SJustin Chen 	DEFINE_DMA_UNMAP_ADDR(dma_addr);
163490cb412SJustin Chen 	DEFINE_DMA_UNMAP_LEN(dma_len);
164490cb412SJustin Chen };
165490cb412SJustin Chen 
166490cb412SJustin Chen struct bcmasp_res {
167490cb412SJustin Chen 	/* Per interface resources */
168490cb412SJustin Chen 	/* Port */
169490cb412SJustin Chen 	void __iomem		*umac;
170490cb412SJustin Chen 	void __iomem		*umac2fb;
171490cb412SJustin Chen 	void __iomem		*rgmii;
172490cb412SJustin Chen 
173490cb412SJustin Chen 	/* TX slowpath/configuration */
174490cb412SJustin Chen 	void __iomem		*tx_spb_ctrl;
175490cb412SJustin Chen 	void __iomem		*tx_spb_top;
176490cb412SJustin Chen 	void __iomem		*tx_epkt_core;
177490cb412SJustin Chen 	void __iomem		*tx_pause_ctrl;
178490cb412SJustin Chen };
179490cb412SJustin Chen 
180490cb412SJustin Chen #define DESC_ADDR(x)		((x) & GENMASK_ULL(39, 0))
181490cb412SJustin Chen #define DESC_FLAGS(x)		((x) & GENMASK_ULL(63, 40))
182490cb412SJustin Chen 
183490cb412SJustin Chen struct bcmasp_desc {
184490cb412SJustin Chen 	u64		buf;
185490cb412SJustin Chen 	#define DESC_CHKSUM	BIT_ULL(40)
186490cb412SJustin Chen 	#define DESC_CRC_ERR	BIT_ULL(41)
187490cb412SJustin Chen 	#define DESC_RX_SYM_ERR	BIT_ULL(42)
188490cb412SJustin Chen 	#define DESC_NO_OCT_ALN BIT_ULL(43)
189490cb412SJustin Chen 	#define DESC_PKT_TRUC	BIT_ULL(44)
190490cb412SJustin Chen 	/*  39:0 (TX/RX) bits 0-39 of buf addr
191490cb412SJustin Chen 	 *    40 (RX) checksum
192490cb412SJustin Chen 	 *    41 (RX) crc_error
193490cb412SJustin Chen 	 *    42 (RX) rx_symbol_error
194490cb412SJustin Chen 	 *    43 (RX) non_octet_aligned
195490cb412SJustin Chen 	 *    44 (RX) pkt_truncated
196490cb412SJustin Chen 	 *    45 Reserved
197490cb412SJustin Chen 	 * 56:46 (RX) mac_filter_id
198490cb412SJustin Chen 	 * 60:57 (RX) rx_port_num (0-unicmac0, 1-unimac1)
199490cb412SJustin Chen 	 *    61 Reserved
200490cb412SJustin Chen 	 * 63:62 (TX) forward CRC, overwrite CRC
201490cb412SJustin Chen 	 */
202490cb412SJustin Chen 	u32		size;
203490cb412SJustin Chen 	u32		flags;
204490cb412SJustin Chen 	#define DESC_INT_EN     BIT(0)
205490cb412SJustin Chen 	#define DESC_SOF	BIT(1)
206490cb412SJustin Chen 	#define DESC_EOF	BIT(2)
207490cb412SJustin Chen 	#define DESC_EPKT_CMD   BIT(3)
208490cb412SJustin Chen 	#define DESC_SCRAM_ST   BIT(8)
209490cb412SJustin Chen 	#define DESC_SCRAM_END  BIT(9)
210490cb412SJustin Chen 	#define DESC_PCPP       BIT(10)
211490cb412SJustin Chen 	#define DESC_PPPP       BIT(11)
212490cb412SJustin Chen 	/*     0 (TX) tx_int_en
213490cb412SJustin Chen 	 *     1 (TX/RX) SOF
214490cb412SJustin Chen 	 *     2 (TX/RX) EOF
215490cb412SJustin Chen 	 *     3 (TX) epkt_command
216490cb412SJustin Chen 	 *   6:4 (TX) PA
217490cb412SJustin Chen 	 *     7 (TX) pause at desc end
218490cb412SJustin Chen 	 *     8 (TX) scram_start
219490cb412SJustin Chen 	 *     9 (TX) scram_end
220490cb412SJustin Chen 	 *    10 (TX) PCPP
221490cb412SJustin Chen 	 *    11 (TX) PPPP
222490cb412SJustin Chen 	 * 14:12 Reserved
223490cb412SJustin Chen 	 *    15 (TX) pid ch Valid
224490cb412SJustin Chen 	 * 19:16 (TX) data_pkt_type
225490cb412SJustin Chen 	 * 32:20 (TX) pid_channel (RX) nw_filter_id
226490cb412SJustin Chen 	 */
227490cb412SJustin Chen };
228490cb412SJustin Chen 
229490cb412SJustin Chen struct bcmasp_intf;
230490cb412SJustin Chen 
231490cb412SJustin Chen struct bcmasp_intf_stats64 {
232490cb412SJustin Chen 	/* Rx Stats */
233490cb412SJustin Chen 	u64_stats_t	rx_packets;
234490cb412SJustin Chen 	u64_stats_t	rx_bytes;
235490cb412SJustin Chen 	u64_stats_t	rx_errors;
236490cb412SJustin Chen 	u64_stats_t	rx_dropped;
237490cb412SJustin Chen 	u64_stats_t	rx_crc_errs;
238490cb412SJustin Chen 	u64_stats_t	rx_sym_errs;
239490cb412SJustin Chen 
240490cb412SJustin Chen 	/* Tx Stats*/
241490cb412SJustin Chen 	u64_stats_t	tx_packets;
242490cb412SJustin Chen 	u64_stats_t	tx_bytes;
243490cb412SJustin Chen 
244490cb412SJustin Chen 	struct u64_stats_sync		syncp;
245490cb412SJustin Chen };
246490cb412SJustin Chen 
2477c10691eSJustin Chen struct bcmasp_mib_counters {
2487c10691eSJustin Chen 	u32	edpkt_ts;
2497c10691eSJustin Chen 	u32	edpkt_rx_pkt_cnt;
2507c10691eSJustin Chen 	u32	edpkt_hdr_ext_cnt;
2517c10691eSJustin Chen 	u32	edpkt_hdr_out_cnt;
2527c10691eSJustin Chen 	u32	umac_frm_cnt;
2537c10691eSJustin Chen 	u32	fb_frm_cnt;
2547c10691eSJustin Chen 	u32	fb_rx_fifo_depth;
2557c10691eSJustin Chen 	u32	fb_out_frm_cnt;
2567c10691eSJustin Chen 	u32	fb_filt_out_frm_cnt;
2577c10691eSJustin Chen 	u32	alloc_rx_skb_failed;
2587c10691eSJustin Chen 	u32	tx_dma_failed;
2597c10691eSJustin Chen 	u32	mc_filters_full_cnt;
2607c10691eSJustin Chen 	u32	uc_filters_full_cnt;
2617c10691eSJustin Chen 	u32	filters_combine_cnt;
2627c10691eSJustin Chen 	u32	promisc_filters_cnt;
2637c10691eSJustin Chen 	u32	tx_realloc_offload_failed;
2647c10691eSJustin Chen 	u32	tx_timeout_cnt;
2657c10691eSJustin Chen };
2667c10691eSJustin Chen 
267490cb412SJustin Chen struct bcmasp_intf_ops {
268490cb412SJustin Chen 	unsigned long (*rx_desc_read)(struct bcmasp_intf *intf);
269490cb412SJustin Chen 	void (*rx_buffer_write)(struct bcmasp_intf *intf, dma_addr_t addr);
270490cb412SJustin Chen 	void (*rx_desc_write)(struct bcmasp_intf *intf, dma_addr_t addr);
271490cb412SJustin Chen 	unsigned long (*tx_read)(struct bcmasp_intf *intf);
272490cb412SJustin Chen 	void (*tx_write)(struct bcmasp_intf *intf, dma_addr_t addr);
273490cb412SJustin Chen };
274490cb412SJustin Chen 
275490cb412SJustin Chen struct bcmasp_priv;
276490cb412SJustin Chen 
277490cb412SJustin Chen struct bcmasp_intf {
278490cb412SJustin Chen 	struct list_head		list;
279490cb412SJustin Chen 	struct net_device		*ndev;
280490cb412SJustin Chen 	struct bcmasp_priv		*parent;
281490cb412SJustin Chen 
282490cb412SJustin Chen 	/* ASP Ch */
283490cb412SJustin Chen 	int				channel;
284490cb412SJustin Chen 	int				port;
285490cb412SJustin Chen 	const struct bcmasp_intf_ops	*ops;
286490cb412SJustin Chen 
287490cb412SJustin Chen 	/* Used for splitting shared resources */
288490cb412SJustin Chen 	int				index;
289490cb412SJustin Chen 
290490cb412SJustin Chen 	struct napi_struct		tx_napi;
291490cb412SJustin Chen 	/* TX ring, starts on a new cacheline boundary */
292490cb412SJustin Chen 	void __iomem			*tx_spb_dma;
293490cb412SJustin Chen 	int				tx_spb_index;
294490cb412SJustin Chen 	int				tx_spb_clean_index;
295490cb412SJustin Chen 	struct bcmasp_desc		*tx_spb_cpu;
296490cb412SJustin Chen 	dma_addr_t			tx_spb_dma_addr;
297490cb412SJustin Chen 	dma_addr_t			tx_spb_dma_valid;
298490cb412SJustin Chen 	dma_addr_t			tx_spb_dma_read;
299490cb412SJustin Chen 	struct bcmasp_tx_cb		*tx_cbs;
300490cb412SJustin Chen 
301490cb412SJustin Chen 	/* RX ring, starts on a new cacheline boundary */
302490cb412SJustin Chen 	void __iomem			*rx_edpkt_cfg;
303490cb412SJustin Chen 	void __iomem			*rx_edpkt_dma;
304490cb412SJustin Chen 	int				rx_edpkt_index;
305490cb412SJustin Chen 	int				rx_buf_order;
306490cb412SJustin Chen 	struct bcmasp_desc		*rx_edpkt_cpu;
307490cb412SJustin Chen 	dma_addr_t			rx_edpkt_dma_addr;
308490cb412SJustin Chen 	dma_addr_t			rx_edpkt_dma_read;
309490cb412SJustin Chen 
310490cb412SJustin Chen 	/* RX buffer prefetcher ring*/
311490cb412SJustin Chen 	void				*rx_ring_cpu;
312490cb412SJustin Chen 	dma_addr_t			rx_ring_dma;
313490cb412SJustin Chen 	dma_addr_t			rx_ring_dma_valid;
314490cb412SJustin Chen 	struct napi_struct		rx_napi;
315490cb412SJustin Chen 
316490cb412SJustin Chen 	struct bcmasp_res		res;
317490cb412SJustin Chen 	unsigned int			crc_fwd;
318490cb412SJustin Chen 
319490cb412SJustin Chen 	/* PHY device */
320490cb412SJustin Chen 	struct device_node		*phy_dn;
321490cb412SJustin Chen 	struct device_node		*ndev_dn;
322490cb412SJustin Chen 	phy_interface_t			phy_interface;
323490cb412SJustin Chen 	bool				internal_phy;
324490cb412SJustin Chen 	int				old_pause;
325490cb412SJustin Chen 	int				old_link;
326490cb412SJustin Chen 	int				old_duplex;
327490cb412SJustin Chen 
328490cb412SJustin Chen 	u32				msg_enable;
329490cb412SJustin Chen 
330490cb412SJustin Chen 	/* Statistics */
331490cb412SJustin Chen 	struct bcmasp_intf_stats64	stats64;
3327c10691eSJustin Chen 	struct bcmasp_mib_counters	mib;
333a2f07512SJustin Chen 
334a2f07512SJustin Chen 	u32				wolopts;
335a2f07512SJustin Chen 	u8				sopass[SOPASS_MAX];
336a2f07512SJustin Chen 	/* Used if per intf wol irq */
337a2f07512SJustin Chen 	int				wol_irq;
338a2f07512SJustin Chen 	unsigned int			wol_irq_enabled:1;
339550e6f34SJustin Chen 
340550e6f34SJustin Chen 	struct ethtool_eee		eee;
341490cb412SJustin Chen };
342490cb412SJustin Chen 
343c5d511c4SJustin Chen #define NUM_NET_FILTERS				32
344c5d511c4SJustin Chen struct bcmasp_net_filter {
345c5d511c4SJustin Chen 	struct ethtool_rx_flow_spec	fs;
346c5d511c4SJustin Chen 
347c5d511c4SJustin Chen 	bool				claimed;
348c5d511c4SJustin Chen 	bool				wake_filter;
349c5d511c4SJustin Chen 
350c5d511c4SJustin Chen 	int				port;
351c5d511c4SJustin Chen 	unsigned int			hw_index;
352c5d511c4SJustin Chen };
353c5d511c4SJustin Chen 
354490cb412SJustin Chen #define NUM_MDA_FILTERS				32
355490cb412SJustin Chen struct bcmasp_mda_filter {
356490cb412SJustin Chen 	/* Current owner of this filter */
357490cb412SJustin Chen 	int		port;
358490cb412SJustin Chen 	bool		en;
359490cb412SJustin Chen 	u8		addr[ETH_ALEN];
360490cb412SJustin Chen 	u8		mask[ETH_ALEN];
361490cb412SJustin Chen };
362490cb412SJustin Chen 
363490cb412SJustin Chen struct bcmasp_hw_info {
364490cb412SJustin Chen 	u32		rx_ctrl_flush;
365490cb412SJustin Chen 	u32		umac2fb;
366490cb412SJustin Chen 	u32		rx_ctrl_fb_out_frame_count;
367490cb412SJustin Chen 	u32		rx_ctrl_fb_filt_out_frame_count;
368490cb412SJustin Chen 	u32		rx_ctrl_fb_rx_fifo_depth;
369490cb412SJustin Chen };
370490cb412SJustin Chen 
371490cb412SJustin Chen struct bcmasp_plat_data {
372a2f07512SJustin Chen 	void (*init_wol)(struct bcmasp_priv *priv);
373a2f07512SJustin Chen 	void (*enable_wol)(struct bcmasp_intf *intf, bool en);
374a2f07512SJustin Chen 	void (*destroy_wol)(struct bcmasp_priv *priv);
375490cb412SJustin Chen 	struct bcmasp_hw_info		*hw_info;
376490cb412SJustin Chen };
377490cb412SJustin Chen 
378490cb412SJustin Chen struct bcmasp_priv {
379490cb412SJustin Chen 	struct platform_device		*pdev;
380490cb412SJustin Chen 	struct clk			*clk;
381490cb412SJustin Chen 
382490cb412SJustin Chen 	int				irq;
383490cb412SJustin Chen 	u32				irq_mask;
384490cb412SJustin Chen 
385a2f07512SJustin Chen 	/* Used if shared wol irq */
386a2f07512SJustin Chen 	struct mutex			wol_lock;
387a2f07512SJustin Chen 	int				wol_irq;
388a2f07512SJustin Chen 	unsigned long			wol_irq_enabled_mask;
389a2f07512SJustin Chen 
390a2f07512SJustin Chen 	void (*init_wol)(struct bcmasp_priv *priv);
391a2f07512SJustin Chen 	void (*enable_wol)(struct bcmasp_intf *intf, bool en);
392a2f07512SJustin Chen 	void (*destroy_wol)(struct bcmasp_priv *priv);
393a2f07512SJustin Chen 
394490cb412SJustin Chen 	void __iomem			*base;
395490cb412SJustin Chen 	struct	bcmasp_hw_info		*hw_info;
396490cb412SJustin Chen 
397490cb412SJustin Chen 	struct list_head		intfs;
398490cb412SJustin Chen 
399490cb412SJustin Chen 	struct bcmasp_mda_filter	mda_filters[NUM_MDA_FILTERS];
400490cb412SJustin Chen 
401490cb412SJustin Chen 	/* MAC destination address filters lock */
402490cb412SJustin Chen 	spinlock_t			mda_lock;
403490cb412SJustin Chen 
404490cb412SJustin Chen 	/* Protects accesses to ASP_CTRL_CLOCK_CTRL */
405490cb412SJustin Chen 	spinlock_t			clk_lock;
406c5d511c4SJustin Chen 
407c5d511c4SJustin Chen 	struct bcmasp_net_filter	net_filters[NUM_NET_FILTERS];
408c5d511c4SJustin Chen 
409c5d511c4SJustin Chen 	/* Network filter lock */
410c5d511c4SJustin Chen 	struct mutex			net_lock;
411490cb412SJustin Chen };
412490cb412SJustin Chen 
bcmasp_intf_rx_desc_read(struct bcmasp_intf * intf)413490cb412SJustin Chen static inline unsigned long bcmasp_intf_rx_desc_read(struct bcmasp_intf *intf)
414490cb412SJustin Chen {
415490cb412SJustin Chen 	return intf->ops->rx_desc_read(intf);
416490cb412SJustin Chen }
417490cb412SJustin Chen 
bcmasp_intf_rx_buffer_write(struct bcmasp_intf * intf,dma_addr_t addr)418490cb412SJustin Chen static inline void bcmasp_intf_rx_buffer_write(struct bcmasp_intf *intf,
419490cb412SJustin Chen 					       dma_addr_t addr)
420490cb412SJustin Chen {
421490cb412SJustin Chen 	intf->ops->rx_buffer_write(intf, addr);
422490cb412SJustin Chen }
423490cb412SJustin Chen 
bcmasp_intf_rx_desc_write(struct bcmasp_intf * intf,dma_addr_t addr)424490cb412SJustin Chen static inline void bcmasp_intf_rx_desc_write(struct bcmasp_intf *intf,
425490cb412SJustin Chen 					     dma_addr_t addr)
426490cb412SJustin Chen {
427490cb412SJustin Chen 	intf->ops->rx_desc_write(intf, addr);
428490cb412SJustin Chen }
429490cb412SJustin Chen 
bcmasp_intf_tx_read(struct bcmasp_intf * intf)430490cb412SJustin Chen static inline unsigned long bcmasp_intf_tx_read(struct bcmasp_intf *intf)
431490cb412SJustin Chen {
432490cb412SJustin Chen 	return intf->ops->tx_read(intf);
433490cb412SJustin Chen }
434490cb412SJustin Chen 
bcmasp_intf_tx_write(struct bcmasp_intf * intf,dma_addr_t addr)435490cb412SJustin Chen static inline void bcmasp_intf_tx_write(struct bcmasp_intf *intf,
436490cb412SJustin Chen 					dma_addr_t addr)
437490cb412SJustin Chen {
438490cb412SJustin Chen 	intf->ops->tx_write(intf, addr);
439490cb412SJustin Chen }
440490cb412SJustin Chen 
441490cb412SJustin Chen #define __BCMASP_IO_MACRO(name, m)					\
442490cb412SJustin Chen static inline u32 name##_rl(struct bcmasp_intf *intf, u32 off)		\
443490cb412SJustin Chen {									\
444490cb412SJustin Chen 	u32 reg = readl_relaxed(intf->m + off);				\
445490cb412SJustin Chen 	return reg;							\
446490cb412SJustin Chen }									\
447490cb412SJustin Chen static inline void name##_wl(struct bcmasp_intf *intf, u32 val, u32 off)\
448490cb412SJustin Chen {									\
449490cb412SJustin Chen 	writel_relaxed(val, intf->m + off);				\
450490cb412SJustin Chen }
451490cb412SJustin Chen 
452490cb412SJustin Chen #define BCMASP_IO_MACRO(name)		__BCMASP_IO_MACRO(name, res.name)
453490cb412SJustin Chen #define BCMASP_FP_IO_MACRO(name)	__BCMASP_IO_MACRO(name, name)
454490cb412SJustin Chen 
455490cb412SJustin Chen BCMASP_IO_MACRO(umac);
456490cb412SJustin Chen BCMASP_IO_MACRO(umac2fb);
457490cb412SJustin Chen BCMASP_IO_MACRO(rgmii);
458490cb412SJustin Chen BCMASP_FP_IO_MACRO(tx_spb_dma);
459490cb412SJustin Chen BCMASP_IO_MACRO(tx_spb_ctrl);
460490cb412SJustin Chen BCMASP_IO_MACRO(tx_spb_top);
461490cb412SJustin Chen BCMASP_IO_MACRO(tx_epkt_core);
462490cb412SJustin Chen BCMASP_IO_MACRO(tx_pause_ctrl);
463490cb412SJustin Chen BCMASP_FP_IO_MACRO(rx_edpkt_dma);
464490cb412SJustin Chen BCMASP_FP_IO_MACRO(rx_edpkt_cfg);
465490cb412SJustin Chen 
466490cb412SJustin Chen #define __BCMASP_FP_IO_MACRO_Q(name, m)					\
467490cb412SJustin Chen static inline u64 name##_rq(struct bcmasp_intf *intf, u32 off)		\
468490cb412SJustin Chen {									\
469490cb412SJustin Chen 	u64 reg = readq_relaxed(intf->m + off);				\
470490cb412SJustin Chen 	return reg;							\
471490cb412SJustin Chen }									\
472490cb412SJustin Chen static inline void name##_wq(struct bcmasp_intf *intf, u64 val, u32 off)\
473490cb412SJustin Chen {									\
474490cb412SJustin Chen 	writeq_relaxed(val, intf->m + off);				\
475490cb412SJustin Chen }
476490cb412SJustin Chen 
477490cb412SJustin Chen #define BCMASP_FP_IO_MACRO_Q(name)	__BCMASP_FP_IO_MACRO_Q(name, name)
478490cb412SJustin Chen 
479490cb412SJustin Chen BCMASP_FP_IO_MACRO_Q(tx_spb_dma);
480490cb412SJustin Chen BCMASP_FP_IO_MACRO_Q(rx_edpkt_dma);
481490cb412SJustin Chen BCMASP_FP_IO_MACRO_Q(rx_edpkt_cfg);
482490cb412SJustin Chen 
483490cb412SJustin Chen #define PKT_OFFLOAD_NOP			(0 << 28)
484490cb412SJustin Chen #define PKT_OFFLOAD_HDR_OP		(1 << 28)
485490cb412SJustin Chen #define  PKT_OFFLOAD_HDR_WRBACK		BIT(19)
486490cb412SJustin Chen #define  PKT_OFFLOAD_HDR_COUNT(x)	((x) << 16)
487490cb412SJustin Chen #define  PKT_OFFLOAD_HDR_SIZE_1(x)	((x) << 4)
488490cb412SJustin Chen #define  PKT_OFFLOAD_HDR_SIZE_2(x)	(x)
489490cb412SJustin Chen #define  PKT_OFFLOAD_HDR2_SIZE_2(x)	((x) << 24)
490490cb412SJustin Chen #define  PKT_OFFLOAD_HDR2_SIZE_3(x)	((x) << 12)
491490cb412SJustin Chen #define  PKT_OFFLOAD_HDR2_SIZE_4(x)	(x)
492490cb412SJustin Chen #define PKT_OFFLOAD_EPKT_OP		(2 << 28)
493490cb412SJustin Chen #define  PKT_OFFLOAD_EPKT_WRBACK	BIT(23)
494490cb412SJustin Chen #define  PKT_OFFLOAD_EPKT_IP(x)		((x) << 21)
495490cb412SJustin Chen #define  PKT_OFFLOAD_EPKT_TP(x)		((x) << 19)
496490cb412SJustin Chen #define  PKT_OFFLOAD_EPKT_LEN(x)	((x) << 16)
497490cb412SJustin Chen #define  PKT_OFFLOAD_EPKT_CSUM_L3	BIT(15)
498490cb412SJustin Chen #define  PKT_OFFLOAD_EPKT_CSUM_L2	BIT(14)
499490cb412SJustin Chen #define  PKT_OFFLOAD_EPKT_ID(x)		((x) << 12)
500490cb412SJustin Chen #define  PKT_OFFLOAD_EPKT_SEQ(x)	((x) << 10)
501490cb412SJustin Chen #define  PKT_OFFLOAD_EPKT_TS(x)		((x) << 8)
502490cb412SJustin Chen #define  PKT_OFFLOAD_EPKT_BLOC(x)	(x)
503490cb412SJustin Chen #define PKT_OFFLOAD_END_OP		(7 << 28)
504490cb412SJustin Chen 
505490cb412SJustin Chen struct bcmasp_pkt_offload {
506490cb412SJustin Chen 	__be32		nop;
507490cb412SJustin Chen 	__be32		header;
508490cb412SJustin Chen 	__be32		header2;
509490cb412SJustin Chen 	__be32		epkt;
510490cb412SJustin Chen 	__be32		end;
511490cb412SJustin Chen };
512490cb412SJustin Chen 
513490cb412SJustin Chen #define BCMASP_CORE_IO_MACRO(name, offset)				\
514490cb412SJustin Chen static inline u32 name##_core_rl(struct bcmasp_priv *priv,		\
515490cb412SJustin Chen 				 u32 off)				\
516490cb412SJustin Chen {									\
517490cb412SJustin Chen 	u32 reg = readl_relaxed(priv->base + (offset) + off);		\
518490cb412SJustin Chen 	return reg;							\
519490cb412SJustin Chen }									\
520490cb412SJustin Chen static inline void name##_core_wl(struct bcmasp_priv *priv,		\
521490cb412SJustin Chen 				  u32 val, u32 off)			\
522490cb412SJustin Chen {									\
523490cb412SJustin Chen 	writel_relaxed(val, priv->base + (offset) + off);		\
524490cb412SJustin Chen }
525490cb412SJustin Chen 
526490cb412SJustin Chen BCMASP_CORE_IO_MACRO(intr2, ASP_INTR2_OFFSET);
527490cb412SJustin Chen BCMASP_CORE_IO_MACRO(wakeup_intr2, ASP_WAKEUP_INTR2_OFFSET);
528490cb412SJustin Chen BCMASP_CORE_IO_MACRO(tx_analytics, ASP_TX_ANALYTICS_OFFSET);
529490cb412SJustin Chen BCMASP_CORE_IO_MACRO(rx_analytics, ASP_RX_ANALYTICS_OFFSET);
530490cb412SJustin Chen BCMASP_CORE_IO_MACRO(rx_ctrl, ASP_RX_CTRL_OFFSET);
531490cb412SJustin Chen BCMASP_CORE_IO_MACRO(rx_filter, ASP_RX_FILTER_OFFSET);
532490cb412SJustin Chen BCMASP_CORE_IO_MACRO(rx_edpkt, ASP_EDPKT_OFFSET);
533490cb412SJustin Chen BCMASP_CORE_IO_MACRO(ctrl, ASP_CTRL);
534490cb412SJustin Chen 
535490cb412SJustin Chen struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
536490cb412SJustin Chen 					    struct device_node *ndev_dn, int i);
537490cb412SJustin Chen 
538490cb412SJustin Chen void bcmasp_interface_destroy(struct bcmasp_intf *intf);
539490cb412SJustin Chen 
540490cb412SJustin Chen void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en);
541490cb412SJustin Chen 
542490cb412SJustin Chen void bcmasp_enable_rx_irq(struct bcmasp_intf *intf, int en);
543490cb412SJustin Chen 
544490cb412SJustin Chen void bcmasp_flush_rx_port(struct bcmasp_intf *intf);
545490cb412SJustin Chen 
546490cb412SJustin Chen extern const struct ethtool_ops bcmasp_ethtool_ops;
547490cb412SJustin Chen 
548490cb412SJustin Chen int bcmasp_interface_suspend(struct bcmasp_intf *intf);
549490cb412SJustin Chen 
550490cb412SJustin Chen int bcmasp_interface_resume(struct bcmasp_intf *intf);
551490cb412SJustin Chen 
552490cb412SJustin Chen void bcmasp_set_promisc(struct bcmasp_intf *intf, bool en);
553490cb412SJustin Chen 
554490cb412SJustin Chen void bcmasp_set_allmulti(struct bcmasp_intf *intf, bool en);
555490cb412SJustin Chen 
556490cb412SJustin Chen void bcmasp_set_broad(struct bcmasp_intf *intf, bool en);
557490cb412SJustin Chen 
558490cb412SJustin Chen void bcmasp_set_oaddr(struct bcmasp_intf *intf, const unsigned char *addr,
559490cb412SJustin Chen 		      bool en);
560490cb412SJustin Chen 
561490cb412SJustin Chen int bcmasp_set_en_mda_filter(struct bcmasp_intf *intf, unsigned char *addr,
562490cb412SJustin Chen 			     unsigned char *mask);
563490cb412SJustin Chen 
564490cb412SJustin Chen void bcmasp_disable_all_filters(struct bcmasp_intf *intf);
565490cb412SJustin Chen 
566490cb412SJustin Chen void bcmasp_core_clock_set_intf(struct bcmasp_intf *intf, bool en);
567490cb412SJustin Chen 
568c5d511c4SJustin Chen struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf,
56948d17c51SDan Carpenter 						  u32 loc, bool wake_filter,
570c5d511c4SJustin Chen 						  bool init);
571c5d511c4SJustin Chen 
572c5d511c4SJustin Chen bool bcmasp_netfilt_check_dup(struct bcmasp_intf *intf,
573c5d511c4SJustin Chen 			      struct ethtool_rx_flow_spec *fs);
574c5d511c4SJustin Chen 
575c5d511c4SJustin Chen void bcmasp_netfilt_release(struct bcmasp_intf *intf,
576c5d511c4SJustin Chen 			    struct bcmasp_net_filter *nfilt);
577c5d511c4SJustin Chen 
578c5d511c4SJustin Chen int bcmasp_netfilt_get_active(struct bcmasp_intf *intf);
579c5d511c4SJustin Chen 
580*9b90aca9SHangyu Hua int bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
581c5d511c4SJustin Chen 				  u32 *rule_cnt);
582c5d511c4SJustin Chen 
583c5d511c4SJustin Chen void bcmasp_netfilt_suspend(struct bcmasp_intf *intf);
584550e6f34SJustin Chen 
585550e6f34SJustin Chen void bcmasp_eee_enable_set(struct bcmasp_intf *intf, bool enable);
586490cb412SJustin Chen #endif
587