blob: 8869ad75b9652a0ab48501ecf2338cc7c58623fc [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01002/*
3 * include/net/devlink.h - Network physical device Netlink interface
4 * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01006 */
7#ifndef _NET_DEVLINK_H_
8#define _NET_DEVLINK_H_
9
10#include <linux/device.h>
11#include <linux/slab.h>
12#include <linux/gfp.h>
13#include <linux/list.h>
14#include <linux/netdevice.h>
Jiri Pirkob8f97552019-03-24 11:14:37 +010015#include <linux/spinlock.h>
Jiri Pirko136bf272019-05-23 10:43:35 +020016#include <linux/workqueue.h>
Ido Schimmel0f420b62019-08-17 16:28:17 +030017#include <linux/refcount.h>
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010018#include <net/net_namespace.h>
Jiri Pirko5a2e1062020-02-25 11:45:21 +010019#include <net/flow_offload.h>
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010020#include <uapi/linux/devlink.h>
21
22struct devlink_ops;
23
24struct devlink {
25 struct list_head list;
26 struct list_head port_list;
Jiri Pirkobf797472016-04-14 18:19:13 +020027 struct list_head sb_list;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020028 struct list_head dpipe_table_list;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +010029 struct list_head resource_list;
Moshe Shemesheabaef12018-07-04 14:30:28 +030030 struct list_head param_list;
Alex Veskerb16ebe92018-07-12 15:13:08 +030031 struct list_head region_list;
Alex Veskerccadfa42018-07-12 15:13:09 +030032 u32 snapshot_id;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +020033 struct list_head reporter_list;
Moshe Shemeshb587bda2019-04-29 12:41:45 +030034 struct mutex reporters_lock; /* protects reporter_list */
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020035 struct devlink_dpipe_headers *dpipe_headers;
Ido Schimmel0f420b62019-08-17 16:28:17 +030036 struct list_head trap_list;
37 struct list_head trap_group_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010038 const struct devlink_ops *ops;
39 struct device *dev;
40 possible_net_t _net;
Arkadi Sharshevsky2406e7e2018-01-15 08:59:02 +010041 struct mutex lock;
Jiri Pirkoa0c76342019-11-08 21:42:43 +010042 u8 reload_failed:1,
43 reload_enabled:1,
44 registered:1;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010045 char priv[0] __aligned(NETDEV_ALIGN);
46};
47
Parav Pandit378ef012019-07-08 23:17:35 -050048struct devlink_port_phys_attrs {
49 u32 port_number; /* Same value as "split group".
50 * A physical port which is visible to the user
51 * for a given port flavour.
52 */
53 u32 split_subport_number;
54};
55
Parav Pandit98fd2d62019-07-08 23:17:37 -050056struct devlink_port_pci_pf_attrs {
57 u16 pf; /* Associated PCI PF for this port. */
58};
59
Parav Pandite41b6bf2019-07-08 23:17:38 -050060struct devlink_port_pci_vf_attrs {
61 u16 pf; /* Associated PCI PF for this port. */
62 u16 vf; /* Associated PCI VF for of the PCI PF for this port. */
63};
64
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020065struct devlink_port_attrs {
Jiri Pirko407dd702019-04-03 14:24:15 +020066 u8 set:1,
Jiri Pirkobec52672019-04-03 14:24:16 +020067 split:1,
68 switch_port:1;
Jiri Pirko5ec13802018-05-18 09:29:01 +020069 enum devlink_port_flavour flavour;
Jiri Pirkobec52672019-04-03 14:24:16 +020070 struct netdev_phys_item_id switch_id;
Parav Pandit378ef012019-07-08 23:17:35 -050071 union {
72 struct devlink_port_phys_attrs phys;
Parav Pandit98fd2d62019-07-08 23:17:37 -050073 struct devlink_port_pci_pf_attrs pci_pf;
Parav Pandite41b6bf2019-07-08 23:17:38 -050074 struct devlink_port_pci_vf_attrs pci_vf;
Parav Pandit378ef012019-07-08 23:17:35 -050075 };
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020076};
77
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010078struct devlink_port {
79 struct list_head list;
Vasundhara Volam39e61602019-01-28 18:00:20 +053080 struct list_head param_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010081 struct devlink *devlink;
Parav Panditc7282b52019-08-30 05:39:44 -050082 unsigned int index;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010083 bool registered;
Jiri Pirkob8f97552019-03-24 11:14:37 +010084 spinlock_t type_lock; /* Protects type and type_dev
85 * pointer consistency.
86 */
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010087 enum devlink_port_type type;
88 enum devlink_port_type desired_type;
89 void *type_dev;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020090 struct devlink_port_attrs attrs;
Jiri Pirko136bf272019-05-23 10:43:35 +020091 struct delayed_work type_warn_dw;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010092};
93
Jiri Pirkobf797472016-04-14 18:19:13 +020094struct devlink_sb_pool_info {
95 enum devlink_sb_pool_type pool_type;
96 u32 size;
97 enum devlink_sb_threshold_type threshold_type;
Jakub Kicinskibff57312019-02-01 17:56:28 -080098 u32 cell_size;
Jiri Pirkobf797472016-04-14 18:19:13 +020099};
100
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200101/**
102 * struct devlink_dpipe_field - dpipe field object
103 * @name: field name
104 * @id: index inside the headers field array
105 * @bitwidth: bitwidth
106 * @mapping_type: mapping type
107 */
108struct devlink_dpipe_field {
109 const char *name;
110 unsigned int id;
111 unsigned int bitwidth;
112 enum devlink_dpipe_field_mapping_type mapping_type;
113};
114
115/**
116 * struct devlink_dpipe_header - dpipe header object
117 * @name: header name
118 * @id: index, global/local detrmined by global bit
119 * @fields: fields
120 * @fields_count: number of fields
121 * @global: indicates if header is shared like most protocol header
122 * or driver specific
123 */
124struct devlink_dpipe_header {
125 const char *name;
126 unsigned int id;
127 struct devlink_dpipe_field *fields;
128 unsigned int fields_count;
129 bool global;
130};
131
132/**
133 * struct devlink_dpipe_match - represents match operation
134 * @type: type of match
135 * @header_index: header index (packets can have several headers of same
136 * type like in case of tunnels)
137 * @header: header
138 * @fieled_id: field index
139 */
140struct devlink_dpipe_match {
141 enum devlink_dpipe_match_type type;
142 unsigned int header_index;
143 struct devlink_dpipe_header *header;
144 unsigned int field_id;
145};
146
147/**
148 * struct devlink_dpipe_action - represents action operation
149 * @type: type of action
150 * @header_index: header index (packets can have several headers of same
151 * type like in case of tunnels)
152 * @header: header
153 * @fieled_id: field index
154 */
155struct devlink_dpipe_action {
156 enum devlink_dpipe_action_type type;
157 unsigned int header_index;
158 struct devlink_dpipe_header *header;
159 unsigned int field_id;
160};
161
162/**
163 * struct devlink_dpipe_value - represents value of match/action
164 * @action: action
165 * @match: match
166 * @mapping_value: in case the field has some mapping this value
167 * specified the mapping value
168 * @mapping_valid: specify if mapping value is valid
169 * @value_size: value size
170 * @value: value
171 * @mask: bit mask
172 */
173struct devlink_dpipe_value {
174 union {
175 struct devlink_dpipe_action *action;
176 struct devlink_dpipe_match *match;
177 };
178 unsigned int mapping_value;
179 bool mapping_valid;
180 unsigned int value_size;
181 void *value;
182 void *mask;
183};
184
185/**
186 * struct devlink_dpipe_entry - table entry object
187 * @index: index of the entry in the table
188 * @match_values: match values
189 * @matche_values_count: count of matches tuples
190 * @action_values: actions values
191 * @action_values_count: count of actions values
192 * @counter: value of counter
193 * @counter_valid: Specify if value is valid from hardware
194 */
195struct devlink_dpipe_entry {
196 u64 index;
197 struct devlink_dpipe_value *match_values;
198 unsigned int match_values_count;
199 struct devlink_dpipe_value *action_values;
200 unsigned int action_values_count;
201 u64 counter;
202 bool counter_valid;
203};
204
205/**
206 * struct devlink_dpipe_dump_ctx - context provided to driver in order
207 * to dump
208 * @info: info
209 * @cmd: devlink command
210 * @skb: skb
211 * @nest: top attribute
212 * @hdr: hdr
213 */
214struct devlink_dpipe_dump_ctx {
215 struct genl_info *info;
216 enum devlink_command cmd;
217 struct sk_buff *skb;
218 struct nlattr *nest;
219 void *hdr;
220};
221
222struct devlink_dpipe_table_ops;
223
224/**
225 * struct devlink_dpipe_table - table object
226 * @priv: private
227 * @name: table name
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200228 * @counters_enabled: indicates if counters are active
229 * @counter_control_extern: indicates if counter control is in dpipe or
230 * external tool
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100231 * @resource_valid: Indicate that the resource id is valid
232 * @resource_id: relative resource this table is related to
233 * @resource_units: number of resource's unit consumed per table's entry
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200234 * @table_ops: table operations
235 * @rcu: rcu
236 */
237struct devlink_dpipe_table {
238 void *priv;
239 struct list_head list;
240 const char *name;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200241 bool counters_enabled;
242 bool counter_control_extern;
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100243 bool resource_valid;
244 u64 resource_id;
245 u64 resource_units;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200246 struct devlink_dpipe_table_ops *table_ops;
247 struct rcu_head rcu;
248};
249
250/**
251 * struct devlink_dpipe_table_ops - dpipe_table ops
252 * @actions_dump - dumps all tables actions
253 * @matches_dump - dumps all tables matches
254 * @entries_dump - dumps all active entries in the table
255 * @counters_set_update - when changing the counter status hardware sync
256 * maybe needed to allocate/free counter related
257 * resources
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200258 * @size_get - get size
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200259 */
260struct devlink_dpipe_table_ops {
261 int (*actions_dump)(void *priv, struct sk_buff *skb);
262 int (*matches_dump)(void *priv, struct sk_buff *skb);
263 int (*entries_dump)(void *priv, bool counters_enabled,
264 struct devlink_dpipe_dump_ctx *dump_ctx);
265 int (*counters_set_update)(void *priv, bool enable);
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200266 u64 (*size_get)(void *priv);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200267};
268
269/**
270 * struct devlink_dpipe_headers - dpipe headers
271 * @headers - header array can be shared (global bit) or driver specific
272 * @headers_count - count of headers
273 */
274struct devlink_dpipe_headers {
275 struct devlink_dpipe_header **headers;
276 unsigned int headers_count;
277};
278
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100279/**
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100280 * struct devlink_resource_size_params - resource's size parameters
281 * @size_min: minimum size which can be set
282 * @size_max: maximum size which can be set
283 * @size_granularity: size granularity
284 * @size_unit: resource's basic unit
285 */
286struct devlink_resource_size_params {
287 u64 size_min;
288 u64 size_max;
289 u64 size_granularity;
290 enum devlink_resource_unit unit;
291};
292
Jiri Pirko77d27092018-02-28 13:12:09 +0100293static inline void
294devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
295 u64 size_min, u64 size_max,
296 u64 size_granularity,
297 enum devlink_resource_unit unit)
298{
299 size_params->size_min = size_min;
300 size_params->size_max = size_max;
301 size_params->size_granularity = size_granularity;
302 size_params->unit = unit;
303}
304
Jiri Pirkofc56be42018-04-05 22:13:21 +0200305typedef u64 devlink_resource_occ_get_t(void *priv);
306
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100307/**
308 * struct devlink_resource - devlink resource
309 * @name: name of the resource
310 * @id: id, per devlink instance
311 * @size: size of the resource
312 * @size_new: updated size of the resource, reload is needed
313 * @size_valid: valid in case the total size of the resource is valid
314 * including its children
315 * @parent: parent resource
316 * @size_params: size parameters
317 * @list: parent list
318 * @resource_list: list of child resources
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100319 */
320struct devlink_resource {
321 const char *name;
322 u64 id;
323 u64 size;
324 u64 size_new;
325 bool size_valid;
326 struct devlink_resource *parent;
Jiri Pirko77d27092018-02-28 13:12:09 +0100327 struct devlink_resource_size_params size_params;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100328 struct list_head list;
329 struct list_head resource_list;
Jiri Pirkofc56be42018-04-05 22:13:21 +0200330 devlink_resource_occ_get_t *occ_get;
331 void *occ_get_priv;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100332};
333
334#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
335
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300336#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
Moshe Shemesheabaef12018-07-04 14:30:28 +0300337enum devlink_param_type {
338 DEVLINK_PARAM_TYPE_U8,
339 DEVLINK_PARAM_TYPE_U16,
340 DEVLINK_PARAM_TYPE_U32,
341 DEVLINK_PARAM_TYPE_STRING,
342 DEVLINK_PARAM_TYPE_BOOL,
343};
344
345union devlink_param_value {
346 u8 vu8;
347 u16 vu16;
348 u32 vu32;
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300349 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
Moshe Shemesheabaef12018-07-04 14:30:28 +0300350 bool vbool;
351};
352
353struct devlink_param_gset_ctx {
354 union devlink_param_value val;
355 enum devlink_param_cmode cmode;
356};
357
358/**
359 * struct devlink_param - devlink configuration parameter data
360 * @name: name of the parameter
361 * @generic: indicates if the parameter is generic or driver specific
362 * @type: parameter type
363 * @supported_cmodes: bitmap of supported configuration modes
364 * @get: get parameter value, used for runtime and permanent
365 * configuration modes
366 * @set: set parameter value, used for runtime and permanent
367 * configuration modes
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300368 * @validate: validate input value is applicable (within value range, etc.)
Moshe Shemesheabaef12018-07-04 14:30:28 +0300369 *
370 * This struct should be used by the driver to fill the data for
371 * a parameter it registers.
372 */
373struct devlink_param {
374 u32 id;
375 const char *name;
376 bool generic;
377 enum devlink_param_type type;
378 unsigned long supported_cmodes;
379 int (*get)(struct devlink *devlink, u32 id,
380 struct devlink_param_gset_ctx *ctx);
381 int (*set)(struct devlink *devlink, u32 id,
382 struct devlink_param_gset_ctx *ctx);
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300383 int (*validate)(struct devlink *devlink, u32 id,
384 union devlink_param_value val,
385 struct netlink_ext_ack *extack);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300386};
387
388struct devlink_param_item {
389 struct list_head list;
390 const struct devlink_param *param;
391 union devlink_param_value driverinit_value;
392 bool driverinit_value_valid;
Jiri Pirko7c62cfb2019-02-07 11:22:45 +0000393 bool published;
Moshe Shemesheabaef12018-07-04 14:30:28 +0300394};
395
396enum devlink_param_generic_id {
Moshe Shemesh036467c2018-07-04 14:30:33 +0300397 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
398 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300399 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
Alex Veskerf6a698852018-07-12 15:13:17 +0300400 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
Vasundhara Volame3b51062018-10-04 11:13:44 +0530401 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530402 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
Vasundhara Volam16511782018-10-04 11:13:46 +0530403 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
Shalom Toledo846e9802018-12-03 07:58:59 +0000404 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
Dirk van der Merwe5bbd21d2019-09-09 00:54:18 +0100405 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
Michael Guralnik6c7295e2019-11-08 23:45:20 +0000406 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
Moshe Shemesheabaef12018-07-04 14:30:28 +0300407
408 /* add new param generic ids above here*/
409 __DEVLINK_PARAM_GENERIC_ID_MAX,
410 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
411};
412
Moshe Shemesh036467c2018-07-04 14:30:33 +0300413#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
414#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
415
416#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
417#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
418
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300419#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
420#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
421
Alex Veskerf6a698852018-07-12 15:13:17 +0300422#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
423#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
424
Vasundhara Volame3b51062018-10-04 11:13:44 +0530425#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
426#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
427
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530428#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
429#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
430
Vasundhara Volam16511782018-10-04 11:13:46 +0530431#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
432#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
433
Shalom Toledo846e9802018-12-03 07:58:59 +0000434#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
435#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
436
Dirk van der Merwe5bbd21d2019-09-09 00:54:18 +0100437#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
438 "reset_dev_on_drv_probe"
439#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
440
Michael Guralnik6c7295e2019-11-08 23:45:20 +0000441#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
442#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
443
Moshe Shemesh036467c2018-07-04 14:30:33 +0300444#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
445{ \
446 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
447 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
448 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
449 .generic = true, \
450 .supported_cmodes = _cmodes, \
451 .get = _get, \
452 .set = _set, \
453 .validate = _validate, \
454}
455
456#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
457{ \
458 .id = _id, \
459 .name = _name, \
460 .type = _type, \
461 .supported_cmodes = _cmodes, \
462 .get = _get, \
463 .set = _set, \
464 .validate = _validate, \
465}
466
Jakub Kicinski785bd552019-01-31 10:50:42 -0800467/* Part number, identifier of board design */
468#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
469/* Revision of board design */
470#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
Jakub Kicinski14fd1902019-02-10 19:35:29 -0800471/* Maker of the board */
472#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800473
Shannon Nelson7d5aa9a2019-09-03 15:28:03 -0700474/* Part number, identifier of asic design */
475#define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
476/* Revision of asic design */
477#define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
478
479/* Overall FW version */
480#define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800481/* Control processor FW version */
482#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
483/* Data path microcode controlling high-speed packet processing */
484#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
485/* UNDI software version */
486#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
487/* NCSI support/handler version */
488#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
Jacob Keller468672b2020-01-09 14:46:09 -0800489/* FW parameter set id */
490#define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
Vasundhara Volam41c0d912020-01-27 04:56:25 -0500491/* RoCE FW version */
492#define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce"
Jacob Kellerc90977a2020-03-11 18:58:16 -0700493/* Firmware bundle identifier */
494#define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800495
Alex Veskerb16ebe92018-07-12 15:13:08 +0300496struct devlink_region;
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800497struct devlink_info_req;
Alex Veskerb16ebe92018-07-12 15:13:08 +0300498
Jacob Kellere8937682020-03-26 11:37:08 -0700499/**
500 * struct devlink_region_ops - Region operations
501 * @name: region name
Jacob Kellera0a09f62020-03-26 11:37:09 -0700502 * @destructor: callback used to free snapshot memory when deleting
Jacob Kellere8937682020-03-26 11:37:08 -0700503 */
504struct devlink_region_ops {
505 const char *name;
Jacob Kellera0a09f62020-03-26 11:37:09 -0700506 void (*destructor)(const void *data);
Jacob Kellere8937682020-03-26 11:37:08 -0700507};
508
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200509struct devlink_fmsg;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200510struct devlink_health_reporter;
511
Eran Ben Elisha3167b272019-03-03 10:57:30 +0200512enum devlink_health_reporter_state {
513 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
514 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
515};
516
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200517/**
518 * struct devlink_health_reporter_ops - Reporter operations
519 * @name: reporter name
520 * @recover: callback to recover from reported error
521 * if priv_ctx is NULL, run a full recover
522 * @dump: callback to dump an object
523 * if priv_ctx is NULL, run a full dump
524 * @diagnose: callback to diagnose the current status
525 */
526
527struct devlink_health_reporter_ops {
528 char *name;
529 int (*recover)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200530 void *priv_ctx, struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200531 int (*dump)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200532 struct devlink_fmsg *fmsg, void *priv_ctx,
533 struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200534 int (*diagnose)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200535 struct devlink_fmsg *fmsg,
536 struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200537};
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200538
Ido Schimmel0f420b62019-08-17 16:28:17 +0300539/**
540 * struct devlink_trap_group - Immutable packet trap group attributes.
541 * @name: Trap group name.
542 * @id: Trap group identifier.
543 * @generic: Whether the trap group is generic or not.
544 *
545 * Describes immutable attributes of packet trap groups that drivers register
546 * with devlink.
547 */
548struct devlink_trap_group {
549 const char *name;
550 u16 id;
551 bool generic;
552};
553
554#define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
Jiri Pirko85b05892020-02-25 11:45:19 +0100555#define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
Ido Schimmel0f420b62019-08-17 16:28:17 +0300556
557/**
558 * struct devlink_trap - Immutable packet trap attributes.
559 * @type: Trap type.
560 * @init_action: Initial trap action.
561 * @generic: Whether the trap is generic or not.
562 * @id: Trap identifier.
563 * @name: Trap name.
Ido Schimmel107f1672020-03-22 20:48:30 +0200564 * @init_group_id: Initial group identifier.
Ido Schimmel0f420b62019-08-17 16:28:17 +0300565 * @metadata_cap: Metadata types that can be provided by the trap.
566 *
567 * Describes immutable attributes of packet traps that drivers register with
568 * devlink.
569 */
570struct devlink_trap {
571 enum devlink_trap_type type;
572 enum devlink_trap_action init_action;
573 bool generic;
574 u16 id;
575 const char *name;
Ido Schimmel107f1672020-03-22 20:48:30 +0200576 u16 init_group_id;
Ido Schimmel0f420b62019-08-17 16:28:17 +0300577 u32 metadata_cap;
578};
579
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300580/* All traps must be documented in
Jacob Kellerf4bdd712020-01-09 14:46:10 -0800581 * Documentation/networking/devlink/devlink-trap.rst
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300582 */
Ido Schimmel0f420b62019-08-17 16:28:17 +0300583enum devlink_trap_generic_id {
Ido Schimmel391203a2019-08-17 16:28:18 +0300584 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
585 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
586 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
587 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
588 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
589 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
590 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
591 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
592 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
Amit Cohen6896cc42019-11-07 18:42:09 +0200593 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
594 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
595 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
596 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
597 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
598 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
599 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
600 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
601 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
Amit Cohen3b063ae2019-11-07 18:42:14 +0200602 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
603 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
604 DEVLINK_TRAP_GENERIC_ID_RPF,
605 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
606 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
607 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
Amit Cohen95f0ead2020-01-19 15:00:48 +0200608 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
Amit Cohen13c056e2020-01-19 15:00:54 +0200609 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
Amit Cohenc3cae492020-01-19 15:00:58 +0200610 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100611 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
612 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
Ido Schimmel391203a2019-08-17 16:28:18 +0300613
Ido Schimmel0f420b62019-08-17 16:28:17 +0300614 /* Add new generic trap IDs above */
615 __DEVLINK_TRAP_GENERIC_ID_MAX,
616 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
617};
618
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300619/* All trap groups must be documented in
Jacob Kellerf4bdd712020-01-09 14:46:10 -0800620 * Documentation/networking/devlink/devlink-trap.rst
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300621 */
Ido Schimmel0f420b62019-08-17 16:28:17 +0300622enum devlink_trap_group_generic_id {
Ido Schimmel391203a2019-08-17 16:28:18 +0300623 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
624 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
625 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
Amit Cohen13c056e2020-01-19 15:00:54 +0200626 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100627 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
Ido Schimmel391203a2019-08-17 16:28:18 +0300628
Ido Schimmel0f420b62019-08-17 16:28:17 +0300629 /* Add new generic trap group IDs above */
630 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
631 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
632 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
633};
634
Ido Schimmel391203a2019-08-17 16:28:18 +0300635#define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
636 "source_mac_is_multicast"
637#define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
638 "vlan_tag_mismatch"
639#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
640 "ingress_vlan_filter"
641#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
642 "ingress_spanning_tree_filter"
643#define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
644 "port_list_is_empty"
645#define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
646 "port_loopback_filter"
647#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
648 "blackhole_route"
649#define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
650 "ttl_value_is_too_small"
651#define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
652 "tail_drop"
Amit Cohen6896cc42019-11-07 18:42:09 +0200653#define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
654 "non_ip"
655#define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
656 "uc_dip_over_mc_dmac"
657#define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
658 "dip_is_loopback_address"
659#define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
660 "sip_is_mc"
661#define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
662 "sip_is_loopback_address"
663#define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
664 "ip_header_corrupted"
665#define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
666 "ipv4_sip_is_limited_bc"
667#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
668 "ipv6_mc_dip_reserved_scope"
669#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
670 "ipv6_mc_dip_interface_local_scope"
Amit Cohen3b063ae2019-11-07 18:42:14 +0200671#define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
672 "mtu_value_is_too_small"
673#define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
674 "unresolved_neigh"
675#define DEVLINK_TRAP_GENERIC_NAME_RPF \
676 "mc_reverse_path_forwarding"
677#define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
678 "reject_route"
679#define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
680 "ipv4_lpm_miss"
681#define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
682 "ipv6_lpm_miss"
Amit Cohen95f0ead2020-01-19 15:00:48 +0200683#define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
684 "non_routable_packet"
Amit Cohen13c056e2020-01-19 15:00:54 +0200685#define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
686 "decap_error"
Amit Cohenc3cae492020-01-19 15:00:58 +0200687#define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
688 "overlay_smac_is_mc"
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100689#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
690 "ingress_flow_action_drop"
691#define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
692 "egress_flow_action_drop"
Ido Schimmel391203a2019-08-17 16:28:18 +0300693
694#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
695 "l2_drops"
696#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
697 "l3_drops"
698#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
699 "buffer_drops"
Amit Cohen13c056e2020-01-19 15:00:54 +0200700#define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
701 "tunnel_drops"
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100702#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
703 "acl_drops"
Ido Schimmel391203a2019-08-17 16:28:18 +0300704
Ido Schimmel107f1672020-03-22 20:48:30 +0200705#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \
706 _metadata_cap) \
Ido Schimmel0f420b62019-08-17 16:28:17 +0300707 { \
708 .type = DEVLINK_TRAP_TYPE_##_type, \
709 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
710 .generic = true, \
711 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
712 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
Ido Schimmel107f1672020-03-22 20:48:30 +0200713 .init_group_id = _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +0300714 .metadata_cap = _metadata_cap, \
715 }
716
Ido Schimmel107f1672020-03-22 20:48:30 +0200717#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +0300718 _metadata_cap) \
719 { \
720 .type = DEVLINK_TRAP_TYPE_##_type, \
721 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
722 .generic = false, \
723 .id = _id, \
724 .name = _name, \
Ido Schimmel107f1672020-03-22 20:48:30 +0200725 .init_group_id = _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +0300726 .metadata_cap = _metadata_cap, \
727 }
728
729#define DEVLINK_TRAP_GROUP_GENERIC(_id) \
730 { \
731 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
732 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
733 .generic = true, \
734 }
735
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100736struct devlink_ops {
Jiri Pirko070c63f2019-10-03 11:49:39 +0200737 int (*reload_down)(struct devlink *devlink, bool netns_change,
Jiri Pirko97691062019-09-12 10:49:45 +0200738 struct netlink_ext_ack *extack);
739 int (*reload_up)(struct devlink *devlink,
740 struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100741 int (*port_type_set)(struct devlink_port *devlink_port,
742 enum devlink_port_type port_type);
743 int (*port_split)(struct devlink *devlink, unsigned int port_index,
David Ahernac0fc8a2018-06-05 08:14:09 -0700744 unsigned int count, struct netlink_ext_ack *extack);
745 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
746 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200747 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
748 u16 pool_index,
749 struct devlink_sb_pool_info *pool_info);
750 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
751 u16 pool_index, u32 size,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000752 enum devlink_sb_threshold_type threshold_type,
753 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200754 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
755 unsigned int sb_index, u16 pool_index,
756 u32 *p_threshold);
757 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
758 unsigned int sb_index, u16 pool_index,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000759 u32 threshold, struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200760 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
761 unsigned int sb_index,
762 u16 tc_index,
763 enum devlink_sb_pool_type pool_type,
764 u16 *p_pool_index, u32 *p_threshold);
765 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
766 unsigned int sb_index,
767 u16 tc_index,
768 enum devlink_sb_pool_type pool_type,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000769 u16 pool_index, u32 threshold,
770 struct netlink_ext_ack *extack);
Jiri Pirkodf38daf2016-04-14 18:19:14 +0200771 int (*sb_occ_snapshot)(struct devlink *devlink,
772 unsigned int sb_index);
773 int (*sb_occ_max_clear)(struct devlink *devlink,
774 unsigned int sb_index);
775 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
776 unsigned int sb_index, u16 pool_index,
777 u32 *p_cur, u32 *p_max);
778 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
779 unsigned int sb_index,
780 u16 tc_index,
781 enum devlink_sb_pool_type pool_type,
782 u32 *p_cur, u32 *p_max);
Or Gerlitz08f4b592016-07-01 14:51:01 +0300783
784 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300785 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
786 struct netlink_ext_ack *extack);
Roi Dayan59bfde02016-11-22 23:09:57 +0200787 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300788 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
789 struct netlink_ext_ack *extack);
Leon Romanovsky98fdbea2019-06-12 15:20:11 +0300790 int (*eswitch_encap_mode_get)(struct devlink *devlink,
791 enum devlink_eswitch_encap_mode *p_encap_mode);
792 int (*eswitch_encap_mode_set)(struct devlink *devlink,
793 enum devlink_eswitch_encap_mode encap_mode,
Eli Britsteindb7ff192018-08-15 16:02:18 +0300794 struct netlink_ext_ack *extack);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800795 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
796 struct netlink_ext_ack *extack);
Jakub Kicinski76726cc2019-02-14 13:40:44 -0800797 int (*flash_update)(struct devlink *devlink, const char *file_name,
798 const char *component,
799 struct netlink_ext_ack *extack);
Ido Schimmel0f420b62019-08-17 16:28:17 +0300800 /**
801 * @trap_init: Trap initialization function.
802 *
803 * Should be used by device drivers to initialize the trap in the
804 * underlying device. Drivers should also store the provided trap
805 * context, so that they could efficiently pass it to
806 * devlink_trap_report() when the trap is triggered.
807 */
808 int (*trap_init)(struct devlink *devlink,
809 const struct devlink_trap *trap, void *trap_ctx);
810 /**
811 * @trap_fini: Trap de-initialization function.
812 *
813 * Should be used by device drivers to de-initialize the trap in the
814 * underlying device.
815 */
816 void (*trap_fini)(struct devlink *devlink,
817 const struct devlink_trap *trap, void *trap_ctx);
818 /**
819 * @trap_action_set: Trap action set function.
820 */
821 int (*trap_action_set)(struct devlink *devlink,
822 const struct devlink_trap *trap,
823 enum devlink_trap_action action);
824 /**
825 * @trap_group_init: Trap group initialization function.
826 *
827 * Should be used by device drivers to initialize the trap group in the
828 * underlying device.
829 */
830 int (*trap_group_init)(struct devlink *devlink,
831 const struct devlink_trap_group *group);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100832};
833
834static inline void *devlink_priv(struct devlink *devlink)
835{
836 BUG_ON(!devlink);
837 return &devlink->priv;
838}
839
840static inline struct devlink *priv_to_devlink(void *priv)
841{
842 BUG_ON(!priv);
843 return container_of(priv, struct devlink, priv);
844}
845
Jiri Pirko5dc37bb2019-03-28 13:56:36 +0100846static inline struct devlink_port *
847netdev_to_devlink_port(struct net_device *dev)
848{
849 if (dev->netdev_ops->ndo_get_devlink_port)
850 return dev->netdev_ops->ndo_get_devlink_port(dev);
851 return NULL;
852}
853
Jakub Kicinskib473b0d2019-02-25 19:34:03 -0800854static inline struct devlink *netdev_to_devlink(struct net_device *dev)
855{
Jiri Pirko5dc37bb2019-03-28 13:56:36 +0100856 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
857
858 if (devlink_port)
859 return devlink_port->devlink;
Jakub Kicinskib473b0d2019-02-25 19:34:03 -0800860 return NULL;
861}
862
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100863struct ib_device;
864
Jiri Pirko471f8942019-10-03 11:49:31 +0200865struct net *devlink_net(const struct devlink *devlink);
Jiri Pirko8273fd82019-10-05 08:10:31 +0200866void devlink_net_set(struct devlink *devlink, struct net *net);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100867struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
868int devlink_register(struct devlink *devlink, struct device *dev);
869void devlink_unregister(struct devlink *devlink);
Jiri Pirkoa0c76342019-11-08 21:42:43 +0100870void devlink_reload_enable(struct devlink *devlink);
871void devlink_reload_disable(struct devlink *devlink);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100872void devlink_free(struct devlink *devlink);
873int devlink_port_register(struct devlink *devlink,
874 struct devlink_port *devlink_port,
875 unsigned int port_index);
876void devlink_port_unregister(struct devlink_port *devlink_port);
877void devlink_port_type_eth_set(struct devlink_port *devlink_port,
878 struct net_device *netdev);
879void devlink_port_type_ib_set(struct devlink_port *devlink_port,
880 struct ib_device *ibdev);
881void devlink_port_type_clear(struct devlink_port *devlink_port);
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200882void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200883 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200884 u32 port_number, bool split,
Jiri Pirkobec52672019-04-03 14:24:16 +0200885 u32 split_subport_number,
886 const unsigned char *switch_id,
887 unsigned char switch_id_len);
Parav Pandit98fd2d62019-07-08 23:17:37 -0500888void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
889 const unsigned char *switch_id,
890 unsigned char switch_id_len, u16 pf);
Parav Pandite41b6bf2019-07-08 23:17:38 -0500891void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
892 const unsigned char *switch_id,
893 unsigned char switch_id_len,
894 u16 pf, u16 vf);
Jiri Pirkobf797472016-04-14 18:19:13 +0200895int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
896 u32 size, u16 ingress_pools_count,
897 u16 egress_pools_count, u16 ingress_tc_count,
898 u16 egress_tc_count);
899void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200900int devlink_dpipe_table_register(struct devlink *devlink,
901 const char *table_name,
902 struct devlink_dpipe_table_ops *table_ops,
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200903 void *priv, bool counter_control_extern);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200904void devlink_dpipe_table_unregister(struct devlink *devlink,
905 const char *table_name);
906int devlink_dpipe_headers_register(struct devlink *devlink,
907 struct devlink_dpipe_headers *dpipe_headers);
908void devlink_dpipe_headers_unregister(struct devlink *devlink);
909bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
910 const char *table_name);
911int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
912int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
913 struct devlink_dpipe_entry *entry);
914int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200915void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200916int devlink_dpipe_action_put(struct sk_buff *skb,
917 struct devlink_dpipe_action *action);
918int devlink_dpipe_match_put(struct sk_buff *skb,
919 struct devlink_dpipe_match *match);
Arkadi Sharshevsky11770092017-08-24 08:39:59 +0200920extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
Arkadi Sharshevsky3fb886e2017-08-24 08:40:00 +0200921extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
Arkadi Sharshevsky1797f5b2017-08-31 17:59:12 +0200922extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100923
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100924int devlink_resource_register(struct devlink *devlink,
925 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100926 u64 resource_size,
927 u64 resource_id,
928 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200929 const struct devlink_resource_size_params *size_params);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100930void devlink_resources_unregister(struct devlink *devlink,
931 struct devlink_resource *resource);
932int devlink_resource_size_get(struct devlink *devlink,
933 u64 resource_id,
934 u64 *p_resource_size);
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100935int devlink_dpipe_table_resource_set(struct devlink *devlink,
936 const char *table_name, u64 resource_id,
937 u64 resource_units);
Jiri Pirkofc56be42018-04-05 22:13:21 +0200938void devlink_resource_occ_get_register(struct devlink *devlink,
939 u64 resource_id,
940 devlink_resource_occ_get_t *occ_get,
941 void *occ_get_priv);
942void devlink_resource_occ_get_unregister(struct devlink *devlink,
943 u64 resource_id);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300944int devlink_params_register(struct devlink *devlink,
945 const struct devlink_param *params,
946 size_t params_count);
947void devlink_params_unregister(struct devlink *devlink,
948 const struct devlink_param *params,
949 size_t params_count);
Jiri Pirko7c62cfb2019-02-07 11:22:45 +0000950void devlink_params_publish(struct devlink *devlink);
951void devlink_params_unpublish(struct devlink *devlink);
Vasundhara Volam39e61602019-01-28 18:00:20 +0530952int devlink_port_params_register(struct devlink_port *devlink_port,
953 const struct devlink_param *params,
954 size_t params_count);
955void devlink_port_params_unregister(struct devlink_port *devlink_port,
956 const struct devlink_param *params,
957 size_t params_count);
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300958int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
959 union devlink_param_value *init_val);
960int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
961 union devlink_param_value init_val);
Vasundhara Volamffd19b92019-01-28 18:00:23 +0530962int
963devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
964 u32 param_id,
965 union devlink_param_value *init_val);
Vasundhara Volam5473a7b2019-01-28 18:00:24 +0530966int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
967 u32 param_id,
968 union devlink_param_value init_val);
Moshe Shemeshea601e12018-07-04 14:30:32 +0300969void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
Vasundhara Volamc1e5786d2019-01-28 18:00:25 +0530970void devlink_port_param_value_changed(struct devlink_port *devlink_port,
971 u32 param_id);
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300972void devlink_param_value_str_fill(union devlink_param_value *dst_val,
973 const char *src);
Jacob Kellere8937682020-03-26 11:37:08 -0700974struct devlink_region *
975devlink_region_create(struct devlink *devlink,
976 const struct devlink_region_ops *ops,
977 u32 region_max_snapshots, u64 region_size);
Alex Veskerb16ebe92018-07-12 15:13:08 +0300978void devlink_region_destroy(struct devlink_region *region);
Jacob Kellerb0efcae2020-01-09 11:08:20 -0800979u32 devlink_region_snapshot_id_get(struct devlink *devlink);
Jiri Pirko3a5e5232019-08-09 15:27:15 +0200980int devlink_region_snapshot_create(struct devlink_region *region,
Jacob Kellera0a09f62020-03-26 11:37:09 -0700981 u8 *data, u32 snapshot_id);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800982int devlink_info_serial_number_put(struct devlink_info_req *req,
983 const char *sn);
984int devlink_info_driver_name_put(struct devlink_info_req *req,
985 const char *name);
Jakub Kicinskifc6fae72019-01-31 10:50:41 -0800986int devlink_info_version_fixed_put(struct devlink_info_req *req,
987 const char *version_name,
988 const char *version_value);
989int devlink_info_version_stored_put(struct devlink_info_req *req,
990 const char *version_name,
991 const char *version_value);
992int devlink_info_version_running_put(struct devlink_info_req *req,
993 const char *version_name,
994 const char *version_value);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100995
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200996int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
997int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
998
999int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1000int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1001
1002int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1003 const char *name);
1004int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
Aya Levin573ed902020-02-11 14:32:42 -08001005int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1006 const char *name);
1007int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001008
1009int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
1010int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
1011int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1012int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
1013int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
Aya Levin573ed902020-02-11 14:32:42 -08001014int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1015 u16 value_len);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001016
1017int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1018 bool value);
1019int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1020 u8 value);
1021int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1022 u32 value);
1023int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1024 u64 value);
1025int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1026 const char *value);
1027int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
Aya Levine2cde862019-11-12 14:07:49 +02001028 const void *value, u32 value_len);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001029
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001030struct devlink_health_reporter *
1031devlink_health_reporter_create(struct devlink *devlink,
1032 const struct devlink_health_reporter_ops *ops,
1033 u64 graceful_period, bool auto_recover,
1034 void *priv);
1035void
1036devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1037
1038void *
1039devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
Eran Ben Elishac8e1da02019-02-07 11:36:34 +02001040int devlink_health_report(struct devlink_health_reporter *reporter,
1041 const char *msg, void *priv_ctx);
Eran Ben Elisha3167b272019-03-03 10:57:30 +02001042void
1043devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1044 enum devlink_health_reporter_state state);
Vikas Gupta6181e5c2020-01-02 21:18:09 +05301045void
1046devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001047
Jiri Pirko2670ac22019-09-12 10:49:46 +02001048bool devlink_is_reload_failed(const struct devlink *devlink);
1049
Jiri Pirko191ed202019-06-04 15:40:40 +02001050void devlink_flash_update_begin_notify(struct devlink *devlink);
1051void devlink_flash_update_end_notify(struct devlink *devlink);
1052void devlink_flash_update_status_notify(struct devlink *devlink,
1053 const char *status_msg,
1054 const char *component,
1055 unsigned long done,
1056 unsigned long total);
1057
Ido Schimmel0f420b62019-08-17 16:28:17 +03001058int devlink_traps_register(struct devlink *devlink,
1059 const struct devlink_trap *traps,
1060 size_t traps_count, void *priv);
1061void devlink_traps_unregister(struct devlink *devlink,
1062 const struct devlink_trap *traps,
1063 size_t traps_count);
Jiri Pirko5a2e1062020-02-25 11:45:21 +01001064void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
1065 void *trap_ctx, struct devlink_port *in_devlink_port,
1066 const struct flow_action_cookie *fa_cookie);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001067void *devlink_trap_ctx_priv(void *trap_ctx);
Ido Schimmel95ad9552020-03-22 20:48:26 +02001068int devlink_trap_groups_register(struct devlink *devlink,
1069 const struct devlink_trap_group *groups,
1070 size_t groups_count);
1071void devlink_trap_groups_unregister(struct devlink *devlink,
1072 const struct devlink_trap_group *groups,
1073 size_t groups_count);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001074
Jiri Pirkof6b19b32019-03-24 11:14:38 +01001075#if IS_ENABLED(CONFIG_NET_DEVLINK)
1076
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -08001077void devlink_compat_running_version(struct net_device *dev,
1078 char *buf, size_t len);
1079int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
Jiri Pirkoaf3836d2019-03-28 13:56:37 +01001080int devlink_compat_phys_port_name_get(struct net_device *dev,
1081 char *name, size_t len);
Jiri Pirko7e1146e2019-04-03 14:24:17 +02001082int devlink_compat_switch_id_get(struct net_device *dev,
1083 struct netdev_phys_item_id *ppid);
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -08001084
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001085#else
1086
Eran Ben Elisha3167b272019-03-03 10:57:30 +02001087static inline void
Jakub Kicinskiddb6e992019-01-31 10:50:47 -08001088devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1089{
1090}
Jakub Kicinski4eceba12019-02-14 13:40:45 -08001091
1092static inline int
1093devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1094{
1095 return -EOPNOTSUPP;
1096}
Jiri Pirkof6b19b32019-03-24 11:14:38 +01001097
Jiri Pirkoaf3836d2019-03-28 13:56:37 +01001098static inline int
1099devlink_compat_phys_port_name_get(struct net_device *dev,
1100 char *name, size_t len)
1101{
1102 return -EOPNOTSUPP;
1103}
1104
Jiri Pirko7e1146e2019-04-03 14:24:17 +02001105static inline int
1106devlink_compat_switch_id_get(struct net_device *dev,
1107 struct netdev_phys_item_id *ppid)
1108{
1109 return -EOPNOTSUPP;
1110}
1111
Jakub Kicinskiddb6e992019-01-31 10:50:47 -08001112#endif
1113
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001114#endif /* _NET_DEVLINK_H_ */