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/ethtool.h>
8 #include <linux/types.h>
9 #include <linux/netdevice.h>
10 #include <linux/rhashtable.h>
11 #include <linux/bitops.h>
12 #include <linux/if_bridge.h>
13 #include <linux/if_vlan.h>
14 #include <linux/list.h>
15 #include <linux/dcbnl.h>
16 #include <linux/in6.h>
17 #include <linux/notifier.h>
18 #include <linux/net_namespace.h>
19 #include <linux/spinlock.h>
20 #include <net/psample.h>
21 #include <net/pkt_cls.h>
22 #include <net/red.h>
23 #include <net/vxlan.h>
24 #include <net/flow_offload.h>
25 #include <net/inet_ecn.h>
26 
27 #include "port.h"
28 #include "core.h"
29 #include "core_acl_flex_keys.h"
30 #include "core_acl_flex_actions.h"
31 #include "reg.h"
32 
33 #define MLXSW_SP_DEFAULT_VID (VLAN_N_VID - 1)
34 
35 #define MLXSW_SP_FID_8021D_MAX 1024
36 
37 #define MLXSW_SP_MID_MAX 7000
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 #define MLXSW_SP_RESOURCE_NAME_SPAN "span_agents"
51 
52 #define MLXSW_SP_RESOURCE_NAME_COUNTERS "counters"
53 #define MLXSW_SP_RESOURCE_NAME_COUNTERS_FLOW "flow"
54 #define MLXSW_SP_RESOURCE_NAME_COUNTERS_RIF "rif"
55 
56 enum mlxsw_sp_resource_id {
57 	MLXSW_SP_RESOURCE_KVD = MLXSW_CORE_RESOURCE_MAX,
58 	MLXSW_SP_RESOURCE_KVD_LINEAR,
59 	MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
60 	MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
61 	MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE,
62 	MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS,
63 	MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS,
64 	MLXSW_SP_RESOURCE_SPAN,
65 	MLXSW_SP_RESOURCE_COUNTERS,
66 	MLXSW_SP_RESOURCE_COUNTERS_FLOW,
67 	MLXSW_SP_RESOURCE_COUNTERS_RIF,
68 	MLXSW_SP_RESOURCE_GLOBAL_POLICERS,
69 	MLXSW_SP_RESOURCE_SINGLE_RATE_POLICERS,
70 	MLXSW_SP_RESOURCE_RIF_MAC_PROFILES,
71 };
72 
73 struct mlxsw_sp_port;
74 struct mlxsw_sp_rif;
75 struct mlxsw_sp_span_entry;
76 enum mlxsw_sp_l3proto;
77 union mlxsw_sp_l3addr;
78 
79 struct mlxsw_sp_upper {
80 	struct net_device *dev;
81 	unsigned int ref_count;
82 };
83 
84 enum mlxsw_sp_rif_type {
85 	MLXSW_SP_RIF_TYPE_SUBPORT,
86 	MLXSW_SP_RIF_TYPE_VLAN,
87 	MLXSW_SP_RIF_TYPE_FID,
88 	MLXSW_SP_RIF_TYPE_IPIP_LB, /* IP-in-IP loopback. */
89 	MLXSW_SP_RIF_TYPE_MAX,
90 };
91 
92 struct mlxsw_sp_router_ops;
93 
94 extern const struct mlxsw_sp_router_ops mlxsw_sp1_router_ops;
95 extern const struct mlxsw_sp_router_ops mlxsw_sp2_router_ops;
96 
97 struct mlxsw_sp_switchdev_ops;
98 
99 extern const struct mlxsw_sp_switchdev_ops mlxsw_sp1_switchdev_ops;
100 extern const struct mlxsw_sp_switchdev_ops mlxsw_sp2_switchdev_ops;
101 
102 enum mlxsw_sp_fid_type {
103 	MLXSW_SP_FID_TYPE_8021Q,
104 	MLXSW_SP_FID_TYPE_8021D,
105 	MLXSW_SP_FID_TYPE_RFID,
106 	MLXSW_SP_FID_TYPE_DUMMY,
107 	MLXSW_SP_FID_TYPE_MAX,
108 };
109 
110 enum mlxsw_sp_nve_type {
111 	MLXSW_SP_NVE_TYPE_VXLAN,
112 };
113 
114 struct mlxsw_sp_mid {
115 	struct list_head list;
116 	unsigned char addr[ETH_ALEN];
117 	u16 fid;
118 	u16 mid;
119 	bool in_hw;
120 	unsigned long *ports_in_mid; /* bits array */
121 };
122 
123 struct mlxsw_sp_sb;
124 struct mlxsw_sp_bridge;
125 struct mlxsw_sp_router;
126 struct mlxsw_sp_mr;
127 struct mlxsw_sp_acl;
128 struct mlxsw_sp_counter_pool;
129 struct mlxsw_sp_fid_core;
130 struct mlxsw_sp_kvdl;
131 struct mlxsw_sp_nve;
132 struct mlxsw_sp_kvdl_ops;
133 struct mlxsw_sp_mr_tcam_ops;
134 struct mlxsw_sp_acl_rulei_ops;
135 struct mlxsw_sp_acl_tcam_ops;
136 struct mlxsw_sp_nve_ops;
137 struct mlxsw_sp_sb_ops;
138 struct mlxsw_sp_sb_vals;
139 struct mlxsw_sp_port_type_speed_ops;
140 struct mlxsw_sp_ptp_state;
141 struct mlxsw_sp_ptp_ops;
142 struct mlxsw_sp_span_ops;
143 struct mlxsw_sp_qdisc_state;
144 struct mlxsw_sp_mall_entry;
145 
146 struct mlxsw_sp_port_mapping {
147 	u8 module;
148 	u8 width; /* Number of lanes used by the port */
149 	u8 module_width; /* Number of lanes in the module (static) */
150 	u8 lane;
151 };
152 
153 struct mlxsw_sp_parsing {
154 	refcount_t parsing_depth_ref;
155 	u16 parsing_depth;
156 	u16 vxlan_udp_dport;
157 	struct mutex lock; /* Protects parsing configuration */
158 };
159 
160 struct mlxsw_sp {
161 	struct mlxsw_sp_port **ports;
162 	struct mlxsw_core *core;
163 	const struct mlxsw_bus_info *bus_info;
164 	unsigned char base_mac[ETH_ALEN];
165 	const unsigned char *mac_mask;
166 	struct mlxsw_sp_upper *lags;
167 	struct mlxsw_sp_port_mapping **port_mapping;
168 	struct rhashtable sample_trigger_ht;
169 	struct mlxsw_sp_sb *sb;
170 	struct mlxsw_sp_bridge *bridge;
171 	struct mlxsw_sp_router *router;
172 	struct mlxsw_sp_mr *mr;
173 	struct mlxsw_afa *afa;
174 	struct mlxsw_sp_acl *acl;
175 	struct mlxsw_sp_fid_core *fid_core;
176 	struct mlxsw_sp_policer_core *policer_core;
177 	struct mlxsw_sp_kvdl *kvdl;
178 	struct mlxsw_sp_nve *nve;
179 	struct notifier_block netdevice_nb;
180 	struct mlxsw_sp_ptp_clock *clock;
181 	struct mlxsw_sp_ptp_state *ptp_state;
182 	struct mlxsw_sp_counter_pool *counter_pool;
183 	struct mlxsw_sp_span *span;
184 	struct mlxsw_sp_trap *trap;
185 	struct mlxsw_sp_parsing parsing;
186 	const struct mlxsw_sp_switchdev_ops *switchdev_ops;
187 	const struct mlxsw_sp_kvdl_ops *kvdl_ops;
188 	const struct mlxsw_afa_ops *afa_ops;
189 	const struct mlxsw_afk_ops *afk_ops;
190 	const struct mlxsw_sp_mr_tcam_ops *mr_tcam_ops;
191 	const struct mlxsw_sp_acl_rulei_ops *acl_rulei_ops;
192 	const struct mlxsw_sp_acl_tcam_ops *acl_tcam_ops;
193 	const struct mlxsw_sp_acl_bf_ops *acl_bf_ops;
194 	const struct mlxsw_sp_nve_ops **nve_ops_arr;
195 	const struct mlxsw_sp_sb_vals *sb_vals;
196 	const struct mlxsw_sp_sb_ops *sb_ops;
197 	const struct mlxsw_sp_port_type_speed_ops *port_type_speed_ops;
198 	const struct mlxsw_sp_ptp_ops *ptp_ops;
199 	const struct mlxsw_sp_span_ops *span_ops;
200 	const struct mlxsw_sp_policer_core_ops *policer_core_ops;
201 	const struct mlxsw_sp_trap_ops *trap_ops;
202 	const struct mlxsw_sp_mall_ops *mall_ops;
203 	const struct mlxsw_sp_router_ops *router_ops;
204 	const struct mlxsw_listener *listeners;
205 	size_t listeners_count;
206 	u32 lowest_shaper_bs;
207 	struct rhashtable ipv6_addr_ht;
208 	struct mutex ipv6_addr_ht_lock; /* Protects ipv6_addr_ht */
209 };
210 
211 struct mlxsw_sp_ptp_ops {
212 	struct mlxsw_sp_ptp_clock *
213 		(*clock_init)(struct mlxsw_sp *mlxsw_sp, struct device *dev);
214 	void (*clock_fini)(struct mlxsw_sp_ptp_clock *clock);
215 
216 	struct mlxsw_sp_ptp_state *(*init)(struct mlxsw_sp *mlxsw_sp);
217 	void (*fini)(struct mlxsw_sp_ptp_state *ptp_state);
218 
219 	/* Notify a driver that a packet that might be PTP was received. Driver
220 	 * is responsible for freeing the passed-in SKB.
221 	 */
222 	void (*receive)(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
223 			u16 local_port);
224 
225 	/* Notify a driver that a timestamped packet was transmitted. Driver
226 	 * is responsible for freeing the passed-in SKB.
227 	 */
228 	void (*transmitted)(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
229 			    u16 local_port);
230 
231 	int (*hwtstamp_get)(struct mlxsw_sp_port *mlxsw_sp_port,
232 			    struct hwtstamp_config *config);
233 	int (*hwtstamp_set)(struct mlxsw_sp_port *mlxsw_sp_port,
234 			    struct hwtstamp_config *config);
235 	void (*shaper_work)(struct work_struct *work);
236 	int (*get_ts_info)(struct mlxsw_sp *mlxsw_sp,
237 			   struct ethtool_ts_info *info);
238 	int (*get_stats_count)(void);
239 	void (*get_stats_strings)(u8 **p);
240 	void (*get_stats)(struct mlxsw_sp_port *mlxsw_sp_port,
241 			  u64 *data, int data_index);
242 };
243 
244 static inline struct mlxsw_sp_upper *
245 mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
246 {
247 	return &mlxsw_sp->lags[lag_id];
248 }
249 
250 struct mlxsw_sp_port_pcpu_stats {
251 	u64			rx_packets;
252 	u64			rx_bytes;
253 	u64			tx_packets;
254 	u64			tx_bytes;
255 	struct u64_stats_sync	syncp;
256 	u32			tx_dropped;
257 };
258 
259 enum mlxsw_sp_sample_trigger_type {
260 	MLXSW_SP_SAMPLE_TRIGGER_TYPE_INGRESS,
261 	MLXSW_SP_SAMPLE_TRIGGER_TYPE_EGRESS,
262 	MLXSW_SP_SAMPLE_TRIGGER_TYPE_POLICY_ENGINE,
263 };
264 
265 struct mlxsw_sp_sample_trigger {
266 	enum mlxsw_sp_sample_trigger_type type;
267 	u16 local_port; /* Reserved when trigger type is not ingress / egress. */
268 };
269 
270 struct mlxsw_sp_sample_params {
271 	struct psample_group *psample_group;
272 	u32 trunc_size;
273 	u32 rate;
274 	bool truncate;
275 };
276 
277 struct mlxsw_sp_bridge_port;
278 struct mlxsw_sp_fid;
279 
280 struct mlxsw_sp_port_vlan {
281 	struct list_head list;
282 	struct mlxsw_sp_port *mlxsw_sp_port;
283 	struct mlxsw_sp_fid *fid;
284 	u16 vid;
285 	struct mlxsw_sp_bridge_port *bridge_port;
286 	struct list_head bridge_vlan_node;
287 };
288 
289 /* No need an internal lock; At worse - miss a single periodic iteration */
290 struct mlxsw_sp_port_xstats {
291 	u64 ecn;
292 	u64 tc_ecn[TC_MAX_QUEUE];
293 	u64 wred_drop[TC_MAX_QUEUE];
294 	u64 tail_drop[TC_MAX_QUEUE];
295 	u64 backlog[TC_MAX_QUEUE];
296 	u64 tx_bytes[IEEE_8021QAZ_MAX_TCS];
297 	u64 tx_packets[IEEE_8021QAZ_MAX_TCS];
298 };
299 
300 struct mlxsw_sp_ptp_port_dir_stats {
301 	u64 packets;
302 	u64 timestamps;
303 };
304 
305 struct mlxsw_sp_ptp_port_stats {
306 	struct mlxsw_sp_ptp_port_dir_stats rx_gcd;
307 	struct mlxsw_sp_ptp_port_dir_stats tx_gcd;
308 };
309 
310 struct mlxsw_sp_port {
311 	struct net_device *dev;
312 	struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
313 	struct mlxsw_sp *mlxsw_sp;
314 	u16 local_port;
315 	u8 lagged:1,
316 	   split:1;
317 	u16 pvid;
318 	u16 lag_id;
319 	struct {
320 		u8 tx_pause:1,
321 		   rx_pause:1,
322 		   autoneg:1;
323 	} link;
324 	struct {
325 		struct ieee_ets *ets;
326 		struct ieee_maxrate *maxrate;
327 		struct ieee_pfc *pfc;
328 		enum mlxsw_reg_qpts_trust_state trust_state;
329 	} dcb;
330 	struct mlxsw_sp_port_mapping mapping; /* mapping is constant during the
331 					       * mlxsw_sp_port lifetime, however
332 					       * the same localport can have
333 					       * different mapping.
334 					       */
335 	struct {
336 		#define MLXSW_HW_STATS_UPDATE_TIME HZ
337 		struct rtnl_link_stats64 stats;
338 		struct mlxsw_sp_port_xstats xstats;
339 		struct delayed_work update_dw;
340 	} periodic_hw_stats;
341 	struct list_head vlans_list;
342 	struct mlxsw_sp_port_vlan *default_vlan;
343 	struct mlxsw_sp_qdisc_state *qdisc;
344 	unsigned acl_rule_count;
345 	struct mlxsw_sp_flow_block *ing_flow_block;
346 	struct mlxsw_sp_flow_block *eg_flow_block;
347 	struct {
348 		struct delayed_work shaper_dw;
349 		struct hwtstamp_config hwtstamp_config;
350 		u16 ing_types;
351 		u16 egr_types;
352 		struct mlxsw_sp_ptp_port_stats stats;
353 	} ptp;
354 	int max_mtu;
355 	u32 max_speed;
356 	struct mlxsw_sp_hdroom *hdroom;
357 	u64 module_overheat_initial_val;
358 };
359 
360 struct mlxsw_sp_port_type_speed_ops {
361 	void (*from_ptys_supported_port)(struct mlxsw_sp *mlxsw_sp,
362 					 u32 ptys_eth_proto,
363 					 struct ethtool_link_ksettings *cmd);
364 	void (*from_ptys_link)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
365 			       unsigned long *mode);
366 	u32 (*from_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto);
367 	void (*from_ptys_link_mode)(struct mlxsw_sp *mlxsw_sp,
368 				    bool carrier_ok, u32 ptys_eth_proto,
369 				    struct ethtool_link_ksettings *cmd);
370 	int (*ptys_max_speed)(struct mlxsw_sp_port *mlxsw_sp_port, u32 *p_max_speed);
371 	u32 (*to_ptys_advert_link)(struct mlxsw_sp *mlxsw_sp,
372 				   const struct ethtool_link_ksettings *cmd);
373 	u32 (*to_ptys_speed_lanes)(struct mlxsw_sp *mlxsw_sp, u8 width,
374 				   const struct ethtool_link_ksettings *cmd);
375 	void (*reg_ptys_eth_pack)(struct mlxsw_sp *mlxsw_sp, char *payload,
376 				  u16 local_port, u32 proto_admin, bool autoneg);
377 	void (*reg_ptys_eth_unpack)(struct mlxsw_sp *mlxsw_sp, char *payload,
378 				    u32 *p_eth_proto_cap,
379 				    u32 *p_eth_proto_admin,
380 				    u32 *p_eth_proto_oper);
381 	u32 (*ptys_proto_cap_masked_get)(u32 eth_proto_cap);
382 };
383 
384 static inline u8 mlxsw_sp_tunnel_ecn_decap(u8 outer_ecn, u8 inner_ecn,
385 					   bool *trap_en)
386 {
387 	bool set_ce = false;
388 
389 	*trap_en = !!__INET_ECN_decapsulate(outer_ecn, inner_ecn, &set_ce);
390 	if (set_ce)
391 		return INET_ECN_CE;
392 	else if (outer_ecn == INET_ECN_ECT_1 && inner_ecn == INET_ECN_ECT_0)
393 		return INET_ECN_ECT_1;
394 	else
395 		return inner_ecn;
396 }
397 
398 static inline struct net_device *
399 mlxsw_sp_bridge_vxlan_dev_find(struct net_device *br_dev)
400 {
401 	struct net_device *dev;
402 	struct list_head *iter;
403 
404 	netdev_for_each_lower_dev(br_dev, dev, iter) {
405 		if (netif_is_vxlan(dev))
406 			return dev;
407 	}
408 
409 	return NULL;
410 }
411 
412 static inline bool mlxsw_sp_bridge_has_vxlan(struct net_device *br_dev)
413 {
414 	return !!mlxsw_sp_bridge_vxlan_dev_find(br_dev);
415 }
416 
417 static inline int
418 mlxsw_sp_vxlan_mapped_vid(const struct net_device *vxlan_dev, u16 *p_vid)
419 {
420 	struct bridge_vlan_info vinfo;
421 	u16 vid = 0;
422 	int err;
423 
424 	err = br_vlan_get_pvid(vxlan_dev, &vid);
425 	if (err || !vid)
426 		goto out;
427 
428 	err = br_vlan_get_info(vxlan_dev, vid, &vinfo);
429 	if (err || !(vinfo.flags & BRIDGE_VLAN_INFO_UNTAGGED))
430 		vid = 0;
431 
432 out:
433 	*p_vid = vid;
434 	return err;
435 }
436 
437 static inline bool
438 mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
439 {
440 	return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
441 }
442 
443 static inline struct mlxsw_sp_port *
444 mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
445 {
446 	struct mlxsw_sp_port *mlxsw_sp_port;
447 	u16 local_port;
448 
449 	local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
450 						lag_id, port_index);
451 	mlxsw_sp_port = mlxsw_sp->ports[local_port];
452 	return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
453 }
454 
455 static inline struct mlxsw_sp_port_vlan *
456 mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
457 			       u16 vid)
458 {
459 	struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
460 
461 	list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
462 			    list) {
463 		if (mlxsw_sp_port_vlan->vid == vid)
464 			return mlxsw_sp_port_vlan;
465 	}
466 
467 	return NULL;
468 }
469 
470 enum mlxsw_sp_flood_type {
471 	MLXSW_SP_FLOOD_TYPE_UC,
472 	MLXSW_SP_FLOOD_TYPE_BC,
473 	MLXSW_SP_FLOOD_TYPE_MC,
474 };
475 
476 int mlxsw_sp_port_get_stats_raw(struct net_device *dev, int grp,
477 				int prio, char *ppcnt_pl);
478 int mlxsw_sp_port_admin_status_set(struct mlxsw_sp_port *mlxsw_sp_port,
479 				   bool is_up);
480 int
481 mlxsw_sp_port_vlan_classification_set(struct mlxsw_sp_port *mlxsw_sp_port,
482 				      bool is_8021ad_tagged,
483 				      bool is_8021q_tagged);
484 static inline bool
485 mlxsw_sp_local_port_is_valid(struct mlxsw_sp *mlxsw_sp, u16 local_port)
486 {
487 	unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core);
488 
489 	return local_port < max_ports && local_port;
490 }
491 
492 /* spectrum_buffers.c */
493 struct mlxsw_sp_hdroom_prio {
494 	/* Number of port buffer associated with this priority. This is the
495 	 * actually configured value.
496 	 */
497 	u8 buf_idx;
498 	/* Value of buf_idx deduced from the DCB ETS configuration. */
499 	u8 ets_buf_idx;
500 	/* Value of buf_idx taken from the dcbnl_setbuffer configuration. */
501 	u8 set_buf_idx;
502 	bool lossy;
503 };
504 
505 struct mlxsw_sp_hdroom_buf {
506 	u32 thres_cells;
507 	u32 size_cells;
508 	/* Size requirement form dcbnl_setbuffer. */
509 	u32 set_size_cells;
510 	bool lossy;
511 };
512 
513 enum mlxsw_sp_hdroom_mode {
514 	MLXSW_SP_HDROOM_MODE_DCB,
515 	MLXSW_SP_HDROOM_MODE_TC,
516 };
517 
518 #define MLXSW_SP_PB_COUNT 10
519 
520 struct mlxsw_sp_hdroom {
521 	enum mlxsw_sp_hdroom_mode mode;
522 
523 	struct {
524 		struct mlxsw_sp_hdroom_prio prio[IEEE_8021Q_MAX_PRIORITIES];
525 	} prios;
526 	struct {
527 		struct mlxsw_sp_hdroom_buf buf[MLXSW_SP_PB_COUNT];
528 	} bufs;
529 	struct {
530 		/* Size actually configured for the internal buffer. Equal to
531 		 * reserve when internal buffer is enabled.
532 		 */
533 		u32 size_cells;
534 		/* Space reserved in the headroom for the internal buffer. Port
535 		 * buffers are not allowed to grow into this space.
536 		 */
537 		u32 reserve_cells;
538 		bool enable;
539 	} int_buf;
540 	int delay_bytes;
541 	int mtu;
542 };
543 
544 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
545 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
546 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
547 void mlxsw_sp_port_buffers_fini(struct mlxsw_sp_port *mlxsw_sp_port);
548 int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
549 			 unsigned int sb_index, u16 pool_index,
550 			 struct devlink_sb_pool_info *pool_info);
551 int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
552 			 unsigned int sb_index, u16 pool_index, u32 size,
553 			 enum devlink_sb_threshold_type threshold_type,
554 			 struct netlink_ext_ack *extack);
555 int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
556 			      unsigned int sb_index, u16 pool_index,
557 			      u32 *p_threshold);
558 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
559 			      unsigned int sb_index, u16 pool_index,
560 			      u32 threshold, struct netlink_ext_ack *extack);
561 int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
562 				 unsigned int sb_index, u16 tc_index,
563 				 enum devlink_sb_pool_type pool_type,
564 				 u16 *p_pool_index, u32 *p_threshold);
565 int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
566 				 unsigned int sb_index, u16 tc_index,
567 				 enum devlink_sb_pool_type pool_type,
568 				 u16 pool_index, u32 threshold,
569 				 struct netlink_ext_ack *extack);
570 int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
571 			     unsigned int sb_index);
572 int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
573 			      unsigned int sb_index);
574 int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
575 				  unsigned int sb_index, u16 pool_index,
576 				  u32 *p_cur, u32 *p_max);
577 int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
578 				     unsigned int sb_index, u16 tc_index,
579 				     enum devlink_sb_pool_type pool_type,
580 				     u32 *p_cur, u32 *p_max);
581 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
582 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
583 void mlxsw_sp_hdroom_prios_reset_buf_idx(struct mlxsw_sp_hdroom *hdroom);
584 void mlxsw_sp_hdroom_bufs_reset_lossiness(struct mlxsw_sp_hdroom *hdroom);
585 void mlxsw_sp_hdroom_bufs_reset_sizes(struct mlxsw_sp_port *mlxsw_sp_port,
586 				      struct mlxsw_sp_hdroom *hdroom);
587 int mlxsw_sp_hdroom_configure(struct mlxsw_sp_port *mlxsw_sp_port,
588 			      const struct mlxsw_sp_hdroom *hdroom);
589 struct mlxsw_sp_sample_params *
590 mlxsw_sp_sample_trigger_params_lookup(struct mlxsw_sp *mlxsw_sp,
591 				      const struct mlxsw_sp_sample_trigger *trigger);
592 int
593 mlxsw_sp_sample_trigger_params_set(struct mlxsw_sp *mlxsw_sp,
594 				   const struct mlxsw_sp_sample_trigger *trigger,
595 				   const struct mlxsw_sp_sample_params *params,
596 				   struct netlink_ext_ack *extack);
597 void
598 mlxsw_sp_sample_trigger_params_unset(struct mlxsw_sp *mlxsw_sp,
599 				     const struct mlxsw_sp_sample_trigger *trigger);
600 int mlxsw_sp_ipv6_addr_kvdl_index_get(struct mlxsw_sp *mlxsw_sp,
601 				      const struct in6_addr *addr6,
602 				      u32 *p_kvdl_index);
603 void
604 mlxsw_sp_ipv6_addr_put(struct mlxsw_sp *mlxsw_sp, const struct in6_addr *addr6);
605 
606 extern const struct mlxsw_sp_sb_vals mlxsw_sp1_sb_vals;
607 extern const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals;
608 
609 extern const struct mlxsw_sp_sb_ops mlxsw_sp1_sb_ops;
610 extern const struct mlxsw_sp_sb_ops mlxsw_sp2_sb_ops;
611 extern const struct mlxsw_sp_sb_ops mlxsw_sp3_sb_ops;
612 
613 /* spectrum_switchdev.c */
614 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
615 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
616 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
617 			bool adding);
618 void
619 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
620 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
621 			      struct net_device *brport_dev,
622 			      struct net_device *br_dev,
623 			      struct netlink_ext_ack *extack);
624 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
625 				struct net_device *brport_dev,
626 				struct net_device *br_dev);
627 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
628 					 const struct net_device *br_dev);
629 int mlxsw_sp_bridge_vxlan_join(struct mlxsw_sp *mlxsw_sp,
630 			       const struct net_device *br_dev,
631 			       const struct net_device *vxlan_dev, u16 vid,
632 			       struct netlink_ext_ack *extack);
633 void mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp,
634 				 const struct net_device *vxlan_dev);
635 extern struct notifier_block mlxsw_sp_switchdev_notifier;
636 
637 /* spectrum.c */
638 void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb,
639 				       u16 local_port, void *priv);
640 void mlxsw_sp_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
641 			  u16 local_port);
642 int mlxsw_sp_port_speed_get(struct mlxsw_sp_port *mlxsw_sp_port, u32 *speed);
643 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
644 			  enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
645 			  bool dwrr, u8 dwrr_weight);
646 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
647 			      u8 switch_prio, u8 tclass);
648 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
649 				  enum mlxsw_reg_qeec_hr hr, u8 index,
650 				  u8 next_index, u32 maxrate, u8 burst_size);
651 enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state);
652 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
653 			      u8 state);
654 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
655 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
656 				   bool learn_enable);
657 int mlxsw_sp_ethtype_to_sver_type(u16 ethtype, u8 *p_sver_type);
658 int mlxsw_sp_port_egress_ethtype_set(struct mlxsw_sp_port *mlxsw_sp_port,
659 				     u16 ethtype);
660 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
661 			   u16 ethtype);
662 struct mlxsw_sp_port_vlan *
663 mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
664 void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
665 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
666 			   u16 vid_end, bool is_member, bool untagged);
667 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
668 			      unsigned int counter_index, u64 *packets,
669 			      u64 *bytes);
670 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
671 				unsigned int *p_counter_index);
672 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
673 				unsigned int counter_index);
674 bool mlxsw_sp_port_dev_check(const struct net_device *dev);
675 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
676 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
677 struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
678 void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
679 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
680 int mlxsw_sp_parsing_depth_inc(struct mlxsw_sp *mlxsw_sp);
681 void mlxsw_sp_parsing_depth_dec(struct mlxsw_sp *mlxsw_sp);
682 int mlxsw_sp_parsing_vxlan_udp_dport_set(struct mlxsw_sp *mlxsw_sp,
683 					 __be16 udp_dport);
684 
685 /* spectrum_dcb.c */
686 #ifdef CONFIG_MLXSW_SPECTRUM_DCB
687 int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
688 void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
689 #else
690 static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
691 {
692 	return 0;
693 }
694 static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
695 {}
696 #endif
697 
698 /* spectrum_router.c */
699 enum mlxsw_sp_l3proto {
700 	MLXSW_SP_L3_PROTO_IPV4,
701 	MLXSW_SP_L3_PROTO_IPV6,
702 #define MLXSW_SP_L3_PROTO_MAX	(MLXSW_SP_L3_PROTO_IPV6 + 1)
703 };
704 
705 union mlxsw_sp_l3addr {
706 	__be32 addr4;
707 	struct in6_addr addr6;
708 };
709 
710 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp,
711 			 struct netlink_ext_ack *extack);
712 void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
713 int mlxsw_sp_netdevice_router_port_event(struct net_device *dev,
714 					 unsigned long event, void *ptr);
715 void mlxsw_sp_rif_macvlan_del(struct mlxsw_sp *mlxsw_sp,
716 			      const struct net_device *macvlan_dev);
717 int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
718 				  unsigned long event, void *ptr);
719 int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
720 				   unsigned long event, void *ptr);
721 int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
722 				 struct netdev_notifier_changeupper_info *info);
723 bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp,
724 				const struct net_device *dev);
725 bool mlxsw_sp_netdev_is_ipip_ul(struct mlxsw_sp *mlxsw_sp,
726 				const struct net_device *dev);
727 int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,
728 				     struct net_device *l3_dev,
729 				     unsigned long event,
730 				     struct netdev_notifier_info *info);
731 int
732 mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
733 				 struct net_device *l3_dev,
734 				 unsigned long event,
735 				 struct netdev_notifier_info *info);
736 int
737 mlxsw_sp_port_vlan_router_join(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan,
738 			       struct net_device *l3_dev,
739 			       struct netlink_ext_ack *extack);
740 void
741 mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
742 void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp,
743 				 struct net_device *dev);
744 bool mlxsw_sp_rif_exists(struct mlxsw_sp *mlxsw_sp,
745 			 const struct net_device *dev);
746 u16 mlxsw_sp_rif_vid(struct mlxsw_sp *mlxsw_sp, const struct net_device *dev);
747 u16 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp);
748 int mlxsw_sp_router_nve_promote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
749 				      enum mlxsw_sp_l3proto ul_proto,
750 				      const union mlxsw_sp_l3addr *ul_sip,
751 				      u32 tunnel_index);
752 void mlxsw_sp_router_nve_demote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
753 				      enum mlxsw_sp_l3proto ul_proto,
754 				      const union mlxsw_sp_l3addr *ul_sip);
755 int mlxsw_sp_router_tb_id_vr_id(struct mlxsw_sp *mlxsw_sp, u32 tb_id,
756 				u16 *vr_id);
757 int mlxsw_sp_router_ul_rif_get(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
758 			       u16 *ul_rif_index);
759 void mlxsw_sp_router_ul_rif_put(struct mlxsw_sp *mlxsw_sp, u16 ul_rif_index);
760 
761 /* spectrum_kvdl.c */
762 enum mlxsw_sp_kvdl_entry_type {
763 	MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
764 	MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
765 	MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
766 	MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
767 	MLXSW_SP_KVDL_ENTRY_TYPE_IPV6_ADDRESS,
768 	MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT,
769 };
770 
771 static inline unsigned int
772 mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type)
773 {
774 	switch (type) {
775 	case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ:
776 	case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET:
777 	case MLXSW_SP_KVDL_ENTRY_TYPE_PBS:
778 	case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR:
779 	case MLXSW_SP_KVDL_ENTRY_TYPE_IPV6_ADDRESS:
780 	case MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT:
781 	default:
782 		return 1;
783 	}
784 }
785 
786 struct mlxsw_sp_kvdl_ops {
787 	size_t priv_size;
788 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
789 	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
790 	int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv,
791 		     enum mlxsw_sp_kvdl_entry_type type,
792 		     unsigned int entry_count, u32 *p_entry_index);
793 	void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv,
794 		     enum mlxsw_sp_kvdl_entry_type type,
795 		     unsigned int entry_count, int entry_index);
796 	int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv,
797 				enum mlxsw_sp_kvdl_entry_type type,
798 				unsigned int entry_count,
799 				unsigned int *p_alloc_count);
800 	int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv);
801 };
802 
803 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
804 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
805 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
806 			enum mlxsw_sp_kvdl_entry_type type,
807 			unsigned int entry_count, u32 *p_entry_index);
808 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
809 			enum mlxsw_sp_kvdl_entry_type type,
810 			unsigned int entry_count, int entry_index);
811 int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
812 				    enum mlxsw_sp_kvdl_entry_type type,
813 				    unsigned int entry_count,
814 				    unsigned int *p_alloc_count);
815 
816 /* spectrum1_kvdl.c */
817 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops;
818 int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core);
819 
820 /* spectrum2_kvdl.c */
821 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops;
822 
823 enum mlxsw_sp_acl_mangle_field {
824 	MLXSW_SP_ACL_MANGLE_FIELD_IP_DSFIELD,
825 	MLXSW_SP_ACL_MANGLE_FIELD_IP_DSCP,
826 	MLXSW_SP_ACL_MANGLE_FIELD_IP_ECN,
827 	MLXSW_SP_ACL_MANGLE_FIELD_IP_SPORT,
828 	MLXSW_SP_ACL_MANGLE_FIELD_IP_DPORT,
829 	MLXSW_SP_ACL_MANGLE_FIELD_IP4_SIP,
830 	MLXSW_SP_ACL_MANGLE_FIELD_IP4_DIP,
831 	MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_1,
832 	MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_2,
833 	MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_3,
834 	MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_4,
835 	MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_1,
836 	MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_2,
837 	MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_3,
838 	MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_4,
839 };
840 
841 struct mlxsw_sp_acl_rule_info {
842 	unsigned int priority;
843 	struct mlxsw_afk_element_values values;
844 	struct mlxsw_afa_block *act_block;
845 	u8 action_created:1,
846 	   ingress_bind_blocker:1,
847 	   egress_bind_blocker:1,
848 	   counter_valid:1,
849 	   policer_index_valid:1,
850 	   ipv6_valid:1;
851 	unsigned int counter_index;
852 	u16 policer_index;
853 	struct {
854 		u32 prev_val;
855 		enum mlxsw_sp_acl_mangle_field prev_field;
856 	} ipv6;
857 };
858 
859 /* spectrum_flow.c */
860 struct mlxsw_sp_flow_block {
861 	struct list_head binding_list;
862 	struct {
863 		struct list_head list;
864 		unsigned int min_prio;
865 		unsigned int max_prio;
866 	} mall;
867 	struct mlxsw_sp_acl_ruleset *ruleset_zero;
868 	struct mlxsw_sp *mlxsw_sp;
869 	unsigned int rule_count;
870 	unsigned int disable_count;
871 	unsigned int ingress_blocker_rule_count;
872 	unsigned int egress_blocker_rule_count;
873 	unsigned int ingress_binding_count;
874 	unsigned int egress_binding_count;
875 	struct net *net;
876 };
877 
878 struct mlxsw_sp_flow_block_binding {
879 	struct list_head list;
880 	struct mlxsw_sp_port *mlxsw_sp_port;
881 	bool ingress;
882 };
883 
884 static inline struct mlxsw_sp *
885 mlxsw_sp_flow_block_mlxsw_sp(struct mlxsw_sp_flow_block *block)
886 {
887 	return block->mlxsw_sp;
888 }
889 
890 static inline unsigned int
891 mlxsw_sp_flow_block_rule_count(const struct mlxsw_sp_flow_block *block)
892 {
893 	return block ? block->rule_count : 0;
894 }
895 
896 static inline void
897 mlxsw_sp_flow_block_disable_inc(struct mlxsw_sp_flow_block *block)
898 {
899 	if (block)
900 		block->disable_count++;
901 }
902 
903 static inline void
904 mlxsw_sp_flow_block_disable_dec(struct mlxsw_sp_flow_block *block)
905 {
906 	if (block)
907 		block->disable_count--;
908 }
909 
910 static inline bool
911 mlxsw_sp_flow_block_disabled(const struct mlxsw_sp_flow_block *block)
912 {
913 	return block->disable_count;
914 }
915 
916 static inline bool
917 mlxsw_sp_flow_block_is_egress_bound(const struct mlxsw_sp_flow_block *block)
918 {
919 	return block->egress_binding_count;
920 }
921 
922 static inline bool
923 mlxsw_sp_flow_block_is_ingress_bound(const struct mlxsw_sp_flow_block *block)
924 {
925 	return block->ingress_binding_count;
926 }
927 
928 static inline bool
929 mlxsw_sp_flow_block_is_mixed_bound(const struct mlxsw_sp_flow_block *block)
930 {
931 	return block->ingress_binding_count && block->egress_binding_count;
932 }
933 
934 struct mlxsw_sp_flow_block *mlxsw_sp_flow_block_create(struct mlxsw_sp *mlxsw_sp,
935 						       struct net *net);
936 void mlxsw_sp_flow_block_destroy(struct mlxsw_sp_flow_block *block);
937 int mlxsw_sp_setup_tc_block_clsact(struct mlxsw_sp_port *mlxsw_sp_port,
938 				   struct flow_block_offload *f,
939 				   bool ingress);
940 
941 /* spectrum_acl.c */
942 struct mlxsw_sp_acl_ruleset;
943 
944 enum mlxsw_sp_acl_profile {
945 	MLXSW_SP_ACL_PROFILE_FLOWER,
946 	MLXSW_SP_ACL_PROFILE_MR,
947 };
948 
949 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
950 
951 int mlxsw_sp_acl_ruleset_bind(struct mlxsw_sp *mlxsw_sp,
952 			      struct mlxsw_sp_flow_block *block,
953 			      struct mlxsw_sp_flow_block_binding *binding);
954 void mlxsw_sp_acl_ruleset_unbind(struct mlxsw_sp *mlxsw_sp,
955 				 struct mlxsw_sp_flow_block *block,
956 				 struct mlxsw_sp_flow_block_binding *binding);
957 struct mlxsw_sp_acl_ruleset *
958 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
959 			    struct mlxsw_sp_flow_block *block, u32 chain_index,
960 			    enum mlxsw_sp_acl_profile profile);
961 struct mlxsw_sp_acl_ruleset *
962 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
963 			 struct mlxsw_sp_flow_block *block, u32 chain_index,
964 			 enum mlxsw_sp_acl_profile profile,
965 			 struct mlxsw_afk_element_usage *tmplt_elusage);
966 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
967 			      struct mlxsw_sp_acl_ruleset *ruleset);
968 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
969 void mlxsw_sp_acl_ruleset_prio_get(struct mlxsw_sp_acl_ruleset *ruleset,
970 				   unsigned int *p_min_prio,
971 				   unsigned int *p_max_prio);
972 
973 struct mlxsw_sp_acl_rule_info *
974 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
975 			  struct mlxsw_afa_block *afa_block);
976 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
977 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
978 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
979 				 unsigned int priority);
980 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
981 				    enum mlxsw_afk_element element,
982 				    u32 key_value, u32 mask_value);
983 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
984 				    enum mlxsw_afk_element element,
985 				    const char *key_value,
986 				    const char *mask_value, unsigned int len);
987 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
988 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
989 				u16 group_id);
990 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
991 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei,
992 				bool ingress,
993 				const struct flow_action_cookie *fa_cookie,
994 				struct netlink_ext_ack *extack);
995 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
996 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
997 				  struct mlxsw_sp_acl_rule_info *rulei,
998 				  struct mlxsw_sp_flow_block *block,
999 				  struct net_device *out_dev,
1000 				  struct netlink_ext_ack *extack);
1001 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
1002 			       struct mlxsw_sp_acl_rule_info *rulei,
1003 			       struct net_device *out_dev,
1004 			       struct netlink_ext_ack *extack);
1005 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
1006 				struct mlxsw_sp_acl_rule_info *rulei,
1007 				u32 action, u16 vid, u16 proto, u8 prio,
1008 				struct netlink_ext_ack *extack);
1009 int mlxsw_sp_acl_rulei_act_priority(struct mlxsw_sp *mlxsw_sp,
1010 				    struct mlxsw_sp_acl_rule_info *rulei,
1011 				    u32 prio, struct netlink_ext_ack *extack);
1012 int mlxsw_sp_acl_rulei_act_mangle(struct mlxsw_sp *mlxsw_sp,
1013 				  struct mlxsw_sp_acl_rule_info *rulei,
1014 				  enum flow_action_mangle_base htype,
1015 				  u32 offset, u32 mask, u32 val,
1016 				  struct netlink_ext_ack *extack);
1017 int mlxsw_sp_acl_rulei_act_police(struct mlxsw_sp *mlxsw_sp,
1018 				  struct mlxsw_sp_acl_rule_info *rulei,
1019 				  u32 index, u64 rate_bytes_ps,
1020 				  u32 burst, struct netlink_ext_ack *extack);
1021 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
1022 				 struct mlxsw_sp_acl_rule_info *rulei,
1023 				 struct netlink_ext_ack *extack);
1024 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
1025 				   struct mlxsw_sp_acl_rule_info *rulei,
1026 				   u16 fid, struct netlink_ext_ack *extack);
1027 int mlxsw_sp_acl_rulei_act_sample(struct mlxsw_sp *mlxsw_sp,
1028 				  struct mlxsw_sp_acl_rule_info *rulei,
1029 				  struct mlxsw_sp_flow_block *block,
1030 				  struct psample_group *psample_group, u32 rate,
1031 				  u32 trunc_size, bool truncate,
1032 				  struct netlink_ext_ack *extack);
1033 
1034 struct mlxsw_sp_acl_rule;
1035 
1036 struct mlxsw_sp_acl_rule *
1037 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
1038 			 struct mlxsw_sp_acl_ruleset *ruleset,
1039 			 unsigned long cookie,
1040 			 struct mlxsw_afa_block *afa_block,
1041 			 struct netlink_ext_ack *extack);
1042 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
1043 			       struct mlxsw_sp_acl_rule *rule);
1044 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
1045 			  struct mlxsw_sp_acl_rule *rule);
1046 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
1047 			   struct mlxsw_sp_acl_rule *rule);
1048 int mlxsw_sp_acl_rule_action_replace(struct mlxsw_sp *mlxsw_sp,
1049 				     struct mlxsw_sp_acl_rule *rule,
1050 				     struct mlxsw_afa_block *afa_block);
1051 struct mlxsw_sp_acl_rule *
1052 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
1053 			 struct mlxsw_sp_acl_ruleset *ruleset,
1054 			 unsigned long cookie);
1055 struct mlxsw_sp_acl_rule_info *
1056 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
1057 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
1058 				struct mlxsw_sp_acl_rule *rule,
1059 				u64 *packets, u64 *bytes, u64 *drops,
1060 				u64 *last_use,
1061 				enum flow_action_hw_stats *used_hw_stats);
1062 
1063 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
1064 
1065 static inline const struct flow_action_cookie *
1066 mlxsw_sp_acl_act_cookie_lookup(struct mlxsw_sp *mlxsw_sp, u32 cookie_index)
1067 {
1068 	return mlxsw_afa_cookie_lookup(mlxsw_sp->afa, cookie_index);
1069 }
1070 
1071 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
1072 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
1073 u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp);
1074 int mlxsw_sp_acl_region_rehash_intrvl_set(struct mlxsw_sp *mlxsw_sp, u32 val);
1075 
1076 struct mlxsw_sp_acl_mangle_action;
1077 
1078 struct mlxsw_sp_acl_rulei_ops {
1079 	int (*act_mangle_field)(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_rule_info *rulei,
1080 				struct mlxsw_sp_acl_mangle_action *mact, u32 val,
1081 				struct netlink_ext_ack *extack);
1082 };
1083 
1084 extern struct mlxsw_sp_acl_rulei_ops mlxsw_sp1_acl_rulei_ops;
1085 extern struct mlxsw_sp_acl_rulei_ops mlxsw_sp2_acl_rulei_ops;
1086 
1087 /* spectrum_acl_tcam.c */
1088 struct mlxsw_sp_acl_tcam;
1089 struct mlxsw_sp_acl_tcam_region;
1090 
1091 struct mlxsw_sp_acl_tcam_ops {
1092 	enum mlxsw_reg_ptar_key_type key_type;
1093 	size_t priv_size;
1094 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv,
1095 		    struct mlxsw_sp_acl_tcam *tcam);
1096 	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
1097 	size_t region_priv_size;
1098 	int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv,
1099 			   void *tcam_priv,
1100 			   struct mlxsw_sp_acl_tcam_region *region,
1101 			   void *hints_priv);
1102 	void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
1103 	int (*region_associate)(struct mlxsw_sp *mlxsw_sp,
1104 				struct mlxsw_sp_acl_tcam_region *region);
1105 	void * (*region_rehash_hints_get)(void *region_priv);
1106 	void (*region_rehash_hints_put)(void *hints_priv);
1107 	size_t chunk_priv_size;
1108 	void (*chunk_init)(void *region_priv, void *chunk_priv,
1109 			   unsigned int priority);
1110 	void (*chunk_fini)(void *chunk_priv);
1111 	size_t entry_priv_size;
1112 	int (*entry_add)(struct mlxsw_sp *mlxsw_sp,
1113 			 void *region_priv, void *chunk_priv,
1114 			 void *entry_priv,
1115 			 struct mlxsw_sp_acl_rule_info *rulei);
1116 	void (*entry_del)(struct mlxsw_sp *mlxsw_sp,
1117 			  void *region_priv, void *chunk_priv,
1118 			  void *entry_priv);
1119 	int (*entry_action_replace)(struct mlxsw_sp *mlxsw_sp,
1120 				    void *region_priv, void *entry_priv,
1121 				    struct mlxsw_sp_acl_rule_info *rulei);
1122 	int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp,
1123 				  void *region_priv, void *entry_priv,
1124 				  bool *activity);
1125 };
1126 
1127 /* spectrum1_acl_tcam.c */
1128 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops;
1129 
1130 /* spectrum2_acl_tcam.c */
1131 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops;
1132 
1133 /* spectrum_acl_flex_actions.c */
1134 extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops;
1135 extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops;
1136 
1137 /* spectrum_acl_flex_keys.c */
1138 extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
1139 extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;
1140 extern const struct mlxsw_afk_ops mlxsw_sp4_afk_ops;
1141 
1142 /* spectrum_acl_bloom_filter.c */
1143 extern const struct mlxsw_sp_acl_bf_ops mlxsw_sp2_acl_bf_ops;
1144 extern const struct mlxsw_sp_acl_bf_ops mlxsw_sp4_acl_bf_ops;
1145 
1146 /* spectrum_matchall.c */
1147 struct mlxsw_sp_mall_ops {
1148 	int (*sample_add)(struct mlxsw_sp *mlxsw_sp,
1149 			  struct mlxsw_sp_port *mlxsw_sp_port,
1150 			  struct mlxsw_sp_mall_entry *mall_entry,
1151 			  struct netlink_ext_ack *extack);
1152 	void (*sample_del)(struct mlxsw_sp *mlxsw_sp,
1153 			   struct mlxsw_sp_port *mlxsw_sp_port,
1154 			   struct mlxsw_sp_mall_entry *mall_entry);
1155 };
1156 
1157 extern const struct mlxsw_sp_mall_ops mlxsw_sp1_mall_ops;
1158 extern const struct mlxsw_sp_mall_ops mlxsw_sp2_mall_ops;
1159 
1160 enum mlxsw_sp_mall_action_type {
1161 	MLXSW_SP_MALL_ACTION_TYPE_MIRROR,
1162 	MLXSW_SP_MALL_ACTION_TYPE_SAMPLE,
1163 	MLXSW_SP_MALL_ACTION_TYPE_TRAP,
1164 };
1165 
1166 struct mlxsw_sp_mall_mirror_entry {
1167 	const struct net_device *to_dev;
1168 	int span_id;
1169 };
1170 
1171 struct mlxsw_sp_mall_trap_entry {
1172 	int span_id;
1173 };
1174 
1175 struct mlxsw_sp_mall_sample_entry {
1176 	struct mlxsw_sp_sample_params params;
1177 	int span_id;	/* Relevant for Spectrum-2 onwards. */
1178 };
1179 
1180 struct mlxsw_sp_mall_entry {
1181 	struct list_head list;
1182 	unsigned long cookie;
1183 	unsigned int priority;
1184 	enum mlxsw_sp_mall_action_type type;
1185 	bool ingress;
1186 	union {
1187 		struct mlxsw_sp_mall_mirror_entry mirror;
1188 		struct mlxsw_sp_mall_trap_entry trap;
1189 		struct mlxsw_sp_mall_sample_entry sample;
1190 	};
1191 	struct rcu_head rcu;
1192 };
1193 
1194 int mlxsw_sp_mall_replace(struct mlxsw_sp *mlxsw_sp,
1195 			  struct mlxsw_sp_flow_block *block,
1196 			  struct tc_cls_matchall_offload *f);
1197 void mlxsw_sp_mall_destroy(struct mlxsw_sp_flow_block *block,
1198 			   struct tc_cls_matchall_offload *f);
1199 int mlxsw_sp_mall_port_bind(struct mlxsw_sp_flow_block *block,
1200 			    struct mlxsw_sp_port *mlxsw_sp_port,
1201 			    struct netlink_ext_ack *extack);
1202 void mlxsw_sp_mall_port_unbind(struct mlxsw_sp_flow_block *block,
1203 			       struct mlxsw_sp_port *mlxsw_sp_port);
1204 int mlxsw_sp_mall_prio_get(struct mlxsw_sp_flow_block *block, u32 chain_index,
1205 			   unsigned int *p_min_prio, unsigned int *p_max_prio);
1206 
1207 /* spectrum_flower.c */
1208 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
1209 			    struct mlxsw_sp_flow_block *block,
1210 			    struct flow_cls_offload *f);
1211 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
1212 			     struct mlxsw_sp_flow_block *block,
1213 			     struct flow_cls_offload *f);
1214 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
1215 			  struct mlxsw_sp_flow_block *block,
1216 			  struct flow_cls_offload *f);
1217 int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
1218 				 struct mlxsw_sp_flow_block *block,
1219 				 struct flow_cls_offload *f);
1220 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
1221 				   struct mlxsw_sp_flow_block *block,
1222 				   struct flow_cls_offload *f);
1223 int mlxsw_sp_flower_prio_get(struct mlxsw_sp *mlxsw_sp,
1224 			     struct mlxsw_sp_flow_block *block,
1225 			     u32 chain_index, unsigned int *p_min_prio,
1226 			     unsigned int *p_max_prio);
1227 
1228 /* spectrum_qdisc.c */
1229 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
1230 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1231 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
1232 			  struct tc_red_qopt_offload *p);
1233 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
1234 			   struct tc_prio_qopt_offload *p);
1235 int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port,
1236 			  struct tc_ets_qopt_offload *p);
1237 int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port,
1238 			  struct tc_tbf_qopt_offload *p);
1239 int mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port,
1240 			   struct tc_fifo_qopt_offload *p);
1241 int mlxsw_sp_setup_tc_block_qevent_early_drop(struct mlxsw_sp_port *mlxsw_sp_port,
1242 					      struct flow_block_offload *f);
1243 int mlxsw_sp_setup_tc_block_qevent_mark(struct mlxsw_sp_port *mlxsw_sp_port,
1244 					struct flow_block_offload *f);
1245 
1246 /* spectrum_fid.c */
1247 bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index);
1248 bool mlxsw_sp_fid_lag_vid_valid(const struct mlxsw_sp_fid *fid);
1249 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp,
1250 						  u16 fid_index);
1251 int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex);
1252 int mlxsw_sp_fid_nve_type(const struct mlxsw_sp_fid *fid,
1253 			  enum mlxsw_sp_nve_type *p_type);
1254 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_vni(struct mlxsw_sp *mlxsw_sp,
1255 						__be32 vni);
1256 int mlxsw_sp_fid_vni(const struct mlxsw_sp_fid *fid, __be32 *vni);
1257 int mlxsw_sp_fid_nve_flood_index_set(struct mlxsw_sp_fid *fid,
1258 				     u32 nve_flood_index);
1259 void mlxsw_sp_fid_nve_flood_index_clear(struct mlxsw_sp_fid *fid);
1260 bool mlxsw_sp_fid_nve_flood_index_is_set(const struct mlxsw_sp_fid *fid);
1261 int mlxsw_sp_fid_vni_set(struct mlxsw_sp_fid *fid, enum mlxsw_sp_nve_type type,
1262 			 __be32 vni, int nve_ifindex);
1263 void mlxsw_sp_fid_vni_clear(struct mlxsw_sp_fid *fid);
1264 bool mlxsw_sp_fid_vni_is_set(const struct mlxsw_sp_fid *fid);
1265 void mlxsw_sp_fid_fdb_clear_offload(const struct mlxsw_sp_fid *fid,
1266 				    const struct net_device *nve_dev);
1267 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
1268 			   enum mlxsw_sp_flood_type packet_type, u16 local_port,
1269 			   bool member);
1270 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
1271 			      struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
1272 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
1273 				 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
1274 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
1275 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
1276 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
1277 struct mlxsw_sp_rif *mlxsw_sp_fid_rif(const struct mlxsw_sp_fid *fid);
1278 enum mlxsw_sp_rif_type
1279 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
1280 			   enum mlxsw_sp_fid_type type);
1281 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
1282 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
1283 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
1284 					    int br_ifindex);
1285 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_lookup(struct mlxsw_sp *mlxsw_sp,
1286 					       u16 vid);
1287 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_lookup(struct mlxsw_sp *mlxsw_sp,
1288 					       int br_ifindex);
1289 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
1290 					   u16 rif_index);
1291 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
1292 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
1293 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
1294 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1295 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
1296 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
1297 
1298 /* spectrum_mr.c */
1299 enum mlxsw_sp_mr_route_prio {
1300 	MLXSW_SP_MR_ROUTE_PRIO_SG,
1301 	MLXSW_SP_MR_ROUTE_PRIO_STARG,
1302 	MLXSW_SP_MR_ROUTE_PRIO_CATCHALL,
1303 	__MLXSW_SP_MR_ROUTE_PRIO_MAX
1304 };
1305 
1306 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
1307 
1308 struct mlxsw_sp_mr_route_key;
1309 
1310 struct mlxsw_sp_mr_tcam_ops {
1311 	size_t priv_size;
1312 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
1313 	void (*fini)(void *priv);
1314 	size_t route_priv_size;
1315 	int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
1316 			    void *route_priv,
1317 			    struct mlxsw_sp_mr_route_key *key,
1318 			    struct mlxsw_afa_block *afa_block,
1319 			    enum mlxsw_sp_mr_route_prio prio);
1320 	void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
1321 			      void *route_priv,
1322 			      struct mlxsw_sp_mr_route_key *key);
1323 	int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
1324 			    struct mlxsw_sp_mr_route_key *key,
1325 			    struct mlxsw_afa_block *afa_block);
1326 };
1327 
1328 /* spectrum1_mr_tcam.c */
1329 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops;
1330 
1331 /* spectrum2_mr_tcam.c */
1332 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops;
1333 
1334 /* spectrum_nve.c */
1335 struct mlxsw_sp_nve_params {
1336 	enum mlxsw_sp_nve_type type;
1337 	__be32 vni;
1338 	const struct net_device *dev;
1339 	u16 ethertype;
1340 };
1341 
1342 extern const struct mlxsw_sp_nve_ops *mlxsw_sp1_nve_ops_arr[];
1343 extern const struct mlxsw_sp_nve_ops *mlxsw_sp2_nve_ops_arr[];
1344 
1345 int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip,
1346 				    enum mlxsw_sp_l3proto proto,
1347 				    union mlxsw_sp_l3addr *addr);
1348 int mlxsw_sp_nve_flood_ip_add(struct mlxsw_sp *mlxsw_sp,
1349 			      struct mlxsw_sp_fid *fid,
1350 			      enum mlxsw_sp_l3proto proto,
1351 			      union mlxsw_sp_l3addr *addr);
1352 void mlxsw_sp_nve_flood_ip_del(struct mlxsw_sp *mlxsw_sp,
1353 			       struct mlxsw_sp_fid *fid,
1354 			       enum mlxsw_sp_l3proto proto,
1355 			       union mlxsw_sp_l3addr *addr);
1356 int mlxsw_sp_nve_ipv6_addr_kvdl_set(struct mlxsw_sp *mlxsw_sp,
1357 				    const struct in6_addr *addr6,
1358 				    u32 *p_kvdl_index);
1359 void mlxsw_sp_nve_ipv6_addr_kvdl_unset(struct mlxsw_sp *mlxsw_sp,
1360 				       const struct in6_addr *addr6);
1361 int
1362 mlxsw_sp_nve_ipv6_addr_map_replace(struct mlxsw_sp *mlxsw_sp, const char *mac,
1363 				   u16 fid_index,
1364 				   const struct in6_addr *new_addr6);
1365 void mlxsw_sp_nve_ipv6_addr_map_del(struct mlxsw_sp *mlxsw_sp, const char *mac,
1366 				    u16 fid_index);
1367 int mlxsw_sp_nve_fid_enable(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *fid,
1368 			    struct mlxsw_sp_nve_params *params,
1369 			    struct netlink_ext_ack *extack);
1370 void mlxsw_sp_nve_fid_disable(struct mlxsw_sp *mlxsw_sp,
1371 			      struct mlxsw_sp_fid *fid);
1372 int mlxsw_sp_port_nve_init(struct mlxsw_sp_port *mlxsw_sp_port);
1373 void mlxsw_sp_port_nve_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1374 int mlxsw_sp_nve_init(struct mlxsw_sp *mlxsw_sp);
1375 void mlxsw_sp_nve_fini(struct mlxsw_sp *mlxsw_sp);
1376 
1377 /* spectrum_nve_vxlan.c */
1378 int mlxsw_sp_nve_inc_parsing_depth_get(struct mlxsw_sp *mlxsw_sp);
1379 void mlxsw_sp_nve_inc_parsing_depth_put(struct mlxsw_sp *mlxsw_sp);
1380 
1381 /* spectrum_trap.c */
1382 int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp);
1383 void mlxsw_sp_devlink_traps_fini(struct mlxsw_sp *mlxsw_sp);
1384 int mlxsw_sp_trap_init(struct mlxsw_core *mlxsw_core,
1385 		       const struct devlink_trap *trap, void *trap_ctx);
1386 void mlxsw_sp_trap_fini(struct mlxsw_core *mlxsw_core,
1387 			const struct devlink_trap *trap, void *trap_ctx);
1388 int mlxsw_sp_trap_action_set(struct mlxsw_core *mlxsw_core,
1389 			     const struct devlink_trap *trap,
1390 			     enum devlink_trap_action action,
1391 			     struct netlink_ext_ack *extack);
1392 int mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core,
1393 			     const struct devlink_trap_group *group);
1394 int mlxsw_sp_trap_group_set(struct mlxsw_core *mlxsw_core,
1395 			    const struct devlink_trap_group *group,
1396 			    const struct devlink_trap_policer *policer,
1397 			    struct netlink_ext_ack *extack);
1398 int
1399 mlxsw_sp_trap_policer_init(struct mlxsw_core *mlxsw_core,
1400 			   const struct devlink_trap_policer *policer);
1401 void mlxsw_sp_trap_policer_fini(struct mlxsw_core *mlxsw_core,
1402 				const struct devlink_trap_policer *policer);
1403 int
1404 mlxsw_sp_trap_policer_set(struct mlxsw_core *mlxsw_core,
1405 			  const struct devlink_trap_policer *policer,
1406 			  u64 rate, u64 burst, struct netlink_ext_ack *extack);
1407 int
1408 mlxsw_sp_trap_policer_counter_get(struct mlxsw_core *mlxsw_core,
1409 				  const struct devlink_trap_policer *policer,
1410 				  u64 *p_drops);
1411 int mlxsw_sp_trap_group_policer_hw_id_get(struct mlxsw_sp *mlxsw_sp, u16 id,
1412 					  bool *p_enabled, u16 *p_hw_id);
1413 
1414 static inline struct net *mlxsw_sp_net(struct mlxsw_sp *mlxsw_sp)
1415 {
1416 	return mlxsw_core_net(mlxsw_sp->core);
1417 }
1418 
1419 /* spectrum_ethtool.c */
1420 extern const struct ethtool_ops mlxsw_sp_port_ethtool_ops;
1421 extern const struct mlxsw_sp_port_type_speed_ops mlxsw_sp1_port_type_speed_ops;
1422 extern const struct mlxsw_sp_port_type_speed_ops mlxsw_sp2_port_type_speed_ops;
1423 
1424 /* spectrum_policer.c */
1425 extern const struct mlxsw_sp_policer_core_ops mlxsw_sp1_policer_core_ops;
1426 extern const struct mlxsw_sp_policer_core_ops mlxsw_sp2_policer_core_ops;
1427 
1428 enum mlxsw_sp_policer_type {
1429 	MLXSW_SP_POLICER_TYPE_SINGLE_RATE,
1430 
1431 	__MLXSW_SP_POLICER_TYPE_MAX,
1432 	MLXSW_SP_POLICER_TYPE_MAX = __MLXSW_SP_POLICER_TYPE_MAX - 1,
1433 };
1434 
1435 struct mlxsw_sp_policer_params {
1436 	u64 rate;
1437 	u64 burst;
1438 	bool bytes;
1439 };
1440 
1441 int mlxsw_sp_policer_add(struct mlxsw_sp *mlxsw_sp,
1442 			 enum mlxsw_sp_policer_type type,
1443 			 const struct mlxsw_sp_policer_params *params,
1444 			 struct netlink_ext_ack *extack, u16 *p_policer_index);
1445 void mlxsw_sp_policer_del(struct mlxsw_sp *mlxsw_sp,
1446 			  enum mlxsw_sp_policer_type type,
1447 			  u16 policer_index);
1448 int mlxsw_sp_policer_drops_counter_get(struct mlxsw_sp *mlxsw_sp,
1449 				       enum mlxsw_sp_policer_type type,
1450 				       u16 policer_index, u64 *p_drops);
1451 int mlxsw_sp_policers_init(struct mlxsw_sp *mlxsw_sp);
1452 void mlxsw_sp_policers_fini(struct mlxsw_sp *mlxsw_sp);
1453 int mlxsw_sp_policer_resources_register(struct mlxsw_core *mlxsw_core);
1454 
1455 #endif
1456