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