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