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