1db8bcaadSHoratiu Vultur /* SPDX-License-Identifier: GPL-2.0+ */
2db8bcaadSHoratiu Vultur
3db8bcaadSHoratiu Vultur #ifndef __LAN966X_MAIN_H__
4db8bcaadSHoratiu Vultur #define __LAN966X_MAIN_H__
5db8bcaadSHoratiu Vultur
694281484SHoratiu Vultur #include <linux/debugfs.h>
7d28d6d2eSHoratiu Vultur #include <linux/etherdevice.h>
86d2c186aSHoratiu Vultur #include <linux/if_vlan.h>
9e18aba89SHoratiu Vultur #include <linux/jiffies.h>
10d28d6d2eSHoratiu Vultur #include <linux/phy.h>
11d28d6d2eSHoratiu Vultur #include <linux/phylink.h>
12d0964594SHoratiu Vultur #include <linux/ptp_clock_kernel.h>
13*a9ca9f9cSYunsheng Lin #include <net/page_pool/types.h>
1494644b6dSHoratiu Vultur #include <net/pkt_cls.h>
15e462b271SHoratiu Vultur #include <net/pkt_sched.h>
16811ba277SHoratiu Vultur #include <net/switchdev.h>
1792272ec4SJakub Kicinski #include <net/xdp.h>
18d28d6d2eSHoratiu Vultur
1994281484SHoratiu Vultur #include <vcap_api.h>
2094281484SHoratiu Vultur #include <vcap_api_client.h>
2194281484SHoratiu Vultur
22db8bcaadSHoratiu Vultur #include "lan966x_regs.h"
23d28d6d2eSHoratiu Vultur #include "lan966x_ifh.h"
24db8bcaadSHoratiu Vultur
25e18aba89SHoratiu Vultur #define TABLE_UPDATE_SLEEP_US 10
26e18aba89SHoratiu Vultur #define TABLE_UPDATE_TIMEOUT_US 100000
27e18aba89SHoratiu Vultur
288f2c7d9aSHoratiu Vultur #define READL_SLEEP_US 10
298f2c7d9aSHoratiu Vultur #define READL_TIMEOUT_US 100000000
308f2c7d9aSHoratiu Vultur
31db8bcaadSHoratiu Vultur #define LAN966X_BUFFER_CELL_SZ 64
32db8bcaadSHoratiu Vultur #define LAN966X_BUFFER_MEMORY (160 * 1024)
33db8bcaadSHoratiu Vultur #define LAN966X_BUFFER_MIN_SZ 60
34db8bcaadSHoratiu Vultur
35486c2922SHoratiu Vultur #define LAN966X_HW_MTU(mtu) ((mtu) + ETH_HLEN + ETH_FCS_LEN)
36486c2922SHoratiu Vultur
37db8bcaadSHoratiu Vultur #define PGID_AGGR 64
38db8bcaadSHoratiu Vultur #define PGID_SRC 80
39db8bcaadSHoratiu Vultur #define PGID_ENTRIES 89
40db8bcaadSHoratiu Vultur
416d2c186aSHoratiu Vultur #define UNAWARE_PVID 0
426d2c186aSHoratiu Vultur #define HOST_PVID 4095
43db8bcaadSHoratiu Vultur
44db8bcaadSHoratiu Vultur /* Reserved amount for (SRC, PRIO) at index 8*SRC + PRIO */
45db8bcaadSHoratiu Vultur #define QSYS_Q_RSRV 95
46db8bcaadSHoratiu Vultur
47e6fa930fSMichael Walle #define NUM_PHYS_PORTS 8
4811b0a277SHoratiu Vultur #define CPU_PORT 8
49644ffce5SHoratiu Vultur #define NUM_PRIO_QUEUES 8
5011b0a277SHoratiu Vultur
51db8bcaadSHoratiu Vultur /* Reserved PGIDs */
52db8bcaadSHoratiu Vultur #define PGID_CPU (PGID_AGGR - 6)
53db8bcaadSHoratiu Vultur #define PGID_UC (PGID_AGGR - 5)
54db8bcaadSHoratiu Vultur #define PGID_BC (PGID_AGGR - 4)
55db8bcaadSHoratiu Vultur #define PGID_MC (PGID_AGGR - 3)
56db8bcaadSHoratiu Vultur #define PGID_MCIPV4 (PGID_AGGR - 2)
57db8bcaadSHoratiu Vultur #define PGID_MCIPV6 (PGID_AGGR - 1)
58db8bcaadSHoratiu Vultur
5911b0a277SHoratiu Vultur /* Non-reserved PGIDs, used for general purpose */
6011b0a277SHoratiu Vultur #define PGID_GP_START (CPU_PORT + 1)
6111b0a277SHoratiu Vultur #define PGID_GP_END PGID_CPU
6211b0a277SHoratiu Vultur
63db8bcaadSHoratiu Vultur #define LAN966X_SPEED_NONE 0
64d28d6d2eSHoratiu Vultur #define LAN966X_SPEED_2500 1
65db8bcaadSHoratiu Vultur #define LAN966X_SPEED_1000 1
66db8bcaadSHoratiu Vultur #define LAN966X_SPEED_100 2
67db8bcaadSHoratiu Vultur #define LAN966X_SPEED_10 3
68db8bcaadSHoratiu Vultur
69d0964594SHoratiu Vultur #define LAN966X_PHC_COUNT 3
70d0964594SHoratiu Vultur #define LAN966X_PHC_PORT 0
712b7ff258SHoratiu Vultur #define LAN966X_PHC_PINS_NUM 7
72d0964594SHoratiu Vultur
73735fec99SHoratiu Vultur #define IFH_REW_OP_NOOP 0x0
74735fec99SHoratiu Vultur #define IFH_REW_OP_ONE_STEP_PTP 0x3
75735fec99SHoratiu Vultur #define IFH_REW_OP_TWO_STEP_PTP 0x4
76735fec99SHoratiu Vultur
77c8349639SHoratiu Vultur #define FDMA_RX_DCB_MAX_DBS 1
78c8349639SHoratiu Vultur #define FDMA_TX_DCB_MAX_DBS 1
79c8349639SHoratiu Vultur #define FDMA_DCB_INFO_DATAL(x) ((x) & GENMASK(15, 0))
80c8349639SHoratiu Vultur
81c8349639SHoratiu Vultur #define FDMA_DCB_STATUS_BLOCKL(x) ((x) & GENMASK(15, 0))
82c8349639SHoratiu Vultur #define FDMA_DCB_STATUS_SOF BIT(16)
83c8349639SHoratiu Vultur #define FDMA_DCB_STATUS_EOF BIT(17)
84c8349639SHoratiu Vultur #define FDMA_DCB_STATUS_INTR BIT(18)
85c8349639SHoratiu Vultur #define FDMA_DCB_STATUS_DONE BIT(19)
86c8349639SHoratiu Vultur #define FDMA_DCB_STATUS_BLOCKO(x) (((x) << 20) & GENMASK(31, 20))
87c8349639SHoratiu Vultur #define FDMA_DCB_INVALID_DATA 0x1
88c8349639SHoratiu Vultur
89c8349639SHoratiu Vultur #define FDMA_XTR_CHANNEL 6
90c8349639SHoratiu Vultur #define FDMA_INJ_CHANNEL 0
91c8349639SHoratiu Vultur #define FDMA_DCB_MAX 512
92c8349639SHoratiu Vultur
9394644b6dSHoratiu Vultur #define SE_IDX_QUEUE 0 /* 0-79 : Queue scheduler elements */
9494644b6dSHoratiu Vultur #define SE_IDX_PORT 80 /* 80-89 : Port schedular elements */
9594644b6dSHoratiu Vultur
96a4d9b3ecSHoratiu Vultur #define LAN966X_VCAP_CID_IS1_L0 VCAP_CID_INGRESS_L0 /* IS1 lookup 0 */
97a4d9b3ecSHoratiu Vultur #define LAN966X_VCAP_CID_IS1_L1 VCAP_CID_INGRESS_L1 /* IS1 lookup 1 */
98a4d9b3ecSHoratiu Vultur #define LAN966X_VCAP_CID_IS1_L2 VCAP_CID_INGRESS_L2 /* IS1 lookup 2 */
99a4d9b3ecSHoratiu Vultur #define LAN966X_VCAP_CID_IS1_MAX (VCAP_CID_INGRESS_L3 - 1) /* IS1 Max */
100a4d9b3ecSHoratiu Vultur
10172df3489SHoratiu Vultur #define LAN966X_VCAP_CID_IS2_L0 VCAP_CID_INGRESS_STAGE2_L0 /* IS2 lookup 0 */
10272df3489SHoratiu Vultur #define LAN966X_VCAP_CID_IS2_L1 VCAP_CID_INGRESS_STAGE2_L1 /* IS2 lookup 1 */
10372df3489SHoratiu Vultur #define LAN966X_VCAP_CID_IS2_MAX (VCAP_CID_INGRESS_STAGE2_L2 - 1) /* IS2 Max */
10472df3489SHoratiu Vultur
10596b6c8a6SHoratiu Vultur #define LAN966X_VCAP_CID_ES0_L0 VCAP_CID_EGRESS_L0 /* ES0 lookup 0 */
10696b6c8a6SHoratiu Vultur #define LAN966X_VCAP_CID_ES0_MAX (VCAP_CID_EGRESS_L1 - 1) /* ES0 Max */
10796b6c8a6SHoratiu Vultur
108a83e4630SHoratiu Vultur #define LAN966X_PORT_QOS_PCP_COUNT 8
109a83e4630SHoratiu Vultur #define LAN966X_PORT_QOS_DEI_COUNT 8
110a83e4630SHoratiu Vultur #define LAN966X_PORT_QOS_PCP_DEI_COUNT \
111a83e4630SHoratiu Vultur (LAN966X_PORT_QOS_PCP_COUNT + LAN966X_PORT_QOS_DEI_COUNT)
112a83e4630SHoratiu Vultur
1130c88d981SHoratiu Vultur #define LAN966X_PORT_QOS_DSCP_COUNT 64
1140c88d981SHoratiu Vultur
115363f98b9SHoratiu Vultur /* Port PCP rewrite mode */
116363f98b9SHoratiu Vultur #define LAN966X_PORT_REW_TAG_CTRL_CLASSIFIED 0
117363f98b9SHoratiu Vultur #define LAN966X_PORT_REW_TAG_CTRL_MAPPED 2
118363f98b9SHoratiu Vultur
119d38ddd56SHoratiu Vultur /* Port DSCP rewrite mode */
120d38ddd56SHoratiu Vultur #define LAN966X_PORT_REW_DSCP_FRAME 0
121d38ddd56SHoratiu Vultur #define LAN966X_PORT_REW_DSCP_ANALIZER 1
122d38ddd56SHoratiu Vultur #define LAN966X_PORT_QOS_REWR_DSCP_ALL 3
123d38ddd56SHoratiu Vultur
124e18aba89SHoratiu Vultur /* MAC table entry types.
125e18aba89SHoratiu Vultur * ENTRYTYPE_NORMAL is subject to aging.
126e18aba89SHoratiu Vultur * ENTRYTYPE_LOCKED is not subject to aging.
127e18aba89SHoratiu Vultur * ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast.
128e18aba89SHoratiu Vultur * ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast.
129e18aba89SHoratiu Vultur */
130e18aba89SHoratiu Vultur enum macaccess_entry_type {
131e18aba89SHoratiu Vultur ENTRYTYPE_NORMAL = 0,
132e18aba89SHoratiu Vultur ENTRYTYPE_LOCKED,
133e18aba89SHoratiu Vultur ENTRYTYPE_MACV4,
134e18aba89SHoratiu Vultur ENTRYTYPE_MACV6,
135e18aba89SHoratiu Vultur };
136e18aba89SHoratiu Vultur
1374a00b0c7SHoratiu Vultur /* FDMA return action codes for checking if the frame is valid
1384a00b0c7SHoratiu Vultur * FDMA_PASS, frame is valid and can be used
1394a00b0c7SHoratiu Vultur * FDMA_ERROR, something went wrong, stop getting more frames
1406a2159beSHoratiu Vultur * FDMA_DROP, frame is dropped, but continue to get more frames
14119c6f534SHoratiu Vultur * FDMA_TX, frame is given to TX, but continue to get more frames
142a825b611SHoratiu Vultur * FDMA_REDIRECT, frame is given to TX, but continue to get more frames
1434a00b0c7SHoratiu Vultur */
1444a00b0c7SHoratiu Vultur enum lan966x_fdma_action {
1454a00b0c7SHoratiu Vultur FDMA_PASS = 0,
1464a00b0c7SHoratiu Vultur FDMA_ERROR,
1476a2159beSHoratiu Vultur FDMA_DROP,
14819c6f534SHoratiu Vultur FDMA_TX,
149a825b611SHoratiu Vultur FDMA_REDIRECT,
1504a00b0c7SHoratiu Vultur };
1514a00b0c7SHoratiu Vultur
15272df3489SHoratiu Vultur /* Controls how PORT_MASK is applied */
15372df3489SHoratiu Vultur enum LAN966X_PORT_MASK_MODE {
15472df3489SHoratiu Vultur LAN966X_PMM_NO_ACTION,
15572df3489SHoratiu Vultur LAN966X_PMM_REPLACE,
15672df3489SHoratiu Vultur LAN966X_PMM_FORWARDING,
15772df3489SHoratiu Vultur LAN966X_PMM_REDIRECT,
15872df3489SHoratiu Vultur };
15972df3489SHoratiu Vultur
16094281484SHoratiu Vultur enum vcap_is2_port_sel_ipv6 {
16194281484SHoratiu Vultur VCAP_IS2_PS_IPV6_TCPUDP_OTHER,
16294281484SHoratiu Vultur VCAP_IS2_PS_IPV6_STD,
16394281484SHoratiu Vultur VCAP_IS2_PS_IPV6_IP4_TCPUDP_IP4_OTHER,
16494281484SHoratiu Vultur VCAP_IS2_PS_IPV6_MAC_ETYPE,
16594281484SHoratiu Vultur };
16694281484SHoratiu Vultur
167a4d9b3ecSHoratiu Vultur enum vcap_is1_port_sel_other {
168a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_OTHER_NORMAL,
169a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_OTHER_7TUPLE,
170a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_OTHER_DBL_VID,
171a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_OTHER_DMAC_VID,
172a4d9b3ecSHoratiu Vultur };
173a4d9b3ecSHoratiu Vultur
174a4d9b3ecSHoratiu Vultur enum vcap_is1_port_sel_ipv4 {
175a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV4_NORMAL,
176a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV4_7TUPLE,
177a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV4_5TUPLE_IP4,
178a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV4_DBL_VID,
179a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV4_DMAC_VID,
180a4d9b3ecSHoratiu Vultur };
181a4d9b3ecSHoratiu Vultur
182a4d9b3ecSHoratiu Vultur enum vcap_is1_port_sel_ipv6 {
183a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV6_NORMAL,
184a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV6_7TUPLE,
185a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV6_5TUPLE_IP4,
186a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV6_NORMAL_IP6,
187a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV6_5TUPLE_IP6,
188a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV6_DBL_VID,
189a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_IPV6_DMAC_VID,
190a4d9b3ecSHoratiu Vultur };
191a4d9b3ecSHoratiu Vultur
192a4d9b3ecSHoratiu Vultur enum vcap_is1_port_sel_rt {
193a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_RT_NORMAL,
194a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_RT_7TUPLE,
195a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_RT_DBL_VID,
196a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_RT_DMAC_VID,
197a4d9b3ecSHoratiu Vultur VCAP_IS1_PS_RT_FOLLOW_OTHER = 7,
198a4d9b3ecSHoratiu Vultur };
199a4d9b3ecSHoratiu Vultur
200db8bcaadSHoratiu Vultur struct lan966x_port;
201db8bcaadSHoratiu Vultur
202c8349639SHoratiu Vultur struct lan966x_db {
203c8349639SHoratiu Vultur u64 dataptr;
204c8349639SHoratiu Vultur u64 status;
205c8349639SHoratiu Vultur };
206c8349639SHoratiu Vultur
207c8349639SHoratiu Vultur struct lan966x_rx_dcb {
208c8349639SHoratiu Vultur u64 nextptr;
209c8349639SHoratiu Vultur u64 info;
210c8349639SHoratiu Vultur struct lan966x_db db[FDMA_RX_DCB_MAX_DBS];
211c8349639SHoratiu Vultur };
212c8349639SHoratiu Vultur
213c8349639SHoratiu Vultur struct lan966x_tx_dcb {
214c8349639SHoratiu Vultur u64 nextptr;
215c8349639SHoratiu Vultur u64 info;
216c8349639SHoratiu Vultur struct lan966x_db db[FDMA_TX_DCB_MAX_DBS];
217c8349639SHoratiu Vultur };
218c8349639SHoratiu Vultur
219c8349639SHoratiu Vultur struct lan966x_rx {
220c8349639SHoratiu Vultur struct lan966x *lan966x;
221c8349639SHoratiu Vultur
222c8349639SHoratiu Vultur /* Pointer to the array of hardware dcbs. */
223c8349639SHoratiu Vultur struct lan966x_rx_dcb *dcbs;
224c8349639SHoratiu Vultur
225c8349639SHoratiu Vultur /* Pointer to the last address in the dcbs. */
226c8349639SHoratiu Vultur struct lan966x_rx_dcb *last_entry;
227c8349639SHoratiu Vultur
228c8349639SHoratiu Vultur /* For each DB, there is a page */
229c8349639SHoratiu Vultur struct page *page[FDMA_DCB_MAX][FDMA_RX_DCB_MAX_DBS];
230c8349639SHoratiu Vultur
231c8349639SHoratiu Vultur /* Represents the db_index, it can have a value between 0 and
232c8349639SHoratiu Vultur * FDMA_RX_DCB_MAX_DBS, once it reaches the value of FDMA_RX_DCB_MAX_DBS
233c8349639SHoratiu Vultur * it means that the DCB can be reused.
234c8349639SHoratiu Vultur */
235c8349639SHoratiu Vultur int db_index;
236c8349639SHoratiu Vultur
237c8349639SHoratiu Vultur /* Represents the index in the dcbs. It has a value between 0 and
238c8349639SHoratiu Vultur * FDMA_DCB_MAX
239c8349639SHoratiu Vultur */
240c8349639SHoratiu Vultur int dcb_index;
241c8349639SHoratiu Vultur
242c8349639SHoratiu Vultur /* Represents the dma address to the dcbs array */
243c8349639SHoratiu Vultur dma_addr_t dma;
244c8349639SHoratiu Vultur
245c8349639SHoratiu Vultur /* Represents the page order that is used to allocate the pages for the
246c8349639SHoratiu Vultur * RX buffers. This value is calculated based on max MTU of the devices.
247c8349639SHoratiu Vultur */
248c8349639SHoratiu Vultur u8 page_order;
249c8349639SHoratiu Vultur
25011871abaSHoratiu Vultur /* Represents the max size frame that it can receive to the CPU. This
25111871abaSHoratiu Vultur * includes the IFH + VLAN tags + frame + skb_shared_info
25211871abaSHoratiu Vultur */
25311871abaSHoratiu Vultur u32 max_mtu;
25411871abaSHoratiu Vultur
255c8349639SHoratiu Vultur u8 channel_id;
25611871abaSHoratiu Vultur
25711871abaSHoratiu Vultur struct page_pool *page_pool;
258c8349639SHoratiu Vultur };
259c8349639SHoratiu Vultur
260c8349639SHoratiu Vultur struct lan966x_tx_dcb_buf {
26149f5eea8SHoratiu Vultur dma_addr_t dma_addr;
262c8349639SHoratiu Vultur struct net_device *dev;
26319c6f534SHoratiu Vultur union {
264c8349639SHoratiu Vultur struct sk_buff *skb;
26519c6f534SHoratiu Vultur struct xdp_frame *xdpf;
266700f11ebSHoratiu Vultur struct page *page;
26719c6f534SHoratiu Vultur } data;
26849f5eea8SHoratiu Vultur u32 len;
26949f5eea8SHoratiu Vultur u32 used : 1;
27049f5eea8SHoratiu Vultur u32 ptp : 1;
27119c6f534SHoratiu Vultur u32 use_skb : 1;
272a825b611SHoratiu Vultur u32 xdp_ndo : 1;
273c8349639SHoratiu Vultur };
274c8349639SHoratiu Vultur
275c8349639SHoratiu Vultur struct lan966x_tx {
276c8349639SHoratiu Vultur struct lan966x *lan966x;
277c8349639SHoratiu Vultur
278c8349639SHoratiu Vultur /* Pointer to the dcb list */
279c8349639SHoratiu Vultur struct lan966x_tx_dcb *dcbs;
280c8349639SHoratiu Vultur u16 last_in_use;
281c8349639SHoratiu Vultur
282c8349639SHoratiu Vultur /* Represents the DMA address to the first entry of the dcb entries. */
283c8349639SHoratiu Vultur dma_addr_t dma;
284c8349639SHoratiu Vultur
285c8349639SHoratiu Vultur /* Array of dcbs that are given to the HW */
286c8349639SHoratiu Vultur struct lan966x_tx_dcb_buf *dcbs_buf;
287c8349639SHoratiu Vultur
288c8349639SHoratiu Vultur u8 channel_id;
289c8349639SHoratiu Vultur
290c8349639SHoratiu Vultur bool activated;
291c8349639SHoratiu Vultur };
292c8349639SHoratiu Vultur
29312c2d0a5SHoratiu Vultur struct lan966x_stat_layout {
29412c2d0a5SHoratiu Vultur u32 offset;
29512c2d0a5SHoratiu Vultur char name[ETH_GSTRING_LEN];
29612c2d0a5SHoratiu Vultur };
29712c2d0a5SHoratiu Vultur
298d0964594SHoratiu Vultur struct lan966x_phc {
299d0964594SHoratiu Vultur struct ptp_clock *clock;
300d0964594SHoratiu Vultur struct ptp_clock_info info;
3012b7ff258SHoratiu Vultur struct ptp_pin_desc pins[LAN966X_PHC_PINS_NUM];
30254e1ed69SVladimir Oltean struct kernel_hwtstamp_config hwtstamp_config;
303d0964594SHoratiu Vultur struct lan966x *lan966x;
304d0964594SHoratiu Vultur u8 index;
305d0964594SHoratiu Vultur };
306d0964594SHoratiu Vultur
30777eecf25SHoratiu Vultur struct lan966x_skb_cb {
30877eecf25SHoratiu Vultur u8 rew_op;
30977eecf25SHoratiu Vultur u16 ts_id;
31077eecf25SHoratiu Vultur unsigned long jiffies;
31177eecf25SHoratiu Vultur };
31277eecf25SHoratiu Vultur
31377eecf25SHoratiu Vultur #define LAN966X_PTP_TIMEOUT msecs_to_jiffies(10)
31477eecf25SHoratiu Vultur #define LAN966X_SKB_CB(skb) \
31577eecf25SHoratiu Vultur ((struct lan966x_skb_cb *)((skb)->cb))
31677eecf25SHoratiu Vultur
317db8bcaadSHoratiu Vultur struct lan966x {
318db8bcaadSHoratiu Vultur struct device *dev;
319db8bcaadSHoratiu Vultur
320db8bcaadSHoratiu Vultur u8 num_phys_ports;
321db8bcaadSHoratiu Vultur struct lan966x_port **ports;
322db8bcaadSHoratiu Vultur
323db8bcaadSHoratiu Vultur void __iomem *regs[NUM_TARGETS];
324db8bcaadSHoratiu Vultur
325db8bcaadSHoratiu Vultur int shared_queue_sz;
326d28d6d2eSHoratiu Vultur
327e18aba89SHoratiu Vultur u8 base_mac[ETH_ALEN];
328e18aba89SHoratiu Vultur
3290dbdf819SHoratiu Vultur spinlock_t tx_lock; /* lock for frame transmition */
3300dbdf819SHoratiu Vultur
331cf2f6089SHoratiu Vultur struct net_device *bridge;
332cf2f6089SHoratiu Vultur u16 bridge_mask;
333cf2f6089SHoratiu Vultur u16 bridge_fwd_mask;
334cf2f6089SHoratiu Vultur
3355ccd66e0SHoratiu Vultur struct list_head mac_entries;
3365ccd66e0SHoratiu Vultur spinlock_t mac_lock; /* lock for mac_entries list */
3375ccd66e0SHoratiu Vultur
3386d2c186aSHoratiu Vultur u16 vlan_mask[VLAN_N_VID];
3396d2c186aSHoratiu Vultur DECLARE_BITMAP(cpu_vlan_mask, VLAN_N_VID);
3406d2c186aSHoratiu Vultur
34112c2d0a5SHoratiu Vultur /* stats */
34212c2d0a5SHoratiu Vultur const struct lan966x_stat_layout *stats_layout;
34312c2d0a5SHoratiu Vultur u32 num_stats;
34412c2d0a5SHoratiu Vultur
34512c2d0a5SHoratiu Vultur /* workqueue for reading stats */
34612c2d0a5SHoratiu Vultur struct mutex stats_lock;
34712c2d0a5SHoratiu Vultur u64 *stats;
34812c2d0a5SHoratiu Vultur struct delayed_work stats_work;
34912c2d0a5SHoratiu Vultur struct workqueue_struct *stats_queue;
35012c2d0a5SHoratiu Vultur
351d28d6d2eSHoratiu Vultur /* interrupts */
352d28d6d2eSHoratiu Vultur int xtr_irq;
3535ccd66e0SHoratiu Vultur int ana_irq;
354e85a96e4SHoratiu Vultur int ptp_irq;
355c8349639SHoratiu Vultur int fdma_irq;
356f3d8e0a9SHoratiu Vultur int ptp_ext_irq;
357811ba277SHoratiu Vultur
358811ba277SHoratiu Vultur /* worqueue for fdb */
359811ba277SHoratiu Vultur struct workqueue_struct *fdb_work;
360811ba277SHoratiu Vultur struct list_head fdb_entries;
3617aacb894SHoratiu Vultur
3627aacb894SHoratiu Vultur /* mdb */
3637aacb894SHoratiu Vultur struct list_head mdb_entries;
3647aacb894SHoratiu Vultur struct list_head pgid_entries;
365d0964594SHoratiu Vultur
366d0964594SHoratiu Vultur /* ptp */
367d0964594SHoratiu Vultur bool ptp;
368d0964594SHoratiu Vultur struct lan966x_phc phc[LAN966X_PHC_COUNT];
369d0964594SHoratiu Vultur spinlock_t ptp_clock_lock; /* lock for phc */
37077eecf25SHoratiu Vultur spinlock_t ptp_ts_id_lock; /* lock for ts_id */
371735fec99SHoratiu Vultur struct mutex ptp_lock; /* lock for ptp interface state */
37277eecf25SHoratiu Vultur u16 ptp_skbs;
373c8349639SHoratiu Vultur
374c8349639SHoratiu Vultur /* fdma */
375c8349639SHoratiu Vultur bool fdma;
376c8349639SHoratiu Vultur struct net_device *fdma_ndev;
377c8349639SHoratiu Vultur struct lan966x_rx rx;
378c8349639SHoratiu Vultur struct lan966x_tx tx;
379c8349639SHoratiu Vultur struct napi_struct napi;
380b69e9539SHoratiu Vultur
381b69e9539SHoratiu Vultur /* Mirror */
382b69e9539SHoratiu Vultur struct lan966x_port *mirror_monitor;
383b69e9539SHoratiu Vultur u32 mirror_mask[2];
384b69e9539SHoratiu Vultur u32 mirror_count;
385b0531225SHoratiu Vultur
386b0531225SHoratiu Vultur /* vcap */
387b0531225SHoratiu Vultur struct vcap_control *vcap_ctrl;
38894281484SHoratiu Vultur
38994281484SHoratiu Vultur /* debugfs */
39094281484SHoratiu Vultur struct dentry *debugfs_root;
391d28d6d2eSHoratiu Vultur };
392d28d6d2eSHoratiu Vultur
393d28d6d2eSHoratiu Vultur struct lan966x_port_config {
394d28d6d2eSHoratiu Vultur phy_interface_t portmode;
395d28d6d2eSHoratiu Vultur const unsigned long *advertising;
396d28d6d2eSHoratiu Vultur int speed;
397d28d6d2eSHoratiu Vultur int duplex;
398d28d6d2eSHoratiu Vultur u32 pause;
399d28d6d2eSHoratiu Vultur bool inband;
400d28d6d2eSHoratiu Vultur bool autoneg;
401db8bcaadSHoratiu Vultur };
402db8bcaadSHoratiu Vultur
4035390334bSHoratiu Vultur struct lan966x_port_tc {
4045390334bSHoratiu Vultur bool ingress_shared_block;
4055390334bSHoratiu Vultur unsigned long police_id;
406b69e9539SHoratiu Vultur unsigned long ingress_mirror_id;
407b69e9539SHoratiu Vultur unsigned long egress_mirror_id;
4085390334bSHoratiu Vultur struct flow_stats police_stat;
409b69e9539SHoratiu Vultur struct flow_stats mirror_stat;
4105390334bSHoratiu Vultur };
4115390334bSHoratiu Vultur
412a83e4630SHoratiu Vultur struct lan966x_port_qos_pcp {
413a83e4630SHoratiu Vultur u8 map[LAN966X_PORT_QOS_PCP_DEI_COUNT];
414a83e4630SHoratiu Vultur bool enable;
415a83e4630SHoratiu Vultur };
416a83e4630SHoratiu Vultur
4170c88d981SHoratiu Vultur struct lan966x_port_qos_dscp {
4180c88d981SHoratiu Vultur u8 map[LAN966X_PORT_QOS_DSCP_COUNT];
4190c88d981SHoratiu Vultur bool enable;
4200c88d981SHoratiu Vultur };
4210c88d981SHoratiu Vultur
422363f98b9SHoratiu Vultur struct lan966x_port_qos_pcp_rewr {
423363f98b9SHoratiu Vultur u16 map[NUM_PRIO_QUEUES];
424363f98b9SHoratiu Vultur bool enable;
425363f98b9SHoratiu Vultur };
426363f98b9SHoratiu Vultur
427d38ddd56SHoratiu Vultur struct lan966x_port_qos_dscp_rewr {
428d38ddd56SHoratiu Vultur u16 map[LAN966X_PORT_QOS_DSCP_COUNT];
429d38ddd56SHoratiu Vultur bool enable;
430d38ddd56SHoratiu Vultur };
431d38ddd56SHoratiu Vultur
432a83e4630SHoratiu Vultur struct lan966x_port_qos {
433a83e4630SHoratiu Vultur struct lan966x_port_qos_pcp pcp;
4340c88d981SHoratiu Vultur struct lan966x_port_qos_dscp dscp;
435363f98b9SHoratiu Vultur struct lan966x_port_qos_pcp_rewr pcp_rewr;
436d38ddd56SHoratiu Vultur struct lan966x_port_qos_dscp_rewr dscp_rewr;
437f8ba50eaSHoratiu Vultur u8 default_prio;
438a83e4630SHoratiu Vultur };
439a83e4630SHoratiu Vultur
440db8bcaadSHoratiu Vultur struct lan966x_port {
441d28d6d2eSHoratiu Vultur struct net_device *dev;
442db8bcaadSHoratiu Vultur struct lan966x *lan966x;
443db8bcaadSHoratiu Vultur
444db8bcaadSHoratiu Vultur u8 chip_port;
445db8bcaadSHoratiu Vultur u16 pvid;
4466d2c186aSHoratiu Vultur u16 vid;
4476d2c186aSHoratiu Vultur bool vlan_aware;
448d28d6d2eSHoratiu Vultur
4492e49761eSHoratiu Vultur bool learn_ena;
45047aeea0dSHoratiu Vultur bool mcast_ena;
4512e49761eSHoratiu Vultur
452d28d6d2eSHoratiu Vultur struct phylink_config phylink_config;
453d28d6d2eSHoratiu Vultur struct phylink_pcs phylink_pcs;
454d28d6d2eSHoratiu Vultur struct lan966x_port_config config;
455d28d6d2eSHoratiu Vultur struct phylink *phylink;
456d28d6d2eSHoratiu Vultur struct phy *serdes;
457d28d6d2eSHoratiu Vultur struct fwnode_handle *fwnode;
458735fec99SHoratiu Vultur
459ff89ac70SHoratiu Vultur u8 ptp_tx_cmd;
460ff89ac70SHoratiu Vultur bool ptp_rx_cmd;
46177eecf25SHoratiu Vultur u16 ts_id;
46277eecf25SHoratiu Vultur struct sk_buff_head tx_skbs;
463cabc9d49SHoratiu Vultur
464cabc9d49SHoratiu Vultur struct net_device *bond;
465cabc9d49SHoratiu Vultur bool lag_tx_active;
466cabc9d49SHoratiu Vultur enum netdev_lag_hash hash_type;
4675390334bSHoratiu Vultur
4685390334bSHoratiu Vultur struct lan966x_port_tc tc;
4696a2159beSHoratiu Vultur
4706a2159beSHoratiu Vultur struct bpf_prog *xdp_prog;
4716a2159beSHoratiu Vultur struct xdp_rxq_info xdp_rxq;
472db8bcaadSHoratiu Vultur };
473db8bcaadSHoratiu Vultur
474d28d6d2eSHoratiu Vultur extern const struct phylink_mac_ops lan966x_phylink_mac_ops;
475d28d6d2eSHoratiu Vultur extern const struct phylink_pcs_ops lan966x_phylink_pcs_ops;
47612c2d0a5SHoratiu Vultur extern const struct ethtool_ops lan966x_ethtool_ops;
477d6208adfSHoratiu Vultur extern struct notifier_block lan966x_switchdev_nb __read_mostly;
478d6208adfSHoratiu Vultur extern struct notifier_block lan966x_switchdev_blocking_nb __read_mostly;
47912c2d0a5SHoratiu Vultur
480cf2f6089SHoratiu Vultur bool lan966x_netdevice_check(const struct net_device *dev);
481cf2f6089SHoratiu Vultur
482cf2f6089SHoratiu Vultur void lan966x_register_notifier_blocks(void);
483cf2f6089SHoratiu Vultur void lan966x_unregister_notifier_blocks(void);
484cf2f6089SHoratiu Vultur
4858f2c7d9aSHoratiu Vultur bool lan966x_hw_offload(struct lan966x *lan966x, u32 port, struct sk_buff *skb);
4868f2c7d9aSHoratiu Vultur
4878f2c7d9aSHoratiu Vultur void lan966x_ifh_get_src_port(void *ifh, u64 *src_port);
4888f2c7d9aSHoratiu Vultur void lan966x_ifh_get_timestamp(void *ifh, u64 *timestamp);
48919c6f534SHoratiu Vultur void lan966x_ifh_set_bypass(void *ifh, u64 bypass);
49019c6f534SHoratiu Vultur void lan966x_ifh_set_port(void *ifh, u64 bypass);
4918f2c7d9aSHoratiu Vultur
49212c2d0a5SHoratiu Vultur void lan966x_stats_get(struct net_device *dev,
49312c2d0a5SHoratiu Vultur struct rtnl_link_stats64 *stats);
49412c2d0a5SHoratiu Vultur int lan966x_stats_init(struct lan966x *lan966x);
495d28d6d2eSHoratiu Vultur
496d28d6d2eSHoratiu Vultur void lan966x_port_config_down(struct lan966x_port *port);
497d28d6d2eSHoratiu Vultur void lan966x_port_config_up(struct lan966x_port *port);
498d28d6d2eSHoratiu Vultur void lan966x_port_status_get(struct lan966x_port *port,
499d28d6d2eSHoratiu Vultur struct phylink_link_state *state);
500d28d6d2eSHoratiu Vultur int lan966x_port_pcs_set(struct lan966x_port *port,
501d28d6d2eSHoratiu Vultur struct lan966x_port_config *config);
502d28d6d2eSHoratiu Vultur void lan966x_port_init(struct lan966x_port *port);
503d28d6d2eSHoratiu Vultur
504a83e4630SHoratiu Vultur void lan966x_port_qos_set(struct lan966x_port *port,
505a83e4630SHoratiu Vultur struct lan966x_port_qos *qos);
506d38ddd56SHoratiu Vultur void lan966x_port_qos_dscp_rewr_mode_set(struct lan966x_port *port,
507d38ddd56SHoratiu Vultur int mode);
508a83e4630SHoratiu Vultur
509fc0c3fe7SHoratiu Vultur int lan966x_mac_ip_learn(struct lan966x *lan966x,
510fc0c3fe7SHoratiu Vultur bool cpu_copy,
511fc0c3fe7SHoratiu Vultur const unsigned char mac[ETH_ALEN],
512fc0c3fe7SHoratiu Vultur unsigned int vid,
513fc0c3fe7SHoratiu Vultur enum macaccess_entry_type type);
514e18aba89SHoratiu Vultur int lan966x_mac_learn(struct lan966x *lan966x, int port,
515e18aba89SHoratiu Vultur const unsigned char mac[ETH_ALEN],
516e18aba89SHoratiu Vultur unsigned int vid,
517e18aba89SHoratiu Vultur enum macaccess_entry_type type);
518e18aba89SHoratiu Vultur int lan966x_mac_forget(struct lan966x *lan966x,
519e18aba89SHoratiu Vultur const unsigned char mac[ETH_ALEN],
520e18aba89SHoratiu Vultur unsigned int vid,
521e18aba89SHoratiu Vultur enum macaccess_entry_type type);
522e18aba89SHoratiu Vultur int lan966x_mac_cpu_learn(struct lan966x *lan966x, const char *addr, u16 vid);
523e18aba89SHoratiu Vultur int lan966x_mac_cpu_forget(struct lan966x *lan966x, const char *addr, u16 vid);
524e18aba89SHoratiu Vultur void lan966x_mac_init(struct lan966x *lan966x);
52525ee9561SHoratiu Vultur void lan966x_mac_set_ageing(struct lan966x *lan966x,
52625ee9561SHoratiu Vultur u32 ageing);
52725ee9561SHoratiu Vultur int lan966x_mac_del_entry(struct lan966x *lan966x,
52825ee9561SHoratiu Vultur const unsigned char *addr,
52925ee9561SHoratiu Vultur u16 vid);
53025ee9561SHoratiu Vultur int lan966x_mac_add_entry(struct lan966x *lan966x,
53125ee9561SHoratiu Vultur struct lan966x_port *port,
53225ee9561SHoratiu Vultur const unsigned char *addr,
53325ee9561SHoratiu Vultur u16 vid);
534e09ce977SHoratiu Vultur void lan966x_mac_lag_replace_port_entry(struct lan966x *lan966x,
535e09ce977SHoratiu Vultur struct lan966x_port *src,
536e09ce977SHoratiu Vultur struct lan966x_port *dst);
537e09ce977SHoratiu Vultur void lan966x_mac_lag_remove_port_entry(struct lan966x *lan966x,
538e09ce977SHoratiu Vultur struct lan966x_port *src);
5395ccd66e0SHoratiu Vultur void lan966x_mac_purge_entries(struct lan966x *lan966x);
5405ccd66e0SHoratiu Vultur irqreturn_t lan966x_mac_irq_handler(struct lan966x *lan966x);
541e18aba89SHoratiu Vultur
5426d2c186aSHoratiu Vultur void lan966x_vlan_init(struct lan966x *lan966x);
5436d2c186aSHoratiu Vultur void lan966x_vlan_port_apply(struct lan966x_port *port);
5446d2c186aSHoratiu Vultur bool lan966x_vlan_cpu_member_cpu_vlan_mask(struct lan966x *lan966x, u16 vid);
5456d2c186aSHoratiu Vultur void lan966x_vlan_port_set_vlan_aware(struct lan966x_port *port,
5466d2c186aSHoratiu Vultur bool vlan_aware);
5476d2c186aSHoratiu Vultur int lan966x_vlan_port_set_vid(struct lan966x_port *port,
5486d2c186aSHoratiu Vultur u16 vid,
5496d2c186aSHoratiu Vultur bool pvid,
5506d2c186aSHoratiu Vultur bool untagged);
5516d2c186aSHoratiu Vultur void lan966x_vlan_port_add_vlan(struct lan966x_port *port,
5526d2c186aSHoratiu Vultur u16 vid,
5536d2c186aSHoratiu Vultur bool pvid,
5546d2c186aSHoratiu Vultur bool untagged);
5556d2c186aSHoratiu Vultur void lan966x_vlan_port_del_vlan(struct lan966x_port *port, u16 vid);
5566d2c186aSHoratiu Vultur void lan966x_vlan_cpu_add_vlan(struct lan966x *lan966x, u16 vid);
5576d2c186aSHoratiu Vultur void lan966x_vlan_cpu_del_vlan(struct lan966x *lan966x, u16 vid);
5586d2c186aSHoratiu Vultur
559811ba277SHoratiu Vultur void lan966x_fdb_write_entries(struct lan966x *lan966x, u16 vid);
560811ba277SHoratiu Vultur void lan966x_fdb_erase_entries(struct lan966x *lan966x, u16 vid);
561811ba277SHoratiu Vultur int lan966x_fdb_init(struct lan966x *lan966x);
562811ba277SHoratiu Vultur void lan966x_fdb_deinit(struct lan966x *lan966x);
56386bac7f1SHoratiu Vultur void lan966x_fdb_flush_workqueue(struct lan966x *lan966x);
564811ba277SHoratiu Vultur int lan966x_handle_fdb(struct net_device *dev,
565811ba277SHoratiu Vultur struct net_device *orig_dev,
566811ba277SHoratiu Vultur unsigned long event, const void *ctx,
567811ba277SHoratiu Vultur const struct switchdev_notifier_fdb_info *fdb_info);
568811ba277SHoratiu Vultur
5697aacb894SHoratiu Vultur void lan966x_mdb_init(struct lan966x *lan966x);
5707aacb894SHoratiu Vultur void lan966x_mdb_deinit(struct lan966x *lan966x);
5717aacb894SHoratiu Vultur int lan966x_handle_port_mdb_add(struct lan966x_port *port,
5727aacb894SHoratiu Vultur const struct switchdev_obj *obj);
5737aacb894SHoratiu Vultur int lan966x_handle_port_mdb_del(struct lan966x_port *port,
5747aacb894SHoratiu Vultur const struct switchdev_obj *obj);
5757aacb894SHoratiu Vultur void lan966x_mdb_erase_entries(struct lan966x *lan966x, u16 vid);
5767aacb894SHoratiu Vultur void lan966x_mdb_write_entries(struct lan966x *lan966x, u16 vid);
577add2c844SHoratiu Vultur void lan966x_mdb_clear_entries(struct lan966x *lan966x);
578add2c844SHoratiu Vultur void lan966x_mdb_restore_entries(struct lan966x *lan966x);
5797aacb894SHoratiu Vultur
580d0964594SHoratiu Vultur int lan966x_ptp_init(struct lan966x *lan966x);
581d0964594SHoratiu Vultur void lan966x_ptp_deinit(struct lan966x *lan966x);
58254e1ed69SVladimir Oltean int lan966x_ptp_hwtstamp_set(struct lan966x_port *port,
58354e1ed69SVladimir Oltean struct kernel_hwtstamp_config *cfg,
58454e1ed69SVladimir Oltean struct netlink_ext_ack *extack);
58554e1ed69SVladimir Oltean void lan966x_ptp_hwtstamp_get(struct lan966x_port *port,
58654e1ed69SVladimir Oltean struct kernel_hwtstamp_config *cfg);
58777eecf25SHoratiu Vultur void lan966x_ptp_rxtstamp(struct lan966x *lan966x, struct sk_buff *skb,
588ff89ac70SHoratiu Vultur u64 src_port, u64 timestamp);
58977eecf25SHoratiu Vultur int lan966x_ptp_txtstamp_request(struct lan966x_port *port,
59077eecf25SHoratiu Vultur struct sk_buff *skb);
59177eecf25SHoratiu Vultur void lan966x_ptp_txtstamp_release(struct lan966x_port *port,
59277eecf25SHoratiu Vultur struct sk_buff *skb);
593e85a96e4SHoratiu Vultur irqreturn_t lan966x_ptp_irq_handler(int irq, void *args);
594f3d8e0a9SHoratiu Vultur irqreturn_t lan966x_ptp_ext_irq_handler(int irq, void *args);
595e462b271SHoratiu Vultur u32 lan966x_ptp_get_period_ps(void);
596e462b271SHoratiu Vultur int lan966x_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts);
59754e1ed69SVladimir Oltean int lan966x_ptp_setup_traps(struct lan966x_port *port,
59854e1ed69SVladimir Oltean struct kernel_hwtstamp_config *cfg);
59972df3489SHoratiu Vultur int lan966x_ptp_del_traps(struct lan966x_port *port);
600d0964594SHoratiu Vultur
601c8349639SHoratiu Vultur int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev);
602700f11ebSHoratiu Vultur int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, void *ptr, u32 len);
6032ea1cbacSHoratiu Vultur int lan966x_fdma_change_mtu(struct lan966x *lan966x);
604c8349639SHoratiu Vultur void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev);
605c8349639SHoratiu Vultur void lan966x_fdma_netdev_deinit(struct lan966x *lan966x, struct net_device *dev);
606c8349639SHoratiu Vultur int lan966x_fdma_init(struct lan966x *lan966x);
607c8349639SHoratiu Vultur void lan966x_fdma_deinit(struct lan966x *lan966x);
608c8349639SHoratiu Vultur irqreturn_t lan966x_fdma_irq_handler(int irq, void *args);
609560c7223SHoratiu Vultur int lan966x_fdma_reload_page_pool(struct lan966x *lan966x);
610c8349639SHoratiu Vultur
611cabc9d49SHoratiu Vultur int lan966x_lag_port_join(struct lan966x_port *port,
612cabc9d49SHoratiu Vultur struct net_device *brport_dev,
613cabc9d49SHoratiu Vultur struct net_device *bond,
614cabc9d49SHoratiu Vultur struct netlink_ext_ack *extack);
615cabc9d49SHoratiu Vultur void lan966x_lag_port_leave(struct lan966x_port *port, struct net_device *bond);
616cabc9d49SHoratiu Vultur int lan966x_lag_port_prechangeupper(struct net_device *dev,
617cabc9d49SHoratiu Vultur struct netdev_notifier_changeupper_info *info);
618cabc9d49SHoratiu Vultur int lan966x_lag_port_changelowerstate(struct net_device *dev,
619cabc9d49SHoratiu Vultur struct netdev_notifier_changelowerstate_info *info);
620cabc9d49SHoratiu Vultur int lan966x_lag_netdev_prechangeupper(struct net_device *dev,
621cabc9d49SHoratiu Vultur struct netdev_notifier_changeupper_info *info);
622cabc9d49SHoratiu Vultur int lan966x_lag_netdev_changeupper(struct net_device *dev,
623cabc9d49SHoratiu Vultur struct netdev_notifier_changeupper_info *info);
624cabc9d49SHoratiu Vultur bool lan966x_lag_first_port(struct net_device *lag, struct net_device *dev);
625cabc9d49SHoratiu Vultur u32 lan966x_lag_get_mask(struct lan966x *lan966x, struct net_device *bond);
626cabc9d49SHoratiu Vultur
627cabc9d49SHoratiu Vultur int lan966x_port_changeupper(struct net_device *dev,
628cabc9d49SHoratiu Vultur struct net_device *brport_dev,
629cabc9d49SHoratiu Vultur struct netdev_notifier_changeupper_info *info);
630cabc9d49SHoratiu Vultur int lan966x_port_prechangeupper(struct net_device *dev,
631cabc9d49SHoratiu Vultur struct net_device *brport_dev,
632cabc9d49SHoratiu Vultur struct netdev_notifier_changeupper_info *info);
633cabc9d49SHoratiu Vultur void lan966x_port_stp_state_set(struct lan966x_port *port, u8 state);
634cabc9d49SHoratiu Vultur void lan966x_port_ageing_set(struct lan966x_port *port,
635cabc9d49SHoratiu Vultur unsigned long ageing_clock_t);
636cabc9d49SHoratiu Vultur void lan966x_update_fwd_mask(struct lan966x *lan966x);
637cabc9d49SHoratiu Vultur
6383c83431fSHoratiu Vultur int lan966x_tc_setup(struct net_device *dev, enum tc_setup_type type,
6393c83431fSHoratiu Vultur void *type_data);
6403c83431fSHoratiu Vultur
6413c83431fSHoratiu Vultur int lan966x_mqprio_add(struct lan966x_port *port, u8 num_tc);
6423c83431fSHoratiu Vultur int lan966x_mqprio_del(struct lan966x_port *port);
6433c83431fSHoratiu Vultur
644e462b271SHoratiu Vultur void lan966x_taprio_init(struct lan966x *lan966x);
645e462b271SHoratiu Vultur void lan966x_taprio_deinit(struct lan966x *lan966x);
646e462b271SHoratiu Vultur int lan966x_taprio_add(struct lan966x_port *port,
647e462b271SHoratiu Vultur struct tc_taprio_qopt_offload *qopt);
648e462b271SHoratiu Vultur int lan966x_taprio_del(struct lan966x_port *port);
649e462b271SHoratiu Vultur int lan966x_taprio_speed_set(struct lan966x_port *port, int speed);
650e462b271SHoratiu Vultur
65194644b6dSHoratiu Vultur int lan966x_tbf_add(struct lan966x_port *port,
65294644b6dSHoratiu Vultur struct tc_tbf_qopt_offload *qopt);
65394644b6dSHoratiu Vultur int lan966x_tbf_del(struct lan966x_port *port,
65494644b6dSHoratiu Vultur struct tc_tbf_qopt_offload *qopt);
65594644b6dSHoratiu Vultur
65621ce14a8SHoratiu Vultur int lan966x_cbs_add(struct lan966x_port *port,
65721ce14a8SHoratiu Vultur struct tc_cbs_qopt_offload *qopt);
65821ce14a8SHoratiu Vultur int lan966x_cbs_del(struct lan966x_port *port,
65921ce14a8SHoratiu Vultur struct tc_cbs_qopt_offload *qopt);
66021ce14a8SHoratiu Vultur
66129aaf3d4SHoratiu Vultur int lan966x_ets_add(struct lan966x_port *port,
66229aaf3d4SHoratiu Vultur struct tc_ets_qopt_offload *qopt);
66329aaf3d4SHoratiu Vultur int lan966x_ets_del(struct lan966x_port *port,
66429aaf3d4SHoratiu Vultur struct tc_ets_qopt_offload *qopt);
66529aaf3d4SHoratiu Vultur
6665390334bSHoratiu Vultur int lan966x_tc_matchall(struct lan966x_port *port,
6675390334bSHoratiu Vultur struct tc_cls_matchall_offload *f,
6685390334bSHoratiu Vultur bool ingress);
6695390334bSHoratiu Vultur
6705390334bSHoratiu Vultur int lan966x_police_port_add(struct lan966x_port *port,
6715390334bSHoratiu Vultur struct flow_action *action,
6725390334bSHoratiu Vultur struct flow_action_entry *act,
6735390334bSHoratiu Vultur unsigned long police_id,
6745390334bSHoratiu Vultur bool ingress,
6755390334bSHoratiu Vultur struct netlink_ext_ack *extack);
6765390334bSHoratiu Vultur int lan966x_police_port_del(struct lan966x_port *port,
6775390334bSHoratiu Vultur unsigned long police_id,
6785390334bSHoratiu Vultur struct netlink_ext_ack *extack);
6795390334bSHoratiu Vultur void lan966x_police_port_stats(struct lan966x_port *port,
6805390334bSHoratiu Vultur struct flow_stats *stats);
6815390334bSHoratiu Vultur
682b69e9539SHoratiu Vultur int lan966x_mirror_port_add(struct lan966x_port *port,
683b69e9539SHoratiu Vultur struct flow_action_entry *action,
684b69e9539SHoratiu Vultur unsigned long mirror_id,
685b69e9539SHoratiu Vultur bool ingress,
686b69e9539SHoratiu Vultur struct netlink_ext_ack *extack);
687b69e9539SHoratiu Vultur int lan966x_mirror_port_del(struct lan966x_port *port,
688b69e9539SHoratiu Vultur bool ingress,
689b69e9539SHoratiu Vultur struct netlink_ext_ack *extack);
690b69e9539SHoratiu Vultur void lan966x_mirror_port_stats(struct lan966x_port *port,
691b69e9539SHoratiu Vultur struct flow_stats *stats,
692b69e9539SHoratiu Vultur bool ingress);
693b69e9539SHoratiu Vultur
6946a2159beSHoratiu Vultur int lan966x_xdp_port_init(struct lan966x_port *port);
6956a2159beSHoratiu Vultur void lan966x_xdp_port_deinit(struct lan966x_port *port);
6966a2159beSHoratiu Vultur int lan966x_xdp(struct net_device *dev, struct netdev_bpf *xdp);
6976a2159beSHoratiu Vultur int lan966x_xdp_run(struct lan966x_port *port,
6986a2159beSHoratiu Vultur struct page *page,
6996a2159beSHoratiu Vultur u32 data_len);
700a825b611SHoratiu Vultur int lan966x_xdp_xmit(struct net_device *dev,
701a825b611SHoratiu Vultur int n,
702a825b611SHoratiu Vultur struct xdp_frame **frames,
703a825b611SHoratiu Vultur u32 flags);
704560c7223SHoratiu Vultur bool lan966x_xdp_present(struct lan966x *lan966x);
lan966x_xdp_port_present(struct lan966x_port * port)7056a2159beSHoratiu Vultur static inline bool lan966x_xdp_port_present(struct lan966x_port *port)
7066a2159beSHoratiu Vultur {
7076a2159beSHoratiu Vultur return !!port->xdp_prog;
7086a2159beSHoratiu Vultur }
7096a2159beSHoratiu Vultur
710b0531225SHoratiu Vultur int lan966x_vcap_init(struct lan966x *lan966x);
711b0531225SHoratiu Vultur void lan966x_vcap_deinit(struct lan966x *lan966x);
71294281484SHoratiu Vultur #if defined(CONFIG_DEBUG_FS)
71394281484SHoratiu Vultur int lan966x_vcap_port_info(struct net_device *dev,
71494281484SHoratiu Vultur struct vcap_admin *admin,
71594281484SHoratiu Vultur struct vcap_output_print *out);
71694281484SHoratiu Vultur #else
lan966x_vcap_port_info(struct net_device * dev,struct vcap_admin * admin,struct vcap_output_print * out)71794281484SHoratiu Vultur static inline int lan966x_vcap_port_info(struct net_device *dev,
71894281484SHoratiu Vultur struct vcap_admin *admin,
71994281484SHoratiu Vultur struct vcap_output_print *out)
72094281484SHoratiu Vultur {
72194281484SHoratiu Vultur return 0;
72294281484SHoratiu Vultur }
72394281484SHoratiu Vultur #endif
724b0531225SHoratiu Vultur
7253643abd6SHoratiu Vultur int lan966x_tc_flower(struct lan966x_port *port,
726e7e3f514SSteen Hegelund struct flow_cls_offload *f,
727e7e3f514SSteen Hegelund bool ingress);
7283643abd6SHoratiu Vultur
72961caac2dSHoratiu Vultur int lan966x_goto_port_add(struct lan966x_port *port,
730cfd9e7b7SSteen Hegelund int from_cid, int to_cid,
73161caac2dSHoratiu Vultur unsigned long goto_id,
73261caac2dSHoratiu Vultur struct netlink_ext_ack *extack);
73361caac2dSHoratiu Vultur int lan966x_goto_port_del(struct lan966x_port *port,
73461caac2dSHoratiu Vultur unsigned long goto_id,
73561caac2dSHoratiu Vultur struct netlink_ext_ack *extack);
73661caac2dSHoratiu Vultur
737a83e4630SHoratiu Vultur #ifdef CONFIG_LAN966X_DCB
738a83e4630SHoratiu Vultur void lan966x_dcb_init(struct lan966x *lan966x);
739a83e4630SHoratiu Vultur #else
lan966x_dcb_init(struct lan966x * lan966x)740a83e4630SHoratiu Vultur static inline void lan966x_dcb_init(struct lan966x *lan966x)
741a83e4630SHoratiu Vultur {
742a83e4630SHoratiu Vultur }
743a83e4630SHoratiu Vultur #endif
744a83e4630SHoratiu Vultur
lan_addr(void __iomem * base[],int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)745db8bcaadSHoratiu Vultur static inline void __iomem *lan_addr(void __iomem *base[],
746db8bcaadSHoratiu Vultur int id, int tinst, int tcnt,
747db8bcaadSHoratiu Vultur int gbase, int ginst,
748db8bcaadSHoratiu Vultur int gcnt, int gwidth,
749db8bcaadSHoratiu Vultur int raddr, int rinst,
750db8bcaadSHoratiu Vultur int rcnt, int rwidth)
751db8bcaadSHoratiu Vultur {
752db8bcaadSHoratiu Vultur WARN_ON((tinst) >= tcnt);
753db8bcaadSHoratiu Vultur WARN_ON((ginst) >= gcnt);
754db8bcaadSHoratiu Vultur WARN_ON((rinst) >= rcnt);
755db8bcaadSHoratiu Vultur return base[id + (tinst)] +
756db8bcaadSHoratiu Vultur gbase + ((ginst) * gwidth) +
757db8bcaadSHoratiu Vultur raddr + ((rinst) * rwidth);
758db8bcaadSHoratiu Vultur }
759db8bcaadSHoratiu Vultur
lan_rd(struct lan966x * lan966x,int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)760db8bcaadSHoratiu Vultur static inline u32 lan_rd(struct lan966x *lan966x, int id, int tinst, int tcnt,
761db8bcaadSHoratiu Vultur int gbase, int ginst, int gcnt, int gwidth,
762db8bcaadSHoratiu Vultur int raddr, int rinst, int rcnt, int rwidth)
763db8bcaadSHoratiu Vultur {
764db8bcaadSHoratiu Vultur return readl(lan_addr(lan966x->regs, id, tinst, tcnt, gbase, ginst,
765db8bcaadSHoratiu Vultur gcnt, gwidth, raddr, rinst, rcnt, rwidth));
766db8bcaadSHoratiu Vultur }
767db8bcaadSHoratiu Vultur
lan_wr(u32 val,struct lan966x * lan966x,int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)768db8bcaadSHoratiu Vultur static inline void lan_wr(u32 val, struct lan966x *lan966x,
769db8bcaadSHoratiu Vultur int id, int tinst, int tcnt,
770db8bcaadSHoratiu Vultur int gbase, int ginst, int gcnt, int gwidth,
771db8bcaadSHoratiu Vultur int raddr, int rinst, int rcnt, int rwidth)
772db8bcaadSHoratiu Vultur {
773db8bcaadSHoratiu Vultur writel(val, lan_addr(lan966x->regs, id, tinst, tcnt,
774db8bcaadSHoratiu Vultur gbase, ginst, gcnt, gwidth,
775db8bcaadSHoratiu Vultur raddr, rinst, rcnt, rwidth));
776db8bcaadSHoratiu Vultur }
777db8bcaadSHoratiu Vultur
lan_rmw(u32 val,u32 mask,struct lan966x * lan966x,int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)778db8bcaadSHoratiu Vultur static inline void lan_rmw(u32 val, u32 mask, struct lan966x *lan966x,
779db8bcaadSHoratiu Vultur int id, int tinst, int tcnt,
780db8bcaadSHoratiu Vultur int gbase, int ginst, int gcnt, int gwidth,
781db8bcaadSHoratiu Vultur int raddr, int rinst, int rcnt, int rwidth)
782db8bcaadSHoratiu Vultur {
783db8bcaadSHoratiu Vultur u32 nval;
784db8bcaadSHoratiu Vultur
785db8bcaadSHoratiu Vultur nval = readl(lan_addr(lan966x->regs, id, tinst, tcnt, gbase, ginst,
786db8bcaadSHoratiu Vultur gcnt, gwidth, raddr, rinst, rcnt, rwidth));
787db8bcaadSHoratiu Vultur nval = (nval & ~mask) | (val & mask);
788db8bcaadSHoratiu Vultur writel(nval, lan_addr(lan966x->regs, id, tinst, tcnt, gbase, ginst,
789db8bcaadSHoratiu Vultur gcnt, gwidth, raddr, rinst, rcnt, rwidth));
790db8bcaadSHoratiu Vultur }
791db8bcaadSHoratiu Vultur
792db8bcaadSHoratiu Vultur #endif /* __LAN966X_MAIN_H__ */
793