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