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