xref: /linux/drivers/net/ethernet/mellanox/mlxsw/spectrum.h (revision 1f8d99de1d1b4b3764203ae02db57041475dab84)
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 struct mlxsw_sp_acl_rule_info {
824 	unsigned int priority;
825 	struct mlxsw_afk_element_values values;
826 	struct mlxsw_afa_block *act_block;
827 	u8 action_created:1,
828 	   ingress_bind_blocker:1,
829 	   egress_bind_blocker:1,
830 	   counter_valid:1,
831 	   policer_index_valid:1;
832 	unsigned int counter_index;
833 	u16 policer_index;
834 };
835 
836 /* spectrum_flow.c */
837 struct mlxsw_sp_flow_block {
838 	struct list_head binding_list;
839 	struct {
840 		struct list_head list;
841 		unsigned int min_prio;
842 		unsigned int max_prio;
843 	} mall;
844 	struct mlxsw_sp_acl_ruleset *ruleset_zero;
845 	struct mlxsw_sp *mlxsw_sp;
846 	unsigned int rule_count;
847 	unsigned int disable_count;
848 	unsigned int ingress_blocker_rule_count;
849 	unsigned int egress_blocker_rule_count;
850 	unsigned int ingress_binding_count;
851 	unsigned int egress_binding_count;
852 	struct net *net;
853 };
854 
855 struct mlxsw_sp_flow_block_binding {
856 	struct list_head list;
857 	struct mlxsw_sp_port *mlxsw_sp_port;
858 	bool ingress;
859 };
860 
861 static inline struct mlxsw_sp *
862 mlxsw_sp_flow_block_mlxsw_sp(struct mlxsw_sp_flow_block *block)
863 {
864 	return block->mlxsw_sp;
865 }
866 
867 static inline unsigned int
868 mlxsw_sp_flow_block_rule_count(const struct mlxsw_sp_flow_block *block)
869 {
870 	return block ? block->rule_count : 0;
871 }
872 
873 static inline void
874 mlxsw_sp_flow_block_disable_inc(struct mlxsw_sp_flow_block *block)
875 {
876 	if (block)
877 		block->disable_count++;
878 }
879 
880 static inline void
881 mlxsw_sp_flow_block_disable_dec(struct mlxsw_sp_flow_block *block)
882 {
883 	if (block)
884 		block->disable_count--;
885 }
886 
887 static inline bool
888 mlxsw_sp_flow_block_disabled(const struct mlxsw_sp_flow_block *block)
889 {
890 	return block->disable_count;
891 }
892 
893 static inline bool
894 mlxsw_sp_flow_block_is_egress_bound(const struct mlxsw_sp_flow_block *block)
895 {
896 	return block->egress_binding_count;
897 }
898 
899 static inline bool
900 mlxsw_sp_flow_block_is_ingress_bound(const struct mlxsw_sp_flow_block *block)
901 {
902 	return block->ingress_binding_count;
903 }
904 
905 static inline bool
906 mlxsw_sp_flow_block_is_mixed_bound(const struct mlxsw_sp_flow_block *block)
907 {
908 	return block->ingress_binding_count && block->egress_binding_count;
909 }
910 
911 struct mlxsw_sp_flow_block *mlxsw_sp_flow_block_create(struct mlxsw_sp *mlxsw_sp,
912 						       struct net *net);
913 void mlxsw_sp_flow_block_destroy(struct mlxsw_sp_flow_block *block);
914 int mlxsw_sp_setup_tc_block_clsact(struct mlxsw_sp_port *mlxsw_sp_port,
915 				   struct flow_block_offload *f,
916 				   bool ingress);
917 
918 /* spectrum_acl.c */
919 struct mlxsw_sp_acl_ruleset;
920 
921 enum mlxsw_sp_acl_profile {
922 	MLXSW_SP_ACL_PROFILE_FLOWER,
923 	MLXSW_SP_ACL_PROFILE_MR,
924 };
925 
926 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
927 
928 int mlxsw_sp_acl_ruleset_bind(struct mlxsw_sp *mlxsw_sp,
929 			      struct mlxsw_sp_flow_block *block,
930 			      struct mlxsw_sp_flow_block_binding *binding);
931 void mlxsw_sp_acl_ruleset_unbind(struct mlxsw_sp *mlxsw_sp,
932 				 struct mlxsw_sp_flow_block *block,
933 				 struct mlxsw_sp_flow_block_binding *binding);
934 struct mlxsw_sp_acl_ruleset *
935 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
936 			    struct mlxsw_sp_flow_block *block, u32 chain_index,
937 			    enum mlxsw_sp_acl_profile profile);
938 struct mlxsw_sp_acl_ruleset *
939 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
940 			 struct mlxsw_sp_flow_block *block, u32 chain_index,
941 			 enum mlxsw_sp_acl_profile profile,
942 			 struct mlxsw_afk_element_usage *tmplt_elusage);
943 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
944 			      struct mlxsw_sp_acl_ruleset *ruleset);
945 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
946 void mlxsw_sp_acl_ruleset_prio_get(struct mlxsw_sp_acl_ruleset *ruleset,
947 				   unsigned int *p_min_prio,
948 				   unsigned int *p_max_prio);
949 
950 struct mlxsw_sp_acl_rule_info *
951 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
952 			  struct mlxsw_afa_block *afa_block);
953 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
954 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
955 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
956 				 unsigned int priority);
957 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
958 				    enum mlxsw_afk_element element,
959 				    u32 key_value, u32 mask_value);
960 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
961 				    enum mlxsw_afk_element element,
962 				    const char *key_value,
963 				    const char *mask_value, unsigned int len);
964 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
965 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
966 				u16 group_id);
967 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
968 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei,
969 				bool ingress,
970 				const struct flow_action_cookie *fa_cookie,
971 				struct netlink_ext_ack *extack);
972 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
973 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
974 				  struct mlxsw_sp_acl_rule_info *rulei,
975 				  struct mlxsw_sp_flow_block *block,
976 				  struct net_device *out_dev,
977 				  struct netlink_ext_ack *extack);
978 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
979 			       struct mlxsw_sp_acl_rule_info *rulei,
980 			       struct net_device *out_dev,
981 			       struct netlink_ext_ack *extack);
982 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
983 				struct mlxsw_sp_acl_rule_info *rulei,
984 				u32 action, u16 vid, u16 proto, u8 prio,
985 				struct netlink_ext_ack *extack);
986 int mlxsw_sp_acl_rulei_act_priority(struct mlxsw_sp *mlxsw_sp,
987 				    struct mlxsw_sp_acl_rule_info *rulei,
988 				    u32 prio, struct netlink_ext_ack *extack);
989 int mlxsw_sp_acl_rulei_act_mangle(struct mlxsw_sp *mlxsw_sp,
990 				  struct mlxsw_sp_acl_rule_info *rulei,
991 				  enum flow_action_mangle_base htype,
992 				  u32 offset, u32 mask, u32 val,
993 				  struct netlink_ext_ack *extack);
994 int mlxsw_sp_acl_rulei_act_police(struct mlxsw_sp *mlxsw_sp,
995 				  struct mlxsw_sp_acl_rule_info *rulei,
996 				  u32 index, u64 rate_bytes_ps,
997 				  u32 burst, struct netlink_ext_ack *extack);
998 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
999 				 struct mlxsw_sp_acl_rule_info *rulei,
1000 				 struct netlink_ext_ack *extack);
1001 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
1002 				   struct mlxsw_sp_acl_rule_info *rulei,
1003 				   u16 fid, struct netlink_ext_ack *extack);
1004 int mlxsw_sp_acl_rulei_act_sample(struct mlxsw_sp *mlxsw_sp,
1005 				  struct mlxsw_sp_acl_rule_info *rulei,
1006 				  struct mlxsw_sp_flow_block *block,
1007 				  struct psample_group *psample_group, u32 rate,
1008 				  u32 trunc_size, bool truncate,
1009 				  struct netlink_ext_ack *extack);
1010 
1011 struct mlxsw_sp_acl_rule;
1012 
1013 struct mlxsw_sp_acl_rule *
1014 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
1015 			 struct mlxsw_sp_acl_ruleset *ruleset,
1016 			 unsigned long cookie,
1017 			 struct mlxsw_afa_block *afa_block,
1018 			 struct netlink_ext_ack *extack);
1019 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
1020 			       struct mlxsw_sp_acl_rule *rule);
1021 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
1022 			  struct mlxsw_sp_acl_rule *rule);
1023 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
1024 			   struct mlxsw_sp_acl_rule *rule);
1025 int mlxsw_sp_acl_rule_action_replace(struct mlxsw_sp *mlxsw_sp,
1026 				     struct mlxsw_sp_acl_rule *rule,
1027 				     struct mlxsw_afa_block *afa_block);
1028 struct mlxsw_sp_acl_rule *
1029 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
1030 			 struct mlxsw_sp_acl_ruleset *ruleset,
1031 			 unsigned long cookie);
1032 struct mlxsw_sp_acl_rule_info *
1033 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
1034 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
1035 				struct mlxsw_sp_acl_rule *rule,
1036 				u64 *packets, u64 *bytes, u64 *drops,
1037 				u64 *last_use,
1038 				enum flow_action_hw_stats *used_hw_stats);
1039 
1040 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
1041 
1042 static inline const struct flow_action_cookie *
1043 mlxsw_sp_acl_act_cookie_lookup(struct mlxsw_sp *mlxsw_sp, u32 cookie_index)
1044 {
1045 	return mlxsw_afa_cookie_lookup(mlxsw_sp->afa, cookie_index);
1046 }
1047 
1048 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
1049 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
1050 u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp);
1051 int mlxsw_sp_acl_region_rehash_intrvl_set(struct mlxsw_sp *mlxsw_sp, u32 val);
1052 
1053 struct mlxsw_sp_acl_mangle_action;
1054 
1055 struct mlxsw_sp_acl_rulei_ops {
1056 	int (*act_mangle_field)(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_rule_info *rulei,
1057 				struct mlxsw_sp_acl_mangle_action *mact, u32 val,
1058 				struct netlink_ext_ack *extack);
1059 };
1060 
1061 extern struct mlxsw_sp_acl_rulei_ops mlxsw_sp1_acl_rulei_ops;
1062 extern struct mlxsw_sp_acl_rulei_ops mlxsw_sp2_acl_rulei_ops;
1063 
1064 /* spectrum_acl_tcam.c */
1065 struct mlxsw_sp_acl_tcam;
1066 struct mlxsw_sp_acl_tcam_region;
1067 
1068 struct mlxsw_sp_acl_tcam_ops {
1069 	enum mlxsw_reg_ptar_key_type key_type;
1070 	size_t priv_size;
1071 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv,
1072 		    struct mlxsw_sp_acl_tcam *tcam);
1073 	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
1074 	size_t region_priv_size;
1075 	int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv,
1076 			   void *tcam_priv,
1077 			   struct mlxsw_sp_acl_tcam_region *region,
1078 			   void *hints_priv);
1079 	void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
1080 	int (*region_associate)(struct mlxsw_sp *mlxsw_sp,
1081 				struct mlxsw_sp_acl_tcam_region *region);
1082 	void * (*region_rehash_hints_get)(void *region_priv);
1083 	void (*region_rehash_hints_put)(void *hints_priv);
1084 	size_t chunk_priv_size;
1085 	void (*chunk_init)(void *region_priv, void *chunk_priv,
1086 			   unsigned int priority);
1087 	void (*chunk_fini)(void *chunk_priv);
1088 	size_t entry_priv_size;
1089 	int (*entry_add)(struct mlxsw_sp *mlxsw_sp,
1090 			 void *region_priv, void *chunk_priv,
1091 			 void *entry_priv,
1092 			 struct mlxsw_sp_acl_rule_info *rulei);
1093 	void (*entry_del)(struct mlxsw_sp *mlxsw_sp,
1094 			  void *region_priv, void *chunk_priv,
1095 			  void *entry_priv);
1096 	int (*entry_action_replace)(struct mlxsw_sp *mlxsw_sp,
1097 				    void *region_priv, void *entry_priv,
1098 				    struct mlxsw_sp_acl_rule_info *rulei);
1099 	int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp,
1100 				  void *region_priv, void *entry_priv,
1101 				  bool *activity);
1102 };
1103 
1104 /* spectrum1_acl_tcam.c */
1105 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops;
1106 
1107 /* spectrum2_acl_tcam.c */
1108 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops;
1109 
1110 /* spectrum_acl_flex_actions.c */
1111 extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops;
1112 extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops;
1113 
1114 /* spectrum_acl_flex_keys.c */
1115 extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
1116 extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;
1117 extern const struct mlxsw_afk_ops mlxsw_sp4_afk_ops;
1118 
1119 /* spectrum_acl_bloom_filter.c */
1120 extern const struct mlxsw_sp_acl_bf_ops mlxsw_sp2_acl_bf_ops;
1121 extern const struct mlxsw_sp_acl_bf_ops mlxsw_sp4_acl_bf_ops;
1122 
1123 /* spectrum_matchall.c */
1124 struct mlxsw_sp_mall_ops {
1125 	int (*sample_add)(struct mlxsw_sp *mlxsw_sp,
1126 			  struct mlxsw_sp_port *mlxsw_sp_port,
1127 			  struct mlxsw_sp_mall_entry *mall_entry,
1128 			  struct netlink_ext_ack *extack);
1129 	void (*sample_del)(struct mlxsw_sp *mlxsw_sp,
1130 			   struct mlxsw_sp_port *mlxsw_sp_port,
1131 			   struct mlxsw_sp_mall_entry *mall_entry);
1132 };
1133 
1134 extern const struct mlxsw_sp_mall_ops mlxsw_sp1_mall_ops;
1135 extern const struct mlxsw_sp_mall_ops mlxsw_sp2_mall_ops;
1136 
1137 enum mlxsw_sp_mall_action_type {
1138 	MLXSW_SP_MALL_ACTION_TYPE_MIRROR,
1139 	MLXSW_SP_MALL_ACTION_TYPE_SAMPLE,
1140 	MLXSW_SP_MALL_ACTION_TYPE_TRAP,
1141 };
1142 
1143 struct mlxsw_sp_mall_mirror_entry {
1144 	const struct net_device *to_dev;
1145 	int span_id;
1146 };
1147 
1148 struct mlxsw_sp_mall_trap_entry {
1149 	int span_id;
1150 };
1151 
1152 struct mlxsw_sp_mall_sample_entry {
1153 	struct mlxsw_sp_sample_params params;
1154 	int span_id;	/* Relevant for Spectrum-2 onwards. */
1155 };
1156 
1157 struct mlxsw_sp_mall_entry {
1158 	struct list_head list;
1159 	unsigned long cookie;
1160 	unsigned int priority;
1161 	enum mlxsw_sp_mall_action_type type;
1162 	bool ingress;
1163 	union {
1164 		struct mlxsw_sp_mall_mirror_entry mirror;
1165 		struct mlxsw_sp_mall_trap_entry trap;
1166 		struct mlxsw_sp_mall_sample_entry sample;
1167 	};
1168 	struct rcu_head rcu;
1169 };
1170 
1171 int mlxsw_sp_mall_replace(struct mlxsw_sp *mlxsw_sp,
1172 			  struct mlxsw_sp_flow_block *block,
1173 			  struct tc_cls_matchall_offload *f);
1174 void mlxsw_sp_mall_destroy(struct mlxsw_sp_flow_block *block,
1175 			   struct tc_cls_matchall_offload *f);
1176 int mlxsw_sp_mall_port_bind(struct mlxsw_sp_flow_block *block,
1177 			    struct mlxsw_sp_port *mlxsw_sp_port,
1178 			    struct netlink_ext_ack *extack);
1179 void mlxsw_sp_mall_port_unbind(struct mlxsw_sp_flow_block *block,
1180 			       struct mlxsw_sp_port *mlxsw_sp_port);
1181 int mlxsw_sp_mall_prio_get(struct mlxsw_sp_flow_block *block, u32 chain_index,
1182 			   unsigned int *p_min_prio, unsigned int *p_max_prio);
1183 
1184 /* spectrum_flower.c */
1185 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
1186 			    struct mlxsw_sp_flow_block *block,
1187 			    struct flow_cls_offload *f);
1188 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
1189 			     struct mlxsw_sp_flow_block *block,
1190 			     struct flow_cls_offload *f);
1191 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
1192 			  struct mlxsw_sp_flow_block *block,
1193 			  struct flow_cls_offload *f);
1194 int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
1195 				 struct mlxsw_sp_flow_block *block,
1196 				 struct flow_cls_offload *f);
1197 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
1198 				   struct mlxsw_sp_flow_block *block,
1199 				   struct flow_cls_offload *f);
1200 int mlxsw_sp_flower_prio_get(struct mlxsw_sp *mlxsw_sp,
1201 			     struct mlxsw_sp_flow_block *block,
1202 			     u32 chain_index, unsigned int *p_min_prio,
1203 			     unsigned int *p_max_prio);
1204 
1205 /* spectrum_qdisc.c */
1206 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
1207 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1208 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
1209 			  struct tc_red_qopt_offload *p);
1210 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
1211 			   struct tc_prio_qopt_offload *p);
1212 int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port,
1213 			  struct tc_ets_qopt_offload *p);
1214 int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port,
1215 			  struct tc_tbf_qopt_offload *p);
1216 int mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port,
1217 			   struct tc_fifo_qopt_offload *p);
1218 int mlxsw_sp_setup_tc_block_qevent_early_drop(struct mlxsw_sp_port *mlxsw_sp_port,
1219 					      struct flow_block_offload *f);
1220 int mlxsw_sp_setup_tc_block_qevent_mark(struct mlxsw_sp_port *mlxsw_sp_port,
1221 					struct flow_block_offload *f);
1222 
1223 /* spectrum_fid.c */
1224 bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index);
1225 bool mlxsw_sp_fid_lag_vid_valid(const struct mlxsw_sp_fid *fid);
1226 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp,
1227 						  u16 fid_index);
1228 int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex);
1229 int mlxsw_sp_fid_nve_type(const struct mlxsw_sp_fid *fid,
1230 			  enum mlxsw_sp_nve_type *p_type);
1231 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_vni(struct mlxsw_sp *mlxsw_sp,
1232 						__be32 vni);
1233 int mlxsw_sp_fid_vni(const struct mlxsw_sp_fid *fid, __be32 *vni);
1234 int mlxsw_sp_fid_nve_flood_index_set(struct mlxsw_sp_fid *fid,
1235 				     u32 nve_flood_index);
1236 void mlxsw_sp_fid_nve_flood_index_clear(struct mlxsw_sp_fid *fid);
1237 bool mlxsw_sp_fid_nve_flood_index_is_set(const struct mlxsw_sp_fid *fid);
1238 int mlxsw_sp_fid_vni_set(struct mlxsw_sp_fid *fid, enum mlxsw_sp_nve_type type,
1239 			 __be32 vni, int nve_ifindex);
1240 void mlxsw_sp_fid_vni_clear(struct mlxsw_sp_fid *fid);
1241 bool mlxsw_sp_fid_vni_is_set(const struct mlxsw_sp_fid *fid);
1242 void mlxsw_sp_fid_fdb_clear_offload(const struct mlxsw_sp_fid *fid,
1243 				    const struct net_device *nve_dev);
1244 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
1245 			   enum mlxsw_sp_flood_type packet_type, u16 local_port,
1246 			   bool member);
1247 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
1248 			      struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
1249 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
1250 				 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
1251 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
1252 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
1253 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
1254 struct mlxsw_sp_rif *mlxsw_sp_fid_rif(const struct mlxsw_sp_fid *fid);
1255 enum mlxsw_sp_rif_type
1256 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
1257 			   enum mlxsw_sp_fid_type type);
1258 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
1259 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
1260 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
1261 					    int br_ifindex);
1262 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_lookup(struct mlxsw_sp *mlxsw_sp,
1263 					       u16 vid);
1264 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_lookup(struct mlxsw_sp *mlxsw_sp,
1265 					       int br_ifindex);
1266 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
1267 					   u16 rif_index);
1268 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
1269 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
1270 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
1271 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1272 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
1273 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
1274 
1275 /* spectrum_mr.c */
1276 enum mlxsw_sp_mr_route_prio {
1277 	MLXSW_SP_MR_ROUTE_PRIO_SG,
1278 	MLXSW_SP_MR_ROUTE_PRIO_STARG,
1279 	MLXSW_SP_MR_ROUTE_PRIO_CATCHALL,
1280 	__MLXSW_SP_MR_ROUTE_PRIO_MAX
1281 };
1282 
1283 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
1284 
1285 struct mlxsw_sp_mr_route_key;
1286 
1287 struct mlxsw_sp_mr_tcam_ops {
1288 	size_t priv_size;
1289 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
1290 	void (*fini)(void *priv);
1291 	size_t route_priv_size;
1292 	int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
1293 			    void *route_priv,
1294 			    struct mlxsw_sp_mr_route_key *key,
1295 			    struct mlxsw_afa_block *afa_block,
1296 			    enum mlxsw_sp_mr_route_prio prio);
1297 	void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
1298 			      void *route_priv,
1299 			      struct mlxsw_sp_mr_route_key *key);
1300 	int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
1301 			    struct mlxsw_sp_mr_route_key *key,
1302 			    struct mlxsw_afa_block *afa_block);
1303 };
1304 
1305 /* spectrum1_mr_tcam.c */
1306 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops;
1307 
1308 /* spectrum2_mr_tcam.c */
1309 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops;
1310 
1311 /* spectrum_nve.c */
1312 struct mlxsw_sp_nve_params {
1313 	enum mlxsw_sp_nve_type type;
1314 	__be32 vni;
1315 	const struct net_device *dev;
1316 	u16 ethertype;
1317 };
1318 
1319 extern const struct mlxsw_sp_nve_ops *mlxsw_sp1_nve_ops_arr[];
1320 extern const struct mlxsw_sp_nve_ops *mlxsw_sp2_nve_ops_arr[];
1321 
1322 int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip,
1323 				    enum mlxsw_sp_l3proto proto,
1324 				    union mlxsw_sp_l3addr *addr);
1325 int mlxsw_sp_nve_flood_ip_add(struct mlxsw_sp *mlxsw_sp,
1326 			      struct mlxsw_sp_fid *fid,
1327 			      enum mlxsw_sp_l3proto proto,
1328 			      union mlxsw_sp_l3addr *addr);
1329 void mlxsw_sp_nve_flood_ip_del(struct mlxsw_sp *mlxsw_sp,
1330 			       struct mlxsw_sp_fid *fid,
1331 			       enum mlxsw_sp_l3proto proto,
1332 			       union mlxsw_sp_l3addr *addr);
1333 int mlxsw_sp_nve_ipv6_addr_kvdl_set(struct mlxsw_sp *mlxsw_sp,
1334 				    const struct in6_addr *addr6,
1335 				    u32 *p_kvdl_index);
1336 void mlxsw_sp_nve_ipv6_addr_kvdl_unset(struct mlxsw_sp *mlxsw_sp,
1337 				       const struct in6_addr *addr6);
1338 int
1339 mlxsw_sp_nve_ipv6_addr_map_replace(struct mlxsw_sp *mlxsw_sp, const char *mac,
1340 				   u16 fid_index,
1341 				   const struct in6_addr *new_addr6);
1342 void mlxsw_sp_nve_ipv6_addr_map_del(struct mlxsw_sp *mlxsw_sp, const char *mac,
1343 				    u16 fid_index);
1344 int mlxsw_sp_nve_fid_enable(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *fid,
1345 			    struct mlxsw_sp_nve_params *params,
1346 			    struct netlink_ext_ack *extack);
1347 void mlxsw_sp_nve_fid_disable(struct mlxsw_sp *mlxsw_sp,
1348 			      struct mlxsw_sp_fid *fid);
1349 int mlxsw_sp_port_nve_init(struct mlxsw_sp_port *mlxsw_sp_port);
1350 void mlxsw_sp_port_nve_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1351 int mlxsw_sp_nve_init(struct mlxsw_sp *mlxsw_sp);
1352 void mlxsw_sp_nve_fini(struct mlxsw_sp *mlxsw_sp);
1353 
1354 /* spectrum_nve_vxlan.c */
1355 int mlxsw_sp_nve_inc_parsing_depth_get(struct mlxsw_sp *mlxsw_sp);
1356 void mlxsw_sp_nve_inc_parsing_depth_put(struct mlxsw_sp *mlxsw_sp);
1357 
1358 /* spectrum_trap.c */
1359 int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp);
1360 void mlxsw_sp_devlink_traps_fini(struct mlxsw_sp *mlxsw_sp);
1361 int mlxsw_sp_trap_init(struct mlxsw_core *mlxsw_core,
1362 		       const struct devlink_trap *trap, void *trap_ctx);
1363 void mlxsw_sp_trap_fini(struct mlxsw_core *mlxsw_core,
1364 			const struct devlink_trap *trap, void *trap_ctx);
1365 int mlxsw_sp_trap_action_set(struct mlxsw_core *mlxsw_core,
1366 			     const struct devlink_trap *trap,
1367 			     enum devlink_trap_action action,
1368 			     struct netlink_ext_ack *extack);
1369 int mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core,
1370 			     const struct devlink_trap_group *group);
1371 int mlxsw_sp_trap_group_set(struct mlxsw_core *mlxsw_core,
1372 			    const struct devlink_trap_group *group,
1373 			    const struct devlink_trap_policer *policer,
1374 			    struct netlink_ext_ack *extack);
1375 int
1376 mlxsw_sp_trap_policer_init(struct mlxsw_core *mlxsw_core,
1377 			   const struct devlink_trap_policer *policer);
1378 void mlxsw_sp_trap_policer_fini(struct mlxsw_core *mlxsw_core,
1379 				const struct devlink_trap_policer *policer);
1380 int
1381 mlxsw_sp_trap_policer_set(struct mlxsw_core *mlxsw_core,
1382 			  const struct devlink_trap_policer *policer,
1383 			  u64 rate, u64 burst, struct netlink_ext_ack *extack);
1384 int
1385 mlxsw_sp_trap_policer_counter_get(struct mlxsw_core *mlxsw_core,
1386 				  const struct devlink_trap_policer *policer,
1387 				  u64 *p_drops);
1388 int mlxsw_sp_trap_group_policer_hw_id_get(struct mlxsw_sp *mlxsw_sp, u16 id,
1389 					  bool *p_enabled, u16 *p_hw_id);
1390 
1391 static inline struct net *mlxsw_sp_net(struct mlxsw_sp *mlxsw_sp)
1392 {
1393 	return mlxsw_core_net(mlxsw_sp->core);
1394 }
1395 
1396 /* spectrum_ethtool.c */
1397 extern const struct ethtool_ops mlxsw_sp_port_ethtool_ops;
1398 extern const struct mlxsw_sp_port_type_speed_ops mlxsw_sp1_port_type_speed_ops;
1399 extern const struct mlxsw_sp_port_type_speed_ops mlxsw_sp2_port_type_speed_ops;
1400 
1401 /* spectrum_policer.c */
1402 extern const struct mlxsw_sp_policer_core_ops mlxsw_sp1_policer_core_ops;
1403 extern const struct mlxsw_sp_policer_core_ops mlxsw_sp2_policer_core_ops;
1404 
1405 enum mlxsw_sp_policer_type {
1406 	MLXSW_SP_POLICER_TYPE_SINGLE_RATE,
1407 
1408 	__MLXSW_SP_POLICER_TYPE_MAX,
1409 	MLXSW_SP_POLICER_TYPE_MAX = __MLXSW_SP_POLICER_TYPE_MAX - 1,
1410 };
1411 
1412 struct mlxsw_sp_policer_params {
1413 	u64 rate;
1414 	u64 burst;
1415 	bool bytes;
1416 };
1417 
1418 int mlxsw_sp_policer_add(struct mlxsw_sp *mlxsw_sp,
1419 			 enum mlxsw_sp_policer_type type,
1420 			 const struct mlxsw_sp_policer_params *params,
1421 			 struct netlink_ext_ack *extack, u16 *p_policer_index);
1422 void mlxsw_sp_policer_del(struct mlxsw_sp *mlxsw_sp,
1423 			  enum mlxsw_sp_policer_type type,
1424 			  u16 policer_index);
1425 int mlxsw_sp_policer_drops_counter_get(struct mlxsw_sp *mlxsw_sp,
1426 				       enum mlxsw_sp_policer_type type,
1427 				       u16 policer_index, u64 *p_drops);
1428 int mlxsw_sp_policers_init(struct mlxsw_sp *mlxsw_sp);
1429 void mlxsw_sp_policers_fini(struct mlxsw_sp *mlxsw_sp);
1430 int mlxsw_sp_policer_resources_register(struct mlxsw_core *mlxsw_core);
1431 
1432 #endif
1433