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 struct mlxsw_sp_span_ops; 144 145 struct mlxsw_sp_port_mapping { 146 u8 module; 147 u8 width; 148 u8 lane; 149 }; 150 151 struct mlxsw_sp { 152 struct mlxsw_sp_port **ports; 153 struct mlxsw_core *core; 154 const struct mlxsw_bus_info *bus_info; 155 unsigned char base_mac[ETH_ALEN]; 156 const unsigned char *mac_mask; 157 struct mlxsw_sp_upper *lags; 158 struct mlxsw_sp_port_mapping **port_mapping; 159 struct mlxsw_sp_sb *sb; 160 struct mlxsw_sp_bridge *bridge; 161 struct mlxsw_sp_router *router; 162 struct mlxsw_sp_mr *mr; 163 struct mlxsw_afa *afa; 164 struct mlxsw_sp_acl *acl; 165 struct mlxsw_sp_fid_core *fid_core; 166 struct mlxsw_sp_kvdl *kvdl; 167 struct mlxsw_sp_nve *nve; 168 struct notifier_block netdevice_nb; 169 struct mlxsw_sp_ptp_clock *clock; 170 struct mlxsw_sp_ptp_state *ptp_state; 171 struct mlxsw_sp_counter_pool *counter_pool; 172 struct mlxsw_sp_span *span; 173 const struct mlxsw_fw_rev *req_rev; 174 const char *fw_filename; 175 const struct mlxsw_sp_kvdl_ops *kvdl_ops; 176 const struct mlxsw_afa_ops *afa_ops; 177 const struct mlxsw_afk_ops *afk_ops; 178 const struct mlxsw_sp_mr_tcam_ops *mr_tcam_ops; 179 const struct mlxsw_sp_acl_tcam_ops *acl_tcam_ops; 180 const struct mlxsw_sp_nve_ops **nve_ops_arr; 181 const struct mlxsw_sp_rif_ops **rif_ops_arr; 182 const struct mlxsw_sp_sb_vals *sb_vals; 183 const struct mlxsw_sp_port_type_speed_ops *port_type_speed_ops; 184 const struct mlxsw_sp_ptp_ops *ptp_ops; 185 const struct mlxsw_sp_span_ops *span_ops; 186 const struct mlxsw_listener *listeners; 187 size_t listeners_count; 188 u32 lowest_shaper_bs; 189 }; 190 191 static inline struct mlxsw_sp_upper * 192 mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id) 193 { 194 return &mlxsw_sp->lags[lag_id]; 195 } 196 197 struct mlxsw_sp_port_pcpu_stats { 198 u64 rx_packets; 199 u64 rx_bytes; 200 u64 tx_packets; 201 u64 tx_bytes; 202 struct u64_stats_sync syncp; 203 u32 tx_dropped; 204 }; 205 206 struct mlxsw_sp_port_sample { 207 struct psample_group __rcu *psample_group; 208 u32 trunc_size; 209 u32 rate; 210 bool truncate; 211 }; 212 213 struct mlxsw_sp_bridge_port; 214 struct mlxsw_sp_fid; 215 216 struct mlxsw_sp_port_vlan { 217 struct list_head list; 218 struct mlxsw_sp_port *mlxsw_sp_port; 219 struct mlxsw_sp_fid *fid; 220 u16 vid; 221 struct mlxsw_sp_bridge_port *bridge_port; 222 struct list_head bridge_vlan_node; 223 }; 224 225 /* No need an internal lock; At worse - miss a single periodic iteration */ 226 struct mlxsw_sp_port_xstats { 227 u64 ecn; 228 u64 wred_drop[TC_MAX_QUEUE]; 229 u64 tail_drop[TC_MAX_QUEUE]; 230 u64 backlog[TC_MAX_QUEUE]; 231 u64 tx_bytes[IEEE_8021QAZ_MAX_TCS]; 232 u64 tx_packets[IEEE_8021QAZ_MAX_TCS]; 233 }; 234 235 struct mlxsw_sp_ptp_port_dir_stats { 236 u64 packets; 237 u64 timestamps; 238 }; 239 240 struct mlxsw_sp_ptp_port_stats { 241 struct mlxsw_sp_ptp_port_dir_stats rx_gcd; 242 struct mlxsw_sp_ptp_port_dir_stats tx_gcd; 243 }; 244 245 struct mlxsw_sp_port { 246 struct net_device *dev; 247 struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats; 248 struct mlxsw_sp *mlxsw_sp; 249 u8 local_port; 250 u8 lagged:1, 251 split:1; 252 u16 pvid; 253 u16 lag_id; 254 struct { 255 u8 tx_pause:1, 256 rx_pause:1, 257 autoneg:1; 258 } link; 259 struct { 260 struct ieee_ets *ets; 261 struct ieee_maxrate *maxrate; 262 struct ieee_pfc *pfc; 263 enum mlxsw_reg_qpts_trust_state trust_state; 264 } dcb; 265 struct mlxsw_sp_port_mapping mapping; /* mapping is constant during the 266 * mlxsw_sp_port lifetime, however 267 * the same localport can have 268 * different mapping. 269 */ 270 /* TC handles */ 271 struct list_head mall_tc_list; 272 struct { 273 #define MLXSW_HW_STATS_UPDATE_TIME HZ 274 struct rtnl_link_stats64 stats; 275 struct mlxsw_sp_port_xstats xstats; 276 struct delayed_work update_dw; 277 } periodic_hw_stats; 278 struct mlxsw_sp_port_sample *sample; 279 struct list_head vlans_list; 280 struct mlxsw_sp_port_vlan *default_vlan; 281 struct mlxsw_sp_qdisc *root_qdisc; 282 struct mlxsw_sp_qdisc *tclass_qdiscs; 283 unsigned acl_rule_count; 284 struct mlxsw_sp_acl_block *ing_acl_block; 285 struct mlxsw_sp_acl_block *eg_acl_block; 286 struct { 287 struct delayed_work shaper_dw; 288 struct hwtstamp_config hwtstamp_config; 289 u16 ing_types; 290 u16 egr_types; 291 struct mlxsw_sp_ptp_port_stats stats; 292 } ptp; 293 u8 split_base_local_port; 294 struct { 295 struct delayed_work speed_update_dw; 296 } span; 297 }; 298 299 struct mlxsw_sp_port_type_speed_ops { 300 void (*from_ptys_supported_port)(struct mlxsw_sp *mlxsw_sp, 301 u32 ptys_eth_proto, 302 struct ethtool_link_ksettings *cmd); 303 void (*from_ptys_link)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto, 304 u8 width, unsigned long *mode); 305 u32 (*from_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto); 306 void (*from_ptys_speed_duplex)(struct mlxsw_sp *mlxsw_sp, 307 bool carrier_ok, u32 ptys_eth_proto, 308 struct ethtool_link_ksettings *cmd); 309 u32 (*to_ptys_advert_link)(struct mlxsw_sp *mlxsw_sp, u8 width, 310 const struct ethtool_link_ksettings *cmd); 311 u32 (*to_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u8 width, u32 speed); 312 u32 (*to_ptys_upper_speed)(struct mlxsw_sp *mlxsw_sp, u32 upper_speed); 313 int (*port_speed_base)(struct mlxsw_sp *mlxsw_sp, u8 local_port, 314 u32 *base_speed); 315 void (*reg_ptys_eth_pack)(struct mlxsw_sp *mlxsw_sp, char *payload, 316 u8 local_port, u32 proto_admin, bool autoneg); 317 void (*reg_ptys_eth_unpack)(struct mlxsw_sp *mlxsw_sp, char *payload, 318 u32 *p_eth_proto_cap, 319 u32 *p_eth_proto_admin, 320 u32 *p_eth_proto_oper); 321 }; 322 323 static inline struct net_device * 324 mlxsw_sp_bridge_vxlan_dev_find(struct net_device *br_dev) 325 { 326 struct net_device *dev; 327 struct list_head *iter; 328 329 netdev_for_each_lower_dev(br_dev, dev, iter) { 330 if (netif_is_vxlan(dev)) 331 return dev; 332 } 333 334 return NULL; 335 } 336 337 static inline bool mlxsw_sp_bridge_has_vxlan(struct net_device *br_dev) 338 { 339 return !!mlxsw_sp_bridge_vxlan_dev_find(br_dev); 340 } 341 342 static inline int 343 mlxsw_sp_vxlan_mapped_vid(const struct net_device *vxlan_dev, u16 *p_vid) 344 { 345 struct bridge_vlan_info vinfo; 346 u16 vid = 0; 347 int err; 348 349 err = br_vlan_get_pvid(vxlan_dev, &vid); 350 if (err || !vid) 351 goto out; 352 353 err = br_vlan_get_info(vxlan_dev, vid, &vinfo); 354 if (err || !(vinfo.flags & BRIDGE_VLAN_INFO_UNTAGGED)) 355 vid = 0; 356 357 out: 358 *p_vid = vid; 359 return err; 360 } 361 362 static inline bool 363 mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port) 364 { 365 return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause; 366 } 367 368 static inline struct mlxsw_sp_port * 369 mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index) 370 { 371 struct mlxsw_sp_port *mlxsw_sp_port; 372 u8 local_port; 373 374 local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core, 375 lag_id, port_index); 376 mlxsw_sp_port = mlxsw_sp->ports[local_port]; 377 return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL; 378 } 379 380 static inline struct mlxsw_sp_port_vlan * 381 mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port, 382 u16 vid) 383 { 384 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan; 385 386 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list, 387 list) { 388 if (mlxsw_sp_port_vlan->vid == vid) 389 return mlxsw_sp_port_vlan; 390 } 391 392 return NULL; 393 } 394 395 enum mlxsw_sp_flood_type { 396 MLXSW_SP_FLOOD_TYPE_UC, 397 MLXSW_SP_FLOOD_TYPE_BC, 398 MLXSW_SP_FLOOD_TYPE_MC, 399 }; 400 401 /* spectrum_buffers.c */ 402 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp); 403 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp); 404 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port); 405 int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core, 406 unsigned int sb_index, u16 pool_index, 407 struct devlink_sb_pool_info *pool_info); 408 int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core, 409 unsigned int sb_index, u16 pool_index, u32 size, 410 enum devlink_sb_threshold_type threshold_type, 411 struct netlink_ext_ack *extack); 412 int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port, 413 unsigned int sb_index, u16 pool_index, 414 u32 *p_threshold); 415 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port, 416 unsigned int sb_index, u16 pool_index, 417 u32 threshold, struct netlink_ext_ack *extack); 418 int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port, 419 unsigned int sb_index, u16 tc_index, 420 enum devlink_sb_pool_type pool_type, 421 u16 *p_pool_index, u32 *p_threshold); 422 int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port, 423 unsigned int sb_index, u16 tc_index, 424 enum devlink_sb_pool_type pool_type, 425 u16 pool_index, u32 threshold, 426 struct netlink_ext_ack *extack); 427 int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core, 428 unsigned int sb_index); 429 int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core, 430 unsigned int sb_index); 431 int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port, 432 unsigned int sb_index, u16 pool_index, 433 u32 *p_cur, u32 *p_max); 434 int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port, 435 unsigned int sb_index, u16 tc_index, 436 enum devlink_sb_pool_type pool_type, 437 u32 *p_cur, u32 *p_max); 438 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells); 439 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes); 440 u32 mlxsw_sp_sb_max_headroom_cells(const struct mlxsw_sp *mlxsw_sp); 441 442 extern const struct mlxsw_sp_sb_vals mlxsw_sp1_sb_vals; 443 extern const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals; 444 445 /* spectrum_switchdev.c */ 446 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp); 447 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp); 448 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid, 449 bool adding); 450 void 451 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan); 452 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port, 453 struct net_device *brport_dev, 454 struct net_device *br_dev, 455 struct netlink_ext_ack *extack); 456 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port, 457 struct net_device *brport_dev, 458 struct net_device *br_dev); 459 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp, 460 const struct net_device *br_dev); 461 int mlxsw_sp_bridge_vxlan_join(struct mlxsw_sp *mlxsw_sp, 462 const struct net_device *br_dev, 463 const struct net_device *vxlan_dev, u16 vid, 464 struct netlink_ext_ack *extack); 465 void mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp, 466 const struct net_device *vxlan_dev); 467 extern struct notifier_block mlxsw_sp_switchdev_notifier; 468 469 /* spectrum.c */ 470 void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb, 471 u8 local_port, void *priv); 472 int mlxsw_sp_port_speed_get(struct mlxsw_sp_port *mlxsw_sp_port, u32 *speed); 473 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port, 474 enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index, 475 bool dwrr, u8 dwrr_weight); 476 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port, 477 u8 switch_prio, u8 tclass); 478 int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu, 479 u8 *prio_tc, bool pause_en, 480 struct ieee_pfc *my_pfc); 481 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port, 482 enum mlxsw_reg_qeec_hr hr, u8 index, 483 u8 next_index, u32 maxrate, u8 burst_size); 484 enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state); 485 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid, 486 u8 state); 487 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable); 488 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid, 489 bool learn_enable); 490 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid); 491 struct mlxsw_sp_port_vlan * 492 mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid); 493 void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan); 494 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin, 495 u16 vid_end, bool is_member, bool untagged); 496 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp, 497 unsigned int counter_index, u64 *packets, 498 u64 *bytes); 499 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp, 500 unsigned int *p_counter_index); 501 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp, 502 unsigned int counter_index); 503 u32 mlxsw_sp_span_buffsize_get(struct mlxsw_sp *mlxsw_sp, int mtu, u32 speed); 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 bool mlxsw_sp_rif_exists(struct mlxsw_sp *mlxsw_sp, 567 const struct net_device *dev); 568 u16 mlxsw_sp_rif_vid(struct mlxsw_sp *mlxsw_sp, const struct net_device *dev); 569 u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp); 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 int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port, 856 struct tc_ets_qopt_offload *p); 857 int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port, 858 struct tc_tbf_qopt_offload *p); 859 860 /* spectrum_fid.c */ 861 bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index); 862 bool mlxsw_sp_fid_lag_vid_valid(const struct mlxsw_sp_fid *fid); 863 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp, 864 u16 fid_index); 865 int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex); 866 int mlxsw_sp_fid_nve_type(const struct mlxsw_sp_fid *fid, 867 enum mlxsw_sp_nve_type *p_type); 868 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_vni(struct mlxsw_sp *mlxsw_sp, 869 __be32 vni); 870 int mlxsw_sp_fid_vni(const struct mlxsw_sp_fid *fid, __be32 *vni); 871 int mlxsw_sp_fid_nve_flood_index_set(struct mlxsw_sp_fid *fid, 872 u32 nve_flood_index); 873 void mlxsw_sp_fid_nve_flood_index_clear(struct mlxsw_sp_fid *fid); 874 bool mlxsw_sp_fid_nve_flood_index_is_set(const struct mlxsw_sp_fid *fid); 875 int mlxsw_sp_fid_vni_set(struct mlxsw_sp_fid *fid, enum mlxsw_sp_nve_type type, 876 __be32 vni, int nve_ifindex); 877 void mlxsw_sp_fid_vni_clear(struct mlxsw_sp_fid *fid); 878 bool mlxsw_sp_fid_vni_is_set(const struct mlxsw_sp_fid *fid); 879 void mlxsw_sp_fid_fdb_clear_offload(const struct mlxsw_sp_fid *fid, 880 const struct net_device *nve_dev); 881 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid, 882 enum mlxsw_sp_flood_type packet_type, u8 local_port, 883 bool member); 884 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid, 885 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid); 886 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid, 887 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid); 888 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid); 889 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid); 890 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif); 891 struct mlxsw_sp_rif *mlxsw_sp_fid_rif(const struct mlxsw_sp_fid *fid); 892 enum mlxsw_sp_rif_type 893 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp, 894 enum mlxsw_sp_fid_type type); 895 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid); 896 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid); 897 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp, 898 int br_ifindex); 899 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_lookup(struct mlxsw_sp *mlxsw_sp, 900 u16 vid); 901 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_lookup(struct mlxsw_sp *mlxsw_sp, 902 int br_ifindex); 903 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp, 904 u16 rif_index); 905 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp); 906 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid); 907 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port); 908 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port); 909 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp); 910 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp); 911 912 /* spectrum_mr.c */ 913 enum mlxsw_sp_mr_route_prio { 914 MLXSW_SP_MR_ROUTE_PRIO_SG, 915 MLXSW_SP_MR_ROUTE_PRIO_STARG, 916 MLXSW_SP_MR_ROUTE_PRIO_CATCHALL, 917 __MLXSW_SP_MR_ROUTE_PRIO_MAX 918 }; 919 920 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1) 921 922 struct mlxsw_sp_mr_route_key; 923 924 struct mlxsw_sp_mr_tcam_ops { 925 size_t priv_size; 926 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv); 927 void (*fini)(void *priv); 928 size_t route_priv_size; 929 int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv, 930 void *route_priv, 931 struct mlxsw_sp_mr_route_key *key, 932 struct mlxsw_afa_block *afa_block, 933 enum mlxsw_sp_mr_route_prio prio); 934 void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv, 935 void *route_priv, 936 struct mlxsw_sp_mr_route_key *key); 937 int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv, 938 struct mlxsw_sp_mr_route_key *key, 939 struct mlxsw_afa_block *afa_block); 940 }; 941 942 /* spectrum1_mr_tcam.c */ 943 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops; 944 945 /* spectrum2_mr_tcam.c */ 946 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops; 947 948 /* spectrum_nve.c */ 949 struct mlxsw_sp_nve_params { 950 enum mlxsw_sp_nve_type type; 951 __be32 vni; 952 const struct net_device *dev; 953 }; 954 955 extern const struct mlxsw_sp_nve_ops *mlxsw_sp1_nve_ops_arr[]; 956 extern const struct mlxsw_sp_nve_ops *mlxsw_sp2_nve_ops_arr[]; 957 958 int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip, 959 enum mlxsw_sp_l3proto proto, 960 union mlxsw_sp_l3addr *addr); 961 int mlxsw_sp_nve_flood_ip_add(struct mlxsw_sp *mlxsw_sp, 962 struct mlxsw_sp_fid *fid, 963 enum mlxsw_sp_l3proto proto, 964 union mlxsw_sp_l3addr *addr); 965 void mlxsw_sp_nve_flood_ip_del(struct mlxsw_sp *mlxsw_sp, 966 struct mlxsw_sp_fid *fid, 967 enum mlxsw_sp_l3proto proto, 968 union mlxsw_sp_l3addr *addr); 969 u32 mlxsw_sp_nve_decap_tunnel_index_get(const struct mlxsw_sp *mlxsw_sp); 970 bool mlxsw_sp_nve_ipv4_route_is_decap(const struct mlxsw_sp *mlxsw_sp, 971 u32 tb_id, __be32 addr); 972 int mlxsw_sp_nve_fid_enable(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *fid, 973 struct mlxsw_sp_nve_params *params, 974 struct netlink_ext_ack *extack); 975 void mlxsw_sp_nve_fid_disable(struct mlxsw_sp *mlxsw_sp, 976 struct mlxsw_sp_fid *fid); 977 int mlxsw_sp_port_nve_init(struct mlxsw_sp_port *mlxsw_sp_port); 978 void mlxsw_sp_port_nve_fini(struct mlxsw_sp_port *mlxsw_sp_port); 979 int mlxsw_sp_nve_init(struct mlxsw_sp *mlxsw_sp); 980 void mlxsw_sp_nve_fini(struct mlxsw_sp *mlxsw_sp); 981 982 /* spectrum_nve_vxlan.c */ 983 int mlxsw_sp_nve_inc_parsing_depth_get(struct mlxsw_sp *mlxsw_sp); 984 void mlxsw_sp_nve_inc_parsing_depth_put(struct mlxsw_sp *mlxsw_sp); 985 986 /* spectrum_trap.c */ 987 int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp); 988 void mlxsw_sp_devlink_traps_fini(struct mlxsw_sp *mlxsw_sp); 989 int mlxsw_sp_trap_init(struct mlxsw_core *mlxsw_core, 990 const struct devlink_trap *trap, void *trap_ctx); 991 void mlxsw_sp_trap_fini(struct mlxsw_core *mlxsw_core, 992 const struct devlink_trap *trap, void *trap_ctx); 993 int mlxsw_sp_trap_action_set(struct mlxsw_core *mlxsw_core, 994 const struct devlink_trap *trap, 995 enum devlink_trap_action action); 996 int mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core, 997 const struct devlink_trap_group *group); 998 999 static inline struct net *mlxsw_sp_net(struct mlxsw_sp *mlxsw_sp) 1000 { 1001 return mlxsw_core_net(mlxsw_sp->core); 1002 } 1003 1004 #endif 1005