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