blob: 05a45dea976b2063b185825571865c884ac3c47d [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>
Jacob Keller12102432020-03-26 11:37:15 -070021#include <linux/xarray.h>
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010022
23struct devlink_ops;
24
25struct devlink {
26 struct list_head list;
27 struct list_head port_list;
Jiri Pirkobf797472016-04-14 18:19:13 +020028 struct list_head sb_list;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020029 struct list_head dpipe_table_list;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +010030 struct list_head resource_list;
Moshe Shemesheabaef12018-07-04 14:30:28 +030031 struct list_head param_list;
Alex Veskerb16ebe92018-07-12 15:13:08 +030032 struct list_head region_list;
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;
Ido Schimmel1e8c6612020-03-30 22:38:18 +030038 struct list_head trap_policer_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010039 const struct devlink_ops *ops;
Jacob Keller12102432020-03-26 11:37:15 -070040 struct xarray snapshot_ids;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010041 struct device *dev;
42 possible_net_t _net;
Arkadi Sharshevsky2406e7e2018-01-15 08:59:02 +010043 struct mutex lock;
Jiri Pirkoa0c76342019-11-08 21:42:43 +010044 u8 reload_failed:1,
45 reload_enabled:1,
46 registered:1;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010047 char priv[0] __aligned(NETDEV_ALIGN);
48};
49
Parav Pandit378ef012019-07-08 23:17:35 -050050struct devlink_port_phys_attrs {
51 u32 port_number; /* Same value as "split group".
52 * A physical port which is visible to the user
53 * for a given port flavour.
54 */
55 u32 split_subport_number;
56};
57
Parav Pandit98fd2d62019-07-08 23:17:37 -050058struct devlink_port_pci_pf_attrs {
59 u16 pf; /* Associated PCI PF for this port. */
60};
61
Parav Pandite41b6bf2019-07-08 23:17:38 -050062struct devlink_port_pci_vf_attrs {
63 u16 pf; /* Associated PCI PF for this port. */
64 u16 vf; /* Associated PCI VF for of the PCI PF for this port. */
65};
66
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020067struct devlink_port_attrs {
Jiri Pirko407dd702019-04-03 14:24:15 +020068 u8 set:1,
Jiri Pirkobec52672019-04-03 14:24:16 +020069 split:1,
70 switch_port:1;
Jiri Pirko5ec13802018-05-18 09:29:01 +020071 enum devlink_port_flavour flavour;
Jiri Pirkobec52672019-04-03 14:24:16 +020072 struct netdev_phys_item_id switch_id;
Parav Pandit378ef012019-07-08 23:17:35 -050073 union {
74 struct devlink_port_phys_attrs phys;
Parav Pandit98fd2d62019-07-08 23:17:37 -050075 struct devlink_port_pci_pf_attrs pci_pf;
Parav Pandite41b6bf2019-07-08 23:17:38 -050076 struct devlink_port_pci_vf_attrs pci_vf;
Parav Pandit378ef012019-07-08 23:17:35 -050077 };
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020078};
79
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010080struct devlink_port {
81 struct list_head list;
Vasundhara Volam39e61602019-01-28 18:00:20 +053082 struct list_head param_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010083 struct devlink *devlink;
Parav Panditc7282b52019-08-30 05:39:44 -050084 unsigned int index;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010085 bool registered;
Jiri Pirkob8f97552019-03-24 11:14:37 +010086 spinlock_t type_lock; /* Protects type and type_dev
87 * pointer consistency.
88 */
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010089 enum devlink_port_type type;
90 enum devlink_port_type desired_type;
91 void *type_dev;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020092 struct devlink_port_attrs attrs;
Jiri Pirko136bf272019-05-23 10:43:35 +020093 struct delayed_work type_warn_dw;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010094};
95
Jiri Pirkobf797472016-04-14 18:19:13 +020096struct devlink_sb_pool_info {
97 enum devlink_sb_pool_type pool_type;
98 u32 size;
99 enum devlink_sb_threshold_type threshold_type;
Jakub Kicinskibff57312019-02-01 17:56:28 -0800100 u32 cell_size;
Jiri Pirkobf797472016-04-14 18:19:13 +0200101};
102
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200103/**
104 * struct devlink_dpipe_field - dpipe field object
105 * @name: field name
106 * @id: index inside the headers field array
107 * @bitwidth: bitwidth
108 * @mapping_type: mapping type
109 */
110struct devlink_dpipe_field {
111 const char *name;
112 unsigned int id;
113 unsigned int bitwidth;
114 enum devlink_dpipe_field_mapping_type mapping_type;
115};
116
117/**
118 * struct devlink_dpipe_header - dpipe header object
119 * @name: header name
120 * @id: index, global/local detrmined by global bit
121 * @fields: fields
122 * @fields_count: number of fields
123 * @global: indicates if header is shared like most protocol header
124 * or driver specific
125 */
126struct devlink_dpipe_header {
127 const char *name;
128 unsigned int id;
129 struct devlink_dpipe_field *fields;
130 unsigned int fields_count;
131 bool global;
132};
133
134/**
135 * struct devlink_dpipe_match - represents match operation
136 * @type: type of match
137 * @header_index: header index (packets can have several headers of same
138 * type like in case of tunnels)
139 * @header: header
140 * @fieled_id: field index
141 */
142struct devlink_dpipe_match {
143 enum devlink_dpipe_match_type type;
144 unsigned int header_index;
145 struct devlink_dpipe_header *header;
146 unsigned int field_id;
147};
148
149/**
150 * struct devlink_dpipe_action - represents action operation
151 * @type: type of action
152 * @header_index: header index (packets can have several headers of same
153 * type like in case of tunnels)
154 * @header: header
155 * @fieled_id: field index
156 */
157struct devlink_dpipe_action {
158 enum devlink_dpipe_action_type type;
159 unsigned int header_index;
160 struct devlink_dpipe_header *header;
161 unsigned int field_id;
162};
163
164/**
165 * struct devlink_dpipe_value - represents value of match/action
166 * @action: action
167 * @match: match
168 * @mapping_value: in case the field has some mapping this value
169 * specified the mapping value
170 * @mapping_valid: specify if mapping value is valid
171 * @value_size: value size
172 * @value: value
173 * @mask: bit mask
174 */
175struct devlink_dpipe_value {
176 union {
177 struct devlink_dpipe_action *action;
178 struct devlink_dpipe_match *match;
179 };
180 unsigned int mapping_value;
181 bool mapping_valid;
182 unsigned int value_size;
183 void *value;
184 void *mask;
185};
186
187/**
188 * struct devlink_dpipe_entry - table entry object
189 * @index: index of the entry in the table
190 * @match_values: match values
191 * @matche_values_count: count of matches tuples
192 * @action_values: actions values
193 * @action_values_count: count of actions values
194 * @counter: value of counter
195 * @counter_valid: Specify if value is valid from hardware
196 */
197struct devlink_dpipe_entry {
198 u64 index;
199 struct devlink_dpipe_value *match_values;
200 unsigned int match_values_count;
201 struct devlink_dpipe_value *action_values;
202 unsigned int action_values_count;
203 u64 counter;
204 bool counter_valid;
205};
206
207/**
208 * struct devlink_dpipe_dump_ctx - context provided to driver in order
209 * to dump
210 * @info: info
211 * @cmd: devlink command
212 * @skb: skb
213 * @nest: top attribute
214 * @hdr: hdr
215 */
216struct devlink_dpipe_dump_ctx {
217 struct genl_info *info;
218 enum devlink_command cmd;
219 struct sk_buff *skb;
220 struct nlattr *nest;
221 void *hdr;
222};
223
224struct devlink_dpipe_table_ops;
225
226/**
227 * struct devlink_dpipe_table - table object
228 * @priv: private
229 * @name: table name
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200230 * @counters_enabled: indicates if counters are active
231 * @counter_control_extern: indicates if counter control is in dpipe or
232 * external tool
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100233 * @resource_valid: Indicate that the resource id is valid
234 * @resource_id: relative resource this table is related to
235 * @resource_units: number of resource's unit consumed per table's entry
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200236 * @table_ops: table operations
237 * @rcu: rcu
238 */
239struct devlink_dpipe_table {
240 void *priv;
241 struct list_head list;
242 const char *name;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200243 bool counters_enabled;
244 bool counter_control_extern;
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100245 bool resource_valid;
246 u64 resource_id;
247 u64 resource_units;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200248 struct devlink_dpipe_table_ops *table_ops;
249 struct rcu_head rcu;
250};
251
252/**
253 * struct devlink_dpipe_table_ops - dpipe_table ops
254 * @actions_dump - dumps all tables actions
255 * @matches_dump - dumps all tables matches
256 * @entries_dump - dumps all active entries in the table
257 * @counters_set_update - when changing the counter status hardware sync
258 * maybe needed to allocate/free counter related
259 * resources
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200260 * @size_get - get size
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200261 */
262struct devlink_dpipe_table_ops {
263 int (*actions_dump)(void *priv, struct sk_buff *skb);
264 int (*matches_dump)(void *priv, struct sk_buff *skb);
265 int (*entries_dump)(void *priv, bool counters_enabled,
266 struct devlink_dpipe_dump_ctx *dump_ctx);
267 int (*counters_set_update)(void *priv, bool enable);
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200268 u64 (*size_get)(void *priv);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200269};
270
271/**
272 * struct devlink_dpipe_headers - dpipe headers
273 * @headers - header array can be shared (global bit) or driver specific
274 * @headers_count - count of headers
275 */
276struct devlink_dpipe_headers {
277 struct devlink_dpipe_header **headers;
278 unsigned int headers_count;
279};
280
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100281/**
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100282 * struct devlink_resource_size_params - resource's size parameters
283 * @size_min: minimum size which can be set
284 * @size_max: maximum size which can be set
285 * @size_granularity: size granularity
286 * @size_unit: resource's basic unit
287 */
288struct devlink_resource_size_params {
289 u64 size_min;
290 u64 size_max;
291 u64 size_granularity;
292 enum devlink_resource_unit unit;
293};
294
Jiri Pirko77d27092018-02-28 13:12:09 +0100295static inline void
296devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
297 u64 size_min, u64 size_max,
298 u64 size_granularity,
299 enum devlink_resource_unit unit)
300{
301 size_params->size_min = size_min;
302 size_params->size_max = size_max;
303 size_params->size_granularity = size_granularity;
304 size_params->unit = unit;
305}
306
Jiri Pirkofc56be42018-04-05 22:13:21 +0200307typedef u64 devlink_resource_occ_get_t(void *priv);
308
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100309/**
310 * struct devlink_resource - devlink resource
311 * @name: name of the resource
312 * @id: id, per devlink instance
313 * @size: size of the resource
314 * @size_new: updated size of the resource, reload is needed
315 * @size_valid: valid in case the total size of the resource is valid
316 * including its children
317 * @parent: parent resource
318 * @size_params: size parameters
319 * @list: parent list
320 * @resource_list: list of child resources
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100321 */
322struct devlink_resource {
323 const char *name;
324 u64 id;
325 u64 size;
326 u64 size_new;
327 bool size_valid;
328 struct devlink_resource *parent;
Jiri Pirko77d27092018-02-28 13:12:09 +0100329 struct devlink_resource_size_params size_params;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100330 struct list_head list;
331 struct list_head resource_list;
Jiri Pirkofc56be42018-04-05 22:13:21 +0200332 devlink_resource_occ_get_t *occ_get;
333 void *occ_get_priv;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100334};
335
336#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
337
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300338#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
Moshe Shemesheabaef12018-07-04 14:30:28 +0300339enum devlink_param_type {
340 DEVLINK_PARAM_TYPE_U8,
341 DEVLINK_PARAM_TYPE_U16,
342 DEVLINK_PARAM_TYPE_U32,
343 DEVLINK_PARAM_TYPE_STRING,
344 DEVLINK_PARAM_TYPE_BOOL,
345};
346
347union devlink_param_value {
348 u8 vu8;
349 u16 vu16;
350 u32 vu32;
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300351 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
Moshe Shemesheabaef12018-07-04 14:30:28 +0300352 bool vbool;
353};
354
355struct devlink_param_gset_ctx {
356 union devlink_param_value val;
357 enum devlink_param_cmode cmode;
358};
359
360/**
361 * struct devlink_param - devlink configuration parameter data
362 * @name: name of the parameter
363 * @generic: indicates if the parameter is generic or driver specific
364 * @type: parameter type
365 * @supported_cmodes: bitmap of supported configuration modes
366 * @get: get parameter value, used for runtime and permanent
367 * configuration modes
368 * @set: set parameter value, used for runtime and permanent
369 * configuration modes
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300370 * @validate: validate input value is applicable (within value range, etc.)
Moshe Shemesheabaef12018-07-04 14:30:28 +0300371 *
372 * This struct should be used by the driver to fill the data for
373 * a parameter it registers.
374 */
375struct devlink_param {
376 u32 id;
377 const char *name;
378 bool generic;
379 enum devlink_param_type type;
380 unsigned long supported_cmodes;
381 int (*get)(struct devlink *devlink, u32 id,
382 struct devlink_param_gset_ctx *ctx);
383 int (*set)(struct devlink *devlink, u32 id,
384 struct devlink_param_gset_ctx *ctx);
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300385 int (*validate)(struct devlink *devlink, u32 id,
386 union devlink_param_value val,
387 struct netlink_ext_ack *extack);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300388};
389
390struct devlink_param_item {
391 struct list_head list;
392 const struct devlink_param *param;
393 union devlink_param_value driverinit_value;
394 bool driverinit_value_valid;
Jiri Pirko7c62cfb2019-02-07 11:22:45 +0000395 bool published;
Moshe Shemesheabaef12018-07-04 14:30:28 +0300396};
397
398enum devlink_param_generic_id {
Moshe Shemesh036467c2018-07-04 14:30:33 +0300399 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
400 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300401 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
Alex Veskerf6a698852018-07-12 15:13:17 +0300402 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
Vasundhara Volame3b51062018-10-04 11:13:44 +0530403 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530404 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
Vasundhara Volam16511782018-10-04 11:13:46 +0530405 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
Shalom Toledo846e9802018-12-03 07:58:59 +0000406 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
Dirk van der Merwe5bbd21d2019-09-09 00:54:18 +0100407 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
Michael Guralnik6c7295e2019-11-08 23:45:20 +0000408 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
Moshe Shemesheabaef12018-07-04 14:30:28 +0300409
410 /* add new param generic ids above here*/
411 __DEVLINK_PARAM_GENERIC_ID_MAX,
412 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
413};
414
Moshe Shemesh036467c2018-07-04 14:30:33 +0300415#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
416#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
417
418#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
419#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
420
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300421#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
422#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
423
Alex Veskerf6a698852018-07-12 15:13:17 +0300424#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
425#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
426
Vasundhara Volame3b51062018-10-04 11:13:44 +0530427#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
428#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
429
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530430#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
431#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
432
Vasundhara Volam16511782018-10-04 11:13:46 +0530433#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
434#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
435
Shalom Toledo846e9802018-12-03 07:58:59 +0000436#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
437#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
438
Dirk van der Merwe5bbd21d2019-09-09 00:54:18 +0100439#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
440 "reset_dev_on_drv_probe"
441#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
442
Michael Guralnik6c7295e2019-11-08 23:45:20 +0000443#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
444#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
445
Moshe Shemesh036467c2018-07-04 14:30:33 +0300446#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
447{ \
448 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
449 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
450 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
451 .generic = true, \
452 .supported_cmodes = _cmodes, \
453 .get = _get, \
454 .set = _set, \
455 .validate = _validate, \
456}
457
458#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
459{ \
460 .id = _id, \
461 .name = _name, \
462 .type = _type, \
463 .supported_cmodes = _cmodes, \
464 .get = _get, \
465 .set = _set, \
466 .validate = _validate, \
467}
468
Jakub Kicinski785bd552019-01-31 10:50:42 -0800469/* Part number, identifier of board design */
470#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
471/* Revision of board design */
472#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
Jakub Kicinski14fd1902019-02-10 19:35:29 -0800473/* Maker of the board */
474#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800475
Shannon Nelson7d5aa9a2019-09-03 15:28:03 -0700476/* Part number, identifier of asic design */
477#define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
478/* Revision of asic design */
479#define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
480
481/* Overall FW version */
482#define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800483/* Control processor FW version */
484#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
Vasundhara Volam2d9eade2020-03-27 15:04:51 +0530485/* FW interface specification version */
486#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API "fw.mgmt.api"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800487/* Data path microcode controlling high-speed packet processing */
488#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
489/* UNDI software version */
490#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
491/* NCSI support/handler version */
492#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
Jacob Keller468672b2020-01-09 14:46:09 -0800493/* FW parameter set id */
494#define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
Vasundhara Volam41c0d912020-01-27 04:56:25 -0500495/* RoCE FW version */
496#define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce"
Jacob Kellerc90977a2020-03-11 18:58:16 -0700497/* Firmware bundle identifier */
498#define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800499
Alex Veskerb16ebe92018-07-12 15:13:08 +0300500struct devlink_region;
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800501struct devlink_info_req;
Alex Veskerb16ebe92018-07-12 15:13:08 +0300502
Jacob Kellere8937682020-03-26 11:37:08 -0700503/**
504 * struct devlink_region_ops - Region operations
505 * @name: region name
Jacob Kellera0a09f62020-03-26 11:37:09 -0700506 * @destructor: callback used to free snapshot memory when deleting
Jacob Kellerb9a17abf2020-03-26 11:37:16 -0700507 * @snapshot: callback to request an immediate snapshot. On success,
508 * the data variable must be updated to point to the snapshot data.
509 * The function will be called while the devlink instance lock is
510 * held.
Jacob Kellere8937682020-03-26 11:37:08 -0700511 */
512struct devlink_region_ops {
513 const char *name;
Jacob Kellera0a09f62020-03-26 11:37:09 -0700514 void (*destructor)(const void *data);
Jacob Kellerb9a17abf2020-03-26 11:37:16 -0700515 int (*snapshot)(struct devlink *devlink, struct netlink_ext_ack *extack,
516 u8 **data);
Jacob Kellere8937682020-03-26 11:37:08 -0700517};
518
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200519struct devlink_fmsg;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200520struct devlink_health_reporter;
521
Eran Ben Elisha3167b272019-03-03 10:57:30 +0200522enum devlink_health_reporter_state {
523 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
524 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
525};
526
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200527/**
528 * struct devlink_health_reporter_ops - Reporter operations
529 * @name: reporter name
530 * @recover: callback to recover from reported error
531 * if priv_ctx is NULL, run a full recover
532 * @dump: callback to dump an object
533 * if priv_ctx is NULL, run a full dump
534 * @diagnose: callback to diagnose the current status
535 */
536
537struct devlink_health_reporter_ops {
538 char *name;
539 int (*recover)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200540 void *priv_ctx, struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200541 int (*dump)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200542 struct devlink_fmsg *fmsg, void *priv_ctx,
543 struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200544 int (*diagnose)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200545 struct devlink_fmsg *fmsg,
546 struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200547};
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200548
Ido Schimmel0f420b62019-08-17 16:28:17 +0300549/**
Ido Schimmel1e8c6612020-03-30 22:38:18 +0300550 * struct devlink_trap_policer - Immutable packet trap policer attributes.
551 * @id: Policer identifier.
552 * @init_rate: Initial rate in packets / sec.
553 * @init_burst: Initial burst size in packets.
554 * @max_rate: Maximum rate.
555 * @min_rate: Minimum rate.
556 * @max_burst: Maximum burst size.
557 * @min_burst: Minimum burst size.
558 *
559 * Describes immutable attributes of packet trap policers that drivers register
560 * with devlink.
561 */
562struct devlink_trap_policer {
563 u32 id;
564 u64 init_rate;
565 u64 init_burst;
566 u64 max_rate;
567 u64 min_rate;
568 u64 max_burst;
569 u64 min_burst;
570};
571
572/**
Ido Schimmel0f420b62019-08-17 16:28:17 +0300573 * struct devlink_trap_group - Immutable packet trap group attributes.
574 * @name: Trap group name.
575 * @id: Trap group identifier.
576 * @generic: Whether the trap group is generic or not.
Ido Schimmelf9f54392020-03-30 22:38:21 +0300577 * @init_policer_id: Initial policer identifier.
Ido Schimmel0f420b62019-08-17 16:28:17 +0300578 *
579 * Describes immutable attributes of packet trap groups that drivers register
580 * with devlink.
581 */
582struct devlink_trap_group {
583 const char *name;
584 u16 id;
585 bool generic;
Ido Schimmelf9f54392020-03-30 22:38:21 +0300586 u32 init_policer_id;
Ido Schimmel0f420b62019-08-17 16:28:17 +0300587};
588
589#define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
Jiri Pirko85b05892020-02-25 11:45:19 +0100590#define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
Ido Schimmel0f420b62019-08-17 16:28:17 +0300591
592/**
593 * struct devlink_trap - Immutable packet trap attributes.
594 * @type: Trap type.
595 * @init_action: Initial trap action.
596 * @generic: Whether the trap is generic or not.
597 * @id: Trap identifier.
598 * @name: Trap name.
Ido Schimmel107f1672020-03-22 20:48:30 +0200599 * @init_group_id: Initial group identifier.
Ido Schimmel0f420b62019-08-17 16:28:17 +0300600 * @metadata_cap: Metadata types that can be provided by the trap.
601 *
602 * Describes immutable attributes of packet traps that drivers register with
603 * devlink.
604 */
605struct devlink_trap {
606 enum devlink_trap_type type;
607 enum devlink_trap_action init_action;
608 bool generic;
609 u16 id;
610 const char *name;
Ido Schimmel107f1672020-03-22 20:48:30 +0200611 u16 init_group_id;
Ido Schimmel0f420b62019-08-17 16:28:17 +0300612 u32 metadata_cap;
613};
614
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300615/* All traps must be documented in
Jacob Kellerf4bdd712020-01-09 14:46:10 -0800616 * Documentation/networking/devlink/devlink-trap.rst
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300617 */
Ido Schimmel0f420b62019-08-17 16:28:17 +0300618enum devlink_trap_generic_id {
Ido Schimmel391203a2019-08-17 16:28:18 +0300619 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
620 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
621 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
622 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
623 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
624 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
625 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
626 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
627 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
Amit Cohen6896cc42019-11-07 18:42:09 +0200628 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
629 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
630 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
631 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
632 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
633 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
634 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
635 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
636 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
Amit Cohen3b063ae2019-11-07 18:42:14 +0200637 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
638 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
639 DEVLINK_TRAP_GENERIC_ID_RPF,
640 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
641 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
642 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
Amit Cohen95f0ead2020-01-19 15:00:48 +0200643 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
Amit Cohen13c056e2020-01-19 15:00:54 +0200644 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
Amit Cohenc3cae492020-01-19 15:00:58 +0200645 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100646 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
647 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
Ido Schimmel515eac62020-05-29 21:36:41 +0300648 DEVLINK_TRAP_GENERIC_ID_STP,
649 DEVLINK_TRAP_GENERIC_ID_LACP,
650 DEVLINK_TRAP_GENERIC_ID_LLDP,
651 DEVLINK_TRAP_GENERIC_ID_IGMP_QUERY,
652 DEVLINK_TRAP_GENERIC_ID_IGMP_V1_REPORT,
653 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_REPORT,
654 DEVLINK_TRAP_GENERIC_ID_IGMP_V3_REPORT,
655 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_LEAVE,
656 DEVLINK_TRAP_GENERIC_ID_MLD_QUERY,
657 DEVLINK_TRAP_GENERIC_ID_MLD_V1_REPORT,
658 DEVLINK_TRAP_GENERIC_ID_MLD_V2_REPORT,
659 DEVLINK_TRAP_GENERIC_ID_MLD_V1_DONE,
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300660 DEVLINK_TRAP_GENERIC_ID_IPV4_DHCP,
661 DEVLINK_TRAP_GENERIC_ID_IPV6_DHCP,
662 DEVLINK_TRAP_GENERIC_ID_ARP_REQUEST,
663 DEVLINK_TRAP_GENERIC_ID_ARP_RESPONSE,
664 DEVLINK_TRAP_GENERIC_ID_ARP_OVERLAY,
665 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_SOLICIT,
666 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_ADVERT,
667 DEVLINK_TRAP_GENERIC_ID_IPV4_BFD,
668 DEVLINK_TRAP_GENERIC_ID_IPV6_BFD,
669 DEVLINK_TRAP_GENERIC_ID_IPV4_OSPF,
670 DEVLINK_TRAP_GENERIC_ID_IPV6_OSPF,
671 DEVLINK_TRAP_GENERIC_ID_IPV4_BGP,
672 DEVLINK_TRAP_GENERIC_ID_IPV6_BGP,
673 DEVLINK_TRAP_GENERIC_ID_IPV4_VRRP,
674 DEVLINK_TRAP_GENERIC_ID_IPV6_VRRP,
675 DEVLINK_TRAP_GENERIC_ID_IPV4_PIM,
676 DEVLINK_TRAP_GENERIC_ID_IPV6_PIM,
677 DEVLINK_TRAP_GENERIC_ID_UC_LB,
678 DEVLINK_TRAP_GENERIC_ID_LOCAL_ROUTE,
679 DEVLINK_TRAP_GENERIC_ID_EXTERNAL_ROUTE,
680 DEVLINK_TRAP_GENERIC_ID_IPV6_UC_DIP_LINK_LOCAL_SCOPE,
681 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_NODES,
682 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_ROUTERS,
683 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_SOLICIT,
684 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ADVERT,
685 DEVLINK_TRAP_GENERIC_ID_IPV6_REDIRECT,
686 DEVLINK_TRAP_GENERIC_ID_IPV4_ROUTER_ALERT,
687 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ALERT,
688 DEVLINK_TRAP_GENERIC_ID_PTP_EVENT,
689 DEVLINK_TRAP_GENERIC_ID_PTP_GENERAL,
Ido Schimmel391203a2019-08-17 16:28:18 +0300690
Ido Schimmel0f420b62019-08-17 16:28:17 +0300691 /* Add new generic trap IDs above */
692 __DEVLINK_TRAP_GENERIC_ID_MAX,
693 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
694};
695
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300696/* All trap groups must be documented in
Jacob Kellerf4bdd712020-01-09 14:46:10 -0800697 * Documentation/networking/devlink/devlink-trap.rst
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300698 */
Ido Schimmel0f420b62019-08-17 16:28:17 +0300699enum devlink_trap_group_generic_id {
Ido Schimmel391203a2019-08-17 16:28:18 +0300700 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
701 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
Ido Schimmel678eb192020-05-29 21:36:36 +0300702 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_EXCEPTIONS,
Ido Schimmel391203a2019-08-17 16:28:18 +0300703 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
Amit Cohen13c056e2020-01-19 15:00:54 +0200704 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100705 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
Ido Schimmel515eac62020-05-29 21:36:41 +0300706 DEVLINK_TRAP_GROUP_GENERIC_ID_STP,
707 DEVLINK_TRAP_GROUP_GENERIC_ID_LACP,
708 DEVLINK_TRAP_GROUP_GENERIC_ID_LLDP,
709 DEVLINK_TRAP_GROUP_GENERIC_ID_MC_SNOOPING,
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300710 DEVLINK_TRAP_GROUP_GENERIC_ID_DHCP,
711 DEVLINK_TRAP_GROUP_GENERIC_ID_NEIGH_DISCOVERY,
712 DEVLINK_TRAP_GROUP_GENERIC_ID_BFD,
713 DEVLINK_TRAP_GROUP_GENERIC_ID_OSPF,
714 DEVLINK_TRAP_GROUP_GENERIC_ID_BGP,
715 DEVLINK_TRAP_GROUP_GENERIC_ID_VRRP,
716 DEVLINK_TRAP_GROUP_GENERIC_ID_PIM,
717 DEVLINK_TRAP_GROUP_GENERIC_ID_UC_LB,
718 DEVLINK_TRAP_GROUP_GENERIC_ID_LOCAL_DELIVERY,
719 DEVLINK_TRAP_GROUP_GENERIC_ID_IPV6,
720 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_EVENT,
721 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_GENERAL,
Ido Schimmel391203a2019-08-17 16:28:18 +0300722
Ido Schimmel0f420b62019-08-17 16:28:17 +0300723 /* Add new generic trap group IDs above */
724 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
725 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
726 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
727};
728
Ido Schimmel391203a2019-08-17 16:28:18 +0300729#define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
730 "source_mac_is_multicast"
731#define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
732 "vlan_tag_mismatch"
733#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
734 "ingress_vlan_filter"
735#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
736 "ingress_spanning_tree_filter"
737#define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
738 "port_list_is_empty"
739#define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
740 "port_loopback_filter"
741#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
742 "blackhole_route"
743#define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
744 "ttl_value_is_too_small"
745#define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
746 "tail_drop"
Amit Cohen6896cc42019-11-07 18:42:09 +0200747#define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
748 "non_ip"
749#define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
750 "uc_dip_over_mc_dmac"
751#define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
752 "dip_is_loopback_address"
753#define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
754 "sip_is_mc"
755#define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
756 "sip_is_loopback_address"
757#define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
758 "ip_header_corrupted"
759#define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
760 "ipv4_sip_is_limited_bc"
761#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
762 "ipv6_mc_dip_reserved_scope"
763#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
764 "ipv6_mc_dip_interface_local_scope"
Amit Cohen3b063ae2019-11-07 18:42:14 +0200765#define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
766 "mtu_value_is_too_small"
767#define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
768 "unresolved_neigh"
769#define DEVLINK_TRAP_GENERIC_NAME_RPF \
770 "mc_reverse_path_forwarding"
771#define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
772 "reject_route"
773#define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
774 "ipv4_lpm_miss"
775#define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
776 "ipv6_lpm_miss"
Amit Cohen95f0ead2020-01-19 15:00:48 +0200777#define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
778 "non_routable_packet"
Amit Cohen13c056e2020-01-19 15:00:54 +0200779#define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
780 "decap_error"
Amit Cohenc3cae492020-01-19 15:00:58 +0200781#define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
782 "overlay_smac_is_mc"
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100783#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
784 "ingress_flow_action_drop"
785#define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
786 "egress_flow_action_drop"
Ido Schimmel515eac62020-05-29 21:36:41 +0300787#define DEVLINK_TRAP_GENERIC_NAME_STP \
788 "stp"
789#define DEVLINK_TRAP_GENERIC_NAME_LACP \
790 "lacp"
791#define DEVLINK_TRAP_GENERIC_NAME_LLDP \
792 "lldp"
793#define DEVLINK_TRAP_GENERIC_NAME_IGMP_QUERY \
794 "igmp_query"
795#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V1_REPORT \
796 "igmp_v1_report"
797#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_REPORT \
798 "igmp_v2_report"
799#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V3_REPORT \
800 "igmp_v3_report"
801#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_LEAVE \
802 "igmp_v2_leave"
803#define DEVLINK_TRAP_GENERIC_NAME_MLD_QUERY \
804 "mld_query"
805#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_REPORT \
806 "mld_v1_report"
807#define DEVLINK_TRAP_GENERIC_NAME_MLD_V2_REPORT \
808 "mld_v2_report"
809#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_DONE \
810 "mld_v1_done"
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300811#define DEVLINK_TRAP_GENERIC_NAME_IPV4_DHCP \
812 "ipv4_dhcp"
813#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DHCP \
814 "ipv6_dhcp"
815#define DEVLINK_TRAP_GENERIC_NAME_ARP_REQUEST \
816 "arp_request"
817#define DEVLINK_TRAP_GENERIC_NAME_ARP_RESPONSE \
818 "arp_response"
819#define DEVLINK_TRAP_GENERIC_NAME_ARP_OVERLAY \
820 "arp_overlay"
821#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_SOLICIT \
822 "ipv6_neigh_solicit"
823#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_ADVERT \
824 "ipv6_neigh_advert"
825#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BFD \
826 "ipv4_bfd"
827#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BFD \
828 "ipv6_bfd"
829#define DEVLINK_TRAP_GENERIC_NAME_IPV4_OSPF \
830 "ipv4_ospf"
831#define DEVLINK_TRAP_GENERIC_NAME_IPV6_OSPF \
832 "ipv6_ospf"
833#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BGP \
834 "ipv4_bgp"
835#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BGP \
836 "ipv6_bgp"
837#define DEVLINK_TRAP_GENERIC_NAME_IPV4_VRRP \
838 "ipv4_vrrp"
839#define DEVLINK_TRAP_GENERIC_NAME_IPV6_VRRP \
840 "ipv6_vrrp"
841#define DEVLINK_TRAP_GENERIC_NAME_IPV4_PIM \
842 "ipv4_pim"
843#define DEVLINK_TRAP_GENERIC_NAME_IPV6_PIM \
844 "ipv6_pim"
845#define DEVLINK_TRAP_GENERIC_NAME_UC_LB \
846 "uc_loopback"
847#define DEVLINK_TRAP_GENERIC_NAME_LOCAL_ROUTE \
848 "local_route"
849#define DEVLINK_TRAP_GENERIC_NAME_EXTERNAL_ROUTE \
850 "external_route"
851#define DEVLINK_TRAP_GENERIC_NAME_IPV6_UC_DIP_LINK_LOCAL_SCOPE \
852 "ipv6_uc_dip_link_local_scope"
853#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_NODES \
854 "ipv6_dip_all_nodes"
855#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_ROUTERS \
856 "ipv6_dip_all_routers"
857#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_SOLICIT \
858 "ipv6_router_solicit"
859#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ADVERT \
860 "ipv6_router_advert"
861#define DEVLINK_TRAP_GENERIC_NAME_IPV6_REDIRECT \
862 "ipv6_redirect"
863#define DEVLINK_TRAP_GENERIC_NAME_IPV4_ROUTER_ALERT \
864 "ipv4_router_alert"
865#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ALERT \
866 "ipv6_router_alert"
867#define DEVLINK_TRAP_GENERIC_NAME_PTP_EVENT \
868 "ptp_event"
869#define DEVLINK_TRAP_GENERIC_NAME_PTP_GENERAL \
870 "ptp_general"
Ido Schimmel391203a2019-08-17 16:28:18 +0300871
872#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
873 "l2_drops"
874#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
875 "l3_drops"
Ido Schimmel678eb192020-05-29 21:36:36 +0300876#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_EXCEPTIONS \
877 "l3_exceptions"
Ido Schimmel391203a2019-08-17 16:28:18 +0300878#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
879 "buffer_drops"
Amit Cohen13c056e2020-01-19 15:00:54 +0200880#define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
881 "tunnel_drops"
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100882#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
883 "acl_drops"
Ido Schimmel515eac62020-05-29 21:36:41 +0300884#define DEVLINK_TRAP_GROUP_GENERIC_NAME_STP \
885 "stp"
886#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LACP \
887 "lacp"
888#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LLDP \
889 "lldp"
890#define DEVLINK_TRAP_GROUP_GENERIC_NAME_MC_SNOOPING \
891 "mc_snooping"
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300892#define DEVLINK_TRAP_GROUP_GENERIC_NAME_DHCP \
893 "dhcp"
894#define DEVLINK_TRAP_GROUP_GENERIC_NAME_NEIGH_DISCOVERY \
895 "neigh_discovery"
896#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BFD \
897 "bfd"
898#define DEVLINK_TRAP_GROUP_GENERIC_NAME_OSPF \
899 "ospf"
900#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BGP \
901 "bgp"
902#define DEVLINK_TRAP_GROUP_GENERIC_NAME_VRRP \
903 "vrrp"
904#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PIM \
905 "pim"
906#define DEVLINK_TRAP_GROUP_GENERIC_NAME_UC_LB \
907 "uc_loopback"
908#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LOCAL_DELIVERY \
909 "local_delivery"
910#define DEVLINK_TRAP_GROUP_GENERIC_NAME_IPV6 \
911 "ipv6"
912#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_EVENT \
913 "ptp_event"
914#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_GENERAL \
915 "ptp_general"
Ido Schimmel391203a2019-08-17 16:28:18 +0300916
Ido Schimmel107f1672020-03-22 20:48:30 +0200917#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \
918 _metadata_cap) \
Ido Schimmel0f420b62019-08-17 16:28:17 +0300919 { \
920 .type = DEVLINK_TRAP_TYPE_##_type, \
921 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
922 .generic = true, \
923 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
924 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
Ido Schimmel107f1672020-03-22 20:48:30 +0200925 .init_group_id = _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +0300926 .metadata_cap = _metadata_cap, \
927 }
928
Ido Schimmel107f1672020-03-22 20:48:30 +0200929#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +0300930 _metadata_cap) \
931 { \
932 .type = DEVLINK_TRAP_TYPE_##_type, \
933 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
934 .generic = false, \
935 .id = _id, \
936 .name = _name, \
Ido Schimmel107f1672020-03-22 20:48:30 +0200937 .init_group_id = _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +0300938 .metadata_cap = _metadata_cap, \
939 }
940
Ido Schimmelf9f54392020-03-30 22:38:21 +0300941#define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id) \
Ido Schimmel0f420b62019-08-17 16:28:17 +0300942 { \
943 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
944 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
945 .generic = true, \
Ido Schimmelf9f54392020-03-30 22:38:21 +0300946 .init_policer_id = _policer_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +0300947 }
948
Ido Schimmel1e8c6612020-03-30 22:38:18 +0300949#define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate, \
950 _max_burst, _min_burst) \
951 { \
952 .id = _id, \
953 .init_rate = _rate, \
954 .init_burst = _burst, \
955 .max_rate = _max_rate, \
956 .min_rate = _min_rate, \
957 .max_burst = _max_burst, \
958 .min_burst = _min_burst, \
959 }
960
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100961struct devlink_ops {
Jiri Pirko070c63f2019-10-03 11:49:39 +0200962 int (*reload_down)(struct devlink *devlink, bool netns_change,
Jiri Pirko97691062019-09-12 10:49:45 +0200963 struct netlink_ext_ack *extack);
964 int (*reload_up)(struct devlink *devlink,
965 struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100966 int (*port_type_set)(struct devlink_port *devlink_port,
967 enum devlink_port_type port_type);
968 int (*port_split)(struct devlink *devlink, unsigned int port_index,
David Ahernac0fc8a2018-06-05 08:14:09 -0700969 unsigned int count, struct netlink_ext_ack *extack);
970 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
971 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200972 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
973 u16 pool_index,
974 struct devlink_sb_pool_info *pool_info);
975 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
976 u16 pool_index, u32 size,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000977 enum devlink_sb_threshold_type threshold_type,
978 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200979 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
980 unsigned int sb_index, u16 pool_index,
981 u32 *p_threshold);
982 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
983 unsigned int sb_index, u16 pool_index,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000984 u32 threshold, struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200985 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
986 unsigned int sb_index,
987 u16 tc_index,
988 enum devlink_sb_pool_type pool_type,
989 u16 *p_pool_index, u32 *p_threshold);
990 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
991 unsigned int sb_index,
992 u16 tc_index,
993 enum devlink_sb_pool_type pool_type,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000994 u16 pool_index, u32 threshold,
995 struct netlink_ext_ack *extack);
Jiri Pirkodf38daf2016-04-14 18:19:14 +0200996 int (*sb_occ_snapshot)(struct devlink *devlink,
997 unsigned int sb_index);
998 int (*sb_occ_max_clear)(struct devlink *devlink,
999 unsigned int sb_index);
1000 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
1001 unsigned int sb_index, u16 pool_index,
1002 u32 *p_cur, u32 *p_max);
1003 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
1004 unsigned int sb_index,
1005 u16 tc_index,
1006 enum devlink_sb_pool_type pool_type,
1007 u32 *p_cur, u32 *p_max);
Or Gerlitz08f4b592016-07-01 14:51:01 +03001008
1009 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +03001010 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
1011 struct netlink_ext_ack *extack);
Roi Dayan59bfde02016-11-22 23:09:57 +02001012 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +03001013 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
1014 struct netlink_ext_ack *extack);
Leon Romanovsky98fdbea2019-06-12 15:20:11 +03001015 int (*eswitch_encap_mode_get)(struct devlink *devlink,
1016 enum devlink_eswitch_encap_mode *p_encap_mode);
1017 int (*eswitch_encap_mode_set)(struct devlink *devlink,
1018 enum devlink_eswitch_encap_mode encap_mode,
Eli Britsteindb7ff192018-08-15 16:02:18 +03001019 struct netlink_ext_ack *extack);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -08001020 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
1021 struct netlink_ext_ack *extack);
Jakub Kicinski76726cc2019-02-14 13:40:44 -08001022 int (*flash_update)(struct devlink *devlink, const char *file_name,
1023 const char *component,
1024 struct netlink_ext_ack *extack);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001025 /**
1026 * @trap_init: Trap initialization function.
1027 *
1028 * Should be used by device drivers to initialize the trap in the
1029 * underlying device. Drivers should also store the provided trap
1030 * context, so that they could efficiently pass it to
1031 * devlink_trap_report() when the trap is triggered.
1032 */
1033 int (*trap_init)(struct devlink *devlink,
1034 const struct devlink_trap *trap, void *trap_ctx);
1035 /**
1036 * @trap_fini: Trap de-initialization function.
1037 *
1038 * Should be used by device drivers to de-initialize the trap in the
1039 * underlying device.
1040 */
1041 void (*trap_fini)(struct devlink *devlink,
1042 const struct devlink_trap *trap, void *trap_ctx);
1043 /**
1044 * @trap_action_set: Trap action set function.
1045 */
1046 int (*trap_action_set)(struct devlink *devlink,
1047 const struct devlink_trap *trap,
1048 enum devlink_trap_action action);
1049 /**
1050 * @trap_group_init: Trap group initialization function.
1051 *
1052 * Should be used by device drivers to initialize the trap group in the
1053 * underlying device.
1054 */
1055 int (*trap_group_init)(struct devlink *devlink,
1056 const struct devlink_trap_group *group);
Ido Schimmel1e8c6612020-03-30 22:38:18 +03001057 /**
Ido Schimmelc0648752020-03-30 22:38:22 +03001058 * @trap_group_set: Trap group parameters set function.
1059 *
1060 * Note: @policer can be NULL when a policer is being unbound from
1061 * @group.
1062 */
1063 int (*trap_group_set)(struct devlink *devlink,
1064 const struct devlink_trap_group *group,
1065 const struct devlink_trap_policer *policer);
1066 /**
Ido Schimmel1e8c6612020-03-30 22:38:18 +03001067 * @trap_policer_init: Trap policer initialization function.
1068 *
1069 * Should be used by device drivers to initialize the trap policer in
1070 * the underlying device.
1071 */
1072 int (*trap_policer_init)(struct devlink *devlink,
1073 const struct devlink_trap_policer *policer);
1074 /**
1075 * @trap_policer_fini: Trap policer de-initialization function.
1076 *
1077 * Should be used by device drivers to de-initialize the trap policer
1078 * in the underlying device.
1079 */
1080 void (*trap_policer_fini)(struct devlink *devlink,
1081 const struct devlink_trap_policer *policer);
1082 /**
1083 * @trap_policer_set: Trap policer parameters set function.
1084 */
1085 int (*trap_policer_set)(struct devlink *devlink,
1086 const struct devlink_trap_policer *policer,
1087 u64 rate, u64 burst,
1088 struct netlink_ext_ack *extack);
1089 /**
1090 * @trap_policer_counter_get: Trap policer counter get function.
1091 *
1092 * Should be used by device drivers to report number of packets dropped
1093 * by the policer.
1094 */
1095 int (*trap_policer_counter_get)(struct devlink *devlink,
1096 const struct devlink_trap_policer *policer,
1097 u64 *p_drops);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001098};
1099
1100static inline void *devlink_priv(struct devlink *devlink)
1101{
1102 BUG_ON(!devlink);
1103 return &devlink->priv;
1104}
1105
1106static inline struct devlink *priv_to_devlink(void *priv)
1107{
1108 BUG_ON(!priv);
1109 return container_of(priv, struct devlink, priv);
1110}
1111
Jiri Pirko5dc37bb2019-03-28 13:56:36 +01001112static inline struct devlink_port *
1113netdev_to_devlink_port(struct net_device *dev)
1114{
1115 if (dev->netdev_ops->ndo_get_devlink_port)
1116 return dev->netdev_ops->ndo_get_devlink_port(dev);
1117 return NULL;
1118}
1119
Jakub Kicinskib473b0d2019-02-25 19:34:03 -08001120static inline struct devlink *netdev_to_devlink(struct net_device *dev)
1121{
Jiri Pirko5dc37bb2019-03-28 13:56:36 +01001122 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
1123
1124 if (devlink_port)
1125 return devlink_port->devlink;
Jakub Kicinskib473b0d2019-02-25 19:34:03 -08001126 return NULL;
1127}
1128
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001129struct ib_device;
1130
Jiri Pirko471f8942019-10-03 11:49:31 +02001131struct net *devlink_net(const struct devlink *devlink);
Jiri Pirko8273fd82019-10-05 08:10:31 +02001132void devlink_net_set(struct devlink *devlink, struct net *net);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001133struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
1134int devlink_register(struct devlink *devlink, struct device *dev);
1135void devlink_unregister(struct devlink *devlink);
Jiri Pirkoa0c76342019-11-08 21:42:43 +01001136void devlink_reload_enable(struct devlink *devlink);
1137void devlink_reload_disable(struct devlink *devlink);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001138void devlink_free(struct devlink *devlink);
1139int devlink_port_register(struct devlink *devlink,
1140 struct devlink_port *devlink_port,
1141 unsigned int port_index);
1142void devlink_port_unregister(struct devlink_port *devlink_port);
1143void devlink_port_type_eth_set(struct devlink_port *devlink_port,
1144 struct net_device *netdev);
1145void devlink_port_type_ib_set(struct devlink_port *devlink_port,
1146 struct ib_device *ibdev);
1147void devlink_port_type_clear(struct devlink_port *devlink_port);
Jiri Pirkob9ffcba2018-05-18 09:29:00 +02001148void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +02001149 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +02001150 u32 port_number, bool split,
Jiri Pirkobec52672019-04-03 14:24:16 +02001151 u32 split_subport_number,
1152 const unsigned char *switch_id,
1153 unsigned char switch_id_len);
Parav Pandit98fd2d62019-07-08 23:17:37 -05001154void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
1155 const unsigned char *switch_id,
1156 unsigned char switch_id_len, u16 pf);
Parav Pandite41b6bf2019-07-08 23:17:38 -05001157void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
1158 const unsigned char *switch_id,
1159 unsigned char switch_id_len,
1160 u16 pf, u16 vf);
Jiri Pirkobf797472016-04-14 18:19:13 +02001161int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
1162 u32 size, u16 ingress_pools_count,
1163 u16 egress_pools_count, u16 ingress_tc_count,
1164 u16 egress_tc_count);
1165void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +02001166int devlink_dpipe_table_register(struct devlink *devlink,
1167 const char *table_name,
1168 struct devlink_dpipe_table_ops *table_ops,
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +02001169 void *priv, bool counter_control_extern);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +02001170void devlink_dpipe_table_unregister(struct devlink *devlink,
1171 const char *table_name);
1172int devlink_dpipe_headers_register(struct devlink *devlink,
1173 struct devlink_dpipe_headers *dpipe_headers);
1174void devlink_dpipe_headers_unregister(struct devlink *devlink);
1175bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
1176 const char *table_name);
1177int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
1178int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
1179 struct devlink_dpipe_entry *entry);
1180int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
Arkadi Sharshevsky35807322017-08-24 08:40:03 +02001181void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +02001182int devlink_dpipe_action_put(struct sk_buff *skb,
1183 struct devlink_dpipe_action *action);
1184int devlink_dpipe_match_put(struct sk_buff *skb,
1185 struct devlink_dpipe_match *match);
Arkadi Sharshevsky11770092017-08-24 08:39:59 +02001186extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
Arkadi Sharshevsky3fb886e2017-08-24 08:40:00 +02001187extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
Arkadi Sharshevsky1797f5b2017-08-31 17:59:12 +02001188extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001189
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001190int devlink_resource_register(struct devlink *devlink,
1191 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001192 u64 resource_size,
1193 u64 resource_id,
1194 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +02001195 const struct devlink_resource_size_params *size_params);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001196void devlink_resources_unregister(struct devlink *devlink,
1197 struct devlink_resource *resource);
1198int devlink_resource_size_get(struct devlink *devlink,
1199 u64 resource_id,
1200 u64 *p_resource_size);
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +01001201int devlink_dpipe_table_resource_set(struct devlink *devlink,
1202 const char *table_name, u64 resource_id,
1203 u64 resource_units);
Jiri Pirkofc56be42018-04-05 22:13:21 +02001204void devlink_resource_occ_get_register(struct devlink *devlink,
1205 u64 resource_id,
1206 devlink_resource_occ_get_t *occ_get,
1207 void *occ_get_priv);
1208void devlink_resource_occ_get_unregister(struct devlink *devlink,
1209 u64 resource_id);
Moshe Shemesheabaef12018-07-04 14:30:28 +03001210int devlink_params_register(struct devlink *devlink,
1211 const struct devlink_param *params,
1212 size_t params_count);
1213void devlink_params_unregister(struct devlink *devlink,
1214 const struct devlink_param *params,
1215 size_t params_count);
Jiri Pirko7c62cfb2019-02-07 11:22:45 +00001216void devlink_params_publish(struct devlink *devlink);
1217void devlink_params_unpublish(struct devlink *devlink);
Vasundhara Volam39e61602019-01-28 18:00:20 +05301218int devlink_port_params_register(struct devlink_port *devlink_port,
1219 const struct devlink_param *params,
1220 size_t params_count);
1221void devlink_port_params_unregister(struct devlink_port *devlink_port,
1222 const struct devlink_param *params,
1223 size_t params_count);
Moshe Shemeshec01aeb2018-07-04 14:30:31 +03001224int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
1225 union devlink_param_value *init_val);
1226int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
1227 union devlink_param_value init_val);
Vasundhara Volamffd19b92019-01-28 18:00:23 +05301228int
1229devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
1230 u32 param_id,
1231 union devlink_param_value *init_val);
Vasundhara Volam5473a7b2019-01-28 18:00:24 +05301232int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
1233 u32 param_id,
1234 union devlink_param_value init_val);
Moshe Shemeshea601e12018-07-04 14:30:32 +03001235void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
Vasundhara Volamc1e5786d2019-01-28 18:00:25 +05301236void devlink_port_param_value_changed(struct devlink_port *devlink_port,
1237 u32 param_id);
Moshe Shemeshbde74ad12018-10-10 16:09:27 +03001238void devlink_param_value_str_fill(union devlink_param_value *dst_val,
1239 const char *src);
Jacob Kellere8937682020-03-26 11:37:08 -07001240struct devlink_region *
1241devlink_region_create(struct devlink *devlink,
1242 const struct devlink_region_ops *ops,
1243 u32 region_max_snapshots, u64 region_size);
Alex Veskerb16ebe92018-07-12 15:13:08 +03001244void devlink_region_destroy(struct devlink_region *region);
Jacob Keller7ef19d32020-03-26 11:37:14 -07001245int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
Jacob Keller12102432020-03-26 11:37:15 -07001246void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
Jiri Pirko3a5e5232019-08-09 15:27:15 +02001247int devlink_region_snapshot_create(struct devlink_region *region,
Jacob Kellera0a09f62020-03-26 11:37:09 -07001248 u8 *data, u32 snapshot_id);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -08001249int devlink_info_serial_number_put(struct devlink_info_req *req,
1250 const char *sn);
1251int devlink_info_driver_name_put(struct devlink_info_req *req,
1252 const char *name);
Jakub Kicinskifc6fae72019-01-31 10:50:41 -08001253int devlink_info_version_fixed_put(struct devlink_info_req *req,
1254 const char *version_name,
1255 const char *version_value);
1256int devlink_info_version_stored_put(struct devlink_info_req *req,
1257 const char *version_name,
1258 const char *version_value);
1259int devlink_info_version_running_put(struct devlink_info_req *req,
1260 const char *version_name,
1261 const char *version_value);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001262
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001263int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
1264int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
1265
1266int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1267int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1268
1269int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1270 const char *name);
1271int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
Aya Levin573ed902020-02-11 14:32:42 -08001272int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1273 const char *name);
1274int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001275
1276int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
1277int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
1278int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1279int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
1280int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
Aya Levin573ed902020-02-11 14:32:42 -08001281int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1282 u16 value_len);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001283
1284int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1285 bool value);
1286int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1287 u8 value);
1288int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1289 u32 value);
1290int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1291 u64 value);
1292int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1293 const char *value);
1294int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
Aya Levine2cde862019-11-12 14:07:49 +02001295 const void *value, u32 value_len);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001296
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001297struct devlink_health_reporter *
1298devlink_health_reporter_create(struct devlink *devlink,
1299 const struct devlink_health_reporter_ops *ops,
Eran Ben Elishaba7d16c2020-03-29 14:05:54 +03001300 u64 graceful_period, void *priv);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001301void
1302devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1303
1304void *
1305devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
Eran Ben Elishac8e1da02019-02-07 11:36:34 +02001306int devlink_health_report(struct devlink_health_reporter *reporter,
1307 const char *msg, void *priv_ctx);
Eran Ben Elisha3167b272019-03-03 10:57:30 +02001308void
1309devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1310 enum devlink_health_reporter_state state);
Vikas Gupta6181e5c2020-01-02 21:18:09 +05301311void
1312devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001313
Jiri Pirko2670ac22019-09-12 10:49:46 +02001314bool devlink_is_reload_failed(const struct devlink *devlink);
1315
Jiri Pirko191ed202019-06-04 15:40:40 +02001316void devlink_flash_update_begin_notify(struct devlink *devlink);
1317void devlink_flash_update_end_notify(struct devlink *devlink);
1318void devlink_flash_update_status_notify(struct devlink *devlink,
1319 const char *status_msg,
1320 const char *component,
1321 unsigned long done,
1322 unsigned long total);
1323
Ido Schimmel0f420b62019-08-17 16:28:17 +03001324int devlink_traps_register(struct devlink *devlink,
1325 const struct devlink_trap *traps,
1326 size_t traps_count, void *priv);
1327void devlink_traps_unregister(struct devlink *devlink,
1328 const struct devlink_trap *traps,
1329 size_t traps_count);
Jiri Pirko5a2e1062020-02-25 11:45:21 +01001330void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
1331 void *trap_ctx, struct devlink_port *in_devlink_port,
1332 const struct flow_action_cookie *fa_cookie);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001333void *devlink_trap_ctx_priv(void *trap_ctx);
Ido Schimmel95ad9552020-03-22 20:48:26 +02001334int devlink_trap_groups_register(struct devlink *devlink,
1335 const struct devlink_trap_group *groups,
1336 size_t groups_count);
1337void devlink_trap_groups_unregister(struct devlink *devlink,
1338 const struct devlink_trap_group *groups,
1339 size_t groups_count);
Ido Schimmel1e8c6612020-03-30 22:38:18 +03001340int
1341devlink_trap_policers_register(struct devlink *devlink,
1342 const struct devlink_trap_policer *policers,
1343 size_t policers_count);
1344void
1345devlink_trap_policers_unregister(struct devlink *devlink,
1346 const struct devlink_trap_policer *policers,
1347 size_t policers_count);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001348
Jiri Pirkof6b19b32019-03-24 11:14:38 +01001349#if IS_ENABLED(CONFIG_NET_DEVLINK)
1350
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -08001351void devlink_compat_running_version(struct net_device *dev,
1352 char *buf, size_t len);
1353int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
Jiri Pirkoaf3836d2019-03-28 13:56:37 +01001354int devlink_compat_phys_port_name_get(struct net_device *dev,
1355 char *name, size_t len);
Jiri Pirko7e1146e2019-04-03 14:24:17 +02001356int devlink_compat_switch_id_get(struct net_device *dev,
1357 struct netdev_phys_item_id *ppid);
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -08001358
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001359#else
1360
Eran Ben Elisha3167b272019-03-03 10:57:30 +02001361static inline void
Jakub Kicinskiddb6e992019-01-31 10:50:47 -08001362devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1363{
1364}
Jakub Kicinski4eceba12019-02-14 13:40:45 -08001365
1366static inline int
1367devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1368{
1369 return -EOPNOTSUPP;
1370}
Jiri Pirkof6b19b32019-03-24 11:14:38 +01001371
Jiri Pirkoaf3836d2019-03-28 13:56:37 +01001372static inline int
1373devlink_compat_phys_port_name_get(struct net_device *dev,
1374 char *name, size_t len)
1375{
1376 return -EOPNOTSUPP;
1377}
1378
Jiri Pirko7e1146e2019-04-03 14:24:17 +02001379static inline int
1380devlink_compat_switch_id_get(struct net_device *dev,
1381 struct netdev_phys_item_id *ppid)
1382{
1383 return -EOPNOTSUPP;
1384}
1385
Jakub Kicinskiddb6e992019-01-31 10:50:47 -08001386#endif
1387
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001388#endif /* _NET_DEVLINK_H_ */