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