blob: f27d8593687a445184ef2be5cc340cdc59aaa148 [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;
51 struct devlink *devlink;
52 unsigned index;
53 bool registered;
54 enum devlink_port_type type;
55 enum devlink_port_type desired_type;
56 void *type_dev;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020057 struct devlink_port_attrs attrs;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010058};
59
Jiri Pirkobf797472016-04-14 18:19:13 +020060struct devlink_sb_pool_info {
61 enum devlink_sb_pool_type pool_type;
62 u32 size;
63 enum devlink_sb_threshold_type threshold_type;
64};
65
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020066/**
67 * struct devlink_dpipe_field - dpipe field object
68 * @name: field name
69 * @id: index inside the headers field array
70 * @bitwidth: bitwidth
71 * @mapping_type: mapping type
72 */
73struct devlink_dpipe_field {
74 const char *name;
75 unsigned int id;
76 unsigned int bitwidth;
77 enum devlink_dpipe_field_mapping_type mapping_type;
78};
79
80/**
81 * struct devlink_dpipe_header - dpipe header object
82 * @name: header name
83 * @id: index, global/local detrmined by global bit
84 * @fields: fields
85 * @fields_count: number of fields
86 * @global: indicates if header is shared like most protocol header
87 * or driver specific
88 */
89struct devlink_dpipe_header {
90 const char *name;
91 unsigned int id;
92 struct devlink_dpipe_field *fields;
93 unsigned int fields_count;
94 bool global;
95};
96
97/**
98 * struct devlink_dpipe_match - represents match operation
99 * @type: type of match
100 * @header_index: header index (packets can have several headers of same
101 * type like in case of tunnels)
102 * @header: header
103 * @fieled_id: field index
104 */
105struct devlink_dpipe_match {
106 enum devlink_dpipe_match_type type;
107 unsigned int header_index;
108 struct devlink_dpipe_header *header;
109 unsigned int field_id;
110};
111
112/**
113 * struct devlink_dpipe_action - represents action operation
114 * @type: type of action
115 * @header_index: header index (packets can have several headers of same
116 * type like in case of tunnels)
117 * @header: header
118 * @fieled_id: field index
119 */
120struct devlink_dpipe_action {
121 enum devlink_dpipe_action_type type;
122 unsigned int header_index;
123 struct devlink_dpipe_header *header;
124 unsigned int field_id;
125};
126
127/**
128 * struct devlink_dpipe_value - represents value of match/action
129 * @action: action
130 * @match: match
131 * @mapping_value: in case the field has some mapping this value
132 * specified the mapping value
133 * @mapping_valid: specify if mapping value is valid
134 * @value_size: value size
135 * @value: value
136 * @mask: bit mask
137 */
138struct devlink_dpipe_value {
139 union {
140 struct devlink_dpipe_action *action;
141 struct devlink_dpipe_match *match;
142 };
143 unsigned int mapping_value;
144 bool mapping_valid;
145 unsigned int value_size;
146 void *value;
147 void *mask;
148};
149
150/**
151 * struct devlink_dpipe_entry - table entry object
152 * @index: index of the entry in the table
153 * @match_values: match values
154 * @matche_values_count: count of matches tuples
155 * @action_values: actions values
156 * @action_values_count: count of actions values
157 * @counter: value of counter
158 * @counter_valid: Specify if value is valid from hardware
159 */
160struct devlink_dpipe_entry {
161 u64 index;
162 struct devlink_dpipe_value *match_values;
163 unsigned int match_values_count;
164 struct devlink_dpipe_value *action_values;
165 unsigned int action_values_count;
166 u64 counter;
167 bool counter_valid;
168};
169
170/**
171 * struct devlink_dpipe_dump_ctx - context provided to driver in order
172 * to dump
173 * @info: info
174 * @cmd: devlink command
175 * @skb: skb
176 * @nest: top attribute
177 * @hdr: hdr
178 */
179struct devlink_dpipe_dump_ctx {
180 struct genl_info *info;
181 enum devlink_command cmd;
182 struct sk_buff *skb;
183 struct nlattr *nest;
184 void *hdr;
185};
186
187struct devlink_dpipe_table_ops;
188
189/**
190 * struct devlink_dpipe_table - table object
191 * @priv: private
192 * @name: table name
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200193 * @counters_enabled: indicates if counters are active
194 * @counter_control_extern: indicates if counter control is in dpipe or
195 * external tool
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100196 * @resource_valid: Indicate that the resource id is valid
197 * @resource_id: relative resource this table is related to
198 * @resource_units: number of resource's unit consumed per table's entry
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200199 * @table_ops: table operations
200 * @rcu: rcu
201 */
202struct devlink_dpipe_table {
203 void *priv;
204 struct list_head list;
205 const char *name;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200206 bool counters_enabled;
207 bool counter_control_extern;
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100208 bool resource_valid;
209 u64 resource_id;
210 u64 resource_units;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200211 struct devlink_dpipe_table_ops *table_ops;
212 struct rcu_head rcu;
213};
214
215/**
216 * struct devlink_dpipe_table_ops - dpipe_table ops
217 * @actions_dump - dumps all tables actions
218 * @matches_dump - dumps all tables matches
219 * @entries_dump - dumps all active entries in the table
220 * @counters_set_update - when changing the counter status hardware sync
221 * maybe needed to allocate/free counter related
222 * resources
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200223 * @size_get - get size
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200224 */
225struct devlink_dpipe_table_ops {
226 int (*actions_dump)(void *priv, struct sk_buff *skb);
227 int (*matches_dump)(void *priv, struct sk_buff *skb);
228 int (*entries_dump)(void *priv, bool counters_enabled,
229 struct devlink_dpipe_dump_ctx *dump_ctx);
230 int (*counters_set_update)(void *priv, bool enable);
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200231 u64 (*size_get)(void *priv);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200232};
233
234/**
235 * struct devlink_dpipe_headers - dpipe headers
236 * @headers - header array can be shared (global bit) or driver specific
237 * @headers_count - count of headers
238 */
239struct devlink_dpipe_headers {
240 struct devlink_dpipe_header **headers;
241 unsigned int headers_count;
242};
243
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100244/**
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100245 * struct devlink_resource_size_params - resource's size parameters
246 * @size_min: minimum size which can be set
247 * @size_max: maximum size which can be set
248 * @size_granularity: size granularity
249 * @size_unit: resource's basic unit
250 */
251struct devlink_resource_size_params {
252 u64 size_min;
253 u64 size_max;
254 u64 size_granularity;
255 enum devlink_resource_unit unit;
256};
257
Jiri Pirko77d27092018-02-28 13:12:09 +0100258static inline void
259devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
260 u64 size_min, u64 size_max,
261 u64 size_granularity,
262 enum devlink_resource_unit unit)
263{
264 size_params->size_min = size_min;
265 size_params->size_max = size_max;
266 size_params->size_granularity = size_granularity;
267 size_params->unit = unit;
268}
269
Jiri Pirkofc56be42018-04-05 22:13:21 +0200270typedef u64 devlink_resource_occ_get_t(void *priv);
271
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100272/**
273 * struct devlink_resource - devlink resource
274 * @name: name of the resource
275 * @id: id, per devlink instance
276 * @size: size of the resource
277 * @size_new: updated size of the resource, reload is needed
278 * @size_valid: valid in case the total size of the resource is valid
279 * including its children
280 * @parent: parent resource
281 * @size_params: size parameters
282 * @list: parent list
283 * @resource_list: list of child resources
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100284 */
285struct devlink_resource {
286 const char *name;
287 u64 id;
288 u64 size;
289 u64 size_new;
290 bool size_valid;
291 struct devlink_resource *parent;
Jiri Pirko77d27092018-02-28 13:12:09 +0100292 struct devlink_resource_size_params size_params;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100293 struct list_head list;
294 struct list_head resource_list;
Jiri Pirkofc56be42018-04-05 22:13:21 +0200295 devlink_resource_occ_get_t *occ_get;
296 void *occ_get_priv;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100297};
298
299#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
300
Moshe Shemesheabaef12018-07-04 14:30:28 +0300301#define DEVLINK_PARAM_MAX_STRING_VALUE 32
302enum devlink_param_type {
303 DEVLINK_PARAM_TYPE_U8,
304 DEVLINK_PARAM_TYPE_U16,
305 DEVLINK_PARAM_TYPE_U32,
306 DEVLINK_PARAM_TYPE_STRING,
307 DEVLINK_PARAM_TYPE_BOOL,
308};
309
310union devlink_param_value {
311 u8 vu8;
312 u16 vu16;
313 u32 vu32;
314 const char *vstr;
315 bool vbool;
316};
317
318struct devlink_param_gset_ctx {
319 union devlink_param_value val;
320 enum devlink_param_cmode cmode;
321};
322
323/**
324 * struct devlink_param - devlink configuration parameter data
325 * @name: name of the parameter
326 * @generic: indicates if the parameter is generic or driver specific
327 * @type: parameter type
328 * @supported_cmodes: bitmap of supported configuration modes
329 * @get: get parameter value, used for runtime and permanent
330 * configuration modes
331 * @set: set parameter value, used for runtime and permanent
332 * configuration modes
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300333 * @validate: validate input value is applicable (within value range, etc.)
Moshe Shemesheabaef12018-07-04 14:30:28 +0300334 *
335 * This struct should be used by the driver to fill the data for
336 * a parameter it registers.
337 */
338struct devlink_param {
339 u32 id;
340 const char *name;
341 bool generic;
342 enum devlink_param_type type;
343 unsigned long supported_cmodes;
344 int (*get)(struct devlink *devlink, u32 id,
345 struct devlink_param_gset_ctx *ctx);
346 int (*set)(struct devlink *devlink, u32 id,
347 struct devlink_param_gset_ctx *ctx);
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300348 int (*validate)(struct devlink *devlink, u32 id,
349 union devlink_param_value val,
350 struct netlink_ext_ack *extack);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300351};
352
353struct devlink_param_item {
354 struct list_head list;
355 const struct devlink_param *param;
356 union devlink_param_value driverinit_value;
357 bool driverinit_value_valid;
358};
359
360enum devlink_param_generic_id {
Moshe Shemesh036467c2018-07-04 14:30:33 +0300361 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
362 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300363 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
Moshe Shemesheabaef12018-07-04 14:30:28 +0300364
365 /* add new param generic ids above here*/
366 __DEVLINK_PARAM_GENERIC_ID_MAX,
367 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
368};
369
Moshe Shemesh036467c2018-07-04 14:30:33 +0300370#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
371#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
372
373#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
374#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
375
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300376#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
377#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
378
Moshe Shemesh036467c2018-07-04 14:30:33 +0300379#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
380{ \
381 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
382 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
383 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
384 .generic = true, \
385 .supported_cmodes = _cmodes, \
386 .get = _get, \
387 .set = _set, \
388 .validate = _validate, \
389}
390
391#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
392{ \
393 .id = _id, \
394 .name = _name, \
395 .type = _type, \
396 .supported_cmodes = _cmodes, \
397 .get = _get, \
398 .set = _set, \
399 .validate = _validate, \
400}
401
Alex Veskerb16ebe92018-07-12 15:13:08 +0300402struct devlink_region;
403
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100404struct devlink_ops {
David Ahernac0fc8a2018-06-05 08:14:09 -0700405 int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100406 int (*port_type_set)(struct devlink_port *devlink_port,
407 enum devlink_port_type port_type);
408 int (*port_split)(struct devlink *devlink, unsigned int port_index,
David Ahernac0fc8a2018-06-05 08:14:09 -0700409 unsigned int count, struct netlink_ext_ack *extack);
410 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
411 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +0200412 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
413 u16 pool_index,
414 struct devlink_sb_pool_info *pool_info);
415 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
416 u16 pool_index, u32 size,
417 enum devlink_sb_threshold_type threshold_type);
418 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
419 unsigned int sb_index, u16 pool_index,
420 u32 *p_threshold);
421 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
422 unsigned int sb_index, u16 pool_index,
423 u32 threshold);
424 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
425 unsigned int sb_index,
426 u16 tc_index,
427 enum devlink_sb_pool_type pool_type,
428 u16 *p_pool_index, u32 *p_threshold);
429 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
430 unsigned int sb_index,
431 u16 tc_index,
432 enum devlink_sb_pool_type pool_type,
433 u16 pool_index, u32 threshold);
Jiri Pirkodf38daf2016-04-14 18:19:14 +0200434 int (*sb_occ_snapshot)(struct devlink *devlink,
435 unsigned int sb_index);
436 int (*sb_occ_max_clear)(struct devlink *devlink,
437 unsigned int sb_index);
438 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
439 unsigned int sb_index, u16 pool_index,
440 u32 *p_cur, u32 *p_max);
441 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
442 unsigned int sb_index,
443 u16 tc_index,
444 enum devlink_sb_pool_type pool_type,
445 u32 *p_cur, u32 *p_max);
Or Gerlitz08f4b592016-07-01 14:51:01 +0300446
447 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
448 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode);
Roi Dayan59bfde02016-11-22 23:09:57 +0200449 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
450 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode);
Roi Dayanf43e9b02016-09-25 13:52:44 +0300451 int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode);
452 int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100453};
454
455static inline void *devlink_priv(struct devlink *devlink)
456{
457 BUG_ON(!devlink);
458 return &devlink->priv;
459}
460
461static inline struct devlink *priv_to_devlink(void *priv)
462{
463 BUG_ON(!priv);
464 return container_of(priv, struct devlink, priv);
465}
466
467struct ib_device;
468
469#if IS_ENABLED(CONFIG_NET_DEVLINK)
470
471struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
472int devlink_register(struct devlink *devlink, struct device *dev);
473void devlink_unregister(struct devlink *devlink);
474void devlink_free(struct devlink *devlink);
475int devlink_port_register(struct devlink *devlink,
476 struct devlink_port *devlink_port,
477 unsigned int port_index);
478void devlink_port_unregister(struct devlink_port *devlink_port);
479void devlink_port_type_eth_set(struct devlink_port *devlink_port,
480 struct net_device *netdev);
481void devlink_port_type_ib_set(struct devlink_port *devlink_port,
482 struct ib_device *ibdev);
483void devlink_port_type_clear(struct devlink_port *devlink_port);
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200484void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200485 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200486 u32 port_number, bool split,
487 u32 split_subport_number);
Jiri Pirko08474c12018-05-18 09:29:02 +0200488int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
489 char *name, size_t len);
Jiri Pirkobf797472016-04-14 18:19:13 +0200490int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
491 u32 size, u16 ingress_pools_count,
492 u16 egress_pools_count, u16 ingress_tc_count,
493 u16 egress_tc_count);
494void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200495int devlink_dpipe_table_register(struct devlink *devlink,
496 const char *table_name,
497 struct devlink_dpipe_table_ops *table_ops,
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200498 void *priv, bool counter_control_extern);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200499void devlink_dpipe_table_unregister(struct devlink *devlink,
500 const char *table_name);
501int devlink_dpipe_headers_register(struct devlink *devlink,
502 struct devlink_dpipe_headers *dpipe_headers);
503void devlink_dpipe_headers_unregister(struct devlink *devlink);
504bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
505 const char *table_name);
506int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
507int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
508 struct devlink_dpipe_entry *entry);
509int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200510void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200511int devlink_dpipe_action_put(struct sk_buff *skb,
512 struct devlink_dpipe_action *action);
513int devlink_dpipe_match_put(struct sk_buff *skb,
514 struct devlink_dpipe_match *match);
Arkadi Sharshevsky11770092017-08-24 08:39:59 +0200515extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
Arkadi Sharshevsky3fb886e2017-08-24 08:40:00 +0200516extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
Arkadi Sharshevsky1797f5b2017-08-31 17:59:12 +0200517extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100518
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100519int devlink_resource_register(struct devlink *devlink,
520 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100521 u64 resource_size,
522 u64 resource_id,
523 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200524 const struct devlink_resource_size_params *size_params);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100525void devlink_resources_unregister(struct devlink *devlink,
526 struct devlink_resource *resource);
527int devlink_resource_size_get(struct devlink *devlink,
528 u64 resource_id,
529 u64 *p_resource_size);
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100530int devlink_dpipe_table_resource_set(struct devlink *devlink,
531 const char *table_name, u64 resource_id,
532 u64 resource_units);
Jiri Pirkofc56be42018-04-05 22:13:21 +0200533void devlink_resource_occ_get_register(struct devlink *devlink,
534 u64 resource_id,
535 devlink_resource_occ_get_t *occ_get,
536 void *occ_get_priv);
537void devlink_resource_occ_get_unregister(struct devlink *devlink,
538 u64 resource_id);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300539int devlink_params_register(struct devlink *devlink,
540 const struct devlink_param *params,
541 size_t params_count);
542void devlink_params_unregister(struct devlink *devlink,
543 const struct devlink_param *params,
544 size_t params_count);
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300545int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
546 union devlink_param_value *init_val);
547int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
548 union devlink_param_value init_val);
Moshe Shemeshea601e12018-07-04 14:30:32 +0300549void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
Alex Veskerb16ebe92018-07-12 15:13:08 +0300550struct devlink_region *devlink_region_create(struct devlink *devlink,
551 const char *region_name,
552 u32 region_max_snapshots,
553 u64 region_size);
554void devlink_region_destroy(struct devlink_region *region);
Alex Veskerccadfa42018-07-12 15:13:09 +0300555u32 devlink_region_shapshot_id_get(struct devlink *devlink);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100556
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100557#else
558
559static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
560 size_t priv_size)
561{
562 return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
563}
564
565static inline int devlink_register(struct devlink *devlink, struct device *dev)
566{
567 return 0;
568}
569
570static inline void devlink_unregister(struct devlink *devlink)
571{
572}
573
574static inline void devlink_free(struct devlink *devlink)
575{
576 kfree(devlink);
577}
578
579static inline int devlink_port_register(struct devlink *devlink,
580 struct devlink_port *devlink_port,
581 unsigned int port_index)
582{
583 return 0;
584}
585
586static inline void devlink_port_unregister(struct devlink_port *devlink_port)
587{
588}
589
590static inline void devlink_port_type_eth_set(struct devlink_port *devlink_port,
591 struct net_device *netdev)
592{
593}
594
595static inline void devlink_port_type_ib_set(struct devlink_port *devlink_port,
596 struct ib_device *ibdev)
597{
598}
599
600static inline void devlink_port_type_clear(struct devlink_port *devlink_port)
601{
602}
603
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200604static inline void devlink_port_attrs_set(struct devlink_port *devlink_port,
Jiri Pirko5ec13802018-05-18 09:29:01 +0200605 enum devlink_port_flavour flavour,
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200606 u32 port_number, bool split,
607 u32 split_subport_number)
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100608{
609}
610
Jiri Pirko08474c12018-05-18 09:29:02 +0200611static inline int
612devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
613 char *name, size_t len)
614{
615 return -EOPNOTSUPP;
616}
617
Jiri Pirkobf797472016-04-14 18:19:13 +0200618static inline int devlink_sb_register(struct devlink *devlink,
619 unsigned int sb_index, u32 size,
620 u16 ingress_pools_count,
Jiri Pirkode33efd2016-04-15 09:17:08 +0200621 u16 egress_pools_count,
622 u16 ingress_tc_count,
623 u16 egress_tc_count)
Jiri Pirkobf797472016-04-14 18:19:13 +0200624{
625 return 0;
626}
627
628static inline void devlink_sb_unregister(struct devlink *devlink,
629 unsigned int sb_index)
630{
631}
632
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200633static inline int
634devlink_dpipe_table_register(struct devlink *devlink,
635 const char *table_name,
636 struct devlink_dpipe_table_ops *table_ops,
David S. Miller790c6052017-08-24 18:10:46 -0700637 void *priv, bool counter_control_extern)
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200638{
639 return 0;
640}
641
642static inline void devlink_dpipe_table_unregister(struct devlink *devlink,
643 const char *table_name)
644{
645}
646
647static inline int devlink_dpipe_headers_register(struct devlink *devlink,
648 struct devlink_dpipe_headers *
649 dpipe_headers)
650{
651 return 0;
652}
653
654static inline void devlink_dpipe_headers_unregister(struct devlink *devlink)
655{
656}
657
658static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
659 const char *table_name)
660{
661 return false;
662}
663
664static inline int
665devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx)
666{
667 return 0;
668}
669
670static inline int
671devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
672 struct devlink_dpipe_entry *entry)
673{
674 return 0;
675}
676
677static inline int
678devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx)
679{
680 return 0;
681}
682
Arkadi Sharshevsky35807322017-08-24 08:40:03 +0200683static inline void
684devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry)
685{
686}
687
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200688static inline int
689devlink_dpipe_action_put(struct sk_buff *skb,
690 struct devlink_dpipe_action *action)
691{
692 return 0;
693}
694
695static inline int
696devlink_dpipe_match_put(struct sk_buff *skb,
697 struct devlink_dpipe_match *match)
698{
699 return 0;
700}
701
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100702static inline int
703devlink_resource_register(struct devlink *devlink,
704 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100705 u64 resource_size,
706 u64 resource_id,
707 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +0200708 const struct devlink_resource_size_params *size_params)
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100709{
710 return 0;
711}
712
713static inline void
714devlink_resources_unregister(struct devlink *devlink,
715 struct devlink_resource *resource)
716{
717}
718
719static inline int
720devlink_resource_size_get(struct devlink *devlink, u64 resource_id,
721 u64 *p_resource_size)
722{
723 return -EOPNOTSUPP;
724}
725
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100726static inline int
727devlink_dpipe_table_resource_set(struct devlink *devlink,
728 const char *table_name, u64 resource_id,
729 u64 resource_units)
730{
731 return -EOPNOTSUPP;
732}
733
Jiri Pirkofc56be42018-04-05 22:13:21 +0200734static inline void
735devlink_resource_occ_get_register(struct devlink *devlink,
736 u64 resource_id,
737 devlink_resource_occ_get_t *occ_get,
738 void *occ_get_priv)
739{
740}
741
742static inline void
743devlink_resource_occ_get_unregister(struct devlink *devlink,
744 u64 resource_id)
745{
746}
747
Moshe Shemesheabaef12018-07-04 14:30:28 +0300748static inline int
749devlink_params_register(struct devlink *devlink,
750 const struct devlink_param *params,
751 size_t params_count)
752{
753 return 0;
754}
755
756static inline void
757devlink_params_unregister(struct devlink *devlink,
758 const struct devlink_param *params,
759 size_t params_count)
760{
761
762}
763
Moshe Shemeshec01aeb2018-07-04 14:30:31 +0300764static inline int
765devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
766 union devlink_param_value *init_val)
767{
768 return -EOPNOTSUPP;
769}
770
771static inline int
772devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
773 union devlink_param_value init_val)
774{
775 return -EOPNOTSUPP;
776}
777
Moshe Shemeshea601e12018-07-04 14:30:32 +0300778static inline void
779devlink_param_value_changed(struct devlink *devlink, u32 param_id)
780{
Moshe Shemeshea601e12018-07-04 14:30:32 +0300781}
782
Alex Veskerb16ebe92018-07-12 15:13:08 +0300783static inline struct devlink_region *
784devlink_region_create(struct devlink *devlink,
785 const char *region_name,
786 u32 region_max_snapshots,
787 u64 region_size)
788{
789 return NULL;
790}
791
792static inline void
793devlink_region_destroy(struct devlink_region *region)
794{
795}
796
Alex Veskerccadfa42018-07-12 15:13:09 +0300797static inline u32
798devlink_region_shapshot_id_get(struct devlink *devlink)
799{
800 return 0;
801}
802
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100803#endif
804
805#endif /* _NET_DEVLINK_H_ */