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