blob: 0f79687612045c08435ba27d0b274f1fa546d452 [file] [log] [blame]
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001/*
2 * include/net/devlink.h - Network physical device Netlink interface
3 * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11#ifndef _NET_DEVLINK_H_
12#define _NET_DEVLINK_H_
13
14#include <linux/device.h>
15#include <linux/slab.h>
16#include <linux/gfp.h>
17#include <linux/list.h>
18#include <linux/netdevice.h>
Jiri Pirkob8f97552019-03-24 11:14:37 +010019#include <linux/spinlock.h>
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010020#include <net/net_namespace.h>
21#include <uapi/linux/devlink.h>
22
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;
Alex Veskerccadfa42018-07-12 15:13:09 +030033 u32 snapshot_id;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +020034 struct list_head reporter_list;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020035 struct devlink_dpipe_headers *dpipe_headers;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010036 const struct devlink_ops *ops;
37 struct device *dev;
38 possible_net_t _net;
Arkadi Sharshevsky2406e7e2018-01-15 08:59:02 +010039 struct mutex lock;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010040 char priv[0] __aligned(NETDEV_ALIGN);
41};
42
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020043struct devlink_port_attrs {
Jiri Pirko407dd702019-04-03 14:24:15 +020044 u8 set:1,
Jiri Pirkobec52672019-04-03 14:24:16 +020045 split:1,
46 switch_port:1;
Jiri Pirko5ec13802018-05-18 09:29:01 +020047 enum devlink_port_flavour flavour;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020048 u32 port_number; /* same value as "split group" */
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020049 u32 split_subport_number;
Jiri Pirkobec52672019-04-03 14:24:16 +020050 struct netdev_phys_item_id switch_id;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020051};
52
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010053struct devlink_port {
54 struct list_head list;
Vasundhara Volam39e61602019-01-28 18:00:20 +053055 struct list_head param_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010056 struct devlink *devlink;
57 unsigned index;
58 bool registered;
Jiri Pirkob8f97552019-03-24 11:14:37 +010059 spinlock_t type_lock; /* Protects type and type_dev
60 * pointer consistency.
61 */
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010062 enum devlink_port_type type;
63 enum devlink_port_type desired_type;
64 void *type_dev;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020065 struct devlink_port_attrs attrs;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010066};
67
Jiri Pirkobf797472016-04-14 18:19:13 +020068struct devlink_sb_pool_info {
69 enum devlink_sb_pool_type pool_type;
70 u32 size;
71 enum devlink_sb_threshold_type threshold_type;
Jakub Kicinskibff57312019-02-01 17:56:28 -080072 u32 cell_size;
Jiri Pirkobf797472016-04-14 18:19:13 +020073};
74
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020075/**
76 * struct devlink_dpipe_field - dpipe field object
77 * @name: field name
78 * @id: index inside the headers field array
79 * @bitwidth: bitwidth
80 * @mapping_type: mapping type
81 */
82struct devlink_dpipe_field {
83 const char *name;
84 unsigned int id;
85 unsigned int bitwidth;
86 enum devlink_dpipe_field_mapping_type mapping_type;
87};
88
89/**
90 * struct devlink_dpipe_header - dpipe header object
91 * @name: header name
92 * @id: index, global/local detrmined by global bit
93 * @fields: fields
94 * @fields_count: number of fields
95 * @global: indicates if header is shared like most protocol header
96 * or driver specific
97 */
98struct devlink_dpipe_header {
99 const char *name;
100 unsigned int id;
101 struct devlink_dpipe_field *fields;
102 unsigned int fields_count;
103 bool global;
104};
105
106/**
107 * struct devlink_dpipe_match - represents match operation
108 * @type: type of match
109 * @header_index: header index (packets can have several headers of same
110 * type like in case of tunnels)
111 * @header: header
112 * @fieled_id: field index
113 */
114struct devlink_dpipe_match {
115 enum devlink_dpipe_match_type type;
116 unsigned int header_index;
117 struct devlink_dpipe_header *header;
118 unsigned int field_id;
119};
120
121/**
122 * struct devlink_dpipe_action - represents action operation
123 * @type: type of action
124 * @header_index: header index (packets can have several headers of same
125 * type like in case of tunnels)
126 * @header: header
127 * @fieled_id: field index
128 */
129struct devlink_dpipe_action {
130 enum devlink_dpipe_action_type type;
131 unsigned int header_index;
132 struct devlink_dpipe_header *header;
133 unsigned int field_id;
134};
135
136/**
137 * struct devlink_dpipe_value - represents value of match/action
138 * @action: action
139 * @match: match
140 * @mapping_value: in case the field has some mapping this value
141 * specified the mapping value
142 * @mapping_valid: specify if mapping value is valid
143 * @value_size: value size
144 * @value: value
145 * @mask: bit mask
146 */
147struct devlink_dpipe_value {
148 union {
149 struct devlink_dpipe_action *action;
150 struct devlink_dpipe_match *match;
151 };
152 unsigned int mapping_value;
153 bool mapping_valid;
154 unsigned int value_size;
155 void *value;
156 void *mask;
157};
158
159/**
160 * struct devlink_dpipe_entry - table entry object
161 * @index: index of the entry in the table
162 * @match_values: match values
163 * @matche_values_count: count of matches tuples
164 * @action_values: actions values
165 * @action_values_count: count of actions values
166 * @counter: value of counter
167 * @counter_valid: Specify if value is valid from hardware
168 */
169struct devlink_dpipe_entry {
170 u64 index;
171 struct devlink_dpipe_value *match_values;
172 unsigned int match_values_count;
173 struct devlink_dpipe_value *action_values;
174 unsigned int action_values_count;
175 u64 counter;
176 bool counter_valid;
177};
178
179/**
180 * struct devlink_dpipe_dump_ctx - context provided to driver in order
181 * to dump
182 * @info: info
183 * @cmd: devlink command
184 * @skb: skb
185 * @nest: top attribute
186 * @hdr: hdr
187 */
188struct devlink_dpipe_dump_ctx {
189 struct genl_info *info;
190 enum devlink_command cmd;
191 struct sk_buff *skb;
192 struct nlattr *nest;
193 void *hdr;
194};
195
196struct devlink_dpipe_table_ops;
197
198/**
199 * struct devlink_dpipe_table - table object
200 * @priv: private
201 * @name: table name
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200202 * @counters_enabled: indicates if counters are active
203 * @counter_control_extern: indicates if counter control is in dpipe or
204 * external tool
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100205 * @resource_valid: Indicate that the resource id is valid
206 * @resource_id: relative resource this table is related to
207 * @resource_units: number of resource's unit consumed per table's entry
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200208 * @table_ops: table operations
209 * @rcu: rcu
210 */
211struct devlink_dpipe_table {
212 void *priv;
213 struct list_head list;
214 const char *name;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200215 bool counters_enabled;
216 bool counter_control_extern;
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100217 bool resource_valid;
218 u64 resource_id;
219 u64 resource_units;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200220 struct devlink_dpipe_table_ops *table_ops;
221 struct rcu_head rcu;
222};
223
224/**
225 * struct devlink_dpipe_table_ops - dpipe_table ops
226 * @actions_dump - dumps all tables actions
227 * @matches_dump - dumps all tables matches
228 * @entries_dump - dumps all active entries in the table
229 * @counters_set_update - when changing the counter status hardware sync
230 * maybe needed to allocate/free counter related
231 * resources
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200232 * @size_get - get size
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200233 */
234struct devlink_dpipe_table_ops {
235 int (*actions_dump)(void *priv, struct sk_buff *skb);
236 int (*matches_dump)(void *priv, struct sk_buff *skb);
237 int (*entries_dump)(void *priv, bool counters_enabled,
238 struct devlink_dpipe_dump_ctx *dump_ctx);
239 int (*counters_set_update)(void *priv, bool enable);
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200240 u64 (*size_get)(void *priv);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200241};
242
243/**
244 * struct devlink_dpipe_headers - dpipe headers
245 * @headers - header array can be shared (global bit) or driver specific
246 * @headers_count - count of headers
247 */
248struct devlink_dpipe_headers {
249 struct devlink_dpipe_header **headers;
250 unsigned int headers_count;
251};
252
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100253/**
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100254 * struct devlink_resource_size_params - resource's size parameters
255 * @size_min: minimum size which can be set
256 * @size_max: maximum size which can be set
257 * @size_granularity: size granularity
258 * @size_unit: resource's basic unit
259 */
260struct devlink_resource_size_params {
261 u64 size_min;
262 u64 size_max;
263 u64 size_granularity;
264 enum devlink_resource_unit unit;
265};
266
Jiri Pirko77d27092018-02-28 13:12:09 +0100267static inline void
268devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
269 u64 size_min, u64 size_max,
270 u64 size_granularity,
271 enum devlink_resource_unit unit)
272{
273 size_params->size_min = size_min;
274 size_params->size_max = size_max;
275 size_params->size_granularity = size_granularity;
276 size_params->unit = unit;
277}
278
Jiri Pirkofc56be42018-04-05 22:13:21 +0200279typedef u64 devlink_resource_occ_get_t(void *priv);
280
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100281/**
282 * struct devlink_resource - devlink resource
283 * @name: name of the resource
284 * @id: id, per devlink instance
285 * @size: size of the resource
286 * @size_new: updated size of the resource, reload is needed
287 * @size_valid: valid in case the total size of the resource is valid
288 * including its children
289 * @parent: parent resource
290 * @size_params: size parameters
291 * @list: parent list
292 * @resource_list: list of child resources
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100293 */
294struct devlink_resource {
295 const char *name;
296 u64 id;
297 u64 size;
298 u64 size_new;
299 bool size_valid;
300 struct devlink_resource *parent;
Jiri Pirko77d27092018-02-28 13:12:09 +0100301 struct devlink_resource_size_params size_params;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100302 struct list_head list;
303 struct list_head resource_list;
Jiri Pirkofc56be42018-04-05 22:13:21 +0200304 devlink_resource_occ_get_t *occ_get;
305 void *occ_get_priv;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100306};
307
308#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
309
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300310#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
Moshe Shemesheabaef12018-07-04 14:30:28 +0300311enum devlink_param_type {
312 DEVLINK_PARAM_TYPE_U8,
313 DEVLINK_PARAM_TYPE_U16,
314 DEVLINK_PARAM_TYPE_U32,
315 DEVLINK_PARAM_TYPE_STRING,
316 DEVLINK_PARAM_TYPE_BOOL,
317};
318
319union devlink_param_value {
320 u8 vu8;
321 u16 vu16;
322 u32 vu32;
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300323 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
Moshe Shemesheabaef12018-07-04 14:30:28 +0300324 bool vbool;
325};
326
327struct devlink_param_gset_ctx {
328 union devlink_param_value val;
329 enum devlink_param_cmode cmode;
330};
331
332/**
333 * struct devlink_param - devlink configuration parameter data
334 * @name: name of the parameter
335 * @generic: indicates if the parameter is generic or driver specific
336 * @type: parameter type
337 * @supported_cmodes: bitmap of supported configuration modes
338 * @get: get parameter value, used for runtime and permanent
339 * configuration modes
340 * @set: set parameter value, used for runtime and permanent
341 * configuration modes
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300342 * @validate: validate input value is applicable (within value range, etc.)
Moshe Shemesheabaef12018-07-04 14:30:28 +0300343 *
344 * This struct should be used by the driver to fill the data for
345 * a parameter it registers.
346 */
347struct devlink_param {
348 u32 id;
349 const char *name;
350 bool generic;
351 enum devlink_param_type type;
352 unsigned long supported_cmodes;
353 int (*get)(struct devlink *devlink, u32 id,
354 struct devlink_param_gset_ctx *ctx);
355 int (*set)(struct devlink *devlink, u32 id,
356 struct devlink_param_gset_ctx *ctx);
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300357 int (*validate)(struct devlink *devlink, u32 id,
358 union devlink_param_value val,
359 struct netlink_ext_ack *extack);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300360};
361
362struct devlink_param_item {
363 struct list_head list;
364 const struct devlink_param *param;
365 union devlink_param_value driverinit_value;
366 bool driverinit_value_valid;
Jiri Pirko7c62cfb2019-02-07 11:22:45 +0000367 bool published;
Moshe Shemesheabaef12018-07-04 14:30:28 +0300368};
369
370enum devlink_param_generic_id {
Moshe Shemesh036467c2018-07-04 14:30:33 +0300371 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
372 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300373 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
Alex Veskerf6a698852018-07-12 15:13:17 +0300374 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
Vasundhara Volame3b51062018-10-04 11:13:44 +0530375 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530376 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
Vasundhara Volam16511782018-10-04 11:13:46 +0530377 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
Shalom Toledo846e9802018-12-03 07:58:59 +0000378 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
Moshe Shemesheabaef12018-07-04 14:30:28 +0300379
380 /* add new param generic ids above here*/
381 __DEVLINK_PARAM_GENERIC_ID_MAX,
382 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
383};
384
Moshe Shemesh036467c2018-07-04 14:30:33 +0300385#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
386#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
387
388#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
389#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
390
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300391#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
392#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
393
Alex Veskerf6a698852018-07-12 15:13:17 +0300394#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
395#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
396
Vasundhara Volame3b51062018-10-04 11:13:44 +0530397#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
398#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
399
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530400#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
401#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
402
Vasundhara Volam16511782018-10-04 11:13:46 +0530403#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
404#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
405
Shalom Toledo846e9802018-12-03 07:58:59 +0000406#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
407#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
408
Moshe Shemesh036467c2018-07-04 14:30:33 +0300409#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
410{ \
411 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
412 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
413 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
414 .generic = true, \
415 .supported_cmodes = _cmodes, \
416 .get = _get, \
417 .set = _set, \
418 .validate = _validate, \
419}
420
421#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
422{ \
423 .id = _id, \
424 .name = _name, \
425 .type = _type, \
426 .supported_cmodes = _cmodes, \
427 .get = _get, \
428 .set = _set, \
429 .validate = _validate, \
430}
431
Jakub Kicinski785bd552019-01-31 10:50:42 -0800432/* Part number, identifier of board design */
433#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
434/* Revision of board design */
435#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
Jakub Kicinski14fd1902019-02-10 19:35:29 -0800436/* Maker of the board */
437#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800438
439/* Control processor FW version */
440#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
441/* Data path microcode controlling high-speed packet processing */
442#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
443/* UNDI software version */
444#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
445/* NCSI support/handler version */
446#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
447
Alex Veskerb16ebe92018-07-12 15:13:08 +0300448struct devlink_region;
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800449struct devlink_info_req;
Alex Veskerb16ebe92018-07-12 15:13:08 +0300450
Alex Veskerd7e52722018-07-12 15:13:10 +0300451typedef void devlink_snapshot_data_dest_t(const void *data);
452
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200453struct devlink_fmsg;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200454struct devlink_health_reporter;
455
Eran Ben Elisha3167b272019-03-03 10:57:30 +0200456enum devlink_health_reporter_state {
457 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
458 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
459};
460
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200461/**
462 * struct devlink_health_reporter_ops - Reporter operations
463 * @name: reporter name
464 * @recover: callback to recover from reported error
465 * if priv_ctx is NULL, run a full recover
466 * @dump: callback to dump an object
467 * if priv_ctx is NULL, run a full dump
468 * @diagnose: callback to diagnose the current status
469 */
470
471struct devlink_health_reporter_ops {
472 char *name;
473 int (*recover)(struct devlink_health_reporter *reporter,
474 void *priv_ctx);
475 int (*dump)(struct devlink_health_reporter *reporter,
476 struct devlink_fmsg *fmsg, void *priv_ctx);
477 int (*diagnose)(struct devlink_health_reporter *reporter,
478 struct devlink_fmsg *fmsg);
479};
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200480
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100481struct devlink_ops {
David Ahernac0fc8a2018-06-05 08:14:09 -0700482 int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100483 int (*port_type_set)(struct devlink_port *devlink_port,
484 enum devlink_port_type port_type);
485 int (*port_split)(struct devlink *devlink, unsigned int port_index,
David Ahernac0fc8a2018-06-05 08:14:09 -0700486 unsigned int count, struct netlink_ext_ack *extack);
487 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
488 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200489 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
490 u16 pool_index,
491 struct devlink_sb_pool_info *pool_info);
492 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
493 u16 pool_index, u32 size,
494 enum devlink_sb_threshold_type threshold_type);
495 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
496 unsigned int sb_index, u16 pool_index,
497 u32 *p_threshold);
498 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
499 unsigned int sb_index, u16 pool_index,
500 u32 threshold);
501 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
502 unsigned int sb_index,
503 u16 tc_index,
504 enum devlink_sb_pool_type pool_type,
505 u16 *p_pool_index, u32 *p_threshold);
506 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
507 unsigned int sb_index,
508 u16 tc_index,
509 enum devlink_sb_pool_type pool_type,
510 u16 pool_index, u32 threshold);
Jiri Pirkodf38daf2016-04-14 18:19:14 +0200511 int (*sb_occ_snapshot)(struct devlink *devlink,
512 unsigned int sb_index);
513 int (*sb_occ_max_clear)(struct devlink *devlink,
514 unsigned int sb_index);
515 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
516 unsigned int sb_index, u16 pool_index,
517 u32 *p_cur, u32 *p_max);
518 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
519 unsigned int sb_index,
520 u16 tc_index,
521 enum devlink_sb_pool_type pool_type,
522 u32 *p_cur, u32 *p_max);
Or Gerlitz08f4b592016-07-01 14:51:01 +0300523
524 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300525 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
526 struct netlink_ext_ack *extack);
Roi Dayan59bfde02016-11-22 23:09:57 +0200527 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300528 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
529 struct netlink_ext_ack *extack);
Roi Dayanf43e9b02016-09-25 13:52:44 +0300530 int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300531 int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode,
532 struct netlink_ext_ack *extack);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800533 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
534 struct netlink_ext_ack *extack);
Jakub Kicinski76726cc2019-02-14 13:40:44 -0800535 int (*flash_update)(struct devlink *devlink, const char *file_name,
536 const char *component,
537 struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100538};
539
540static inline void *devlink_priv(struct devlink *devlink)
541{
542 BUG_ON(!devlink);
543 return &devlink->priv;
544}
545
546static inline struct devlink *priv_to_devlink(void *priv)
547{
548 BUG_ON(!priv);
549 return container_of(priv, struct devlink, priv);
550}
551
Jiri Pirko5dc37bb2019-03-28 13:56:36 +0100552static inline struct devlink_port *
553netdev_to_devlink_port(struct net_device *dev)
554{
555 if (dev->netdev_ops->ndo_get_devlink_port)
556 return dev->netdev_ops->ndo_get_devlink_port(dev);
557 return NULL;
558}
559
Jakub Kicinskib473b0d2019-02-25 19:34:03 -0800560static inline struct devlink *netdev_to_devlink(struct net_device *dev)
561{
Jiri Pirko5dc37bb2019-03-28 13:56:36 +0100562 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
563
564 if (devlink_port)
565 return devlink_port->devlink;
Jakub Kicinskib473b0d2019-02-25 19:34:03 -0800566 return NULL;
567}
568
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100569struct ib_device;
570
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100571struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
572int devlink_register(struct devlink *devlink, struct device *dev);
573void devlink_unregister(struct devlink *devlink);
574void devlink_free(struct devlink *devlink);
575int devlink_port_register(struct devlink *devlink,
576 struct devlink_port *devlink_port,
577 unsigned int port_index);
578void devlink_port_unregister(struct devlink_port *devlink_port);
579void devlink_port_type_eth_set(struct devlink_port *devlink_port,
580 struct net_device *netdev);
581void devlink_port_type_ib_set(struct devlink_port *devlink_port,
582 struct ib_device *ibdev);
583void devlink_port_type_clear(struct devlink_port *devlink_port);
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200584void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200585 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200586 u32 port_number, bool split,
Jiri Pirkobec52672019-04-03 14:24:16 +0200587 u32 split_subport_number,
588 const unsigned char *switch_id,
589 unsigned char switch_id_len);
Jiri Pirkobf797472016-04-14 18:19:13 +0200590int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
591 u32 size, u16 ingress_pools_count,
592 u16 egress_pools_count, u16 ingress_tc_count,
593 u16 egress_tc_count);
594void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200595int devlink_dpipe_table_register(struct devlink *devlink,
596 const char *table_name,
597 struct devlink_dpipe_table_ops *table_ops,
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200598 void *priv, bool counter_control_extern);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200599void devlink_dpipe_table_unregister(struct devlink *devlink,
600 const char *table_name);
601int devlink_dpipe_headers_register(struct devlink *devlink,
602 struct devlink_dpipe_headers *dpipe_headers);
603void devlink_dpipe_headers_unregister(struct devlink *devlink);
604bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
605 const char *table_name);
606int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
607int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
608 struct devlink_dpipe_entry *entry);
609int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200610void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200611int devlink_dpipe_action_put(struct sk_buff *skb,
612 struct devlink_dpipe_action *action);
613int devlink_dpipe_match_put(struct sk_buff *skb,
614 struct devlink_dpipe_match *match);
Arkadi Sharshevsky11770092017-08-24 08:39:59 +0200615extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
Arkadi Sharshevsky3fb886e2017-08-24 08:40:00 +0200616extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
Arkadi Sharshevsky1797f5b2017-08-31 17:59:12 +0200617extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100618
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100619int devlink_resource_register(struct devlink *devlink,
620 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100621 u64 resource_size,
622 u64 resource_id,
623 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200624 const struct devlink_resource_size_params *size_params);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100625void devlink_resources_unregister(struct devlink *devlink,
626 struct devlink_resource *resource);
627int devlink_resource_size_get(struct devlink *devlink,
628 u64 resource_id,
629 u64 *p_resource_size);
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100630int devlink_dpipe_table_resource_set(struct devlink *devlink,
631 const char *table_name, u64 resource_id,
632 u64 resource_units);
Jiri Pirkofc56be42018-04-05 22:13:21 +0200633void devlink_resource_occ_get_register(struct devlink *devlink,
634 u64 resource_id,
635 devlink_resource_occ_get_t *occ_get,
636 void *occ_get_priv);
637void devlink_resource_occ_get_unregister(struct devlink *devlink,
638 u64 resource_id);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300639int devlink_params_register(struct devlink *devlink,
640 const struct devlink_param *params,
641 size_t params_count);
642void devlink_params_unregister(struct devlink *devlink,
643 const struct devlink_param *params,
644 size_t params_count);
Jiri Pirko7c62cfb2019-02-07 11:22:45 +0000645void devlink_params_publish(struct devlink *devlink);
646void devlink_params_unpublish(struct devlink *devlink);
Vasundhara Volam39e61602019-01-28 18:00:20 +0530647int devlink_port_params_register(struct devlink_port *devlink_port,
648 const struct devlink_param *params,
649 size_t params_count);
650void devlink_port_params_unregister(struct devlink_port *devlink_port,
651 const struct devlink_param *params,
652 size_t params_count);
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300653int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
654 union devlink_param_value *init_val);
655int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
656 union devlink_param_value init_val);
Vasundhara Volamffd19b92019-01-28 18:00:23 +0530657int
658devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
659 u32 param_id,
660 union devlink_param_value *init_val);
Vasundhara Volam5473a7b2019-01-28 18:00:24 +0530661int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
662 u32 param_id,
663 union devlink_param_value init_val);
Moshe Shemeshea601e12018-07-04 14:30:32 +0300664void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
Vasundhara Volamc1e5786d2019-01-28 18:00:25 +0530665void devlink_port_param_value_changed(struct devlink_port *devlink_port,
666 u32 param_id);
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300667void devlink_param_value_str_fill(union devlink_param_value *dst_val,
668 const char *src);
Alex Veskerb16ebe92018-07-12 15:13:08 +0300669struct devlink_region *devlink_region_create(struct devlink *devlink,
670 const char *region_name,
671 u32 region_max_snapshots,
672 u64 region_size);
673void devlink_region_destroy(struct devlink_region *region);
Alex Veskerccadfa42018-07-12 15:13:09 +0300674u32 devlink_region_shapshot_id_get(struct devlink *devlink);
Alex Veskerd7e52722018-07-12 15:13:10 +0300675int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
676 u8 *data, u32 snapshot_id,
677 devlink_snapshot_data_dest_t *data_destructor);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800678int devlink_info_serial_number_put(struct devlink_info_req *req,
679 const char *sn);
680int devlink_info_driver_name_put(struct devlink_info_req *req,
681 const char *name);
Jakub Kicinskifc6fae72019-01-31 10:50:41 -0800682int devlink_info_version_fixed_put(struct devlink_info_req *req,
683 const char *version_name,
684 const char *version_value);
685int devlink_info_version_stored_put(struct devlink_info_req *req,
686 const char *version_name,
687 const char *version_value);
688int devlink_info_version_running_put(struct devlink_info_req *req,
689 const char *version_name,
690 const char *version_value);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100691
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200692int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
693int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
694
695int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
696int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
697
698int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
699 const char *name);
700int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
701
702int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
703int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
704int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
705int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
706int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
707int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
708 u16 value_len);
709
710int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
711 bool value);
712int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
713 u8 value);
714int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
715 u32 value);
716int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
717 u64 value);
718int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
719 const char *value);
720int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
721 const void *value, u16 value_len);
722
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200723struct devlink_health_reporter *
724devlink_health_reporter_create(struct devlink *devlink,
725 const struct devlink_health_reporter_ops *ops,
726 u64 graceful_period, bool auto_recover,
727 void *priv);
728void
729devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
730
731void *
732devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
Eran Ben Elishac8e1da02019-02-07 11:36:34 +0200733int devlink_health_report(struct devlink_health_reporter *reporter,
734 const char *msg, void *priv_ctx);
Eran Ben Elisha3167b272019-03-03 10:57:30 +0200735void
736devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
737 enum devlink_health_reporter_state state);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200738
Jiri Pirkof6b19b32019-03-24 11:14:38 +0100739#if IS_ENABLED(CONFIG_NET_DEVLINK)
740
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -0800741void devlink_compat_running_version(struct net_device *dev,
742 char *buf, size_t len);
743int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
Jiri Pirkoaf3836d2019-03-28 13:56:37 +0100744int devlink_compat_phys_port_name_get(struct net_device *dev,
745 char *name, size_t len);
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -0800746
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100747#else
748
Eran Ben Elisha3167b272019-03-03 10:57:30 +0200749static inline void
Jakub Kicinskiddb6e992019-01-31 10:50:47 -0800750devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
751{
752}
Jakub Kicinski4eceba12019-02-14 13:40:45 -0800753
754static inline int
755devlink_compat_flash_update(struct net_device *dev, const char *file_name)
756{
757 return -EOPNOTSUPP;
758}
Jiri Pirkof6b19b32019-03-24 11:14:38 +0100759
Jiri Pirkoaf3836d2019-03-28 13:56:37 +0100760static inline int
761devlink_compat_phys_port_name_get(struct net_device *dev,
762 char *name, size_t len)
763{
764 return -EOPNOTSUPP;
765}
766
Jakub Kicinskiddb6e992019-01-31 10:50:47 -0800767#endif
768
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100769#endif /* _NET_DEVLINK_H_ */