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