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 void
378 mlxsw_sp_port_headroom_8x_adjust(const struct mlxsw_sp_port *mlxsw_sp_port,
379 				 u16 *p_size)
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 	if (mlxsw_sp_port->mapping.width != 8)
386 		return;
387 	*p_size *= 2;
388 }
389 
390 enum mlxsw_sp_flood_type {
391 	MLXSW_SP_FLOOD_TYPE_UC,
392 	MLXSW_SP_FLOOD_TYPE_BC,
393 	MLXSW_SP_FLOOD_TYPE_MC,
394 };
395 
396 /* spectrum_buffers.c */
397 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
398 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
399 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
400 int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
401 			 unsigned int sb_index, u16 pool_index,
402 			 struct devlink_sb_pool_info *pool_info);
403 int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
404 			 unsigned int sb_index, u16 pool_index, u32 size,
405 			 enum devlink_sb_threshold_type threshold_type,
406 			 struct netlink_ext_ack *extack);
407 int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
408 			      unsigned int sb_index, u16 pool_index,
409 			      u32 *p_threshold);
410 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
411 			      unsigned int sb_index, u16 pool_index,
412 			      u32 threshold, struct netlink_ext_ack *extack);
413 int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
414 				 unsigned int sb_index, u16 tc_index,
415 				 enum devlink_sb_pool_type pool_type,
416 				 u16 *p_pool_index, u32 *p_threshold);
417 int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
418 				 unsigned int sb_index, u16 tc_index,
419 				 enum devlink_sb_pool_type pool_type,
420 				 u16 pool_index, u32 threshold,
421 				 struct netlink_ext_ack *extack);
422 int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
423 			     unsigned int sb_index);
424 int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
425 			      unsigned int sb_index);
426 int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
427 				  unsigned int sb_index, u16 pool_index,
428 				  u32 *p_cur, u32 *p_max);
429 int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
430 				     unsigned int sb_index, u16 tc_index,
431 				     enum devlink_sb_pool_type pool_type,
432 				     u32 *p_cur, u32 *p_max);
433 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
434 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
435 u32 mlxsw_sp_sb_max_headroom_cells(const struct mlxsw_sp *mlxsw_sp);
436 
437 extern const struct mlxsw_sp_sb_vals mlxsw_sp1_sb_vals;
438 extern const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals;
439 
440 /* spectrum_switchdev.c */
441 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
442 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
443 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
444 			bool adding);
445 void
446 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
447 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
448 			      struct net_device *brport_dev,
449 			      struct net_device *br_dev,
450 			      struct netlink_ext_ack *extack);
451 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
452 				struct net_device *brport_dev,
453 				struct net_device *br_dev);
454 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
455 					 const struct net_device *br_dev);
456 int mlxsw_sp_bridge_vxlan_join(struct mlxsw_sp *mlxsw_sp,
457 			       const struct net_device *br_dev,
458 			       const struct net_device *vxlan_dev, u16 vid,
459 			       struct netlink_ext_ack *extack);
460 void mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp,
461 				 const struct net_device *vxlan_dev);
462 extern struct notifier_block mlxsw_sp_switchdev_notifier;
463 
464 /* spectrum.c */
465 void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb,
466 				       u8 local_port, void *priv);
467 void mlxsw_sp_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
468 			  u8 local_port);
469 void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
470 			     u8 local_port);
471 int mlxsw_sp_port_speed_get(struct mlxsw_sp_port *mlxsw_sp_port, u32 *speed);
472 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
473 			  enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
474 			  bool dwrr, u8 dwrr_weight);
475 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
476 			      u8 switch_prio, u8 tclass);
477 int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
478 				 u8 *prio_tc, bool pause_en,
479 				 struct ieee_pfc *my_pfc);
480 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
481 				  enum mlxsw_reg_qeec_hr hr, u8 index,
482 				  u8 next_index, u32 maxrate, u8 burst_size);
483 enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state);
484 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
485 			      u8 state);
486 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
487 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
488 				   bool learn_enable);
489 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
490 struct mlxsw_sp_port_vlan *
491 mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
492 void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
493 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
494 			   u16 vid_end, bool is_member, bool untagged);
495 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
496 			      unsigned int counter_index, u64 *packets,
497 			      u64 *bytes);
498 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
499 				unsigned int *p_counter_index);
500 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
501 				unsigned int counter_index);
502 u32 mlxsw_sp_span_buffsize_get(struct mlxsw_sp *mlxsw_sp, int mtu, u32 speed);
503 bool mlxsw_sp_port_dev_check(const struct net_device *dev);
504 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
505 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
506 struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
507 void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
508 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
509 
510 /* spectrum_dcb.c */
511 #ifdef CONFIG_MLXSW_SPECTRUM_DCB
512 int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
513 void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
514 #else
515 static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
516 {
517 	return 0;
518 }
519 static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
520 {}
521 #endif
522 
523 /* spectrum_router.c */
524 enum mlxsw_sp_l3proto {
525 	MLXSW_SP_L3_PROTO_IPV4,
526 	MLXSW_SP_L3_PROTO_IPV6,
527 #define MLXSW_SP_L3_PROTO_MAX	(MLXSW_SP_L3_PROTO_IPV6 + 1)
528 };
529 
530 union mlxsw_sp_l3addr {
531 	__be32 addr4;
532 	struct in6_addr addr6;
533 };
534 
535 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp,
536 			 struct netlink_ext_ack *extack);
537 void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
538 int mlxsw_sp_netdevice_router_port_event(struct net_device *dev,
539 					 unsigned long event, void *ptr);
540 void mlxsw_sp_rif_macvlan_del(struct mlxsw_sp *mlxsw_sp,
541 			      const struct net_device *macvlan_dev);
542 int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
543 				  unsigned long event, void *ptr);
544 int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
545 				   unsigned long event, void *ptr);
546 int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
547 				 struct netdev_notifier_changeupper_info *info);
548 bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp,
549 				const struct net_device *dev);
550 bool mlxsw_sp_netdev_is_ipip_ul(struct mlxsw_sp *mlxsw_sp,
551 				const struct net_device *dev);
552 int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,
553 				     struct net_device *l3_dev,
554 				     unsigned long event,
555 				     struct netdev_notifier_info *info);
556 int
557 mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
558 				 struct net_device *l3_dev,
559 				 unsigned long event,
560 				 struct netdev_notifier_info *info);
561 void
562 mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
563 void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp,
564 				 struct net_device *dev);
565 bool mlxsw_sp_rif_exists(struct mlxsw_sp *mlxsw_sp,
566 			 const struct net_device *dev);
567 u16 mlxsw_sp_rif_vid(struct mlxsw_sp *mlxsw_sp, const struct net_device *dev);
568 u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp);
569 int mlxsw_sp_router_nve_promote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
570 				      enum mlxsw_sp_l3proto ul_proto,
571 				      const union mlxsw_sp_l3addr *ul_sip,
572 				      u32 tunnel_index);
573 void mlxsw_sp_router_nve_demote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
574 				      enum mlxsw_sp_l3proto ul_proto,
575 				      const union mlxsw_sp_l3addr *ul_sip);
576 int mlxsw_sp_router_tb_id_vr_id(struct mlxsw_sp *mlxsw_sp, u32 tb_id,
577 				u16 *vr_id);
578 int mlxsw_sp_router_ul_rif_get(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
579 			       u16 *ul_rif_index);
580 void mlxsw_sp_router_ul_rif_put(struct mlxsw_sp *mlxsw_sp, u16 ul_rif_index);
581 
582 /* spectrum_kvdl.c */
583 enum mlxsw_sp_kvdl_entry_type {
584 	MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
585 	MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
586 	MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
587 	MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
588 	MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT,
589 };
590 
591 static inline unsigned int
592 mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type)
593 {
594 	switch (type) {
595 	case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ: /* fall through */
596 	case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET: /* fall through */
597 	case MLXSW_SP_KVDL_ENTRY_TYPE_PBS: /* fall through */
598 	case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR: /* fall through */
599 	case MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT: /* fall through */
600 	default:
601 		return 1;
602 	}
603 }
604 
605 struct mlxsw_sp_kvdl_ops {
606 	size_t priv_size;
607 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
608 	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
609 	int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv,
610 		     enum mlxsw_sp_kvdl_entry_type type,
611 		     unsigned int entry_count, u32 *p_entry_index);
612 	void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv,
613 		     enum mlxsw_sp_kvdl_entry_type type,
614 		     unsigned int entry_count, int entry_index);
615 	int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv,
616 				enum mlxsw_sp_kvdl_entry_type type,
617 				unsigned int entry_count,
618 				unsigned int *p_alloc_count);
619 	int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv);
620 };
621 
622 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
623 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
624 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
625 			enum mlxsw_sp_kvdl_entry_type type,
626 			unsigned int entry_count, u32 *p_entry_index);
627 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
628 			enum mlxsw_sp_kvdl_entry_type type,
629 			unsigned int entry_count, int entry_index);
630 int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
631 				    enum mlxsw_sp_kvdl_entry_type type,
632 				    unsigned int entry_count,
633 				    unsigned int *p_alloc_count);
634 
635 /* spectrum1_kvdl.c */
636 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops;
637 int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core);
638 
639 /* spectrum2_kvdl.c */
640 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops;
641 
642 struct mlxsw_sp_acl_rule_info {
643 	unsigned int priority;
644 	struct mlxsw_afk_element_values values;
645 	struct mlxsw_afa_block *act_block;
646 	u8 action_created:1,
647 	   ingress_bind_blocker:1,
648 	   egress_bind_blocker:1,
649 	   counter_valid:1;
650 	unsigned int counter_index;
651 };
652 
653 /* spectrum_flow.c */
654 struct mlxsw_sp_flow_block {
655 	struct list_head binding_list;
656 	struct {
657 		struct list_head list;
658 		unsigned int min_prio;
659 		unsigned int max_prio;
660 	} mall;
661 	struct mlxsw_sp_acl_ruleset *ruleset_zero;
662 	struct mlxsw_sp *mlxsw_sp;
663 	unsigned int rule_count;
664 	unsigned int disable_count;
665 	unsigned int ingress_blocker_rule_count;
666 	unsigned int egress_blocker_rule_count;
667 	unsigned int ingress_binding_count;
668 	unsigned int egress_binding_count;
669 	struct net *net;
670 };
671 
672 struct mlxsw_sp_flow_block_binding {
673 	struct list_head list;
674 	struct net_device *dev;
675 	struct mlxsw_sp_port *mlxsw_sp_port;
676 	bool ingress;
677 };
678 
679 static inline struct mlxsw_sp *
680 mlxsw_sp_flow_block_mlxsw_sp(struct mlxsw_sp_flow_block *block)
681 {
682 	return block->mlxsw_sp;
683 }
684 
685 static inline unsigned int
686 mlxsw_sp_flow_block_rule_count(const struct mlxsw_sp_flow_block *block)
687 {
688 	return block ? block->rule_count : 0;
689 }
690 
691 static inline void
692 mlxsw_sp_flow_block_disable_inc(struct mlxsw_sp_flow_block *block)
693 {
694 	if (block)
695 		block->disable_count++;
696 }
697 
698 static inline void
699 mlxsw_sp_flow_block_disable_dec(struct mlxsw_sp_flow_block *block)
700 {
701 	if (block)
702 		block->disable_count--;
703 }
704 
705 static inline bool
706 mlxsw_sp_flow_block_disabled(const struct mlxsw_sp_flow_block *block)
707 {
708 	return block->disable_count;
709 }
710 
711 static inline bool
712 mlxsw_sp_flow_block_is_egress_bound(const struct mlxsw_sp_flow_block *block)
713 {
714 	return block->egress_binding_count;
715 }
716 
717 static inline bool
718 mlxsw_sp_flow_block_is_ingress_bound(const struct mlxsw_sp_flow_block *block)
719 {
720 	return block->ingress_binding_count;
721 }
722 
723 static inline bool
724 mlxsw_sp_flow_block_is_mixed_bound(const struct mlxsw_sp_flow_block *block)
725 {
726 	return block->ingress_binding_count && block->egress_binding_count;
727 }
728 
729 struct mlxsw_sp_flow_block *mlxsw_sp_flow_block_create(struct mlxsw_sp *mlxsw_sp,
730 						       struct net *net);
731 void mlxsw_sp_flow_block_destroy(struct mlxsw_sp_flow_block *block);
732 int mlxsw_sp_setup_tc_block(struct mlxsw_sp_port *mlxsw_sp_port,
733 			    struct flow_block_offload *f);
734 
735 /* spectrum_acl.c */
736 struct mlxsw_sp_acl_ruleset;
737 
738 enum mlxsw_sp_acl_profile {
739 	MLXSW_SP_ACL_PROFILE_FLOWER,
740 	MLXSW_SP_ACL_PROFILE_MR,
741 };
742 
743 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
744 
745 int mlxsw_sp_acl_ruleset_bind(struct mlxsw_sp *mlxsw_sp,
746 			      struct mlxsw_sp_flow_block *block,
747 			      struct mlxsw_sp_flow_block_binding *binding);
748 void mlxsw_sp_acl_ruleset_unbind(struct mlxsw_sp *mlxsw_sp,
749 				 struct mlxsw_sp_flow_block *block,
750 				 struct mlxsw_sp_flow_block_binding *binding);
751 struct mlxsw_sp_acl_ruleset *
752 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
753 			    struct mlxsw_sp_flow_block *block, u32 chain_index,
754 			    enum mlxsw_sp_acl_profile profile);
755 struct mlxsw_sp_acl_ruleset *
756 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
757 			 struct mlxsw_sp_flow_block *block, u32 chain_index,
758 			 enum mlxsw_sp_acl_profile profile,
759 			 struct mlxsw_afk_element_usage *tmplt_elusage);
760 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
761 			      struct mlxsw_sp_acl_ruleset *ruleset);
762 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
763 void mlxsw_sp_acl_ruleset_prio_get(struct mlxsw_sp_acl_ruleset *ruleset,
764 				   unsigned int *p_min_prio,
765 				   unsigned int *p_max_prio);
766 
767 struct mlxsw_sp_acl_rule_info *
768 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
769 			  struct mlxsw_afa_block *afa_block);
770 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
771 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
772 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
773 				 unsigned int priority);
774 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
775 				    enum mlxsw_afk_element element,
776 				    u32 key_value, u32 mask_value);
777 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
778 				    enum mlxsw_afk_element element,
779 				    const char *key_value,
780 				    const char *mask_value, unsigned int len);
781 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
782 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
783 				u16 group_id);
784 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
785 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei,
786 				bool ingress,
787 				const struct flow_action_cookie *fa_cookie,
788 				struct netlink_ext_ack *extack);
789 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
790 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
791 				  struct mlxsw_sp_acl_rule_info *rulei,
792 				  struct mlxsw_sp_flow_block *block,
793 				  struct net_device *out_dev,
794 				  struct netlink_ext_ack *extack);
795 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
796 			       struct mlxsw_sp_acl_rule_info *rulei,
797 			       struct net_device *out_dev,
798 			       struct netlink_ext_ack *extack);
799 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
800 				struct mlxsw_sp_acl_rule_info *rulei,
801 				u32 action, u16 vid, u16 proto, u8 prio,
802 				struct netlink_ext_ack *extack);
803 int mlxsw_sp_acl_rulei_act_priority(struct mlxsw_sp *mlxsw_sp,
804 				    struct mlxsw_sp_acl_rule_info *rulei,
805 				    u32 prio, struct netlink_ext_ack *extack);
806 int mlxsw_sp_acl_rulei_act_mangle(struct mlxsw_sp *mlxsw_sp,
807 				  struct mlxsw_sp_acl_rule_info *rulei,
808 				  enum flow_action_mangle_base htype,
809 				  u32 offset, u32 mask, u32 val,
810 				  struct netlink_ext_ack *extack);
811 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
812 				 struct mlxsw_sp_acl_rule_info *rulei,
813 				 struct netlink_ext_ack *extack);
814 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
815 				   struct mlxsw_sp_acl_rule_info *rulei,
816 				   u16 fid, struct netlink_ext_ack *extack);
817 
818 struct mlxsw_sp_acl_rule;
819 
820 struct mlxsw_sp_acl_rule *
821 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
822 			 struct mlxsw_sp_acl_ruleset *ruleset,
823 			 unsigned long cookie,
824 			 struct mlxsw_afa_block *afa_block,
825 			 struct netlink_ext_ack *extack);
826 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
827 			       struct mlxsw_sp_acl_rule *rule);
828 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
829 			  struct mlxsw_sp_acl_rule *rule);
830 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
831 			   struct mlxsw_sp_acl_rule *rule);
832 int mlxsw_sp_acl_rule_action_replace(struct mlxsw_sp *mlxsw_sp,
833 				     struct mlxsw_sp_acl_rule *rule,
834 				     struct mlxsw_afa_block *afa_block);
835 struct mlxsw_sp_acl_rule *
836 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
837 			 struct mlxsw_sp_acl_ruleset *ruleset,
838 			 unsigned long cookie);
839 struct mlxsw_sp_acl_rule_info *
840 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
841 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
842 				struct mlxsw_sp_acl_rule *rule,
843 				u64 *packets, u64 *bytes, u64 *last_use,
844 				enum flow_action_hw_stats *used_hw_stats);
845 
846 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
847 
848 static inline const struct flow_action_cookie *
849 mlxsw_sp_acl_act_cookie_lookup(struct mlxsw_sp *mlxsw_sp, u32 cookie_index)
850 {
851 	return mlxsw_afa_cookie_lookup(mlxsw_sp->afa, cookie_index);
852 }
853 
854 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
855 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
856 u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp);
857 int mlxsw_sp_acl_region_rehash_intrvl_set(struct mlxsw_sp *mlxsw_sp, u32 val);
858 
859 /* spectrum_acl_tcam.c */
860 struct mlxsw_sp_acl_tcam;
861 struct mlxsw_sp_acl_tcam_region;
862 
863 struct mlxsw_sp_acl_tcam_ops {
864 	enum mlxsw_reg_ptar_key_type key_type;
865 	size_t priv_size;
866 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv,
867 		    struct mlxsw_sp_acl_tcam *tcam);
868 	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
869 	size_t region_priv_size;
870 	int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv,
871 			   void *tcam_priv,
872 			   struct mlxsw_sp_acl_tcam_region *region,
873 			   void *hints_priv);
874 	void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
875 	int (*region_associate)(struct mlxsw_sp *mlxsw_sp,
876 				struct mlxsw_sp_acl_tcam_region *region);
877 	void * (*region_rehash_hints_get)(void *region_priv);
878 	void (*region_rehash_hints_put)(void *hints_priv);
879 	size_t chunk_priv_size;
880 	void (*chunk_init)(void *region_priv, void *chunk_priv,
881 			   unsigned int priority);
882 	void (*chunk_fini)(void *chunk_priv);
883 	size_t entry_priv_size;
884 	int (*entry_add)(struct mlxsw_sp *mlxsw_sp,
885 			 void *region_priv, void *chunk_priv,
886 			 void *entry_priv,
887 			 struct mlxsw_sp_acl_rule_info *rulei);
888 	void (*entry_del)(struct mlxsw_sp *mlxsw_sp,
889 			  void *region_priv, void *chunk_priv,
890 			  void *entry_priv);
891 	int (*entry_action_replace)(struct mlxsw_sp *mlxsw_sp,
892 				    void *region_priv, void *entry_priv,
893 				    struct mlxsw_sp_acl_rule_info *rulei);
894 	int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp,
895 				  void *region_priv, void *entry_priv,
896 				  bool *activity);
897 };
898 
899 /* spectrum1_acl_tcam.c */
900 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops;
901 
902 /* spectrum2_acl_tcam.c */
903 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops;
904 
905 /* spectrum_acl_flex_actions.c */
906 extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops;
907 extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops;
908 
909 /* spectrum_acl_flex_keys.c */
910 extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
911 extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;
912 
913 /* spectrum_matchall.c */
914 int mlxsw_sp_mall_replace(struct mlxsw_sp *mlxsw_sp,
915 			  struct mlxsw_sp_flow_block *block,
916 			  struct tc_cls_matchall_offload *f);
917 void mlxsw_sp_mall_destroy(struct mlxsw_sp_flow_block *block,
918 			   struct tc_cls_matchall_offload *f);
919 int mlxsw_sp_mall_port_bind(struct mlxsw_sp_flow_block *block,
920 			    struct mlxsw_sp_port *mlxsw_sp_port);
921 void mlxsw_sp_mall_port_unbind(struct mlxsw_sp_flow_block *block,
922 			       struct mlxsw_sp_port *mlxsw_sp_port);
923 int mlxsw_sp_mall_prio_get(struct mlxsw_sp_flow_block *block, u32 chain_index,
924 			   unsigned int *p_min_prio, unsigned int *p_max_prio);
925 
926 /* spectrum_flower.c */
927 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
928 			    struct mlxsw_sp_flow_block *block,
929 			    struct flow_cls_offload *f);
930 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
931 			     struct mlxsw_sp_flow_block *block,
932 			     struct flow_cls_offload *f);
933 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
934 			  struct mlxsw_sp_flow_block *block,
935 			  struct flow_cls_offload *f);
936 int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
937 				 struct mlxsw_sp_flow_block *block,
938 				 struct flow_cls_offload *f);
939 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
940 				   struct mlxsw_sp_flow_block *block,
941 				   struct flow_cls_offload *f);
942 int mlxsw_sp_flower_prio_get(struct mlxsw_sp *mlxsw_sp,
943 			     struct mlxsw_sp_flow_block *block,
944 			     u32 chain_index, unsigned int *p_min_prio,
945 			     unsigned int *p_max_prio);
946 
947 /* spectrum_qdisc.c */
948 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
949 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
950 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
951 			  struct tc_red_qopt_offload *p);
952 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
953 			   struct tc_prio_qopt_offload *p);
954 int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port,
955 			  struct tc_ets_qopt_offload *p);
956 int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port,
957 			  struct tc_tbf_qopt_offload *p);
958 int mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port,
959 			   struct tc_fifo_qopt_offload *p);
960 
961 /* spectrum_fid.c */
962 bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index);
963 bool mlxsw_sp_fid_lag_vid_valid(const struct mlxsw_sp_fid *fid);
964 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp,
965 						  u16 fid_index);
966 int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex);
967 int mlxsw_sp_fid_nve_type(const struct mlxsw_sp_fid *fid,
968 			  enum mlxsw_sp_nve_type *p_type);
969 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_vni(struct mlxsw_sp *mlxsw_sp,
970 						__be32 vni);
971 int mlxsw_sp_fid_vni(const struct mlxsw_sp_fid *fid, __be32 *vni);
972 int mlxsw_sp_fid_nve_flood_index_set(struct mlxsw_sp_fid *fid,
973 				     u32 nve_flood_index);
974 void mlxsw_sp_fid_nve_flood_index_clear(struct mlxsw_sp_fid *fid);
975 bool mlxsw_sp_fid_nve_flood_index_is_set(const struct mlxsw_sp_fid *fid);
976 int mlxsw_sp_fid_vni_set(struct mlxsw_sp_fid *fid, enum mlxsw_sp_nve_type type,
977 			 __be32 vni, int nve_ifindex);
978 void mlxsw_sp_fid_vni_clear(struct mlxsw_sp_fid *fid);
979 bool mlxsw_sp_fid_vni_is_set(const struct mlxsw_sp_fid *fid);
980 void mlxsw_sp_fid_fdb_clear_offload(const struct mlxsw_sp_fid *fid,
981 				    const struct net_device *nve_dev);
982 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
983 			   enum mlxsw_sp_flood_type packet_type, u8 local_port,
984 			   bool member);
985 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
986 			      struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
987 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
988 				 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
989 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
990 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
991 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
992 struct mlxsw_sp_rif *mlxsw_sp_fid_rif(const struct mlxsw_sp_fid *fid);
993 enum mlxsw_sp_rif_type
994 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
995 			   enum mlxsw_sp_fid_type type);
996 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
997 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
998 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
999 					    int br_ifindex);
1000 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_lookup(struct mlxsw_sp *mlxsw_sp,
1001 					       u16 vid);
1002 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_lookup(struct mlxsw_sp *mlxsw_sp,
1003 					       int br_ifindex);
1004 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
1005 					   u16 rif_index);
1006 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
1007 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
1008 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
1009 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1010 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
1011 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
1012 
1013 /* spectrum_mr.c */
1014 enum mlxsw_sp_mr_route_prio {
1015 	MLXSW_SP_MR_ROUTE_PRIO_SG,
1016 	MLXSW_SP_MR_ROUTE_PRIO_STARG,
1017 	MLXSW_SP_MR_ROUTE_PRIO_CATCHALL,
1018 	__MLXSW_SP_MR_ROUTE_PRIO_MAX
1019 };
1020 
1021 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
1022 
1023 struct mlxsw_sp_mr_route_key;
1024 
1025 struct mlxsw_sp_mr_tcam_ops {
1026 	size_t priv_size;
1027 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
1028 	void (*fini)(void *priv);
1029 	size_t route_priv_size;
1030 	int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
1031 			    void *route_priv,
1032 			    struct mlxsw_sp_mr_route_key *key,
1033 			    struct mlxsw_afa_block *afa_block,
1034 			    enum mlxsw_sp_mr_route_prio prio);
1035 	void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
1036 			      void *route_priv,
1037 			      struct mlxsw_sp_mr_route_key *key);
1038 	int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
1039 			    struct mlxsw_sp_mr_route_key *key,
1040 			    struct mlxsw_afa_block *afa_block);
1041 };
1042 
1043 /* spectrum1_mr_tcam.c */
1044 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops;
1045 
1046 /* spectrum2_mr_tcam.c */
1047 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops;
1048 
1049 /* spectrum_nve.c */
1050 struct mlxsw_sp_nve_params {
1051 	enum mlxsw_sp_nve_type type;
1052 	__be32 vni;
1053 	const struct net_device *dev;
1054 };
1055 
1056 extern const struct mlxsw_sp_nve_ops *mlxsw_sp1_nve_ops_arr[];
1057 extern const struct mlxsw_sp_nve_ops *mlxsw_sp2_nve_ops_arr[];
1058 
1059 int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip,
1060 				    enum mlxsw_sp_l3proto proto,
1061 				    union mlxsw_sp_l3addr *addr);
1062 int mlxsw_sp_nve_flood_ip_add(struct mlxsw_sp *mlxsw_sp,
1063 			      struct mlxsw_sp_fid *fid,
1064 			      enum mlxsw_sp_l3proto proto,
1065 			      union mlxsw_sp_l3addr *addr);
1066 void mlxsw_sp_nve_flood_ip_del(struct mlxsw_sp *mlxsw_sp,
1067 			       struct mlxsw_sp_fid *fid,
1068 			       enum mlxsw_sp_l3proto proto,
1069 			       union mlxsw_sp_l3addr *addr);
1070 int mlxsw_sp_nve_fid_enable(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *fid,
1071 			    struct mlxsw_sp_nve_params *params,
1072 			    struct netlink_ext_ack *extack);
1073 void mlxsw_sp_nve_fid_disable(struct mlxsw_sp *mlxsw_sp,
1074 			      struct mlxsw_sp_fid *fid);
1075 int mlxsw_sp_port_nve_init(struct mlxsw_sp_port *mlxsw_sp_port);
1076 void mlxsw_sp_port_nve_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1077 int mlxsw_sp_nve_init(struct mlxsw_sp *mlxsw_sp);
1078 void mlxsw_sp_nve_fini(struct mlxsw_sp *mlxsw_sp);
1079 
1080 /* spectrum_nve_vxlan.c */
1081 int mlxsw_sp_nve_inc_parsing_depth_get(struct mlxsw_sp *mlxsw_sp);
1082 void mlxsw_sp_nve_inc_parsing_depth_put(struct mlxsw_sp *mlxsw_sp);
1083 
1084 /* spectrum_trap.c */
1085 int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp);
1086 void mlxsw_sp_devlink_traps_fini(struct mlxsw_sp *mlxsw_sp);
1087 int mlxsw_sp_trap_init(struct mlxsw_core *mlxsw_core,
1088 		       const struct devlink_trap *trap, void *trap_ctx);
1089 void mlxsw_sp_trap_fini(struct mlxsw_core *mlxsw_core,
1090 			const struct devlink_trap *trap, void *trap_ctx);
1091 int mlxsw_sp_trap_action_set(struct mlxsw_core *mlxsw_core,
1092 			     const struct devlink_trap *trap,
1093 			     enum devlink_trap_action action);
1094 int mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core,
1095 			     const struct devlink_trap_group *group);
1096 int mlxsw_sp_trap_group_set(struct mlxsw_core *mlxsw_core,
1097 			    const struct devlink_trap_group *group,
1098 			    const struct devlink_trap_policer *policer);
1099 int
1100 mlxsw_sp_trap_policer_init(struct mlxsw_core *mlxsw_core,
1101 			   const struct devlink_trap_policer *policer);
1102 void mlxsw_sp_trap_policer_fini(struct mlxsw_core *mlxsw_core,
1103 				const struct devlink_trap_policer *policer);
1104 int
1105 mlxsw_sp_trap_policer_set(struct mlxsw_core *mlxsw_core,
1106 			  const struct devlink_trap_policer *policer,
1107 			  u64 rate, u64 burst, struct netlink_ext_ack *extack);
1108 int
1109 mlxsw_sp_trap_policer_counter_get(struct mlxsw_core *mlxsw_core,
1110 				  const struct devlink_trap_policer *policer,
1111 				  u64 *p_drops);
1112 
1113 static inline struct net *mlxsw_sp_net(struct mlxsw_sp *mlxsw_sp)
1114 {
1115 	return mlxsw_core_net(mlxsw_sp->core);
1116 }
1117 
1118 #endif
1119