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