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