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