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