blob: 99760fd55ba192d8263a18f7edee410c851b92cc [file] [log] [blame]
Jiri Pirko56ade8f2015-10-16 14:01:37 +02001/*
2 * drivers/net/ethernet/mellanox/mlxsw/spectrum.h
Jiri Pirko22a67762017-02-03 10:29:07 +01003 * Copyright (c) 2015-2017 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2015-2017 Jiri Pirko <jiri@mellanox.com>
Jiri Pirko56ade8f2015-10-16 14:01:37 +02005 * 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>
Jiri Pirko6cf3c972016-07-05 11:27:39 +020042#include <linux/rhashtable.h>
Jiri Pirko56ade8f2015-10-16 14:01:37 +020043#include <linux/bitops.h>
44#include <linux/if_vlan.h>
Ido Schimmel7f71eb42015-12-15 16:03:37 +010045#include <linux/list.h>
Ido Schimmel8e8dfe92016-04-06 17:10:10 +020046#include <linux/dcbnl.h>
Jiri Pirko5e9c16c2016-07-04 08:23:04 +020047#include <linux/in6.h>
Jiri Pirkob45f64d2016-09-26 12:52:31 +020048#include <linux/notifier.h>
Yotam Gigi98d0f7b2017-01-23 11:07:11 +010049#include <net/psample.h>
Jiri Pirko7aa0f5a2017-02-03 10:29:09 +010050#include <net/pkt_cls.h>
Jiri Pirko56ade8f2015-10-16 14:01:37 +020051
Elad Raz3a49b4f2016-01-10 21:06:28 +010052#include "port.h"
Jiri Pirko56ade8f2015-10-16 14:01:37 +020053#include "core.h"
Jiri Pirko22a67762017-02-03 10:29:07 +010054#include "core_acl_flex_keys.h"
55#include "core_acl_flex_actions.h"
Jiri Pirko56ade8f2015-10-16 14:01:37 +020056
Ido Schimmela1107482017-05-26 08:37:39 +020057#define MLXSW_SP_FID_8021D_MAX 1024
Ido Schimmel7f71eb42015-12-15 16:03:37 +010058
Elad Raz53ae6282016-01-10 21:06:26 +010059#define MLXSW_SP_MID_MAX 7000
60
Ido Schimmel18f1e702016-02-26 17:32:31 +010061#define MLXSW_SP_PORTS_PER_CLUSTER_MAX 4
62
63#define MLXSW_SP_PORT_BASE_SPEED 25000 /* Mb/s */
64
Jiri Pirkoc6022422016-07-05 11:27:46 +020065#define MLXSW_SP_KVD_LINEAR_SIZE 65536 /* entries */
Nogah Frankel403547d2016-09-20 11:16:52 +020066#define MLXSW_SP_KVD_GRANULARITY 128
Jiri Pirkoc6022422016-07-05 11:27:46 +020067
Jiri Pirko56ade8f2015-10-16 14:01:37 +020068struct mlxsw_sp_port;
Ido Schimmel4724ba562017-03-10 08:53:39 +010069struct mlxsw_sp_rif;
Jiri Pirko56ade8f2015-10-16 14:01:37 +020070
Jiri Pirko0d65fc12015-12-03 12:12:28 +010071struct mlxsw_sp_upper {
72 struct net_device *dev;
73 unsigned int ref_count;
74};
75
Ido Schimmela1107482017-05-26 08:37:39 +020076enum mlxsw_sp_rif_type {
77 MLXSW_SP_RIF_TYPE_SUBPORT,
78 MLXSW_SP_RIF_TYPE_VLAN,
79 MLXSW_SP_RIF_TYPE_FID,
80 MLXSW_SP_RIF_TYPE_MAX,
81};
82
83enum mlxsw_sp_fid_type {
84 MLXSW_SP_FID_TYPE_8021Q,
85 MLXSW_SP_FID_TYPE_8021D,
86 MLXSW_SP_FID_TYPE_RFID,
87 MLXSW_SP_FID_TYPE_DUMMY,
88 MLXSW_SP_FID_TYPE_MAX,
Ido Schimmel7f71eb42015-12-15 16:03:37 +010089};
90
Elad Raz3a49b4f2016-01-10 21:06:28 +010091struct mlxsw_sp_mid {
92 struct list_head list;
93 unsigned char addr[ETH_ALEN];
Ido Schimmel46d08472016-10-30 10:09:22 +010094 u16 fid;
Elad Raz3a49b4f2016-01-10 21:06:28 +010095 u16 mid;
96 unsigned int ref_count;
97};
98
Yotam Gigi763b4b72016-07-21 12:03:17 +020099enum mlxsw_sp_span_type {
100 MLXSW_SP_SPAN_EGRESS,
101 MLXSW_SP_SPAN_INGRESS
102};
103
104struct mlxsw_sp_span_inspected_port {
105 struct list_head list;
106 enum mlxsw_sp_span_type type;
107 u8 local_port;
108};
109
110struct mlxsw_sp_span_entry {
111 u8 local_port;
112 bool used;
113 struct list_head bound_ports_list;
114 int ref_count;
115 int id;
116};
117
118enum mlxsw_sp_port_mall_action_type {
119 MLXSW_SP_PORT_MALL_MIRROR,
Yotam Gigi98d0f7b2017-01-23 11:07:11 +0100120 MLXSW_SP_PORT_MALL_SAMPLE,
Yotam Gigi763b4b72016-07-21 12:03:17 +0200121};
122
123struct mlxsw_sp_port_mall_mirror_tc_entry {
124 u8 to_local_port;
125 bool ingress;
126};
127
128struct mlxsw_sp_port_mall_tc_entry {
129 struct list_head list;
130 unsigned long cookie;
131 enum mlxsw_sp_port_mall_action_type type;
132 union {
133 struct mlxsw_sp_port_mall_mirror_tc_entry mirror;
134 };
135};
136
Ido Schimmel33cbd872017-05-16 19:38:24 +0200137struct mlxsw_sp_sb;
Ido Schimmel5f6935c2017-05-16 19:38:26 +0200138struct mlxsw_sp_bridge;
Ido Schimmel9011b672017-05-16 19:38:25 +0200139struct mlxsw_sp_router;
Jiri Pirko22a67762017-02-03 10:29:07 +0100140struct mlxsw_sp_acl;
Arkadi Sharshevskyff7b0d22017-03-11 09:42:51 +0100141struct mlxsw_sp_counter_pool;
Ido Schimmela1107482017-05-26 08:37:39 +0200142struct mlxsw_sp_fid_core;
Jiri Pirko22a67762017-02-03 10:29:07 +0100143
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200144struct mlxsw_sp {
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200145 struct mlxsw_sp_port **ports;
146 struct mlxsw_core *core;
147 const struct mlxsw_bus_info *bus_info;
148 unsigned char base_mac[ETH_ALEN];
Nogah Frankelce0bd2b2016-09-20 11:16:50 +0200149 struct mlxsw_sp_upper *lags;
Ido Schimmel5ec2ee72017-03-24 08:02:48 +0100150 u8 *port_to_module;
Ido Schimmel33cbd872017-05-16 19:38:24 +0200151 struct mlxsw_sp_sb *sb;
Ido Schimmel5f6935c2017-05-16 19:38:26 +0200152 struct mlxsw_sp_bridge *bridge;
Ido Schimmel9011b672017-05-16 19:38:25 +0200153 struct mlxsw_sp_router *router;
Jiri Pirko22a67762017-02-03 10:29:07 +0100154 struct mlxsw_sp_acl *acl;
Ido Schimmela1107482017-05-26 08:37:39 +0200155 struct mlxsw_sp_fid_core *fid_core;
Jiri Pirkob090ef02016-07-05 11:27:47 +0200156 struct {
157 DECLARE_BITMAP(usage, MLXSW_SP_KVD_LINEAR_SIZE);
158 } kvdl;
Yotam Gigi763b4b72016-07-21 12:03:17 +0200159
Arkadi Sharshevskyff7b0d22017-03-11 09:42:51 +0100160 struct mlxsw_sp_counter_pool *counter_pool;
Yotam Gigi763b4b72016-07-21 12:03:17 +0200161 struct {
162 struct mlxsw_sp_span_entry *entries;
163 int entries_count;
164 } span;
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200165};
166
Jiri Pirko0d65fc12015-12-03 12:12:28 +0100167static inline struct mlxsw_sp_upper *
168mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
169{
170 return &mlxsw_sp->lags[lag_id];
171}
172
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200173struct mlxsw_sp_port_pcpu_stats {
174 u64 rx_packets;
175 u64 rx_bytes;
176 u64 tx_packets;
177 u64 tx_bytes;
178 struct u64_stats_sync syncp;
179 u32 tx_dropped;
180};
181
Yotam Gigi98d0f7b2017-01-23 11:07:11 +0100182struct mlxsw_sp_port_sample {
183 struct psample_group __rcu *psample_group;
184 u32 trunc_size;
185 u32 rate;
186 bool truncate;
187};
188
Ido Schimmelc57529e2017-05-26 08:37:31 +0200189struct mlxsw_sp_bridge_port;
Ido Schimmela1107482017-05-26 08:37:39 +0200190struct mlxsw_sp_fid;
Ido Schimmelc57529e2017-05-26 08:37:31 +0200191
Ido Schimmel31a08a52017-05-26 08:37:26 +0200192struct mlxsw_sp_port_vlan {
193 struct list_head list;
194 struct mlxsw_sp_port *mlxsw_sp_port;
195 struct mlxsw_sp_fid *fid;
196 u16 vid;
Ido Schimmelc57529e2017-05-26 08:37:31 +0200197 struct mlxsw_sp_bridge_port *bridge_port;
198 struct list_head bridge_vlan_node;
Ido Schimmel31a08a52017-05-26 08:37:26 +0200199};
200
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200201struct mlxsw_sp_port {
202 struct net_device *dev;
203 struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
204 struct mlxsw_sp *mlxsw_sp;
205 u8 local_port;
Ido Schimmelc57529e2017-05-26 08:37:31 +0200206 u8 lagged:1,
Ido Schimmel18f1e702016-02-26 17:32:31 +0100207 split:1;
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200208 u16 pvid;
Jiri Pirko0d65fc12015-12-03 12:12:28 +0100209 u16 lag_id;
Ido Schimmel7f71eb42015-12-15 16:03:37 +0100210 struct {
Ido Schimmel9f7ec052016-04-06 17:10:14 +0200211 u8 tx_pause:1,
Ido Schimmel0c83f882016-09-12 13:26:23 +0200212 rx_pause:1,
213 autoneg:1;
Ido Schimmel9f7ec052016-04-06 17:10:14 +0200214 } link;
215 struct {
Ido Schimmel8e8dfe92016-04-06 17:10:10 +0200216 struct ieee_ets *ets;
Ido Schimmelcc7cf512016-04-06 17:10:11 +0200217 struct ieee_maxrate *maxrate;
Ido Schimmeld81a6bd2016-04-06 17:10:16 +0200218 struct ieee_pfc *pfc;
Ido Schimmel8e8dfe92016-04-06 17:10:10 +0200219 } dcb;
Ido Schimmeld664b412016-06-09 09:51:40 +0200220 struct {
221 u8 module;
222 u8 width;
223 u8 lane;
224 } mapping;
Yotam Gigi763b4b72016-07-21 12:03:17 +0200225 /* TC handles */
226 struct list_head mall_tc_list;
Nogah Frankelfc1bbb02016-09-16 15:05:38 +0200227 struct {
228 #define MLXSW_HW_STATS_UPDATE_TIME HZ
229 struct rtnl_link_stats64 *cache;
230 struct delayed_work update_dw;
231 } hw_stats;
Yotam Gigi98d0f7b2017-01-23 11:07:11 +0100232 struct mlxsw_sp_port_sample *sample;
Ido Schimmel31a08a52017-05-26 08:37:26 +0200233 struct list_head vlans_list;
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200234};
235
Ido Schimmel9f7ec052016-04-06 17:10:14 +0200236static inline bool
237mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
238{
239 return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
240}
241
Jiri Pirko0d65fc12015-12-03 12:12:28 +0100242static inline struct mlxsw_sp_port *
243mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
244{
245 struct mlxsw_sp_port *mlxsw_sp_port;
246 u8 local_port;
247
248 local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
249 lag_id, port_index);
250 mlxsw_sp_port = mlxsw_sp->ports[local_port];
251 return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
252}
253
Ido Schimmel31a08a52017-05-26 08:37:26 +0200254static inline struct mlxsw_sp_port_vlan *
255mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
256 u16 vid)
257{
258 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
259
260 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
261 list) {
262 if (mlxsw_sp_port_vlan->vid == vid)
263 return mlxsw_sp_port_vlan;
264 }
265
266 return NULL;
267}
268
Ido Schimmela1107482017-05-26 08:37:39 +0200269enum mlxsw_sp_flood_type {
270 MLXSW_SP_FLOOD_TYPE_UC,
271 MLXSW_SP_FLOOD_TYPE_BC,
272 MLXSW_SP_FLOOD_TYPE_MC,
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200273};
274
Ido Schimmelcb4cc0e2017-06-04 16:53:38 +0200275/* spectrum_buffers.c */
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200276int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
Jiri Pirko0f433fa2016-04-14 18:19:24 +0200277void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200278int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
Jiri Pirko0f433fa2016-04-14 18:19:24 +0200279int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
280 unsigned int sb_index, u16 pool_index,
281 struct devlink_sb_pool_info *pool_info);
282int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
283 unsigned int sb_index, u16 pool_index, u32 size,
284 enum devlink_sb_threshold_type threshold_type);
285int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
286 unsigned int sb_index, u16 pool_index,
287 u32 *p_threshold);
288int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
289 unsigned int sb_index, u16 pool_index,
290 u32 threshold);
291int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
292 unsigned int sb_index, u16 tc_index,
293 enum devlink_sb_pool_type pool_type,
294 u16 *p_pool_index, u32 *p_threshold);
295int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
296 unsigned int sb_index, u16 tc_index,
297 enum devlink_sb_pool_type pool_type,
298 u16 pool_index, u32 threshold);
Jiri Pirko2d0ed392016-04-14 18:19:30 +0200299int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
300 unsigned int sb_index);
301int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
302 unsigned int sb_index);
303int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
304 unsigned int sb_index, u16 pool_index,
305 u32 *p_cur, u32 *p_max);
306int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
307 unsigned int sb_index, u16 tc_index,
308 enum devlink_sb_pool_type pool_type,
309 u32 *p_cur, u32 *p_max);
Ido Schimmel33cbd872017-05-16 19:38:24 +0200310u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
311u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200312
Ido Schimmelcb4cc0e2017-06-04 16:53:38 +0200313/* spectrum_switchdev.c */
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200314int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
315void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200316void mlxsw_sp_port_switchdev_init(struct mlxsw_sp_port *mlxsw_sp_port);
317void mlxsw_sp_port_switchdev_fini(struct mlxsw_sp_port *mlxsw_sp_port);
Ido Schimmel6e095fd2016-07-04 08:23:13 +0200318int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
319 bool adding);
Ido Schimmelc57529e2017-05-26 08:37:31 +0200320void
321mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
322int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
323 struct net_device *brport_dev,
324 struct net_device *br_dev);
325void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
326 struct net_device *brport_dev,
327 struct net_device *br_dev);
328
Ido Schimmelcb4cc0e2017-06-04 16:53:38 +0200329/* spectrum.c */
Ido Schimmel8e8dfe92016-04-06 17:10:10 +0200330int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
331 enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
332 bool dwrr, u8 dwrr_weight);
333int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
334 u8 switch_prio, u8 tclass);
335int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
Ido Schimmeld81a6bd2016-04-06 17:10:16 +0200336 u8 *prio_tc, bool pause_en,
337 struct ieee_pfc *my_pfc);
Ido Schimmelcc7cf512016-04-06 17:10:11 +0200338int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
339 enum mlxsw_reg_qeec_hr hr, u8 index,
340 u8 next_index, u32 maxrate);
Ido Schimmelfe9ccc72017-05-16 19:38:31 +0200341int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
342 u8 state);
Ido Schimmela1107482017-05-26 08:37:39 +0200343int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
Ido Schimmelfe9ccc72017-05-16 19:38:31 +0200344int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
345 bool learn_enable);
Ido Schimmelb02eae92017-05-16 19:38:34 +0200346int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
Ido Schimmelc57529e2017-05-26 08:37:31 +0200347struct mlxsw_sp_port_vlan *
348mlxsw_sp_port_vlan_get(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
349void mlxsw_sp_port_vlan_put(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
Ido Schimmelcb4cc0e2017-06-04 16:53:38 +0200350int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
351 u16 vid_end, bool is_member, bool untagged);
352int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
353 unsigned int counter_index, u64 *packets,
354 u64 *bytes);
355int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
356 unsigned int *p_counter_index);
357void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
358 unsigned int counter_index);
359bool mlxsw_sp_port_dev_check(const struct net_device *dev);
360struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
361struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
362struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
363void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200364
Ido Schimmelcb4cc0e2017-06-04 16:53:38 +0200365/* spectrum_dcb.c */
Ido Schimmelf00817d2016-04-06 17:10:09 +0200366#ifdef CONFIG_MLXSW_SPECTRUM_DCB
Ido Schimmelf00817d2016-04-06 17:10:09 +0200367int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
368void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
Ido Schimmelf00817d2016-04-06 17:10:09 +0200369#else
Ido Schimmelf00817d2016-04-06 17:10:09 +0200370static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
371{
372 return 0;
373}
Ido Schimmelf00817d2016-04-06 17:10:09 +0200374static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
375{}
Ido Schimmelf00817d2016-04-06 17:10:09 +0200376#endif
377
Ido Schimmelcb4cc0e2017-06-04 16:53:38 +0200378/* spectrum_router.c */
Ido Schimmel464dce12016-07-02 11:00:15 +0200379int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp);
380void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
Jiri Pirkoe7322632016-09-01 10:37:43 +0200381int mlxsw_sp_router_netevent_event(struct notifier_block *unused,
382 unsigned long event, void *ptr);
Ido Schimmel4724ba562017-03-10 08:53:39 +0100383int mlxsw_sp_netdevice_router_port_event(struct net_device *dev);
384int mlxsw_sp_inetaddr_event(struct notifier_block *unused,
385 unsigned long event, void *ptr);
Ido Schimmelb1e45522017-04-30 19:47:14 +0300386int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
387 struct netdev_notifier_changeupper_info *info);
Ido Schimmela1107482017-05-26 08:37:39 +0200388void
389mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
Ido Schimmele4f3c1c2017-05-26 08:37:40 +0200390void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif);
Ido Schimmel464dce12016-07-02 11:00:15 +0200391
Ido Schimmelcb4cc0e2017-06-04 16:53:38 +0200392/* spectrum_kvdl.c */
Arkadi Sharshevsky13124442017-03-25 08:28:22 +0100393int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, unsigned int entry_count,
394 u32 *p_entry_index);
Jiri Pirkob090ef02016-07-05 11:27:47 +0200395void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp, int entry_index);
396
Jiri Pirko22a67762017-02-03 10:29:07 +0100397struct mlxsw_sp_acl_rule_info {
398 unsigned int priority;
399 struct mlxsw_afk_element_values values;
400 struct mlxsw_afa_block *act_block;
Arkadi Sharshevsky48170722017-03-11 09:42:58 +0100401 unsigned int counter_index;
402 bool counter_valid;
Jiri Pirko22a67762017-02-03 10:29:07 +0100403};
404
405enum mlxsw_sp_acl_profile {
406 MLXSW_SP_ACL_PROFILE_FLOWER,
407};
408
409struct mlxsw_sp_acl_profile_ops {
410 size_t ruleset_priv_size;
411 int (*ruleset_add)(struct mlxsw_sp *mlxsw_sp,
412 void *priv, void *ruleset_priv);
413 void (*ruleset_del)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv);
414 int (*ruleset_bind)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv,
415 struct net_device *dev, bool ingress);
416 void (*ruleset_unbind)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv);
417 size_t rule_priv_size;
418 int (*rule_add)(struct mlxsw_sp *mlxsw_sp,
419 void *ruleset_priv, void *rule_priv,
420 struct mlxsw_sp_acl_rule_info *rulei);
421 void (*rule_del)(struct mlxsw_sp *mlxsw_sp, void *rule_priv);
Arkadi Sharshevsky7fd056c2017-03-11 09:42:54 +0100422 int (*rule_activity_get)(struct mlxsw_sp *mlxsw_sp, void *rule_priv,
423 bool *activity);
Jiri Pirko22a67762017-02-03 10:29:07 +0100424};
425
426struct mlxsw_sp_acl_ops {
427 size_t priv_size;
428 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
429 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
430 const struct mlxsw_sp_acl_profile_ops *
431 (*profile_ops)(struct mlxsw_sp *mlxsw_sp,
432 enum mlxsw_sp_acl_profile profile);
433};
434
435struct mlxsw_sp_acl_ruleset;
436
Ido Schimmelcb4cc0e2017-06-04 16:53:38 +0200437/* spectrum_acl.c */
438struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
Jiri Pirko22a67762017-02-03 10:29:07 +0100439struct mlxsw_sp_acl_ruleset *
440mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
441 struct net_device *dev, bool ingress,
442 enum mlxsw_sp_acl_profile profile);
443void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
444 struct mlxsw_sp_acl_ruleset *ruleset);
445
446struct mlxsw_sp_acl_rule_info *
447mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl);
448void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
449int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
450void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
451 unsigned int priority);
452void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
453 enum mlxsw_afk_element element,
454 u32 key_value, u32 mask_value);
455void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
456 enum mlxsw_afk_element element,
457 const char *key_value,
458 const char *mask_value, unsigned int len);
459void mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
460void mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
461 u16 group_id);
462int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei);
463int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
464 struct mlxsw_sp_acl_rule_info *rulei,
465 struct net_device *out_dev);
Petr Machataa1502012017-03-09 09:25:19 +0100466int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
467 struct mlxsw_sp_acl_rule_info *rulei,
468 u32 action, u16 vid, u16 proto, u8 prio);
Arkadi Sharshevsky48170722017-03-11 09:42:58 +0100469int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
470 struct mlxsw_sp_acl_rule_info *rulei);
Jiri Pirkoac44dd42017-04-18 16:55:32 +0200471int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
472 struct mlxsw_sp_acl_rule_info *rulei,
473 u16 fid);
Jiri Pirko22a67762017-02-03 10:29:07 +0100474
475struct mlxsw_sp_acl_rule;
476
477struct mlxsw_sp_acl_rule *
478mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
479 struct mlxsw_sp_acl_ruleset *ruleset,
480 unsigned long cookie);
481void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
482 struct mlxsw_sp_acl_rule *rule);
483int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
484 struct mlxsw_sp_acl_rule *rule);
485void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
486 struct mlxsw_sp_acl_rule *rule);
487struct mlxsw_sp_acl_rule *
488mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
489 struct mlxsw_sp_acl_ruleset *ruleset,
490 unsigned long cookie);
491struct mlxsw_sp_acl_rule_info *
492mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
Arkadi Sharshevsky48170722017-03-11 09:42:58 +0100493int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
494 struct mlxsw_sp_acl_rule *rule,
495 u64 *packets, u64 *bytes, u64 *last_use);
Jiri Pirko22a67762017-02-03 10:29:07 +0100496
Ido Schimmela1107482017-05-26 08:37:39 +0200497struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
498
Jiri Pirko22a67762017-02-03 10:29:07 +0100499int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
500void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
501
Ido Schimmelcb4cc0e2017-06-04 16:53:38 +0200502/* spectrum_acl_tcam.c */
Jiri Pirko22a67762017-02-03 10:29:07 +0100503extern const struct mlxsw_sp_acl_ops mlxsw_sp_acl_tcam_ops;
504
Ido Schimmelcb4cc0e2017-06-04 16:53:38 +0200505/* spectrum_flower.c */
Jiri Pirko7aa0f5a2017-02-03 10:29:09 +0100506int mlxsw_sp_flower_replace(struct mlxsw_sp_port *mlxsw_sp_port, bool ingress,
507 __be16 protocol, struct tc_cls_flower_offload *f);
508void mlxsw_sp_flower_destroy(struct mlxsw_sp_port *mlxsw_sp_port, bool ingress,
509 struct tc_cls_flower_offload *f);
Arkadi Sharshevsky7c1b8eb2017-03-11 09:42:59 +0100510int mlxsw_sp_flower_stats(struct mlxsw_sp_port *mlxsw_sp_port, bool ingress,
511 struct tc_cls_flower_offload *f);
Jiri Pirko7aa0f5a2017-02-03 10:29:09 +0100512
Ido Schimmelcb4cc0e2017-06-04 16:53:38 +0200513/* spectrum_fid.c */
Ido Schimmela1107482017-05-26 08:37:39 +0200514int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
515 enum mlxsw_sp_flood_type packet_type, u8 local_port,
516 bool member);
517int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
518 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
519void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
520 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
521enum mlxsw_sp_rif_type mlxsw_sp_fid_rif_type(const struct mlxsw_sp_fid *fid);
522u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
523enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
524void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
Ido Schimmele4f3c1c2017-05-26 08:37:40 +0200525enum mlxsw_sp_rif_type
526mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
527 enum mlxsw_sp_fid_type type);
528u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
Ido Schimmela1107482017-05-26 08:37:39 +0200529struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
530struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
531 int br_ifindex);
532struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
533 u16 rif_index);
534struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
535void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
536int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
537void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
538int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
539void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
540
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200541#endif