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>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
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.
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.
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.
37 #ifndef _MLXSW_SPECTRUM_H
38 #define _MLXSW_SPECTRUM_H
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>
55 #include "core_acl_flex_keys.h"
56 #include "core_acl_flex_actions.h"
58 #define MLXSW_SP_FID_8021D_MAX 1024
60 #define MLXSW_SP_MID_MAX 7000
62 #define MLXSW_SP_PORTS_PER_CLUSTER_MAX 4
64 #define MLXSW_SP_PORT_BASE_SPEED 25000 /* Mb/s */
66 #define MLXSW_SP_KVD_LINEAR_SIZE 98304 /* entries */
67 #define MLXSW_SP_KVD_GRANULARITY 128
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"
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,
89 struct mlxsw_sp_span_entry;
91 struct mlxsw_sp_upper {
92 struct net_device *dev;
93 unsigned int ref_count;
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,
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,
112 struct mlxsw_sp_mid {
113 struct list_head list;
114 unsigned char addr[ETH_ALEN];
118 unsigned long *ports_in_mid; /* bits array */
121 enum mlxsw_sp_port_mall_action_type {
122 MLXSW_SP_PORT_MALL_MIRROR,
123 MLXSW_SP_PORT_MALL_SAMPLE,
126 struct mlxsw_sp_port_mall_mirror_tc_entry {
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;
136 struct mlxsw_sp_port_mall_mirror_tc_entry mirror;
141 struct mlxsw_sp_bridge;
142 struct mlxsw_sp_router;
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;
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;
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;
169 struct mlxsw_sp_counter_pool *counter_pool;
171 struct mlxsw_sp_span_entry *entries;
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;
183 static inline struct mlxsw_sp_upper *
184 mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
186 return &mlxsw_sp->lags[lag_id];
189 struct mlxsw_sp_port_pcpu_stats {
194 struct u64_stats_sync syncp;
198 struct mlxsw_sp_port_sample {
199 struct psample_group __rcu *psample_group;
205 struct mlxsw_sp_bridge_port;
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;
214 struct mlxsw_sp_bridge_port *bridge_port;
215 struct list_head bridge_vlan_node;
218 /* No need an internal lock; At worse - miss a single periodic iteration */
219 struct mlxsw_sp_port_xstats {
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];
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;
243 struct ieee_ets *ets;
244 struct ieee_maxrate *maxrate;
245 struct ieee_pfc *pfc;
253 struct list_head mall_tc_list;
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;
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;
270 mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
272 return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
275 static inline struct mlxsw_sp_port *
276 mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
278 struct mlxsw_sp_port *mlxsw_sp_port;
281 local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
283 mlxsw_sp_port = mlxsw_sp->ports[local_port];
284 return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
287 static inline struct mlxsw_sp_port_vlan *
288 mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
291 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
293 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
295 if (mlxsw_sp_port_vlan->vid == vid)
296 return mlxsw_sp_port_vlan;
302 enum mlxsw_sp_flood_type {
303 MLXSW_SP_FLOOD_TYPE_UC,
304 MLXSW_SP_FLOOD_TYPE_BC,
305 MLXSW_SP_FLOOD_TYPE_MC,
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,
321 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
322 unsigned int sb_index, u16 pool_index,
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);
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,
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);
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,
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,
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,
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);
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);
408 static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
412 static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
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,
439 struct netdev_notifier_info *info);
441 mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
442 struct net_device *l3_dev,
444 struct netdev_notifier_info *info);
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);
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,
457 static inline unsigned int
458 mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type 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 */
470 struct mlxsw_sp_kvdl_ops {
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);
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);
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);
504 struct mlxsw_sp_acl_rule_info {
505 unsigned int priority;
506 struct mlxsw_afk_element_values values;
507 struct mlxsw_afa_block *act_block;
508 unsigned int counter_index;
511 struct mlxsw_sp_acl_block;
512 struct mlxsw_sp_acl_ruleset;
515 enum mlxsw_sp_acl_profile {
516 MLXSW_SP_ACL_PROFILE_FLOWER,
519 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
520 struct mlxsw_sp *mlxsw_sp_acl_block_mlxsw_sp(struct mlxsw_sp_acl_block *block);
521 unsigned int mlxsw_sp_acl_block_rule_count(struct mlxsw_sp_acl_block *block);
522 void mlxsw_sp_acl_block_disable_inc(struct mlxsw_sp_acl_block *block);
523 void mlxsw_sp_acl_block_disable_dec(struct mlxsw_sp_acl_block *block);
524 bool mlxsw_sp_acl_block_disabled(struct mlxsw_sp_acl_block *block);
525 struct mlxsw_sp_acl_block *mlxsw_sp_acl_block_create(struct mlxsw_sp *mlxsw_sp,
527 void mlxsw_sp_acl_block_destroy(struct mlxsw_sp_acl_block *block);
528 int mlxsw_sp_acl_block_bind(struct mlxsw_sp *mlxsw_sp,
529 struct mlxsw_sp_acl_block *block,
530 struct mlxsw_sp_port *mlxsw_sp_port,
532 int mlxsw_sp_acl_block_unbind(struct mlxsw_sp *mlxsw_sp,
533 struct mlxsw_sp_acl_block *block,
534 struct mlxsw_sp_port *mlxsw_sp_port,
536 struct mlxsw_sp_acl_ruleset *
537 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
538 struct mlxsw_sp_acl_block *block, u32 chain_index,
539 enum mlxsw_sp_acl_profile profile);
540 struct mlxsw_sp_acl_ruleset *
541 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
542 struct mlxsw_sp_acl_block *block, u32 chain_index,
543 enum mlxsw_sp_acl_profile profile);
544 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
545 struct mlxsw_sp_acl_ruleset *ruleset);
546 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
548 struct mlxsw_sp_acl_rule_info *
549 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl);
550 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
551 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
552 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
553 unsigned int priority);
554 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
555 enum mlxsw_afk_element element,
556 u32 key_value, u32 mask_value);
557 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
558 enum mlxsw_afk_element element,
559 const char *key_value,
560 const char *mask_value, unsigned int len);
561 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
562 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
564 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
565 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei);
566 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
567 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
568 struct mlxsw_sp_acl_rule_info *rulei,
569 struct mlxsw_sp_acl_block *block,
570 struct net_device *out_dev);
571 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
572 struct mlxsw_sp_acl_rule_info *rulei,
573 struct net_device *out_dev);
574 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
575 struct mlxsw_sp_acl_rule_info *rulei,
576 u32 action, u16 vid, u16 proto, u8 prio);
577 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
578 struct mlxsw_sp_acl_rule_info *rulei);
579 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
580 struct mlxsw_sp_acl_rule_info *rulei,
583 struct mlxsw_sp_acl_rule;
585 struct mlxsw_sp_acl_rule *
586 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
587 struct mlxsw_sp_acl_ruleset *ruleset,
588 unsigned long cookie);
589 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
590 struct mlxsw_sp_acl_rule *rule);
591 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
592 struct mlxsw_sp_acl_rule *rule);
593 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
594 struct mlxsw_sp_acl_rule *rule);
595 struct mlxsw_sp_acl_rule *
596 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
597 struct mlxsw_sp_acl_ruleset *ruleset,
598 unsigned long cookie);
599 struct mlxsw_sp_acl_rule_info *
600 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
601 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
602 struct mlxsw_sp_acl_rule *rule,
603 u64 *packets, u64 *bytes, u64 *last_use);
605 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
607 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
608 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
610 /* spectrum_acl_tcam.c */
611 struct mlxsw_sp_acl_tcam;
612 struct mlxsw_sp_acl_tcam_region;
614 struct mlxsw_sp_acl_tcam_ops {
615 enum mlxsw_reg_ptar_key_type key_type;
617 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv,
618 struct mlxsw_sp_acl_tcam *tcam);
619 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
620 size_t region_priv_size;
621 int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv,
622 struct mlxsw_sp_acl_tcam_region *region);
623 void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
624 size_t chunk_priv_size;
625 void (*chunk_init)(void *region_priv, void *chunk_priv,
626 unsigned int priority);
627 void (*chunk_fini)(void *chunk_priv);
628 size_t entry_priv_size;
629 int (*entry_add)(struct mlxsw_sp *mlxsw_sp,
630 void *region_priv, void *chunk_priv,
632 struct mlxsw_sp_acl_rule_info *rulei);
633 void (*entry_del)(struct mlxsw_sp *mlxsw_sp,
634 void *region_priv, void *chunk_priv,
636 int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp,
637 void *region_priv, void *entry_priv,
641 /* spectrum1_acl_tcam.c */
642 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops;
644 /* spectrum_acl_flex_actions.c */
645 extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops;
647 /* spectrum_acl_flex_keys.c */
648 extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
650 /* spectrum_flower.c */
651 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
652 struct mlxsw_sp_acl_block *block,
653 struct tc_cls_flower_offload *f);
654 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
655 struct mlxsw_sp_acl_block *block,
656 struct tc_cls_flower_offload *f);
657 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
658 struct mlxsw_sp_acl_block *block,
659 struct tc_cls_flower_offload *f);
661 /* spectrum_qdisc.c */
662 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
663 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
664 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
665 struct tc_red_qopt_offload *p);
666 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
667 struct tc_prio_qopt_offload *p);
670 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
671 enum mlxsw_sp_flood_type packet_type, u8 local_port,
673 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
674 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
675 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
676 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
677 enum mlxsw_sp_rif_type mlxsw_sp_fid_rif_type(const struct mlxsw_sp_fid *fid);
678 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
679 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
680 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
681 enum mlxsw_sp_rif_type
682 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
683 enum mlxsw_sp_fid_type type);
684 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
685 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
686 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
688 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
690 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
691 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
692 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
693 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
694 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
695 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
698 enum mlxsw_sp_mr_route_prio {
699 MLXSW_SP_MR_ROUTE_PRIO_SG,
700 MLXSW_SP_MR_ROUTE_PRIO_STARG,
701 MLXSW_SP_MR_ROUTE_PRIO_CATCHALL,
702 __MLXSW_SP_MR_ROUTE_PRIO_MAX
705 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
707 struct mlxsw_sp_mr_route_key;
709 struct mlxsw_sp_mr_tcam_ops {
711 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
712 void (*fini)(void *priv);
713 size_t route_priv_size;
714 int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
716 struct mlxsw_sp_mr_route_key *key,
717 struct mlxsw_afa_block *afa_block,
718 enum mlxsw_sp_mr_route_prio prio);
719 void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
721 struct mlxsw_sp_mr_route_key *key);
722 int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
723 struct mlxsw_sp_mr_route_key *key,
724 struct mlxsw_afa_block *afa_block);
727 /* spectrum1_mr_tcam.c */
728 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops;