blob: 8ed5713856269bb1bb8a4de679f673a1bf812e08 [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;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020031 struct devlink_dpipe_headers *dpipe_headers;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010032 const struct devlink_ops *ops;
33 struct device *dev;
34 possible_net_t _net;
Arkadi Sharshevsky2406e7e2018-01-15 08:59:02 +010035 struct mutex lock;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010036 char priv[0] __aligned(NETDEV_ALIGN);
37};
38
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020039struct devlink_port_attrs {
40 bool set;
Jiri Pirko5ec13802018-05-18 09:29:01 +020041 enum devlink_port_flavour flavour;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020042 u32 port_number; /* same value as "split group" */
43 bool split;
44 u32 split_subport_number;
45};
46
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010047struct devlink_port {
48 struct list_head list;
49 struct devlink *devlink;
50 unsigned index;
51 bool registered;
52 enum devlink_port_type type;
53 enum devlink_port_type desired_type;
54 void *type_dev;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020055 struct devlink_port_attrs attrs;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010056};
57
Jiri Pirkobf797472016-04-14 18:19:13 +020058struct devlink_sb_pool_info {
59 enum devlink_sb_pool_type pool_type;
60 u32 size;
61 enum devlink_sb_threshold_type threshold_type;
62};
63
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020064/**
65 * struct devlink_dpipe_field - dpipe field object
66 * @name: field name
67 * @id: index inside the headers field array
68 * @bitwidth: bitwidth
69 * @mapping_type: mapping type
70 */
71struct devlink_dpipe_field {
72 const char *name;
73 unsigned int id;
74 unsigned int bitwidth;
75 enum devlink_dpipe_field_mapping_type mapping_type;
76};
77
78/**
79 * struct devlink_dpipe_header - dpipe header object
80 * @name: header name
81 * @id: index, global/local detrmined by global bit
82 * @fields: fields
83 * @fields_count: number of fields
84 * @global: indicates if header is shared like most protocol header
85 * or driver specific
86 */
87struct devlink_dpipe_header {
88 const char *name;
89 unsigned int id;
90 struct devlink_dpipe_field *fields;
91 unsigned int fields_count;
92 bool global;
93};
94
95/**
96 * struct devlink_dpipe_match - represents match operation
97 * @type: type of match
98 * @header_index: header index (packets can have several headers of same
99 * type like in case of tunnels)
100 * @header: header
101 * @fieled_id: field index
102 */
103struct devlink_dpipe_match {
104 enum devlink_dpipe_match_type type;
105 unsigned int header_index;
106 struct devlink_dpipe_header *header;
107 unsigned int field_id;
108};
109
110/**
111 * struct devlink_dpipe_action - represents action operation
112 * @type: type of action
113 * @header_index: header index (packets can have several headers of same
114 * type like in case of tunnels)
115 * @header: header
116 * @fieled_id: field index
117 */
118struct devlink_dpipe_action {
119 enum devlink_dpipe_action_type type;
120 unsigned int header_index;
121 struct devlink_dpipe_header *header;
122 unsigned int field_id;
123};
124
125/**
126 * struct devlink_dpipe_value - represents value of match/action
127 * @action: action
128 * @match: match
129 * @mapping_value: in case the field has some mapping this value
130 * specified the mapping value
131 * @mapping_valid: specify if mapping value is valid
132 * @value_size: value size
133 * @value: value
134 * @mask: bit mask
135 */
136struct devlink_dpipe_value {
137 union {
138 struct devlink_dpipe_action *action;
139 struct devlink_dpipe_match *match;
140 };
141 unsigned int mapping_value;
142 bool mapping_valid;
143 unsigned int value_size;
144 void *value;
145 void *mask;
146};
147
148/**
149 * struct devlink_dpipe_entry - table entry object
150 * @index: index of the entry in the table
151 * @match_values: match values
152 * @matche_values_count: count of matches tuples
153 * @action_values: actions values
154 * @action_values_count: count of actions values
155 * @counter: value of counter
156 * @counter_valid: Specify if value is valid from hardware
157 */
158struct devlink_dpipe_entry {
159 u64 index;
160 struct devlink_dpipe_value *match_values;
161 unsigned int match_values_count;
162 struct devlink_dpipe_value *action_values;
163 unsigned int action_values_count;
164 u64 counter;
165 bool counter_valid;
166};
167
168/**
169 * struct devlink_dpipe_dump_ctx - context provided to driver in order
170 * to dump
171 * @info: info
172 * @cmd: devlink command
173 * @skb: skb
174 * @nest: top attribute
175 * @hdr: hdr
176 */
177struct devlink_dpipe_dump_ctx {
178 struct genl_info *info;
179 enum devlink_command cmd;
180 struct sk_buff *skb;
181 struct nlattr *nest;
182 void *hdr;
183};
184
185struct devlink_dpipe_table_ops;
186
187/**
188 * struct devlink_dpipe_table - table object
189 * @priv: private
190 * @name: table name
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200191 * @counters_enabled: indicates if counters are active
192 * @counter_control_extern: indicates if counter control is in dpipe or
193 * external tool
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100194 * @resource_valid: Indicate that the resource id is valid
195 * @resource_id: relative resource this table is related to
196 * @resource_units: number of resource's unit consumed per table's entry
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200197 * @table_ops: table operations
198 * @rcu: rcu
199 */
200struct devlink_dpipe_table {
201 void *priv;
202 struct list_head list;
203 const char *name;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200204 bool counters_enabled;
205 bool counter_control_extern;
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100206 bool resource_valid;
207 u64 resource_id;
208 u64 resource_units;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200209 struct devlink_dpipe_table_ops *table_ops;
210 struct rcu_head rcu;
211};
212
213/**
214 * struct devlink_dpipe_table_ops - dpipe_table ops
215 * @actions_dump - dumps all tables actions
216 * @matches_dump - dumps all tables matches
217 * @entries_dump - dumps all active entries in the table
218 * @counters_set_update - when changing the counter status hardware sync
219 * maybe needed to allocate/free counter related
220 * resources
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200221 * @size_get - get size
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200222 */
223struct devlink_dpipe_table_ops {
224 int (*actions_dump)(void *priv, struct sk_buff *skb);
225 int (*matches_dump)(void *priv, struct sk_buff *skb);
226 int (*entries_dump)(void *priv, bool counters_enabled,
227 struct devlink_dpipe_dump_ctx *dump_ctx);
228 int (*counters_set_update)(void *priv, bool enable);
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200229 u64 (*size_get)(void *priv);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200230};
231
232/**
233 * struct devlink_dpipe_headers - dpipe headers
234 * @headers - header array can be shared (global bit) or driver specific
235 * @headers_count - count of headers
236 */
237struct devlink_dpipe_headers {
238 struct devlink_dpipe_header **headers;
239 unsigned int headers_count;
240};
241
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100242/**
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100243 * struct devlink_resource_size_params - resource's size parameters
244 * @size_min: minimum size which can be set
245 * @size_max: maximum size which can be set
246 * @size_granularity: size granularity
247 * @size_unit: resource's basic unit
248 */
249struct devlink_resource_size_params {
250 u64 size_min;
251 u64 size_max;
252 u64 size_granularity;
253 enum devlink_resource_unit unit;
254};
255
Jiri Pirko77d27092018-02-28 13:12:09 +0100256static inline void
257devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
258 u64 size_min, u64 size_max,
259 u64 size_granularity,
260 enum devlink_resource_unit unit)
261{
262 size_params->size_min = size_min;
263 size_params->size_max = size_max;
264 size_params->size_granularity = size_granularity;
265 size_params->unit = unit;
266}
267
Jiri Pirkofc56be42018-04-05 22:13:21 +0200268typedef u64 devlink_resource_occ_get_t(void *priv);
269
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100270/**
271 * struct devlink_resource - devlink resource
272 * @name: name of the resource
273 * @id: id, per devlink instance
274 * @size: size of the resource
275 * @size_new: updated size of the resource, reload is needed
276 * @size_valid: valid in case the total size of the resource is valid
277 * including its children
278 * @parent: parent resource
279 * @size_params: size parameters
280 * @list: parent list
281 * @resource_list: list of child resources
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100282 */
283struct devlink_resource {
284 const char *name;
285 u64 id;
286 u64 size;
287 u64 size_new;
288 bool size_valid;
289 struct devlink_resource *parent;
Jiri Pirko77d27092018-02-28 13:12:09 +0100290 struct devlink_resource_size_params size_params;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100291 struct list_head list;
292 struct list_head resource_list;
Jiri Pirkofc56be42018-04-05 22:13:21 +0200293 devlink_resource_occ_get_t *occ_get;
294 void *occ_get_priv;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100295};
296
297#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
298
Moshe Shemesheabaef12018-07-04 14:30:28 +0300299#define DEVLINK_PARAM_MAX_STRING_VALUE 32
300enum devlink_param_type {
301 DEVLINK_PARAM_TYPE_U8,
302 DEVLINK_PARAM_TYPE_U16,
303 DEVLINK_PARAM_TYPE_U32,
304 DEVLINK_PARAM_TYPE_STRING,
305 DEVLINK_PARAM_TYPE_BOOL,
306};
307
308union devlink_param_value {
309 u8 vu8;
310 u16 vu16;
311 u32 vu32;
312 const char *vstr;
313 bool vbool;
314};
315
316struct devlink_param_gset_ctx {
317 union devlink_param_value val;
318 enum devlink_param_cmode cmode;
319};
320
321/**
322 * struct devlink_param - devlink configuration parameter data
323 * @name: name of the parameter
324 * @generic: indicates if the parameter is generic or driver specific
325 * @type: parameter type
326 * @supported_cmodes: bitmap of supported configuration modes
327 * @get: get parameter value, used for runtime and permanent
328 * configuration modes
329 * @set: set parameter value, used for runtime and permanent
330 * configuration modes
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300331 * @validate: validate input value is applicable (within value range, etc.)
Moshe Shemesheabaef12018-07-04 14:30:28 +0300332 *
333 * This struct should be used by the driver to fill the data for
334 * a parameter it registers.
335 */
336struct devlink_param {
337 u32 id;
338 const char *name;
339 bool generic;
340 enum devlink_param_type type;
341 unsigned long supported_cmodes;
342 int (*get)(struct devlink *devlink, u32 id,
343 struct devlink_param_gset_ctx *ctx);
344 int (*set)(struct devlink *devlink, u32 id,
345 struct devlink_param_gset_ctx *ctx);
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300346 int (*validate)(struct devlink *devlink, u32 id,
347 union devlink_param_value val,
348 struct netlink_ext_ack *extack);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300349};
350
351struct devlink_param_item {
352 struct list_head list;
353 const struct devlink_param *param;
354 union devlink_param_value driverinit_value;
355 bool driverinit_value_valid;
356};
357
358enum devlink_param_generic_id {
Moshe Shemesh036467c2018-07-04 14:30:33 +0300359 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
360 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300361 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
Moshe Shemesheabaef12018-07-04 14:30:28 +0300362
363 /* add new param generic ids above here*/
364 __DEVLINK_PARAM_GENERIC_ID_MAX,
365 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
366};
367
Moshe Shemesh036467c2018-07-04 14:30:33 +0300368#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
369#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
370
371#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
372#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
373
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300374#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
375#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
376
Moshe Shemesh036467c2018-07-04 14:30:33 +0300377#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
378{ \
379 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
380 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
381 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
382 .generic = true, \
383 .supported_cmodes = _cmodes, \
384 .get = _get, \
385 .set = _set, \
386 .validate = _validate, \
387}
388
389#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
390{ \
391 .id = _id, \
392 .name = _name, \
393 .type = _type, \
394 .supported_cmodes = _cmodes, \
395 .get = _get, \
396 .set = _set, \
397 .validate = _validate, \
398}
399
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100400struct devlink_ops {
David Ahernac0fc8a2018-06-05 08:14:09 -0700401 int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100402 int (*port_type_set)(struct devlink_port *devlink_port,
403 enum devlink_port_type port_type);
404 int (*port_split)(struct devlink *devlink, unsigned int port_index,
David Ahernac0fc8a2018-06-05 08:14:09 -0700405 unsigned int count, struct netlink_ext_ack *extack);
406 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
407 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200408 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
409 u16 pool_index,
410 struct devlink_sb_pool_info *pool_info);
411 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
412 u16 pool_index, u32 size,
413 enum devlink_sb_threshold_type threshold_type);
414 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
415 unsigned int sb_index, u16 pool_index,
416 u32 *p_threshold);
417 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
418 unsigned int sb_index, u16 pool_index,
419 u32 threshold);
420 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
421 unsigned int sb_index,
422 u16 tc_index,
423 enum devlink_sb_pool_type pool_type,
424 u16 *p_pool_index, u32 *p_threshold);
425 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
426 unsigned int sb_index,
427 u16 tc_index,
428 enum devlink_sb_pool_type pool_type,
429 u16 pool_index, u32 threshold);
Jiri Pirkodf38daf2016-04-14 18:19:14 +0200430 int (*sb_occ_snapshot)(struct devlink *devlink,
431 unsigned int sb_index);
432 int (*sb_occ_max_clear)(struct devlink *devlink,
433 unsigned int sb_index);
434 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
435 unsigned int sb_index, u16 pool_index,
436 u32 *p_cur, u32 *p_max);
437 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
438 unsigned int sb_index,
439 u16 tc_index,
440 enum devlink_sb_pool_type pool_type,
441 u32 *p_cur, u32 *p_max);
Or Gerlitz08f4b592016-07-01 14:51:01 +0300442
443 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
444 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode);
Roi Dayan59bfde02016-11-22 23:09:57 +0200445 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
446 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode);
Roi Dayanf43e9b02016-09-25 13:52:44 +0300447 int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode);
448 int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100449};
450
451static inline void *devlink_priv(struct devlink *devlink)
452{
453 BUG_ON(!devlink);
454 return &devlink->priv;
455}
456
457static inline struct devlink *priv_to_devlink(void *priv)
458{
459 BUG_ON(!priv);
460 return container_of(priv, struct devlink, priv);
461}
462
463struct ib_device;
464
465#if IS_ENABLED(CONFIG_NET_DEVLINK)
466
467struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
468int devlink_register(struct devlink *devlink, struct device *dev);
469void devlink_unregister(struct devlink *devlink);
470void devlink_free(struct devlink *devlink);
471int devlink_port_register(struct devlink *devlink,
472 struct devlink_port *devlink_port,
473 unsigned int port_index);
474void devlink_port_unregister(struct devlink_port *devlink_port);
475void devlink_port_type_eth_set(struct devlink_port *devlink_port,
476 struct net_device *netdev);
477void devlink_port_type_ib_set(struct devlink_port *devlink_port,
478 struct ib_device *ibdev);
479void devlink_port_type_clear(struct devlink_port *devlink_port);
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200480void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200481 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200482 u32 port_number, bool split,
483 u32 split_subport_number);
Jiri Pirko08474c12018-05-18 09:29:02 +0200484int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
485 char *name, size_t len);
Jiri Pirkobf797472016-04-14 18:19:13 +0200486int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
487 u32 size, u16 ingress_pools_count,
488 u16 egress_pools_count, u16 ingress_tc_count,
489 u16 egress_tc_count);
490void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200491int devlink_dpipe_table_register(struct devlink *devlink,
492 const char *table_name,
493 struct devlink_dpipe_table_ops *table_ops,
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200494 void *priv, bool counter_control_extern);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200495void devlink_dpipe_table_unregister(struct devlink *devlink,
496 const char *table_name);
497int devlink_dpipe_headers_register(struct devlink *devlink,
498 struct devlink_dpipe_headers *dpipe_headers);
499void devlink_dpipe_headers_unregister(struct devlink *devlink);
500bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
501 const char *table_name);
502int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
503int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
504 struct devlink_dpipe_entry *entry);
505int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200506void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200507int devlink_dpipe_action_put(struct sk_buff *skb,
508 struct devlink_dpipe_action *action);
509int devlink_dpipe_match_put(struct sk_buff *skb,
510 struct devlink_dpipe_match *match);
Arkadi Sharshevsky11770092017-08-24 08:39:59 +0200511extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
Arkadi Sharshevsky3fb886e2017-08-24 08:40:00 +0200512extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
Arkadi Sharshevsky1797f5b2017-08-31 17:59:12 +0200513extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100514
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100515int devlink_resource_register(struct devlink *devlink,
516 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100517 u64 resource_size,
518 u64 resource_id,
519 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200520 const struct devlink_resource_size_params *size_params);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100521void devlink_resources_unregister(struct devlink *devlink,
522 struct devlink_resource *resource);
523int devlink_resource_size_get(struct devlink *devlink,
524 u64 resource_id,
525 u64 *p_resource_size);
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100526int devlink_dpipe_table_resource_set(struct devlink *devlink,
527 const char *table_name, u64 resource_id,
528 u64 resource_units);
Jiri Pirkofc56be42018-04-05 22:13:21 +0200529void devlink_resource_occ_get_register(struct devlink *devlink,
530 u64 resource_id,
531 devlink_resource_occ_get_t *occ_get,
532 void *occ_get_priv);
533void devlink_resource_occ_get_unregister(struct devlink *devlink,
534 u64 resource_id);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300535int devlink_params_register(struct devlink *devlink,
536 const struct devlink_param *params,
537 size_t params_count);
538void devlink_params_unregister(struct devlink *devlink,
539 const struct devlink_param *params,
540 size_t params_count);
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300541int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
542 union devlink_param_value *init_val);
543int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
544 union devlink_param_value init_val);
Moshe Shemeshea601e12018-07-04 14:30:32 +0300545void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100546
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100547#else
548
549static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
550 size_t priv_size)
551{
552 return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
553}
554
555static inline int devlink_register(struct devlink *devlink, struct device *dev)
556{
557 return 0;
558}
559
560static inline void devlink_unregister(struct devlink *devlink)
561{
562}
563
564static inline void devlink_free(struct devlink *devlink)
565{
566 kfree(devlink);
567}
568
569static inline int devlink_port_register(struct devlink *devlink,
570 struct devlink_port *devlink_port,
571 unsigned int port_index)
572{
573 return 0;
574}
575
576static inline void devlink_port_unregister(struct devlink_port *devlink_port)
577{
578}
579
580static inline void devlink_port_type_eth_set(struct devlink_port *devlink_port,
581 struct net_device *netdev)
582{
583}
584
585static inline void devlink_port_type_ib_set(struct devlink_port *devlink_port,
586 struct ib_device *ibdev)
587{
588}
589
590static inline void devlink_port_type_clear(struct devlink_port *devlink_port)
591{
592}
593
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200594static inline void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200595 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200596 u32 port_number, bool split,
597 u32 split_subport_number)
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100598{
599}
600
Jiri Pirko08474c12018-05-18 09:29:02 +0200601static inline int
602devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
603 char *name, size_t len)
604{
605 return -EOPNOTSUPP;
606}
607
Jiri Pirkobf797472016-04-14 18:19:13 +0200608static inline int devlink_sb_register(struct devlink *devlink,
609 unsigned int sb_index, u32 size,
610 u16 ingress_pools_count,
Jiri Pirkode33efd2016-04-15 09:17:08 +0200611 u16 egress_pools_count,
612 u16 ingress_tc_count,
613 u16 egress_tc_count)
Jiri Pirkobf797472016-04-14 18:19:13 +0200614{
615 return 0;
616}
617
618static inline void devlink_sb_unregister(struct devlink *devlink,
619 unsigned int sb_index)
620{
621}
622
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200623static inline int
624devlink_dpipe_table_register(struct devlink *devlink,
625 const char *table_name,
626 struct devlink_dpipe_table_ops *table_ops,
David S. Miller790c6052017-08-24 18:10:46 -0700627 void *priv, bool counter_control_extern)
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200628{
629 return 0;
630}
631
632static inline void devlink_dpipe_table_unregister(struct devlink *devlink,
633 const char *table_name)
634{
635}
636
637static inline int devlink_dpipe_headers_register(struct devlink *devlink,
638 struct devlink_dpipe_headers *
639 dpipe_headers)
640{
641 return 0;
642}
643
644static inline void devlink_dpipe_headers_unregister(struct devlink *devlink)
645{
646}
647
648static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
649 const char *table_name)
650{
651 return false;
652}
653
654static inline int
655devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx)
656{
657 return 0;
658}
659
660static inline int
661devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
662 struct devlink_dpipe_entry *entry)
663{
664 return 0;
665}
666
667static inline int
668devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx)
669{
670 return 0;
671}
672
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200673static inline void
674devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry)
675{
676}
677
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200678static inline int
679devlink_dpipe_action_put(struct sk_buff *skb,
680 struct devlink_dpipe_action *action)
681{
682 return 0;
683}
684
685static inline int
686devlink_dpipe_match_put(struct sk_buff *skb,
687 struct devlink_dpipe_match *match)
688{
689 return 0;
690}
691
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100692static inline int
693devlink_resource_register(struct devlink *devlink,
694 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100695 u64 resource_size,
696 u64 resource_id,
697 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200698 const struct devlink_resource_size_params *size_params)
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100699{
700 return 0;
701}
702
703static inline void
704devlink_resources_unregister(struct devlink *devlink,
705 struct devlink_resource *resource)
706{
707}
708
709static inline int
710devlink_resource_size_get(struct devlink *devlink, u64 resource_id,
711 u64 *p_resource_size)
712{
713 return -EOPNOTSUPP;
714}
715
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100716static inline int
717devlink_dpipe_table_resource_set(struct devlink *devlink,
718 const char *table_name, u64 resource_id,
719 u64 resource_units)
720{
721 return -EOPNOTSUPP;
722}
723
Jiri Pirkofc56be42018-04-05 22:13:21 +0200724static inline void
725devlink_resource_occ_get_register(struct devlink *devlink,
726 u64 resource_id,
727 devlink_resource_occ_get_t *occ_get,
728 void *occ_get_priv)
729{
730}
731
732static inline void
733devlink_resource_occ_get_unregister(struct devlink *devlink,
734 u64 resource_id)
735{
736}
737
Moshe Shemesheabaef12018-07-04 14:30:28 +0300738static inline int
739devlink_params_register(struct devlink *devlink,
740 const struct devlink_param *params,
741 size_t params_count)
742{
743 return 0;
744}
745
746static inline void
747devlink_params_unregister(struct devlink *devlink,
748 const struct devlink_param *params,
749 size_t params_count)
750{
751
752}
753
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300754static inline int
755devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
756 union devlink_param_value *init_val)
757{
758 return -EOPNOTSUPP;
759}
760
761static inline int
762devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
763 union devlink_param_value init_val)
764{
765 return -EOPNOTSUPP;
766}
767
Moshe Shemeshea601e12018-07-04 14:30:32 +0300768static inline void
769devlink_param_value_changed(struct devlink *devlink, u32 param_id)
770{
771 return -EOPNOTSUPP;
772}
773
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100774#endif
775
776#endif /* _NET_DEVLINK_H_ */