Merge tag 'nds32-for-linus-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.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 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES "singles"
74 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS "chunks"
75 #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks"
76
77 enum mlxsw_sp_resource_id {
78         MLXSW_SP_RESOURCE_KVD = 1,
79         MLXSW_SP_RESOURCE_KVD_LINEAR,
80         MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
81         MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
82         MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE,
83         MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS,
84         MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS,
85 };
86
87 struct mlxsw_sp_port;
88 struct mlxsw_sp_rif;
89 struct mlxsw_sp_span_entry;
90
91 struct mlxsw_sp_upper {
92         struct net_device *dev;
93         unsigned int ref_count;
94 };
95
96 enum mlxsw_sp_rif_type {
97         MLXSW_SP_RIF_TYPE_SUBPORT,
98         MLXSW_SP_RIF_TYPE_VLAN,
99         MLXSW_SP_RIF_TYPE_FID,
100         MLXSW_SP_RIF_TYPE_IPIP_LB, /* IP-in-IP loopback. */
101         MLXSW_SP_RIF_TYPE_MAX,
102 };
103
104 enum mlxsw_sp_fid_type {
105         MLXSW_SP_FID_TYPE_8021Q,
106         MLXSW_SP_FID_TYPE_8021D,
107         MLXSW_SP_FID_TYPE_RFID,
108         MLXSW_SP_FID_TYPE_DUMMY,
109         MLXSW_SP_FID_TYPE_MAX,
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 enum mlxsw_sp_port_mall_action_type {
122         MLXSW_SP_PORT_MALL_MIRROR,
123         MLXSW_SP_PORT_MALL_SAMPLE,
124 };
125
126 struct mlxsw_sp_port_mall_mirror_tc_entry {
127         int span_id;
128         bool ingress;
129 };
130
131 struct mlxsw_sp_port_mall_tc_entry {
132         struct list_head list;
133         unsigned long cookie;
134         enum mlxsw_sp_port_mall_action_type type;
135         union {
136                 struct mlxsw_sp_port_mall_mirror_tc_entry mirror;
137         };
138 };
139
140 struct mlxsw_sp_sb;
141 struct mlxsw_sp_bridge;
142 struct mlxsw_sp_router;
143 struct mlxsw_sp_mr;
144 struct mlxsw_sp_acl;
145 struct mlxsw_sp_counter_pool;
146 struct mlxsw_sp_fid_core;
147 struct mlxsw_sp_kvdl;
148
149 struct mlxsw_sp {
150         struct mlxsw_sp_port **ports;
151         struct mlxsw_core *core;
152         const struct mlxsw_bus_info *bus_info;
153         unsigned char base_mac[ETH_ALEN];
154         struct mlxsw_sp_upper *lags;
155         int *port_to_module;
156         struct mlxsw_sp_sb *sb;
157         struct mlxsw_sp_bridge *bridge;
158         struct mlxsw_sp_router *router;
159         struct mlxsw_sp_mr *mr;
160         struct mlxsw_afa *afa;
161         struct mlxsw_sp_acl *acl;
162         struct mlxsw_sp_fid_core *fid_core;
163         struct mlxsw_sp_kvdl *kvdl;
164         struct notifier_block netdevice_nb;
165
166         struct mlxsw_sp_counter_pool *counter_pool;
167         struct {
168                 struct mlxsw_sp_span_entry *entries;
169                 int entries_count;
170         } span;
171 };
172
173 static inline struct mlxsw_sp_upper *
174 mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
175 {
176         return &mlxsw_sp->lags[lag_id];
177 }
178
179 struct mlxsw_sp_port_pcpu_stats {
180         u64                     rx_packets;
181         u64                     rx_bytes;
182         u64                     tx_packets;
183         u64                     tx_bytes;
184         struct u64_stats_sync   syncp;
185         u32                     tx_dropped;
186 };
187
188 struct mlxsw_sp_port_sample {
189         struct psample_group __rcu *psample_group;
190         u32 trunc_size;
191         u32 rate;
192         bool truncate;
193 };
194
195 struct mlxsw_sp_bridge_port;
196 struct mlxsw_sp_fid;
197
198 struct mlxsw_sp_port_vlan {
199         struct list_head list;
200         struct mlxsw_sp_port *mlxsw_sp_port;
201         struct mlxsw_sp_fid *fid;
202         unsigned int ref_count;
203         u16 vid;
204         struct mlxsw_sp_bridge_port *bridge_port;
205         struct list_head bridge_vlan_node;
206 };
207
208 /* No need an internal lock; At worse - miss a single periodic iteration */
209 struct mlxsw_sp_port_xstats {
210         u64 ecn;
211         u64 wred_drop[TC_MAX_QUEUE];
212         u64 tail_drop[TC_MAX_QUEUE];
213         u64 backlog[TC_MAX_QUEUE];
214         u64 tx_bytes[IEEE_8021QAZ_MAX_TCS];
215         u64 tx_packets[IEEE_8021QAZ_MAX_TCS];
216 };
217
218 struct mlxsw_sp_port {
219         struct net_device *dev;
220         struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
221         struct mlxsw_sp *mlxsw_sp;
222         u8 local_port;
223         u8 lagged:1,
224            split:1;
225         u16 pvid;
226         u16 lag_id;
227         struct {
228                 u8 tx_pause:1,
229                    rx_pause:1,
230                    autoneg:1;
231         } link;
232         struct {
233                 struct ieee_ets *ets;
234                 struct ieee_maxrate *maxrate;
235                 struct ieee_pfc *pfc;
236         } dcb;
237         struct {
238                 u8 module;
239                 u8 width;
240                 u8 lane;
241         } mapping;
242         /* TC handles */
243         struct list_head mall_tc_list;
244         struct {
245                 #define MLXSW_HW_STATS_UPDATE_TIME HZ
246                 struct rtnl_link_stats64 stats;
247                 struct mlxsw_sp_port_xstats xstats;
248                 struct delayed_work update_dw;
249         } periodic_hw_stats;
250         struct mlxsw_sp_port_sample *sample;
251         struct list_head vlans_list;
252         struct mlxsw_sp_qdisc *root_qdisc;
253         struct mlxsw_sp_qdisc *tclass_qdiscs;
254         unsigned acl_rule_count;
255         struct mlxsw_sp_acl_block *ing_acl_block;
256         struct mlxsw_sp_acl_block *eg_acl_block;
257 };
258
259 static inline bool
260 mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
261 {
262         return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
263 }
264
265 static inline struct mlxsw_sp_port *
266 mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
267 {
268         struct mlxsw_sp_port *mlxsw_sp_port;
269         u8 local_port;
270
271         local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
272                                                 lag_id, port_index);
273         mlxsw_sp_port = mlxsw_sp->ports[local_port];
274         return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
275 }
276
277 static inline struct mlxsw_sp_port_vlan *
278 mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
279                                u16 vid)
280 {
281         struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
282
283         list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
284                             list) {
285                 if (mlxsw_sp_port_vlan->vid == vid)
286                         return mlxsw_sp_port_vlan;
287         }
288
289         return NULL;
290 }
291
292 enum mlxsw_sp_flood_type {
293         MLXSW_SP_FLOOD_TYPE_UC,
294         MLXSW_SP_FLOOD_TYPE_BC,
295         MLXSW_SP_FLOOD_TYPE_MC,
296 };
297
298 /* spectrum_buffers.c */
299 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
300 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
301 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
302 int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
303                          unsigned int sb_index, u16 pool_index,
304                          struct devlink_sb_pool_info *pool_info);
305 int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
306                          unsigned int sb_index, u16 pool_index, u32 size,
307                          enum devlink_sb_threshold_type threshold_type);
308 int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
309                               unsigned int sb_index, u16 pool_index,
310                               u32 *p_threshold);
311 int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
312                               unsigned int sb_index, u16 pool_index,
313                               u32 threshold);
314 int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
315                                  unsigned int sb_index, u16 tc_index,
316                                  enum devlink_sb_pool_type pool_type,
317                                  u16 *p_pool_index, u32 *p_threshold);
318 int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
319                                  unsigned int sb_index, u16 tc_index,
320                                  enum devlink_sb_pool_type pool_type,
321                                  u16 pool_index, u32 threshold);
322 int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
323                              unsigned int sb_index);
324 int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
325                               unsigned int sb_index);
326 int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
327                                   unsigned int sb_index, u16 pool_index,
328                                   u32 *p_cur, u32 *p_max);
329 int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
330                                      unsigned int sb_index, u16 tc_index,
331                                      enum devlink_sb_pool_type pool_type,
332                                      u32 *p_cur, u32 *p_max);
333 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
334 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
335
336 /* spectrum_switchdev.c */
337 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
338 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
339 void mlxsw_sp_port_switchdev_init(struct mlxsw_sp_port *mlxsw_sp_port);
340 void mlxsw_sp_port_switchdev_fini(struct mlxsw_sp_port *mlxsw_sp_port);
341 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
342                         bool adding);
343 void
344 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
345 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
346                               struct net_device *brport_dev,
347                               struct net_device *br_dev,
348                               struct netlink_ext_ack *extack);
349 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
350                                 struct net_device *brport_dev,
351                                 struct net_device *br_dev);
352 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
353                                          const struct net_device *br_dev);
354
355 /* spectrum.c */
356 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
357                           enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
358                           bool dwrr, u8 dwrr_weight);
359 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
360                               u8 switch_prio, u8 tclass);
361 int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
362                                  u8 *prio_tc, bool pause_en,
363                                  struct ieee_pfc *my_pfc);
364 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
365                                   enum mlxsw_reg_qeec_hr hr, u8 index,
366                                   u8 next_index, u32 maxrate);
367 enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state);
368 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
369                               u8 state);
370 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
371 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
372                                    bool learn_enable);
373 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
374 struct mlxsw_sp_port_vlan *
375 mlxsw_sp_port_vlan_get(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
376 void mlxsw_sp_port_vlan_put(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
377 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
378                            u16 vid_end, bool is_member, bool untagged);
379 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
380                               unsigned int counter_index, u64 *packets,
381                               u64 *bytes);
382 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
383                                 unsigned int *p_counter_index);
384 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
385                                 unsigned int counter_index);
386 bool mlxsw_sp_port_dev_check(const struct net_device *dev);
387 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
388 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
389 struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
390 void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
391 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
392
393 /* spectrum_dcb.c */
394 #ifdef CONFIG_MLXSW_SPECTRUM_DCB
395 int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
396 void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
397 #else
398 static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
399 {
400         return 0;
401 }
402 static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
403 {}
404 #endif
405
406 /* spectrum_router.c */
407 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp);
408 void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
409 int mlxsw_sp_netdevice_router_port_event(struct net_device *dev);
410 int mlxsw_sp_inetaddr_event(struct notifier_block *unused,
411                             unsigned long event, void *ptr);
412 int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
413                                   unsigned long event, void *ptr);
414 int mlxsw_sp_inet6addr_event(struct notifier_block *unused,
415                              unsigned long event, void *ptr);
416 int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
417                                    unsigned long event, void *ptr);
418 int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
419                                  struct netdev_notifier_changeupper_info *info);
420 bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp,
421                                 const struct net_device *dev);
422 bool mlxsw_sp_netdev_is_ipip_ul(const struct mlxsw_sp *mlxsw_sp,
423                                 const struct net_device *dev);
424 int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,
425                                      struct net_device *l3_dev,
426                                      unsigned long event,
427                                      struct netdev_notifier_info *info);
428 int
429 mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
430                                  struct net_device *l3_dev,
431                                  unsigned long event,
432                                  struct netdev_notifier_info *info);
433 void
434 mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
435 void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif);
436
437 /* spectrum_kvdl.c */
438 int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
439 void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
440 int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, unsigned int entry_count,
441                         u32 *p_entry_index);
442 void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp, int entry_index);
443 int mlxsw_sp_kvdl_alloc_size_query(struct mlxsw_sp *mlxsw_sp,
444                                    unsigned int entry_count,
445                                    unsigned int *p_alloc_size);
446 int mlxsw_sp_kvdl_resources_register(struct mlxsw_core *mlxsw_core);
447
448 struct mlxsw_sp_acl_rule_info {
449         unsigned int priority;
450         struct mlxsw_afk_element_values values;
451         struct mlxsw_afa_block *act_block;
452         unsigned int counter_index;
453 };
454
455 enum mlxsw_sp_acl_profile {
456         MLXSW_SP_ACL_PROFILE_FLOWER,
457 };
458
459 struct mlxsw_sp_acl_profile_ops {
460         size_t ruleset_priv_size;
461         int (*ruleset_add)(struct mlxsw_sp *mlxsw_sp,
462                            void *priv, void *ruleset_priv);
463         void (*ruleset_del)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv);
464         int (*ruleset_bind)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv,
465                             struct mlxsw_sp_port *mlxsw_sp_port,
466                             bool ingress);
467         void (*ruleset_unbind)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv,
468                                struct mlxsw_sp_port *mlxsw_sp_port,
469                                bool ingress);
470         u16 (*ruleset_group_id)(void *ruleset_priv);
471         size_t rule_priv_size;
472         int (*rule_add)(struct mlxsw_sp *mlxsw_sp,
473                         void *ruleset_priv, void *rule_priv,
474                         struct mlxsw_sp_acl_rule_info *rulei);
475         void (*rule_del)(struct mlxsw_sp *mlxsw_sp, void *rule_priv);
476         int (*rule_activity_get)(struct mlxsw_sp *mlxsw_sp, void *rule_priv,
477                                  bool *activity);
478 };
479
480 struct mlxsw_sp_acl_ops {
481         size_t priv_size;
482         int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
483         void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
484         const struct mlxsw_sp_acl_profile_ops *
485                         (*profile_ops)(struct mlxsw_sp *mlxsw_sp,
486                                        enum mlxsw_sp_acl_profile profile);
487 };
488
489 struct mlxsw_sp_acl_block;
490 struct mlxsw_sp_acl_ruleset;
491
492 /* spectrum_acl.c */
493 struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
494 struct mlxsw_sp *mlxsw_sp_acl_block_mlxsw_sp(struct mlxsw_sp_acl_block *block);
495 unsigned int mlxsw_sp_acl_block_rule_count(struct mlxsw_sp_acl_block *block);
496 void mlxsw_sp_acl_block_disable_inc(struct mlxsw_sp_acl_block *block);
497 void mlxsw_sp_acl_block_disable_dec(struct mlxsw_sp_acl_block *block);
498 bool mlxsw_sp_acl_block_disabled(struct mlxsw_sp_acl_block *block);
499 struct mlxsw_sp_acl_block *mlxsw_sp_acl_block_create(struct mlxsw_sp *mlxsw_sp,
500                                                      struct net *net);
501 void mlxsw_sp_acl_block_destroy(struct mlxsw_sp_acl_block *block);
502 int mlxsw_sp_acl_block_bind(struct mlxsw_sp *mlxsw_sp,
503                             struct mlxsw_sp_acl_block *block,
504                             struct mlxsw_sp_port *mlxsw_sp_port,
505                             bool ingress);
506 int mlxsw_sp_acl_block_unbind(struct mlxsw_sp *mlxsw_sp,
507                               struct mlxsw_sp_acl_block *block,
508                               struct mlxsw_sp_port *mlxsw_sp_port,
509                               bool ingress);
510 struct mlxsw_sp_acl_ruleset *
511 mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
512                             struct mlxsw_sp_acl_block *block, u32 chain_index,
513                             enum mlxsw_sp_acl_profile profile);
514 struct mlxsw_sp_acl_ruleset *
515 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
516                          struct mlxsw_sp_acl_block *block, u32 chain_index,
517                          enum mlxsw_sp_acl_profile profile);
518 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
519                               struct mlxsw_sp_acl_ruleset *ruleset);
520 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
521
522 struct mlxsw_sp_acl_rule_info *
523 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl);
524 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
525 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
526 void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
527                                  unsigned int priority);
528 void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
529                                     enum mlxsw_afk_element element,
530                                     u32 key_value, u32 mask_value);
531 void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
532                                     enum mlxsw_afk_element element,
533                                     const char *key_value,
534                                     const char *mask_value, unsigned int len);
535 int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
536 int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
537                                 u16 group_id);
538 int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
539 int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei);
540 int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
541 int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
542                                   struct mlxsw_sp_acl_rule_info *rulei,
543                                   struct mlxsw_sp_acl_block *block,
544                                   struct net_device *out_dev);
545 int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
546                                struct mlxsw_sp_acl_rule_info *rulei,
547                                struct net_device *out_dev);
548 int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
549                                 struct mlxsw_sp_acl_rule_info *rulei,
550                                 u32 action, u16 vid, u16 proto, u8 prio);
551 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
552                                  struct mlxsw_sp_acl_rule_info *rulei);
553 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
554                                    struct mlxsw_sp_acl_rule_info *rulei,
555                                    u16 fid);
556
557 struct mlxsw_sp_acl_rule;
558
559 struct mlxsw_sp_acl_rule *
560 mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
561                          struct mlxsw_sp_acl_ruleset *ruleset,
562                          unsigned long cookie);
563 void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
564                                struct mlxsw_sp_acl_rule *rule);
565 int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
566                           struct mlxsw_sp_acl_rule *rule);
567 void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
568                            struct mlxsw_sp_acl_rule *rule);
569 struct mlxsw_sp_acl_rule *
570 mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
571                          struct mlxsw_sp_acl_ruleset *ruleset,
572                          unsigned long cookie);
573 struct mlxsw_sp_acl_rule_info *
574 mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
575 int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
576                                 struct mlxsw_sp_acl_rule *rule,
577                                 u64 *packets, u64 *bytes, u64 *last_use);
578
579 struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
580
581 int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
582 void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
583
584 /* spectrum_acl_tcam.c */
585 extern const struct mlxsw_sp_acl_ops mlxsw_sp_acl_tcam_ops;
586
587 /* spectrum_flower.c */
588 int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
589                             struct mlxsw_sp_acl_block *block,
590                             struct tc_cls_flower_offload *f);
591 void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
592                              struct mlxsw_sp_acl_block *block,
593                              struct tc_cls_flower_offload *f);
594 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
595                           struct mlxsw_sp_acl_block *block,
596                           struct tc_cls_flower_offload *f);
597
598 /* spectrum_qdisc.c */
599 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
600 void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
601 int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
602                           struct tc_red_qopt_offload *p);
603 int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
604                            struct tc_prio_qopt_offload *p);
605
606 /* spectrum_fid.c */
607 int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
608                            enum mlxsw_sp_flood_type packet_type, u8 local_port,
609                            bool member);
610 int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
611                               struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
612 void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
613                                  struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
614 enum mlxsw_sp_rif_type mlxsw_sp_fid_rif_type(const struct mlxsw_sp_fid *fid);
615 u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
616 enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
617 void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
618 enum mlxsw_sp_rif_type
619 mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
620                            enum mlxsw_sp_fid_type type);
621 u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
622 struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
623 struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
624                                             int br_ifindex);
625 struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
626                                            u16 rif_index);
627 struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
628 void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
629 int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
630 void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
631 int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
632 void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
633
634 #endif