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