blob: 6b417f141fd62cee18904058a1a72254105e4742 [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>
19#include <net/net_namespace.h>
20#include <uapi/linux/devlink.h>
21
22struct devlink_ops;
23
24struct devlink {
25 struct list_head list;
26 struct list_head port_list;
Jiri Pirkobf797472016-04-14 18:19:13 +020027 struct list_head sb_list;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020028 struct list_head dpipe_table_list;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +010029 struct list_head resource_list;
Moshe Shemesheabaef12018-07-04 14:30:28 +030030 struct list_head param_list;
Alex Veskerb16ebe92018-07-12 15:13:08 +030031 struct list_head region_list;
Alex Veskerccadfa42018-07-12 15:13:09 +030032 u32 snapshot_id;
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
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020041struct devlink_port_attrs {
42 bool set;
Jiri Pirko5ec13802018-05-18 09:29:01 +020043 enum devlink_port_flavour flavour;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020044 u32 port_number; /* same value as "split group" */
45 bool split;
46 u32 split_subport_number;
47};
48
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010049struct devlink_port {
50 struct list_head list;
Vasundhara Volam39e61602019-01-28 18:00:20 +053051 struct list_head param_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010052 struct devlink *devlink;
53 unsigned index;
54 bool registered;
55 enum devlink_port_type type;
56 enum devlink_port_type desired_type;
57 void *type_dev;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020058 struct devlink_port_attrs attrs;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010059};
60
Jiri Pirkobf797472016-04-14 18:19:13 +020061struct devlink_sb_pool_info {
62 enum devlink_sb_pool_type pool_type;
63 u32 size;
64 enum devlink_sb_threshold_type threshold_type;
65};
66
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020067/**
68 * struct devlink_dpipe_field - dpipe field object
69 * @name: field name
70 * @id: index inside the headers field array
71 * @bitwidth: bitwidth
72 * @mapping_type: mapping type
73 */
74struct devlink_dpipe_field {
75 const char *name;
76 unsigned int id;
77 unsigned int bitwidth;
78 enum devlink_dpipe_field_mapping_type mapping_type;
79};
80
81/**
82 * struct devlink_dpipe_header - dpipe header object
83 * @name: header name
84 * @id: index, global/local detrmined by global bit
85 * @fields: fields
86 * @fields_count: number of fields
87 * @global: indicates if header is shared like most protocol header
88 * or driver specific
89 */
90struct devlink_dpipe_header {
91 const char *name;
92 unsigned int id;
93 struct devlink_dpipe_field *fields;
94 unsigned int fields_count;
95 bool global;
96};
97
98/**
99 * struct devlink_dpipe_match - represents match operation
100 * @type: type of match
101 * @header_index: header index (packets can have several headers of same
102 * type like in case of tunnels)
103 * @header: header
104 * @fieled_id: field index
105 */
106struct devlink_dpipe_match {
107 enum devlink_dpipe_match_type type;
108 unsigned int header_index;
109 struct devlink_dpipe_header *header;
110 unsigned int field_id;
111};
112
113/**
114 * struct devlink_dpipe_action - represents action operation
115 * @type: type of action
116 * @header_index: header index (packets can have several headers of same
117 * type like in case of tunnels)
118 * @header: header
119 * @fieled_id: field index
120 */
121struct devlink_dpipe_action {
122 enum devlink_dpipe_action_type type;
123 unsigned int header_index;
124 struct devlink_dpipe_header *header;
125 unsigned int field_id;
126};
127
128/**
129 * struct devlink_dpipe_value - represents value of match/action
130 * @action: action
131 * @match: match
132 * @mapping_value: in case the field has some mapping this value
133 * specified the mapping value
134 * @mapping_valid: specify if mapping value is valid
135 * @value_size: value size
136 * @value: value
137 * @mask: bit mask
138 */
139struct devlink_dpipe_value {
140 union {
141 struct devlink_dpipe_action *action;
142 struct devlink_dpipe_match *match;
143 };
144 unsigned int mapping_value;
145 bool mapping_valid;
146 unsigned int value_size;
147 void *value;
148 void *mask;
149};
150
151/**
152 * struct devlink_dpipe_entry - table entry object
153 * @index: index of the entry in the table
154 * @match_values: match values
155 * @matche_values_count: count of matches tuples
156 * @action_values: actions values
157 * @action_values_count: count of actions values
158 * @counter: value of counter
159 * @counter_valid: Specify if value is valid from hardware
160 */
161struct devlink_dpipe_entry {
162 u64 index;
163 struct devlink_dpipe_value *match_values;
164 unsigned int match_values_count;
165 struct devlink_dpipe_value *action_values;
166 unsigned int action_values_count;
167 u64 counter;
168 bool counter_valid;
169};
170
171/**
172 * struct devlink_dpipe_dump_ctx - context provided to driver in order
173 * to dump
174 * @info: info
175 * @cmd: devlink command
176 * @skb: skb
177 * @nest: top attribute
178 * @hdr: hdr
179 */
180struct devlink_dpipe_dump_ctx {
181 struct genl_info *info;
182 enum devlink_command cmd;
183 struct sk_buff *skb;
184 struct nlattr *nest;
185 void *hdr;
186};
187
188struct devlink_dpipe_table_ops;
189
190/**
191 * struct devlink_dpipe_table - table object
192 * @priv: private
193 * @name: table name
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200194 * @counters_enabled: indicates if counters are active
195 * @counter_control_extern: indicates if counter control is in dpipe or
196 * external tool
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100197 * @resource_valid: Indicate that the resource id is valid
198 * @resource_id: relative resource this table is related to
199 * @resource_units: number of resource's unit consumed per table's entry
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200200 * @table_ops: table operations
201 * @rcu: rcu
202 */
203struct devlink_dpipe_table {
204 void *priv;
205 struct list_head list;
206 const char *name;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200207 bool counters_enabled;
208 bool counter_control_extern;
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100209 bool resource_valid;
210 u64 resource_id;
211 u64 resource_units;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200212 struct devlink_dpipe_table_ops *table_ops;
213 struct rcu_head rcu;
214};
215
216/**
217 * struct devlink_dpipe_table_ops - dpipe_table ops
218 * @actions_dump - dumps all tables actions
219 * @matches_dump - dumps all tables matches
220 * @entries_dump - dumps all active entries in the table
221 * @counters_set_update - when changing the counter status hardware sync
222 * maybe needed to allocate/free counter related
223 * resources
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200224 * @size_get - get size
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200225 */
226struct devlink_dpipe_table_ops {
227 int (*actions_dump)(void *priv, struct sk_buff *skb);
228 int (*matches_dump)(void *priv, struct sk_buff *skb);
229 int (*entries_dump)(void *priv, bool counters_enabled,
230 struct devlink_dpipe_dump_ctx *dump_ctx);
231 int (*counters_set_update)(void *priv, bool enable);
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200232 u64 (*size_get)(void *priv);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200233};
234
235/**
236 * struct devlink_dpipe_headers - dpipe headers
237 * @headers - header array can be shared (global bit) or driver specific
238 * @headers_count - count of headers
239 */
240struct devlink_dpipe_headers {
241 struct devlink_dpipe_header **headers;
242 unsigned int headers_count;
243};
244
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100245/**
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100246 * struct devlink_resource_size_params - resource's size parameters
247 * @size_min: minimum size which can be set
248 * @size_max: maximum size which can be set
249 * @size_granularity: size granularity
250 * @size_unit: resource's basic unit
251 */
252struct devlink_resource_size_params {
253 u64 size_min;
254 u64 size_max;
255 u64 size_granularity;
256 enum devlink_resource_unit unit;
257};
258
Jiri Pirko77d27092018-02-28 13:12:09 +0100259static inline void
260devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
261 u64 size_min, u64 size_max,
262 u64 size_granularity,
263 enum devlink_resource_unit unit)
264{
265 size_params->size_min = size_min;
266 size_params->size_max = size_max;
267 size_params->size_granularity = size_granularity;
268 size_params->unit = unit;
269}
270
Jiri Pirkofc56be42018-04-05 22:13:21 +0200271typedef u64 devlink_resource_occ_get_t(void *priv);
272
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100273/**
274 * struct devlink_resource - devlink resource
275 * @name: name of the resource
276 * @id: id, per devlink instance
277 * @size: size of the resource
278 * @size_new: updated size of the resource, reload is needed
279 * @size_valid: valid in case the total size of the resource is valid
280 * including its children
281 * @parent: parent resource
282 * @size_params: size parameters
283 * @list: parent list
284 * @resource_list: list of child resources
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100285 */
286struct devlink_resource {
287 const char *name;
288 u64 id;
289 u64 size;
290 u64 size_new;
291 bool size_valid;
292 struct devlink_resource *parent;
Jiri Pirko77d27092018-02-28 13:12:09 +0100293 struct devlink_resource_size_params size_params;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100294 struct list_head list;
295 struct list_head resource_list;
Jiri Pirkofc56be42018-04-05 22:13:21 +0200296 devlink_resource_occ_get_t *occ_get;
297 void *occ_get_priv;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100298};
299
300#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
301
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300302#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
Moshe Shemesheabaef12018-07-04 14:30:28 +0300303enum devlink_param_type {
304 DEVLINK_PARAM_TYPE_U8,
305 DEVLINK_PARAM_TYPE_U16,
306 DEVLINK_PARAM_TYPE_U32,
307 DEVLINK_PARAM_TYPE_STRING,
308 DEVLINK_PARAM_TYPE_BOOL,
309};
310
311union devlink_param_value {
312 u8 vu8;
313 u16 vu16;
314 u32 vu32;
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300315 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
Moshe Shemesheabaef12018-07-04 14:30:28 +0300316 bool vbool;
317};
318
319struct devlink_param_gset_ctx {
320 union devlink_param_value val;
321 enum devlink_param_cmode cmode;
322};
323
324/**
325 * struct devlink_param - devlink configuration parameter data
326 * @name: name of the parameter
327 * @generic: indicates if the parameter is generic or driver specific
328 * @type: parameter type
329 * @supported_cmodes: bitmap of supported configuration modes
330 * @get: get parameter value, used for runtime and permanent
331 * configuration modes
332 * @set: set parameter value, used for runtime and permanent
333 * configuration modes
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300334 * @validate: validate input value is applicable (within value range, etc.)
Moshe Shemesheabaef12018-07-04 14:30:28 +0300335 *
336 * This struct should be used by the driver to fill the data for
337 * a parameter it registers.
338 */
339struct devlink_param {
340 u32 id;
341 const char *name;
342 bool generic;
343 enum devlink_param_type type;
344 unsigned long supported_cmodes;
345 int (*get)(struct devlink *devlink, u32 id,
346 struct devlink_param_gset_ctx *ctx);
347 int (*set)(struct devlink *devlink, u32 id,
348 struct devlink_param_gset_ctx *ctx);
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300349 int (*validate)(struct devlink *devlink, u32 id,
350 union devlink_param_value val,
351 struct netlink_ext_ack *extack);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300352};
353
354struct devlink_param_item {
355 struct list_head list;
356 const struct devlink_param *param;
357 union devlink_param_value driverinit_value;
358 bool driverinit_value_valid;
359};
360
361enum devlink_param_generic_id {
Moshe Shemesh036467c2018-07-04 14:30:33 +0300362 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
363 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300364 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
Alex Veskerf6a698852018-07-12 15:13:17 +0300365 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
Vasundhara Volame3b51062018-10-04 11:13:44 +0530366 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530367 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
Vasundhara Volam16511782018-10-04 11:13:46 +0530368 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
Shalom Toledo846e9802018-12-03 07:58:59 +0000369 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
Vasundhara Volamb6395832019-01-28 18:00:26 +0530370 DEVLINK_PARAM_GENERIC_ID_WOL,
Moshe Shemesheabaef12018-07-04 14:30:28 +0300371
372 /* add new param generic ids above here*/
373 __DEVLINK_PARAM_GENERIC_ID_MAX,
374 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
375};
376
Vasundhara Volamb6395832019-01-28 18:00:26 +0530377enum devlink_param_wol_types {
378 DEVLINK_PARAM_WAKE_MAGIC = (1 << 0),
379};
380
Moshe Shemesh036467c2018-07-04 14:30:33 +0300381#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
382#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
383
384#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
385#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
386
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300387#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
388#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
389
Alex Veskerf6a698852018-07-12 15:13:17 +0300390#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
391#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
392
Vasundhara Volame3b51062018-10-04 11:13:44 +0530393#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
394#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
395
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530396#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
397#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
398
Vasundhara Volam16511782018-10-04 11:13:46 +0530399#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
400#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
401
Shalom Toledo846e9802018-12-03 07:58:59 +0000402#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
403#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
404
Vasundhara Volamb6395832019-01-28 18:00:26 +0530405#define DEVLINK_PARAM_GENERIC_WOL_NAME "wake_on_lan"
406#define DEVLINK_PARAM_GENERIC_WOL_TYPE DEVLINK_PARAM_TYPE_U8
407
Moshe Shemesh036467c2018-07-04 14:30:33 +0300408#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
409{ \
410 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
411 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
412 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
413 .generic = true, \
414 .supported_cmodes = _cmodes, \
415 .get = _get, \
416 .set = _set, \
417 .validate = _validate, \
418}
419
420#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
421{ \
422 .id = _id, \
423 .name = _name, \
424 .type = _type, \
425 .supported_cmodes = _cmodes, \
426 .get = _get, \
427 .set = _set, \
428 .validate = _validate, \
429}
430
Jakub Kicinski785bd552019-01-31 10:50:42 -0800431/* Part number, identifier of board design */
432#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
433/* Revision of board design */
434#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
435
436/* Control processor FW version */
437#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
438/* Data path microcode controlling high-speed packet processing */
439#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
440/* UNDI software version */
441#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
442/* NCSI support/handler version */
443#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
444
Alex Veskerb16ebe92018-07-12 15:13:08 +0300445struct devlink_region;
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800446struct devlink_info_req;
Alex Veskerb16ebe92018-07-12 15:13:08 +0300447
Alex Veskerd7e52722018-07-12 15:13:10 +0300448typedef void devlink_snapshot_data_dest_t(const void *data);
449
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100450struct devlink_ops {
David Ahernac0fc8a2018-06-05 08:14:09 -0700451 int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100452 int (*port_type_set)(struct devlink_port *devlink_port,
453 enum devlink_port_type port_type);
454 int (*port_split)(struct devlink *devlink, unsigned int port_index,
David Ahernac0fc8a2018-06-05 08:14:09 -0700455 unsigned int count, struct netlink_ext_ack *extack);
456 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
457 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200458 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
459 u16 pool_index,
460 struct devlink_sb_pool_info *pool_info);
461 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
462 u16 pool_index, u32 size,
463 enum devlink_sb_threshold_type threshold_type);
464 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
465 unsigned int sb_index, u16 pool_index,
466 u32 *p_threshold);
467 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
468 unsigned int sb_index, u16 pool_index,
469 u32 threshold);
470 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
471 unsigned int sb_index,
472 u16 tc_index,
473 enum devlink_sb_pool_type pool_type,
474 u16 *p_pool_index, u32 *p_threshold);
475 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
476 unsigned int sb_index,
477 u16 tc_index,
478 enum devlink_sb_pool_type pool_type,
479 u16 pool_index, u32 threshold);
Jiri Pirkodf38daf2016-04-14 18:19:14 +0200480 int (*sb_occ_snapshot)(struct devlink *devlink,
481 unsigned int sb_index);
482 int (*sb_occ_max_clear)(struct devlink *devlink,
483 unsigned int sb_index);
484 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
485 unsigned int sb_index, u16 pool_index,
486 u32 *p_cur, u32 *p_max);
487 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
488 unsigned int sb_index,
489 u16 tc_index,
490 enum devlink_sb_pool_type pool_type,
491 u32 *p_cur, u32 *p_max);
Or Gerlitz08f4b592016-07-01 14:51:01 +0300492
493 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300494 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
495 struct netlink_ext_ack *extack);
Roi Dayan59bfde02016-11-22 23:09:57 +0200496 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300497 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
498 struct netlink_ext_ack *extack);
Roi Dayanf43e9b02016-09-25 13:52:44 +0300499 int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300500 int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode,
501 struct netlink_ext_ack *extack);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800502 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
503 struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100504};
505
506static inline void *devlink_priv(struct devlink *devlink)
507{
508 BUG_ON(!devlink);
509 return &devlink->priv;
510}
511
512static inline struct devlink *priv_to_devlink(void *priv)
513{
514 BUG_ON(!priv);
515 return container_of(priv, struct devlink, priv);
516}
517
518struct ib_device;
519
520#if IS_ENABLED(CONFIG_NET_DEVLINK)
521
522struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
523int devlink_register(struct devlink *devlink, struct device *dev);
524void devlink_unregister(struct devlink *devlink);
525void devlink_free(struct devlink *devlink);
526int devlink_port_register(struct devlink *devlink,
527 struct devlink_port *devlink_port,
528 unsigned int port_index);
529void devlink_port_unregister(struct devlink_port *devlink_port);
530void devlink_port_type_eth_set(struct devlink_port *devlink_port,
531 struct net_device *netdev);
532void devlink_port_type_ib_set(struct devlink_port *devlink_port,
533 struct ib_device *ibdev);
534void devlink_port_type_clear(struct devlink_port *devlink_port);
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200535void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200536 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200537 u32 port_number, bool split,
538 u32 split_subport_number);
Jiri Pirko08474c12018-05-18 09:29:02 +0200539int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
540 char *name, size_t len);
Jiri Pirkobf797472016-04-14 18:19:13 +0200541int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
542 u32 size, u16 ingress_pools_count,
543 u16 egress_pools_count, u16 ingress_tc_count,
544 u16 egress_tc_count);
545void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200546int devlink_dpipe_table_register(struct devlink *devlink,
547 const char *table_name,
548 struct devlink_dpipe_table_ops *table_ops,
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200549 void *priv, bool counter_control_extern);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200550void devlink_dpipe_table_unregister(struct devlink *devlink,
551 const char *table_name);
552int devlink_dpipe_headers_register(struct devlink *devlink,
553 struct devlink_dpipe_headers *dpipe_headers);
554void devlink_dpipe_headers_unregister(struct devlink *devlink);
555bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
556 const char *table_name);
557int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
558int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
559 struct devlink_dpipe_entry *entry);
560int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200561void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200562int devlink_dpipe_action_put(struct sk_buff *skb,
563 struct devlink_dpipe_action *action);
564int devlink_dpipe_match_put(struct sk_buff *skb,
565 struct devlink_dpipe_match *match);
Arkadi Sharshevsky11770092017-08-24 08:39:59 +0200566extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
Arkadi Sharshevsky3fb886e2017-08-24 08:40:00 +0200567extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
Arkadi Sharshevsky1797f5b2017-08-31 17:59:12 +0200568extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100569
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100570int devlink_resource_register(struct devlink *devlink,
571 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100572 u64 resource_size,
573 u64 resource_id,
574 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200575 const struct devlink_resource_size_params *size_params);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100576void devlink_resources_unregister(struct devlink *devlink,
577 struct devlink_resource *resource);
578int devlink_resource_size_get(struct devlink *devlink,
579 u64 resource_id,
580 u64 *p_resource_size);
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100581int devlink_dpipe_table_resource_set(struct devlink *devlink,
582 const char *table_name, u64 resource_id,
583 u64 resource_units);
Jiri Pirkofc56be42018-04-05 22:13:21 +0200584void devlink_resource_occ_get_register(struct devlink *devlink,
585 u64 resource_id,
586 devlink_resource_occ_get_t *occ_get,
587 void *occ_get_priv);
588void devlink_resource_occ_get_unregister(struct devlink *devlink,
589 u64 resource_id);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300590int devlink_params_register(struct devlink *devlink,
591 const struct devlink_param *params,
592 size_t params_count);
593void devlink_params_unregister(struct devlink *devlink,
594 const struct devlink_param *params,
595 size_t params_count);
Vasundhara Volam39e61602019-01-28 18:00:20 +0530596int devlink_port_params_register(struct devlink_port *devlink_port,
597 const struct devlink_param *params,
598 size_t params_count);
599void devlink_port_params_unregister(struct devlink_port *devlink_port,
600 const struct devlink_param *params,
601 size_t params_count);
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300602int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
603 union devlink_param_value *init_val);
604int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
605 union devlink_param_value init_val);
Vasundhara Volamffd19b92019-01-28 18:00:23 +0530606int
607devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
608 u32 param_id,
609 union devlink_param_value *init_val);
Vasundhara Volam5473a7b2019-01-28 18:00:24 +0530610int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
611 u32 param_id,
612 union devlink_param_value init_val);
Moshe Shemeshea601e12018-07-04 14:30:32 +0300613void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
Vasundhara Volamc1e5786d2019-01-28 18:00:25 +0530614void devlink_port_param_value_changed(struct devlink_port *devlink_port,
615 u32 param_id);
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300616void devlink_param_value_str_fill(union devlink_param_value *dst_val,
617 const char *src);
Alex Veskerb16ebe92018-07-12 15:13:08 +0300618struct devlink_region *devlink_region_create(struct devlink *devlink,
619 const char *region_name,
620 u32 region_max_snapshots,
621 u64 region_size);
622void devlink_region_destroy(struct devlink_region *region);
Alex Veskerccadfa42018-07-12 15:13:09 +0300623u32 devlink_region_shapshot_id_get(struct devlink *devlink);
Alex Veskerd7e52722018-07-12 15:13:10 +0300624int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
625 u8 *data, u32 snapshot_id,
626 devlink_snapshot_data_dest_t *data_destructor);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800627int devlink_info_serial_number_put(struct devlink_info_req *req,
628 const char *sn);
629int devlink_info_driver_name_put(struct devlink_info_req *req,
630 const char *name);
Jakub Kicinskifc6fae72019-01-31 10:50:41 -0800631int devlink_info_version_fixed_put(struct devlink_info_req *req,
632 const char *version_name,
633 const char *version_value);
634int devlink_info_version_stored_put(struct devlink_info_req *req,
635 const char *version_name,
636 const char *version_value);
637int devlink_info_version_running_put(struct devlink_info_req *req,
638 const char *version_name,
639 const char *version_value);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100640
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100641#else
642
643static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
644 size_t priv_size)
645{
646 return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
647}
648
649static inline int devlink_register(struct devlink *devlink, struct device *dev)
650{
651 return 0;
652}
653
654static inline void devlink_unregister(struct devlink *devlink)
655{
656}
657
658static inline void devlink_free(struct devlink *devlink)
659{
660 kfree(devlink);
661}
662
663static inline int devlink_port_register(struct devlink *devlink,
664 struct devlink_port *devlink_port,
665 unsigned int port_index)
666{
667 return 0;
668}
669
670static inline void devlink_port_unregister(struct devlink_port *devlink_port)
671{
672}
673
674static inline void devlink_port_type_eth_set(struct devlink_port *devlink_port,
675 struct net_device *netdev)
676{
677}
678
679static inline void devlink_port_type_ib_set(struct devlink_port *devlink_port,
680 struct ib_device *ibdev)
681{
682}
683
684static inline void devlink_port_type_clear(struct devlink_port *devlink_port)
685{
686}
687
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200688static inline void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200689 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200690 u32 port_number, bool split,
691 u32 split_subport_number)
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100692{
693}
694
Jiri Pirko08474c12018-05-18 09:29:02 +0200695static inline int
696devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
697 char *name, size_t len)
698{
699 return -EOPNOTSUPP;
700}
701
Jiri Pirkobf797472016-04-14 18:19:13 +0200702static inline int devlink_sb_register(struct devlink *devlink,
703 unsigned int sb_index, u32 size,
704 u16 ingress_pools_count,
Jiri Pirkode33efd2016-04-15 09:17:08 +0200705 u16 egress_pools_count,
706 u16 ingress_tc_count,
707 u16 egress_tc_count)
Jiri Pirkobf797472016-04-14 18:19:13 +0200708{
709 return 0;
710}
711
712static inline void devlink_sb_unregister(struct devlink *devlink,
713 unsigned int sb_index)
714{
715}
716
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200717static inline int
718devlink_dpipe_table_register(struct devlink *devlink,
719 const char *table_name,
720 struct devlink_dpipe_table_ops *table_ops,
David S. Miller790c6052017-08-24 18:10:46 -0700721 void *priv, bool counter_control_extern)
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200722{
723 return 0;
724}
725
726static inline void devlink_dpipe_table_unregister(struct devlink *devlink,
727 const char *table_name)
728{
729}
730
731static inline int devlink_dpipe_headers_register(struct devlink *devlink,
732 struct devlink_dpipe_headers *
733 dpipe_headers)
734{
735 return 0;
736}
737
738static inline void devlink_dpipe_headers_unregister(struct devlink *devlink)
739{
740}
741
742static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
743 const char *table_name)
744{
745 return false;
746}
747
748static inline int
749devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx)
750{
751 return 0;
752}
753
754static inline int
755devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
756 struct devlink_dpipe_entry *entry)
757{
758 return 0;
759}
760
761static inline int
762devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx)
763{
764 return 0;
765}
766
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200767static inline void
768devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry)
769{
770}
771
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200772static inline int
773devlink_dpipe_action_put(struct sk_buff *skb,
774 struct devlink_dpipe_action *action)
775{
776 return 0;
777}
778
779static inline int
780devlink_dpipe_match_put(struct sk_buff *skb,
781 struct devlink_dpipe_match *match)
782{
783 return 0;
784}
785
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100786static inline int
787devlink_resource_register(struct devlink *devlink,
788 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100789 u64 resource_size,
790 u64 resource_id,
791 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200792 const struct devlink_resource_size_params *size_params)
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100793{
794 return 0;
795}
796
797static inline void
798devlink_resources_unregister(struct devlink *devlink,
799 struct devlink_resource *resource)
800{
801}
802
803static inline int
804devlink_resource_size_get(struct devlink *devlink, u64 resource_id,
805 u64 *p_resource_size)
806{
807 return -EOPNOTSUPP;
808}
809
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100810static inline int
811devlink_dpipe_table_resource_set(struct devlink *devlink,
812 const char *table_name, u64 resource_id,
813 u64 resource_units)
814{
815 return -EOPNOTSUPP;
816}
817
Jiri Pirkofc56be42018-04-05 22:13:21 +0200818static inline void
819devlink_resource_occ_get_register(struct devlink *devlink,
820 u64 resource_id,
821 devlink_resource_occ_get_t *occ_get,
822 void *occ_get_priv)
823{
824}
825
826static inline void
827devlink_resource_occ_get_unregister(struct devlink *devlink,
828 u64 resource_id)
829{
830}
831
Moshe Shemesheabaef12018-07-04 14:30:28 +0300832static inline int
833devlink_params_register(struct devlink *devlink,
834 const struct devlink_param *params,
835 size_t params_count)
836{
837 return 0;
838}
839
840static inline void
841devlink_params_unregister(struct devlink *devlink,
842 const struct devlink_param *params,
843 size_t params_count)
844{
845
846}
847
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300848static inline int
Vasundhara Volam39e61602019-01-28 18:00:20 +0530849devlink_port_params_register(struct devlink_port *devlink_port,
850 const struct devlink_param *params,
851 size_t params_count)
852{
853 return 0;
854}
855
856static inline void
857devlink_port_params_unregister(struct devlink_port *devlink_port,
858 const struct devlink_param *params,
859 size_t params_count)
860{
861}
862
863static inline int
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300864devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
865 union devlink_param_value *init_val)
866{
867 return -EOPNOTSUPP;
868}
869
870static inline int
871devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
872 union devlink_param_value init_val)
873{
874 return -EOPNOTSUPP;
875}
876
Vasundhara Volamffd19b92019-01-28 18:00:23 +0530877static inline int
878devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
879 u32 param_id,
880 union devlink_param_value *init_val)
881{
882 return -EOPNOTSUPP;
883}
884
Vasundhara Volam5473a7b2019-01-28 18:00:24 +0530885static inline int
886devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
887 u32 param_id,
888 union devlink_param_value init_val)
889{
890 return -EOPNOTSUPP;
891}
892
Moshe Shemeshea601e12018-07-04 14:30:32 +0300893static inline void
894devlink_param_value_changed(struct devlink *devlink, u32 param_id)
895{
Moshe Shemeshea601e12018-07-04 14:30:32 +0300896}
897
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300898static inline void
Vasundhara Volamc1e5786d2019-01-28 18:00:25 +0530899devlink_port_param_value_changed(struct devlink_port *devlink_port,
900 u32 param_id)
901{
902}
903
904static inline void
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300905devlink_param_value_str_fill(union devlink_param_value *dst_val,
906 const char *src)
907{
908}
909
Alex Veskerb16ebe92018-07-12 15:13:08 +0300910static inline struct devlink_region *
911devlink_region_create(struct devlink *devlink,
912 const char *region_name,
913 u32 region_max_snapshots,
914 u64 region_size)
915{
916 return NULL;
917}
918
919static inline void
920devlink_region_destroy(struct devlink_region *region)
921{
922}
923
Alex Veskerccadfa42018-07-12 15:13:09 +0300924static inline u32
925devlink_region_shapshot_id_get(struct devlink *devlink)
926{
927 return 0;
928}
929
Alex Veskerd7e52722018-07-12 15:13:10 +0300930static inline int
931devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
932 u8 *data, u32 snapshot_id,
933 devlink_snapshot_data_dest_t *data_destructor)
934{
935 return 0;
936}
937
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800938static inline int
939devlink_info_driver_name_put(struct devlink_info_req *req, const char *name)
940{
941 return 0;
942}
943
944static inline int
945devlink_info_serial_number_put(struct devlink_info_req *req, const char *sn)
946{
947 return 0;
948}
Jakub Kicinskifc6fae72019-01-31 10:50:41 -0800949
950static inline int
951devlink_info_version_fixed_put(struct devlink_info_req *req,
952 const char *version_name,
953 const char *version_value)
954{
955 return 0;
956}
957
958static inline int
959devlink_info_version_stored_put(struct devlink_info_req *req,
960 const char *version_name,
961 const char *version_value)
962{
963 return 0;
964}
965
966static inline int
967devlink_info_version_running_put(struct devlink_info_req *req,
968 const char *version_name,
969 const char *version_value)
970{
971 return 0;
972}
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100973#endif
974
975#endif /* _NET_DEVLINK_H_ */