1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
4 #ifndef _MLXSW_SPECTRUM_H
5 #define _MLXSW_SPECTRUM_H
7 #include <linux/types.h>
8 #include <linux/netdevice.h>
9 #include <linux/rhashtable.h>
10 #include <linux/bitops.h>
11 #include <linux/if_bridge.h>
12 #include <linux/if_vlan.h>
13 #include <linux/list.h>
14 #include <linux/dcbnl.h>
15 #include <linux/in6.h>
16 #include <linux/notifier.h>
17 #include <linux/net_namespace.h>
18 #include <net/psample.h>
19 #include <net/pkt_cls.h>
21 #include <net/vxlan.h>
22 #include <net/flow_offload.h>
26 #include "core_acl_flex_keys.h"
27 #include "core_acl_flex_actions.h"
30 #define MLXSW_SP_DEFAULT_VID (VLAN_N_VID - 1)
32 #define MLXSW_SP_FID_8021D_MAX 1024
34 #define MLXSW_SP_MID_MAX 7000
36 #define MLXSW_SP_KVD_LINEAR_SIZE 98304 /* entries */
37 #define MLXSW_SP_KVD_GRANULARITY 128
39 #define MLXSW_SP_RESOURCE_NAME_KVD "kvd"
40 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR "linear"
41 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE "hash_single"
42 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE "hash_double"
43 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES "singles"
44 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS "chunks"
45 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks"
47 #define MLXSW_SP_RESOURCE_NAME_SPAN "span_agents"
49 #define MLXSW_SP_RESOURCE_NAME_COUNTERS "counters"
50 #define MLXSW_SP_RESOURCE_NAME_COUNTERS_FLOW "flow"
51 #define MLXSW_SP_RESOURCE_NAME_COUNTERS_RIF "rif"
53 enum mlxsw_sp_resource_id {
54 MLXSW_SP_RESOURCE_KVD = 1,
55 MLXSW_SP_RESOURCE_KVD_LINEAR,
56 MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
57 MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
58 MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE,
59 MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS,
60 MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS,
61 MLXSW_SP_RESOURCE_SPAN,
62 MLXSW_SP_RESOURCE_COUNTERS,
63 MLXSW_SP_RESOURCE_COUNTERS_FLOW,
64 MLXSW_SP_RESOURCE_COUNTERS_RIF,
65 MLXSW_SP_RESOURCE_GLOBAL_POLICERS,
66 MLXSW_SP_RESOURCE_SINGLE_RATE_POLICERS,
71 struct mlxsw_sp_span_entry;
72 enum mlxsw_sp_l3proto;
73 union mlxsw_sp_l3addr;
75 struct mlxsw_sp_upper {
76 struct net_device *dev;
77 unsigned int ref_count;
80 enum mlxsw_sp_rif_type {
81 MLXSW_SP_RIF_TYPE_SUBPORT,
82 MLXSW_SP_RIF_TYPE_VLAN,
83 MLXSW_SP_RIF_TYPE_FID,
84 MLXSW_SP_RIF_TYPE_IPIP_LB, /* IP-in-IP loopback. */
85 MLXSW_SP_RIF_TYPE_MAX,
88 struct mlxsw_sp_rif_ops;
90 extern const struct mlxsw_sp_rif_ops *mlxsw_sp1_rif_ops_arr[];
91 extern const struct mlxsw_sp_rif_ops *mlxsw_sp2_rif_ops_arr[];
93 enum mlxsw_sp_fid_type {
94 MLXSW_SP_FID_TYPE_8021Q,
95 MLXSW_SP_FID_TYPE_8021D,
96 MLXSW_SP_FID_TYPE_RFID,
97 MLXSW_SP_FID_TYPE_DUMMY,
98 MLXSW_SP_FID_TYPE_MAX,
101 enum mlxsw_sp_nve_type {
102 MLXSW_SP_NVE_TYPE_VXLAN,
105 struct mlxsw_sp_mid {
106 struct list_head list;
107 unsigned char addr[ETH_ALEN];
111 unsigned long *ports_in_mid; /* bits array */
115 struct mlxsw_sp_bridge;
116 struct mlxsw_sp_router;
119 struct mlxsw_sp_counter_pool;
120 struct mlxsw_sp_fid_core;
121 struct mlxsw_sp_kvdl;
123 struct mlxsw_sp_kvdl_ops;
124 struct mlxsw_sp_mr_tcam_ops;
125 struct mlxsw_sp_acl_rulei_ops;
126 struct mlxsw_sp_acl_tcam_ops;
127 struct mlxsw_sp_nve_ops;
128 struct mlxsw_sp_sb_vals;
129 struct mlxsw_sp_port_type_speed_ops;
130 struct mlxsw_sp_ptp_state;
131 struct mlxsw_sp_ptp_ops;
132 struct mlxsw_sp_span_ops;
133 struct mlxsw_sp_qdisc_state;
135 struct mlxsw_sp_port_mapping {
142 struct mlxsw_sp_port **ports;
143 struct mlxsw_core *core;
144 const struct mlxsw_bus_info *bus_info;
145 unsigned char base_mac[ETH_ALEN];
146 const unsigned char *mac_mask;
147 struct mlxsw_sp_upper *lags;
148 struct mlxsw_sp_port_mapping **port_mapping;
149 struct mlxsw_sp_sb *sb;
150 struct mlxsw_sp_bridge *bridge;
151 struct mlxsw_sp_router *router;
152 struct mlxsw_sp_mr *mr;
153 struct mlxsw_afa *afa;
154 struct mlxsw_sp_acl *acl;
155 struct mlxsw_sp_fid_core *fid_core;
156 struct mlxsw_sp_policer_core *policer_core;
157 struct mlxsw_sp_kvdl *kvdl;
158 struct mlxsw_sp_nve *nve;
159 struct notifier_block netdevice_nb;
160 struct mlxsw_sp_ptp_clock *clock;
161 struct mlxsw_sp_ptp_state *ptp_state;
162 struct mlxsw_sp_counter_pool *counter_pool;
163 struct mlxsw_sp_span *span;
164 struct mlxsw_sp_trap *trap;
165 const struct mlxsw_fw_rev *req_rev;
166 const char *fw_filename;
167 const struct mlxsw_sp_kvdl_ops *kvdl_ops;
168 const struct mlxsw_afa_ops *afa_ops;
169 const struct mlxsw_afk_ops *afk_ops;
170 const struct mlxsw_sp_mr_tcam_ops *mr_tcam_ops;
171 const struct mlxsw_sp_acl_rulei_ops *acl_rulei_ops;
172 const struct mlxsw_sp_acl_tcam_ops *acl_tcam_ops;
173 const struct mlxsw_sp_nve_ops **nve_ops_arr;
174 const struct mlxsw_sp_rif_ops **rif_ops_arr;
175 const struct mlxsw_sp_sb_vals *sb_vals;
176 const struct mlxsw_sp_port_type_speed_ops *port_type_speed_ops;
177 const struct mlxsw_sp_ptp_ops *ptp_ops;
178 const struct mlxsw_sp_span_ops *span_ops;
179 const struct mlxsw_sp_policer_core_ops *policer_core_ops;
180 const struct mlxsw_sp_trap_ops *trap_ops;
181 const struct mlxsw_listener *listeners;
182 size_t listeners_count;
183 u32 lowest_shaper_bs;
186 struct mlxsw_sp_ptp_ops {
187 struct mlxsw_sp_ptp_clock *
188 (*clock_init)(struct mlxsw_sp *mlxsw_sp, struct device *dev);
189 void (*clock_fini)(struct mlxsw_sp_ptp_clock *clock);
191 struct mlxsw_sp_ptp_state *(*init)(struct mlxsw_sp *mlxsw_sp);
192 void (*fini)(struct mlxsw_sp_ptp_state *ptp_state);
194 /* Notify a driver that a packet that might be PTP was received. Driver
195 * is responsible for freeing the passed-in SKB.
197 void (*receive)(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
200 /* Notify a driver that a timestamped packet was transmitted. Driver
201 * is responsible for freeing the passed-in SKB.
203 void (*transmitted)(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
206 int (*hwtstamp_get)(struct mlxsw_sp_port *mlxsw_sp_port,
207 struct hwtstamp_config *config);
208 int (*hwtstamp_set)(struct mlxsw_sp_port *mlxsw_sp_port,
209 struct hwtstamp_config *config);
210 void (*shaper_work)(struct work_struct *work);
211 int (*get_ts_info)(struct mlxsw_sp *mlxsw_sp,
212 struct ethtool_ts_info *info);
213 int (*get_stats_count)(void);
214 void (*get_stats_strings)(u8 **p);
215 void (*get_stats)(struct mlxsw_sp_port *mlxsw_sp_port,
216 u64 *data, int data_index);
219 static inline struct mlxsw_sp_upper *
220 mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
222 return &mlxsw_sp->lags[lag_id];
225 struct mlxsw_sp_port_pcpu_stats {
230 struct u64_stats_sync syncp;
234 struct mlxsw_sp_port_sample {
235 struct psample_group *psample_group;
241 struct mlxsw_sp_bridge_port;
244 struct mlxsw_sp_port_vlan {
245 struct list_head list;
246 struct mlxsw_sp_port *mlxsw_sp_port;
247 struct mlxsw_sp_fid *fid;
249 struct mlxsw_sp_bridge_port *bridge_port;
250 struct list_head bridge_vlan_node;
253 /* No need an internal lock; At worse - miss a single periodic iteration */
254 struct mlxsw_sp_port_xstats {
256 u64 wred_drop[TC_MAX_QUEUE];
257 u64 tail_drop[TC_MAX_QUEUE];
258 u64 backlog[TC_MAX_QUEUE];
259 u64 tx_bytes[IEEE_8021QAZ_MAX_TCS];
260 u64 tx_packets[IEEE_8021QAZ_MAX_TCS];
263 struct mlxsw_sp_ptp_port_dir_stats {
268 struct mlxsw_sp_ptp_port_stats {
269 struct mlxsw_sp_ptp_port_dir_stats rx_gcd;
270 struct mlxsw_sp_ptp_port_dir_stats tx_gcd;
273 struct mlxsw_sp_port {
274 struct net_device *dev;
275 struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
276 struct mlxsw_sp *mlxsw_sp;
288 struct ieee_ets *ets;
289 struct ieee_maxrate *maxrate;
290 struct ieee_pfc *pfc;
291 enum mlxsw_reg_qpts_trust_state trust_state;
293 struct mlxsw_sp_port_mapping mapping; /* mapping is constant during the
294 * mlxsw_sp_port lifetime, however
295 * the same localport can have
299 #define MLXSW_HW_STATS_UPDATE_TIME HZ
300 struct rtnl_link_stats64 stats;
301 struct mlxsw_sp_port_xstats xstats;
302 struct delayed_work update_dw;
304 struct mlxsw_sp_port_sample __rcu *sample;
305 struct list_head vlans_list;
306 struct mlxsw_sp_port_vlan *default_vlan;
307 struct mlxsw_sp_qdisc_state *qdisc;
308 unsigned acl_rule_count;
309 struct mlxsw_sp_flow_block *ing_flow_block;
310 struct mlxsw_sp_flow_block *eg_flow_block;
312 struct delayed_work shaper_dw;
313 struct hwtstamp_config hwtstamp_config;
316 struct mlxsw_sp_ptp_port_stats stats;
318 u8 split_base_local_port;
320 struct delayed_work speed_update_dw;
324 struct mlxsw_sp_port_type_speed_ops {
325 void (*from_ptys_supported_port)(struct mlxsw_sp *mlxsw_sp,
327 struct ethtool_link_ksettings *cmd);
328 void (*from_ptys_link)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
329 u8 width, unsigned long *mode);
330 u32 (*from_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto);
331 void (*from_ptys_speed_duplex)(struct mlxsw_sp *mlxsw_sp,
332 bool carrier_ok, u32 ptys_eth_proto,
333 struct ethtool_link_ksettings *cmd);
334 u32 (*to_ptys_advert_link)(struct mlxsw_sp *mlxsw_sp, u8 width,
335 const struct ethtool_link_ksettings *cmd);
336 u32 (*to_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u8 width, u32 speed);
337 void (*reg_ptys_eth_pack)(struct mlxsw_sp *mlxsw_sp, char *payload,
338 u8 local_port, u32 proto_admin, bool autoneg);
339 void (*reg_ptys_eth_unpack)(struct mlxsw_sp *mlxsw_sp, char *payload,
340 u32 *p_eth_proto_cap,
341 u32 *p_eth_proto_admin,
342 u32 *p_eth_proto_oper);
345 static inline struct net_device *
346 mlxsw_sp_bridge_vxlan_dev_find(struct net_device *br_dev)
348 struct net_device *dev;
349 struct list_head *iter;
351 netdev_for_each_lower_dev(br_dev, dev, iter) {
352 if (netif_is_vxlan(dev))
359 static inline bool mlxsw_sp_bridge_has_vxlan(struct net_device *br_dev)
361 return !!mlxsw_sp_bridge_vxlan_dev_find(br_dev);
365 mlxsw_sp_vxlan_mapped_vid(const struct net_device *vxlan_dev, u16 *p_vid)
367 struct bridge_vlan_info vinfo;
371 err = br_vlan_get_pvid(vxlan_dev, &vid);
375 err = br_vlan_get_info(vxlan_dev, vid, &vinfo);
376 if (err || !(vinfo.flags & BRIDGE_VLAN_INFO_UNTAGGED))
385 mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
387 return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
390 static inline struct mlxsw_sp_port *
391 mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
393 struct mlxsw_sp_port *mlxsw_sp_port;
396 local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
398 mlxsw_sp_port = mlxsw_sp->ports[local_port];
399 return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
402 static inline struct mlxsw_sp_port_vlan *
403 mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
406 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
408 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
410 if (mlxsw_sp_port_vlan->vid == vid)
411 return mlxsw_sp_port_vlan;
418 mlxsw_sp_port_headroom_8x_adjust(const struct mlxsw_sp_port *mlxsw_sp_port,
421 /* Ports with eight lanes use two headroom buffers between which the
422 * configured headroom size is split. Therefore, multiply the calculated
423 * headroom size by two.
425 return mlxsw_sp_port->mapping.width == 8 ? 2 * size_cells : size_cells;
428 enum mlxsw_sp_flood_type {
429 MLXSW_SP_FLOOD_TYPE_UC,
430 MLXSW_SP_FLOOD_TYPE_BC,
431 MLXSW_SP_FLOOD_TYPE_MC,
434 int mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port,
435 int mtu, bool pause_en);
436 int mlxsw_sp_port_get_stats_raw(struct net_device *dev, int grp,
437 int prio, char *ppcnt_pl);
438 int mlxsw_sp_port_admin_status_set(struct mlxsw_sp_port *mlxsw_sp_port,
441 /* spectrum_buffers.c */
442 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
443 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
444 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
445 int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
446 unsigned int sb_index, u16 pool_index,
447 struct devlink_sb_pool_info *pool_info);
448 int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
449 unsigned int sb_index, u16 pool_index, u32 size,
450 enum devlink_sb_threshold_type threshold_type,
451 struct netlink_ext_ack *extack);
452 int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
453 unsigned int sb_index, u16 pool_index,
455 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
456 unsigned int sb_index, u16 pool_index,
457 u32 threshold, struct netlink_ext_ack *extack);
458 int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
459 unsigned int sb_index, u16 tc_index,
460 enum devlink_sb_pool_type pool_type,
461 u16 *p_pool_index, u32 *p_threshold);
462 int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
463 unsigned int sb_index, u16 tc_index,
464 enum devlink_sb_pool_type pool_type,
465 u16 pool_index, u32 threshold,
466 struct netlink_ext_ack *extack);
467 int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
468 unsigned int sb_index);
469 int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
470 unsigned int sb_index);
471 int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
472 unsigned int sb_index, u16 pool_index,
473 u32 *p_cur, u32 *p_max);
474 int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
475 unsigned int sb_index, u16 tc_index,
476 enum devlink_sb_pool_type pool_type,
477 u32 *p_cur, u32 *p_max);
478 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
479 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
480 u32 mlxsw_sp_sb_max_headroom_cells(const struct mlxsw_sp *mlxsw_sp);
482 extern const struct mlxsw_sp_sb_vals mlxsw_sp1_sb_vals;
483 extern const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals;
485 /* spectrum_switchdev.c */
486 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
487 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
488 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
491 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
492 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
493 struct net_device *brport_dev,
494 struct net_device *br_dev,
495 struct netlink_ext_ack *extack);
496 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
497 struct net_device *brport_dev,
498 struct net_device *br_dev);
499 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
500 const struct net_device *br_dev);
501 int mlxsw_sp_bridge_vxlan_join(struct mlxsw_sp *mlxsw_sp,
502 const struct net_device *br_dev,
503 const struct net_device *vxlan_dev, u16 vid,
504 struct netlink_ext_ack *extack);
505 void mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp,
506 const struct net_device *vxlan_dev);
507 extern struct notifier_block mlxsw_sp_switchdev_notifier;
510 void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb,
511 u8 local_port, void *priv);
512 void mlxsw_sp_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
514 void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
516 int mlxsw_sp_port_speed_get(struct mlxsw_sp_port *mlxsw_sp_port, u32 *speed);
517 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
518 enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
519 bool dwrr, u8 dwrr_weight);
520 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
521 u8 switch_prio, u8 tclass);
522 int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
523 u8 *prio_tc, bool pause_en,
524 struct ieee_pfc *my_pfc);
525 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
526 enum mlxsw_reg_qeec_hr hr, u8 index,
527 u8 next_index, u32 maxrate, u8 burst_size);
528 enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state);
529 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
531 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
532 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
534 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
535 struct mlxsw_sp_port_vlan *
536 mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
537 void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
538 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
539 u16 vid_end, bool is_member, bool untagged);
540 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
541 unsigned int counter_index, u64 *packets,
543 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
544 unsigned int *p_counter_index);
545 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
546 unsigned int counter_index);
547 bool mlxsw_sp_port_dev_check(const struct net_device *dev);
548 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
549 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
550 struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
551 void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
552 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
555 #ifdef CONFIG_MLXSW_SPECTRUM_DCB
556 int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
557 void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
559 static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
563 static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
567 /* spectrum_router.c */
568 enum mlxsw_sp_l3proto {
569 MLXSW_SP_L3_PROTO_IPV4,
570 MLXSW_SP_L3_PROTO_IPV6,
571 #define MLXSW_SP_L3_PROTO_MAX (MLXSW_SP_L3_PROTO_IPV6 + 1)
574 union mlxsw_sp_l3addr {
576 struct in6_addr addr6;
579 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp,
580 struct netlink_ext_ack *extack);
581 void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
582 int mlxsw_sp_netdevice_router_port_event(struct net_device *dev,
583 unsigned long event, void *ptr);
584 void mlxsw_sp_rif_macvlan_del(struct mlxsw_sp *mlxsw_sp,
585 const struct net_device *macvlan_dev);
586 int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
587 unsigned long event, void *ptr);
588 int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
589 unsigned long event, void *ptr);
590 int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
591 struct netdev_notifier_changeupper_info *info);
592 bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp,
593 const struct net_device *dev);
594 bool mlxsw_sp_netdev_is_ipip_ul(struct mlxsw_sp *mlxsw_sp,
595 const struct net_device *dev);
596 int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,
597 struct net_device *l3_dev,
599 struct netdev_notifier_info *info);
601 mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
602 struct net_device *l3_dev,
604 struct netdev_notifier_info *info);
606 mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
607 void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp,
608 struct net_device *dev);
609 bool mlxsw_sp_rif_exists(struct mlxsw_sp *mlxsw_sp,
610 const struct net_device *dev);
611 u16 mlxsw_sp_rif_vid(struct mlxsw_sp *mlxsw_sp, const struct net_device *dev);
612 u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp);
613 int mlxsw_sp_router_nve_promote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
614 enum mlxsw_sp_l3proto ul_proto,
615 const union mlxsw_sp_l3addr *ul_sip,
617 void mlxsw_sp_router_nve_demote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
618 enum mlxsw_sp_l3proto ul_proto,
619 const union mlxsw_sp_l3addr *ul_sip);
620 int mlxsw_sp_router_tb_id_vr_id(struct mlxsw_sp *mlxsw_sp, u32 tb_id,
622 int mlxsw_sp_router_ul_rif_get(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
624 void mlxsw_sp_router_ul_rif_put(struct mlxsw_sp *mlxsw_sp, u16 ul_rif_index);
626 /* spectrum_kvdl.c */
627 enum mlxsw_sp_kvdl_entry_type {
628 MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
629 MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
630 MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
631 MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
632 MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT,
635 static inline unsigned int
636 mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type)
639 case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ:
640 case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET:
641 case MLXSW_SP_KVDL_ENTRY_TYPE_PBS:
642 case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR:
643 case MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT:
649 struct mlxsw_sp_kvdl_ops {
651 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
652 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
653 int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv,
654 enum mlxsw_sp_kvdl_entry_type type,
655 unsigned int entry_count, u32 *p_entry_index);
656 void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv,
657 enum mlxsw_sp_kvdl_entry_type type,
658 unsigned int entry_count, int entry_index);
659 int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv,
660 enum mlxsw_sp_kvdl_entry_type type,
661 unsigned int entry_count,
662 unsigned int *p_alloc_count);
663 int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv);
666 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
667 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
668 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
669 enum mlxsw_sp_kvdl_entry_type type,
670 unsigned int entry_count, u32 *p_entry_index);
671 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
672 enum mlxsw_sp_kvdl_entry_type type,
673 unsigned int entry_count, int entry_index);
674 int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
675 enum mlxsw_sp_kvdl_entry_type type,
676 unsigned int entry_count,
677 unsigned int *p_alloc_count);
679 /* spectrum1_kvdl.c */
680 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops;
681 int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core);
683 /* spectrum2_kvdl.c */
684 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops;
686 struct mlxsw_sp_acl_rule_info {
687 unsigned int priority;
688 struct mlxsw_afk_element_values values;
689 struct mlxsw_afa_block *act_block;
691 ingress_bind_blocker:1,
692 egress_bind_blocker:1,
694 policer_index_valid:1;
695 unsigned int counter_index;
699 /* spectrum_flow.c */
700 struct mlxsw_sp_flow_block {
701 struct list_head binding_list;
703 struct list_head list;
704 unsigned int min_prio;
705 unsigned int max_prio;
707 struct mlxsw_sp_acl_ruleset *ruleset_zero;
708 struct mlxsw_sp *mlxsw_sp;
709 unsigned int rule_count;
710 unsigned int disable_count;
711 unsigned int ingress_blocker_rule_count;
712 unsigned int egress_blocker_rule_count;
713 unsigned int ingress_binding_count;
714 unsigned int egress_binding_count;
718 struct mlxsw_sp_flow_block_binding {
719 struct list_head list;
720 struct mlxsw_sp_port *mlxsw_sp_port;
724 static inline struct mlxsw_sp *
725 mlxsw_sp_flow_block_mlxsw_sp(struct mlxsw_sp_flow_block *block)
727 return block->mlxsw_sp;
730 static inline unsigned int
731 mlxsw_sp_flow_block_rule_count(const struct mlxsw_sp_flow_block *block)
733 return block ? block->rule_count : 0;
737 mlxsw_sp_flow_block_disable_inc(struct mlxsw_sp_flow_block *block)
740 block->disable_count++;
744 mlxsw_sp_flow_block_disable_dec(struct mlxsw_sp_flow_block *block)
747 block->disable_count--;
751 mlxsw_sp_flow_block_disabled(const struct mlxsw_sp_flow_block *block)
753 return block->disable_count;
757 mlxsw_sp_flow_block_is_egress_bound(const struct mlxsw_sp_flow_block *block)
759 return block->egress_binding_count;
763 mlxsw_sp_flow_block_is_ingress_bound(const struct mlxsw_sp_flow_block *block)
765 return block->ingress_binding_count;
769 mlxsw_sp_flow_block_is_mixed_bound(const struct mlxsw_sp_flow_block *block)
771 return block->ingress_binding_count && block->egress_binding_count;
774 struct mlxsw_sp_flow_block *mlxsw_sp_flow_block_create(struct mlxsw_sp *mlxsw_sp,
776 void mlxsw_sp_flow_block_destroy(struct mlxsw_sp_flow_block *block);
777 int mlxsw_sp_setup_tc_block_clsact(struct mlxsw_sp_port *mlxsw_sp_port,
778 struct flow_block_offload *f,
782 struct mlxsw_sp_acl_ruleset;
784 enum mlxsw_sp_acl_profile {
785 MLXSW_SP_ACL_PROFILE_FLOWER,
786 MLXSW_SP_ACL_PROFILE_MR,
789 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
791 int mlxsw_sp_acl_ruleset_bind(struct mlxsw_sp *mlxsw_sp,
792 struct mlxsw_sp_flow_block *block,
793 struct mlxsw_sp_flow_block_binding *binding);
794 void mlxsw_sp_acl_ruleset_unbind(struct mlxsw_sp *mlxsw_sp,
795 struct mlxsw_sp_flow_block *block,
796 struct mlxsw_sp_flow_block_binding *binding);
797 struct mlxsw_sp_acl_ruleset *
798 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
799 struct mlxsw_sp_flow_block *block, u32 chain_index,
800 enum mlxsw_sp_acl_profile profile);
801 struct mlxsw_sp_acl_ruleset *
802 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
803 struct mlxsw_sp_flow_block *block, u32 chain_index,
804 enum mlxsw_sp_acl_profile profile,
805 struct mlxsw_afk_element_usage *tmplt_elusage);
806 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
807 struct mlxsw_sp_acl_ruleset *ruleset);
808 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
809 void mlxsw_sp_acl_ruleset_prio_get(struct mlxsw_sp_acl_ruleset *ruleset,
810 unsigned int *p_min_prio,
811 unsigned int *p_max_prio);
813 struct mlxsw_sp_acl_rule_info *
814 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
815 struct mlxsw_afa_block *afa_block);
816 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
817 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
818 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
819 unsigned int priority);
820 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
821 enum mlxsw_afk_element element,
822 u32 key_value, u32 mask_value);
823 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
824 enum mlxsw_afk_element element,
825 const char *key_value,
826 const char *mask_value, unsigned int len);
827 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
828 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
830 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
831 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei,
833 const struct flow_action_cookie *fa_cookie,
834 struct netlink_ext_ack *extack);
835 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
836 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
837 struct mlxsw_sp_acl_rule_info *rulei,
838 struct mlxsw_sp_flow_block *block,
839 struct net_device *out_dev,
840 struct netlink_ext_ack *extack);
841 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
842 struct mlxsw_sp_acl_rule_info *rulei,
843 struct net_device *out_dev,
844 struct netlink_ext_ack *extack);
845 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
846 struct mlxsw_sp_acl_rule_info *rulei,
847 u32 action, u16 vid, u16 proto, u8 prio,
848 struct netlink_ext_ack *extack);
849 int mlxsw_sp_acl_rulei_act_priority(struct mlxsw_sp *mlxsw_sp,
850 struct mlxsw_sp_acl_rule_info *rulei,
851 u32 prio, struct netlink_ext_ack *extack);
852 int mlxsw_sp_acl_rulei_act_mangle(struct mlxsw_sp *mlxsw_sp,
853 struct mlxsw_sp_acl_rule_info *rulei,
854 enum flow_action_mangle_base htype,
855 u32 offset, u32 mask, u32 val,
856 struct netlink_ext_ack *extack);
857 int mlxsw_sp_acl_rulei_act_police(struct mlxsw_sp *mlxsw_sp,
858 struct mlxsw_sp_acl_rule_info *rulei,
859 u32 index, u64 rate_bytes_ps,
860 u32 burst, struct netlink_ext_ack *extack);
861 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
862 struct mlxsw_sp_acl_rule_info *rulei,
863 struct netlink_ext_ack *extack);
864 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
865 struct mlxsw_sp_acl_rule_info *rulei,
866 u16 fid, struct netlink_ext_ack *extack);
868 struct mlxsw_sp_acl_rule;
870 struct mlxsw_sp_acl_rule *
871 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
872 struct mlxsw_sp_acl_ruleset *ruleset,
873 unsigned long cookie,
874 struct mlxsw_afa_block *afa_block,
875 struct netlink_ext_ack *extack);
876 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
877 struct mlxsw_sp_acl_rule *rule);
878 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
879 struct mlxsw_sp_acl_rule *rule);
880 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
881 struct mlxsw_sp_acl_rule *rule);
882 int mlxsw_sp_acl_rule_action_replace(struct mlxsw_sp *mlxsw_sp,
883 struct mlxsw_sp_acl_rule *rule,
884 struct mlxsw_afa_block *afa_block);
885 struct mlxsw_sp_acl_rule *
886 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
887 struct mlxsw_sp_acl_ruleset *ruleset,
888 unsigned long cookie);
889 struct mlxsw_sp_acl_rule_info *
890 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
891 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
892 struct mlxsw_sp_acl_rule *rule,
893 u64 *packets, u64 *bytes, u64 *drops,
895 enum flow_action_hw_stats *used_hw_stats);
897 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
899 static inline const struct flow_action_cookie *
900 mlxsw_sp_acl_act_cookie_lookup(struct mlxsw_sp *mlxsw_sp, u32 cookie_index)
902 return mlxsw_afa_cookie_lookup(mlxsw_sp->afa, cookie_index);
905 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
906 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
907 u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp);
908 int mlxsw_sp_acl_region_rehash_intrvl_set(struct mlxsw_sp *mlxsw_sp, u32 val);
910 struct mlxsw_sp_acl_mangle_action;
912 struct mlxsw_sp_acl_rulei_ops {
913 int (*act_mangle_field)(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_rule_info *rulei,
914 struct mlxsw_sp_acl_mangle_action *mact, u32 val,
915 struct netlink_ext_ack *extack);
918 extern struct mlxsw_sp_acl_rulei_ops mlxsw_sp1_acl_rulei_ops;
919 extern struct mlxsw_sp_acl_rulei_ops mlxsw_sp2_acl_rulei_ops;
921 /* spectrum_acl_tcam.c */
922 struct mlxsw_sp_acl_tcam;
923 struct mlxsw_sp_acl_tcam_region;
925 struct mlxsw_sp_acl_tcam_ops {
926 enum mlxsw_reg_ptar_key_type key_type;
928 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv,
929 struct mlxsw_sp_acl_tcam *tcam);
930 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
931 size_t region_priv_size;
932 int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv,
934 struct mlxsw_sp_acl_tcam_region *region,
936 void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
937 int (*region_associate)(struct mlxsw_sp *mlxsw_sp,
938 struct mlxsw_sp_acl_tcam_region *region);
939 void * (*region_rehash_hints_get)(void *region_priv);
940 void (*region_rehash_hints_put)(void *hints_priv);
941 size_t chunk_priv_size;
942 void (*chunk_init)(void *region_priv, void *chunk_priv,
943 unsigned int priority);
944 void (*chunk_fini)(void *chunk_priv);
945 size_t entry_priv_size;
946 int (*entry_add)(struct mlxsw_sp *mlxsw_sp,
947 void *region_priv, void *chunk_priv,
949 struct mlxsw_sp_acl_rule_info *rulei);
950 void (*entry_del)(struct mlxsw_sp *mlxsw_sp,
951 void *region_priv, void *chunk_priv,
953 int (*entry_action_replace)(struct mlxsw_sp *mlxsw_sp,
954 void *region_priv, void *entry_priv,
955 struct mlxsw_sp_acl_rule_info *rulei);
956 int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp,
957 void *region_priv, void *entry_priv,
961 /* spectrum1_acl_tcam.c */
962 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops;
964 /* spectrum2_acl_tcam.c */
965 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops;
967 /* spectrum_acl_flex_actions.c */
968 extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops;
969 extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops;
971 /* spectrum_acl_flex_keys.c */
972 extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
973 extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;
975 /* spectrum_matchall.c */
976 enum mlxsw_sp_mall_action_type {
977 MLXSW_SP_MALL_ACTION_TYPE_MIRROR,
978 MLXSW_SP_MALL_ACTION_TYPE_SAMPLE,
979 MLXSW_SP_MALL_ACTION_TYPE_TRAP,
982 struct mlxsw_sp_mall_mirror_entry {
983 const struct net_device *to_dev;
987 struct mlxsw_sp_mall_trap_entry {
991 struct mlxsw_sp_mall_entry {
992 struct list_head list;
993 unsigned long cookie;
994 unsigned int priority;
995 enum mlxsw_sp_mall_action_type type;
998 struct mlxsw_sp_mall_mirror_entry mirror;
999 struct mlxsw_sp_mall_trap_entry trap;
1000 struct mlxsw_sp_port_sample sample;
1002 struct rcu_head rcu;
1005 int mlxsw_sp_mall_replace(struct mlxsw_sp *mlxsw_sp,
1006 struct mlxsw_sp_flow_block *block,
1007 struct tc_cls_matchall_offload *f);
1008 void mlxsw_sp_mall_destroy(struct mlxsw_sp_flow_block *block,
1009 struct tc_cls_matchall_offload *f);
1010 int mlxsw_sp_mall_port_bind(struct mlxsw_sp_flow_block *block,
1011 struct mlxsw_sp_port *mlxsw_sp_port);
1012 void mlxsw_sp_mall_port_unbind(struct mlxsw_sp_flow_block *block,
1013 struct mlxsw_sp_port *mlxsw_sp_port);
1014 int mlxsw_sp_mall_prio_get(struct mlxsw_sp_flow_block *block, u32 chain_index,
1015 unsigned int *p_min_prio, unsigned int *p_max_prio);
1017 /* spectrum_flower.c */
1018 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
1019 struct mlxsw_sp_flow_block *block,
1020 struct flow_cls_offload *f);
1021 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
1022 struct mlxsw_sp_flow_block *block,
1023 struct flow_cls_offload *f);
1024 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
1025 struct mlxsw_sp_flow_block *block,
1026 struct flow_cls_offload *f);
1027 int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
1028 struct mlxsw_sp_flow_block *block,
1029 struct flow_cls_offload *f);
1030 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
1031 struct mlxsw_sp_flow_block *block,
1032 struct flow_cls_offload *f);
1033 int mlxsw_sp_flower_prio_get(struct mlxsw_sp *mlxsw_sp,
1034 struct mlxsw_sp_flow_block *block,
1035 u32 chain_index, unsigned int *p_min_prio,
1036 unsigned int *p_max_prio);
1038 /* spectrum_qdisc.c */
1039 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
1040 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1041 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
1042 struct tc_red_qopt_offload *p);
1043 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
1044 struct tc_prio_qopt_offload *p);
1045 int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port,
1046 struct tc_ets_qopt_offload *p);
1047 int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port,
1048 struct tc_tbf_qopt_offload *p);
1049 int mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port,
1050 struct tc_fifo_qopt_offload *p);
1051 int mlxsw_sp_setup_tc_block_qevent_early_drop(struct mlxsw_sp_port *mlxsw_sp_port,
1052 struct flow_block_offload *f);
1054 /* spectrum_fid.c */
1055 bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index);
1056 bool mlxsw_sp_fid_lag_vid_valid(const struct mlxsw_sp_fid *fid);
1057 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp,
1059 int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex);
1060 int mlxsw_sp_fid_nve_type(const struct mlxsw_sp_fid *fid,
1061 enum mlxsw_sp_nve_type *p_type);
1062 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_vni(struct mlxsw_sp *mlxsw_sp,
1064 int mlxsw_sp_fid_vni(const struct mlxsw_sp_fid *fid, __be32 *vni);
1065 int mlxsw_sp_fid_nve_flood_index_set(struct mlxsw_sp_fid *fid,
1066 u32 nve_flood_index);
1067 void mlxsw_sp_fid_nve_flood_index_clear(struct mlxsw_sp_fid *fid);
1068 bool mlxsw_sp_fid_nve_flood_index_is_set(const struct mlxsw_sp_fid *fid);
1069 int mlxsw_sp_fid_vni_set(struct mlxsw_sp_fid *fid, enum mlxsw_sp_nve_type type,
1070 __be32 vni, int nve_ifindex);
1071 void mlxsw_sp_fid_vni_clear(struct mlxsw_sp_fid *fid);
1072 bool mlxsw_sp_fid_vni_is_set(const struct mlxsw_sp_fid *fid);
1073 void mlxsw_sp_fid_fdb_clear_offload(const struct mlxsw_sp_fid *fid,
1074 const struct net_device *nve_dev);
1075 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
1076 enum mlxsw_sp_flood_type packet_type, u8 local_port,
1078 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
1079 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
1080 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
1081 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
1082 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
1083 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
1084 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
1085 struct mlxsw_sp_rif *mlxsw_sp_fid_rif(const struct mlxsw_sp_fid *fid);
1086 enum mlxsw_sp_rif_type
1087 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
1088 enum mlxsw_sp_fid_type type);
1089 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
1090 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
1091 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
1093 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_lookup(struct mlxsw_sp *mlxsw_sp,
1095 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_lookup(struct mlxsw_sp *mlxsw_sp,
1097 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
1099 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
1100 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
1101 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
1102 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1103 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
1104 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
1107 enum mlxsw_sp_mr_route_prio {
1108 MLXSW_SP_MR_ROUTE_PRIO_SG,
1109 MLXSW_SP_MR_ROUTE_PRIO_STARG,
1110 MLXSW_SP_MR_ROUTE_PRIO_CATCHALL,
1111 __MLXSW_SP_MR_ROUTE_PRIO_MAX
1114 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
1116 struct mlxsw_sp_mr_route_key;
1118 struct mlxsw_sp_mr_tcam_ops {
1120 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
1121 void (*fini)(void *priv);
1122 size_t route_priv_size;
1123 int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
1125 struct mlxsw_sp_mr_route_key *key,
1126 struct mlxsw_afa_block *afa_block,
1127 enum mlxsw_sp_mr_route_prio prio);
1128 void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
1130 struct mlxsw_sp_mr_route_key *key);
1131 int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
1132 struct mlxsw_sp_mr_route_key *key,
1133 struct mlxsw_afa_block *afa_block);
1136 /* spectrum1_mr_tcam.c */
1137 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops;
1139 /* spectrum2_mr_tcam.c */
1140 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops;
1142 /* spectrum_nve.c */
1143 struct mlxsw_sp_nve_params {
1144 enum mlxsw_sp_nve_type type;
1146 const struct net_device *dev;
1149 extern const struct mlxsw_sp_nve_ops *mlxsw_sp1_nve_ops_arr[];
1150 extern const struct mlxsw_sp_nve_ops *mlxsw_sp2_nve_ops_arr[];
1152 int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip,
1153 enum mlxsw_sp_l3proto proto,
1154 union mlxsw_sp_l3addr *addr);
1155 int mlxsw_sp_nve_flood_ip_add(struct mlxsw_sp *mlxsw_sp,
1156 struct mlxsw_sp_fid *fid,
1157 enum mlxsw_sp_l3proto proto,
1158 union mlxsw_sp_l3addr *addr);
1159 void mlxsw_sp_nve_flood_ip_del(struct mlxsw_sp *mlxsw_sp,
1160 struct mlxsw_sp_fid *fid,
1161 enum mlxsw_sp_l3proto proto,
1162 union mlxsw_sp_l3addr *addr);
1163 int mlxsw_sp_nve_fid_enable(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *fid,
1164 struct mlxsw_sp_nve_params *params,
1165 struct netlink_ext_ack *extack);
1166 void mlxsw_sp_nve_fid_disable(struct mlxsw_sp *mlxsw_sp,
1167 struct mlxsw_sp_fid *fid);
1168 int mlxsw_sp_port_nve_init(struct mlxsw_sp_port *mlxsw_sp_port);
1169 void mlxsw_sp_port_nve_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1170 int mlxsw_sp_nve_init(struct mlxsw_sp *mlxsw_sp);
1171 void mlxsw_sp_nve_fini(struct mlxsw_sp *mlxsw_sp);
1173 /* spectrum_nve_vxlan.c */
1174 int mlxsw_sp_nve_inc_parsing_depth_get(struct mlxsw_sp *mlxsw_sp);
1175 void mlxsw_sp_nve_inc_parsing_depth_put(struct mlxsw_sp *mlxsw_sp);
1177 /* spectrum_trap.c */
1178 int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp);
1179 void mlxsw_sp_devlink_traps_fini(struct mlxsw_sp *mlxsw_sp);
1180 int mlxsw_sp_trap_init(struct mlxsw_core *mlxsw_core,
1181 const struct devlink_trap *trap, void *trap_ctx);
1182 void mlxsw_sp_trap_fini(struct mlxsw_core *mlxsw_core,
1183 const struct devlink_trap *trap, void *trap_ctx);
1184 int mlxsw_sp_trap_action_set(struct mlxsw_core *mlxsw_core,
1185 const struct devlink_trap *trap,
1186 enum devlink_trap_action action,
1187 struct netlink_ext_ack *extack);
1188 int mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core,
1189 const struct devlink_trap_group *group);
1190 int mlxsw_sp_trap_group_set(struct mlxsw_core *mlxsw_core,
1191 const struct devlink_trap_group *group,
1192 const struct devlink_trap_policer *policer,
1193 struct netlink_ext_ack *extack);
1195 mlxsw_sp_trap_policer_init(struct mlxsw_core *mlxsw_core,
1196 const struct devlink_trap_policer *policer);
1197 void mlxsw_sp_trap_policer_fini(struct mlxsw_core *mlxsw_core,
1198 const struct devlink_trap_policer *policer);
1200 mlxsw_sp_trap_policer_set(struct mlxsw_core *mlxsw_core,
1201 const struct devlink_trap_policer *policer,
1202 u64 rate, u64 burst, struct netlink_ext_ack *extack);
1204 mlxsw_sp_trap_policer_counter_get(struct mlxsw_core *mlxsw_core,
1205 const struct devlink_trap_policer *policer,
1207 int mlxsw_sp_trap_group_policer_hw_id_get(struct mlxsw_sp *mlxsw_sp, u16 id,
1208 bool *p_enabled, u16 *p_hw_id);
1210 static inline struct net *mlxsw_sp_net(struct mlxsw_sp *mlxsw_sp)
1212 return mlxsw_core_net(mlxsw_sp->core);
1215 /* spectrum_ethtool.c */
1216 extern const struct ethtool_ops mlxsw_sp_port_ethtool_ops;
1217 extern const struct mlxsw_sp_port_type_speed_ops mlxsw_sp1_port_type_speed_ops;
1218 extern const struct mlxsw_sp_port_type_speed_ops mlxsw_sp2_port_type_speed_ops;
1220 /* spectrum_policer.c */
1221 extern const struct mlxsw_sp_policer_core_ops mlxsw_sp1_policer_core_ops;
1222 extern const struct mlxsw_sp_policer_core_ops mlxsw_sp2_policer_core_ops;
1224 enum mlxsw_sp_policer_type {
1225 MLXSW_SP_POLICER_TYPE_SINGLE_RATE,
1227 __MLXSW_SP_POLICER_TYPE_MAX,
1228 MLXSW_SP_POLICER_TYPE_MAX = __MLXSW_SP_POLICER_TYPE_MAX - 1,
1231 struct mlxsw_sp_policer_params {
1237 int mlxsw_sp_policer_add(struct mlxsw_sp *mlxsw_sp,
1238 enum mlxsw_sp_policer_type type,
1239 const struct mlxsw_sp_policer_params *params,
1240 struct netlink_ext_ack *extack, u16 *p_policer_index);
1241 void mlxsw_sp_policer_del(struct mlxsw_sp *mlxsw_sp,
1242 enum mlxsw_sp_policer_type type,
1244 int mlxsw_sp_policer_drops_counter_get(struct mlxsw_sp *mlxsw_sp,
1245 enum mlxsw_sp_policer_type type,
1246 u16 policer_index, u64 *p_drops);
1247 int mlxsw_sp_policers_init(struct mlxsw_sp *mlxsw_sp);
1248 void mlxsw_sp_policers_fini(struct mlxsw_sp *mlxsw_sp);
1249 int mlxsw_sp_policer_resources_register(struct mlxsw_core *mlxsw_core);