xref: /linux/drivers/net/ethernet/mellanox/mlxsw/spectrum.h (revision ba95c7452439756d4f6dceb5a188b7c31dbbe5b6)
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_bridge.h>
12 #include <linux/if_vlan.h>
13 #include <linux/list.h>
14 #include <linux/dcbnl.h>
15 #include <linux/in6.h>
16 #include <linux/notifier.h>
17 #include <net/psample.h>
18 #include <net/pkt_cls.h>
19 #include <net/red.h>
20 #include <net/vxlan.h>
21 
22 #include "port.h"
23 #include "core.h"
24 #include "core_acl_flex_keys.h"
25 #include "core_acl_flex_actions.h"
26 #include "reg.h"
27 
28 #define MLXSW_SP_DEFAULT_VID (VLAN_N_VID - 1)
29 
30 #define MLXSW_SP_FID_8021D_MAX 1024
31 
32 #define MLXSW_SP_MID_MAX 7000
33 
34 #define MLXSW_SP_PORTS_PER_CLUSTER_MAX 4
35 
36 #define MLXSW_SP_PORT_BASE_SPEED_25G 25000 /* Mb/s */
37 #define MLXSW_SP_PORT_BASE_SPEED_50G 50000 /* Mb/s */
38 
39 #define MLXSW_SP_KVD_LINEAR_SIZE 98304 /* entries */
40 #define MLXSW_SP_KVD_GRANULARITY 128
41 
42 #define MLXSW_SP_RESOURCE_NAME_KVD "kvd"
43 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR "linear"
44 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE "hash_single"
45 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE "hash_double"
46 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES "singles"
47 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS "chunks"
48 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks"
49 
50 enum mlxsw_sp_resource_id {
51 	MLXSW_SP_RESOURCE_KVD = 1,
52 	MLXSW_SP_RESOURCE_KVD_LINEAR,
53 	MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
54 	MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
55 	MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE,
56 	MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS,
57 	MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS,
58 };
59 
60 struct mlxsw_sp_port;
61 struct mlxsw_sp_rif;
62 struct mlxsw_sp_span_entry;
63 enum mlxsw_sp_l3proto;
64 union mlxsw_sp_l3addr;
65 
66 struct mlxsw_sp_upper {
67 	struct net_device *dev;
68 	unsigned int ref_count;
69 };
70 
71 enum mlxsw_sp_rif_type {
72 	MLXSW_SP_RIF_TYPE_SUBPORT,
73 	MLXSW_SP_RIF_TYPE_VLAN,
74 	MLXSW_SP_RIF_TYPE_FID,
75 	MLXSW_SP_RIF_TYPE_IPIP_LB, /* IP-in-IP loopback. */
76 	MLXSW_SP_RIF_TYPE_MAX,
77 };
78 
79 struct mlxsw_sp_rif_ops;
80 
81 extern const struct mlxsw_sp_rif_ops *mlxsw_sp1_rif_ops_arr[];
82 extern const struct mlxsw_sp_rif_ops *mlxsw_sp2_rif_ops_arr[];
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 enum mlxsw_sp_nve_type {
93 	MLXSW_SP_NVE_TYPE_VXLAN,
94 };
95 
96 struct mlxsw_sp_mid {
97 	struct list_head list;
98 	unsigned char addr[ETH_ALEN];
99 	u16 fid;
100 	u16 mid;
101 	bool in_hw;
102 	unsigned long *ports_in_mid; /* bits array */
103 };
104 
105 enum mlxsw_sp_port_mall_action_type {
106 	MLXSW_SP_PORT_MALL_MIRROR,
107 	MLXSW_SP_PORT_MALL_SAMPLE,
108 };
109 
110 struct mlxsw_sp_port_mall_mirror_tc_entry {
111 	int span_id;
112 	bool ingress;
113 };
114 
115 struct mlxsw_sp_port_mall_tc_entry {
116 	struct list_head list;
117 	unsigned long cookie;
118 	enum mlxsw_sp_port_mall_action_type type;
119 	union {
120 		struct mlxsw_sp_port_mall_mirror_tc_entry mirror;
121 	};
122 };
123 
124 struct mlxsw_sp_sb;
125 struct mlxsw_sp_bridge;
126 struct mlxsw_sp_router;
127 struct mlxsw_sp_mr;
128 struct mlxsw_sp_acl;
129 struct mlxsw_sp_counter_pool;
130 struct mlxsw_sp_fid_core;
131 struct mlxsw_sp_kvdl;
132 struct mlxsw_sp_nve;
133 struct mlxsw_sp_kvdl_ops;
134 struct mlxsw_sp_mr_tcam_ops;
135 struct mlxsw_sp_acl_tcam_ops;
136 struct mlxsw_sp_nve_ops;
137 struct mlxsw_sp_sb_vals;
138 struct mlxsw_sp_port_type_speed_ops;
139 struct mlxsw_sp_ptp_state;
140 struct mlxsw_sp_ptp_ops;
141 
142 struct mlxsw_sp {
143 	struct mlxsw_sp_port **ports;
144 	struct mlxsw_core *core;
145 	const struct mlxsw_bus_info *bus_info;
146 	unsigned char base_mac[ETH_ALEN];
147 	const unsigned char *mac_mask;
148 	struct mlxsw_sp_upper *lags;
149 	int *port_to_module;
150 	struct mlxsw_sp_sb *sb;
151 	struct mlxsw_sp_bridge *bridge;
152 	struct mlxsw_sp_router *router;
153 	struct mlxsw_sp_mr *mr;
154 	struct mlxsw_afa *afa;
155 	struct mlxsw_sp_acl *acl;
156 	struct mlxsw_sp_fid_core *fid_core;
157 	struct mlxsw_sp_kvdl *kvdl;
158 	struct mlxsw_sp_nve *nve;
159 	struct notifier_block netdevice_nb;
160 	struct mlxsw_sp_ptp_clock *clock;
161 	struct mlxsw_sp_ptp_state *ptp_state;
162 
163 	struct mlxsw_sp_counter_pool *counter_pool;
164 	struct {
165 		struct mlxsw_sp_span_entry *entries;
166 		int entries_count;
167 	} span;
168 	const struct mlxsw_fw_rev *req_rev;
169 	const char *fw_filename;
170 	const struct mlxsw_sp_kvdl_ops *kvdl_ops;
171 	const struct mlxsw_afa_ops *afa_ops;
172 	const struct mlxsw_afk_ops *afk_ops;
173 	const struct mlxsw_sp_mr_tcam_ops *mr_tcam_ops;
174 	const struct mlxsw_sp_acl_tcam_ops *acl_tcam_ops;
175 	const struct mlxsw_sp_nve_ops **nve_ops_arr;
176 	const struct mlxsw_sp_rif_ops **rif_ops_arr;
177 	const struct mlxsw_sp_sb_vals *sb_vals;
178 	const struct mlxsw_sp_port_type_speed_ops *port_type_speed_ops;
179 	const struct mlxsw_sp_ptp_ops *ptp_ops;
180 	const struct mlxsw_listener *listeners;
181 	size_t listeners_count;
182 };
183 
184 static inline struct mlxsw_sp_upper *
185 mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
186 {
187 	return &mlxsw_sp->lags[lag_id];
188 }
189 
190 struct mlxsw_sp_port_pcpu_stats {
191 	u64			rx_packets;
192 	u64			rx_bytes;
193 	u64			tx_packets;
194 	u64			tx_bytes;
195 	struct u64_stats_sync	syncp;
196 	u32			tx_dropped;
197 };
198 
199 struct mlxsw_sp_port_sample {
200 	struct psample_group __rcu *psample_group;
201 	u32 trunc_size;
202 	u32 rate;
203 	bool truncate;
204 };
205 
206 struct mlxsw_sp_bridge_port;
207 struct mlxsw_sp_fid;
208 
209 struct mlxsw_sp_port_vlan {
210 	struct list_head list;
211 	struct mlxsw_sp_port *mlxsw_sp_port;
212 	struct mlxsw_sp_fid *fid;
213 	u16 vid;
214 	struct mlxsw_sp_bridge_port *bridge_port;
215 	struct list_head bridge_vlan_node;
216 };
217 
218 /* No need an internal lock; At worse - miss a single periodic iteration */
219 struct mlxsw_sp_port_xstats {
220 	u64 ecn;
221 	u64 wred_drop[TC_MAX_QUEUE];
222 	u64 tail_drop[TC_MAX_QUEUE];
223 	u64 backlog[TC_MAX_QUEUE];
224 	u64 tx_bytes[IEEE_8021QAZ_MAX_TCS];
225 	u64 tx_packets[IEEE_8021QAZ_MAX_TCS];
226 };
227 
228 struct mlxsw_sp_port {
229 	struct net_device *dev;
230 	struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
231 	struct mlxsw_sp *mlxsw_sp;
232 	u8 local_port;
233 	u8 lagged:1,
234 	   split:1;
235 	u16 pvid;
236 	u16 lag_id;
237 	struct {
238 		u8 tx_pause:1,
239 		   rx_pause:1,
240 		   autoneg:1;
241 	} link;
242 	struct {
243 		struct ieee_ets *ets;
244 		struct ieee_maxrate *maxrate;
245 		struct ieee_pfc *pfc;
246 		enum mlxsw_reg_qpts_trust_state trust_state;
247 	} dcb;
248 	struct {
249 		u8 module;
250 		u8 width;
251 		u8 lane;
252 	} mapping;
253 	/* TC handles */
254 	struct list_head mall_tc_list;
255 	struct {
256 		#define MLXSW_HW_STATS_UPDATE_TIME HZ
257 		struct rtnl_link_stats64 stats;
258 		struct mlxsw_sp_port_xstats xstats;
259 		struct delayed_work update_dw;
260 	} periodic_hw_stats;
261 	struct mlxsw_sp_port_sample *sample;
262 	struct list_head vlans_list;
263 	struct mlxsw_sp_port_vlan *default_vlan;
264 	struct mlxsw_sp_qdisc *root_qdisc;
265 	struct mlxsw_sp_qdisc *tclass_qdiscs;
266 	unsigned acl_rule_count;
267 	struct mlxsw_sp_acl_block *ing_acl_block;
268 	struct mlxsw_sp_acl_block *eg_acl_block;
269 	struct {
270 		struct hwtstamp_config hwtstamp_config;
271 		u16 ing_types;
272 		u16 egr_types;
273 	} ptp;
274 };
275 
276 struct mlxsw_sp_port_type_speed_ops {
277 	void (*from_ptys_supported_port)(struct mlxsw_sp *mlxsw_sp,
278 					 u32 ptys_eth_proto,
279 					 struct ethtool_link_ksettings *cmd);
280 	void (*from_ptys_link)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
281 			       unsigned long *mode);
282 	void (*from_ptys_speed_duplex)(struct mlxsw_sp *mlxsw_sp,
283 				       bool carrier_ok, u32 ptys_eth_proto,
284 				       struct ethtool_link_ksettings *cmd);
285 	u32 (*to_ptys_advert_link)(struct mlxsw_sp *mlxsw_sp,
286 				   const struct ethtool_link_ksettings *cmd);
287 	u32 (*to_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u32 speed);
288 	u32 (*to_ptys_upper_speed)(struct mlxsw_sp *mlxsw_sp, u32 upper_speed);
289 	int (*port_speed_base)(struct mlxsw_sp *mlxsw_sp, u8 local_port,
290 			       u32 *base_speed);
291 	void (*reg_ptys_eth_pack)(struct mlxsw_sp *mlxsw_sp, char *payload,
292 				  u8 local_port, u32 proto_admin, bool autoneg);
293 	void (*reg_ptys_eth_unpack)(struct mlxsw_sp *mlxsw_sp, char *payload,
294 				    u32 *p_eth_proto_cap,
295 				    u32 *p_eth_proto_admin,
296 				    u32 *p_eth_proto_oper);
297 };
298 
299 static inline struct net_device *
300 mlxsw_sp_bridge_vxlan_dev_find(struct net_device *br_dev)
301 {
302 	struct net_device *dev;
303 	struct list_head *iter;
304 
305 	netdev_for_each_lower_dev(br_dev, dev, iter) {
306 		if (netif_is_vxlan(dev))
307 			return dev;
308 	}
309 
310 	return NULL;
311 }
312 
313 static inline bool mlxsw_sp_bridge_has_vxlan(struct net_device *br_dev)
314 {
315 	return !!mlxsw_sp_bridge_vxlan_dev_find(br_dev);
316 }
317 
318 static inline int
319 mlxsw_sp_vxlan_mapped_vid(const struct net_device *vxlan_dev, u16 *p_vid)
320 {
321 	struct bridge_vlan_info vinfo;
322 	u16 vid = 0;
323 	int err;
324 
325 	err = br_vlan_get_pvid(vxlan_dev, &vid);
326 	if (err || !vid)
327 		goto out;
328 
329 	err = br_vlan_get_info(vxlan_dev, vid, &vinfo);
330 	if (err || !(vinfo.flags & BRIDGE_VLAN_INFO_UNTAGGED))
331 		vid = 0;
332 
333 out:
334 	*p_vid = vid;
335 	return err;
336 }
337 
338 static inline bool
339 mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
340 {
341 	return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
342 }
343 
344 static inline struct mlxsw_sp_port *
345 mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
346 {
347 	struct mlxsw_sp_port *mlxsw_sp_port;
348 	u8 local_port;
349 
350 	local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
351 						lag_id, port_index);
352 	mlxsw_sp_port = mlxsw_sp->ports[local_port];
353 	return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
354 }
355 
356 static inline struct mlxsw_sp_port_vlan *
357 mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
358 			       u16 vid)
359 {
360 	struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
361 
362 	list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
363 			    list) {
364 		if (mlxsw_sp_port_vlan->vid == vid)
365 			return mlxsw_sp_port_vlan;
366 	}
367 
368 	return NULL;
369 }
370 
371 enum mlxsw_sp_flood_type {
372 	MLXSW_SP_FLOOD_TYPE_UC,
373 	MLXSW_SP_FLOOD_TYPE_BC,
374 	MLXSW_SP_FLOOD_TYPE_MC,
375 };
376 
377 /* spectrum_buffers.c */
378 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
379 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
380 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
381 int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
382 			 unsigned int sb_index, u16 pool_index,
383 			 struct devlink_sb_pool_info *pool_info);
384 int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
385 			 unsigned int sb_index, u16 pool_index, u32 size,
386 			 enum devlink_sb_threshold_type threshold_type,
387 			 struct netlink_ext_ack *extack);
388 int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
389 			      unsigned int sb_index, u16 pool_index,
390 			      u32 *p_threshold);
391 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
392 			      unsigned int sb_index, u16 pool_index,
393 			      u32 threshold, struct netlink_ext_ack *extack);
394 int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
395 				 unsigned int sb_index, u16 tc_index,
396 				 enum devlink_sb_pool_type pool_type,
397 				 u16 *p_pool_index, u32 *p_threshold);
398 int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
399 				 unsigned int sb_index, u16 tc_index,
400 				 enum devlink_sb_pool_type pool_type,
401 				 u16 pool_index, u32 threshold,
402 				 struct netlink_ext_ack *extack);
403 int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
404 			     unsigned int sb_index);
405 int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
406 			      unsigned int sb_index);
407 int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
408 				  unsigned int sb_index, u16 pool_index,
409 				  u32 *p_cur, u32 *p_max);
410 int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
411 				     unsigned int sb_index, u16 tc_index,
412 				     enum devlink_sb_pool_type pool_type,
413 				     u32 *p_cur, u32 *p_max);
414 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
415 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
416 u32 mlxsw_sp_sb_max_headroom_cells(const struct mlxsw_sp *mlxsw_sp);
417 
418 extern const struct mlxsw_sp_sb_vals mlxsw_sp1_sb_vals;
419 extern const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals;
420 
421 /* spectrum_switchdev.c */
422 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
423 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
424 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
425 			bool adding);
426 void
427 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
428 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
429 			      struct net_device *brport_dev,
430 			      struct net_device *br_dev,
431 			      struct netlink_ext_ack *extack);
432 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
433 				struct net_device *brport_dev,
434 				struct net_device *br_dev);
435 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
436 					 const struct net_device *br_dev);
437 int mlxsw_sp_bridge_vxlan_join(struct mlxsw_sp *mlxsw_sp,
438 			       const struct net_device *br_dev,
439 			       const struct net_device *vxlan_dev, u16 vid,
440 			       struct netlink_ext_ack *extack);
441 void mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp,
442 				 const struct net_device *vxlan_dev);
443 struct mlxsw_sp_fid *mlxsw_sp_bridge_fid_get(struct mlxsw_sp *mlxsw_sp,
444 					     const struct net_device *br_dev,
445 					     u16 vid,
446 					     struct netlink_ext_ack *extack);
447 extern struct notifier_block mlxsw_sp_switchdev_notifier;
448 
449 /* spectrum.c */
450 void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb,
451 				       u8 local_port, void *priv);
452 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
453 			  enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
454 			  bool dwrr, u8 dwrr_weight);
455 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
456 			      u8 switch_prio, u8 tclass);
457 int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
458 				 u8 *prio_tc, bool pause_en,
459 				 struct ieee_pfc *my_pfc);
460 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
461 				  enum mlxsw_reg_qeec_hr hr, u8 index,
462 				  u8 next_index, u32 maxrate);
463 enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state);
464 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
465 			      u8 state);
466 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
467 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
468 				   bool learn_enable);
469 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
470 struct mlxsw_sp_port_vlan *
471 mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
472 void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
473 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
474 			   u16 vid_end, bool is_member, bool untagged);
475 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
476 			      unsigned int counter_index, u64 *packets,
477 			      u64 *bytes);
478 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
479 				unsigned int *p_counter_index);
480 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
481 				unsigned int counter_index);
482 bool mlxsw_sp_port_dev_check(const struct net_device *dev);
483 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
484 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
485 struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
486 void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
487 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
488 
489 /* spectrum_dcb.c */
490 #ifdef CONFIG_MLXSW_SPECTRUM_DCB
491 int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
492 void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
493 #else
494 static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
495 {
496 	return 0;
497 }
498 static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
499 {}
500 #endif
501 
502 /* spectrum_router.c */
503 enum mlxsw_sp_l3proto {
504 	MLXSW_SP_L3_PROTO_IPV4,
505 	MLXSW_SP_L3_PROTO_IPV6,
506 #define MLXSW_SP_L3_PROTO_MAX	(MLXSW_SP_L3_PROTO_IPV6 + 1)
507 };
508 
509 union mlxsw_sp_l3addr {
510 	__be32 addr4;
511 	struct in6_addr addr6;
512 };
513 
514 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp);
515 void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
516 int mlxsw_sp_netdevice_router_port_event(struct net_device *dev,
517 					 unsigned long event, void *ptr);
518 void mlxsw_sp_rif_macvlan_del(struct mlxsw_sp *mlxsw_sp,
519 			      const struct net_device *macvlan_dev);
520 int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
521 				  unsigned long event, void *ptr);
522 int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
523 				   unsigned long event, void *ptr);
524 int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
525 				 struct netdev_notifier_changeupper_info *info);
526 bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp,
527 				const struct net_device *dev);
528 bool mlxsw_sp_netdev_is_ipip_ul(const struct mlxsw_sp *mlxsw_sp,
529 				const struct net_device *dev);
530 int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,
531 				     struct net_device *l3_dev,
532 				     unsigned long event,
533 				     struct netdev_notifier_info *info);
534 int
535 mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
536 				 struct net_device *l3_dev,
537 				 unsigned long event,
538 				 struct netdev_notifier_info *info);
539 void
540 mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
541 void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp,
542 				 struct net_device *dev);
543 struct mlxsw_sp_rif *mlxsw_sp_rif_find_by_dev(const struct mlxsw_sp *mlxsw_sp,
544 					      const struct net_device *dev);
545 u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp);
546 struct mlxsw_sp_fid *mlxsw_sp_rif_fid(const struct mlxsw_sp_rif *rif);
547 int mlxsw_sp_router_nve_promote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
548 				      enum mlxsw_sp_l3proto ul_proto,
549 				      const union mlxsw_sp_l3addr *ul_sip,
550 				      u32 tunnel_index);
551 void mlxsw_sp_router_nve_demote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
552 				      enum mlxsw_sp_l3proto ul_proto,
553 				      const union mlxsw_sp_l3addr *ul_sip);
554 int mlxsw_sp_router_tb_id_vr_id(struct mlxsw_sp *mlxsw_sp, u32 tb_id,
555 				u16 *vr_id);
556 int mlxsw_sp_router_ul_rif_get(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
557 			       u16 *ul_rif_index);
558 void mlxsw_sp_router_ul_rif_put(struct mlxsw_sp *mlxsw_sp, u16 ul_rif_index);
559 
560 /* spectrum_kvdl.c */
561 enum mlxsw_sp_kvdl_entry_type {
562 	MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
563 	MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
564 	MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
565 	MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
566 	MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT,
567 };
568 
569 static inline unsigned int
570 mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type)
571 {
572 	switch (type) {
573 	case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ: /* fall through */
574 	case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET: /* fall through */
575 	case MLXSW_SP_KVDL_ENTRY_TYPE_PBS: /* fall through */
576 	case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR: /* fall through */
577 	case MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT: /* fall through */
578 	default:
579 		return 1;
580 	}
581 }
582 
583 struct mlxsw_sp_kvdl_ops {
584 	size_t priv_size;
585 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
586 	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
587 	int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv,
588 		     enum mlxsw_sp_kvdl_entry_type type,
589 		     unsigned int entry_count, u32 *p_entry_index);
590 	void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv,
591 		     enum mlxsw_sp_kvdl_entry_type type,
592 		     unsigned int entry_count, int entry_index);
593 	int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv,
594 				enum mlxsw_sp_kvdl_entry_type type,
595 				unsigned int entry_count,
596 				unsigned int *p_alloc_count);
597 	int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv);
598 };
599 
600 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
601 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
602 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
603 			enum mlxsw_sp_kvdl_entry_type type,
604 			unsigned int entry_count, u32 *p_entry_index);
605 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
606 			enum mlxsw_sp_kvdl_entry_type type,
607 			unsigned int entry_count, int entry_index);
608 int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
609 				    enum mlxsw_sp_kvdl_entry_type type,
610 				    unsigned int entry_count,
611 				    unsigned int *p_alloc_count);
612 
613 /* spectrum1_kvdl.c */
614 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops;
615 int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core);
616 
617 /* spectrum2_kvdl.c */
618 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops;
619 
620 struct mlxsw_sp_acl_rule_info {
621 	unsigned int priority;
622 	struct mlxsw_afk_element_values values;
623 	struct mlxsw_afa_block *act_block;
624 	u8 action_created:1;
625 	unsigned int counter_index;
626 };
627 
628 struct mlxsw_sp_acl_block;
629 struct mlxsw_sp_acl_ruleset;
630 
631 /* spectrum_acl.c */
632 enum mlxsw_sp_acl_profile {
633 	MLXSW_SP_ACL_PROFILE_FLOWER,
634 	MLXSW_SP_ACL_PROFILE_MR,
635 };
636 
637 struct mlxsw_sp_acl_block {
638 	struct list_head binding_list;
639 	struct mlxsw_sp_acl_ruleset *ruleset_zero;
640 	struct mlxsw_sp *mlxsw_sp;
641 	unsigned int rule_count;
642 	unsigned int disable_count;
643 	struct net *net;
644 };
645 
646 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
647 struct mlxsw_sp *mlxsw_sp_acl_block_mlxsw_sp(struct mlxsw_sp_acl_block *block);
648 unsigned int mlxsw_sp_acl_block_rule_count(struct mlxsw_sp_acl_block *block);
649 void mlxsw_sp_acl_block_disable_inc(struct mlxsw_sp_acl_block *block);
650 void mlxsw_sp_acl_block_disable_dec(struct mlxsw_sp_acl_block *block);
651 bool mlxsw_sp_acl_block_disabled(struct mlxsw_sp_acl_block *block);
652 struct mlxsw_sp_acl_block *mlxsw_sp_acl_block_create(struct mlxsw_sp *mlxsw_sp,
653 						     struct net *net);
654 void mlxsw_sp_acl_block_destroy(struct mlxsw_sp_acl_block *block);
655 int mlxsw_sp_acl_block_bind(struct mlxsw_sp *mlxsw_sp,
656 			    struct mlxsw_sp_acl_block *block,
657 			    struct mlxsw_sp_port *mlxsw_sp_port,
658 			    bool ingress);
659 int mlxsw_sp_acl_block_unbind(struct mlxsw_sp *mlxsw_sp,
660 			      struct mlxsw_sp_acl_block *block,
661 			      struct mlxsw_sp_port *mlxsw_sp_port,
662 			      bool ingress);
663 bool mlxsw_sp_acl_block_is_egress_bound(struct mlxsw_sp_acl_block *block);
664 struct mlxsw_sp_acl_ruleset *
665 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
666 			    struct mlxsw_sp_acl_block *block, u32 chain_index,
667 			    enum mlxsw_sp_acl_profile profile);
668 struct mlxsw_sp_acl_ruleset *
669 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
670 			 struct mlxsw_sp_acl_block *block, u32 chain_index,
671 			 enum mlxsw_sp_acl_profile profile,
672 			 struct mlxsw_afk_element_usage *tmplt_elusage);
673 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
674 			      struct mlxsw_sp_acl_ruleset *ruleset);
675 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
676 
677 struct mlxsw_sp_acl_rule_info *
678 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
679 			  struct mlxsw_afa_block *afa_block);
680 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
681 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
682 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
683 				 unsigned int priority);
684 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
685 				    enum mlxsw_afk_element element,
686 				    u32 key_value, u32 mask_value);
687 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
688 				    enum mlxsw_afk_element element,
689 				    const char *key_value,
690 				    const char *mask_value, unsigned int len);
691 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
692 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
693 				u16 group_id);
694 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
695 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei);
696 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
697 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
698 				  struct mlxsw_sp_acl_rule_info *rulei,
699 				  struct mlxsw_sp_acl_block *block,
700 				  struct net_device *out_dev,
701 				  struct netlink_ext_ack *extack);
702 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
703 			       struct mlxsw_sp_acl_rule_info *rulei,
704 			       struct net_device *out_dev,
705 			       struct netlink_ext_ack *extack);
706 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
707 				struct mlxsw_sp_acl_rule_info *rulei,
708 				u32 action, u16 vid, u16 proto, u8 prio,
709 				struct netlink_ext_ack *extack);
710 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
711 				 struct mlxsw_sp_acl_rule_info *rulei,
712 				 struct netlink_ext_ack *extack);
713 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
714 				   struct mlxsw_sp_acl_rule_info *rulei,
715 				   u16 fid, struct netlink_ext_ack *extack);
716 
717 struct mlxsw_sp_acl_rule;
718 
719 struct mlxsw_sp_acl_rule *
720 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
721 			 struct mlxsw_sp_acl_ruleset *ruleset,
722 			 unsigned long cookie,
723 			 struct mlxsw_afa_block *afa_block,
724 			 struct netlink_ext_ack *extack);
725 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
726 			       struct mlxsw_sp_acl_rule *rule);
727 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
728 			  struct mlxsw_sp_acl_rule *rule);
729 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
730 			   struct mlxsw_sp_acl_rule *rule);
731 int mlxsw_sp_acl_rule_action_replace(struct mlxsw_sp *mlxsw_sp,
732 				     struct mlxsw_sp_acl_rule *rule,
733 				     struct mlxsw_afa_block *afa_block);
734 struct mlxsw_sp_acl_rule *
735 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
736 			 struct mlxsw_sp_acl_ruleset *ruleset,
737 			 unsigned long cookie);
738 struct mlxsw_sp_acl_rule_info *
739 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
740 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
741 				struct mlxsw_sp_acl_rule *rule,
742 				u64 *packets, u64 *bytes, u64 *last_use);
743 
744 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
745 
746 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
747 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
748 u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp);
749 int mlxsw_sp_acl_region_rehash_intrvl_set(struct mlxsw_sp *mlxsw_sp, u32 val);
750 
751 /* spectrum_acl_tcam.c */
752 struct mlxsw_sp_acl_tcam;
753 struct mlxsw_sp_acl_tcam_region;
754 
755 struct mlxsw_sp_acl_tcam_ops {
756 	enum mlxsw_reg_ptar_key_type key_type;
757 	size_t priv_size;
758 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv,
759 		    struct mlxsw_sp_acl_tcam *tcam);
760 	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
761 	size_t region_priv_size;
762 	int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv,
763 			   void *tcam_priv,
764 			   struct mlxsw_sp_acl_tcam_region *region,
765 			   void *hints_priv);
766 	void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
767 	int (*region_associate)(struct mlxsw_sp *mlxsw_sp,
768 				struct mlxsw_sp_acl_tcam_region *region);
769 	void * (*region_rehash_hints_get)(void *region_priv);
770 	void (*region_rehash_hints_put)(void *hints_priv);
771 	size_t chunk_priv_size;
772 	void (*chunk_init)(void *region_priv, void *chunk_priv,
773 			   unsigned int priority);
774 	void (*chunk_fini)(void *chunk_priv);
775 	size_t entry_priv_size;
776 	int (*entry_add)(struct mlxsw_sp *mlxsw_sp,
777 			 void *region_priv, void *chunk_priv,
778 			 void *entry_priv,
779 			 struct mlxsw_sp_acl_rule_info *rulei);
780 	void (*entry_del)(struct mlxsw_sp *mlxsw_sp,
781 			  void *region_priv, void *chunk_priv,
782 			  void *entry_priv);
783 	int (*entry_action_replace)(struct mlxsw_sp *mlxsw_sp,
784 				    void *region_priv, void *entry_priv,
785 				    struct mlxsw_sp_acl_rule_info *rulei);
786 	int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp,
787 				  void *region_priv, void *entry_priv,
788 				  bool *activity);
789 };
790 
791 /* spectrum1_acl_tcam.c */
792 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops;
793 
794 /* spectrum2_acl_tcam.c */
795 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops;
796 
797 /* spectrum_acl_flex_actions.c */
798 extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops;
799 extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops;
800 
801 /* spectrum_acl_flex_keys.c */
802 extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
803 extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;
804 
805 /* spectrum_flower.c */
806 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
807 			    struct mlxsw_sp_acl_block *block,
808 			    struct tc_cls_flower_offload *f);
809 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
810 			     struct mlxsw_sp_acl_block *block,
811 			     struct tc_cls_flower_offload *f);
812 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
813 			  struct mlxsw_sp_acl_block *block,
814 			  struct tc_cls_flower_offload *f);
815 int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
816 				 struct mlxsw_sp_acl_block *block,
817 				 struct tc_cls_flower_offload *f);
818 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
819 				   struct mlxsw_sp_acl_block *block,
820 				   struct tc_cls_flower_offload *f);
821 
822 /* spectrum_qdisc.c */
823 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
824 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
825 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
826 			  struct tc_red_qopt_offload *p);
827 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
828 			   struct tc_prio_qopt_offload *p);
829 
830 /* spectrum_fid.c */
831 bool mlxsw_sp_fid_lag_vid_valid(const struct mlxsw_sp_fid *fid);
832 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp,
833 						  u16 fid_index);
834 int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex);
835 int mlxsw_sp_fid_nve_type(const struct mlxsw_sp_fid *fid,
836 			  enum mlxsw_sp_nve_type *p_type);
837 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_vni(struct mlxsw_sp *mlxsw_sp,
838 						__be32 vni);
839 int mlxsw_sp_fid_vni(const struct mlxsw_sp_fid *fid, __be32 *vni);
840 int mlxsw_sp_fid_nve_flood_index_set(struct mlxsw_sp_fid *fid,
841 				     u32 nve_flood_index);
842 void mlxsw_sp_fid_nve_flood_index_clear(struct mlxsw_sp_fid *fid);
843 bool mlxsw_sp_fid_nve_flood_index_is_set(const struct mlxsw_sp_fid *fid);
844 int mlxsw_sp_fid_vni_set(struct mlxsw_sp_fid *fid, enum mlxsw_sp_nve_type type,
845 			 __be32 vni, int nve_ifindex);
846 void mlxsw_sp_fid_vni_clear(struct mlxsw_sp_fid *fid);
847 bool mlxsw_sp_fid_vni_is_set(const struct mlxsw_sp_fid *fid);
848 void mlxsw_sp_fid_fdb_clear_offload(const struct mlxsw_sp_fid *fid,
849 				    const struct net_device *nve_dev);
850 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
851 			   enum mlxsw_sp_flood_type packet_type, u8 local_port,
852 			   bool member);
853 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
854 			      struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
855 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
856 				 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
857 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
858 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
859 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
860 struct mlxsw_sp_rif *mlxsw_sp_fid_rif(const struct mlxsw_sp_fid *fid);
861 enum mlxsw_sp_rif_type
862 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
863 			   enum mlxsw_sp_fid_type type);
864 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
865 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
866 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
867 					    int br_ifindex);
868 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_lookup(struct mlxsw_sp *mlxsw_sp,
869 					       u16 vid);
870 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_lookup(struct mlxsw_sp *mlxsw_sp,
871 					       int br_ifindex);
872 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
873 					   u16 rif_index);
874 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
875 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
876 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
877 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
878 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
879 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
880 
881 /* spectrum_mr.c */
882 enum mlxsw_sp_mr_route_prio {
883 	MLXSW_SP_MR_ROUTE_PRIO_SG,
884 	MLXSW_SP_MR_ROUTE_PRIO_STARG,
885 	MLXSW_SP_MR_ROUTE_PRIO_CATCHALL,
886 	__MLXSW_SP_MR_ROUTE_PRIO_MAX
887 };
888 
889 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
890 
891 struct mlxsw_sp_mr_route_key;
892 
893 struct mlxsw_sp_mr_tcam_ops {
894 	size_t priv_size;
895 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
896 	void (*fini)(void *priv);
897 	size_t route_priv_size;
898 	int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
899 			    void *route_priv,
900 			    struct mlxsw_sp_mr_route_key *key,
901 			    struct mlxsw_afa_block *afa_block,
902 			    enum mlxsw_sp_mr_route_prio prio);
903 	void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
904 			      void *route_priv,
905 			      struct mlxsw_sp_mr_route_key *key);
906 	int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
907 			    struct mlxsw_sp_mr_route_key *key,
908 			    struct mlxsw_afa_block *afa_block);
909 };
910 
911 /* spectrum1_mr_tcam.c */
912 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops;
913 
914 /* spectrum2_mr_tcam.c */
915 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops;
916 
917 /* spectrum_nve.c */
918 struct mlxsw_sp_nve_params {
919 	enum mlxsw_sp_nve_type type;
920 	__be32 vni;
921 	const struct net_device *dev;
922 };
923 
924 extern const struct mlxsw_sp_nve_ops *mlxsw_sp1_nve_ops_arr[];
925 extern const struct mlxsw_sp_nve_ops *mlxsw_sp2_nve_ops_arr[];
926 
927 int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip,
928 				    enum mlxsw_sp_l3proto proto,
929 				    union mlxsw_sp_l3addr *addr);
930 int mlxsw_sp_nve_flood_ip_add(struct mlxsw_sp *mlxsw_sp,
931 			      struct mlxsw_sp_fid *fid,
932 			      enum mlxsw_sp_l3proto proto,
933 			      union mlxsw_sp_l3addr *addr);
934 void mlxsw_sp_nve_flood_ip_del(struct mlxsw_sp *mlxsw_sp,
935 			       struct mlxsw_sp_fid *fid,
936 			       enum mlxsw_sp_l3proto proto,
937 			       union mlxsw_sp_l3addr *addr);
938 u32 mlxsw_sp_nve_decap_tunnel_index_get(const struct mlxsw_sp *mlxsw_sp);
939 bool mlxsw_sp_nve_ipv4_route_is_decap(const struct mlxsw_sp *mlxsw_sp,
940 				      u32 tb_id, __be32 addr);
941 int mlxsw_sp_nve_fid_enable(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *fid,
942 			    struct mlxsw_sp_nve_params *params,
943 			    struct netlink_ext_ack *extack);
944 void mlxsw_sp_nve_fid_disable(struct mlxsw_sp *mlxsw_sp,
945 			      struct mlxsw_sp_fid *fid);
946 int mlxsw_sp_port_nve_init(struct mlxsw_sp_port *mlxsw_sp_port);
947 void mlxsw_sp_port_nve_fini(struct mlxsw_sp_port *mlxsw_sp_port);
948 int mlxsw_sp_nve_init(struct mlxsw_sp *mlxsw_sp);
949 void mlxsw_sp_nve_fini(struct mlxsw_sp *mlxsw_sp);
950 
951 #endif
952