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