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