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