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