1 /* SPDX-License-Identifier: GPL-2.0+ */
2 
3 #ifndef __LAN966X_MAIN_H__
4 #define __LAN966X_MAIN_H__
5 
6 #include <linux/debugfs.h>
7 #include <linux/etherdevice.h>
8 #include <linux/if_vlan.h>
9 #include <linux/jiffies.h>
10 #include <linux/phy.h>
11 #include <linux/phylink.h>
12 #include <linux/ptp_clock_kernel.h>
13 #include <net/page_pool.h>
14 #include <net/pkt_cls.h>
15 #include <net/pkt_sched.h>
16 #include <net/switchdev.h>
17 
18 #include <vcap_api.h>
19 #include <vcap_api_client.h>
20 
21 #include "lan966x_regs.h"
22 #include "lan966x_ifh.h"
23 
24 #define TABLE_UPDATE_SLEEP_US		10
25 #define TABLE_UPDATE_TIMEOUT_US		100000
26 
27 #define READL_SLEEP_US			10
28 #define READL_TIMEOUT_US		100000000
29 
30 #define LAN966X_BUFFER_CELL_SZ		64
31 #define LAN966X_BUFFER_MEMORY		(160 * 1024)
32 #define LAN966X_BUFFER_MIN_SZ		60
33 
34 #define LAN966X_HW_MTU(mtu)		((mtu) + ETH_HLEN + ETH_FCS_LEN)
35 
36 #define PGID_AGGR			64
37 #define PGID_SRC			80
38 #define PGID_ENTRIES			89
39 
40 #define UNAWARE_PVID			0
41 #define HOST_PVID			4095
42 
43 /* Reserved amount for (SRC, PRIO) at index 8*SRC + PRIO */
44 #define QSYS_Q_RSRV			95
45 
46 #define NUM_PHYS_PORTS			8
47 #define CPU_PORT			8
48 #define NUM_PRIO_QUEUES			8
49 
50 /* Reserved PGIDs */
51 #define PGID_CPU			(PGID_AGGR - 6)
52 #define PGID_UC				(PGID_AGGR - 5)
53 #define PGID_BC				(PGID_AGGR - 4)
54 #define PGID_MC				(PGID_AGGR - 3)
55 #define PGID_MCIPV4			(PGID_AGGR - 2)
56 #define PGID_MCIPV6			(PGID_AGGR - 1)
57 
58 /* Non-reserved PGIDs, used for general purpose */
59 #define PGID_GP_START			(CPU_PORT + 1)
60 #define PGID_GP_END			PGID_CPU
61 
62 #define LAN966X_SPEED_NONE		0
63 #define LAN966X_SPEED_2500		1
64 #define LAN966X_SPEED_1000		1
65 #define LAN966X_SPEED_100		2
66 #define LAN966X_SPEED_10		3
67 
68 #define LAN966X_PHC_COUNT		3
69 #define LAN966X_PHC_PORT		0
70 #define LAN966X_PHC_PINS_NUM		7
71 
72 #define IFH_REW_OP_NOOP			0x0
73 #define IFH_REW_OP_ONE_STEP_PTP		0x3
74 #define IFH_REW_OP_TWO_STEP_PTP		0x4
75 
76 #define FDMA_RX_DCB_MAX_DBS		1
77 #define FDMA_TX_DCB_MAX_DBS		1
78 #define FDMA_DCB_INFO_DATAL(x)		((x) & GENMASK(15, 0))
79 
80 #define FDMA_DCB_STATUS_BLOCKL(x)	((x) & GENMASK(15, 0))
81 #define FDMA_DCB_STATUS_SOF		BIT(16)
82 #define FDMA_DCB_STATUS_EOF		BIT(17)
83 #define FDMA_DCB_STATUS_INTR		BIT(18)
84 #define FDMA_DCB_STATUS_DONE		BIT(19)
85 #define FDMA_DCB_STATUS_BLOCKO(x)	(((x) << 20) & GENMASK(31, 20))
86 #define FDMA_DCB_INVALID_DATA		0x1
87 
88 #define FDMA_XTR_CHANNEL		6
89 #define FDMA_INJ_CHANNEL		0
90 #define FDMA_DCB_MAX			512
91 
92 #define SE_IDX_QUEUE			0  /* 0-79 : Queue scheduler elements */
93 #define SE_IDX_PORT			80 /* 80-89 : Port schedular elements */
94 
95 #define LAN966X_VCAP_CID_IS1_L0 VCAP_CID_INGRESS_L0 /* IS1 lookup 0 */
96 #define LAN966X_VCAP_CID_IS1_L1 VCAP_CID_INGRESS_L1 /* IS1 lookup 1 */
97 #define LAN966X_VCAP_CID_IS1_L2 VCAP_CID_INGRESS_L2 /* IS1 lookup 2 */
98 #define LAN966X_VCAP_CID_IS1_MAX (VCAP_CID_INGRESS_L3 - 1) /* IS1 Max */
99 
100 #define LAN966X_VCAP_CID_IS2_L0 VCAP_CID_INGRESS_STAGE2_L0 /* IS2 lookup 0 */
101 #define LAN966X_VCAP_CID_IS2_L1 VCAP_CID_INGRESS_STAGE2_L1 /* IS2 lookup 1 */
102 #define LAN966X_VCAP_CID_IS2_MAX (VCAP_CID_INGRESS_STAGE2_L2 - 1) /* IS2 Max */
103 
104 /* MAC table entry types.
105  * ENTRYTYPE_NORMAL is subject to aging.
106  * ENTRYTYPE_LOCKED is not subject to aging.
107  * ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast.
108  * ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast.
109  */
110 enum macaccess_entry_type {
111 	ENTRYTYPE_NORMAL = 0,
112 	ENTRYTYPE_LOCKED,
113 	ENTRYTYPE_MACV4,
114 	ENTRYTYPE_MACV6,
115 };
116 
117 /* FDMA return action codes for checking if the frame is valid
118  * FDMA_PASS, frame is valid and can be used
119  * FDMA_ERROR, something went wrong, stop getting more frames
120  * FDMA_DROP, frame is dropped, but continue to get more frames
121  * FDMA_TX, frame is given to TX, but continue to get more frames
122  * FDMA_REDIRECT, frame is given to TX, but continue to get more frames
123  */
124 enum lan966x_fdma_action {
125 	FDMA_PASS = 0,
126 	FDMA_ERROR,
127 	FDMA_DROP,
128 	FDMA_TX,
129 	FDMA_REDIRECT,
130 };
131 
132 /* Controls how PORT_MASK is applied */
133 enum LAN966X_PORT_MASK_MODE {
134 	LAN966X_PMM_NO_ACTION,
135 	LAN966X_PMM_REPLACE,
136 	LAN966X_PMM_FORWARDING,
137 	LAN966X_PMM_REDIRECT,
138 };
139 
140 enum vcap_is2_port_sel_ipv6 {
141 	VCAP_IS2_PS_IPV6_TCPUDP_OTHER,
142 	VCAP_IS2_PS_IPV6_STD,
143 	VCAP_IS2_PS_IPV6_IP4_TCPUDP_IP4_OTHER,
144 	VCAP_IS2_PS_IPV6_MAC_ETYPE,
145 };
146 
147 enum vcap_is1_port_sel_other {
148 	VCAP_IS1_PS_OTHER_NORMAL,
149 	VCAP_IS1_PS_OTHER_7TUPLE,
150 	VCAP_IS1_PS_OTHER_DBL_VID,
151 	VCAP_IS1_PS_OTHER_DMAC_VID,
152 };
153 
154 enum vcap_is1_port_sel_ipv4 {
155 	VCAP_IS1_PS_IPV4_NORMAL,
156 	VCAP_IS1_PS_IPV4_7TUPLE,
157 	VCAP_IS1_PS_IPV4_5TUPLE_IP4,
158 	VCAP_IS1_PS_IPV4_DBL_VID,
159 	VCAP_IS1_PS_IPV4_DMAC_VID,
160 };
161 
162 enum vcap_is1_port_sel_ipv6 {
163 	VCAP_IS1_PS_IPV6_NORMAL,
164 	VCAP_IS1_PS_IPV6_7TUPLE,
165 	VCAP_IS1_PS_IPV6_5TUPLE_IP4,
166 	VCAP_IS1_PS_IPV6_NORMAL_IP6,
167 	VCAP_IS1_PS_IPV6_5TUPLE_IP6,
168 	VCAP_IS1_PS_IPV6_DBL_VID,
169 	VCAP_IS1_PS_IPV6_DMAC_VID,
170 };
171 
172 enum vcap_is1_port_sel_rt {
173 	VCAP_IS1_PS_RT_NORMAL,
174 	VCAP_IS1_PS_RT_7TUPLE,
175 	VCAP_IS1_PS_RT_DBL_VID,
176 	VCAP_IS1_PS_RT_DMAC_VID,
177 	VCAP_IS1_PS_RT_FOLLOW_OTHER = 7,
178 };
179 
180 struct lan966x_port;
181 
182 struct lan966x_db {
183 	u64 dataptr;
184 	u64 status;
185 };
186 
187 struct lan966x_rx_dcb {
188 	u64 nextptr;
189 	u64 info;
190 	struct lan966x_db db[FDMA_RX_DCB_MAX_DBS];
191 };
192 
193 struct lan966x_tx_dcb {
194 	u64 nextptr;
195 	u64 info;
196 	struct lan966x_db db[FDMA_TX_DCB_MAX_DBS];
197 };
198 
199 struct lan966x_rx {
200 	struct lan966x *lan966x;
201 
202 	/* Pointer to the array of hardware dcbs. */
203 	struct lan966x_rx_dcb *dcbs;
204 
205 	/* Pointer to the last address in the dcbs. */
206 	struct lan966x_rx_dcb *last_entry;
207 
208 	/* For each DB, there is a page */
209 	struct page *page[FDMA_DCB_MAX][FDMA_RX_DCB_MAX_DBS];
210 
211 	/* Represents the db_index, it can have a value between 0 and
212 	 * FDMA_RX_DCB_MAX_DBS, once it reaches the value of FDMA_RX_DCB_MAX_DBS
213 	 * it means that the DCB can be reused.
214 	 */
215 	int db_index;
216 
217 	/* Represents the index in the dcbs. It has a value between 0 and
218 	 * FDMA_DCB_MAX
219 	 */
220 	int dcb_index;
221 
222 	/* Represents the dma address to the dcbs array */
223 	dma_addr_t dma;
224 
225 	/* Represents the page order that is used to allocate the pages for the
226 	 * RX buffers. This value is calculated based on max MTU of the devices.
227 	 */
228 	u8 page_order;
229 
230 	/* Represents the max size frame that it can receive to the CPU. This
231 	 * includes the IFH + VLAN tags + frame + skb_shared_info
232 	 */
233 	u32 max_mtu;
234 
235 	u8 channel_id;
236 
237 	struct page_pool *page_pool;
238 };
239 
240 struct lan966x_tx_dcb_buf {
241 	dma_addr_t dma_addr;
242 	struct net_device *dev;
243 	union {
244 		struct sk_buff *skb;
245 		struct xdp_frame *xdpf;
246 		struct page *page;
247 	} data;
248 	u32 len;
249 	u32 used : 1;
250 	u32 ptp : 1;
251 	u32 use_skb : 1;
252 	u32 xdp_ndo : 1;
253 };
254 
255 struct lan966x_tx {
256 	struct lan966x *lan966x;
257 
258 	/* Pointer to the dcb list */
259 	struct lan966x_tx_dcb *dcbs;
260 	u16 last_in_use;
261 
262 	/* Represents the DMA address to the first entry of the dcb entries. */
263 	dma_addr_t dma;
264 
265 	/* Array of dcbs that are given to the HW */
266 	struct lan966x_tx_dcb_buf *dcbs_buf;
267 
268 	u8 channel_id;
269 
270 	bool activated;
271 };
272 
273 struct lan966x_stat_layout {
274 	u32 offset;
275 	char name[ETH_GSTRING_LEN];
276 };
277 
278 struct lan966x_phc {
279 	struct ptp_clock *clock;
280 	struct ptp_clock_info info;
281 	struct ptp_pin_desc pins[LAN966X_PHC_PINS_NUM];
282 	struct hwtstamp_config hwtstamp_config;
283 	struct lan966x *lan966x;
284 	u8 index;
285 };
286 
287 struct lan966x_skb_cb {
288 	u8 rew_op;
289 	u16 ts_id;
290 	unsigned long jiffies;
291 };
292 
293 #define LAN966X_PTP_TIMEOUT		msecs_to_jiffies(10)
294 #define LAN966X_SKB_CB(skb) \
295 	((struct lan966x_skb_cb *)((skb)->cb))
296 
297 struct lan966x {
298 	struct device *dev;
299 
300 	u8 num_phys_ports;
301 	struct lan966x_port **ports;
302 
303 	void __iomem *regs[NUM_TARGETS];
304 
305 	int shared_queue_sz;
306 
307 	u8 base_mac[ETH_ALEN];
308 
309 	spinlock_t tx_lock; /* lock for frame transmition */
310 
311 	struct net_device *bridge;
312 	u16 bridge_mask;
313 	u16 bridge_fwd_mask;
314 
315 	struct list_head mac_entries;
316 	spinlock_t mac_lock; /* lock for mac_entries list */
317 
318 	u16 vlan_mask[VLAN_N_VID];
319 	DECLARE_BITMAP(cpu_vlan_mask, VLAN_N_VID);
320 
321 	/* stats */
322 	const struct lan966x_stat_layout *stats_layout;
323 	u32 num_stats;
324 
325 	/* workqueue for reading stats */
326 	struct mutex stats_lock;
327 	u64 *stats;
328 	struct delayed_work stats_work;
329 	struct workqueue_struct *stats_queue;
330 
331 	/* interrupts */
332 	int xtr_irq;
333 	int ana_irq;
334 	int ptp_irq;
335 	int fdma_irq;
336 	int ptp_ext_irq;
337 
338 	/* worqueue for fdb */
339 	struct workqueue_struct *fdb_work;
340 	struct list_head fdb_entries;
341 
342 	/* mdb */
343 	struct list_head mdb_entries;
344 	struct list_head pgid_entries;
345 
346 	/* ptp */
347 	bool ptp;
348 	struct lan966x_phc phc[LAN966X_PHC_COUNT];
349 	spinlock_t ptp_clock_lock; /* lock for phc */
350 	spinlock_t ptp_ts_id_lock; /* lock for ts_id */
351 	struct mutex ptp_lock; /* lock for ptp interface state */
352 	u16 ptp_skbs;
353 
354 	/* fdma */
355 	bool fdma;
356 	struct net_device *fdma_ndev;
357 	struct lan966x_rx rx;
358 	struct lan966x_tx tx;
359 	struct napi_struct napi;
360 
361 	/* Mirror */
362 	struct lan966x_port *mirror_monitor;
363 	u32 mirror_mask[2];
364 	u32 mirror_count;
365 
366 	/* vcap */
367 	struct vcap_control *vcap_ctrl;
368 
369 	/* debugfs */
370 	struct dentry *debugfs_root;
371 };
372 
373 struct lan966x_port_config {
374 	phy_interface_t portmode;
375 	const unsigned long *advertising;
376 	int speed;
377 	int duplex;
378 	u32 pause;
379 	bool inband;
380 	bool autoneg;
381 };
382 
383 struct lan966x_port_tc {
384 	bool ingress_shared_block;
385 	unsigned long police_id;
386 	unsigned long ingress_mirror_id;
387 	unsigned long egress_mirror_id;
388 	struct flow_stats police_stat;
389 	struct flow_stats mirror_stat;
390 };
391 
392 struct lan966x_port {
393 	struct net_device *dev;
394 	struct lan966x *lan966x;
395 
396 	u8 chip_port;
397 	u16 pvid;
398 	u16 vid;
399 	bool vlan_aware;
400 
401 	bool learn_ena;
402 	bool mcast_ena;
403 
404 	struct phylink_config phylink_config;
405 	struct phylink_pcs phylink_pcs;
406 	struct lan966x_port_config config;
407 	struct phylink *phylink;
408 	struct phy *serdes;
409 	struct fwnode_handle *fwnode;
410 
411 	u8 ptp_tx_cmd;
412 	bool ptp_rx_cmd;
413 	u16 ts_id;
414 	struct sk_buff_head tx_skbs;
415 
416 	struct net_device *bond;
417 	bool lag_tx_active;
418 	enum netdev_lag_hash hash_type;
419 
420 	struct lan966x_port_tc tc;
421 
422 	struct bpf_prog *xdp_prog;
423 	struct xdp_rxq_info xdp_rxq;
424 };
425 
426 extern const struct phylink_mac_ops lan966x_phylink_mac_ops;
427 extern const struct phylink_pcs_ops lan966x_phylink_pcs_ops;
428 extern const struct ethtool_ops lan966x_ethtool_ops;
429 extern struct notifier_block lan966x_switchdev_nb __read_mostly;
430 extern struct notifier_block lan966x_switchdev_blocking_nb __read_mostly;
431 
432 bool lan966x_netdevice_check(const struct net_device *dev);
433 
434 void lan966x_register_notifier_blocks(void);
435 void lan966x_unregister_notifier_blocks(void);
436 
437 bool lan966x_hw_offload(struct lan966x *lan966x, u32 port, struct sk_buff *skb);
438 
439 void lan966x_ifh_get_src_port(void *ifh, u64 *src_port);
440 void lan966x_ifh_get_timestamp(void *ifh, u64 *timestamp);
441 void lan966x_ifh_set_bypass(void *ifh, u64 bypass);
442 void lan966x_ifh_set_port(void *ifh, u64 bypass);
443 
444 void lan966x_stats_get(struct net_device *dev,
445 		       struct rtnl_link_stats64 *stats);
446 int lan966x_stats_init(struct lan966x *lan966x);
447 
448 void lan966x_port_config_down(struct lan966x_port *port);
449 void lan966x_port_config_up(struct lan966x_port *port);
450 void lan966x_port_status_get(struct lan966x_port *port,
451 			     struct phylink_link_state *state);
452 int lan966x_port_pcs_set(struct lan966x_port *port,
453 			 struct lan966x_port_config *config);
454 void lan966x_port_init(struct lan966x_port *port);
455 
456 int lan966x_mac_ip_learn(struct lan966x *lan966x,
457 			 bool cpu_copy,
458 			 const unsigned char mac[ETH_ALEN],
459 			 unsigned int vid,
460 			 enum macaccess_entry_type type);
461 int lan966x_mac_learn(struct lan966x *lan966x, int port,
462 		      const unsigned char mac[ETH_ALEN],
463 		      unsigned int vid,
464 		      enum macaccess_entry_type type);
465 int lan966x_mac_forget(struct lan966x *lan966x,
466 		       const unsigned char mac[ETH_ALEN],
467 		       unsigned int vid,
468 		       enum macaccess_entry_type type);
469 int lan966x_mac_cpu_learn(struct lan966x *lan966x, const char *addr, u16 vid);
470 int lan966x_mac_cpu_forget(struct lan966x *lan966x, const char *addr, u16 vid);
471 void lan966x_mac_init(struct lan966x *lan966x);
472 void lan966x_mac_set_ageing(struct lan966x *lan966x,
473 			    u32 ageing);
474 int lan966x_mac_del_entry(struct lan966x *lan966x,
475 			  const unsigned char *addr,
476 			  u16 vid);
477 int lan966x_mac_add_entry(struct lan966x *lan966x,
478 			  struct lan966x_port *port,
479 			  const unsigned char *addr,
480 			  u16 vid);
481 void lan966x_mac_lag_replace_port_entry(struct lan966x *lan966x,
482 					struct lan966x_port *src,
483 					struct lan966x_port *dst);
484 void lan966x_mac_lag_remove_port_entry(struct lan966x *lan966x,
485 				       struct lan966x_port *src);
486 void lan966x_mac_purge_entries(struct lan966x *lan966x);
487 irqreturn_t lan966x_mac_irq_handler(struct lan966x *lan966x);
488 
489 void lan966x_vlan_init(struct lan966x *lan966x);
490 void lan966x_vlan_port_apply(struct lan966x_port *port);
491 bool lan966x_vlan_cpu_member_cpu_vlan_mask(struct lan966x *lan966x, u16 vid);
492 void lan966x_vlan_port_set_vlan_aware(struct lan966x_port *port,
493 				      bool vlan_aware);
494 int lan966x_vlan_port_set_vid(struct lan966x_port *port,
495 			      u16 vid,
496 			      bool pvid,
497 			      bool untagged);
498 void lan966x_vlan_port_add_vlan(struct lan966x_port *port,
499 				u16 vid,
500 				bool pvid,
501 				bool untagged);
502 void lan966x_vlan_port_del_vlan(struct lan966x_port *port, u16 vid);
503 void lan966x_vlan_cpu_add_vlan(struct lan966x *lan966x, u16 vid);
504 void lan966x_vlan_cpu_del_vlan(struct lan966x *lan966x, u16 vid);
505 
506 void lan966x_fdb_write_entries(struct lan966x *lan966x, u16 vid);
507 void lan966x_fdb_erase_entries(struct lan966x *lan966x, u16 vid);
508 int lan966x_fdb_init(struct lan966x *lan966x);
509 void lan966x_fdb_deinit(struct lan966x *lan966x);
510 void lan966x_fdb_flush_workqueue(struct lan966x *lan966x);
511 int lan966x_handle_fdb(struct net_device *dev,
512 		       struct net_device *orig_dev,
513 		       unsigned long event, const void *ctx,
514 		       const struct switchdev_notifier_fdb_info *fdb_info);
515 
516 void lan966x_mdb_init(struct lan966x *lan966x);
517 void lan966x_mdb_deinit(struct lan966x *lan966x);
518 int lan966x_handle_port_mdb_add(struct lan966x_port *port,
519 				const struct switchdev_obj *obj);
520 int lan966x_handle_port_mdb_del(struct lan966x_port *port,
521 				const struct switchdev_obj *obj);
522 void lan966x_mdb_erase_entries(struct lan966x *lan966x, u16 vid);
523 void lan966x_mdb_write_entries(struct lan966x *lan966x, u16 vid);
524 void lan966x_mdb_clear_entries(struct lan966x *lan966x);
525 void lan966x_mdb_restore_entries(struct lan966x *lan966x);
526 
527 int lan966x_ptp_init(struct lan966x *lan966x);
528 void lan966x_ptp_deinit(struct lan966x *lan966x);
529 int lan966x_ptp_hwtstamp_set(struct lan966x_port *port, struct ifreq *ifr);
530 int lan966x_ptp_hwtstamp_get(struct lan966x_port *port, struct ifreq *ifr);
531 void lan966x_ptp_rxtstamp(struct lan966x *lan966x, struct sk_buff *skb,
532 			  u64 src_port, u64 timestamp);
533 int lan966x_ptp_txtstamp_request(struct lan966x_port *port,
534 				 struct sk_buff *skb);
535 void lan966x_ptp_txtstamp_release(struct lan966x_port *port,
536 				  struct sk_buff *skb);
537 irqreturn_t lan966x_ptp_irq_handler(int irq, void *args);
538 irqreturn_t lan966x_ptp_ext_irq_handler(int irq, void *args);
539 u32 lan966x_ptp_get_period_ps(void);
540 int lan966x_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts);
541 int lan966x_ptp_setup_traps(struct lan966x_port *port, struct ifreq *ifr);
542 int lan966x_ptp_del_traps(struct lan966x_port *port);
543 
544 int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev);
545 int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, void *ptr, u32 len);
546 int lan966x_fdma_change_mtu(struct lan966x *lan966x);
547 void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev);
548 void lan966x_fdma_netdev_deinit(struct lan966x *lan966x, struct net_device *dev);
549 int lan966x_fdma_init(struct lan966x *lan966x);
550 void lan966x_fdma_deinit(struct lan966x *lan966x);
551 irqreturn_t lan966x_fdma_irq_handler(int irq, void *args);
552 int lan966x_fdma_reload_page_pool(struct lan966x *lan966x);
553 
554 int lan966x_lag_port_join(struct lan966x_port *port,
555 			  struct net_device *brport_dev,
556 			  struct net_device *bond,
557 			  struct netlink_ext_ack *extack);
558 void lan966x_lag_port_leave(struct lan966x_port *port, struct net_device *bond);
559 int lan966x_lag_port_prechangeupper(struct net_device *dev,
560 				    struct netdev_notifier_changeupper_info *info);
561 int lan966x_lag_port_changelowerstate(struct net_device *dev,
562 				      struct netdev_notifier_changelowerstate_info *info);
563 int lan966x_lag_netdev_prechangeupper(struct net_device *dev,
564 				      struct netdev_notifier_changeupper_info *info);
565 int lan966x_lag_netdev_changeupper(struct net_device *dev,
566 				   struct netdev_notifier_changeupper_info *info);
567 bool lan966x_lag_first_port(struct net_device *lag, struct net_device *dev);
568 u32 lan966x_lag_get_mask(struct lan966x *lan966x, struct net_device *bond);
569 
570 int lan966x_port_changeupper(struct net_device *dev,
571 			     struct net_device *brport_dev,
572 			     struct netdev_notifier_changeupper_info *info);
573 int lan966x_port_prechangeupper(struct net_device *dev,
574 				struct net_device *brport_dev,
575 				struct netdev_notifier_changeupper_info *info);
576 void lan966x_port_stp_state_set(struct lan966x_port *port, u8 state);
577 void lan966x_port_ageing_set(struct lan966x_port *port,
578 			     unsigned long ageing_clock_t);
579 void lan966x_update_fwd_mask(struct lan966x *lan966x);
580 
581 int lan966x_tc_setup(struct net_device *dev, enum tc_setup_type type,
582 		     void *type_data);
583 
584 int lan966x_mqprio_add(struct lan966x_port *port, u8 num_tc);
585 int lan966x_mqprio_del(struct lan966x_port *port);
586 
587 void lan966x_taprio_init(struct lan966x *lan966x);
588 void lan966x_taprio_deinit(struct lan966x *lan966x);
589 int lan966x_taprio_add(struct lan966x_port *port,
590 		       struct tc_taprio_qopt_offload *qopt);
591 int lan966x_taprio_del(struct lan966x_port *port);
592 int lan966x_taprio_speed_set(struct lan966x_port *port, int speed);
593 
594 int lan966x_tbf_add(struct lan966x_port *port,
595 		    struct tc_tbf_qopt_offload *qopt);
596 int lan966x_tbf_del(struct lan966x_port *port,
597 		    struct tc_tbf_qopt_offload *qopt);
598 
599 int lan966x_cbs_add(struct lan966x_port *port,
600 		    struct tc_cbs_qopt_offload *qopt);
601 int lan966x_cbs_del(struct lan966x_port *port,
602 		    struct tc_cbs_qopt_offload *qopt);
603 
604 int lan966x_ets_add(struct lan966x_port *port,
605 		    struct tc_ets_qopt_offload *qopt);
606 int lan966x_ets_del(struct lan966x_port *port,
607 		    struct tc_ets_qopt_offload *qopt);
608 
609 int lan966x_tc_matchall(struct lan966x_port *port,
610 			struct tc_cls_matchall_offload *f,
611 			bool ingress);
612 
613 int lan966x_police_port_add(struct lan966x_port *port,
614 			    struct flow_action *action,
615 			    struct flow_action_entry *act,
616 			    unsigned long police_id,
617 			    bool ingress,
618 			    struct netlink_ext_ack *extack);
619 int lan966x_police_port_del(struct lan966x_port *port,
620 			    unsigned long police_id,
621 			    struct netlink_ext_ack *extack);
622 void lan966x_police_port_stats(struct lan966x_port *port,
623 			       struct flow_stats *stats);
624 
625 int lan966x_mirror_port_add(struct lan966x_port *port,
626 			    struct flow_action_entry *action,
627 			    unsigned long mirror_id,
628 			    bool ingress,
629 			    struct netlink_ext_ack *extack);
630 int lan966x_mirror_port_del(struct lan966x_port *port,
631 			    bool ingress,
632 			    struct netlink_ext_ack *extack);
633 void lan966x_mirror_port_stats(struct lan966x_port *port,
634 			       struct flow_stats *stats,
635 			       bool ingress);
636 
637 int lan966x_xdp_port_init(struct lan966x_port *port);
638 void lan966x_xdp_port_deinit(struct lan966x_port *port);
639 int lan966x_xdp(struct net_device *dev, struct netdev_bpf *xdp);
640 int lan966x_xdp_run(struct lan966x_port *port,
641 		    struct page *page,
642 		    u32 data_len);
643 int lan966x_xdp_xmit(struct net_device *dev,
644 		     int n,
645 		     struct xdp_frame **frames,
646 		     u32 flags);
647 bool lan966x_xdp_present(struct lan966x *lan966x);
648 static inline bool lan966x_xdp_port_present(struct lan966x_port *port)
649 {
650 	return !!port->xdp_prog;
651 }
652 
653 int lan966x_vcap_init(struct lan966x *lan966x);
654 void lan966x_vcap_deinit(struct lan966x *lan966x);
655 #if defined(CONFIG_DEBUG_FS)
656 int lan966x_vcap_port_info(struct net_device *dev,
657 			   struct vcap_admin *admin,
658 			   struct vcap_output_print *out);
659 #else
660 static inline int lan966x_vcap_port_info(struct net_device *dev,
661 					 struct vcap_admin *admin,
662 					 struct vcap_output_print *out)
663 {
664 	return 0;
665 }
666 #endif
667 
668 int lan966x_tc_flower(struct lan966x_port *port,
669 		      struct flow_cls_offload *f,
670 		      bool ingress);
671 
672 int lan966x_goto_port_add(struct lan966x_port *port,
673 			  int from_cid, int to_cid,
674 			  unsigned long goto_id,
675 			  struct netlink_ext_ack *extack);
676 int lan966x_goto_port_del(struct lan966x_port *port,
677 			  unsigned long goto_id,
678 			  struct netlink_ext_ack *extack);
679 
680 static inline void __iomem *lan_addr(void __iomem *base[],
681 				     int id, int tinst, int tcnt,
682 				     int gbase, int ginst,
683 				     int gcnt, int gwidth,
684 				     int raddr, int rinst,
685 				     int rcnt, int rwidth)
686 {
687 	WARN_ON((tinst) >= tcnt);
688 	WARN_ON((ginst) >= gcnt);
689 	WARN_ON((rinst) >= rcnt);
690 	return base[id + (tinst)] +
691 		gbase + ((ginst) * gwidth) +
692 		raddr + ((rinst) * rwidth);
693 }
694 
695 static inline u32 lan_rd(struct lan966x *lan966x, int id, int tinst, int tcnt,
696 			 int gbase, int ginst, int gcnt, int gwidth,
697 			 int raddr, int rinst, int rcnt, int rwidth)
698 {
699 	return readl(lan_addr(lan966x->regs, id, tinst, tcnt, gbase, ginst,
700 			      gcnt, gwidth, raddr, rinst, rcnt, rwidth));
701 }
702 
703 static inline void lan_wr(u32 val, struct lan966x *lan966x,
704 			  int id, int tinst, int tcnt,
705 			  int gbase, int ginst, int gcnt, int gwidth,
706 			  int raddr, int rinst, int rcnt, int rwidth)
707 {
708 	writel(val, lan_addr(lan966x->regs, id, tinst, tcnt,
709 			     gbase, ginst, gcnt, gwidth,
710 			     raddr, rinst, rcnt, rwidth));
711 }
712 
713 static inline void lan_rmw(u32 val, u32 mask, struct lan966x *lan966x,
714 			   int id, int tinst, int tcnt,
715 			   int gbase, int ginst, int gcnt, int gwidth,
716 			   int raddr, int rinst, int rcnt, int rwidth)
717 {
718 	u32 nval;
719 
720 	nval = readl(lan_addr(lan966x->regs, id, tinst, tcnt, gbase, ginst,
721 			      gcnt, gwidth, raddr, rinst, rcnt, rwidth));
722 	nval = (nval & ~mask) | (val & mask);
723 	writel(nval, lan_addr(lan966x->regs, id, tinst, tcnt, gbase, ginst,
724 			      gcnt, gwidth, raddr, rinst, rcnt, rwidth));
725 }
726 
727 #endif /* __LAN966X_MAIN_H__ */
728