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