blob: 6dc0ef964392a3e365a7e66c9ba4a3a895dc4468 [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
Alex Veskerb16ebe92018-07-12 15:13:08 +0300431struct devlink_region;
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800432struct devlink_info_req;
Alex Veskerb16ebe92018-07-12 15:13:08 +0300433
Alex Veskerd7e52722018-07-12 15:13:10 +0300434typedef void devlink_snapshot_data_dest_t(const void *data);
435
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100436struct devlink_ops {
David Ahernac0fc8a2018-06-05 08:14:09 -0700437 int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100438 int (*port_type_set)(struct devlink_port *devlink_port,
439 enum devlink_port_type port_type);
440 int (*port_split)(struct devlink *devlink, unsigned int port_index,
David Ahernac0fc8a2018-06-05 08:14:09 -0700441 unsigned int count, struct netlink_ext_ack *extack);
442 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
443 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200444 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
445 u16 pool_index,
446 struct devlink_sb_pool_info *pool_info);
447 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
448 u16 pool_index, u32 size,
449 enum devlink_sb_threshold_type threshold_type);
450 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
451 unsigned int sb_index, u16 pool_index,
452 u32 *p_threshold);
453 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
454 unsigned int sb_index, u16 pool_index,
455 u32 threshold);
456 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
457 unsigned int sb_index,
458 u16 tc_index,
459 enum devlink_sb_pool_type pool_type,
460 u16 *p_pool_index, u32 *p_threshold);
461 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
462 unsigned int sb_index,
463 u16 tc_index,
464 enum devlink_sb_pool_type pool_type,
465 u16 pool_index, u32 threshold);
Jiri Pirkodf38daf2016-04-14 18:19:14 +0200466 int (*sb_occ_snapshot)(struct devlink *devlink,
467 unsigned int sb_index);
468 int (*sb_occ_max_clear)(struct devlink *devlink,
469 unsigned int sb_index);
470 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
471 unsigned int sb_index, u16 pool_index,
472 u32 *p_cur, u32 *p_max);
473 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
474 unsigned int sb_index,
475 u16 tc_index,
476 enum devlink_sb_pool_type pool_type,
477 u32 *p_cur, u32 *p_max);
Or Gerlitz08f4b592016-07-01 14:51:01 +0300478
479 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300480 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
481 struct netlink_ext_ack *extack);
Roi Dayan59bfde02016-11-22 23:09:57 +0200482 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300483 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
484 struct netlink_ext_ack *extack);
Roi Dayanf43e9b02016-09-25 13:52:44 +0300485 int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +0300486 int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode,
487 struct netlink_ext_ack *extack);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800488 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
489 struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100490};
491
492static inline void *devlink_priv(struct devlink *devlink)
493{
494 BUG_ON(!devlink);
495 return &devlink->priv;
496}
497
498static inline struct devlink *priv_to_devlink(void *priv)
499{
500 BUG_ON(!priv);
501 return container_of(priv, struct devlink, priv);
502}
503
504struct ib_device;
505
506#if IS_ENABLED(CONFIG_NET_DEVLINK)
507
508struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
509int devlink_register(struct devlink *devlink, struct device *dev);
510void devlink_unregister(struct devlink *devlink);
511void devlink_free(struct devlink *devlink);
512int devlink_port_register(struct devlink *devlink,
513 struct devlink_port *devlink_port,
514 unsigned int port_index);
515void devlink_port_unregister(struct devlink_port *devlink_port);
516void devlink_port_type_eth_set(struct devlink_port *devlink_port,
517 struct net_device *netdev);
518void devlink_port_type_ib_set(struct devlink_port *devlink_port,
519 struct ib_device *ibdev);
520void devlink_port_type_clear(struct devlink_port *devlink_port);
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200521void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200522 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200523 u32 port_number, bool split,
524 u32 split_subport_number);
Jiri Pirko08474c12018-05-18 09:29:02 +0200525int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
526 char *name, size_t len);
Jiri Pirkobf797472016-04-14 18:19:13 +0200527int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
528 u32 size, u16 ingress_pools_count,
529 u16 egress_pools_count, u16 ingress_tc_count,
530 u16 egress_tc_count);
531void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200532int devlink_dpipe_table_register(struct devlink *devlink,
533 const char *table_name,
534 struct devlink_dpipe_table_ops *table_ops,
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200535 void *priv, bool counter_control_extern);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200536void devlink_dpipe_table_unregister(struct devlink *devlink,
537 const char *table_name);
538int devlink_dpipe_headers_register(struct devlink *devlink,
539 struct devlink_dpipe_headers *dpipe_headers);
540void devlink_dpipe_headers_unregister(struct devlink *devlink);
541bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
542 const char *table_name);
543int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
544int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
545 struct devlink_dpipe_entry *entry);
546int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200547void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200548int devlink_dpipe_action_put(struct sk_buff *skb,
549 struct devlink_dpipe_action *action);
550int devlink_dpipe_match_put(struct sk_buff *skb,
551 struct devlink_dpipe_match *match);
Arkadi Sharshevsky11770092017-08-24 08:39:59 +0200552extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
Arkadi Sharshevsky3fb886e2017-08-24 08:40:00 +0200553extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
Arkadi Sharshevsky1797f5b2017-08-31 17:59:12 +0200554extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100555
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100556int devlink_resource_register(struct devlink *devlink,
557 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100558 u64 resource_size,
559 u64 resource_id,
560 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200561 const struct devlink_resource_size_params *size_params);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100562void devlink_resources_unregister(struct devlink *devlink,
563 struct devlink_resource *resource);
564int devlink_resource_size_get(struct devlink *devlink,
565 u64 resource_id,
566 u64 *p_resource_size);
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100567int devlink_dpipe_table_resource_set(struct devlink *devlink,
568 const char *table_name, u64 resource_id,
569 u64 resource_units);
Jiri Pirkofc56be42018-04-05 22:13:21 +0200570void devlink_resource_occ_get_register(struct devlink *devlink,
571 u64 resource_id,
572 devlink_resource_occ_get_t *occ_get,
573 void *occ_get_priv);
574void devlink_resource_occ_get_unregister(struct devlink *devlink,
575 u64 resource_id);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300576int devlink_params_register(struct devlink *devlink,
577 const struct devlink_param *params,
578 size_t params_count);
579void devlink_params_unregister(struct devlink *devlink,
580 const struct devlink_param *params,
581 size_t params_count);
Vasundhara Volam39e61602019-01-28 18:00:20 +0530582int devlink_port_params_register(struct devlink_port *devlink_port,
583 const struct devlink_param *params,
584 size_t params_count);
585void devlink_port_params_unregister(struct devlink_port *devlink_port,
586 const struct devlink_param *params,
587 size_t params_count);
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300588int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
589 union devlink_param_value *init_val);
590int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
591 union devlink_param_value init_val);
Vasundhara Volamffd19b92019-01-28 18:00:23 +0530592int
593devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
594 u32 param_id,
595 union devlink_param_value *init_val);
Vasundhara Volam5473a7b2019-01-28 18:00:24 +0530596int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
597 u32 param_id,
598 union devlink_param_value init_val);
Moshe Shemeshea601e12018-07-04 14:30:32 +0300599void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
Vasundhara Volamc1e5786d2019-01-28 18:00:25 +0530600void devlink_port_param_value_changed(struct devlink_port *devlink_port,
601 u32 param_id);
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300602void devlink_param_value_str_fill(union devlink_param_value *dst_val,
603 const char *src);
Alex Veskerb16ebe92018-07-12 15:13:08 +0300604struct devlink_region *devlink_region_create(struct devlink *devlink,
605 const char *region_name,
606 u32 region_max_snapshots,
607 u64 region_size);
608void devlink_region_destroy(struct devlink_region *region);
Alex Veskerccadfa42018-07-12 15:13:09 +0300609u32 devlink_region_shapshot_id_get(struct devlink *devlink);
Alex Veskerd7e52722018-07-12 15:13:10 +0300610int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
611 u8 *data, u32 snapshot_id,
612 devlink_snapshot_data_dest_t *data_destructor);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800613int devlink_info_serial_number_put(struct devlink_info_req *req,
614 const char *sn);
615int devlink_info_driver_name_put(struct devlink_info_req *req,
616 const char *name);
Jakub Kicinskifc6fae72019-01-31 10:50:41 -0800617int devlink_info_version_fixed_put(struct devlink_info_req *req,
618 const char *version_name,
619 const char *version_value);
620int devlink_info_version_stored_put(struct devlink_info_req *req,
621 const char *version_name,
622 const char *version_value);
623int devlink_info_version_running_put(struct devlink_info_req *req,
624 const char *version_name,
625 const char *version_value);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100626
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100627#else
628
629static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
630 size_t priv_size)
631{
632 return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
633}
634
635static inline int devlink_register(struct devlink *devlink, struct device *dev)
636{
637 return 0;
638}
639
640static inline void devlink_unregister(struct devlink *devlink)
641{
642}
643
644static inline void devlink_free(struct devlink *devlink)
645{
646 kfree(devlink);
647}
648
649static inline int devlink_port_register(struct devlink *devlink,
650 struct devlink_port *devlink_port,
651 unsigned int port_index)
652{
653 return 0;
654}
655
656static inline void devlink_port_unregister(struct devlink_port *devlink_port)
657{
658}
659
660static inline void devlink_port_type_eth_set(struct devlink_port *devlink_port,
661 struct net_device *netdev)
662{
663}
664
665static inline void devlink_port_type_ib_set(struct devlink_port *devlink_port,
666 struct ib_device *ibdev)
667{
668}
669
670static inline void devlink_port_type_clear(struct devlink_port *devlink_port)
671{
672}
673
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200674static inline void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200675 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200676 u32 port_number, bool split,
677 u32 split_subport_number)
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100678{
679}
680
Jiri Pirko08474c12018-05-18 09:29:02 +0200681static inline int
682devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
683 char *name, size_t len)
684{
685 return -EOPNOTSUPP;
686}
687
Jiri Pirkobf797472016-04-14 18:19:13 +0200688static inline int devlink_sb_register(struct devlink *devlink,
689 unsigned int sb_index, u32 size,
690 u16 ingress_pools_count,
Jiri Pirkode33efd2016-04-15 09:17:08 +0200691 u16 egress_pools_count,
692 u16 ingress_tc_count,
693 u16 egress_tc_count)
Jiri Pirkobf797472016-04-14 18:19:13 +0200694{
695 return 0;
696}
697
698static inline void devlink_sb_unregister(struct devlink *devlink,
699 unsigned int sb_index)
700{
701}
702
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200703static inline int
704devlink_dpipe_table_register(struct devlink *devlink,
705 const char *table_name,
706 struct devlink_dpipe_table_ops *table_ops,
David S. Miller790c6052017-08-24 18:10:46 -0700707 void *priv, bool counter_control_extern)
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200708{
709 return 0;
710}
711
712static inline void devlink_dpipe_table_unregister(struct devlink *devlink,
713 const char *table_name)
714{
715}
716
717static inline int devlink_dpipe_headers_register(struct devlink *devlink,
718 struct devlink_dpipe_headers *
719 dpipe_headers)
720{
721 return 0;
722}
723
724static inline void devlink_dpipe_headers_unregister(struct devlink *devlink)
725{
726}
727
728static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
729 const char *table_name)
730{
731 return false;
732}
733
734static inline int
735devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx)
736{
737 return 0;
738}
739
740static inline int
741devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
742 struct devlink_dpipe_entry *entry)
743{
744 return 0;
745}
746
747static inline int
748devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx)
749{
750 return 0;
751}
752
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200753static inline void
754devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry)
755{
756}
757
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200758static inline int
759devlink_dpipe_action_put(struct sk_buff *skb,
760 struct devlink_dpipe_action *action)
761{
762 return 0;
763}
764
765static inline int
766devlink_dpipe_match_put(struct sk_buff *skb,
767 struct devlink_dpipe_match *match)
768{
769 return 0;
770}
771
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100772static inline int
773devlink_resource_register(struct devlink *devlink,
774 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100775 u64 resource_size,
776 u64 resource_id,
777 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200778 const struct devlink_resource_size_params *size_params)
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100779{
780 return 0;
781}
782
783static inline void
784devlink_resources_unregister(struct devlink *devlink,
785 struct devlink_resource *resource)
786{
787}
788
789static inline int
790devlink_resource_size_get(struct devlink *devlink, u64 resource_id,
791 u64 *p_resource_size)
792{
793 return -EOPNOTSUPP;
794}
795
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100796static inline int
797devlink_dpipe_table_resource_set(struct devlink *devlink,
798 const char *table_name, u64 resource_id,
799 u64 resource_units)
800{
801 return -EOPNOTSUPP;
802}
803
Jiri Pirkofc56be42018-04-05 22:13:21 +0200804static inline void
805devlink_resource_occ_get_register(struct devlink *devlink,
806 u64 resource_id,
807 devlink_resource_occ_get_t *occ_get,
808 void *occ_get_priv)
809{
810}
811
812static inline void
813devlink_resource_occ_get_unregister(struct devlink *devlink,
814 u64 resource_id)
815{
816}
817
Moshe Shemesheabaef12018-07-04 14:30:28 +0300818static inline int
819devlink_params_register(struct devlink *devlink,
820 const struct devlink_param *params,
821 size_t params_count)
822{
823 return 0;
824}
825
826static inline void
827devlink_params_unregister(struct devlink *devlink,
828 const struct devlink_param *params,
829 size_t params_count)
830{
831
832}
833
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300834static inline int
Vasundhara Volam39e61602019-01-28 18:00:20 +0530835devlink_port_params_register(struct devlink_port *devlink_port,
836 const struct devlink_param *params,
837 size_t params_count)
838{
839 return 0;
840}
841
842static inline void
843devlink_port_params_unregister(struct devlink_port *devlink_port,
844 const struct devlink_param *params,
845 size_t params_count)
846{
847}
848
849static inline int
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300850devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
851 union devlink_param_value *init_val)
852{
853 return -EOPNOTSUPP;
854}
855
856static inline int
857devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
858 union devlink_param_value init_val)
859{
860 return -EOPNOTSUPP;
861}
862
Vasundhara Volamffd19b92019-01-28 18:00:23 +0530863static inline int
864devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
865 u32 param_id,
866 union devlink_param_value *init_val)
867{
868 return -EOPNOTSUPP;
869}
870
Vasundhara Volam5473a7b2019-01-28 18:00:24 +0530871static inline int
872devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
873 u32 param_id,
874 union devlink_param_value init_val)
875{
876 return -EOPNOTSUPP;
877}
878
Moshe Shemeshea601e12018-07-04 14:30:32 +0300879static inline void
880devlink_param_value_changed(struct devlink *devlink, u32 param_id)
881{
Moshe Shemeshea601e12018-07-04 14:30:32 +0300882}
883
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300884static inline void
Vasundhara Volamc1e5786d2019-01-28 18:00:25 +0530885devlink_port_param_value_changed(struct devlink_port *devlink_port,
886 u32 param_id)
887{
888}
889
890static inline void
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300891devlink_param_value_str_fill(union devlink_param_value *dst_val,
892 const char *src)
893{
894}
895
Alex Veskerb16ebe92018-07-12 15:13:08 +0300896static inline struct devlink_region *
897devlink_region_create(struct devlink *devlink,
898 const char *region_name,
899 u32 region_max_snapshots,
900 u64 region_size)
901{
902 return NULL;
903}
904
905static inline void
906devlink_region_destroy(struct devlink_region *region)
907{
908}
909
Alex Veskerccadfa42018-07-12 15:13:09 +0300910static inline u32
911devlink_region_shapshot_id_get(struct devlink *devlink)
912{
913 return 0;
914}
915
Alex Veskerd7e52722018-07-12 15:13:10 +0300916static inline int
917devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
918 u8 *data, u32 snapshot_id,
919 devlink_snapshot_data_dest_t *data_destructor)
920{
921 return 0;
922}
923
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800924static inline int
925devlink_info_driver_name_put(struct devlink_info_req *req, const char *name)
926{
927 return 0;
928}
929
930static inline int
931devlink_info_serial_number_put(struct devlink_info_req *req, const char *sn)
932{
933 return 0;
934}
Jakub Kicinskifc6fae72019-01-31 10:50:41 -0800935
936static inline int
937devlink_info_version_fixed_put(struct devlink_info_req *req,
938 const char *version_name,
939 const char *version_value)
940{
941 return 0;
942}
943
944static inline int
945devlink_info_version_stored_put(struct devlink_info_req *req,
946 const char *version_name,
947 const char *version_value)
948{
949 return 0;
950}
951
952static inline int
953devlink_info_version_running_put(struct devlink_info_req *req,
954 const char *version_name,
955 const char *version_value)
956{
957 return 0;
958}
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100959#endif
960
961#endif /* _NET_DEVLINK_H_ */