blob: 08b757753e1c7a36e4b63c12c249be0d45bd6f39 [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>
19#include <uapi/linux/devlink.h>
20
21struct devlink_ops;
22
23struct devlink {
24 struct list_head list;
25 struct list_head port_list;
Jiri Pirkobf797472016-04-14 18:19:13 +020026 struct list_head sb_list;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020027 struct list_head dpipe_table_list;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +010028 struct list_head resource_list;
Moshe Shemesheabaef12018-07-04 14:30:28 +030029 struct list_head param_list;
Alex Veskerb16ebe92018-07-12 15:13:08 +030030 struct list_head region_list;
Alex Veskerccadfa42018-07-12 15:13:09 +030031 u32 snapshot_id;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +020032 struct list_head reporter_list;
Moshe Shemeshb587bda2019-04-29 12:41:45 +030033 struct mutex reporters_lock; /* protects reporter_list */
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020034 struct devlink_dpipe_headers *dpipe_headers;
Ido Schimmel0f420b62019-08-17 16:28:17 +030035 struct list_head trap_list;
36 struct list_head trap_group_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010037 const struct devlink_ops *ops;
38 struct device *dev;
39 possible_net_t _net;
Arkadi Sharshevsky2406e7e2018-01-15 08:59:02 +010040 struct mutex lock;
Jiri Pirkoa0c76342019-11-08 21:42:43 +010041 u8 reload_failed:1,
42 reload_enabled:1,
43 registered:1;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010044 char priv[0] __aligned(NETDEV_ALIGN);
45};
46
Parav Pandit378ef012019-07-08 23:17:35 -050047struct devlink_port_phys_attrs {
48 u32 port_number; /* Same value as "split group".
49 * A physical port which is visible to the user
50 * for a given port flavour.
51 */
52 u32 split_subport_number;
53};
54
Parav Pandit98fd2d62019-07-08 23:17:37 -050055struct devlink_port_pci_pf_attrs {
56 u16 pf; /* Associated PCI PF for this port. */
57};
58
Parav Pandite41b6bf2019-07-08 23:17:38 -050059struct devlink_port_pci_vf_attrs {
60 u16 pf; /* Associated PCI PF for this port. */
61 u16 vf; /* Associated PCI VF for of the PCI PF for this port. */
62};
63
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020064struct devlink_port_attrs {
Jiri Pirko407dd702019-04-03 14:24:15 +020065 u8 set:1,
Jiri Pirkobec52672019-04-03 14:24:16 +020066 split:1,
67 switch_port:1;
Jiri Pirko5ec13802018-05-18 09:29:01 +020068 enum devlink_port_flavour flavour;
Jiri Pirkobec52672019-04-03 14:24:16 +020069 struct netdev_phys_item_id switch_id;
Parav Pandit378ef012019-07-08 23:17:35 -050070 union {
71 struct devlink_port_phys_attrs phys;
Parav Pandit98fd2d62019-07-08 23:17:37 -050072 struct devlink_port_pci_pf_attrs pci_pf;
Parav Pandite41b6bf2019-07-08 23:17:38 -050073 struct devlink_port_pci_vf_attrs pci_vf;
Parav Pandit378ef012019-07-08 23:17:35 -050074 };
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020075};
76
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010077struct devlink_port {
78 struct list_head list;
Vasundhara Volam39e61602019-01-28 18:00:20 +053079 struct list_head param_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010080 struct devlink *devlink;
Parav Panditc7282b52019-08-30 05:39:44 -050081 unsigned int index;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010082 bool registered;
Jiri Pirkob8f97552019-03-24 11:14:37 +010083 spinlock_t type_lock; /* Protects type and type_dev
84 * pointer consistency.
85 */
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010086 enum devlink_port_type type;
87 enum devlink_port_type desired_type;
88 void *type_dev;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020089 struct devlink_port_attrs attrs;
Jiri Pirko136bf272019-05-23 10:43:35 +020090 struct delayed_work type_warn_dw;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010091};
92
Jiri Pirkobf797472016-04-14 18:19:13 +020093struct devlink_sb_pool_info {
94 enum devlink_sb_pool_type pool_type;
95 u32 size;
96 enum devlink_sb_threshold_type threshold_type;
Jakub Kicinskibff57312019-02-01 17:56:28 -080097 u32 cell_size;
Jiri Pirkobf797472016-04-14 18:19:13 +020098};
99
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200100/**
101 * struct devlink_dpipe_field - dpipe field object
102 * @name: field name
103 * @id: index inside the headers field array
104 * @bitwidth: bitwidth
105 * @mapping_type: mapping type
106 */
107struct devlink_dpipe_field {
108 const char *name;
109 unsigned int id;
110 unsigned int bitwidth;
111 enum devlink_dpipe_field_mapping_type mapping_type;
112};
113
114/**
115 * struct devlink_dpipe_header - dpipe header object
116 * @name: header name
117 * @id: index, global/local detrmined by global bit
118 * @fields: fields
119 * @fields_count: number of fields
120 * @global: indicates if header is shared like most protocol header
121 * or driver specific
122 */
123struct devlink_dpipe_header {
124 const char *name;
125 unsigned int id;
126 struct devlink_dpipe_field *fields;
127 unsigned int fields_count;
128 bool global;
129};
130
131/**
132 * struct devlink_dpipe_match - represents match operation
133 * @type: type of match
134 * @header_index: header index (packets can have several headers of same
135 * type like in case of tunnels)
136 * @header: header
137 * @fieled_id: field index
138 */
139struct devlink_dpipe_match {
140 enum devlink_dpipe_match_type type;
141 unsigned int header_index;
142 struct devlink_dpipe_header *header;
143 unsigned int field_id;
144};
145
146/**
147 * struct devlink_dpipe_action - represents action operation
148 * @type: type of action
149 * @header_index: header index (packets can have several headers of same
150 * type like in case of tunnels)
151 * @header: header
152 * @fieled_id: field index
153 */
154struct devlink_dpipe_action {
155 enum devlink_dpipe_action_type type;
156 unsigned int header_index;
157 struct devlink_dpipe_header *header;
158 unsigned int field_id;
159};
160
161/**
162 * struct devlink_dpipe_value - represents value of match/action
163 * @action: action
164 * @match: match
165 * @mapping_value: in case the field has some mapping this value
166 * specified the mapping value
167 * @mapping_valid: specify if mapping value is valid
168 * @value_size: value size
169 * @value: value
170 * @mask: bit mask
171 */
172struct devlink_dpipe_value {
173 union {
174 struct devlink_dpipe_action *action;
175 struct devlink_dpipe_match *match;
176 };
177 unsigned int mapping_value;
178 bool mapping_valid;
179 unsigned int value_size;
180 void *value;
181 void *mask;
182};
183
184/**
185 * struct devlink_dpipe_entry - table entry object
186 * @index: index of the entry in the table
187 * @match_values: match values
188 * @matche_values_count: count of matches tuples
189 * @action_values: actions values
190 * @action_values_count: count of actions values
191 * @counter: value of counter
192 * @counter_valid: Specify if value is valid from hardware
193 */
194struct devlink_dpipe_entry {
195 u64 index;
196 struct devlink_dpipe_value *match_values;
197 unsigned int match_values_count;
198 struct devlink_dpipe_value *action_values;
199 unsigned int action_values_count;
200 u64 counter;
201 bool counter_valid;
202};
203
204/**
205 * struct devlink_dpipe_dump_ctx - context provided to driver in order
206 * to dump
207 * @info: info
208 * @cmd: devlink command
209 * @skb: skb
210 * @nest: top attribute
211 * @hdr: hdr
212 */
213struct devlink_dpipe_dump_ctx {
214 struct genl_info *info;
215 enum devlink_command cmd;
216 struct sk_buff *skb;
217 struct nlattr *nest;
218 void *hdr;
219};
220
221struct devlink_dpipe_table_ops;
222
223/**
224 * struct devlink_dpipe_table - table object
225 * @priv: private
226 * @name: table name
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200227 * @counters_enabled: indicates if counters are active
228 * @counter_control_extern: indicates if counter control is in dpipe or
229 * external tool
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100230 * @resource_valid: Indicate that the resource id is valid
231 * @resource_id: relative resource this table is related to
232 * @resource_units: number of resource's unit consumed per table's entry
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200233 * @table_ops: table operations
234 * @rcu: rcu
235 */
236struct devlink_dpipe_table {
237 void *priv;
238 struct list_head list;
239 const char *name;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200240 bool counters_enabled;
241 bool counter_control_extern;
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100242 bool resource_valid;
243 u64 resource_id;
244 u64 resource_units;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200245 struct devlink_dpipe_table_ops *table_ops;
246 struct rcu_head rcu;
247};
248
249/**
250 * struct devlink_dpipe_table_ops - dpipe_table ops
251 * @actions_dump - dumps all tables actions
252 * @matches_dump - dumps all tables matches
253 * @entries_dump - dumps all active entries in the table
254 * @counters_set_update - when changing the counter status hardware sync
255 * maybe needed to allocate/free counter related
256 * resources
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200257 * @size_get - get size
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200258 */
259struct devlink_dpipe_table_ops {
260 int (*actions_dump)(void *priv, struct sk_buff *skb);
261 int (*matches_dump)(void *priv, struct sk_buff *skb);
262 int (*entries_dump)(void *priv, bool counters_enabled,
263 struct devlink_dpipe_dump_ctx *dump_ctx);
264 int (*counters_set_update)(void *priv, bool enable);
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200265 u64 (*size_get)(void *priv);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200266};
267
268/**
269 * struct devlink_dpipe_headers - dpipe headers
270 * @headers - header array can be shared (global bit) or driver specific
271 * @headers_count - count of headers
272 */
273struct devlink_dpipe_headers {
274 struct devlink_dpipe_header **headers;
275 unsigned int headers_count;
276};
277
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100278/**
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100279 * struct devlink_resource_size_params - resource's size parameters
280 * @size_min: minimum size which can be set
281 * @size_max: maximum size which can be set
282 * @size_granularity: size granularity
283 * @size_unit: resource's basic unit
284 */
285struct devlink_resource_size_params {
286 u64 size_min;
287 u64 size_max;
288 u64 size_granularity;
289 enum devlink_resource_unit unit;
290};
291
Jiri Pirko77d27092018-02-28 13:12:09 +0100292static inline void
293devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
294 u64 size_min, u64 size_max,
295 u64 size_granularity,
296 enum devlink_resource_unit unit)
297{
298 size_params->size_min = size_min;
299 size_params->size_max = size_max;
300 size_params->size_granularity = size_granularity;
301 size_params->unit = unit;
302}
303
Jiri Pirkofc56be42018-04-05 22:13:21 +0200304typedef u64 devlink_resource_occ_get_t(void *priv);
305
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100306/**
307 * struct devlink_resource - devlink resource
308 * @name: name of the resource
309 * @id: id, per devlink instance
310 * @size: size of the resource
311 * @size_new: updated size of the resource, reload is needed
312 * @size_valid: valid in case the total size of the resource is valid
313 * including its children
314 * @parent: parent resource
315 * @size_params: size parameters
316 * @list: parent list
317 * @resource_list: list of child resources
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100318 */
319struct devlink_resource {
320 const char *name;
321 u64 id;
322 u64 size;
323 u64 size_new;
324 bool size_valid;
325 struct devlink_resource *parent;
Jiri Pirko77d27092018-02-28 13:12:09 +0100326 struct devlink_resource_size_params size_params;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100327 struct list_head list;
328 struct list_head resource_list;
Jiri Pirkofc56be42018-04-05 22:13:21 +0200329 devlink_resource_occ_get_t *occ_get;
330 void *occ_get_priv;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100331};
332
333#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
334
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300335#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
Moshe Shemesheabaef12018-07-04 14:30:28 +0300336enum devlink_param_type {
337 DEVLINK_PARAM_TYPE_U8,
338 DEVLINK_PARAM_TYPE_U16,
339 DEVLINK_PARAM_TYPE_U32,
340 DEVLINK_PARAM_TYPE_STRING,
341 DEVLINK_PARAM_TYPE_BOOL,
342};
343
344union devlink_param_value {
345 u8 vu8;
346 u16 vu16;
347 u32 vu32;
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300348 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
Moshe Shemesheabaef12018-07-04 14:30:28 +0300349 bool vbool;
350};
351
352struct devlink_param_gset_ctx {
353 union devlink_param_value val;
354 enum devlink_param_cmode cmode;
355};
356
357/**
358 * struct devlink_param - devlink configuration parameter data
359 * @name: name of the parameter
360 * @generic: indicates if the parameter is generic or driver specific
361 * @type: parameter type
362 * @supported_cmodes: bitmap of supported configuration modes
363 * @get: get parameter value, used for runtime and permanent
364 * configuration modes
365 * @set: set parameter value, used for runtime and permanent
366 * configuration modes
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300367 * @validate: validate input value is applicable (within value range, etc.)
Moshe Shemesheabaef12018-07-04 14:30:28 +0300368 *
369 * This struct should be used by the driver to fill the data for
370 * a parameter it registers.
371 */
372struct devlink_param {
373 u32 id;
374 const char *name;
375 bool generic;
376 enum devlink_param_type type;
377 unsigned long supported_cmodes;
378 int (*get)(struct devlink *devlink, u32 id,
379 struct devlink_param_gset_ctx *ctx);
380 int (*set)(struct devlink *devlink, u32 id,
381 struct devlink_param_gset_ctx *ctx);
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300382 int (*validate)(struct devlink *devlink, u32 id,
383 union devlink_param_value val,
384 struct netlink_ext_ack *extack);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300385};
386
387struct devlink_param_item {
388 struct list_head list;
389 const struct devlink_param *param;
390 union devlink_param_value driverinit_value;
391 bool driverinit_value_valid;
Jiri Pirko7c62cfb2019-02-07 11:22:45 +0000392 bool published;
Moshe Shemesheabaef12018-07-04 14:30:28 +0300393};
394
395enum devlink_param_generic_id {
Moshe Shemesh036467c2018-07-04 14:30:33 +0300396 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
397 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300398 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
Alex Veskerf6a698852018-07-12 15:13:17 +0300399 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
Vasundhara Volame3b51062018-10-04 11:13:44 +0530400 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530401 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
Vasundhara Volam16511782018-10-04 11:13:46 +0530402 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
Shalom Toledo846e9802018-12-03 07:58:59 +0000403 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
Dirk van der Merwe5bbd21d2019-09-09 00:54:18 +0100404 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
Michael Guralnik6c7295e2019-11-08 23:45:20 +0000405 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
Moshe Shemesheabaef12018-07-04 14:30:28 +0300406
407 /* add new param generic ids above here*/
408 __DEVLINK_PARAM_GENERIC_ID_MAX,
409 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
410};
411
Moshe Shemesh036467c2018-07-04 14:30:33 +0300412#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
413#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
414
415#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
416#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
417
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300418#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
419#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
420
Alex Veskerf6a698852018-07-12 15:13:17 +0300421#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
422#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
423
Vasundhara Volame3b51062018-10-04 11:13:44 +0530424#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
425#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
426
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530427#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
428#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
429
Vasundhara Volam16511782018-10-04 11:13:46 +0530430#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
431#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
432
Shalom Toledo846e9802018-12-03 07:58:59 +0000433#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
434#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
435
Dirk van der Merwe5bbd21d2019-09-09 00:54:18 +0100436#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
437 "reset_dev_on_drv_probe"
438#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
439
Michael Guralnik6c7295e2019-11-08 23:45:20 +0000440#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
441#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
442
Moshe Shemesh036467c2018-07-04 14:30:33 +0300443#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
444{ \
445 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
446 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
447 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
448 .generic = true, \
449 .supported_cmodes = _cmodes, \
450 .get = _get, \
451 .set = _set, \
452 .validate = _validate, \
453}
454
455#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
456{ \
457 .id = _id, \
458 .name = _name, \
459 .type = _type, \
460 .supported_cmodes = _cmodes, \
461 .get = _get, \
462 .set = _set, \
463 .validate = _validate, \
464}
465
Jakub Kicinski785bd552019-01-31 10:50:42 -0800466/* Part number, identifier of board design */
467#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
468/* Revision of board design */
469#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
Jakub Kicinski14fd1902019-02-10 19:35:29 -0800470/* Maker of the board */
471#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800472
Shannon Nelson7d5aa9a2019-09-03 15:28:03 -0700473/* Part number, identifier of asic design */
474#define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
475/* Revision of asic design */
476#define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
477
478/* Overall FW version */
479#define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800480/* Control processor FW version */
481#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
482/* Data path microcode controlling high-speed packet processing */
483#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
484/* UNDI software version */
485#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
486/* NCSI support/handler version */
487#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
Jacob Keller468672b2020-01-09 14:46:09 -0800488/* FW parameter set id */
489#define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800490
Alex Veskerb16ebe92018-07-12 15:13:08 +0300491struct devlink_region;
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800492struct devlink_info_req;
Alex Veskerb16ebe92018-07-12 15:13:08 +0300493
Alex Veskerd7e52722018-07-12 15:13:10 +0300494typedef void devlink_snapshot_data_dest_t(const void *data);
495
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200496struct devlink_fmsg;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200497struct devlink_health_reporter;
498
Eran Ben Elisha3167b272019-03-03 10:57:30 +0200499enum devlink_health_reporter_state {
500 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
501 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
502};
503
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200504/**
505 * struct devlink_health_reporter_ops - Reporter operations
506 * @name: reporter name
507 * @recover: callback to recover from reported error
508 * if priv_ctx is NULL, run a full recover
509 * @dump: callback to dump an object
510 * if priv_ctx is NULL, run a full dump
511 * @diagnose: callback to diagnose the current status
512 */
513
514struct devlink_health_reporter_ops {
515 char *name;
516 int (*recover)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200517 void *priv_ctx, struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200518 int (*dump)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200519 struct devlink_fmsg *fmsg, void *priv_ctx,
520 struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200521 int (*diagnose)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200522 struct devlink_fmsg *fmsg,
523 struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200524};
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200525
Ido Schimmel0f420b62019-08-17 16:28:17 +0300526/**
527 * struct devlink_trap_group - Immutable packet trap group attributes.
528 * @name: Trap group name.
529 * @id: Trap group identifier.
530 * @generic: Whether the trap group is generic or not.
531 *
532 * Describes immutable attributes of packet trap groups that drivers register
533 * with devlink.
534 */
535struct devlink_trap_group {
536 const char *name;
537 u16 id;
538 bool generic;
539};
540
541#define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
542
543/**
544 * struct devlink_trap - Immutable packet trap attributes.
545 * @type: Trap type.
546 * @init_action: Initial trap action.
547 * @generic: Whether the trap is generic or not.
548 * @id: Trap identifier.
549 * @name: Trap name.
550 * @group: Immutable packet trap group attributes.
551 * @metadata_cap: Metadata types that can be provided by the trap.
552 *
553 * Describes immutable attributes of packet traps that drivers register with
554 * devlink.
555 */
556struct devlink_trap {
557 enum devlink_trap_type type;
558 enum devlink_trap_action init_action;
559 bool generic;
560 u16 id;
561 const char *name;
562 struct devlink_trap_group group;
563 u32 metadata_cap;
564};
565
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300566/* All traps must be documented in
Jacob Kellerf4bdd712020-01-09 14:46:10 -0800567 * Documentation/networking/devlink/devlink-trap.rst
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300568 */
Ido Schimmel0f420b62019-08-17 16:28:17 +0300569enum devlink_trap_generic_id {
Ido Schimmel391203a2019-08-17 16:28:18 +0300570 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
571 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
572 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
573 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
574 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
575 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
576 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
577 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
578 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
Amit Cohen6896cc42019-11-07 18:42:09 +0200579 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
580 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
581 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
582 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
583 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
584 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
585 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
586 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
587 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
Amit Cohen3b063ae2019-11-07 18:42:14 +0200588 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
589 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
590 DEVLINK_TRAP_GENERIC_ID_RPF,
591 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
592 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
593 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
Amit Cohen95f0ead2020-01-19 15:00:48 +0200594 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
Ido Schimmel391203a2019-08-17 16:28:18 +0300595
Ido Schimmel0f420b62019-08-17 16:28:17 +0300596 /* Add new generic trap IDs above */
597 __DEVLINK_TRAP_GENERIC_ID_MAX,
598 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
599};
600
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300601/* All trap groups must be documented in
Jacob Kellerf4bdd712020-01-09 14:46:10 -0800602 * Documentation/networking/devlink/devlink-trap.rst
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300603 */
Ido Schimmel0f420b62019-08-17 16:28:17 +0300604enum devlink_trap_group_generic_id {
Ido Schimmel391203a2019-08-17 16:28:18 +0300605 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
606 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
607 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
608
Ido Schimmel0f420b62019-08-17 16:28:17 +0300609 /* Add new generic trap group IDs above */
610 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
611 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
612 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
613};
614
Ido Schimmel391203a2019-08-17 16:28:18 +0300615#define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
616 "source_mac_is_multicast"
617#define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
618 "vlan_tag_mismatch"
619#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
620 "ingress_vlan_filter"
621#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
622 "ingress_spanning_tree_filter"
623#define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
624 "port_list_is_empty"
625#define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
626 "port_loopback_filter"
627#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
628 "blackhole_route"
629#define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
630 "ttl_value_is_too_small"
631#define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
632 "tail_drop"
Amit Cohen6896cc42019-11-07 18:42:09 +0200633#define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
634 "non_ip"
635#define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
636 "uc_dip_over_mc_dmac"
637#define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
638 "dip_is_loopback_address"
639#define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
640 "sip_is_mc"
641#define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
642 "sip_is_loopback_address"
643#define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
644 "ip_header_corrupted"
645#define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
646 "ipv4_sip_is_limited_bc"
647#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
648 "ipv6_mc_dip_reserved_scope"
649#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
650 "ipv6_mc_dip_interface_local_scope"
Amit Cohen3b063ae2019-11-07 18:42:14 +0200651#define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
652 "mtu_value_is_too_small"
653#define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
654 "unresolved_neigh"
655#define DEVLINK_TRAP_GENERIC_NAME_RPF \
656 "mc_reverse_path_forwarding"
657#define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
658 "reject_route"
659#define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
660 "ipv4_lpm_miss"
661#define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
662 "ipv6_lpm_miss"
Amit Cohen95f0ead2020-01-19 15:00:48 +0200663#define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
664 "non_routable_packet"
Ido Schimmel391203a2019-08-17 16:28:18 +0300665
666#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
667 "l2_drops"
668#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
669 "l3_drops"
670#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
671 "buffer_drops"
672
Ido Schimmel0f420b62019-08-17 16:28:17 +0300673#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group, _metadata_cap) \
674 { \
675 .type = DEVLINK_TRAP_TYPE_##_type, \
676 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
677 .generic = true, \
678 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
679 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
680 .group = _group, \
681 .metadata_cap = _metadata_cap, \
682 }
683
684#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group, \
685 _metadata_cap) \
686 { \
687 .type = DEVLINK_TRAP_TYPE_##_type, \
688 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
689 .generic = false, \
690 .id = _id, \
691 .name = _name, \
692 .group = _group, \
693 .metadata_cap = _metadata_cap, \
694 }
695
696#define DEVLINK_TRAP_GROUP_GENERIC(_id) \
697 { \
698 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
699 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
700 .generic = true, \
701 }
702
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100703struct devlink_ops {
Jiri Pirko070c63f2019-10-03 11:49:39 +0200704 int (*reload_down)(struct devlink *devlink, bool netns_change,
Jiri Pirko97691062019-09-12 10:49:45 +0200705 struct netlink_ext_ack *extack);
706 int (*reload_up)(struct devlink *devlink,
707 struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100708 int (*port_type_set)(struct devlink_port *devlink_port,
709 enum devlink_port_type port_type);
710 int (*port_split)(struct devlink *devlink, unsigned int port_index,
David Ahernac0fc8a2018-06-05 08:14:09 -0700711 unsigned int count, struct netlink_ext_ack *extack);
712 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
713 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200714 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
715 u16 pool_index,
716 struct devlink_sb_pool_info *pool_info);
717 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
718 u16 pool_index, u32 size,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000719 enum devlink_sb_threshold_type threshold_type,
720 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200721 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
722 unsigned int sb_index, u16 pool_index,
723 u32 *p_threshold);
724 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
725 unsigned int sb_index, u16 pool_index,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000726 u32 threshold, struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200727 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
728 unsigned int sb_index,
729 u16 tc_index,
730 enum devlink_sb_pool_type pool_type,
731 u16 *p_pool_index, u32 *p_threshold);
732 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
733 unsigned int sb_index,
734 u16 tc_index,
735 enum devlink_sb_pool_type pool_type,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000736 u16 pool_index, u32 threshold,
737 struct netlink_ext_ack *extack);
Jiri Pirkodf38daf2016-04-14 18:19:14 +0200738 int (*sb_occ_snapshot)(struct devlink *devlink,
739 unsigned int sb_index);
740 int (*sb_occ_max_clear)(struct devlink *devlink,
741 unsigned int sb_index);
742 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
743 unsigned int sb_index, u16 pool_index,
744 u32 *p_cur, u32 *p_max);
745 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
746 unsigned int sb_index,
747 u16 tc_index,
748 enum devlink_sb_pool_type pool_type,
749 u32 *p_cur, u32 *p_max);
Or Gerlitz08f4b592016-07-01 14:51:01 +0300750
751 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300752 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
753 struct netlink_ext_ack *extack);
Roi Dayan59bfde02016-11-22 23:09:57 +0200754 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300755 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
756 struct netlink_ext_ack *extack);
Leon Romanovsky98fdbea2019-06-12 15:20:11 +0300757 int (*eswitch_encap_mode_get)(struct devlink *devlink,
758 enum devlink_eswitch_encap_mode *p_encap_mode);
759 int (*eswitch_encap_mode_set)(struct devlink *devlink,
760 enum devlink_eswitch_encap_mode encap_mode,
Eli Britsteindb7ff192018-08-15 16:02:18 +0300761 struct netlink_ext_ack *extack);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800762 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
763 struct netlink_ext_ack *extack);
Jakub Kicinski76726cc2019-02-14 13:40:44 -0800764 int (*flash_update)(struct devlink *devlink, const char *file_name,
765 const char *component,
766 struct netlink_ext_ack *extack);
Ido Schimmel0f420b62019-08-17 16:28:17 +0300767 /**
768 * @trap_init: Trap initialization function.
769 *
770 * Should be used by device drivers to initialize the trap in the
771 * underlying device. Drivers should also store the provided trap
772 * context, so that they could efficiently pass it to
773 * devlink_trap_report() when the trap is triggered.
774 */
775 int (*trap_init)(struct devlink *devlink,
776 const struct devlink_trap *trap, void *trap_ctx);
777 /**
778 * @trap_fini: Trap de-initialization function.
779 *
780 * Should be used by device drivers to de-initialize the trap in the
781 * underlying device.
782 */
783 void (*trap_fini)(struct devlink *devlink,
784 const struct devlink_trap *trap, void *trap_ctx);
785 /**
786 * @trap_action_set: Trap action set function.
787 */
788 int (*trap_action_set)(struct devlink *devlink,
789 const struct devlink_trap *trap,
790 enum devlink_trap_action action);
791 /**
792 * @trap_group_init: Trap group initialization function.
793 *
794 * Should be used by device drivers to initialize the trap group in the
795 * underlying device.
796 */
797 int (*trap_group_init)(struct devlink *devlink,
798 const struct devlink_trap_group *group);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100799};
800
801static inline void *devlink_priv(struct devlink *devlink)
802{
803 BUG_ON(!devlink);
804 return &devlink->priv;
805}
806
807static inline struct devlink *priv_to_devlink(void *priv)
808{
809 BUG_ON(!priv);
810 return container_of(priv, struct devlink, priv);
811}
812
Jiri Pirko5dc37bb2019-03-28 13:56:36 +0100813static inline struct devlink_port *
814netdev_to_devlink_port(struct net_device *dev)
815{
816 if (dev->netdev_ops->ndo_get_devlink_port)
817 return dev->netdev_ops->ndo_get_devlink_port(dev);
818 return NULL;
819}
820
Jakub Kicinskib473b0d2019-02-25 19:34:03 -0800821static inline struct devlink *netdev_to_devlink(struct net_device *dev)
822{
Jiri Pirko5dc37bb2019-03-28 13:56:36 +0100823 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
824
825 if (devlink_port)
826 return devlink_port->devlink;
Jakub Kicinskib473b0d2019-02-25 19:34:03 -0800827 return NULL;
828}
829
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100830struct ib_device;
831
Jiri Pirko471f8942019-10-03 11:49:31 +0200832struct net *devlink_net(const struct devlink *devlink);
Jiri Pirko8273fd82019-10-05 08:10:31 +0200833void devlink_net_set(struct devlink *devlink, struct net *net);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100834struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
835int devlink_register(struct devlink *devlink, struct device *dev);
836void devlink_unregister(struct devlink *devlink);
Jiri Pirkoa0c76342019-11-08 21:42:43 +0100837void devlink_reload_enable(struct devlink *devlink);
838void devlink_reload_disable(struct devlink *devlink);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100839void devlink_free(struct devlink *devlink);
840int devlink_port_register(struct devlink *devlink,
841 struct devlink_port *devlink_port,
842 unsigned int port_index);
843void devlink_port_unregister(struct devlink_port *devlink_port);
844void devlink_port_type_eth_set(struct devlink_port *devlink_port,
845 struct net_device *netdev);
846void devlink_port_type_ib_set(struct devlink_port *devlink_port,
847 struct ib_device *ibdev);
848void devlink_port_type_clear(struct devlink_port *devlink_port);
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200849void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200850 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200851 u32 port_number, bool split,
Jiri Pirkobec52672019-04-03 14:24:16 +0200852 u32 split_subport_number,
853 const unsigned char *switch_id,
854 unsigned char switch_id_len);
Parav Pandit98fd2d62019-07-08 23:17:37 -0500855void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
856 const unsigned char *switch_id,
857 unsigned char switch_id_len, u16 pf);
Parav Pandite41b6bf2019-07-08 23:17:38 -0500858void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
859 const unsigned char *switch_id,
860 unsigned char switch_id_len,
861 u16 pf, u16 vf);
Jiri Pirkobf797472016-04-14 18:19:13 +0200862int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
863 u32 size, u16 ingress_pools_count,
864 u16 egress_pools_count, u16 ingress_tc_count,
865 u16 egress_tc_count);
866void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200867int devlink_dpipe_table_register(struct devlink *devlink,
868 const char *table_name,
869 struct devlink_dpipe_table_ops *table_ops,
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200870 void *priv, bool counter_control_extern);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200871void devlink_dpipe_table_unregister(struct devlink *devlink,
872 const char *table_name);
873int devlink_dpipe_headers_register(struct devlink *devlink,
874 struct devlink_dpipe_headers *dpipe_headers);
875void devlink_dpipe_headers_unregister(struct devlink *devlink);
876bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
877 const char *table_name);
878int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
879int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
880 struct devlink_dpipe_entry *entry);
881int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200882void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200883int devlink_dpipe_action_put(struct sk_buff *skb,
884 struct devlink_dpipe_action *action);
885int devlink_dpipe_match_put(struct sk_buff *skb,
886 struct devlink_dpipe_match *match);
Arkadi Sharshevsky11770092017-08-24 08:39:59 +0200887extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
Arkadi Sharshevsky3fb886e2017-08-24 08:40:00 +0200888extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
Arkadi Sharshevsky1797f5b2017-08-31 17:59:12 +0200889extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100890
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100891int devlink_resource_register(struct devlink *devlink,
892 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100893 u64 resource_size,
894 u64 resource_id,
895 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200896 const struct devlink_resource_size_params *size_params);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100897void devlink_resources_unregister(struct devlink *devlink,
898 struct devlink_resource *resource);
899int devlink_resource_size_get(struct devlink *devlink,
900 u64 resource_id,
901 u64 *p_resource_size);
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100902int devlink_dpipe_table_resource_set(struct devlink *devlink,
903 const char *table_name, u64 resource_id,
904 u64 resource_units);
Jiri Pirkofc56be42018-04-05 22:13:21 +0200905void devlink_resource_occ_get_register(struct devlink *devlink,
906 u64 resource_id,
907 devlink_resource_occ_get_t *occ_get,
908 void *occ_get_priv);
909void devlink_resource_occ_get_unregister(struct devlink *devlink,
910 u64 resource_id);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300911int devlink_params_register(struct devlink *devlink,
912 const struct devlink_param *params,
913 size_t params_count);
914void devlink_params_unregister(struct devlink *devlink,
915 const struct devlink_param *params,
916 size_t params_count);
Jiri Pirko7c62cfb2019-02-07 11:22:45 +0000917void devlink_params_publish(struct devlink *devlink);
918void devlink_params_unpublish(struct devlink *devlink);
Vasundhara Volam39e61602019-01-28 18:00:20 +0530919int devlink_port_params_register(struct devlink_port *devlink_port,
920 const struct devlink_param *params,
921 size_t params_count);
922void devlink_port_params_unregister(struct devlink_port *devlink_port,
923 const struct devlink_param *params,
924 size_t params_count);
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300925int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
926 union devlink_param_value *init_val);
927int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
928 union devlink_param_value init_val);
Vasundhara Volamffd19b92019-01-28 18:00:23 +0530929int
930devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
931 u32 param_id,
932 union devlink_param_value *init_val);
Vasundhara Volam5473a7b2019-01-28 18:00:24 +0530933int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
934 u32 param_id,
935 union devlink_param_value init_val);
Moshe Shemeshea601e12018-07-04 14:30:32 +0300936void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
Vasundhara Volamc1e5786d2019-01-28 18:00:25 +0530937void devlink_port_param_value_changed(struct devlink_port *devlink_port,
938 u32 param_id);
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300939void devlink_param_value_str_fill(union devlink_param_value *dst_val,
940 const char *src);
Alex Veskerb16ebe92018-07-12 15:13:08 +0300941struct devlink_region *devlink_region_create(struct devlink *devlink,
942 const char *region_name,
943 u32 region_max_snapshots,
944 u64 region_size);
945void devlink_region_destroy(struct devlink_region *region);
Alex Veskerccadfa42018-07-12 15:13:09 +0300946u32 devlink_region_shapshot_id_get(struct devlink *devlink);
Jiri Pirko3a5e5232019-08-09 15:27:15 +0200947int devlink_region_snapshot_create(struct devlink_region *region,
Alex Veskerd7e52722018-07-12 15:13:10 +0300948 u8 *data, u32 snapshot_id,
949 devlink_snapshot_data_dest_t *data_destructor);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800950int devlink_info_serial_number_put(struct devlink_info_req *req,
951 const char *sn);
952int devlink_info_driver_name_put(struct devlink_info_req *req,
953 const char *name);
Jakub Kicinskifc6fae72019-01-31 10:50:41 -0800954int devlink_info_version_fixed_put(struct devlink_info_req *req,
955 const char *version_name,
956 const char *version_value);
957int devlink_info_version_stored_put(struct devlink_info_req *req,
958 const char *version_name,
959 const char *version_value);
960int devlink_info_version_running_put(struct devlink_info_req *req,
961 const char *version_name,
962 const char *version_value);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100963
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200964int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
965int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
966
967int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
968int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
969
970int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
971 const char *name);
972int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
973
974int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
975int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
976int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
977int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
978int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200979
980int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
981 bool value);
982int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
983 u8 value);
984int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
985 u32 value);
986int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
987 u64 value);
988int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
989 const char *value);
990int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
Aya Levine2cde862019-11-12 14:07:49 +0200991 const void *value, u32 value_len);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200992
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200993struct devlink_health_reporter *
994devlink_health_reporter_create(struct devlink *devlink,
995 const struct devlink_health_reporter_ops *ops,
996 u64 graceful_period, bool auto_recover,
997 void *priv);
998void
999devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1000
1001void *
1002devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
Eran Ben Elishac8e1da02019-02-07 11:36:34 +02001003int devlink_health_report(struct devlink_health_reporter *reporter,
1004 const char *msg, void *priv_ctx);
Eran Ben Elisha3167b272019-03-03 10:57:30 +02001005void
1006devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1007 enum devlink_health_reporter_state state);
Vikas Gupta6181e5c2020-01-02 21:18:09 +05301008void
1009devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001010
Jiri Pirko2670ac22019-09-12 10:49:46 +02001011bool devlink_is_reload_failed(const struct devlink *devlink);
1012
Jiri Pirko191ed202019-06-04 15:40:40 +02001013void devlink_flash_update_begin_notify(struct devlink *devlink);
1014void devlink_flash_update_end_notify(struct devlink *devlink);
1015void devlink_flash_update_status_notify(struct devlink *devlink,
1016 const char *status_msg,
1017 const char *component,
1018 unsigned long done,
1019 unsigned long total);
1020
Ido Schimmel0f420b62019-08-17 16:28:17 +03001021int devlink_traps_register(struct devlink *devlink,
1022 const struct devlink_trap *traps,
1023 size_t traps_count, void *priv);
1024void devlink_traps_unregister(struct devlink *devlink,
1025 const struct devlink_trap *traps,
1026 size_t traps_count);
1027void devlink_trap_report(struct devlink *devlink,
1028 struct sk_buff *skb, void *trap_ctx,
1029 struct devlink_port *in_devlink_port);
1030void *devlink_trap_ctx_priv(void *trap_ctx);
1031
Jiri Pirkof6b19b32019-03-24 11:14:38 +01001032#if IS_ENABLED(CONFIG_NET_DEVLINK)
1033
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -08001034void devlink_compat_running_version(struct net_device *dev,
1035 char *buf, size_t len);
1036int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
Jiri Pirkoaf3836d2019-03-28 13:56:37 +01001037int devlink_compat_phys_port_name_get(struct net_device *dev,
1038 char *name, size_t len);
Jiri Pirko7e1146e2019-04-03 14:24:17 +02001039int devlink_compat_switch_id_get(struct net_device *dev,
1040 struct netdev_phys_item_id *ppid);
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -08001041
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001042#else
1043
Eran Ben Elisha3167b272019-03-03 10:57:30 +02001044static inline void
Jakub Kicinskiddb6e992019-01-31 10:50:47 -08001045devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1046{
1047}
Jakub Kicinski4eceba12019-02-14 13:40:45 -08001048
1049static inline int
1050devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1051{
1052 return -EOPNOTSUPP;
1053}
Jiri Pirkof6b19b32019-03-24 11:14:38 +01001054
Jiri Pirkoaf3836d2019-03-28 13:56:37 +01001055static inline int
1056devlink_compat_phys_port_name_get(struct net_device *dev,
1057 char *name, size_t len)
1058{
1059 return -EOPNOTSUPP;
1060}
1061
Jiri Pirko7e1146e2019-04-03 14:24:17 +02001062static inline int
1063devlink_compat_switch_id_get(struct net_device *dev,
1064 struct netdev_phys_item_id *ppid)
1065{
1066 return -EOPNOTSUPP;
1067}
1068
Jakub Kicinskiddb6e992019-01-31 10:50:47 -08001069#endif
1070
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001071#endif /* _NET_DEVLINK_H_ */