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