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