xref: /linux/drivers/net/ethernet/mellanox/mlxsw/spectrum.h (revision d96fc832bcb6269d96e33d506f33033d7ed08598)
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,
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 	u8 to_local_port;
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 
149 struct mlxsw_sp {
150 	struct mlxsw_sp_port **ports;
151 	struct mlxsw_core *core;
152 	const struct mlxsw_bus_info *bus_info;
153 	unsigned char base_mac[ETH_ALEN];
154 	struct mlxsw_sp_upper *lags;
155 	int *port_to_module;
156 	struct mlxsw_sp_sb *sb;
157 	struct mlxsw_sp_bridge *bridge;
158 	struct mlxsw_sp_router *router;
159 	struct mlxsw_sp_mr *mr;
160 	struct mlxsw_afa *afa;
161 	struct mlxsw_sp_acl *acl;
162 	struct mlxsw_sp_fid_core *fid_core;
163 	struct mlxsw_sp_kvdl *kvdl;
164 	struct notifier_block netdevice_nb;
165 
166 	struct mlxsw_sp_counter_pool *counter_pool;
167 	struct {
168 		struct mlxsw_sp_span_entry *entries;
169 		int entries_count;
170 	} span;
171 };
172 
173 static inline struct mlxsw_sp_upper *
174 mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
175 {
176 	return &mlxsw_sp->lags[lag_id];
177 }
178 
179 struct mlxsw_sp_port_pcpu_stats {
180 	u64			rx_packets;
181 	u64			rx_bytes;
182 	u64			tx_packets;
183 	u64			tx_bytes;
184 	struct u64_stats_sync	syncp;
185 	u32			tx_dropped;
186 };
187 
188 struct mlxsw_sp_port_sample {
189 	struct psample_group __rcu *psample_group;
190 	u32 trunc_size;
191 	u32 rate;
192 	bool truncate;
193 };
194 
195 struct mlxsw_sp_bridge_port;
196 struct mlxsw_sp_fid;
197 
198 struct mlxsw_sp_port_vlan {
199 	struct list_head list;
200 	struct mlxsw_sp_port *mlxsw_sp_port;
201 	struct mlxsw_sp_fid *fid;
202 	u16 vid;
203 	struct mlxsw_sp_bridge_port *bridge_port;
204 	struct list_head bridge_vlan_node;
205 };
206 
207 /* No need an internal lock; At worse - miss a single periodic iteration */
208 struct mlxsw_sp_port_xstats {
209 	u64 ecn;
210 	u64 wred_drop[TC_MAX_QUEUE];
211 	u64 tail_drop[TC_MAX_QUEUE];
212 	u64 backlog[TC_MAX_QUEUE];
213 };
214 
215 struct mlxsw_sp_port {
216 	struct net_device *dev;
217 	struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
218 	struct mlxsw_sp *mlxsw_sp;
219 	u8 local_port;
220 	u8 lagged:1,
221 	   split:1;
222 	u16 pvid;
223 	u16 lag_id;
224 	struct {
225 		u8 tx_pause:1,
226 		   rx_pause:1,
227 		   autoneg:1;
228 	} link;
229 	struct {
230 		struct ieee_ets *ets;
231 		struct ieee_maxrate *maxrate;
232 		struct ieee_pfc *pfc;
233 	} dcb;
234 	struct {
235 		u8 module;
236 		u8 width;
237 		u8 lane;
238 	} mapping;
239 	/* TC handles */
240 	struct list_head mall_tc_list;
241 	struct {
242 		#define MLXSW_HW_STATS_UPDATE_TIME HZ
243 		struct rtnl_link_stats64 stats;
244 		struct mlxsw_sp_port_xstats xstats;
245 		struct delayed_work update_dw;
246 	} periodic_hw_stats;
247 	struct mlxsw_sp_port_sample *sample;
248 	struct list_head vlans_list;
249 	struct mlxsw_sp_qdisc *root_qdisc;
250 	unsigned acl_rule_count;
251 	struct mlxsw_sp_acl_block *ing_acl_block;
252 	struct mlxsw_sp_acl_block *eg_acl_block;
253 };
254 
255 static inline bool
256 mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
257 {
258 	return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
259 }
260 
261 static inline struct mlxsw_sp_port *
262 mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
263 {
264 	struct mlxsw_sp_port *mlxsw_sp_port;
265 	u8 local_port;
266 
267 	local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
268 						lag_id, port_index);
269 	mlxsw_sp_port = mlxsw_sp->ports[local_port];
270 	return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
271 }
272 
273 static inline struct mlxsw_sp_port_vlan *
274 mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
275 			       u16 vid)
276 {
277 	struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
278 
279 	list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
280 			    list) {
281 		if (mlxsw_sp_port_vlan->vid == vid)
282 			return mlxsw_sp_port_vlan;
283 	}
284 
285 	return NULL;
286 }
287 
288 enum mlxsw_sp_flood_type {
289 	MLXSW_SP_FLOOD_TYPE_UC,
290 	MLXSW_SP_FLOOD_TYPE_BC,
291 	MLXSW_SP_FLOOD_TYPE_MC,
292 };
293 
294 /* spectrum_buffers.c */
295 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
296 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
297 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
298 int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
299 			 unsigned int sb_index, u16 pool_index,
300 			 struct devlink_sb_pool_info *pool_info);
301 int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
302 			 unsigned int sb_index, u16 pool_index, u32 size,
303 			 enum devlink_sb_threshold_type threshold_type);
304 int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
305 			      unsigned int sb_index, u16 pool_index,
306 			      u32 *p_threshold);
307 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
308 			      unsigned int sb_index, u16 pool_index,
309 			      u32 threshold);
310 int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
311 				 unsigned int sb_index, u16 tc_index,
312 				 enum devlink_sb_pool_type pool_type,
313 				 u16 *p_pool_index, u32 *p_threshold);
314 int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
315 				 unsigned int sb_index, u16 tc_index,
316 				 enum devlink_sb_pool_type pool_type,
317 				 u16 pool_index, u32 threshold);
318 int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
319 			     unsigned int sb_index);
320 int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
321 			      unsigned int sb_index);
322 int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
323 				  unsigned int sb_index, u16 pool_index,
324 				  u32 *p_cur, u32 *p_max);
325 int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
326 				     unsigned int sb_index, u16 tc_index,
327 				     enum devlink_sb_pool_type pool_type,
328 				     u32 *p_cur, u32 *p_max);
329 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
330 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
331 
332 /* spectrum_switchdev.c */
333 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
334 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
335 void mlxsw_sp_port_switchdev_init(struct mlxsw_sp_port *mlxsw_sp_port);
336 void mlxsw_sp_port_switchdev_fini(struct mlxsw_sp_port *mlxsw_sp_port);
337 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
338 			bool adding);
339 void
340 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
341 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
342 			      struct net_device *brport_dev,
343 			      struct net_device *br_dev,
344 			      struct netlink_ext_ack *extack);
345 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
346 				struct net_device *brport_dev,
347 				struct net_device *br_dev);
348 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
349 					 const struct net_device *br_dev);
350 
351 /* spectrum.c */
352 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
353 			  enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
354 			  bool dwrr, u8 dwrr_weight);
355 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
356 			      u8 switch_prio, u8 tclass);
357 int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
358 				 u8 *prio_tc, bool pause_en,
359 				 struct ieee_pfc *my_pfc);
360 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
361 				  enum mlxsw_reg_qeec_hr hr, u8 index,
362 				  u8 next_index, u32 maxrate);
363 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
364 			      u8 state);
365 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
366 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
367 				   bool learn_enable);
368 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
369 struct mlxsw_sp_port_vlan *
370 mlxsw_sp_port_vlan_get(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
371 void mlxsw_sp_port_vlan_put(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
372 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
373 			   u16 vid_end, bool is_member, bool untagged);
374 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
375 			      unsigned int counter_index, u64 *packets,
376 			      u64 *bytes);
377 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
378 				unsigned int *p_counter_index);
379 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
380 				unsigned int counter_index);
381 bool mlxsw_sp_port_dev_check(const struct net_device *dev);
382 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
383 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
384 struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
385 void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
386 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
387 
388 /* spectrum_dcb.c */
389 #ifdef CONFIG_MLXSW_SPECTRUM_DCB
390 int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
391 void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
392 #else
393 static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
394 {
395 	return 0;
396 }
397 static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
398 {}
399 #endif
400 
401 /* spectrum_router.c */
402 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp);
403 void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
404 int mlxsw_sp_netdevice_router_port_event(struct net_device *dev);
405 int mlxsw_sp_inetaddr_event(struct notifier_block *unused,
406 			    unsigned long event, void *ptr);
407 int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
408 				  unsigned long event, void *ptr);
409 int mlxsw_sp_inet6addr_event(struct notifier_block *unused,
410 			     unsigned long event, void *ptr);
411 int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
412 				   unsigned long event, void *ptr);
413 int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
414 				 struct netdev_notifier_changeupper_info *info);
415 bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp,
416 				const struct net_device *dev);
417 bool mlxsw_sp_netdev_is_ipip_ul(const struct mlxsw_sp *mlxsw_sp,
418 				const struct net_device *dev);
419 int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,
420 				     struct net_device *l3_dev,
421 				     unsigned long event,
422 				     struct netdev_notifier_info *info);
423 int
424 mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
425 				 struct net_device *l3_dev,
426 				 unsigned long event,
427 				 struct netdev_notifier_info *info);
428 void
429 mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
430 void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif);
431 
432 /* spectrum_kvdl.c */
433 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
434 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
435 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, unsigned int entry_count,
436 			u32 *p_entry_index);
437 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp, int entry_index);
438 int mlxsw_sp_kvdl_alloc_size_query(struct mlxsw_sp *mlxsw_sp,
439 				   unsigned int entry_count,
440 				   unsigned int *p_alloc_size);
441 u64 mlxsw_sp_kvdl_occ_get(const struct mlxsw_sp *mlxsw_sp);
442 int mlxsw_sp_kvdl_resources_register(struct devlink *devlink);
443 
444 struct mlxsw_sp_acl_rule_info {
445 	unsigned int priority;
446 	struct mlxsw_afk_element_values values;
447 	struct mlxsw_afa_block *act_block;
448 	unsigned int counter_index;
449 };
450 
451 enum mlxsw_sp_acl_profile {
452 	MLXSW_SP_ACL_PROFILE_FLOWER,
453 };
454 
455 struct mlxsw_sp_acl_profile_ops {
456 	size_t ruleset_priv_size;
457 	int (*ruleset_add)(struct mlxsw_sp *mlxsw_sp,
458 			   void *priv, void *ruleset_priv);
459 	void (*ruleset_del)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv);
460 	int (*ruleset_bind)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv,
461 			    struct mlxsw_sp_port *mlxsw_sp_port,
462 			    bool ingress);
463 	void (*ruleset_unbind)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv,
464 			       struct mlxsw_sp_port *mlxsw_sp_port,
465 			       bool ingress);
466 	u16 (*ruleset_group_id)(void *ruleset_priv);
467 	size_t rule_priv_size;
468 	int (*rule_add)(struct mlxsw_sp *mlxsw_sp,
469 			void *ruleset_priv, void *rule_priv,
470 			struct mlxsw_sp_acl_rule_info *rulei);
471 	void (*rule_del)(struct mlxsw_sp *mlxsw_sp, void *rule_priv);
472 	int (*rule_activity_get)(struct mlxsw_sp *mlxsw_sp, void *rule_priv,
473 				 bool *activity);
474 };
475 
476 struct mlxsw_sp_acl_ops {
477 	size_t priv_size;
478 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
479 	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
480 	const struct mlxsw_sp_acl_profile_ops *
481 			(*profile_ops)(struct mlxsw_sp *mlxsw_sp,
482 				       enum mlxsw_sp_acl_profile profile);
483 };
484 
485 struct mlxsw_sp_acl_block;
486 struct mlxsw_sp_acl_ruleset;
487 
488 /* spectrum_acl.c */
489 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
490 struct mlxsw_sp *mlxsw_sp_acl_block_mlxsw_sp(struct mlxsw_sp_acl_block *block);
491 unsigned int mlxsw_sp_acl_block_rule_count(struct mlxsw_sp_acl_block *block);
492 void mlxsw_sp_acl_block_disable_inc(struct mlxsw_sp_acl_block *block);
493 void mlxsw_sp_acl_block_disable_dec(struct mlxsw_sp_acl_block *block);
494 bool mlxsw_sp_acl_block_disabled(struct mlxsw_sp_acl_block *block);
495 struct mlxsw_sp_acl_block *mlxsw_sp_acl_block_create(struct mlxsw_sp *mlxsw_sp,
496 						     struct net *net);
497 void mlxsw_sp_acl_block_destroy(struct mlxsw_sp_acl_block *block);
498 int mlxsw_sp_acl_block_bind(struct mlxsw_sp *mlxsw_sp,
499 			    struct mlxsw_sp_acl_block *block,
500 			    struct mlxsw_sp_port *mlxsw_sp_port,
501 			    bool ingress);
502 int mlxsw_sp_acl_block_unbind(struct mlxsw_sp *mlxsw_sp,
503 			      struct mlxsw_sp_acl_block *block,
504 			      struct mlxsw_sp_port *mlxsw_sp_port,
505 			      bool ingress);
506 struct mlxsw_sp_acl_ruleset *
507 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
508 			    struct mlxsw_sp_acl_block *block, u32 chain_index,
509 			    enum mlxsw_sp_acl_profile profile);
510 struct mlxsw_sp_acl_ruleset *
511 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
512 			 struct mlxsw_sp_acl_block *block, u32 chain_index,
513 			 enum mlxsw_sp_acl_profile profile);
514 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
515 			      struct mlxsw_sp_acl_ruleset *ruleset);
516 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
517 
518 struct mlxsw_sp_acl_rule_info *
519 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl);
520 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
521 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
522 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
523 				 unsigned int priority);
524 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
525 				    enum mlxsw_afk_element element,
526 				    u32 key_value, u32 mask_value);
527 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
528 				    enum mlxsw_afk_element element,
529 				    const char *key_value,
530 				    const char *mask_value, unsigned int len);
531 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
532 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
533 				u16 group_id);
534 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei);
535 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
536 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
537 				  struct mlxsw_sp_acl_rule_info *rulei,
538 				  struct mlxsw_sp_acl_block *block,
539 				  struct net_device *out_dev);
540 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
541 			       struct mlxsw_sp_acl_rule_info *rulei,
542 			       struct net_device *out_dev);
543 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
544 				struct mlxsw_sp_acl_rule_info *rulei,
545 				u32 action, u16 vid, u16 proto, u8 prio);
546 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
547 				 struct mlxsw_sp_acl_rule_info *rulei);
548 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
549 				   struct mlxsw_sp_acl_rule_info *rulei,
550 				   u16 fid);
551 
552 struct mlxsw_sp_acl_rule;
553 
554 struct mlxsw_sp_acl_rule *
555 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
556 			 struct mlxsw_sp_acl_ruleset *ruleset,
557 			 unsigned long cookie);
558 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
559 			       struct mlxsw_sp_acl_rule *rule);
560 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
561 			  struct mlxsw_sp_acl_rule *rule);
562 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
563 			   struct mlxsw_sp_acl_rule *rule);
564 struct mlxsw_sp_acl_rule *
565 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
566 			 struct mlxsw_sp_acl_ruleset *ruleset,
567 			 unsigned long cookie);
568 struct mlxsw_sp_acl_rule_info *
569 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
570 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
571 				struct mlxsw_sp_acl_rule *rule,
572 				u64 *packets, u64 *bytes, u64 *last_use);
573 
574 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
575 
576 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
577 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
578 
579 /* spectrum_acl_tcam.c */
580 extern const struct mlxsw_sp_acl_ops mlxsw_sp_acl_tcam_ops;
581 
582 /* spectrum_flower.c */
583 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
584 			    struct mlxsw_sp_acl_block *block,
585 			    struct tc_cls_flower_offload *f);
586 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
587 			     struct mlxsw_sp_acl_block *block,
588 			     struct tc_cls_flower_offload *f);
589 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
590 			  struct mlxsw_sp_acl_block *block,
591 			  struct tc_cls_flower_offload *f);
592 
593 /* spectrum_qdisc.c */
594 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
595 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
596 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
597 			  struct tc_red_qopt_offload *p);
598 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
599 			   struct tc_prio_qopt_offload *p);
600 
601 /* spectrum_fid.c */
602 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
603 			   enum mlxsw_sp_flood_type packet_type, u8 local_port,
604 			   bool member);
605 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
606 			      struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
607 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
608 				 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
609 enum mlxsw_sp_rif_type mlxsw_sp_fid_rif_type(const struct mlxsw_sp_fid *fid);
610 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
611 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
612 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
613 enum mlxsw_sp_rif_type
614 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
615 			   enum mlxsw_sp_fid_type type);
616 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
617 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
618 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
619 					    int br_ifindex);
620 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
621 					   u16 rif_index);
622 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
623 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
624 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
625 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
626 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
627 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
628 
629 #endif
630