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