1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ 2 /* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */ 3 4 #ifndef _MLXSW_SPECTRUM_H 5 #define _MLXSW_SPECTRUM_H 6 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> 20 #include <net/red.h> 21 #include <net/vxlan.h> 22 23 #include "port.h" 24 #include "core.h" 25 #include "core_acl_flex_keys.h" 26 #include "core_acl_flex_actions.h" 27 #include "reg.h" 28 29 #define MLXSW_SP_DEFAULT_VID (VLAN_N_VID - 1) 30 31 #define MLXSW_SP_FID_8021D_MAX 1024 32 33 #define MLXSW_SP_MID_MAX 7000 34 35 #define MLXSW_SP_PORT_BASE_SPEED_25G 25000 /* Mb/s */ 36 #define MLXSW_SP_PORT_BASE_SPEED_50G 50000 /* Mb/s */ 37 38 #define MLXSW_SP_KVD_LINEAR_SIZE 98304 /* entries */ 39 #define MLXSW_SP_KVD_GRANULARITY 128 40 41 #define MLXSW_SP_RESOURCE_NAME_KVD "kvd" 42 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR "linear" 43 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE "hash_single" 44 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE "hash_double" 45 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES "singles" 46 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS "chunks" 47 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks" 48 49 #define MLXSW_SP_RESOURCE_NAME_SPAN "span_agents" 50 51 enum mlxsw_sp_resource_id { 52 MLXSW_SP_RESOURCE_KVD = 1, 53 MLXSW_SP_RESOURCE_KVD_LINEAR, 54 MLXSW_SP_RESOURCE_KVD_HASH_SINGLE, 55 MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE, 56 MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE, 57 MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS, 58 MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS, 59 MLXSW_SP_RESOURCE_SPAN, 60 }; 61 62 struct mlxsw_sp_port; 63 struct mlxsw_sp_rif; 64 struct mlxsw_sp_span_entry; 65 enum mlxsw_sp_l3proto; 66 union mlxsw_sp_l3addr; 67 68 struct mlxsw_sp_upper { 69 struct net_device *dev; 70 unsigned int ref_count; 71 }; 72 73 enum mlxsw_sp_rif_type { 74 MLXSW_SP_RIF_TYPE_SUBPORT, 75 MLXSW_SP_RIF_TYPE_VLAN, 76 MLXSW_SP_RIF_TYPE_FID, 77 MLXSW_SP_RIF_TYPE_IPIP_LB, /* IP-in-IP loopback. */ 78 MLXSW_SP_RIF_TYPE_MAX, 79 }; 80 81 struct mlxsw_sp_rif_ops; 82 83 extern const struct mlxsw_sp_rif_ops *mlxsw_sp1_rif_ops_arr[]; 84 extern const struct mlxsw_sp_rif_ops *mlxsw_sp2_rif_ops_arr[]; 85 86 enum mlxsw_sp_fid_type { 87 MLXSW_SP_FID_TYPE_8021Q, 88 MLXSW_SP_FID_TYPE_8021D, 89 MLXSW_SP_FID_TYPE_RFID, 90 MLXSW_SP_FID_TYPE_DUMMY, 91 MLXSW_SP_FID_TYPE_MAX, 92 }; 93 94 enum mlxsw_sp_nve_type { 95 MLXSW_SP_NVE_TYPE_VXLAN, 96 }; 97 98 struct mlxsw_sp_mid { 99 struct list_head list; 100 unsigned char addr[ETH_ALEN]; 101 u16 fid; 102 u16 mid; 103 bool in_hw; 104 unsigned long *ports_in_mid; /* bits array */ 105 }; 106 107 enum mlxsw_sp_port_mall_action_type { 108 MLXSW_SP_PORT_MALL_MIRROR, 109 MLXSW_SP_PORT_MALL_SAMPLE, 110 }; 111 112 struct mlxsw_sp_port_mall_mirror_tc_entry { 113 int span_id; 114 bool ingress; 115 }; 116 117 struct mlxsw_sp_port_mall_tc_entry { 118 struct list_head list; 119 unsigned long cookie; 120 enum mlxsw_sp_port_mall_action_type type; 121 union { 122 struct mlxsw_sp_port_mall_mirror_tc_entry mirror; 123 }; 124 }; 125 126 struct mlxsw_sp_sb; 127 struct mlxsw_sp_bridge; 128 struct mlxsw_sp_router; 129 struct mlxsw_sp_mr; 130 struct mlxsw_sp_acl; 131 struct mlxsw_sp_counter_pool; 132 struct mlxsw_sp_fid_core; 133 struct mlxsw_sp_kvdl; 134 struct mlxsw_sp_nve; 135 struct mlxsw_sp_kvdl_ops; 136 struct mlxsw_sp_mr_tcam_ops; 137 struct mlxsw_sp_acl_tcam_ops; 138 struct mlxsw_sp_nve_ops; 139 struct mlxsw_sp_sb_vals; 140 struct mlxsw_sp_port_type_speed_ops; 141 struct mlxsw_sp_ptp_state; 142 struct mlxsw_sp_ptp_ops; 143 144 struct mlxsw_sp_port_mapping { 145 u8 module; 146 u8 width; 147 u8 lane; 148 }; 149 150 struct mlxsw_sp { 151 struct mlxsw_sp_port **ports; 152 struct mlxsw_core *core; 153 const struct mlxsw_bus_info *bus_info; 154 unsigned char base_mac[ETH_ALEN]; 155 const unsigned char *mac_mask; 156 struct mlxsw_sp_upper *lags; 157 struct mlxsw_sp_port_mapping **port_mapping; 158 struct mlxsw_sp_sb *sb; 159 struct mlxsw_sp_bridge *bridge; 160 struct mlxsw_sp_router *router; 161 struct mlxsw_sp_mr *mr; 162 struct mlxsw_afa *afa; 163 struct mlxsw_sp_acl *acl; 164 struct mlxsw_sp_fid_core *fid_core; 165 struct mlxsw_sp_kvdl *kvdl; 166 struct mlxsw_sp_nve *nve; 167 struct notifier_block netdevice_nb; 168 struct mlxsw_sp_ptp_clock *clock; 169 struct mlxsw_sp_ptp_state *ptp_state; 170 171 struct mlxsw_sp_counter_pool *counter_pool; 172 struct { 173 struct mlxsw_sp_span_entry *entries; 174 int entries_count; 175 } span; 176 const struct mlxsw_fw_rev *req_rev; 177 const char *fw_filename; 178 const struct mlxsw_sp_kvdl_ops *kvdl_ops; 179 const struct mlxsw_afa_ops *afa_ops; 180 const struct mlxsw_afk_ops *afk_ops; 181 const struct mlxsw_sp_mr_tcam_ops *mr_tcam_ops; 182 const struct mlxsw_sp_acl_tcam_ops *acl_tcam_ops; 183 const struct mlxsw_sp_nve_ops **nve_ops_arr; 184 const struct mlxsw_sp_rif_ops **rif_ops_arr; 185 const struct mlxsw_sp_sb_vals *sb_vals; 186 const struct mlxsw_sp_port_type_speed_ops *port_type_speed_ops; 187 const struct mlxsw_sp_ptp_ops *ptp_ops; 188 const struct mlxsw_listener *listeners; 189 size_t listeners_count; 190 }; 191 192 static inline struct mlxsw_sp_upper * 193 mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id) 194 { 195 return &mlxsw_sp->lags[lag_id]; 196 } 197 198 struct mlxsw_sp_port_pcpu_stats { 199 u64 rx_packets; 200 u64 rx_bytes; 201 u64 tx_packets; 202 u64 tx_bytes; 203 struct u64_stats_sync syncp; 204 u32 tx_dropped; 205 }; 206 207 struct mlxsw_sp_port_sample { 208 struct psample_group __rcu *psample_group; 209 u32 trunc_size; 210 u32 rate; 211 bool truncate; 212 }; 213 214 struct mlxsw_sp_bridge_port; 215 struct mlxsw_sp_fid; 216 217 struct mlxsw_sp_port_vlan { 218 struct list_head list; 219 struct mlxsw_sp_port *mlxsw_sp_port; 220 struct mlxsw_sp_fid *fid; 221 u16 vid; 222 struct mlxsw_sp_bridge_port *bridge_port; 223 struct list_head bridge_vlan_node; 224 }; 225 226 /* No need an internal lock; At worse - miss a single periodic iteration */ 227 struct mlxsw_sp_port_xstats { 228 u64 ecn; 229 u64 wred_drop[TC_MAX_QUEUE]; 230 u64 tail_drop[TC_MAX_QUEUE]; 231 u64 backlog[TC_MAX_QUEUE]; 232 u64 tx_bytes[IEEE_8021QAZ_MAX_TCS]; 233 u64 tx_packets[IEEE_8021QAZ_MAX_TCS]; 234 }; 235 236 struct mlxsw_sp_ptp_port_dir_stats { 237 u64 packets; 238 u64 timestamps; 239 }; 240 241 struct mlxsw_sp_ptp_port_stats { 242 struct mlxsw_sp_ptp_port_dir_stats rx_gcd; 243 struct mlxsw_sp_ptp_port_dir_stats tx_gcd; 244 }; 245 246 struct mlxsw_sp_port { 247 struct net_device *dev; 248 struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats; 249 struct mlxsw_sp *mlxsw_sp; 250 u8 local_port; 251 u8 lagged:1, 252 split:1; 253 u16 pvid; 254 u16 lag_id; 255 struct { 256 u8 tx_pause:1, 257 rx_pause:1, 258 autoneg:1; 259 } link; 260 struct { 261 struct ieee_ets *ets; 262 struct ieee_maxrate *maxrate; 263 struct ieee_pfc *pfc; 264 enum mlxsw_reg_qpts_trust_state trust_state; 265 } dcb; 266 struct mlxsw_sp_port_mapping mapping; /* mapping is constant during the 267 * mlxsw_sp_port lifetime, however 268 * the same localport can have 269 * different mapping. 270 */ 271 /* TC handles */ 272 struct list_head mall_tc_list; 273 struct { 274 #define MLXSW_HW_STATS_UPDATE_TIME HZ 275 struct rtnl_link_stats64 stats; 276 struct mlxsw_sp_port_xstats xstats; 277 struct delayed_work update_dw; 278 } periodic_hw_stats; 279 struct mlxsw_sp_port_sample *sample; 280 struct list_head vlans_list; 281 struct mlxsw_sp_port_vlan *default_vlan; 282 struct mlxsw_sp_qdisc *root_qdisc; 283 struct mlxsw_sp_qdisc *tclass_qdiscs; 284 unsigned acl_rule_count; 285 struct mlxsw_sp_acl_block *ing_acl_block; 286 struct mlxsw_sp_acl_block *eg_acl_block; 287 struct { 288 struct delayed_work shaper_dw; 289 struct hwtstamp_config hwtstamp_config; 290 u16 ing_types; 291 u16 egr_types; 292 struct mlxsw_sp_ptp_port_stats stats; 293 } ptp; 294 u8 split_base_local_port; 295 }; 296 297 struct mlxsw_sp_port_type_speed_ops { 298 void (*from_ptys_supported_port)(struct mlxsw_sp *mlxsw_sp, 299 u32 ptys_eth_proto, 300 struct ethtool_link_ksettings *cmd); 301 void (*from_ptys_link)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto, 302 u8 width, unsigned long *mode); 303 u32 (*from_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto); 304 void (*from_ptys_speed_duplex)(struct mlxsw_sp *mlxsw_sp, 305 bool carrier_ok, u32 ptys_eth_proto, 306 struct ethtool_link_ksettings *cmd); 307 u32 (*to_ptys_advert_link)(struct mlxsw_sp *mlxsw_sp, u8 width, 308 const struct ethtool_link_ksettings *cmd); 309 u32 (*to_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u8 width, u32 speed); 310 u32 (*to_ptys_upper_speed)(struct mlxsw_sp *mlxsw_sp, u32 upper_speed); 311 int (*port_speed_base)(struct mlxsw_sp *mlxsw_sp, u8 local_port, 312 u32 *base_speed); 313 void (*reg_ptys_eth_pack)(struct mlxsw_sp *mlxsw_sp, char *payload, 314 u8 local_port, u32 proto_admin, bool autoneg); 315 void (*reg_ptys_eth_unpack)(struct mlxsw_sp *mlxsw_sp, char *payload, 316 u32 *p_eth_proto_cap, 317 u32 *p_eth_proto_admin, 318 u32 *p_eth_proto_oper); 319 }; 320 321 static inline struct net_device * 322 mlxsw_sp_bridge_vxlan_dev_find(struct net_device *br_dev) 323 { 324 struct net_device *dev; 325 struct list_head *iter; 326 327 netdev_for_each_lower_dev(br_dev, dev, iter) { 328 if (netif_is_vxlan(dev)) 329 return dev; 330 } 331 332 return NULL; 333 } 334 335 static inline bool mlxsw_sp_bridge_has_vxlan(struct net_device *br_dev) 336 { 337 return !!mlxsw_sp_bridge_vxlan_dev_find(br_dev); 338 } 339 340 static inline int 341 mlxsw_sp_vxlan_mapped_vid(const struct net_device *vxlan_dev, u16 *p_vid) 342 { 343 struct bridge_vlan_info vinfo; 344 u16 vid = 0; 345 int err; 346 347 err = br_vlan_get_pvid(vxlan_dev, &vid); 348 if (err || !vid) 349 goto out; 350 351 err = br_vlan_get_info(vxlan_dev, vid, &vinfo); 352 if (err || !(vinfo.flags & BRIDGE_VLAN_INFO_UNTAGGED)) 353 vid = 0; 354 355 out: 356 *p_vid = vid; 357 return err; 358 } 359 360 static inline bool 361 mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port) 362 { 363 return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause; 364 } 365 366 static inline struct mlxsw_sp_port * 367 mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index) 368 { 369 struct mlxsw_sp_port *mlxsw_sp_port; 370 u8 local_port; 371 372 local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core, 373 lag_id, port_index); 374 mlxsw_sp_port = mlxsw_sp->ports[local_port]; 375 return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL; 376 } 377 378 static inline struct mlxsw_sp_port_vlan * 379 mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port, 380 u16 vid) 381 { 382 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan; 383 384 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list, 385 list) { 386 if (mlxsw_sp_port_vlan->vid == vid) 387 return mlxsw_sp_port_vlan; 388 } 389 390 return NULL; 391 } 392 393 enum mlxsw_sp_flood_type { 394 MLXSW_SP_FLOOD_TYPE_UC, 395 MLXSW_SP_FLOOD_TYPE_BC, 396 MLXSW_SP_FLOOD_TYPE_MC, 397 }; 398 399 /* spectrum_buffers.c */ 400 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp); 401 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp); 402 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port); 403 int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core, 404 unsigned int sb_index, u16 pool_index, 405 struct devlink_sb_pool_info *pool_info); 406 int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core, 407 unsigned int sb_index, u16 pool_index, u32 size, 408 enum devlink_sb_threshold_type threshold_type, 409 struct netlink_ext_ack *extack); 410 int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port, 411 unsigned int sb_index, u16 pool_index, 412 u32 *p_threshold); 413 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port, 414 unsigned int sb_index, u16 pool_index, 415 u32 threshold, struct netlink_ext_ack *extack); 416 int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port, 417 unsigned int sb_index, u16 tc_index, 418 enum devlink_sb_pool_type pool_type, 419 u16 *p_pool_index, u32 *p_threshold); 420 int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port, 421 unsigned int sb_index, u16 tc_index, 422 enum devlink_sb_pool_type pool_type, 423 u16 pool_index, u32 threshold, 424 struct netlink_ext_ack *extack); 425 int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core, 426 unsigned int sb_index); 427 int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core, 428 unsigned int sb_index); 429 int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port, 430 unsigned int sb_index, u16 pool_index, 431 u32 *p_cur, u32 *p_max); 432 int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port, 433 unsigned int sb_index, u16 tc_index, 434 enum devlink_sb_pool_type pool_type, 435 u32 *p_cur, u32 *p_max); 436 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells); 437 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes); 438 u32 mlxsw_sp_sb_max_headroom_cells(const struct mlxsw_sp *mlxsw_sp); 439 440 extern const struct mlxsw_sp_sb_vals mlxsw_sp1_sb_vals; 441 extern const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals; 442 443 /* spectrum_switchdev.c */ 444 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp); 445 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp); 446 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid, 447 bool adding); 448 void 449 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan); 450 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port, 451 struct net_device *brport_dev, 452 struct net_device *br_dev, 453 struct netlink_ext_ack *extack); 454 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port, 455 struct net_device *brport_dev, 456 struct net_device *br_dev); 457 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp, 458 const struct net_device *br_dev); 459 int mlxsw_sp_bridge_vxlan_join(struct mlxsw_sp *mlxsw_sp, 460 const struct net_device *br_dev, 461 const struct net_device *vxlan_dev, u16 vid, 462 struct netlink_ext_ack *extack); 463 void mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp, 464 const struct net_device *vxlan_dev); 465 struct mlxsw_sp_fid *mlxsw_sp_bridge_fid_get(struct mlxsw_sp *mlxsw_sp, 466 const struct net_device *br_dev, 467 u16 vid, 468 struct netlink_ext_ack *extack); 469 extern struct notifier_block mlxsw_sp_switchdev_notifier; 470 471 /* spectrum.c */ 472 void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb, 473 u8 local_port, void *priv); 474 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port, 475 enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index, 476 bool dwrr, u8 dwrr_weight); 477 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port, 478 u8 switch_prio, u8 tclass); 479 int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu, 480 u8 *prio_tc, bool pause_en, 481 struct ieee_pfc *my_pfc); 482 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port, 483 enum mlxsw_reg_qeec_hr hr, u8 index, 484 u8 next_index, u32 maxrate); 485 enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state); 486 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid, 487 u8 state); 488 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable); 489 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid, 490 bool learn_enable); 491 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid); 492 struct mlxsw_sp_port_vlan * 493 mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid); 494 void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan); 495 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin, 496 u16 vid_end, bool is_member, bool untagged); 497 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp, 498 unsigned int counter_index, u64 *packets, 499 u64 *bytes); 500 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp, 501 unsigned int *p_counter_index); 502 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp, 503 unsigned int counter_index); 504 bool mlxsw_sp_port_dev_check(const struct net_device *dev); 505 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev); 506 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev); 507 struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev); 508 void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port); 509 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev); 510 511 /* spectrum_dcb.c */ 512 #ifdef CONFIG_MLXSW_SPECTRUM_DCB 513 int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port); 514 void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port); 515 #else 516 static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port) 517 { 518 return 0; 519 } 520 static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port) 521 {} 522 #endif 523 524 /* spectrum_router.c */ 525 enum mlxsw_sp_l3proto { 526 MLXSW_SP_L3_PROTO_IPV4, 527 MLXSW_SP_L3_PROTO_IPV6, 528 #define MLXSW_SP_L3_PROTO_MAX (MLXSW_SP_L3_PROTO_IPV6 + 1) 529 }; 530 531 union mlxsw_sp_l3addr { 532 __be32 addr4; 533 struct in6_addr addr6; 534 }; 535 536 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp, 537 struct netlink_ext_ack *extack); 538 void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp); 539 int mlxsw_sp_netdevice_router_port_event(struct net_device *dev, 540 unsigned long event, void *ptr); 541 void mlxsw_sp_rif_macvlan_del(struct mlxsw_sp *mlxsw_sp, 542 const struct net_device *macvlan_dev); 543 int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused, 544 unsigned long event, void *ptr); 545 int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused, 546 unsigned long event, void *ptr); 547 int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event, 548 struct netdev_notifier_changeupper_info *info); 549 bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp, 550 const struct net_device *dev); 551 bool mlxsw_sp_netdev_is_ipip_ul(const struct mlxsw_sp *mlxsw_sp, 552 const struct net_device *dev); 553 int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp, 554 struct net_device *l3_dev, 555 unsigned long event, 556 struct netdev_notifier_info *info); 557 int 558 mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp, 559 struct net_device *l3_dev, 560 unsigned long event, 561 struct netdev_notifier_info *info); 562 void 563 mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan); 564 void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp, 565 struct net_device *dev); 566 struct mlxsw_sp_rif *mlxsw_sp_rif_find_by_dev(const struct mlxsw_sp *mlxsw_sp, 567 const struct net_device *dev); 568 u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp); 569 struct mlxsw_sp_fid *mlxsw_sp_rif_fid(const struct mlxsw_sp_rif *rif); 570 int mlxsw_sp_router_nve_promote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id, 571 enum mlxsw_sp_l3proto ul_proto, 572 const union mlxsw_sp_l3addr *ul_sip, 573 u32 tunnel_index); 574 void mlxsw_sp_router_nve_demote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id, 575 enum mlxsw_sp_l3proto ul_proto, 576 const union mlxsw_sp_l3addr *ul_sip); 577 int mlxsw_sp_router_tb_id_vr_id(struct mlxsw_sp *mlxsw_sp, u32 tb_id, 578 u16 *vr_id); 579 int mlxsw_sp_router_ul_rif_get(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id, 580 u16 *ul_rif_index); 581 void mlxsw_sp_router_ul_rif_put(struct mlxsw_sp *mlxsw_sp, u16 ul_rif_index); 582 583 /* spectrum_kvdl.c */ 584 enum mlxsw_sp_kvdl_entry_type { 585 MLXSW_SP_KVDL_ENTRY_TYPE_ADJ, 586 MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET, 587 MLXSW_SP_KVDL_ENTRY_TYPE_PBS, 588 MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR, 589 MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT, 590 }; 591 592 static inline unsigned int 593 mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type) 594 { 595 switch (type) { 596 case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ: /* fall through */ 597 case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET: /* fall through */ 598 case MLXSW_SP_KVDL_ENTRY_TYPE_PBS: /* fall through */ 599 case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR: /* fall through */ 600 case MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT: /* fall through */ 601 default: 602 return 1; 603 } 604 } 605 606 struct mlxsw_sp_kvdl_ops { 607 size_t priv_size; 608 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv); 609 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv); 610 int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv, 611 enum mlxsw_sp_kvdl_entry_type type, 612 unsigned int entry_count, u32 *p_entry_index); 613 void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv, 614 enum mlxsw_sp_kvdl_entry_type type, 615 unsigned int entry_count, int entry_index); 616 int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv, 617 enum mlxsw_sp_kvdl_entry_type type, 618 unsigned int entry_count, 619 unsigned int *p_alloc_count); 620 int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv); 621 }; 622 623 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp); 624 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp); 625 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, 626 enum mlxsw_sp_kvdl_entry_type type, 627 unsigned int entry_count, u32 *p_entry_index); 628 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp, 629 enum mlxsw_sp_kvdl_entry_type type, 630 unsigned int entry_count, int entry_index); 631 int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp, 632 enum mlxsw_sp_kvdl_entry_type type, 633 unsigned int entry_count, 634 unsigned int *p_alloc_count); 635 636 /* spectrum1_kvdl.c */ 637 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops; 638 int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core); 639 640 /* spectrum2_kvdl.c */ 641 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops; 642 643 struct mlxsw_sp_acl_rule_info { 644 unsigned int priority; 645 struct mlxsw_afk_element_values values; 646 struct mlxsw_afa_block *act_block; 647 u8 action_created:1, 648 egress_bind_blocker:1; 649 unsigned int counter_index; 650 }; 651 652 struct mlxsw_sp_acl_block; 653 struct mlxsw_sp_acl_ruleset; 654 655 /* spectrum_acl.c */ 656 enum mlxsw_sp_acl_profile { 657 MLXSW_SP_ACL_PROFILE_FLOWER, 658 MLXSW_SP_ACL_PROFILE_MR, 659 }; 660 661 struct mlxsw_sp_acl_block { 662 struct list_head binding_list; 663 struct mlxsw_sp_acl_ruleset *ruleset_zero; 664 struct mlxsw_sp *mlxsw_sp; 665 unsigned int rule_count; 666 unsigned int disable_count; 667 unsigned int egress_blocker_rule_count; 668 struct net *net; 669 }; 670 671 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl); 672 struct mlxsw_sp *mlxsw_sp_acl_block_mlxsw_sp(struct mlxsw_sp_acl_block *block); 673 unsigned int mlxsw_sp_acl_block_rule_count(struct mlxsw_sp_acl_block *block); 674 void mlxsw_sp_acl_block_disable_inc(struct mlxsw_sp_acl_block *block); 675 void mlxsw_sp_acl_block_disable_dec(struct mlxsw_sp_acl_block *block); 676 bool mlxsw_sp_acl_block_disabled(struct mlxsw_sp_acl_block *block); 677 struct mlxsw_sp_acl_block *mlxsw_sp_acl_block_create(struct mlxsw_sp *mlxsw_sp, 678 struct net *net); 679 void mlxsw_sp_acl_block_destroy(struct mlxsw_sp_acl_block *block); 680 int mlxsw_sp_acl_block_bind(struct mlxsw_sp *mlxsw_sp, 681 struct mlxsw_sp_acl_block *block, 682 struct mlxsw_sp_port *mlxsw_sp_port, 683 bool ingress, 684 struct netlink_ext_ack *extack); 685 int mlxsw_sp_acl_block_unbind(struct mlxsw_sp *mlxsw_sp, 686 struct mlxsw_sp_acl_block *block, 687 struct mlxsw_sp_port *mlxsw_sp_port, 688 bool ingress); 689 bool mlxsw_sp_acl_block_is_egress_bound(struct mlxsw_sp_acl_block *block); 690 struct mlxsw_sp_acl_ruleset * 691 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp, 692 struct mlxsw_sp_acl_block *block, u32 chain_index, 693 enum mlxsw_sp_acl_profile profile); 694 struct mlxsw_sp_acl_ruleset * 695 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp, 696 struct mlxsw_sp_acl_block *block, u32 chain_index, 697 enum mlxsw_sp_acl_profile profile, 698 struct mlxsw_afk_element_usage *tmplt_elusage); 699 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp, 700 struct mlxsw_sp_acl_ruleset *ruleset); 701 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset); 702 703 struct mlxsw_sp_acl_rule_info * 704 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl, 705 struct mlxsw_afa_block *afa_block); 706 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei); 707 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei); 708 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei, 709 unsigned int priority); 710 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei, 711 enum mlxsw_afk_element element, 712 u32 key_value, u32 mask_value); 713 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei, 714 enum mlxsw_afk_element element, 715 const char *key_value, 716 const char *mask_value, unsigned int len); 717 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei); 718 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei, 719 u16 group_id); 720 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei); 721 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei); 722 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei); 723 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp, 724 struct mlxsw_sp_acl_rule_info *rulei, 725 struct mlxsw_sp_acl_block *block, 726 struct net_device *out_dev, 727 struct netlink_ext_ack *extack); 728 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp, 729 struct mlxsw_sp_acl_rule_info *rulei, 730 struct net_device *out_dev, 731 struct netlink_ext_ack *extack); 732 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp, 733 struct mlxsw_sp_acl_rule_info *rulei, 734 u32 action, u16 vid, u16 proto, u8 prio, 735 struct netlink_ext_ack *extack); 736 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp, 737 struct mlxsw_sp_acl_rule_info *rulei, 738 struct netlink_ext_ack *extack); 739 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp, 740 struct mlxsw_sp_acl_rule_info *rulei, 741 u16 fid, struct netlink_ext_ack *extack); 742 743 struct mlxsw_sp_acl_rule; 744 745 struct mlxsw_sp_acl_rule * 746 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp, 747 struct mlxsw_sp_acl_ruleset *ruleset, 748 unsigned long cookie, 749 struct mlxsw_afa_block *afa_block, 750 struct netlink_ext_ack *extack); 751 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp, 752 struct mlxsw_sp_acl_rule *rule); 753 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp, 754 struct mlxsw_sp_acl_rule *rule); 755 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp, 756 struct mlxsw_sp_acl_rule *rule); 757 int mlxsw_sp_acl_rule_action_replace(struct mlxsw_sp *mlxsw_sp, 758 struct mlxsw_sp_acl_rule *rule, 759 struct mlxsw_afa_block *afa_block); 760 struct mlxsw_sp_acl_rule * 761 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp, 762 struct mlxsw_sp_acl_ruleset *ruleset, 763 unsigned long cookie); 764 struct mlxsw_sp_acl_rule_info * 765 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule); 766 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp, 767 struct mlxsw_sp_acl_rule *rule, 768 u64 *packets, u64 *bytes, u64 *last_use); 769 770 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp); 771 772 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp); 773 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp); 774 u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp); 775 int mlxsw_sp_acl_region_rehash_intrvl_set(struct mlxsw_sp *mlxsw_sp, u32 val); 776 777 /* spectrum_acl_tcam.c */ 778 struct mlxsw_sp_acl_tcam; 779 struct mlxsw_sp_acl_tcam_region; 780 781 struct mlxsw_sp_acl_tcam_ops { 782 enum mlxsw_reg_ptar_key_type key_type; 783 size_t priv_size; 784 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv, 785 struct mlxsw_sp_acl_tcam *tcam); 786 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv); 787 size_t region_priv_size; 788 int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv, 789 void *tcam_priv, 790 struct mlxsw_sp_acl_tcam_region *region, 791 void *hints_priv); 792 void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv); 793 int (*region_associate)(struct mlxsw_sp *mlxsw_sp, 794 struct mlxsw_sp_acl_tcam_region *region); 795 void * (*region_rehash_hints_get)(void *region_priv); 796 void (*region_rehash_hints_put)(void *hints_priv); 797 size_t chunk_priv_size; 798 void (*chunk_init)(void *region_priv, void *chunk_priv, 799 unsigned int priority); 800 void (*chunk_fini)(void *chunk_priv); 801 size_t entry_priv_size; 802 int (*entry_add)(struct mlxsw_sp *mlxsw_sp, 803 void *region_priv, void *chunk_priv, 804 void *entry_priv, 805 struct mlxsw_sp_acl_rule_info *rulei); 806 void (*entry_del)(struct mlxsw_sp *mlxsw_sp, 807 void *region_priv, void *chunk_priv, 808 void *entry_priv); 809 int (*entry_action_replace)(struct mlxsw_sp *mlxsw_sp, 810 void *region_priv, void *entry_priv, 811 struct mlxsw_sp_acl_rule_info *rulei); 812 int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp, 813 void *region_priv, void *entry_priv, 814 bool *activity); 815 }; 816 817 /* spectrum1_acl_tcam.c */ 818 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops; 819 820 /* spectrum2_acl_tcam.c */ 821 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops; 822 823 /* spectrum_acl_flex_actions.c */ 824 extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops; 825 extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops; 826 827 /* spectrum_acl_flex_keys.c */ 828 extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops; 829 extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops; 830 831 /* spectrum_flower.c */ 832 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp, 833 struct mlxsw_sp_acl_block *block, 834 struct flow_cls_offload *f); 835 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp, 836 struct mlxsw_sp_acl_block *block, 837 struct flow_cls_offload *f); 838 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp, 839 struct mlxsw_sp_acl_block *block, 840 struct flow_cls_offload *f); 841 int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp, 842 struct mlxsw_sp_acl_block *block, 843 struct flow_cls_offload *f); 844 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp, 845 struct mlxsw_sp_acl_block *block, 846 struct flow_cls_offload *f); 847 848 /* spectrum_qdisc.c */ 849 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port); 850 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port); 851 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port, 852 struct tc_red_qopt_offload *p); 853 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port, 854 struct tc_prio_qopt_offload *p); 855 856 /* spectrum_fid.c */ 857 bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index); 858 bool mlxsw_sp_fid_lag_vid_valid(const struct mlxsw_sp_fid *fid); 859 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp, 860 u16 fid_index); 861 int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex); 862 int mlxsw_sp_fid_nve_type(const struct mlxsw_sp_fid *fid, 863 enum mlxsw_sp_nve_type *p_type); 864 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_vni(struct mlxsw_sp *mlxsw_sp, 865 __be32 vni); 866 int mlxsw_sp_fid_vni(const struct mlxsw_sp_fid *fid, __be32 *vni); 867 int mlxsw_sp_fid_nve_flood_index_set(struct mlxsw_sp_fid *fid, 868 u32 nve_flood_index); 869 void mlxsw_sp_fid_nve_flood_index_clear(struct mlxsw_sp_fid *fid); 870 bool mlxsw_sp_fid_nve_flood_index_is_set(const struct mlxsw_sp_fid *fid); 871 int mlxsw_sp_fid_vni_set(struct mlxsw_sp_fid *fid, enum mlxsw_sp_nve_type type, 872 __be32 vni, int nve_ifindex); 873 void mlxsw_sp_fid_vni_clear(struct mlxsw_sp_fid *fid); 874 bool mlxsw_sp_fid_vni_is_set(const struct mlxsw_sp_fid *fid); 875 void mlxsw_sp_fid_fdb_clear_offload(const struct mlxsw_sp_fid *fid, 876 const struct net_device *nve_dev); 877 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid, 878 enum mlxsw_sp_flood_type packet_type, u8 local_port, 879 bool member); 880 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid, 881 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid); 882 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid, 883 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid); 884 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid); 885 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid); 886 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif); 887 struct mlxsw_sp_rif *mlxsw_sp_fid_rif(const struct mlxsw_sp_fid *fid); 888 enum mlxsw_sp_rif_type 889 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp, 890 enum mlxsw_sp_fid_type type); 891 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid); 892 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid); 893 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp, 894 int br_ifindex); 895 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_lookup(struct mlxsw_sp *mlxsw_sp, 896 u16 vid); 897 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_lookup(struct mlxsw_sp *mlxsw_sp, 898 int br_ifindex); 899 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp, 900 u16 rif_index); 901 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp); 902 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid); 903 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port); 904 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port); 905 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp); 906 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp); 907 908 /* spectrum_mr.c */ 909 enum mlxsw_sp_mr_route_prio { 910 MLXSW_SP_MR_ROUTE_PRIO_SG, 911 MLXSW_SP_MR_ROUTE_PRIO_STARG, 912 MLXSW_SP_MR_ROUTE_PRIO_CATCHALL, 913 __MLXSW_SP_MR_ROUTE_PRIO_MAX 914 }; 915 916 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1) 917 918 struct mlxsw_sp_mr_route_key; 919 920 struct mlxsw_sp_mr_tcam_ops { 921 size_t priv_size; 922 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv); 923 void (*fini)(void *priv); 924 size_t route_priv_size; 925 int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv, 926 void *route_priv, 927 struct mlxsw_sp_mr_route_key *key, 928 struct mlxsw_afa_block *afa_block, 929 enum mlxsw_sp_mr_route_prio prio); 930 void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv, 931 void *route_priv, 932 struct mlxsw_sp_mr_route_key *key); 933 int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv, 934 struct mlxsw_sp_mr_route_key *key, 935 struct mlxsw_afa_block *afa_block); 936 }; 937 938 /* spectrum1_mr_tcam.c */ 939 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops; 940 941 /* spectrum2_mr_tcam.c */ 942 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops; 943 944 /* spectrum_nve.c */ 945 struct mlxsw_sp_nve_params { 946 enum mlxsw_sp_nve_type type; 947 __be32 vni; 948 const struct net_device *dev; 949 }; 950 951 extern const struct mlxsw_sp_nve_ops *mlxsw_sp1_nve_ops_arr[]; 952 extern const struct mlxsw_sp_nve_ops *mlxsw_sp2_nve_ops_arr[]; 953 954 int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip, 955 enum mlxsw_sp_l3proto proto, 956 union mlxsw_sp_l3addr *addr); 957 int mlxsw_sp_nve_flood_ip_add(struct mlxsw_sp *mlxsw_sp, 958 struct mlxsw_sp_fid *fid, 959 enum mlxsw_sp_l3proto proto, 960 union mlxsw_sp_l3addr *addr); 961 void mlxsw_sp_nve_flood_ip_del(struct mlxsw_sp *mlxsw_sp, 962 struct mlxsw_sp_fid *fid, 963 enum mlxsw_sp_l3proto proto, 964 union mlxsw_sp_l3addr *addr); 965 u32 mlxsw_sp_nve_decap_tunnel_index_get(const struct mlxsw_sp *mlxsw_sp); 966 bool mlxsw_sp_nve_ipv4_route_is_decap(const struct mlxsw_sp *mlxsw_sp, 967 u32 tb_id, __be32 addr); 968 int mlxsw_sp_nve_fid_enable(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *fid, 969 struct mlxsw_sp_nve_params *params, 970 struct netlink_ext_ack *extack); 971 void mlxsw_sp_nve_fid_disable(struct mlxsw_sp *mlxsw_sp, 972 struct mlxsw_sp_fid *fid); 973 int mlxsw_sp_port_nve_init(struct mlxsw_sp_port *mlxsw_sp_port); 974 void mlxsw_sp_port_nve_fini(struct mlxsw_sp_port *mlxsw_sp_port); 975 int mlxsw_sp_nve_init(struct mlxsw_sp *mlxsw_sp); 976 void mlxsw_sp_nve_fini(struct mlxsw_sp *mlxsw_sp); 977 978 /* spectrum_nve_vxlan.c */ 979 int mlxsw_sp_nve_inc_parsing_depth_get(struct mlxsw_sp *mlxsw_sp); 980 void mlxsw_sp_nve_inc_parsing_depth_put(struct mlxsw_sp *mlxsw_sp); 981 982 /* spectrum_trap.c */ 983 int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp); 984 void mlxsw_sp_devlink_traps_fini(struct mlxsw_sp *mlxsw_sp); 985 int mlxsw_sp_trap_init(struct mlxsw_core *mlxsw_core, 986 const struct devlink_trap *trap, void *trap_ctx); 987 void mlxsw_sp_trap_fini(struct mlxsw_core *mlxsw_core, 988 const struct devlink_trap *trap, void *trap_ctx); 989 int mlxsw_sp_trap_action_set(struct mlxsw_core *mlxsw_core, 990 const struct devlink_trap *trap, 991 enum devlink_trap_action action); 992 int mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core, 993 const struct devlink_trap_group *group); 994 995 static inline struct net *mlxsw_sp_net(struct mlxsw_sp *mlxsw_sp) 996 { 997 return mlxsw_core_net(mlxsw_sp->core); 998 } 999 1000 #endif 1001