Merge remote-tracking branch 'asoc/topic/pcm5102a' into asoc-next
[linux-block.git] / drivers / net / ethernet / mellanox / mlxsw / spectrum.h
1 /*
2  * drivers/net/ethernet/mellanox/mlxsw/spectrum.h
3  * Copyright (c) 2015-2017 Mellanox Technologies. All rights reserved.
4  * Copyright (c) 2015-2017 Jiri Pirko <jiri@mellanox.com>
5  * Copyright (c) 2015 Ido Schimmel <idosch@mellanox.com>
6  * Copyright (c) 2015 Elad Raz <eladr@mellanox.com>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the names of the copyright holders nor the names of its
17  *    contributors may be used to endorse or promote products derived from
18  *    this software without specific prior written permission.
19  *
20  * Alternatively, this software may be distributed under the terms of the
21  * GNU General Public License ("GPL") version 2 as published by the Free
22  * Software Foundation.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36
37 #ifndef _MLXSW_SPECTRUM_H
38 #define _MLXSW_SPECTRUM_H
39
40 #include <linux/types.h>
41 #include <linux/netdevice.h>
42 #include <linux/rhashtable.h>
43 #include <linux/bitops.h>
44 #include <linux/if_vlan.h>
45 #include <linux/list.h>
46 #include <linux/dcbnl.h>
47 #include <linux/in6.h>
48 #include <linux/notifier.h>
49 #include <net/psample.h>
50 #include <net/pkt_cls.h>
51 #include <net/red.h>
52
53 #include "port.h"
54 #include "core.h"
55 #include "core_acl_flex_keys.h"
56 #include "core_acl_flex_actions.h"
57
58 #define MLXSW_SP_FID_8021D_MAX 1024
59
60 #define MLXSW_SP_MID_MAX 7000
61
62 #define MLXSW_SP_PORTS_PER_CLUSTER_MAX 4
63
64 #define MLXSW_SP_PORT_BASE_SPEED 25000  /* Mb/s */
65
66 #define MLXSW_SP_KVD_LINEAR_SIZE 98304 /* entries */
67 #define MLXSW_SP_KVD_GRANULARITY 128
68
69 #define MLXSW_SP_RESOURCE_NAME_KVD "kvd"
70 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR "linear"
71 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE "hash_single"
72 #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE "hash_double"
73
74 enum mlxsw_sp_resource_id {
75         MLXSW_SP_RESOURCE_KVD,
76         MLXSW_SP_RESOURCE_KVD_LINEAR,
77         MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
78         MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
79 };
80
81 struct mlxsw_sp_port;
82 struct mlxsw_sp_rif;
83
84 struct mlxsw_sp_upper {
85         struct net_device *dev;
86         unsigned int ref_count;
87 };
88
89 enum mlxsw_sp_rif_type {
90         MLXSW_SP_RIF_TYPE_SUBPORT,
91         MLXSW_SP_RIF_TYPE_VLAN,
92         MLXSW_SP_RIF_TYPE_FID,
93         MLXSW_SP_RIF_TYPE_IPIP_LB, /* IP-in-IP loopback. */
94         MLXSW_SP_RIF_TYPE_MAX,
95 };
96
97 enum mlxsw_sp_fid_type {
98         MLXSW_SP_FID_TYPE_8021Q,
99         MLXSW_SP_FID_TYPE_8021D,
100         MLXSW_SP_FID_TYPE_RFID,
101         MLXSW_SP_FID_TYPE_DUMMY,
102         MLXSW_SP_FID_TYPE_MAX,
103 };
104
105 struct mlxsw_sp_mid {
106         struct list_head list;
107         unsigned char addr[ETH_ALEN];
108         u16 fid;
109         u16 mid;
110         bool in_hw;
111         unsigned long *ports_in_mid; /* bits array */
112 };
113
114 enum mlxsw_sp_span_type {
115         MLXSW_SP_SPAN_EGRESS,
116         MLXSW_SP_SPAN_INGRESS
117 };
118
119 struct mlxsw_sp_span_inspected_port {
120         struct list_head list;
121         enum mlxsw_sp_span_type type;
122         u8 local_port;
123
124         /* Whether this is a directly bound mirror (port-to-port) or an ACL. */
125         bool bound;
126 };
127
128 struct mlxsw_sp_span_entry {
129         u8 local_port;
130         bool used;
131         struct list_head bound_ports_list;
132         int ref_count;
133         int id;
134 };
135
136 enum mlxsw_sp_port_mall_action_type {
137         MLXSW_SP_PORT_MALL_MIRROR,
138         MLXSW_SP_PORT_MALL_SAMPLE,
139 };
140
141 struct mlxsw_sp_port_mall_mirror_tc_entry {
142         u8 to_local_port;
143         bool ingress;
144 };
145
146 struct mlxsw_sp_port_mall_tc_entry {
147         struct list_head list;
148         unsigned long cookie;
149         enum mlxsw_sp_port_mall_action_type type;
150         union {
151                 struct mlxsw_sp_port_mall_mirror_tc_entry mirror;
152         };
153 };
154
155 struct mlxsw_sp_sb;
156 struct mlxsw_sp_bridge;
157 struct mlxsw_sp_router;
158 struct mlxsw_sp_mr;
159 struct mlxsw_sp_acl;
160 struct mlxsw_sp_counter_pool;
161 struct mlxsw_sp_fid_core;
162 struct mlxsw_sp_kvdl;
163
164 struct mlxsw_sp {
165         struct mlxsw_sp_port **ports;
166         struct mlxsw_core *core;
167         const struct mlxsw_bus_info *bus_info;
168         unsigned char base_mac[ETH_ALEN];
169         struct mlxsw_sp_upper *lags;
170         int *port_to_module;
171         struct mlxsw_sp_sb *sb;
172         struct mlxsw_sp_bridge *bridge;
173         struct mlxsw_sp_router *router;
174         struct mlxsw_sp_mr *mr;
175         struct mlxsw_afa *afa;
176         struct mlxsw_sp_acl *acl;
177         struct mlxsw_sp_fid_core *fid_core;
178         struct mlxsw_sp_kvdl *kvdl;
179         struct notifier_block netdevice_nb;
180
181         struct mlxsw_sp_counter_pool *counter_pool;
182         struct {
183                 struct mlxsw_sp_span_entry *entries;
184                 int entries_count;
185         } span;
186 };
187
188 static inline struct mlxsw_sp_upper *
189 mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
190 {
191         return &mlxsw_sp->lags[lag_id];
192 }
193
194 struct mlxsw_sp_port_pcpu_stats {
195         u64                     rx_packets;
196         u64                     rx_bytes;
197         u64                     tx_packets;
198         u64                     tx_bytes;
199         struct u64_stats_sync   syncp;
200         u32                     tx_dropped;
201 };
202
203 struct mlxsw_sp_port_sample {
204         struct psample_group __rcu *psample_group;
205         u32 trunc_size;
206         u32 rate;
207         bool truncate;
208 };
209
210 struct mlxsw_sp_bridge_port;
211 struct mlxsw_sp_fid;
212
213 struct mlxsw_sp_port_vlan {
214         struct list_head list;
215         struct mlxsw_sp_port *mlxsw_sp_port;
216         struct mlxsw_sp_fid *fid;
217         unsigned int ref_count;
218         u16 vid;
219         struct mlxsw_sp_bridge_port *bridge_port;
220         struct list_head bridge_vlan_node;
221 };
222
223 /* No need an internal lock; At worse - miss a single periodic iteration */
224 struct mlxsw_sp_port_xstats {
225         u64 ecn;
226         u64 wred_drop[TC_MAX_QUEUE];
227         u64 tail_drop[TC_MAX_QUEUE];
228         u64 backlog[TC_MAX_QUEUE];
229 };
230
231 struct mlxsw_sp_port {
232         struct net_device *dev;
233         struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
234         struct mlxsw_sp *mlxsw_sp;
235         u8 local_port;
236         u8 lagged:1,
237            split:1;
238         u16 pvid;
239         u16 lag_id;
240         struct {
241                 u8 tx_pause:1,
242                    rx_pause:1,
243                    autoneg:1;
244         } link;
245         struct {
246                 struct ieee_ets *ets;
247                 struct ieee_maxrate *maxrate;
248                 struct ieee_pfc *pfc;
249         } dcb;
250         struct {
251                 u8 module;
252                 u8 width;
253                 u8 lane;
254         } mapping;
255         /* TC handles */
256         struct list_head mall_tc_list;
257         struct {
258                 #define MLXSW_HW_STATS_UPDATE_TIME HZ
259                 struct rtnl_link_stats64 stats;
260                 struct mlxsw_sp_port_xstats xstats;
261                 struct delayed_work update_dw;
262         } periodic_hw_stats;
263         struct mlxsw_sp_port_sample *sample;
264         struct list_head vlans_list;
265         struct mlxsw_sp_qdisc *root_qdisc;
266         unsigned acl_rule_count;
267         struct mlxsw_sp_acl_block *ing_acl_block;
268         struct mlxsw_sp_acl_block *eg_acl_block;
269 };
270
271 static inline bool
272 mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
273 {
274         return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
275 }
276
277 static inline struct mlxsw_sp_port *
278 mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
279 {
280         struct mlxsw_sp_port *mlxsw_sp_port;
281         u8 local_port;
282
283         local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
284                                                 lag_id, port_index);
285         mlxsw_sp_port = mlxsw_sp->ports[local_port];
286         return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
287 }
288
289 static inline struct mlxsw_sp_port_vlan *
290 mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
291                                u16 vid)
292 {
293         struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
294
295         list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
296                             list) {
297                 if (mlxsw_sp_port_vlan->vid == vid)
298                         return mlxsw_sp_port_vlan;
299         }
300
301         return NULL;
302 }
303
304 enum mlxsw_sp_flood_type {
305         MLXSW_SP_FLOOD_TYPE_UC,
306         MLXSW_SP_FLOOD_TYPE_BC,
307         MLXSW_SP_FLOOD_TYPE_MC,
308 };
309
310 /* spectrum_buffers.c */
311 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
312 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
313 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
314 int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
315                          unsigned int sb_index, u16 pool_index,
316                          struct devlink_sb_pool_info *pool_info);
317 int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
318                          unsigned int sb_index, u16 pool_index, u32 size,
319                          enum devlink_sb_threshold_type threshold_type);
320 int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
321                               unsigned int sb_index, u16 pool_index,
322                               u32 *p_threshold);
323 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
324                               unsigned int sb_index, u16 pool_index,
325                               u32 threshold);
326 int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
327                                  unsigned int sb_index, u16 tc_index,
328                                  enum devlink_sb_pool_type pool_type,
329                                  u16 *p_pool_index, u32 *p_threshold);
330 int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
331                                  unsigned int sb_index, u16 tc_index,
332                                  enum devlink_sb_pool_type pool_type,
333                                  u16 pool_index, u32 threshold);
334 int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
335                              unsigned int sb_index);
336 int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
337                               unsigned int sb_index);
338 int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
339                                   unsigned int sb_index, u16 pool_index,
340                                   u32 *p_cur, u32 *p_max);
341 int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
342                                      unsigned int sb_index, u16 tc_index,
343                                      enum devlink_sb_pool_type pool_type,
344                                      u32 *p_cur, u32 *p_max);
345 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
346 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
347
348 /* spectrum_switchdev.c */
349 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
350 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
351 void mlxsw_sp_port_switchdev_init(struct mlxsw_sp_port *mlxsw_sp_port);
352 void mlxsw_sp_port_switchdev_fini(struct mlxsw_sp_port *mlxsw_sp_port);
353 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
354                         bool adding);
355 void
356 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
357 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
358                               struct net_device *brport_dev,
359                               struct net_device *br_dev,
360                               struct netlink_ext_ack *extack);
361 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
362                                 struct net_device *brport_dev,
363                                 struct net_device *br_dev);
364 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
365                                          const struct net_device *br_dev);
366
367 /* spectrum.c */
368 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
369                           enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
370                           bool dwrr, u8 dwrr_weight);
371 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
372                               u8 switch_prio, u8 tclass);
373 int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
374                                  u8 *prio_tc, bool pause_en,
375                                  struct ieee_pfc *my_pfc);
376 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
377                                   enum mlxsw_reg_qeec_hr hr, u8 index,
378                                   u8 next_index, u32 maxrate);
379 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
380                               u8 state);
381 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
382 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
383                                    bool learn_enable);
384 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
385 struct mlxsw_sp_port_vlan *
386 mlxsw_sp_port_vlan_get(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
387 void mlxsw_sp_port_vlan_put(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
388 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
389                            u16 vid_end, bool is_member, bool untagged);
390 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
391                               unsigned int counter_index, u64 *packets,
392                               u64 *bytes);
393 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
394                                 unsigned int *p_counter_index);
395 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
396                                 unsigned int counter_index);
397 bool mlxsw_sp_port_dev_check(const struct net_device *dev);
398 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
399 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
400 struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
401 void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
402 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
403 int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from,
404                              struct mlxsw_sp_port *to,
405                              enum mlxsw_sp_span_type type,
406                              bool bind);
407 void mlxsw_sp_span_mirror_del(struct mlxsw_sp_port *from,
408                               u8 destination_port,
409                               enum mlxsw_sp_span_type type,
410                               bool bind);
411 struct mlxsw_sp_span_entry *
412 mlxsw_sp_span_entry_find(struct mlxsw_sp *mlxsw_sp, u8 local_port);
413
414 /* spectrum_dcb.c */
415 #ifdef CONFIG_MLXSW_SPECTRUM_DCB
416 int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
417 void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
418 #else
419 static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
420 {
421         return 0;
422 }
423 static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
424 {}
425 #endif
426
427 /* spectrum_router.c */
428 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp);
429 void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
430 int mlxsw_sp_netdevice_router_port_event(struct net_device *dev);
431 int mlxsw_sp_inetaddr_event(struct notifier_block *unused,
432                             unsigned long event, void *ptr);
433 int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
434                                   unsigned long event, void *ptr);
435 int mlxsw_sp_inet6addr_event(struct notifier_block *unused,
436                              unsigned long event, void *ptr);
437 int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
438                                    unsigned long event, void *ptr);
439 int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
440                                  struct netdev_notifier_changeupper_info *info);
441 bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp,
442                                 const struct net_device *dev);
443 bool mlxsw_sp_netdev_is_ipip_ul(const struct mlxsw_sp *mlxsw_sp,
444                                 const struct net_device *dev);
445 int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,
446                                      struct net_device *l3_dev,
447                                      unsigned long event,
448                                      struct netdev_notifier_info *info);
449 int
450 mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
451                                  struct net_device *l3_dev,
452                                  unsigned long event,
453                                  struct netdev_notifier_info *info);
454 void
455 mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
456 void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif);
457
458 /* spectrum_kvdl.c */
459 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
460 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
461 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, unsigned int entry_count,
462                         u32 *p_entry_index);
463 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp, int entry_index);
464 int mlxsw_sp_kvdl_alloc_size_query(struct mlxsw_sp *mlxsw_sp,
465                                    unsigned int entry_count,
466                                    unsigned int *p_alloc_size);
467 u64 mlxsw_sp_kvdl_occ_get(const struct mlxsw_sp *mlxsw_sp);
468
469 struct mlxsw_sp_acl_rule_info {
470         unsigned int priority;
471         struct mlxsw_afk_element_values values;
472         struct mlxsw_afa_block *act_block;
473         unsigned int counter_index;
474 };
475
476 enum mlxsw_sp_acl_profile {
477         MLXSW_SP_ACL_PROFILE_FLOWER,
478 };
479
480 struct mlxsw_sp_acl_profile_ops {
481         size_t ruleset_priv_size;
482         int (*ruleset_add)(struct mlxsw_sp *mlxsw_sp,
483                            void *priv, void *ruleset_priv);
484         void (*ruleset_del)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv);
485         int (*ruleset_bind)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv,
486                             struct mlxsw_sp_port *mlxsw_sp_port,
487                             bool ingress);
488         void (*ruleset_unbind)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv,
489                                struct mlxsw_sp_port *mlxsw_sp_port,
490                                bool ingress);
491         u16 (*ruleset_group_id)(void *ruleset_priv);
492         size_t rule_priv_size;
493         int (*rule_add)(struct mlxsw_sp *mlxsw_sp,
494                         void *ruleset_priv, void *rule_priv,
495                         struct mlxsw_sp_acl_rule_info *rulei);
496         void (*rule_del)(struct mlxsw_sp *mlxsw_sp, void *rule_priv);
497         int (*rule_activity_get)(struct mlxsw_sp *mlxsw_sp, void *rule_priv,
498                                  bool *activity);
499 };
500
501 struct mlxsw_sp_acl_ops {
502         size_t priv_size;
503         int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
504         void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
505         const struct mlxsw_sp_acl_profile_ops *
506                         (*profile_ops)(struct mlxsw_sp *mlxsw_sp,
507                                        enum mlxsw_sp_acl_profile profile);
508 };
509
510 struct mlxsw_sp_acl_block;
511 struct mlxsw_sp_acl_ruleset;
512
513 /* spectrum_acl.c */
514 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
515 struct mlxsw_sp *mlxsw_sp_acl_block_mlxsw_sp(struct mlxsw_sp_acl_block *block);
516 unsigned int mlxsw_sp_acl_block_rule_count(struct mlxsw_sp_acl_block *block);
517 void mlxsw_sp_acl_block_disable_inc(struct mlxsw_sp_acl_block *block);
518 void mlxsw_sp_acl_block_disable_dec(struct mlxsw_sp_acl_block *block);
519 bool mlxsw_sp_acl_block_disabled(struct mlxsw_sp_acl_block *block);
520 struct mlxsw_sp_acl_block *mlxsw_sp_acl_block_create(struct mlxsw_sp *mlxsw_sp,
521                                                      struct net *net);
522 void mlxsw_sp_acl_block_destroy(struct mlxsw_sp_acl_block *block);
523 int mlxsw_sp_acl_block_bind(struct mlxsw_sp *mlxsw_sp,
524                             struct mlxsw_sp_acl_block *block,
525                             struct mlxsw_sp_port *mlxsw_sp_port,
526                             bool ingress);
527 int mlxsw_sp_acl_block_unbind(struct mlxsw_sp *mlxsw_sp,
528                               struct mlxsw_sp_acl_block *block,
529                               struct mlxsw_sp_port *mlxsw_sp_port,
530                               bool ingress);
531 struct mlxsw_sp_acl_ruleset *
532 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
533                             struct mlxsw_sp_acl_block *block, u32 chain_index,
534                             enum mlxsw_sp_acl_profile profile);
535 struct mlxsw_sp_acl_ruleset *
536 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
537                          struct mlxsw_sp_acl_block *block, u32 chain_index,
538                          enum mlxsw_sp_acl_profile profile);
539 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
540                               struct mlxsw_sp_acl_ruleset *ruleset);
541 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
542
543 struct mlxsw_sp_acl_rule_info *
544 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl);
545 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
546 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
547 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
548                                  unsigned int priority);
549 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
550                                     enum mlxsw_afk_element element,
551                                     u32 key_value, u32 mask_value);
552 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
553                                     enum mlxsw_afk_element element,
554                                     const char *key_value,
555                                     const char *mask_value, unsigned int len);
556 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
557 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
558                                 u16 group_id);
559 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
560 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei);
561 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
562 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
563                                   struct mlxsw_sp_acl_rule_info *rulei,
564                                   struct mlxsw_sp_acl_block *block,
565                                   struct net_device *out_dev);
566 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
567                                struct mlxsw_sp_acl_rule_info *rulei,
568                                struct net_device *out_dev);
569 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
570                                 struct mlxsw_sp_acl_rule_info *rulei,
571                                 u32 action, u16 vid, u16 proto, u8 prio);
572 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
573                                  struct mlxsw_sp_acl_rule_info *rulei);
574 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
575                                    struct mlxsw_sp_acl_rule_info *rulei,
576                                    u16 fid);
577
578 struct mlxsw_sp_acl_rule;
579
580 struct mlxsw_sp_acl_rule *
581 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
582                          struct mlxsw_sp_acl_ruleset *ruleset,
583                          unsigned long cookie);
584 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
585                                struct mlxsw_sp_acl_rule *rule);
586 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
587                           struct mlxsw_sp_acl_rule *rule);
588 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
589                            struct mlxsw_sp_acl_rule *rule);
590 struct mlxsw_sp_acl_rule *
591 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
592                          struct mlxsw_sp_acl_ruleset *ruleset,
593                          unsigned long cookie);
594 struct mlxsw_sp_acl_rule_info *
595 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
596 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
597                                 struct mlxsw_sp_acl_rule *rule,
598                                 u64 *packets, u64 *bytes, u64 *last_use);
599
600 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
601
602 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
603 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
604
605 /* spectrum_acl_tcam.c */
606 extern const struct mlxsw_sp_acl_ops mlxsw_sp_acl_tcam_ops;
607
608 /* spectrum_flower.c */
609 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
610                             struct mlxsw_sp_acl_block *block,
611                             struct tc_cls_flower_offload *f);
612 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
613                              struct mlxsw_sp_acl_block *block,
614                              struct tc_cls_flower_offload *f);
615 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
616                           struct mlxsw_sp_acl_block *block,
617                           struct tc_cls_flower_offload *f);
618
619 /* spectrum_qdisc.c */
620 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
621 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
622 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
623                           struct tc_red_qopt_offload *p);
624 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
625                            struct tc_prio_qopt_offload *p);
626
627 /* spectrum_fid.c */
628 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
629                            enum mlxsw_sp_flood_type packet_type, u8 local_port,
630                            bool member);
631 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
632                               struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
633 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
634                                  struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
635 enum mlxsw_sp_rif_type mlxsw_sp_fid_rif_type(const struct mlxsw_sp_fid *fid);
636 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
637 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
638 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
639 enum mlxsw_sp_rif_type
640 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
641                            enum mlxsw_sp_fid_type type);
642 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
643 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
644 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
645                                             int br_ifindex);
646 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
647                                            u16 rif_index);
648 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
649 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
650 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
651 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
652 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
653 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
654
655 #endif