blob: 4538c80fe293f52a53d82dd3978f028f13425f8e [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>
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010017#include <net/net_namespace.h>
18#include <uapi/linux/devlink.h>
19
20struct devlink_ops;
21
22struct devlink {
23 struct list_head list;
24 struct list_head port_list;
Jiri Pirkobf797472016-04-14 18:19:13 +020025 struct list_head sb_list;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020026 struct list_head dpipe_table_list;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +010027 struct list_head resource_list;
Moshe Shemesheabaef12018-07-04 14:30:28 +030028 struct list_head param_list;
Alex Veskerb16ebe92018-07-12 15:13:08 +030029 struct list_head region_list;
Alex Veskerccadfa42018-07-12 15:13:09 +030030 u32 snapshot_id;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +020031 struct list_head reporter_list;
Moshe Shemeshb587bda2019-04-29 12:41:45 +030032 struct mutex reporters_lock; /* protects reporter_list */
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020033 struct devlink_dpipe_headers *dpipe_headers;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010034 const struct devlink_ops *ops;
35 struct device *dev;
36 possible_net_t _net;
Arkadi Sharshevsky2406e7e2018-01-15 08:59:02 +010037 struct mutex lock;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010038 char priv[0] __aligned(NETDEV_ALIGN);
39};
40
Parav Pandit378ef012019-07-08 23:17:35 -050041struct devlink_port_phys_attrs {
42 u32 port_number; /* Same value as "split group".
43 * A physical port which is visible to the user
44 * for a given port flavour.
45 */
46 u32 split_subport_number;
47};
48
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020049struct devlink_port_attrs {
Jiri Pirko407dd702019-04-03 14:24:15 +020050 u8 set:1,
Jiri Pirkobec52672019-04-03 14:24:16 +020051 split:1,
52 switch_port:1;
Jiri Pirko5ec13802018-05-18 09:29:01 +020053 enum devlink_port_flavour flavour;
Jiri Pirkobec52672019-04-03 14:24:16 +020054 struct netdev_phys_item_id switch_id;
Parav Pandit378ef012019-07-08 23:17:35 -050055 union {
56 struct devlink_port_phys_attrs phys;
57 };
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020058};
59
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010060struct devlink_port {
61 struct list_head list;
Vasundhara Volam39e61602019-01-28 18:00:20 +053062 struct list_head param_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010063 struct devlink *devlink;
64 unsigned index;
65 bool registered;
Jiri Pirkob8f97552019-03-24 11:14:37 +010066 spinlock_t type_lock; /* Protects type and type_dev
67 * pointer consistency.
68 */
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010069 enum devlink_port_type type;
70 enum devlink_port_type desired_type;
71 void *type_dev;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020072 struct devlink_port_attrs attrs;
Jiri Pirko136bf272019-05-23 10:43:35 +020073 struct delayed_work type_warn_dw;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010074};
75
Jiri Pirkobf797472016-04-14 18:19:13 +020076struct devlink_sb_pool_info {
77 enum devlink_sb_pool_type pool_type;
78 u32 size;
79 enum devlink_sb_threshold_type threshold_type;
Jakub Kicinskibff57312019-02-01 17:56:28 -080080 u32 cell_size;
Jiri Pirkobf797472016-04-14 18:19:13 +020081};
82
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020083/**
84 * struct devlink_dpipe_field - dpipe field object
85 * @name: field name
86 * @id: index inside the headers field array
87 * @bitwidth: bitwidth
88 * @mapping_type: mapping type
89 */
90struct devlink_dpipe_field {
91 const char *name;
92 unsigned int id;
93 unsigned int bitwidth;
94 enum devlink_dpipe_field_mapping_type mapping_type;
95};
96
97/**
98 * struct devlink_dpipe_header - dpipe header object
99 * @name: header name
100 * @id: index, global/local detrmined by global bit
101 * @fields: fields
102 * @fields_count: number of fields
103 * @global: indicates if header is shared like most protocol header
104 * or driver specific
105 */
106struct devlink_dpipe_header {
107 const char *name;
108 unsigned int id;
109 struct devlink_dpipe_field *fields;
110 unsigned int fields_count;
111 bool global;
112};
113
114/**
115 * struct devlink_dpipe_match - represents match operation
116 * @type: type of match
117 * @header_index: header index (packets can have several headers of same
118 * type like in case of tunnels)
119 * @header: header
120 * @fieled_id: field index
121 */
122struct devlink_dpipe_match {
123 enum devlink_dpipe_match_type type;
124 unsigned int header_index;
125 struct devlink_dpipe_header *header;
126 unsigned int field_id;
127};
128
129/**
130 * struct devlink_dpipe_action - represents action operation
131 * @type: type of action
132 * @header_index: header index (packets can have several headers of same
133 * type like in case of tunnels)
134 * @header: header
135 * @fieled_id: field index
136 */
137struct devlink_dpipe_action {
138 enum devlink_dpipe_action_type type;
139 unsigned int header_index;
140 struct devlink_dpipe_header *header;
141 unsigned int field_id;
142};
143
144/**
145 * struct devlink_dpipe_value - represents value of match/action
146 * @action: action
147 * @match: match
148 * @mapping_value: in case the field has some mapping this value
149 * specified the mapping value
150 * @mapping_valid: specify if mapping value is valid
151 * @value_size: value size
152 * @value: value
153 * @mask: bit mask
154 */
155struct devlink_dpipe_value {
156 union {
157 struct devlink_dpipe_action *action;
158 struct devlink_dpipe_match *match;
159 };
160 unsigned int mapping_value;
161 bool mapping_valid;
162 unsigned int value_size;
163 void *value;
164 void *mask;
165};
166
167/**
168 * struct devlink_dpipe_entry - table entry object
169 * @index: index of the entry in the table
170 * @match_values: match values
171 * @matche_values_count: count of matches tuples
172 * @action_values: actions values
173 * @action_values_count: count of actions values
174 * @counter: value of counter
175 * @counter_valid: Specify if value is valid from hardware
176 */
177struct devlink_dpipe_entry {
178 u64 index;
179 struct devlink_dpipe_value *match_values;
180 unsigned int match_values_count;
181 struct devlink_dpipe_value *action_values;
182 unsigned int action_values_count;
183 u64 counter;
184 bool counter_valid;
185};
186
187/**
188 * struct devlink_dpipe_dump_ctx - context provided to driver in order
189 * to dump
190 * @info: info
191 * @cmd: devlink command
192 * @skb: skb
193 * @nest: top attribute
194 * @hdr: hdr
195 */
196struct devlink_dpipe_dump_ctx {
197 struct genl_info *info;
198 enum devlink_command cmd;
199 struct sk_buff *skb;
200 struct nlattr *nest;
201 void *hdr;
202};
203
204struct devlink_dpipe_table_ops;
205
206/**
207 * struct devlink_dpipe_table - table object
208 * @priv: private
209 * @name: table name
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200210 * @counters_enabled: indicates if counters are active
211 * @counter_control_extern: indicates if counter control is in dpipe or
212 * external tool
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100213 * @resource_valid: Indicate that the resource id is valid
214 * @resource_id: relative resource this table is related to
215 * @resource_units: number of resource's unit consumed per table's entry
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200216 * @table_ops: table operations
217 * @rcu: rcu
218 */
219struct devlink_dpipe_table {
220 void *priv;
221 struct list_head list;
222 const char *name;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200223 bool counters_enabled;
224 bool counter_control_extern;
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100225 bool resource_valid;
226 u64 resource_id;
227 u64 resource_units;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200228 struct devlink_dpipe_table_ops *table_ops;
229 struct rcu_head rcu;
230};
231
232/**
233 * struct devlink_dpipe_table_ops - dpipe_table ops
234 * @actions_dump - dumps all tables actions
235 * @matches_dump - dumps all tables matches
236 * @entries_dump - dumps all active entries in the table
237 * @counters_set_update - when changing the counter status hardware sync
238 * maybe needed to allocate/free counter related
239 * resources
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200240 * @size_get - get size
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200241 */
242struct devlink_dpipe_table_ops {
243 int (*actions_dump)(void *priv, struct sk_buff *skb);
244 int (*matches_dump)(void *priv, struct sk_buff *skb);
245 int (*entries_dump)(void *priv, bool counters_enabled,
246 struct devlink_dpipe_dump_ctx *dump_ctx);
247 int (*counters_set_update)(void *priv, bool enable);
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200248 u64 (*size_get)(void *priv);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200249};
250
251/**
252 * struct devlink_dpipe_headers - dpipe headers
253 * @headers - header array can be shared (global bit) or driver specific
254 * @headers_count - count of headers
255 */
256struct devlink_dpipe_headers {
257 struct devlink_dpipe_header **headers;
258 unsigned int headers_count;
259};
260
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100261/**
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100262 * struct devlink_resource_size_params - resource's size parameters
263 * @size_min: minimum size which can be set
264 * @size_max: maximum size which can be set
265 * @size_granularity: size granularity
266 * @size_unit: resource's basic unit
267 */
268struct devlink_resource_size_params {
269 u64 size_min;
270 u64 size_max;
271 u64 size_granularity;
272 enum devlink_resource_unit unit;
273};
274
Jiri Pirko77d27092018-02-28 13:12:09 +0100275static inline void
276devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
277 u64 size_min, u64 size_max,
278 u64 size_granularity,
279 enum devlink_resource_unit unit)
280{
281 size_params->size_min = size_min;
282 size_params->size_max = size_max;
283 size_params->size_granularity = size_granularity;
284 size_params->unit = unit;
285}
286
Jiri Pirkofc56be42018-04-05 22:13:21 +0200287typedef u64 devlink_resource_occ_get_t(void *priv);
288
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100289/**
290 * struct devlink_resource - devlink resource
291 * @name: name of the resource
292 * @id: id, per devlink instance
293 * @size: size of the resource
294 * @size_new: updated size of the resource, reload is needed
295 * @size_valid: valid in case the total size of the resource is valid
296 * including its children
297 * @parent: parent resource
298 * @size_params: size parameters
299 * @list: parent list
300 * @resource_list: list of child resources
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100301 */
302struct devlink_resource {
303 const char *name;
304 u64 id;
305 u64 size;
306 u64 size_new;
307 bool size_valid;
308 struct devlink_resource *parent;
Jiri Pirko77d27092018-02-28 13:12:09 +0100309 struct devlink_resource_size_params size_params;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100310 struct list_head list;
311 struct list_head resource_list;
Jiri Pirkofc56be42018-04-05 22:13:21 +0200312 devlink_resource_occ_get_t *occ_get;
313 void *occ_get_priv;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100314};
315
316#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
317
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300318#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
Moshe Shemesheabaef12018-07-04 14:30:28 +0300319enum devlink_param_type {
320 DEVLINK_PARAM_TYPE_U8,
321 DEVLINK_PARAM_TYPE_U16,
322 DEVLINK_PARAM_TYPE_U32,
323 DEVLINK_PARAM_TYPE_STRING,
324 DEVLINK_PARAM_TYPE_BOOL,
325};
326
327union devlink_param_value {
328 u8 vu8;
329 u16 vu16;
330 u32 vu32;
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300331 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
Moshe Shemesheabaef12018-07-04 14:30:28 +0300332 bool vbool;
333};
334
335struct devlink_param_gset_ctx {
336 union devlink_param_value val;
337 enum devlink_param_cmode cmode;
338};
339
340/**
341 * struct devlink_param - devlink configuration parameter data
342 * @name: name of the parameter
343 * @generic: indicates if the parameter is generic or driver specific
344 * @type: parameter type
345 * @supported_cmodes: bitmap of supported configuration modes
346 * @get: get parameter value, used for runtime and permanent
347 * configuration modes
348 * @set: set parameter value, used for runtime and permanent
349 * configuration modes
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300350 * @validate: validate input value is applicable (within value range, etc.)
Moshe Shemesheabaef12018-07-04 14:30:28 +0300351 *
352 * This struct should be used by the driver to fill the data for
353 * a parameter it registers.
354 */
355struct devlink_param {
356 u32 id;
357 const char *name;
358 bool generic;
359 enum devlink_param_type type;
360 unsigned long supported_cmodes;
361 int (*get)(struct devlink *devlink, u32 id,
362 struct devlink_param_gset_ctx *ctx);
363 int (*set)(struct devlink *devlink, u32 id,
364 struct devlink_param_gset_ctx *ctx);
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300365 int (*validate)(struct devlink *devlink, u32 id,
366 union devlink_param_value val,
367 struct netlink_ext_ack *extack);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300368};
369
370struct devlink_param_item {
371 struct list_head list;
372 const struct devlink_param *param;
373 union devlink_param_value driverinit_value;
374 bool driverinit_value_valid;
Jiri Pirko7c62cfb2019-02-07 11:22:45 +0000375 bool published;
Moshe Shemesheabaef12018-07-04 14:30:28 +0300376};
377
378enum devlink_param_generic_id {
Moshe Shemesh036467c2018-07-04 14:30:33 +0300379 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
380 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300381 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
Alex Veskerf6a698852018-07-12 15:13:17 +0300382 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
Vasundhara Volame3b51062018-10-04 11:13:44 +0530383 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530384 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
Vasundhara Volam16511782018-10-04 11:13:46 +0530385 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
Shalom Toledo846e9802018-12-03 07:58:59 +0000386 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
Moshe Shemesheabaef12018-07-04 14:30:28 +0300387
388 /* add new param generic ids above here*/
389 __DEVLINK_PARAM_GENERIC_ID_MAX,
390 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
391};
392
Moshe Shemesh036467c2018-07-04 14:30:33 +0300393#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
394#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
395
396#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
397#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
398
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300399#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
400#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
401
Alex Veskerf6a698852018-07-12 15:13:17 +0300402#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
403#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
404
Vasundhara Volame3b51062018-10-04 11:13:44 +0530405#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
406#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
407
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530408#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
409#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
410
Vasundhara Volam16511782018-10-04 11:13:46 +0530411#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
412#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
413
Shalom Toledo846e9802018-12-03 07:58:59 +0000414#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
415#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
416
Moshe Shemesh036467c2018-07-04 14:30:33 +0300417#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
418{ \
419 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
420 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
421 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
422 .generic = true, \
423 .supported_cmodes = _cmodes, \
424 .get = _get, \
425 .set = _set, \
426 .validate = _validate, \
427}
428
429#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
430{ \
431 .id = _id, \
432 .name = _name, \
433 .type = _type, \
434 .supported_cmodes = _cmodes, \
435 .get = _get, \
436 .set = _set, \
437 .validate = _validate, \
438}
439
Jakub Kicinski785bd552019-01-31 10:50:42 -0800440/* Part number, identifier of board design */
441#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
442/* Revision of board design */
443#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
Jakub Kicinski14fd1902019-02-10 19:35:29 -0800444/* Maker of the board */
445#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800446
447/* Control processor FW version */
448#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
449/* Data path microcode controlling high-speed packet processing */
450#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
451/* UNDI software version */
452#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
453/* NCSI support/handler version */
454#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
455
Alex Veskerb16ebe92018-07-12 15:13:08 +0300456struct devlink_region;
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800457struct devlink_info_req;
Alex Veskerb16ebe92018-07-12 15:13:08 +0300458
Alex Veskerd7e52722018-07-12 15:13:10 +0300459typedef void devlink_snapshot_data_dest_t(const void *data);
460
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200461struct devlink_fmsg;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200462struct devlink_health_reporter;
463
Eran Ben Elisha3167b272019-03-03 10:57:30 +0200464enum devlink_health_reporter_state {
465 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
466 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
467};
468
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200469/**
470 * struct devlink_health_reporter_ops - Reporter operations
471 * @name: reporter name
472 * @recover: callback to recover from reported error
473 * if priv_ctx is NULL, run a full recover
474 * @dump: callback to dump an object
475 * if priv_ctx is NULL, run a full dump
476 * @diagnose: callback to diagnose the current status
477 */
478
479struct devlink_health_reporter_ops {
480 char *name;
481 int (*recover)(struct devlink_health_reporter *reporter,
482 void *priv_ctx);
483 int (*dump)(struct devlink_health_reporter *reporter,
484 struct devlink_fmsg *fmsg, void *priv_ctx);
485 int (*diagnose)(struct devlink_health_reporter *reporter,
486 struct devlink_fmsg *fmsg);
487};
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200488
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100489struct devlink_ops {
David Ahernac0fc8a2018-06-05 08:14:09 -0700490 int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100491 int (*port_type_set)(struct devlink_port *devlink_port,
492 enum devlink_port_type port_type);
493 int (*port_split)(struct devlink *devlink, unsigned int port_index,
David Ahernac0fc8a2018-06-05 08:14:09 -0700494 unsigned int count, struct netlink_ext_ack *extack);
495 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
496 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200497 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
498 u16 pool_index,
499 struct devlink_sb_pool_info *pool_info);
500 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
501 u16 pool_index, u32 size,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000502 enum devlink_sb_threshold_type threshold_type,
503 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200504 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
505 unsigned int sb_index, u16 pool_index,
506 u32 *p_threshold);
507 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
508 unsigned int sb_index, u16 pool_index,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000509 u32 threshold, struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200510 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
511 unsigned int sb_index,
512 u16 tc_index,
513 enum devlink_sb_pool_type pool_type,
514 u16 *p_pool_index, u32 *p_threshold);
515 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
516 unsigned int sb_index,
517 u16 tc_index,
518 enum devlink_sb_pool_type pool_type,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +0000519 u16 pool_index, u32 threshold,
520 struct netlink_ext_ack *extack);
Jiri Pirkodf38daf2016-04-14 18:19:14 +0200521 int (*sb_occ_snapshot)(struct devlink *devlink,
522 unsigned int sb_index);
523 int (*sb_occ_max_clear)(struct devlink *devlink,
524 unsigned int sb_index);
525 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
526 unsigned int sb_index, u16 pool_index,
527 u32 *p_cur, u32 *p_max);
528 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
529 unsigned int sb_index,
530 u16 tc_index,
531 enum devlink_sb_pool_type pool_type,
532 u32 *p_cur, u32 *p_max);
Or Gerlitz08f4b592016-07-01 14:51:01 +0300533
534 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300535 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
536 struct netlink_ext_ack *extack);
Roi Dayan59bfde02016-11-22 23:09:57 +0200537 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300538 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
539 struct netlink_ext_ack *extack);
Leon Romanovsky98fdbea2019-06-12 15:20:11 +0300540 int (*eswitch_encap_mode_get)(struct devlink *devlink,
541 enum devlink_eswitch_encap_mode *p_encap_mode);
542 int (*eswitch_encap_mode_set)(struct devlink *devlink,
543 enum devlink_eswitch_encap_mode encap_mode,
Eli Britsteindb7ff192018-08-15 16:02:18 +0300544 struct netlink_ext_ack *extack);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800545 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
546 struct netlink_ext_ack *extack);
Jakub Kicinski76726cc2019-02-14 13:40:44 -0800547 int (*flash_update)(struct devlink *devlink, const char *file_name,
548 const char *component,
549 struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100550};
551
552static inline void *devlink_priv(struct devlink *devlink)
553{
554 BUG_ON(!devlink);
555 return &devlink->priv;
556}
557
558static inline struct devlink *priv_to_devlink(void *priv)
559{
560 BUG_ON(!priv);
561 return container_of(priv, struct devlink, priv);
562}
563
Jiri Pirko5dc37bb2019-03-28 13:56:36 +0100564static inline struct devlink_port *
565netdev_to_devlink_port(struct net_device *dev)
566{
567 if (dev->netdev_ops->ndo_get_devlink_port)
568 return dev->netdev_ops->ndo_get_devlink_port(dev);
569 return NULL;
570}
571
Jakub Kicinskib473b0d2019-02-25 19:34:03 -0800572static inline struct devlink *netdev_to_devlink(struct net_device *dev)
573{
Jiri Pirko5dc37bb2019-03-28 13:56:36 +0100574 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
575
576 if (devlink_port)
577 return devlink_port->devlink;
Jakub Kicinskib473b0d2019-02-25 19:34:03 -0800578 return NULL;
579}
580
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100581struct ib_device;
582
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100583struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
584int devlink_register(struct devlink *devlink, struct device *dev);
585void devlink_unregister(struct devlink *devlink);
586void devlink_free(struct devlink *devlink);
587int devlink_port_register(struct devlink *devlink,
588 struct devlink_port *devlink_port,
589 unsigned int port_index);
590void devlink_port_unregister(struct devlink_port *devlink_port);
591void devlink_port_type_eth_set(struct devlink_port *devlink_port,
592 struct net_device *netdev);
593void devlink_port_type_ib_set(struct devlink_port *devlink_port,
594 struct ib_device *ibdev);
595void devlink_port_type_clear(struct devlink_port *devlink_port);
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200596void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200597 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200598 u32 port_number, bool split,
Jiri Pirkobec52672019-04-03 14:24:16 +0200599 u32 split_subport_number,
600 const unsigned char *switch_id,
601 unsigned char switch_id_len);
Jiri Pirkobf797472016-04-14 18:19:13 +0200602int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
603 u32 size, u16 ingress_pools_count,
604 u16 egress_pools_count, u16 ingress_tc_count,
605 u16 egress_tc_count);
606void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200607int devlink_dpipe_table_register(struct devlink *devlink,
608 const char *table_name,
609 struct devlink_dpipe_table_ops *table_ops,
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200610 void *priv, bool counter_control_extern);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200611void devlink_dpipe_table_unregister(struct devlink *devlink,
612 const char *table_name);
613int devlink_dpipe_headers_register(struct devlink *devlink,
614 struct devlink_dpipe_headers *dpipe_headers);
615void devlink_dpipe_headers_unregister(struct devlink *devlink);
616bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
617 const char *table_name);
618int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
619int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
620 struct devlink_dpipe_entry *entry);
621int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200622void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200623int devlink_dpipe_action_put(struct sk_buff *skb,
624 struct devlink_dpipe_action *action);
625int devlink_dpipe_match_put(struct sk_buff *skb,
626 struct devlink_dpipe_match *match);
Arkadi Sharshevsky11770092017-08-24 08:39:59 +0200627extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
Arkadi Sharshevsky3fb886e2017-08-24 08:40:00 +0200628extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
Arkadi Sharshevsky1797f5b2017-08-31 17:59:12 +0200629extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100630
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100631int devlink_resource_register(struct devlink *devlink,
632 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100633 u64 resource_size,
634 u64 resource_id,
635 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200636 const struct devlink_resource_size_params *size_params);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100637void devlink_resources_unregister(struct devlink *devlink,
638 struct devlink_resource *resource);
639int devlink_resource_size_get(struct devlink *devlink,
640 u64 resource_id,
641 u64 *p_resource_size);
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100642int devlink_dpipe_table_resource_set(struct devlink *devlink,
643 const char *table_name, u64 resource_id,
644 u64 resource_units);
Jiri Pirkofc56be42018-04-05 22:13:21 +0200645void devlink_resource_occ_get_register(struct devlink *devlink,
646 u64 resource_id,
647 devlink_resource_occ_get_t *occ_get,
648 void *occ_get_priv);
649void devlink_resource_occ_get_unregister(struct devlink *devlink,
650 u64 resource_id);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300651int devlink_params_register(struct devlink *devlink,
652 const struct devlink_param *params,
653 size_t params_count);
654void devlink_params_unregister(struct devlink *devlink,
655 const struct devlink_param *params,
656 size_t params_count);
Jiri Pirko7c62cfb2019-02-07 11:22:45 +0000657void devlink_params_publish(struct devlink *devlink);
658void devlink_params_unpublish(struct devlink *devlink);
Vasundhara Volam39e61602019-01-28 18:00:20 +0530659int devlink_port_params_register(struct devlink_port *devlink_port,
660 const struct devlink_param *params,
661 size_t params_count);
662void devlink_port_params_unregister(struct devlink_port *devlink_port,
663 const struct devlink_param *params,
664 size_t params_count);
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300665int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
666 union devlink_param_value *init_val);
667int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
668 union devlink_param_value init_val);
Vasundhara Volamffd19b92019-01-28 18:00:23 +0530669int
670devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
671 u32 param_id,
672 union devlink_param_value *init_val);
Vasundhara Volam5473a7b2019-01-28 18:00:24 +0530673int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
674 u32 param_id,
675 union devlink_param_value init_val);
Moshe Shemeshea601e12018-07-04 14:30:32 +0300676void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
Vasundhara Volamc1e5786d2019-01-28 18:00:25 +0530677void devlink_port_param_value_changed(struct devlink_port *devlink_port,
678 u32 param_id);
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300679void devlink_param_value_str_fill(union devlink_param_value *dst_val,
680 const char *src);
Alex Veskerb16ebe92018-07-12 15:13:08 +0300681struct devlink_region *devlink_region_create(struct devlink *devlink,
682 const char *region_name,
683 u32 region_max_snapshots,
684 u64 region_size);
685void devlink_region_destroy(struct devlink_region *region);
Alex Veskerccadfa42018-07-12 15:13:09 +0300686u32 devlink_region_shapshot_id_get(struct devlink *devlink);
Alex Veskerd7e52722018-07-12 15:13:10 +0300687int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
688 u8 *data, u32 snapshot_id,
689 devlink_snapshot_data_dest_t *data_destructor);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800690int devlink_info_serial_number_put(struct devlink_info_req *req,
691 const char *sn);
692int devlink_info_driver_name_put(struct devlink_info_req *req,
693 const char *name);
Jakub Kicinskifc6fae72019-01-31 10:50:41 -0800694int devlink_info_version_fixed_put(struct devlink_info_req *req,
695 const char *version_name,
696 const char *version_value);
697int devlink_info_version_stored_put(struct devlink_info_req *req,
698 const char *version_name,
699 const char *version_value);
700int devlink_info_version_running_put(struct devlink_info_req *req,
701 const char *version_name,
702 const char *version_value);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100703
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200704int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
705int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
706
707int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
708int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
709
710int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
711 const char *name);
712int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
713
714int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
715int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
716int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
717int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
718int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
719int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
720 u16 value_len);
721
722int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
723 bool value);
724int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
725 u8 value);
726int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
727 u32 value);
728int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
729 u64 value);
730int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
731 const char *value);
732int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
733 const void *value, u16 value_len);
734
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200735struct devlink_health_reporter *
736devlink_health_reporter_create(struct devlink *devlink,
737 const struct devlink_health_reporter_ops *ops,
738 u64 graceful_period, bool auto_recover,
739 void *priv);
740void
741devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
742
743void *
744devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
Eran Ben Elishac8e1da02019-02-07 11:36:34 +0200745int devlink_health_report(struct devlink_health_reporter *reporter,
746 const char *msg, void *priv_ctx);
Eran Ben Elisha3167b272019-03-03 10:57:30 +0200747void
748devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
749 enum devlink_health_reporter_state state);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200750
Jiri Pirko191ed202019-06-04 15:40:40 +0200751void devlink_flash_update_begin_notify(struct devlink *devlink);
752void devlink_flash_update_end_notify(struct devlink *devlink);
753void devlink_flash_update_status_notify(struct devlink *devlink,
754 const char *status_msg,
755 const char *component,
756 unsigned long done,
757 unsigned long total);
758
Jiri Pirkof6b19b32019-03-24 11:14:38 +0100759#if IS_ENABLED(CONFIG_NET_DEVLINK)
760
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -0800761void devlink_compat_running_version(struct net_device *dev,
762 char *buf, size_t len);
763int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
Jiri Pirkoaf3836d2019-03-28 13:56:37 +0100764int devlink_compat_phys_port_name_get(struct net_device *dev,
765 char *name, size_t len);
Jiri Pirko7e1146e2019-04-03 14:24:17 +0200766int devlink_compat_switch_id_get(struct net_device *dev,
767 struct netdev_phys_item_id *ppid);
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -0800768
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100769#else
770
Eran Ben Elisha3167b272019-03-03 10:57:30 +0200771static inline void
Jakub Kicinskiddb6e992019-01-31 10:50:47 -0800772devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
773{
774}
Jakub Kicinski4eceba12019-02-14 13:40:45 -0800775
776static inline int
777devlink_compat_flash_update(struct net_device *dev, const char *file_name)
778{
779 return -EOPNOTSUPP;
780}
Jiri Pirkof6b19b32019-03-24 11:14:38 +0100781
Jiri Pirkoaf3836d2019-03-28 13:56:37 +0100782static inline int
783devlink_compat_phys_port_name_get(struct net_device *dev,
784 char *name, size_t len)
785{
786 return -EOPNOTSUPP;
787}
788
Jiri Pirko7e1146e2019-04-03 14:24:17 +0200789static inline int
790devlink_compat_switch_id_get(struct net_device *dev,
791 struct netdev_phys_item_id *ppid)
792{
793 return -EOPNOTSUPP;
794}
795
Jakub Kicinskiddb6e992019-01-31 10:50:47 -0800796#endif
797
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100798#endif /* _NET_DEVLINK_H_ */