]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/net/ethernet/mellanox/mlxsw/core.h
mlxsw: reg: Extend SBPM register for occupancy control
[mirror_ubuntu-hirsute-kernel.git] / drivers / net / ethernet / mellanox / mlxsw / core.h
CommitLineData
93c1edb2
JP
1/*
2 * drivers/net/ethernet/mellanox/mlxsw/core.h
3 * Copyright (c) 2015 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2015 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_CORE_H
38#define _MLXSW_CORE_H
39
40#include <linux/module.h>
41#include <linux/device.h>
42#include <linux/slab.h>
43#include <linux/gfp.h>
44#include <linux/types.h>
45#include <linux/skbuff.h>
932762b6 46#include <net/devlink.h>
93c1edb2 47
4ec14b76
IS
48#include "trap.h"
49#include "reg.h"
50
93c1edb2
JP
51#include "cmd.h"
52
53#define MLXSW_MODULE_ALIAS_PREFIX "mlxsw-driver-"
54#define MODULE_MLXSW_DRIVER_ALIAS(kind) \
55 MODULE_ALIAS(MLXSW_MODULE_ALIAS_PREFIX kind)
56
31557f0f 57#define MLXSW_DEVICE_KIND_SWITCHX2 "switchx2"
56ade8fe 58#define MLXSW_DEVICE_KIND_SPECTRUM "spectrum"
31557f0f 59
93c1edb2
JP
60struct mlxsw_core;
61struct mlxsw_driver;
62struct mlxsw_bus;
63struct mlxsw_bus_info;
64
b2f10571
JP
65void *mlxsw_core_driver_priv(struct mlxsw_core *mlxsw_core);
66
93c1edb2
JP
67int mlxsw_core_driver_register(struct mlxsw_driver *mlxsw_driver);
68void mlxsw_core_driver_unregister(struct mlxsw_driver *mlxsw_driver);
69
70int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
71 const struct mlxsw_bus *mlxsw_bus,
72 void *bus_priv);
73void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core);
74
75struct mlxsw_tx_info {
76 u8 local_port;
77 bool is_emad;
78};
79
307c2431 80bool mlxsw_core_skb_transmit_busy(struct mlxsw_core *mlxsw_core,
d003462a 81 const struct mlxsw_tx_info *tx_info);
307c2431 82int mlxsw_core_skb_transmit(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
93c1edb2
JP
83 const struct mlxsw_tx_info *tx_info);
84
85struct mlxsw_rx_listener {
86 void (*func)(struct sk_buff *skb, u8 local_port, void *priv);
87 u8 local_port;
88 u16 trap_id;
89};
90
4ec14b76
IS
91struct mlxsw_event_listener {
92 void (*func)(const struct mlxsw_reg_info *reg,
93 char *payload, void *priv);
94 enum mlxsw_event_trap_id trap_id;
95};
96
93c1edb2
JP
97int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core,
98 const struct mlxsw_rx_listener *rxl,
99 void *priv);
100void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core,
101 const struct mlxsw_rx_listener *rxl,
102 void *priv);
103
4ec14b76
IS
104int mlxsw_core_event_listener_register(struct mlxsw_core *mlxsw_core,
105 const struct mlxsw_event_listener *el,
106 void *priv);
107void mlxsw_core_event_listener_unregister(struct mlxsw_core *mlxsw_core,
108 const struct mlxsw_event_listener *el,
109 void *priv);
110
111int mlxsw_reg_query(struct mlxsw_core *mlxsw_core,
112 const struct mlxsw_reg_info *reg, char *payload);
113int mlxsw_reg_write(struct mlxsw_core *mlxsw_core,
114 const struct mlxsw_reg_info *reg, char *payload);
115
93c1edb2 116struct mlxsw_rx_info {
8060646a
JP
117 bool is_lag;
118 union {
119 u16 sys_port;
120 u16 lag_id;
121 } u;
122 u8 lag_port_index;
93c1edb2
JP
123 int trap_id;
124};
125
126void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
127 struct mlxsw_rx_info *rx_info);
128
8060646a
JP
129void mlxsw_core_lag_mapping_set(struct mlxsw_core *mlxsw_core,
130 u16 lag_id, u8 port_index, u8 local_port);
131u8 mlxsw_core_lag_mapping_get(struct mlxsw_core *mlxsw_core,
132 u16 lag_id, u8 port_index);
133void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core,
134 u16 lag_id, u8 local_port);
135
932762b6
JP
136struct mlxsw_core_port {
137 struct devlink_port devlink_port;
138};
139
325f2f19
JP
140static inline void *
141mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port)
142{
143 /* mlxsw_core_port is ensured to always be the first field in driver
144 * port structure.
145 */
146 return mlxsw_core_port;
147}
148
932762b6
JP
149int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core,
150 struct mlxsw_core_port *mlxsw_core_port, u8 local_port,
151 struct net_device *dev, bool split, u32 split_group);
152void mlxsw_core_port_fini(struct mlxsw_core_port *mlxsw_core_port);
153
93c1edb2
JP
154#define MLXSW_CONFIG_PROFILE_SWID_COUNT 8
155
156struct mlxsw_swid_config {
157 u8 used_type:1,
158 used_properties:1;
159 u8 type;
160 u8 properties;
161};
162
163struct mlxsw_config_profile {
164 u16 used_max_vepa_channels:1,
165 used_max_lag:1,
166 used_max_port_per_lag:1,
167 used_max_mid:1,
168 used_max_pgt:1,
169 used_max_system_port:1,
170 used_max_vlan_groups:1,
171 used_max_regions:1,
172 used_flood_tables:1,
173 used_flood_mode:1,
174 used_max_ib_mc:1,
175 used_max_pkey:1,
176 used_ar_sec:1,
177 used_adaptive_routing_group_cap:1;
178 u8 max_vepa_channels;
179 u16 max_lag;
180 u16 max_port_per_lag;
181 u16 max_mid;
182 u16 max_pgt;
183 u16 max_system_port;
184 u16 max_vlan_groups;
185 u16 max_regions;
186 u8 max_flood_tables;
187 u8 max_vid_flood_tables;
188 u8 flood_mode;
12fd35ab
IS
189 u8 max_fid_offset_flood_tables;
190 u16 fid_offset_flood_table_size;
453b6a8d
IS
191 u8 max_fid_flood_tables;
192 u16 fid_flood_table_size;
93c1edb2
JP
193 u16 max_ib_mc;
194 u16 max_pkey;
195 u8 ar_sec;
196 u16 adaptive_routing_group_cap;
197 u8 arn;
198 struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT];
199};
200
201struct mlxsw_driver {
202 struct list_head list;
203 const char *kind;
204 struct module *owner;
205 size_t priv_size;
b2f10571 206 int (*init)(struct mlxsw_core *mlxsw_core,
93c1edb2 207 const struct mlxsw_bus_info *mlxsw_bus_info);
b2f10571
JP
208 void (*fini)(struct mlxsw_core *mlxsw_core);
209 int (*port_split)(struct mlxsw_core *mlxsw_core, u8 local_port,
210 unsigned int count);
211 int (*port_unsplit)(struct mlxsw_core *mlxsw_core, u8 local_port);
a6179bf0
JP
212 int (*sb_pool_get)(struct mlxsw_core *mlxsw_core,
213 unsigned int sb_index, u16 pool_index,
214 struct devlink_sb_pool_info *pool_info);
215 int (*sb_pool_set)(struct mlxsw_core *mlxsw_core,
216 unsigned int sb_index, u16 pool_index, u32 size,
217 enum devlink_sb_threshold_type threshold_type);
218 int (*sb_port_pool_get)(struct mlxsw_core_port *mlxsw_core_port,
219 unsigned int sb_index, u16 pool_index,
220 u32 *p_threshold);
221 int (*sb_port_pool_set)(struct mlxsw_core_port *mlxsw_core_port,
222 unsigned int sb_index, u16 pool_index,
223 u32 threshold);
224 int (*sb_tc_pool_bind_get)(struct mlxsw_core_port *mlxsw_core_port,
225 unsigned int sb_index, u16 tc_index,
226 enum devlink_sb_pool_type pool_type,
227 u16 *p_pool_index, u32 *p_threshold);
228 int (*sb_tc_pool_bind_set)(struct mlxsw_core_port *mlxsw_core_port,
229 unsigned int sb_index, u16 tc_index,
230 enum devlink_sb_pool_type pool_type,
231 u16 pool_index, u32 threshold);
1ceecc88
JP
232 int (*sb_occ_snapshot)(struct mlxsw_core *mlxsw_core,
233 unsigned int sb_index);
234 int (*sb_occ_max_clear)(struct mlxsw_core *mlxsw_core,
235 unsigned int sb_index);
236 int (*sb_occ_port_pool_get)(struct mlxsw_core_port *mlxsw_core_port,
237 unsigned int sb_index, u16 pool_index,
238 u32 *p_cur, u32 *p_max);
239 int (*sb_occ_tc_port_bind_get)(struct mlxsw_core_port *mlxsw_core_port,
240 unsigned int sb_index, u16 tc_index,
241 enum devlink_sb_pool_type pool_type,
242 u32 *p_cur, u32 *p_max);
93c1edb2
JP
243 void (*txhdr_construct)(struct sk_buff *skb,
244 const struct mlxsw_tx_info *tx_info);
245 u8 txhdr_len;
246 const struct mlxsw_config_profile *profile;
247};
248
249struct mlxsw_bus {
250 const char *kind;
251 int (*init)(void *bus_priv, struct mlxsw_core *mlxsw_core,
252 const struct mlxsw_config_profile *profile);
253 void (*fini)(void *bus_priv);
d003462a
IS
254 bool (*skb_transmit_busy)(void *bus_priv,
255 const struct mlxsw_tx_info *tx_info);
93c1edb2
JP
256 int (*skb_transmit)(void *bus_priv, struct sk_buff *skb,
257 const struct mlxsw_tx_info *tx_info);
258 int (*cmd_exec)(void *bus_priv, u16 opcode, u8 opcode_mod,
259 u32 in_mod, bool out_mbox_direct,
260 char *in_mbox, size_t in_mbox_size,
261 char *out_mbox, size_t out_mbox_size,
262 u8 *p_status);
263};
264
265struct mlxsw_bus_info {
266 const char *device_kind;
267 const char *device_name;
268 struct device *dev;
269 struct {
270 u16 major;
271 u16 minor;
272 u16 subminor;
273 } fw_rev;
274 u8 vsd[MLXSW_CMD_BOARDINFO_VSD_LEN];
275 u8 psid[MLXSW_CMD_BOARDINFO_PSID_LEN];
276};
277
89309da3
JP
278struct mlxsw_hwmon;
279
280#ifdef CONFIG_MLXSW_CORE_HWMON
281
282int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
283 const struct mlxsw_bus_info *mlxsw_bus_info,
284 struct mlxsw_hwmon **p_hwmon);
285void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon);
286
287#else
288
289static inline int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
290 const struct mlxsw_bus_info *mlxsw_bus_info,
291 struct mlxsw_hwmon **p_hwmon)
292{
293 return 0;
294}
295
89309da3
JP
296#endif
297
93c1edb2 298#endif