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 <net/psample.h>
18 #include <net/pkt_cls.h>
20 #include <net/vxlan.h>
24 #include "core_acl_flex_keys.h"
25 #include "core_acl_flex_actions.h"
28 #define MLXSW_SP_DEFAULT_VID (VLAN_N_VID - 1)
30 #define MLXSW_SP_FID_8021D_MAX 1024
32 #define MLXSW_SP_MID_MAX 7000
34 #define MLXSW_SP_PORTS_PER_CLUSTER_MAX 4
36 #define MLXSW_SP_PORT_BASE_SPEED_25G 25000 /* Mb/s */
37 #define MLXSW_SP_PORT_BASE_SPEED_50G 50000 /* Mb/s */
39 #define MLXSW_SP_KVD_LINEAR_SIZE 98304 /* entries */
40 #define MLXSW_SP_KVD_GRANULARITY 128
42 #define MLXSW_SP_RESOURCE_NAME_KVD "kvd"
43 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR "linear"
44 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE "hash_single"
45 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE "hash_double"
46 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES "singles"
47 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS "chunks"
48 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks"
50 enum mlxsw_sp_resource_id {
51 MLXSW_SP_RESOURCE_KVD = 1,
52 MLXSW_SP_RESOURCE_KVD_LINEAR,
53 MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
54 MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
55 MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE,
56 MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS,
57 MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS,
62 struct mlxsw_sp_span_entry;
63 enum mlxsw_sp_l3proto;
64 union mlxsw_sp_l3addr;
66 struct mlxsw_sp_upper {
67 struct net_device *dev;
68 unsigned int ref_count;
71 enum mlxsw_sp_rif_type {
72 MLXSW_SP_RIF_TYPE_SUBPORT,
73 MLXSW_SP_RIF_TYPE_VLAN,
74 MLXSW_SP_RIF_TYPE_FID,
75 MLXSW_SP_RIF_TYPE_IPIP_LB, /* IP-in-IP loopback. */
76 MLXSW_SP_RIF_TYPE_MAX,
79 struct mlxsw_sp_rif_ops;
81 extern const struct mlxsw_sp_rif_ops *mlxsw_sp1_rif_ops_arr[];
82 extern const struct mlxsw_sp_rif_ops *mlxsw_sp2_rif_ops_arr[];
84 enum mlxsw_sp_fid_type {
85 MLXSW_SP_FID_TYPE_8021Q,
86 MLXSW_SP_FID_TYPE_8021D,
87 MLXSW_SP_FID_TYPE_RFID,
88 MLXSW_SP_FID_TYPE_DUMMY,
89 MLXSW_SP_FID_TYPE_MAX,
92 enum mlxsw_sp_nve_type {
93 MLXSW_SP_NVE_TYPE_VXLAN,
97 struct list_head list;
98 unsigned char addr[ETH_ALEN];
102 unsigned long *ports_in_mid; /* bits array */
105 enum mlxsw_sp_port_mall_action_type {
106 MLXSW_SP_PORT_MALL_MIRROR,
107 MLXSW_SP_PORT_MALL_SAMPLE,
110 struct mlxsw_sp_port_mall_mirror_tc_entry {
115 struct mlxsw_sp_port_mall_tc_entry {
116 struct list_head list;
117 unsigned long cookie;
118 enum mlxsw_sp_port_mall_action_type type;
120 struct mlxsw_sp_port_mall_mirror_tc_entry mirror;
125 struct mlxsw_sp_bridge;
126 struct mlxsw_sp_router;
129 struct mlxsw_sp_counter_pool;
130 struct mlxsw_sp_fid_core;
131 struct mlxsw_sp_kvdl;
133 struct mlxsw_sp_kvdl_ops;
134 struct mlxsw_sp_mr_tcam_ops;
135 struct mlxsw_sp_acl_tcam_ops;
136 struct mlxsw_sp_nve_ops;
137 struct mlxsw_sp_sb_vals;
138 struct mlxsw_sp_port_type_speed_ops;
139 struct mlxsw_sp_ptp_state;
140 struct mlxsw_sp_ptp_ops;
143 struct mlxsw_sp_port **ports;
144 struct mlxsw_core *core;
145 const struct mlxsw_bus_info *bus_info;
146 unsigned char base_mac[ETH_ALEN];
147 const unsigned char *mac_mask;
148 struct mlxsw_sp_upper *lags;
150 struct mlxsw_sp_sb *sb;
151 struct mlxsw_sp_bridge *bridge;
152 struct mlxsw_sp_router *router;
153 struct mlxsw_sp_mr *mr;
154 struct mlxsw_afa *afa;
155 struct mlxsw_sp_acl *acl;
156 struct mlxsw_sp_fid_core *fid_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;
163 struct mlxsw_sp_counter_pool *counter_pool;
165 struct mlxsw_sp_span_entry *entries;
168 const struct mlxsw_fw_rev *req_rev;
169 const char *fw_filename;
170 const struct mlxsw_sp_kvdl_ops *kvdl_ops;
171 const struct mlxsw_afa_ops *afa_ops;
172 const struct mlxsw_afk_ops *afk_ops;
173 const struct mlxsw_sp_mr_tcam_ops *mr_tcam_ops;
174 const struct mlxsw_sp_acl_tcam_ops *acl_tcam_ops;
175 const struct mlxsw_sp_nve_ops **nve_ops_arr;
176 const struct mlxsw_sp_rif_ops **rif_ops_arr;
177 const struct mlxsw_sp_sb_vals *sb_vals;
178 const struct mlxsw_sp_port_type_speed_ops *port_type_speed_ops;
179 const struct mlxsw_sp_ptp_ops *ptp_ops;
180 const struct mlxsw_listener *listeners;
181 size_t listeners_count;
184 static inline struct mlxsw_sp_upper *
185 mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
187 return &mlxsw_sp->lags[lag_id];
190 struct mlxsw_sp_port_pcpu_stats {
195 struct u64_stats_sync syncp;
199 struct mlxsw_sp_port_sample {
200 struct psample_group __rcu *psample_group;
206 struct mlxsw_sp_bridge_port;
209 struct mlxsw_sp_port_vlan {
210 struct list_head list;
211 struct mlxsw_sp_port *mlxsw_sp_port;
212 struct mlxsw_sp_fid *fid;
214 struct mlxsw_sp_bridge_port *bridge_port;
215 struct list_head bridge_vlan_node;
218 /* No need an internal lock; At worse - miss a single periodic iteration */
219 struct mlxsw_sp_port_xstats {
221 u64 wred_drop[TC_MAX_QUEUE];
222 u64 tail_drop[TC_MAX_QUEUE];
223 u64 backlog[TC_MAX_QUEUE];
224 u64 tx_bytes[IEEE_8021QAZ_MAX_TCS];
225 u64 tx_packets[IEEE_8021QAZ_MAX_TCS];
228 struct mlxsw_sp_port {
229 struct net_device *dev;
230 struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
231 struct mlxsw_sp *mlxsw_sp;
243 struct ieee_ets *ets;
244 struct ieee_maxrate *maxrate;
245 struct ieee_pfc *pfc;
246 enum mlxsw_reg_qpts_trust_state trust_state;
254 struct list_head mall_tc_list;
256 #define MLXSW_HW_STATS_UPDATE_TIME HZ
257 struct rtnl_link_stats64 stats;
258 struct mlxsw_sp_port_xstats xstats;
259 struct delayed_work update_dw;
261 struct mlxsw_sp_port_sample *sample;
262 struct list_head vlans_list;
263 struct mlxsw_sp_port_vlan *default_vlan;
264 struct mlxsw_sp_qdisc *root_qdisc;
265 struct mlxsw_sp_qdisc *tclass_qdiscs;
266 unsigned acl_rule_count;
267 struct mlxsw_sp_acl_block *ing_acl_block;
268 struct mlxsw_sp_acl_block *eg_acl_block;
270 struct delayed_work shaper_dw;
271 struct hwtstamp_config hwtstamp_config;
277 struct mlxsw_sp_port_type_speed_ops {
278 void (*from_ptys_supported_port)(struct mlxsw_sp *mlxsw_sp,
280 struct ethtool_link_ksettings *cmd);
281 void (*from_ptys_link)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
282 unsigned long *mode);
283 u32 (*from_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto);
284 void (*from_ptys_speed_duplex)(struct mlxsw_sp *mlxsw_sp,
285 bool carrier_ok, u32 ptys_eth_proto,
286 struct ethtool_link_ksettings *cmd);
287 u32 (*to_ptys_advert_link)(struct mlxsw_sp *mlxsw_sp,
288 const struct ethtool_link_ksettings *cmd);
289 u32 (*to_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u32 speed);
290 u32 (*to_ptys_upper_speed)(struct mlxsw_sp *mlxsw_sp, u32 upper_speed);
291 int (*port_speed_base)(struct mlxsw_sp *mlxsw_sp, u8 local_port,
293 void (*reg_ptys_eth_pack)(struct mlxsw_sp *mlxsw_sp, char *payload,
294 u8 local_port, u32 proto_admin, bool autoneg);
295 void (*reg_ptys_eth_unpack)(struct mlxsw_sp *mlxsw_sp, char *payload,
296 u32 *p_eth_proto_cap,
297 u32 *p_eth_proto_admin,
298 u32 *p_eth_proto_oper);
301 static inline struct net_device *
302 mlxsw_sp_bridge_vxlan_dev_find(struct net_device *br_dev)
304 struct net_device *dev;
305 struct list_head *iter;
307 netdev_for_each_lower_dev(br_dev, dev, iter) {
308 if (netif_is_vxlan(dev))
315 static inline bool mlxsw_sp_bridge_has_vxlan(struct net_device *br_dev)
317 return !!mlxsw_sp_bridge_vxlan_dev_find(br_dev);
321 mlxsw_sp_vxlan_mapped_vid(const struct net_device *vxlan_dev, u16 *p_vid)
323 struct bridge_vlan_info vinfo;
327 err = br_vlan_get_pvid(vxlan_dev, &vid);
331 err = br_vlan_get_info(vxlan_dev, vid, &vinfo);
332 if (err || !(vinfo.flags & BRIDGE_VLAN_INFO_UNTAGGED))
341 mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
343 return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
346 static inline struct mlxsw_sp_port *
347 mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
349 struct mlxsw_sp_port *mlxsw_sp_port;
352 local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
354 mlxsw_sp_port = mlxsw_sp->ports[local_port];
355 return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
358 static inline struct mlxsw_sp_port_vlan *
359 mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
362 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
364 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
366 if (mlxsw_sp_port_vlan->vid == vid)
367 return mlxsw_sp_port_vlan;
373 enum mlxsw_sp_flood_type {
374 MLXSW_SP_FLOOD_TYPE_UC,
375 MLXSW_SP_FLOOD_TYPE_BC,
376 MLXSW_SP_FLOOD_TYPE_MC,
379 /* spectrum_buffers.c */
380 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
381 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
382 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
383 int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
384 unsigned int sb_index, u16 pool_index,
385 struct devlink_sb_pool_info *pool_info);
386 int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
387 unsigned int sb_index, u16 pool_index, u32 size,
388 enum devlink_sb_threshold_type threshold_type,
389 struct netlink_ext_ack *extack);
390 int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
391 unsigned int sb_index, u16 pool_index,
393 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
394 unsigned int sb_index, u16 pool_index,
395 u32 threshold, struct netlink_ext_ack *extack);
396 int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
397 unsigned int sb_index, u16 tc_index,
398 enum devlink_sb_pool_type pool_type,
399 u16 *p_pool_index, u32 *p_threshold);
400 int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
401 unsigned int sb_index, u16 tc_index,
402 enum devlink_sb_pool_type pool_type,
403 u16 pool_index, u32 threshold,
404 struct netlink_ext_ack *extack);
405 int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
406 unsigned int sb_index);
407 int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
408 unsigned int sb_index);
409 int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
410 unsigned int sb_index, u16 pool_index,
411 u32 *p_cur, u32 *p_max);
412 int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
413 unsigned int sb_index, u16 tc_index,
414 enum devlink_sb_pool_type pool_type,
415 u32 *p_cur, u32 *p_max);
416 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
417 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
418 u32 mlxsw_sp_sb_max_headroom_cells(const struct mlxsw_sp *mlxsw_sp);
420 extern const struct mlxsw_sp_sb_vals mlxsw_sp1_sb_vals;
421 extern const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals;
423 /* spectrum_switchdev.c */
424 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
425 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
426 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
429 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
430 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
431 struct net_device *brport_dev,
432 struct net_device *br_dev,
433 struct netlink_ext_ack *extack);
434 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
435 struct net_device *brport_dev,
436 struct net_device *br_dev);
437 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
438 const struct net_device *br_dev);
439 int mlxsw_sp_bridge_vxlan_join(struct mlxsw_sp *mlxsw_sp,
440 const struct net_device *br_dev,
441 const struct net_device *vxlan_dev, u16 vid,
442 struct netlink_ext_ack *extack);
443 void mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp,
444 const struct net_device *vxlan_dev);
445 struct mlxsw_sp_fid *mlxsw_sp_bridge_fid_get(struct mlxsw_sp *mlxsw_sp,
446 const struct net_device *br_dev,
448 struct netlink_ext_ack *extack);
449 extern struct notifier_block mlxsw_sp_switchdev_notifier;
452 void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb,
453 u8 local_port, void *priv);
454 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
455 enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
456 bool dwrr, u8 dwrr_weight);
457 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
458 u8 switch_prio, u8 tclass);
459 int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
460 u8 *prio_tc, bool pause_en,
461 struct ieee_pfc *my_pfc);
462 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
463 enum mlxsw_reg_qeec_hr hr, u8 index,
464 u8 next_index, u32 maxrate);
465 enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state);
466 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
468 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
469 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
471 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
472 struct mlxsw_sp_port_vlan *
473 mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
474 void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
475 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
476 u16 vid_end, bool is_member, bool untagged);
477 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
478 unsigned int counter_index, u64 *packets,
480 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
481 unsigned int *p_counter_index);
482 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
483 unsigned int counter_index);
484 bool mlxsw_sp_port_dev_check(const struct net_device *dev);
485 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
486 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
487 struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
488 void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
489 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
492 #ifdef CONFIG_MLXSW_SPECTRUM_DCB
493 int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
494 void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
496 static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
500 static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
504 /* spectrum_router.c */
505 enum mlxsw_sp_l3proto {
506 MLXSW_SP_L3_PROTO_IPV4,
507 MLXSW_SP_L3_PROTO_IPV6,
508 #define MLXSW_SP_L3_PROTO_MAX (MLXSW_SP_L3_PROTO_IPV6 + 1)
511 union mlxsw_sp_l3addr {
513 struct in6_addr addr6;
516 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp);
517 void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
518 int mlxsw_sp_netdevice_router_port_event(struct net_device *dev,
519 unsigned long event, void *ptr);
520 void mlxsw_sp_rif_macvlan_del(struct mlxsw_sp *mlxsw_sp,
521 const struct net_device *macvlan_dev);
522 int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
523 unsigned long event, void *ptr);
524 int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
525 unsigned long event, void *ptr);
526 int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
527 struct netdev_notifier_changeupper_info *info);
528 bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp,
529 const struct net_device *dev);
530 bool mlxsw_sp_netdev_is_ipip_ul(const struct mlxsw_sp *mlxsw_sp,
531 const struct net_device *dev);
532 int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,
533 struct net_device *l3_dev,
535 struct netdev_notifier_info *info);
537 mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
538 struct net_device *l3_dev,
540 struct netdev_notifier_info *info);
542 mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
543 void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp,
544 struct net_device *dev);
545 struct mlxsw_sp_rif *mlxsw_sp_rif_find_by_dev(const struct mlxsw_sp *mlxsw_sp,
546 const struct net_device *dev);
547 u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp);
548 struct mlxsw_sp_fid *mlxsw_sp_rif_fid(const struct mlxsw_sp_rif *rif);
549 int mlxsw_sp_router_nve_promote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
550 enum mlxsw_sp_l3proto ul_proto,
551 const union mlxsw_sp_l3addr *ul_sip,
553 void mlxsw_sp_router_nve_demote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
554 enum mlxsw_sp_l3proto ul_proto,
555 const union mlxsw_sp_l3addr *ul_sip);
556 int mlxsw_sp_router_tb_id_vr_id(struct mlxsw_sp *mlxsw_sp, u32 tb_id,
558 int mlxsw_sp_router_ul_rif_get(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
560 void mlxsw_sp_router_ul_rif_put(struct mlxsw_sp *mlxsw_sp, u16 ul_rif_index);
562 /* spectrum_kvdl.c */
563 enum mlxsw_sp_kvdl_entry_type {
564 MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
565 MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
566 MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
567 MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
568 MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT,
571 static inline unsigned int
572 mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type)
575 case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ: /* fall through */
576 case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET: /* fall through */
577 case MLXSW_SP_KVDL_ENTRY_TYPE_PBS: /* fall through */
578 case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR: /* fall through */
579 case MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT: /* fall through */
585 struct mlxsw_sp_kvdl_ops {
587 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
588 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
589 int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv,
590 enum mlxsw_sp_kvdl_entry_type type,
591 unsigned int entry_count, u32 *p_entry_index);
592 void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv,
593 enum mlxsw_sp_kvdl_entry_type type,
594 unsigned int entry_count, int entry_index);
595 int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv,
596 enum mlxsw_sp_kvdl_entry_type type,
597 unsigned int entry_count,
598 unsigned int *p_alloc_count);
599 int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv);
602 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
603 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
604 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
605 enum mlxsw_sp_kvdl_entry_type type,
606 unsigned int entry_count, u32 *p_entry_index);
607 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
608 enum mlxsw_sp_kvdl_entry_type type,
609 unsigned int entry_count, int entry_index);
610 int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
611 enum mlxsw_sp_kvdl_entry_type type,
612 unsigned int entry_count,
613 unsigned int *p_alloc_count);
615 /* spectrum1_kvdl.c */
616 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops;
617 int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core);
619 /* spectrum2_kvdl.c */
620 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops;
622 struct mlxsw_sp_acl_rule_info {
623 unsigned int priority;
624 struct mlxsw_afk_element_values values;
625 struct mlxsw_afa_block *act_block;
627 unsigned int counter_index;
630 struct mlxsw_sp_acl_block;
631 struct mlxsw_sp_acl_ruleset;
634 enum mlxsw_sp_acl_profile {
635 MLXSW_SP_ACL_PROFILE_FLOWER,
636 MLXSW_SP_ACL_PROFILE_MR,
639 struct mlxsw_sp_acl_block {
640 struct list_head binding_list;
641 struct mlxsw_sp_acl_ruleset *ruleset_zero;
642 struct mlxsw_sp *mlxsw_sp;
643 unsigned int rule_count;
644 unsigned int disable_count;
648 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
649 struct mlxsw_sp *mlxsw_sp_acl_block_mlxsw_sp(struct mlxsw_sp_acl_block *block);
650 unsigned int mlxsw_sp_acl_block_rule_count(struct mlxsw_sp_acl_block *block);
651 void mlxsw_sp_acl_block_disable_inc(struct mlxsw_sp_acl_block *block);
652 void mlxsw_sp_acl_block_disable_dec(struct mlxsw_sp_acl_block *block);
653 bool mlxsw_sp_acl_block_disabled(struct mlxsw_sp_acl_block *block);
654 struct mlxsw_sp_acl_block *mlxsw_sp_acl_block_create(struct mlxsw_sp *mlxsw_sp,
656 void mlxsw_sp_acl_block_destroy(struct mlxsw_sp_acl_block *block);
657 int mlxsw_sp_acl_block_bind(struct mlxsw_sp *mlxsw_sp,
658 struct mlxsw_sp_acl_block *block,
659 struct mlxsw_sp_port *mlxsw_sp_port,
661 int mlxsw_sp_acl_block_unbind(struct mlxsw_sp *mlxsw_sp,
662 struct mlxsw_sp_acl_block *block,
663 struct mlxsw_sp_port *mlxsw_sp_port,
665 bool mlxsw_sp_acl_block_is_egress_bound(struct mlxsw_sp_acl_block *block);
666 struct mlxsw_sp_acl_ruleset *
667 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
668 struct mlxsw_sp_acl_block *block, u32 chain_index,
669 enum mlxsw_sp_acl_profile profile);
670 struct mlxsw_sp_acl_ruleset *
671 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
672 struct mlxsw_sp_acl_block *block, u32 chain_index,
673 enum mlxsw_sp_acl_profile profile,
674 struct mlxsw_afk_element_usage *tmplt_elusage);
675 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
676 struct mlxsw_sp_acl_ruleset *ruleset);
677 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
679 struct mlxsw_sp_acl_rule_info *
680 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
681 struct mlxsw_afa_block *afa_block);
682 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
683 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
684 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
685 unsigned int priority);
686 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
687 enum mlxsw_afk_element element,
688 u32 key_value, u32 mask_value);
689 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
690 enum mlxsw_afk_element element,
691 const char *key_value,
692 const char *mask_value, unsigned int len);
693 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
694 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
696 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
697 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei);
698 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
699 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
700 struct mlxsw_sp_acl_rule_info *rulei,
701 struct mlxsw_sp_acl_block *block,
702 struct net_device *out_dev,
703 struct netlink_ext_ack *extack);
704 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
705 struct mlxsw_sp_acl_rule_info *rulei,
706 struct net_device *out_dev,
707 struct netlink_ext_ack *extack);
708 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
709 struct mlxsw_sp_acl_rule_info *rulei,
710 u32 action, u16 vid, u16 proto, u8 prio,
711 struct netlink_ext_ack *extack);
712 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
713 struct mlxsw_sp_acl_rule_info *rulei,
714 struct netlink_ext_ack *extack);
715 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
716 struct mlxsw_sp_acl_rule_info *rulei,
717 u16 fid, struct netlink_ext_ack *extack);
719 struct mlxsw_sp_acl_rule;
721 struct mlxsw_sp_acl_rule *
722 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
723 struct mlxsw_sp_acl_ruleset *ruleset,
724 unsigned long cookie,
725 struct mlxsw_afa_block *afa_block,
726 struct netlink_ext_ack *extack);
727 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
728 struct mlxsw_sp_acl_rule *rule);
729 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
730 struct mlxsw_sp_acl_rule *rule);
731 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
732 struct mlxsw_sp_acl_rule *rule);
733 int mlxsw_sp_acl_rule_action_replace(struct mlxsw_sp *mlxsw_sp,
734 struct mlxsw_sp_acl_rule *rule,
735 struct mlxsw_afa_block *afa_block);
736 struct mlxsw_sp_acl_rule *
737 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
738 struct mlxsw_sp_acl_ruleset *ruleset,
739 unsigned long cookie);
740 struct mlxsw_sp_acl_rule_info *
741 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
742 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
743 struct mlxsw_sp_acl_rule *rule,
744 u64 *packets, u64 *bytes, u64 *last_use);
746 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
748 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
749 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
750 u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp);
751 int mlxsw_sp_acl_region_rehash_intrvl_set(struct mlxsw_sp *mlxsw_sp, u32 val);
753 /* spectrum_acl_tcam.c */
754 struct mlxsw_sp_acl_tcam;
755 struct mlxsw_sp_acl_tcam_region;
757 struct mlxsw_sp_acl_tcam_ops {
758 enum mlxsw_reg_ptar_key_type key_type;
760 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv,
761 struct mlxsw_sp_acl_tcam *tcam);
762 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
763 size_t region_priv_size;
764 int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv,
766 struct mlxsw_sp_acl_tcam_region *region,
768 void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
769 int (*region_associate)(struct mlxsw_sp *mlxsw_sp,
770 struct mlxsw_sp_acl_tcam_region *region);
771 void * (*region_rehash_hints_get)(void *region_priv);
772 void (*region_rehash_hints_put)(void *hints_priv);
773 size_t chunk_priv_size;
774 void (*chunk_init)(void *region_priv, void *chunk_priv,
775 unsigned int priority);
776 void (*chunk_fini)(void *chunk_priv);
777 size_t entry_priv_size;
778 int (*entry_add)(struct mlxsw_sp *mlxsw_sp,
779 void *region_priv, void *chunk_priv,
781 struct mlxsw_sp_acl_rule_info *rulei);
782 void (*entry_del)(struct mlxsw_sp *mlxsw_sp,
783 void *region_priv, void *chunk_priv,
785 int (*entry_action_replace)(struct mlxsw_sp *mlxsw_sp,
786 void *region_priv, void *entry_priv,
787 struct mlxsw_sp_acl_rule_info *rulei);
788 int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp,
789 void *region_priv, void *entry_priv,
793 /* spectrum1_acl_tcam.c */
794 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops;
796 /* spectrum2_acl_tcam.c */
797 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops;
799 /* spectrum_acl_flex_actions.c */
800 extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops;
801 extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops;
803 /* spectrum_acl_flex_keys.c */
804 extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
805 extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;
807 /* spectrum_flower.c */
808 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
809 struct mlxsw_sp_acl_block *block,
810 struct flow_cls_offload *f);
811 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
812 struct mlxsw_sp_acl_block *block,
813 struct flow_cls_offload *f);
814 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
815 struct mlxsw_sp_acl_block *block,
816 struct flow_cls_offload *f);
817 int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
818 struct mlxsw_sp_acl_block *block,
819 struct flow_cls_offload *f);
820 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
821 struct mlxsw_sp_acl_block *block,
822 struct flow_cls_offload *f);
824 /* spectrum_qdisc.c */
825 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
826 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
827 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
828 struct tc_red_qopt_offload *p);
829 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
830 struct tc_prio_qopt_offload *p);
833 bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index);
834 bool mlxsw_sp_fid_lag_vid_valid(const struct mlxsw_sp_fid *fid);
835 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp,
837 int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex);
838 int mlxsw_sp_fid_nve_type(const struct mlxsw_sp_fid *fid,
839 enum mlxsw_sp_nve_type *p_type);
840 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_vni(struct mlxsw_sp *mlxsw_sp,
842 int mlxsw_sp_fid_vni(const struct mlxsw_sp_fid *fid, __be32 *vni);
843 int mlxsw_sp_fid_nve_flood_index_set(struct mlxsw_sp_fid *fid,
844 u32 nve_flood_index);
845 void mlxsw_sp_fid_nve_flood_index_clear(struct mlxsw_sp_fid *fid);
846 bool mlxsw_sp_fid_nve_flood_index_is_set(const struct mlxsw_sp_fid *fid);
847 int mlxsw_sp_fid_vni_set(struct mlxsw_sp_fid *fid, enum mlxsw_sp_nve_type type,
848 __be32 vni, int nve_ifindex);
849 void mlxsw_sp_fid_vni_clear(struct mlxsw_sp_fid *fid);
850 bool mlxsw_sp_fid_vni_is_set(const struct mlxsw_sp_fid *fid);
851 void mlxsw_sp_fid_fdb_clear_offload(const struct mlxsw_sp_fid *fid,
852 const struct net_device *nve_dev);
853 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
854 enum mlxsw_sp_flood_type packet_type, u8 local_port,
856 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
857 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
858 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
859 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
860 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
861 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
862 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
863 struct mlxsw_sp_rif *mlxsw_sp_fid_rif(const struct mlxsw_sp_fid *fid);
864 enum mlxsw_sp_rif_type
865 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
866 enum mlxsw_sp_fid_type type);
867 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
868 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
869 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
871 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_lookup(struct mlxsw_sp *mlxsw_sp,
873 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_lookup(struct mlxsw_sp *mlxsw_sp,
875 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
877 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
878 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
879 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
880 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
881 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
882 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
885 enum mlxsw_sp_mr_route_prio {
886 MLXSW_SP_MR_ROUTE_PRIO_SG,
887 MLXSW_SP_MR_ROUTE_PRIO_STARG,
888 MLXSW_SP_MR_ROUTE_PRIO_CATCHALL,
889 __MLXSW_SP_MR_ROUTE_PRIO_MAX
892 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
894 struct mlxsw_sp_mr_route_key;
896 struct mlxsw_sp_mr_tcam_ops {
898 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
899 void (*fini)(void *priv);
900 size_t route_priv_size;
901 int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
903 struct mlxsw_sp_mr_route_key *key,
904 struct mlxsw_afa_block *afa_block,
905 enum mlxsw_sp_mr_route_prio prio);
906 void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
908 struct mlxsw_sp_mr_route_key *key);
909 int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
910 struct mlxsw_sp_mr_route_key *key,
911 struct mlxsw_afa_block *afa_block);
914 /* spectrum1_mr_tcam.c */
915 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops;
917 /* spectrum2_mr_tcam.c */
918 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops;
921 struct mlxsw_sp_nve_params {
922 enum mlxsw_sp_nve_type type;
924 const struct net_device *dev;
927 extern const struct mlxsw_sp_nve_ops *mlxsw_sp1_nve_ops_arr[];
928 extern const struct mlxsw_sp_nve_ops *mlxsw_sp2_nve_ops_arr[];
930 int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip,
931 enum mlxsw_sp_l3proto proto,
932 union mlxsw_sp_l3addr *addr);
933 int mlxsw_sp_nve_flood_ip_add(struct mlxsw_sp *mlxsw_sp,
934 struct mlxsw_sp_fid *fid,
935 enum mlxsw_sp_l3proto proto,
936 union mlxsw_sp_l3addr *addr);
937 void mlxsw_sp_nve_flood_ip_del(struct mlxsw_sp *mlxsw_sp,
938 struct mlxsw_sp_fid *fid,
939 enum mlxsw_sp_l3proto proto,
940 union mlxsw_sp_l3addr *addr);
941 u32 mlxsw_sp_nve_decap_tunnel_index_get(const struct mlxsw_sp *mlxsw_sp);
942 bool mlxsw_sp_nve_ipv4_route_is_decap(const struct mlxsw_sp *mlxsw_sp,
943 u32 tb_id, __be32 addr);
944 int mlxsw_sp_nve_fid_enable(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *fid,
945 struct mlxsw_sp_nve_params *params,
946 struct netlink_ext_ack *extack);
947 void mlxsw_sp_nve_fid_disable(struct mlxsw_sp *mlxsw_sp,
948 struct mlxsw_sp_fid *fid);
949 int mlxsw_sp_port_nve_init(struct mlxsw_sp_port *mlxsw_sp_port);
950 void mlxsw_sp_port_nve_fini(struct mlxsw_sp_port *mlxsw_sp_port);
951 int mlxsw_sp_nve_init(struct mlxsw_sp *mlxsw_sp);
952 void mlxsw_sp_nve_fini(struct mlxsw_sp *mlxsw_sp);