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