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