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