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