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