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