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