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 void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp, 418 struct net_device *dev); 419 420 /* spectrum_kvdl.c */ 421 enum mlxsw_sp_kvdl_entry_type { 422 MLXSW_SP_KVDL_ENTRY_TYPE_ADJ, 423 MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET, 424 MLXSW_SP_KVDL_ENTRY_TYPE_PBS, 425 MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR, 426 }; 427 428 static inline unsigned int 429 mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type) 430 { 431 switch (type) { 432 case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ: /* fall through */ 433 case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET: /* fall through */ 434 case MLXSW_SP_KVDL_ENTRY_TYPE_PBS: /* fall through */ 435 case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR: /* fall through */ 436 default: 437 return 1; 438 } 439 } 440 441 struct mlxsw_sp_kvdl_ops { 442 size_t priv_size; 443 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv); 444 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv); 445 int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv, 446 enum mlxsw_sp_kvdl_entry_type type, 447 unsigned int entry_count, u32 *p_entry_index); 448 void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv, 449 enum mlxsw_sp_kvdl_entry_type type, 450 unsigned int entry_count, int entry_index); 451 int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv, 452 enum mlxsw_sp_kvdl_entry_type type, 453 unsigned int entry_count, 454 unsigned int *p_alloc_count); 455 int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv); 456 }; 457 458 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp); 459 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp); 460 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, 461 enum mlxsw_sp_kvdl_entry_type type, 462 unsigned int entry_count, u32 *p_entry_index); 463 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp, 464 enum mlxsw_sp_kvdl_entry_type type, 465 unsigned int entry_count, int entry_index); 466 int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp, 467 enum mlxsw_sp_kvdl_entry_type type, 468 unsigned int entry_count, 469 unsigned int *p_alloc_count); 470 471 /* spectrum1_kvdl.c */ 472 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops; 473 int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core); 474 475 /* spectrum2_kvdl.c */ 476 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops; 477 478 struct mlxsw_sp_acl_rule_info { 479 unsigned int priority; 480 struct mlxsw_afk_element_values values; 481 struct mlxsw_afa_block *act_block; 482 unsigned int counter_index; 483 }; 484 485 struct mlxsw_sp_acl_block; 486 struct mlxsw_sp_acl_ruleset; 487 488 /* spectrum_acl.c */ 489 enum mlxsw_sp_acl_profile { 490 MLXSW_SP_ACL_PROFILE_FLOWER, 491 }; 492 493 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl); 494 struct mlxsw_sp *mlxsw_sp_acl_block_mlxsw_sp(struct mlxsw_sp_acl_block *block); 495 unsigned int mlxsw_sp_acl_block_rule_count(struct mlxsw_sp_acl_block *block); 496 void mlxsw_sp_acl_block_disable_inc(struct mlxsw_sp_acl_block *block); 497 void mlxsw_sp_acl_block_disable_dec(struct mlxsw_sp_acl_block *block); 498 bool mlxsw_sp_acl_block_disabled(struct mlxsw_sp_acl_block *block); 499 struct mlxsw_sp_acl_block *mlxsw_sp_acl_block_create(struct mlxsw_sp *mlxsw_sp, 500 struct net *net); 501 void mlxsw_sp_acl_block_destroy(struct mlxsw_sp_acl_block *block); 502 int mlxsw_sp_acl_block_bind(struct mlxsw_sp *mlxsw_sp, 503 struct mlxsw_sp_acl_block *block, 504 struct mlxsw_sp_port *mlxsw_sp_port, 505 bool ingress); 506 int mlxsw_sp_acl_block_unbind(struct mlxsw_sp *mlxsw_sp, 507 struct mlxsw_sp_acl_block *block, 508 struct mlxsw_sp_port *mlxsw_sp_port, 509 bool ingress); 510 bool mlxsw_sp_acl_block_is_egress_bound(struct mlxsw_sp_acl_block *block); 511 struct mlxsw_sp_acl_ruleset * 512 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp, 513 struct mlxsw_sp_acl_block *block, u32 chain_index, 514 enum mlxsw_sp_acl_profile profile); 515 struct mlxsw_sp_acl_ruleset * 516 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp, 517 struct mlxsw_sp_acl_block *block, u32 chain_index, 518 enum mlxsw_sp_acl_profile profile, 519 struct mlxsw_afk_element_usage *tmplt_elusage); 520 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp, 521 struct mlxsw_sp_acl_ruleset *ruleset); 522 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset); 523 524 struct mlxsw_sp_acl_rule_info * 525 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl); 526 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei); 527 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei); 528 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei, 529 unsigned int priority); 530 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei, 531 enum mlxsw_afk_element element, 532 u32 key_value, u32 mask_value); 533 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei, 534 enum mlxsw_afk_element element, 535 const char *key_value, 536 const char *mask_value, unsigned int len); 537 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei); 538 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei, 539 u16 group_id); 540 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei); 541 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei); 542 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei); 543 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp, 544 struct mlxsw_sp_acl_rule_info *rulei, 545 struct mlxsw_sp_acl_block *block, 546 struct net_device *out_dev, 547 struct netlink_ext_ack *extack); 548 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp, 549 struct mlxsw_sp_acl_rule_info *rulei, 550 struct net_device *out_dev, 551 struct netlink_ext_ack *extack); 552 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp, 553 struct mlxsw_sp_acl_rule_info *rulei, 554 u32 action, u16 vid, u16 proto, u8 prio, 555 struct netlink_ext_ack *extack); 556 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp, 557 struct mlxsw_sp_acl_rule_info *rulei, 558 struct netlink_ext_ack *extack); 559 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp, 560 struct mlxsw_sp_acl_rule_info *rulei, 561 u16 fid, struct netlink_ext_ack *extack); 562 563 struct mlxsw_sp_acl_rule; 564 565 struct mlxsw_sp_acl_rule * 566 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp, 567 struct mlxsw_sp_acl_ruleset *ruleset, 568 unsigned long cookie, 569 struct netlink_ext_ack *extack); 570 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp, 571 struct mlxsw_sp_acl_rule *rule); 572 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp, 573 struct mlxsw_sp_acl_rule *rule); 574 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp, 575 struct mlxsw_sp_acl_rule *rule); 576 struct mlxsw_sp_acl_rule * 577 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp, 578 struct mlxsw_sp_acl_ruleset *ruleset, 579 unsigned long cookie); 580 struct mlxsw_sp_acl_rule_info * 581 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule); 582 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp, 583 struct mlxsw_sp_acl_rule *rule, 584 u64 *packets, u64 *bytes, u64 *last_use); 585 586 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp); 587 588 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp); 589 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp); 590 591 /* spectrum_acl_tcam.c */ 592 struct mlxsw_sp_acl_tcam; 593 struct mlxsw_sp_acl_tcam_region; 594 595 struct mlxsw_sp_acl_tcam_ops { 596 enum mlxsw_reg_ptar_key_type key_type; 597 size_t priv_size; 598 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv, 599 struct mlxsw_sp_acl_tcam *tcam); 600 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv); 601 size_t region_priv_size; 602 int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv, 603 void *tcam_priv, 604 struct mlxsw_sp_acl_tcam_region *region); 605 void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv); 606 int (*region_associate)(struct mlxsw_sp *mlxsw_sp, 607 struct mlxsw_sp_acl_tcam_region *region); 608 size_t chunk_priv_size; 609 void (*chunk_init)(void *region_priv, void *chunk_priv, 610 unsigned int priority); 611 void (*chunk_fini)(void *chunk_priv); 612 size_t entry_priv_size; 613 int (*entry_add)(struct mlxsw_sp *mlxsw_sp, 614 void *region_priv, void *chunk_priv, 615 void *entry_priv, 616 struct mlxsw_sp_acl_rule_info *rulei); 617 void (*entry_del)(struct mlxsw_sp *mlxsw_sp, 618 void *region_priv, void *chunk_priv, 619 void *entry_priv); 620 int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp, 621 void *region_priv, void *entry_priv, 622 bool *activity); 623 }; 624 625 /* spectrum1_acl_tcam.c */ 626 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops; 627 628 /* spectrum2_acl_tcam.c */ 629 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops; 630 631 /* spectrum_acl_flex_actions.c */ 632 extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops; 633 extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops; 634 635 /* spectrum_acl_flex_keys.c */ 636 extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops; 637 extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops; 638 639 /* spectrum_flower.c */ 640 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp, 641 struct mlxsw_sp_acl_block *block, 642 struct tc_cls_flower_offload *f); 643 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp, 644 struct mlxsw_sp_acl_block *block, 645 struct tc_cls_flower_offload *f); 646 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp, 647 struct mlxsw_sp_acl_block *block, 648 struct tc_cls_flower_offload *f); 649 int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp, 650 struct mlxsw_sp_acl_block *block, 651 struct tc_cls_flower_offload *f); 652 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp, 653 struct mlxsw_sp_acl_block *block, 654 struct tc_cls_flower_offload *f); 655 656 /* spectrum_qdisc.c */ 657 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port); 658 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port); 659 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port, 660 struct tc_red_qopt_offload *p); 661 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port, 662 struct tc_prio_qopt_offload *p); 663 664 /* spectrum_fid.c */ 665 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid, 666 enum mlxsw_sp_flood_type packet_type, u8 local_port, 667 bool member); 668 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid, 669 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid); 670 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid, 671 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid); 672 enum mlxsw_sp_rif_type mlxsw_sp_fid_rif_type(const struct mlxsw_sp_fid *fid); 673 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid); 674 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid); 675 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif); 676 enum mlxsw_sp_rif_type 677 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp, 678 enum mlxsw_sp_fid_type type); 679 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid); 680 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid); 681 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp, 682 int br_ifindex); 683 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp, 684 u16 rif_index); 685 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp); 686 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid); 687 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port); 688 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port); 689 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp); 690 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp); 691 692 /* spectrum_mr.c */ 693 enum mlxsw_sp_mr_route_prio { 694 MLXSW_SP_MR_ROUTE_PRIO_SG, 695 MLXSW_SP_MR_ROUTE_PRIO_STARG, 696 MLXSW_SP_MR_ROUTE_PRIO_CATCHALL, 697 __MLXSW_SP_MR_ROUTE_PRIO_MAX 698 }; 699 700 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1) 701 702 struct mlxsw_sp_mr_route_key; 703 704 struct mlxsw_sp_mr_tcam_ops { 705 size_t priv_size; 706 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv); 707 void (*fini)(void *priv); 708 size_t route_priv_size; 709 int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv, 710 void *route_priv, 711 struct mlxsw_sp_mr_route_key *key, 712 struct mlxsw_afa_block *afa_block, 713 enum mlxsw_sp_mr_route_prio prio); 714 void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv, 715 void *route_priv, 716 struct mlxsw_sp_mr_route_key *key); 717 int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv, 718 struct mlxsw_sp_mr_route_key *key, 719 struct mlxsw_afa_block *afa_block); 720 }; 721 722 /* spectrum1_mr_tcam.c */ 723 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops; 724 725 /* spectrum2_mr_tcam.c */ 726 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops; 727 728 #endif 729