net: sched: expose HW stats types per action used by drivers
[linux-2.6-block.git] / drivers / net / ethernet / mellanox / mlxsw / spectrum.h
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/types.h>
8 #include <linux/netdevice.h>
9 #include <linux/rhashtable.h>
10 #include <linux/bitops.h>
11 #include <linux/if_bridge.h>
12 #include <linux/if_vlan.h>
13 #include <linux/list.h>
14 #include <linux/dcbnl.h>
15 #include <linux/in6.h>
16 #include <linux/notifier.h>
17 #include <linux/net_namespace.h>
18 #include <net/psample.h>
19 #include <net/pkt_cls.h>
20 #include <net/red.h>
21 #include <net/vxlan.h>
22 #include <net/flow_offload.h>
23
24 #include "port.h"
25 #include "core.h"
26 #include "core_acl_flex_keys.h"
27 #include "core_acl_flex_actions.h"
28 #include "reg.h"
29
30 #define MLXSW_SP_DEFAULT_VID (VLAN_N_VID - 1)
31
32 #define MLXSW_SP_FID_8021D_MAX 1024
33
34 #define MLXSW_SP_MID_MAX 7000
35
36 #define MLXSW_SP_KVD_LINEAR_SIZE 98304 /* entries */
37 #define MLXSW_SP_KVD_GRANULARITY 128
38
39 #define MLXSW_SP_RESOURCE_NAME_KVD "kvd"
40 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR "linear"
41 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE "hash_single"
42 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE "hash_double"
43 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES "singles"
44 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS "chunks"
45 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks"
46
47 #define MLXSW_SP_RESOURCE_NAME_SPAN "span_agents"
48
49 #define MLXSW_SP_RESOURCE_NAME_COUNTERS "counters"
50 #define MLXSW_SP_RESOURCE_NAME_COUNTERS_FLOW "flow"
51 #define MLXSW_SP_RESOURCE_NAME_COUNTERS_RIF "rif"
52
53 enum mlxsw_sp_resource_id {
54         MLXSW_SP_RESOURCE_KVD = 1,
55         MLXSW_SP_RESOURCE_KVD_LINEAR,
56         MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
57         MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
58         MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE,
59         MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS,
60         MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS,
61         MLXSW_SP_RESOURCE_SPAN,
62         MLXSW_SP_RESOURCE_COUNTERS,
63         MLXSW_SP_RESOURCE_COUNTERS_FLOW,
64         MLXSW_SP_RESOURCE_COUNTERS_RIF,
65 };
66
67 struct mlxsw_sp_port;
68 struct mlxsw_sp_rif;
69 struct mlxsw_sp_span_entry;
70 enum mlxsw_sp_l3proto;
71 union mlxsw_sp_l3addr;
72
73 struct mlxsw_sp_upper {
74         struct net_device *dev;
75         unsigned int ref_count;
76 };
77
78 enum mlxsw_sp_rif_type {
79         MLXSW_SP_RIF_TYPE_SUBPORT,
80         MLXSW_SP_RIF_TYPE_VLAN,
81         MLXSW_SP_RIF_TYPE_FID,
82         MLXSW_SP_RIF_TYPE_IPIP_LB, /* IP-in-IP loopback. */
83         MLXSW_SP_RIF_TYPE_MAX,
84 };
85
86 struct mlxsw_sp_rif_ops;
87
88 extern const struct mlxsw_sp_rif_ops *mlxsw_sp1_rif_ops_arr[];
89 extern const struct mlxsw_sp_rif_ops *mlxsw_sp2_rif_ops_arr[];
90
91 enum mlxsw_sp_fid_type {
92         MLXSW_SP_FID_TYPE_8021Q,
93         MLXSW_SP_FID_TYPE_8021D,
94         MLXSW_SP_FID_TYPE_RFID,
95         MLXSW_SP_FID_TYPE_DUMMY,
96         MLXSW_SP_FID_TYPE_MAX,
97 };
98
99 enum mlxsw_sp_nve_type {
100         MLXSW_SP_NVE_TYPE_VXLAN,
101 };
102
103 struct mlxsw_sp_mid {
104         struct list_head list;
105         unsigned char addr[ETH_ALEN];
106         u16 fid;
107         u16 mid;
108         bool in_hw;
109         unsigned long *ports_in_mid; /* bits array */
110 };
111
112 enum mlxsw_sp_port_mall_action_type {
113         MLXSW_SP_PORT_MALL_MIRROR,
114         MLXSW_SP_PORT_MALL_SAMPLE,
115 };
116
117 struct mlxsw_sp_port_mall_mirror_tc_entry {
118         int span_id;
119         bool ingress;
120 };
121
122 struct mlxsw_sp_port_mall_tc_entry {
123         struct list_head list;
124         unsigned long cookie;
125         enum mlxsw_sp_port_mall_action_type type;
126         union {
127                 struct mlxsw_sp_port_mall_mirror_tc_entry mirror;
128         };
129 };
130
131 struct mlxsw_sp_sb;
132 struct mlxsw_sp_bridge;
133 struct mlxsw_sp_router;
134 struct mlxsw_sp_mr;
135 struct mlxsw_sp_acl;
136 struct mlxsw_sp_counter_pool;
137 struct mlxsw_sp_fid_core;
138 struct mlxsw_sp_kvdl;
139 struct mlxsw_sp_nve;
140 struct mlxsw_sp_kvdl_ops;
141 struct mlxsw_sp_mr_tcam_ops;
142 struct mlxsw_sp_acl_tcam_ops;
143 struct mlxsw_sp_nve_ops;
144 struct mlxsw_sp_sb_vals;
145 struct mlxsw_sp_port_type_speed_ops;
146 struct mlxsw_sp_ptp_state;
147 struct mlxsw_sp_ptp_ops;
148 struct mlxsw_sp_span_ops;
149 struct mlxsw_sp_qdisc_state;
150
151 struct mlxsw_sp_port_mapping {
152         u8 module;
153         u8 width;
154         u8 lane;
155 };
156
157 struct mlxsw_sp {
158         struct mlxsw_sp_port **ports;
159         struct mlxsw_core *core;
160         const struct mlxsw_bus_info *bus_info;
161         unsigned char base_mac[ETH_ALEN];
162         const unsigned char *mac_mask;
163         struct mlxsw_sp_upper *lags;
164         struct mlxsw_sp_port_mapping **port_mapping;
165         struct mlxsw_sp_sb *sb;
166         struct mlxsw_sp_bridge *bridge;
167         struct mlxsw_sp_router *router;
168         struct mlxsw_sp_mr *mr;
169         struct mlxsw_afa *afa;
170         struct mlxsw_sp_acl *acl;
171         struct mlxsw_sp_fid_core *fid_core;
172         struct mlxsw_sp_kvdl *kvdl;
173         struct mlxsw_sp_nve *nve;
174         struct notifier_block netdevice_nb;
175         struct mlxsw_sp_ptp_clock *clock;
176         struct mlxsw_sp_ptp_state *ptp_state;
177         struct mlxsw_sp_counter_pool *counter_pool;
178         struct mlxsw_sp_span *span;
179         const struct mlxsw_fw_rev *req_rev;
180         const char *fw_filename;
181         const struct mlxsw_sp_kvdl_ops *kvdl_ops;
182         const struct mlxsw_afa_ops *afa_ops;
183         const struct mlxsw_afk_ops *afk_ops;
184         const struct mlxsw_sp_mr_tcam_ops *mr_tcam_ops;
185         const struct mlxsw_sp_acl_tcam_ops *acl_tcam_ops;
186         const struct mlxsw_sp_nve_ops **nve_ops_arr;
187         const struct mlxsw_sp_rif_ops **rif_ops_arr;
188         const struct mlxsw_sp_sb_vals *sb_vals;
189         const struct mlxsw_sp_port_type_speed_ops *port_type_speed_ops;
190         const struct mlxsw_sp_ptp_ops *ptp_ops;
191         const struct mlxsw_sp_span_ops *span_ops;
192         const struct mlxsw_listener *listeners;
193         size_t listeners_count;
194         u32 lowest_shaper_bs;
195 };
196
197 static inline struct mlxsw_sp_upper *
198 mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
199 {
200         return &mlxsw_sp->lags[lag_id];
201 }
202
203 struct mlxsw_sp_port_pcpu_stats {
204         u64                     rx_packets;
205         u64                     rx_bytes;
206         u64                     tx_packets;
207         u64                     tx_bytes;
208         struct u64_stats_sync   syncp;
209         u32                     tx_dropped;
210 };
211
212 struct mlxsw_sp_port_sample {
213         struct psample_group __rcu *psample_group;
214         u32 trunc_size;
215         u32 rate;
216         bool truncate;
217 };
218
219 struct mlxsw_sp_bridge_port;
220 struct mlxsw_sp_fid;
221
222 struct mlxsw_sp_port_vlan {
223         struct list_head list;
224         struct mlxsw_sp_port *mlxsw_sp_port;
225         struct mlxsw_sp_fid *fid;
226         u16 vid;
227         struct mlxsw_sp_bridge_port *bridge_port;
228         struct list_head bridge_vlan_node;
229 };
230
231 /* No need an internal lock; At worse - miss a single periodic iteration */
232 struct mlxsw_sp_port_xstats {
233         u64 ecn;
234         u64 wred_drop[TC_MAX_QUEUE];
235         u64 tail_drop[TC_MAX_QUEUE];
236         u64 backlog[TC_MAX_QUEUE];
237         u64 tx_bytes[IEEE_8021QAZ_MAX_TCS];
238         u64 tx_packets[IEEE_8021QAZ_MAX_TCS];
239 };
240
241 struct mlxsw_sp_ptp_port_dir_stats {
242         u64 packets;
243         u64 timestamps;
244 };
245
246 struct mlxsw_sp_ptp_port_stats {
247         struct mlxsw_sp_ptp_port_dir_stats rx_gcd;
248         struct mlxsw_sp_ptp_port_dir_stats tx_gcd;
249 };
250
251 struct mlxsw_sp_port {
252         struct net_device *dev;
253         struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
254         struct mlxsw_sp *mlxsw_sp;
255         u8 local_port;
256         u8 lagged:1,
257            split:1;
258         u16 pvid;
259         u16 lag_id;
260         struct {
261                 u8 tx_pause:1,
262                    rx_pause:1,
263                    autoneg:1;
264         } link;
265         struct {
266                 struct ieee_ets *ets;
267                 struct ieee_maxrate *maxrate;
268                 struct ieee_pfc *pfc;
269                 enum mlxsw_reg_qpts_trust_state trust_state;
270         } dcb;
271         struct mlxsw_sp_port_mapping mapping; /* mapping is constant during the
272                                                * mlxsw_sp_port lifetime, however
273                                                * the same localport can have
274                                                * different mapping.
275                                                */
276         /* TC handles */
277         struct list_head mall_tc_list;
278         struct {
279                 #define MLXSW_HW_STATS_UPDATE_TIME HZ
280                 struct rtnl_link_stats64 stats;
281                 struct mlxsw_sp_port_xstats xstats;
282                 struct delayed_work update_dw;
283         } periodic_hw_stats;
284         struct mlxsw_sp_port_sample *sample;
285         struct list_head vlans_list;
286         struct mlxsw_sp_port_vlan *default_vlan;
287         struct mlxsw_sp_qdisc_state *qdisc;
288         unsigned acl_rule_count;
289         struct mlxsw_sp_acl_block *ing_acl_block;
290         struct mlxsw_sp_acl_block *eg_acl_block;
291         struct {
292                 struct delayed_work shaper_dw;
293                 struct hwtstamp_config hwtstamp_config;
294                 u16 ing_types;
295                 u16 egr_types;
296                 struct mlxsw_sp_ptp_port_stats stats;
297         } ptp;
298         u8 split_base_local_port;
299         struct {
300                 struct delayed_work speed_update_dw;
301         } span;
302 };
303
304 struct mlxsw_sp_port_type_speed_ops {
305         void (*from_ptys_supported_port)(struct mlxsw_sp *mlxsw_sp,
306                                          u32 ptys_eth_proto,
307                                          struct ethtool_link_ksettings *cmd);
308         void (*from_ptys_link)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
309                                u8 width, unsigned long *mode);
310         u32 (*from_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto);
311         void (*from_ptys_speed_duplex)(struct mlxsw_sp *mlxsw_sp,
312                                        bool carrier_ok, u32 ptys_eth_proto,
313                                        struct ethtool_link_ksettings *cmd);
314         u32 (*to_ptys_advert_link)(struct mlxsw_sp *mlxsw_sp, u8 width,
315                                    const struct ethtool_link_ksettings *cmd);
316         u32 (*to_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u8 width, u32 speed);
317         void (*reg_ptys_eth_pack)(struct mlxsw_sp *mlxsw_sp, char *payload,
318                                   u8 local_port, u32 proto_admin, bool autoneg);
319         void (*reg_ptys_eth_unpack)(struct mlxsw_sp *mlxsw_sp, char *payload,
320                                     u32 *p_eth_proto_cap,
321                                     u32 *p_eth_proto_admin,
322                                     u32 *p_eth_proto_oper);
323 };
324
325 static inline struct net_device *
326 mlxsw_sp_bridge_vxlan_dev_find(struct net_device *br_dev)
327 {
328         struct net_device *dev;
329         struct list_head *iter;
330
331         netdev_for_each_lower_dev(br_dev, dev, iter) {
332                 if (netif_is_vxlan(dev))
333                         return dev;
334         }
335
336         return NULL;
337 }
338
339 static inline bool mlxsw_sp_bridge_has_vxlan(struct net_device *br_dev)
340 {
341         return !!mlxsw_sp_bridge_vxlan_dev_find(br_dev);
342 }
343
344 static inline int
345 mlxsw_sp_vxlan_mapped_vid(const struct net_device *vxlan_dev, u16 *p_vid)
346 {
347         struct bridge_vlan_info vinfo;
348         u16 vid = 0;
349         int err;
350
351         err = br_vlan_get_pvid(vxlan_dev, &vid);
352         if (err || !vid)
353                 goto out;
354
355         err = br_vlan_get_info(vxlan_dev, vid, &vinfo);
356         if (err || !(vinfo.flags & BRIDGE_VLAN_INFO_UNTAGGED))
357                 vid = 0;
358
359 out:
360         *p_vid = vid;
361         return err;
362 }
363
364 static inline bool
365 mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
366 {
367         return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
368 }
369
370 static inline struct mlxsw_sp_port *
371 mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
372 {
373         struct mlxsw_sp_port *mlxsw_sp_port;
374         u8 local_port;
375
376         local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
377                                                 lag_id, port_index);
378         mlxsw_sp_port = mlxsw_sp->ports[local_port];
379         return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
380 }
381
382 static inline struct mlxsw_sp_port_vlan *
383 mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
384                                u16 vid)
385 {
386         struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
387
388         list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
389                             list) {
390                 if (mlxsw_sp_port_vlan->vid == vid)
391                         return mlxsw_sp_port_vlan;
392         }
393
394         return NULL;
395 }
396
397 enum mlxsw_sp_flood_type {
398         MLXSW_SP_FLOOD_TYPE_UC,
399         MLXSW_SP_FLOOD_TYPE_BC,
400         MLXSW_SP_FLOOD_TYPE_MC,
401 };
402
403 /* spectrum_buffers.c */
404 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
405 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
406 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
407 int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
408                          unsigned int sb_index, u16 pool_index,
409                          struct devlink_sb_pool_info *pool_info);
410 int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
411                          unsigned int sb_index, u16 pool_index, u32 size,
412                          enum devlink_sb_threshold_type threshold_type,
413                          struct netlink_ext_ack *extack);
414 int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
415                               unsigned int sb_index, u16 pool_index,
416                               u32 *p_threshold);
417 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
418                               unsigned int sb_index, u16 pool_index,
419                               u32 threshold, struct netlink_ext_ack *extack);
420 int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
421                                  unsigned int sb_index, u16 tc_index,
422                                  enum devlink_sb_pool_type pool_type,
423                                  u16 *p_pool_index, u32 *p_threshold);
424 int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
425                                  unsigned int sb_index, u16 tc_index,
426                                  enum devlink_sb_pool_type pool_type,
427                                  u16 pool_index, u32 threshold,
428                                  struct netlink_ext_ack *extack);
429 int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
430                              unsigned int sb_index);
431 int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
432                               unsigned int sb_index);
433 int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
434                                   unsigned int sb_index, u16 pool_index,
435                                   u32 *p_cur, u32 *p_max);
436 int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
437                                      unsigned int sb_index, u16 tc_index,
438                                      enum devlink_sb_pool_type pool_type,
439                                      u32 *p_cur, u32 *p_max);
440 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
441 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
442 u32 mlxsw_sp_sb_max_headroom_cells(const struct mlxsw_sp *mlxsw_sp);
443
444 extern const struct mlxsw_sp_sb_vals mlxsw_sp1_sb_vals;
445 extern const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals;
446
447 /* spectrum_switchdev.c */
448 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
449 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
450 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
451                         bool adding);
452 void
453 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
454 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
455                               struct net_device *brport_dev,
456                               struct net_device *br_dev,
457                               struct netlink_ext_ack *extack);
458 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
459                                 struct net_device *brport_dev,
460                                 struct net_device *br_dev);
461 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
462                                          const struct net_device *br_dev);
463 int mlxsw_sp_bridge_vxlan_join(struct mlxsw_sp *mlxsw_sp,
464                                const struct net_device *br_dev,
465                                const struct net_device *vxlan_dev, u16 vid,
466                                struct netlink_ext_ack *extack);
467 void mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp,
468                                  const struct net_device *vxlan_dev);
469 extern struct notifier_block mlxsw_sp_switchdev_notifier;
470
471 /* spectrum.c */
472 void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb,
473                                        u8 local_port, void *priv);
474 int mlxsw_sp_port_speed_get(struct mlxsw_sp_port *mlxsw_sp_port, u32 *speed);
475 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
476                           enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
477                           bool dwrr, u8 dwrr_weight);
478 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
479                               u8 switch_prio, u8 tclass);
480 int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
481                                  u8 *prio_tc, bool pause_en,
482                                  struct ieee_pfc *my_pfc);
483 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
484                                   enum mlxsw_reg_qeec_hr hr, u8 index,
485                                   u8 next_index, u32 maxrate, u8 burst_size);
486 enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state);
487 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
488                               u8 state);
489 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
490 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
491                                    bool learn_enable);
492 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
493 struct mlxsw_sp_port_vlan *
494 mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
495 void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
496 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
497                            u16 vid_end, bool is_member, bool untagged);
498 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
499                               unsigned int counter_index, u64 *packets,
500                               u64 *bytes);
501 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
502                                 unsigned int *p_counter_index);
503 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
504                                 unsigned int counter_index);
505 u32 mlxsw_sp_span_buffsize_get(struct mlxsw_sp *mlxsw_sp, int mtu, u32 speed);
506 bool mlxsw_sp_port_dev_check(const struct net_device *dev);
507 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
508 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
509 struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
510 void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
511 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
512
513 /* spectrum_dcb.c */
514 #ifdef CONFIG_MLXSW_SPECTRUM_DCB
515 int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
516 void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
517 #else
518 static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
519 {
520         return 0;
521 }
522 static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
523 {}
524 #endif
525
526 /* spectrum_router.c */
527 enum mlxsw_sp_l3proto {
528         MLXSW_SP_L3_PROTO_IPV4,
529         MLXSW_SP_L3_PROTO_IPV6,
530 #define MLXSW_SP_L3_PROTO_MAX   (MLXSW_SP_L3_PROTO_IPV6 + 1)
531 };
532
533 union mlxsw_sp_l3addr {
534         __be32 addr4;
535         struct in6_addr addr6;
536 };
537
538 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp,
539                          struct netlink_ext_ack *extack);
540 void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
541 int mlxsw_sp_netdevice_router_port_event(struct net_device *dev,
542                                          unsigned long event, void *ptr);
543 void mlxsw_sp_rif_macvlan_del(struct mlxsw_sp *mlxsw_sp,
544                               const struct net_device *macvlan_dev);
545 int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
546                                   unsigned long event, void *ptr);
547 int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
548                                    unsigned long event, void *ptr);
549 int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
550                                  struct netdev_notifier_changeupper_info *info);
551 bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp,
552                                 const struct net_device *dev);
553 bool mlxsw_sp_netdev_is_ipip_ul(struct mlxsw_sp *mlxsw_sp,
554                                 const struct net_device *dev);
555 int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,
556                                      struct net_device *l3_dev,
557                                      unsigned long event,
558                                      struct netdev_notifier_info *info);
559 int
560 mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
561                                  struct net_device *l3_dev,
562                                  unsigned long event,
563                                  struct netdev_notifier_info *info);
564 void
565 mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
566 void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp,
567                                  struct net_device *dev);
568 bool mlxsw_sp_rif_exists(struct mlxsw_sp *mlxsw_sp,
569                          const struct net_device *dev);
570 u16 mlxsw_sp_rif_vid(struct mlxsw_sp *mlxsw_sp, const struct net_device *dev);
571 u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp);
572 int mlxsw_sp_router_nve_promote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
573                                       enum mlxsw_sp_l3proto ul_proto,
574                                       const union mlxsw_sp_l3addr *ul_sip,
575                                       u32 tunnel_index);
576 void mlxsw_sp_router_nve_demote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
577                                       enum mlxsw_sp_l3proto ul_proto,
578                                       const union mlxsw_sp_l3addr *ul_sip);
579 int mlxsw_sp_router_tb_id_vr_id(struct mlxsw_sp *mlxsw_sp, u32 tb_id,
580                                 u16 *vr_id);
581 int mlxsw_sp_router_ul_rif_get(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
582                                u16 *ul_rif_index);
583 void mlxsw_sp_router_ul_rif_put(struct mlxsw_sp *mlxsw_sp, u16 ul_rif_index);
584
585 /* spectrum_kvdl.c */
586 enum mlxsw_sp_kvdl_entry_type {
587         MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
588         MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
589         MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
590         MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
591         MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT,
592 };
593
594 static inline unsigned int
595 mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type)
596 {
597         switch (type) {
598         case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ: /* fall through */
599         case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET: /* fall through */
600         case MLXSW_SP_KVDL_ENTRY_TYPE_PBS: /* fall through */
601         case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR: /* fall through */
602         case MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT: /* fall through */
603         default:
604                 return 1;
605         }
606 }
607
608 struct mlxsw_sp_kvdl_ops {
609         size_t priv_size;
610         int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
611         void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
612         int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv,
613                      enum mlxsw_sp_kvdl_entry_type type,
614                      unsigned int entry_count, u32 *p_entry_index);
615         void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv,
616                      enum mlxsw_sp_kvdl_entry_type type,
617                      unsigned int entry_count, int entry_index);
618         int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv,
619                                 enum mlxsw_sp_kvdl_entry_type type,
620                                 unsigned int entry_count,
621                                 unsigned int *p_alloc_count);
622         int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv);
623 };
624
625 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
626 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
627 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
628                         enum mlxsw_sp_kvdl_entry_type type,
629                         unsigned int entry_count, u32 *p_entry_index);
630 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
631                         enum mlxsw_sp_kvdl_entry_type type,
632                         unsigned int entry_count, int entry_index);
633 int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
634                                     enum mlxsw_sp_kvdl_entry_type type,
635                                     unsigned int entry_count,
636                                     unsigned int *p_alloc_count);
637
638 /* spectrum1_kvdl.c */
639 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops;
640 int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core);
641
642 /* spectrum2_kvdl.c */
643 extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops;
644
645 struct mlxsw_sp_acl_rule_info {
646         unsigned int priority;
647         struct mlxsw_afk_element_values values;
648         struct mlxsw_afa_block *act_block;
649         u8 action_created:1,
650            ingress_bind_blocker:1,
651            egress_bind_blocker:1,
652            counter_valid:1;
653         unsigned int counter_index;
654 };
655
656 struct mlxsw_sp_acl_block;
657 struct mlxsw_sp_acl_ruleset;
658
659 /* spectrum_acl.c */
660 enum mlxsw_sp_acl_profile {
661         MLXSW_SP_ACL_PROFILE_FLOWER,
662         MLXSW_SP_ACL_PROFILE_MR,
663 };
664
665 struct mlxsw_sp_acl_block {
666         struct list_head binding_list;
667         struct mlxsw_sp_acl_ruleset *ruleset_zero;
668         struct mlxsw_sp *mlxsw_sp;
669         unsigned int rule_count;
670         unsigned int disable_count;
671         unsigned int ingress_blocker_rule_count;
672         unsigned int egress_blocker_rule_count;
673         unsigned int ingress_binding_count;
674         unsigned int egress_binding_count;
675         struct net *net;
676 };
677
678 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
679 struct mlxsw_sp *mlxsw_sp_acl_block_mlxsw_sp(struct mlxsw_sp_acl_block *block);
680 unsigned int
681 mlxsw_sp_acl_block_rule_count(const struct mlxsw_sp_acl_block *block);
682 void mlxsw_sp_acl_block_disable_inc(struct mlxsw_sp_acl_block *block);
683 void mlxsw_sp_acl_block_disable_dec(struct mlxsw_sp_acl_block *block);
684 bool mlxsw_sp_acl_block_disabled(const struct mlxsw_sp_acl_block *block);
685 struct mlxsw_sp_acl_block *mlxsw_sp_acl_block_create(struct mlxsw_sp *mlxsw_sp,
686                                                      struct net *net);
687 void mlxsw_sp_acl_block_destroy(struct mlxsw_sp_acl_block *block);
688 int mlxsw_sp_acl_block_bind(struct mlxsw_sp *mlxsw_sp,
689                             struct mlxsw_sp_acl_block *block,
690                             struct mlxsw_sp_port *mlxsw_sp_port,
691                             bool ingress,
692                             struct netlink_ext_ack *extack);
693 int mlxsw_sp_acl_block_unbind(struct mlxsw_sp *mlxsw_sp,
694                               struct mlxsw_sp_acl_block *block,
695                               struct mlxsw_sp_port *mlxsw_sp_port,
696                               bool ingress);
697 bool mlxsw_sp_acl_block_is_egress_bound(const struct mlxsw_sp_acl_block *block);
698 bool mlxsw_sp_acl_block_is_ingress_bound(const struct mlxsw_sp_acl_block *block);
699 bool mlxsw_sp_acl_block_is_mixed_bound(const struct mlxsw_sp_acl_block *block);
700 struct mlxsw_sp_acl_ruleset *
701 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
702                             struct mlxsw_sp_acl_block *block, u32 chain_index,
703                             enum mlxsw_sp_acl_profile profile);
704 struct mlxsw_sp_acl_ruleset *
705 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
706                          struct mlxsw_sp_acl_block *block, u32 chain_index,
707                          enum mlxsw_sp_acl_profile profile,
708                          struct mlxsw_afk_element_usage *tmplt_elusage);
709 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
710                               struct mlxsw_sp_acl_ruleset *ruleset);
711 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
712
713 struct mlxsw_sp_acl_rule_info *
714 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
715                           struct mlxsw_afa_block *afa_block);
716 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
717 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
718 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
719                                  unsigned int priority);
720 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
721                                     enum mlxsw_afk_element element,
722                                     u32 key_value, u32 mask_value);
723 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
724                                     enum mlxsw_afk_element element,
725                                     const char *key_value,
726                                     const char *mask_value, unsigned int len);
727 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
728 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
729                                 u16 group_id);
730 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
731 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei,
732                                 bool ingress,
733                                 const struct flow_action_cookie *fa_cookie,
734                                 struct netlink_ext_ack *extack);
735 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
736 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
737                                   struct mlxsw_sp_acl_rule_info *rulei,
738                                   struct mlxsw_sp_acl_block *block,
739                                   struct net_device *out_dev,
740                                   struct netlink_ext_ack *extack);
741 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
742                                struct mlxsw_sp_acl_rule_info *rulei,
743                                struct net_device *out_dev,
744                                struct netlink_ext_ack *extack);
745 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
746                                 struct mlxsw_sp_acl_rule_info *rulei,
747                                 u32 action, u16 vid, u16 proto, u8 prio,
748                                 struct netlink_ext_ack *extack);
749 int mlxsw_sp_acl_rulei_act_priority(struct mlxsw_sp *mlxsw_sp,
750                                     struct mlxsw_sp_acl_rule_info *rulei,
751                                     u32 prio, struct netlink_ext_ack *extack);
752 int mlxsw_sp_acl_rulei_act_mangle(struct mlxsw_sp *mlxsw_sp,
753                                   struct mlxsw_sp_acl_rule_info *rulei,
754                                   enum flow_action_mangle_base htype,
755                                   u32 offset, u32 mask, u32 val,
756                                   struct netlink_ext_ack *extack);
757 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
758                                  struct mlxsw_sp_acl_rule_info *rulei,
759                                  struct netlink_ext_ack *extack);
760 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
761                                    struct mlxsw_sp_acl_rule_info *rulei,
762                                    u16 fid, struct netlink_ext_ack *extack);
763
764 struct mlxsw_sp_acl_rule;
765
766 struct mlxsw_sp_acl_rule *
767 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
768                          struct mlxsw_sp_acl_ruleset *ruleset,
769                          unsigned long cookie,
770                          struct mlxsw_afa_block *afa_block,
771                          struct netlink_ext_ack *extack);
772 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
773                                struct mlxsw_sp_acl_rule *rule);
774 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
775                           struct mlxsw_sp_acl_rule *rule);
776 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
777                            struct mlxsw_sp_acl_rule *rule);
778 int mlxsw_sp_acl_rule_action_replace(struct mlxsw_sp *mlxsw_sp,
779                                      struct mlxsw_sp_acl_rule *rule,
780                                      struct mlxsw_afa_block *afa_block);
781 struct mlxsw_sp_acl_rule *
782 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
783                          struct mlxsw_sp_acl_ruleset *ruleset,
784                          unsigned long cookie);
785 struct mlxsw_sp_acl_rule_info *
786 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
787 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
788                                 struct mlxsw_sp_acl_rule *rule,
789                                 u64 *packets, u64 *bytes, u64 *last_use,
790                                 enum flow_action_hw_stats *used_hw_stats);
791
792 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
793
794 static inline const struct flow_action_cookie *
795 mlxsw_sp_acl_act_cookie_lookup(struct mlxsw_sp *mlxsw_sp, u32 cookie_index)
796 {
797         return mlxsw_afa_cookie_lookup(mlxsw_sp->afa, cookie_index);
798 }
799
800 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
801 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
802 u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp);
803 int mlxsw_sp_acl_region_rehash_intrvl_set(struct mlxsw_sp *mlxsw_sp, u32 val);
804
805 /* spectrum_acl_tcam.c */
806 struct mlxsw_sp_acl_tcam;
807 struct mlxsw_sp_acl_tcam_region;
808
809 struct mlxsw_sp_acl_tcam_ops {
810         enum mlxsw_reg_ptar_key_type key_type;
811         size_t priv_size;
812         int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv,
813                     struct mlxsw_sp_acl_tcam *tcam);
814         void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
815         size_t region_priv_size;
816         int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv,
817                            void *tcam_priv,
818                            struct mlxsw_sp_acl_tcam_region *region,
819                            void *hints_priv);
820         void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
821         int (*region_associate)(struct mlxsw_sp *mlxsw_sp,
822                                 struct mlxsw_sp_acl_tcam_region *region);
823         void * (*region_rehash_hints_get)(void *region_priv);
824         void (*region_rehash_hints_put)(void *hints_priv);
825         size_t chunk_priv_size;
826         void (*chunk_init)(void *region_priv, void *chunk_priv,
827                            unsigned int priority);
828         void (*chunk_fini)(void *chunk_priv);
829         size_t entry_priv_size;
830         int (*entry_add)(struct mlxsw_sp *mlxsw_sp,
831                          void *region_priv, void *chunk_priv,
832                          void *entry_priv,
833                          struct mlxsw_sp_acl_rule_info *rulei);
834         void (*entry_del)(struct mlxsw_sp *mlxsw_sp,
835                           void *region_priv, void *chunk_priv,
836                           void *entry_priv);
837         int (*entry_action_replace)(struct mlxsw_sp *mlxsw_sp,
838                                     void *region_priv, void *entry_priv,
839                                     struct mlxsw_sp_acl_rule_info *rulei);
840         int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp,
841                                   void *region_priv, void *entry_priv,
842                                   bool *activity);
843 };
844
845 /* spectrum1_acl_tcam.c */
846 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops;
847
848 /* spectrum2_acl_tcam.c */
849 extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops;
850
851 /* spectrum_acl_flex_actions.c */
852 extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops;
853 extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops;
854
855 /* spectrum_acl_flex_keys.c */
856 extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
857 extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;
858
859 /* spectrum_flower.c */
860 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
861                             struct mlxsw_sp_acl_block *block,
862                             struct flow_cls_offload *f);
863 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
864                              struct mlxsw_sp_acl_block *block,
865                              struct flow_cls_offload *f);
866 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
867                           struct mlxsw_sp_acl_block *block,
868                           struct flow_cls_offload *f);
869 int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
870                                  struct mlxsw_sp_acl_block *block,
871                                  struct flow_cls_offload *f);
872 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
873                                    struct mlxsw_sp_acl_block *block,
874                                    struct flow_cls_offload *f);
875
876 /* spectrum_qdisc.c */
877 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
878 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
879 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
880                           struct tc_red_qopt_offload *p);
881 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
882                            struct tc_prio_qopt_offload *p);
883 int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port,
884                           struct tc_ets_qopt_offload *p);
885 int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port,
886                           struct tc_tbf_qopt_offload *p);
887 int mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port,
888                            struct tc_fifo_qopt_offload *p);
889
890 /* spectrum_fid.c */
891 bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index);
892 bool mlxsw_sp_fid_lag_vid_valid(const struct mlxsw_sp_fid *fid);
893 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp,
894                                                   u16 fid_index);
895 int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex);
896 int mlxsw_sp_fid_nve_type(const struct mlxsw_sp_fid *fid,
897                           enum mlxsw_sp_nve_type *p_type);
898 struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_vni(struct mlxsw_sp *mlxsw_sp,
899                                                 __be32 vni);
900 int mlxsw_sp_fid_vni(const struct mlxsw_sp_fid *fid, __be32 *vni);
901 int mlxsw_sp_fid_nve_flood_index_set(struct mlxsw_sp_fid *fid,
902                                      u32 nve_flood_index);
903 void mlxsw_sp_fid_nve_flood_index_clear(struct mlxsw_sp_fid *fid);
904 bool mlxsw_sp_fid_nve_flood_index_is_set(const struct mlxsw_sp_fid *fid);
905 int mlxsw_sp_fid_vni_set(struct mlxsw_sp_fid *fid, enum mlxsw_sp_nve_type type,
906                          __be32 vni, int nve_ifindex);
907 void mlxsw_sp_fid_vni_clear(struct mlxsw_sp_fid *fid);
908 bool mlxsw_sp_fid_vni_is_set(const struct mlxsw_sp_fid *fid);
909 void mlxsw_sp_fid_fdb_clear_offload(const struct mlxsw_sp_fid *fid,
910                                     const struct net_device *nve_dev);
911 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
912                            enum mlxsw_sp_flood_type packet_type, u8 local_port,
913                            bool member);
914 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
915                               struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
916 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
917                                  struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
918 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
919 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
920 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
921 struct mlxsw_sp_rif *mlxsw_sp_fid_rif(const struct mlxsw_sp_fid *fid);
922 enum mlxsw_sp_rif_type
923 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
924                            enum mlxsw_sp_fid_type type);
925 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
926 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
927 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
928                                             int br_ifindex);
929 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_lookup(struct mlxsw_sp *mlxsw_sp,
930                                                u16 vid);
931 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_lookup(struct mlxsw_sp *mlxsw_sp,
932                                                int br_ifindex);
933 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
934                                            u16 rif_index);
935 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
936 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
937 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
938 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
939 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
940 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
941
942 /* spectrum_mr.c */
943 enum mlxsw_sp_mr_route_prio {
944         MLXSW_SP_MR_ROUTE_PRIO_SG,
945         MLXSW_SP_MR_ROUTE_PRIO_STARG,
946         MLXSW_SP_MR_ROUTE_PRIO_CATCHALL,
947         __MLXSW_SP_MR_ROUTE_PRIO_MAX
948 };
949
950 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
951
952 struct mlxsw_sp_mr_route_key;
953
954 struct mlxsw_sp_mr_tcam_ops {
955         size_t priv_size;
956         int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
957         void (*fini)(void *priv);
958         size_t route_priv_size;
959         int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
960                             void *route_priv,
961                             struct mlxsw_sp_mr_route_key *key,
962                             struct mlxsw_afa_block *afa_block,
963                             enum mlxsw_sp_mr_route_prio prio);
964         void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
965                               void *route_priv,
966                               struct mlxsw_sp_mr_route_key *key);
967         int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
968                             struct mlxsw_sp_mr_route_key *key,
969                             struct mlxsw_afa_block *afa_block);
970 };
971
972 /* spectrum1_mr_tcam.c */
973 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops;
974
975 /* spectrum2_mr_tcam.c */
976 extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops;
977
978 /* spectrum_nve.c */
979 struct mlxsw_sp_nve_params {
980         enum mlxsw_sp_nve_type type;
981         __be32 vni;
982         const struct net_device *dev;
983 };
984
985 extern const struct mlxsw_sp_nve_ops *mlxsw_sp1_nve_ops_arr[];
986 extern const struct mlxsw_sp_nve_ops *mlxsw_sp2_nve_ops_arr[];
987
988 int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip,
989                                     enum mlxsw_sp_l3proto proto,
990                                     union mlxsw_sp_l3addr *addr);
991 int mlxsw_sp_nve_flood_ip_add(struct mlxsw_sp *mlxsw_sp,
992                               struct mlxsw_sp_fid *fid,
993                               enum mlxsw_sp_l3proto proto,
994                               union mlxsw_sp_l3addr *addr);
995 void mlxsw_sp_nve_flood_ip_del(struct mlxsw_sp *mlxsw_sp,
996                                struct mlxsw_sp_fid *fid,
997                                enum mlxsw_sp_l3proto proto,
998                                union mlxsw_sp_l3addr *addr);
999 int mlxsw_sp_nve_fid_enable(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *fid,
1000                             struct mlxsw_sp_nve_params *params,
1001                             struct netlink_ext_ack *extack);
1002 void mlxsw_sp_nve_fid_disable(struct mlxsw_sp *mlxsw_sp,
1003                               struct mlxsw_sp_fid *fid);
1004 int mlxsw_sp_port_nve_init(struct mlxsw_sp_port *mlxsw_sp_port);
1005 void mlxsw_sp_port_nve_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1006 int mlxsw_sp_nve_init(struct mlxsw_sp *mlxsw_sp);
1007 void mlxsw_sp_nve_fini(struct mlxsw_sp *mlxsw_sp);
1008
1009 /* spectrum_nve_vxlan.c */
1010 int mlxsw_sp_nve_inc_parsing_depth_get(struct mlxsw_sp *mlxsw_sp);
1011 void mlxsw_sp_nve_inc_parsing_depth_put(struct mlxsw_sp *mlxsw_sp);
1012
1013 /* spectrum_trap.c */
1014 int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp);
1015 void mlxsw_sp_devlink_traps_fini(struct mlxsw_sp *mlxsw_sp);
1016 int mlxsw_sp_trap_init(struct mlxsw_core *mlxsw_core,
1017                        const struct devlink_trap *trap, void *trap_ctx);
1018 void mlxsw_sp_trap_fini(struct mlxsw_core *mlxsw_core,
1019                         const struct devlink_trap *trap, void *trap_ctx);
1020 int mlxsw_sp_trap_action_set(struct mlxsw_core *mlxsw_core,
1021                              const struct devlink_trap *trap,
1022                              enum devlink_trap_action action);
1023 int mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core,
1024                              const struct devlink_trap_group *group);
1025
1026 static inline struct net *mlxsw_sp_net(struct mlxsw_sp *mlxsw_sp)
1027 {
1028         return mlxsw_core_net(mlxsw_sp->core);
1029 }
1030
1031 #endif