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