xref: /openbmc/linux/include/net/devlink.h (revision 9f7d35d9)
1 /*
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 
22 struct devlink_ops;
23 
24 struct devlink {
25 	struct list_head list;
26 	struct list_head port_list;
27 	struct list_head sb_list;
28 	struct list_head dpipe_table_list;
29 	struct list_head resource_list;
30 	struct list_head param_list;
31 	struct list_head region_list;
32 	u32 snapshot_id;
33 	struct devlink_dpipe_headers *dpipe_headers;
34 	const struct devlink_ops *ops;
35 	struct device *dev;
36 	possible_net_t _net;
37 	struct mutex lock;
38 	char priv[0] __aligned(NETDEV_ALIGN);
39 };
40 
41 struct devlink_port_attrs {
42 	bool set;
43 	enum devlink_port_flavour flavour;
44 	u32 port_number; /* same value as "split group" */
45 	bool split;
46 	u32 split_subport_number;
47 };
48 
49 struct 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;
57 	struct devlink_port_attrs attrs;
58 };
59 
60 struct 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 
66 /**
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  */
73 struct 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  */
89 struct 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  */
105 struct 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  */
120 struct 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  */
138 struct 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  */
160 struct 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  */
179 struct 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 
187 struct devlink_dpipe_table_ops;
188 
189 /**
190  * struct devlink_dpipe_table - table object
191  * @priv: private
192  * @name: table name
193  * @counters_enabled: indicates if counters are active
194  * @counter_control_extern: indicates if counter control is in dpipe or
195  *			    external tool
196  * @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
199  * @table_ops: table operations
200  * @rcu: rcu
201  */
202 struct devlink_dpipe_table {
203 	void *priv;
204 	struct list_head list;
205 	const char *name;
206 	bool counters_enabled;
207 	bool counter_control_extern;
208 	bool resource_valid;
209 	u64 resource_id;
210 	u64 resource_units;
211 	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
223  * @size_get - get size
224  */
225 struct 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);
231 	u64 (*size_get)(void *priv);
232 };
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  */
239 struct devlink_dpipe_headers {
240 	struct devlink_dpipe_header **headers;
241 	unsigned int headers_count;
242 };
243 
244 /**
245  * 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  */
251 struct devlink_resource_size_params {
252 	u64 size_min;
253 	u64 size_max;
254 	u64 size_granularity;
255 	enum devlink_resource_unit unit;
256 };
257 
258 static inline void
259 devlink_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 
270 typedef u64 devlink_resource_occ_get_t(void *priv);
271 
272 /**
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
284  */
285 struct 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;
292 	struct devlink_resource_size_params size_params;
293 	struct list_head list;
294 	struct list_head resource_list;
295 	devlink_resource_occ_get_t *occ_get;
296 	void *occ_get_priv;
297 };
298 
299 #define DEVLINK_RESOURCE_ID_PARENT_TOP 0
300 
301 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32
302 enum 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 
310 union devlink_param_value {
311 	u8 vu8;
312 	u16 vu16;
313 	u32 vu32;
314 	char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
315 	bool vbool;
316 };
317 
318 struct 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
333  * @validate: validate input value is applicable (within value range, etc.)
334  *
335  * This struct should be used by the driver to fill the data for
336  * a parameter it registers.
337  */
338 struct 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);
348 	int (*validate)(struct devlink *devlink, u32 id,
349 			union devlink_param_value val,
350 			struct netlink_ext_ack *extack);
351 };
352 
353 struct 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 
360 enum devlink_param_generic_id {
361 	DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
362 	DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
363 	DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
364 	DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
365 	DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
366 	DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
367 	DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
368 	DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
369 
370 	/* add new param generic ids above here*/
371 	__DEVLINK_PARAM_GENERIC_ID_MAX,
372 	DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
373 };
374 
375 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
376 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
377 
378 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
379 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
380 
381 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
382 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
383 
384 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
385 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
386 
387 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
388 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
389 
390 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
391 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
392 
393 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
394 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
395 
396 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
397 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
398 
399 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate)	\
400 {									\
401 	.id = DEVLINK_PARAM_GENERIC_ID_##_id,				\
402 	.name = DEVLINK_PARAM_GENERIC_##_id##_NAME,			\
403 	.type = DEVLINK_PARAM_GENERIC_##_id##_TYPE,			\
404 	.generic = true,						\
405 	.supported_cmodes = _cmodes,					\
406 	.get = _get,							\
407 	.set = _set,							\
408 	.validate = _validate,						\
409 }
410 
411 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate)	\
412 {									\
413 	.id = _id,							\
414 	.name = _name,							\
415 	.type = _type,							\
416 	.supported_cmodes = _cmodes,					\
417 	.get = _get,							\
418 	.set = _set,							\
419 	.validate = _validate,						\
420 }
421 
422 struct devlink_region;
423 
424 typedef void devlink_snapshot_data_dest_t(const void *data);
425 
426 struct devlink_ops {
427 	int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
428 	int (*port_type_set)(struct devlink_port *devlink_port,
429 			     enum devlink_port_type port_type);
430 	int (*port_split)(struct devlink *devlink, unsigned int port_index,
431 			  unsigned int count, struct netlink_ext_ack *extack);
432 	int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
433 			    struct netlink_ext_ack *extack);
434 	int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
435 			   u16 pool_index,
436 			   struct devlink_sb_pool_info *pool_info);
437 	int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
438 			   u16 pool_index, u32 size,
439 			   enum devlink_sb_threshold_type threshold_type);
440 	int (*sb_port_pool_get)(struct devlink_port *devlink_port,
441 				unsigned int sb_index, u16 pool_index,
442 				u32 *p_threshold);
443 	int (*sb_port_pool_set)(struct devlink_port *devlink_port,
444 				unsigned int sb_index, u16 pool_index,
445 				u32 threshold);
446 	int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
447 				   unsigned int sb_index,
448 				   u16 tc_index,
449 				   enum devlink_sb_pool_type pool_type,
450 				   u16 *p_pool_index, u32 *p_threshold);
451 	int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
452 				   unsigned int sb_index,
453 				   u16 tc_index,
454 				   enum devlink_sb_pool_type pool_type,
455 				   u16 pool_index, u32 threshold);
456 	int (*sb_occ_snapshot)(struct devlink *devlink,
457 			       unsigned int sb_index);
458 	int (*sb_occ_max_clear)(struct devlink *devlink,
459 				unsigned int sb_index);
460 	int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
461 				    unsigned int sb_index, u16 pool_index,
462 				    u32 *p_cur, u32 *p_max);
463 	int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
464 				       unsigned int sb_index,
465 				       u16 tc_index,
466 				       enum devlink_sb_pool_type pool_type,
467 				       u32 *p_cur, u32 *p_max);
468 
469 	int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
470 	int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
471 				struct netlink_ext_ack *extack);
472 	int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
473 	int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
474 				       struct netlink_ext_ack *extack);
475 	int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode);
476 	int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode,
477 				      struct netlink_ext_ack *extack);
478 };
479 
480 static inline void *devlink_priv(struct devlink *devlink)
481 {
482 	BUG_ON(!devlink);
483 	return &devlink->priv;
484 }
485 
486 static inline struct devlink *priv_to_devlink(void *priv)
487 {
488 	BUG_ON(!priv);
489 	return container_of(priv, struct devlink, priv);
490 }
491 
492 struct ib_device;
493 
494 #if IS_ENABLED(CONFIG_NET_DEVLINK)
495 
496 struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
497 int devlink_register(struct devlink *devlink, struct device *dev);
498 void devlink_unregister(struct devlink *devlink);
499 void devlink_free(struct devlink *devlink);
500 int devlink_port_register(struct devlink *devlink,
501 			  struct devlink_port *devlink_port,
502 			  unsigned int port_index);
503 void devlink_port_unregister(struct devlink_port *devlink_port);
504 void devlink_port_type_eth_set(struct devlink_port *devlink_port,
505 			       struct net_device *netdev);
506 void devlink_port_type_ib_set(struct devlink_port *devlink_port,
507 			      struct ib_device *ibdev);
508 void devlink_port_type_clear(struct devlink_port *devlink_port);
509 void devlink_port_attrs_set(struct devlink_port *devlink_port,
510 			    enum devlink_port_flavour flavour,
511 			    u32 port_number, bool split,
512 			    u32 split_subport_number);
513 int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
514 				    char *name, size_t len);
515 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
516 			u32 size, u16 ingress_pools_count,
517 			u16 egress_pools_count, u16 ingress_tc_count,
518 			u16 egress_tc_count);
519 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
520 int devlink_dpipe_table_register(struct devlink *devlink,
521 				 const char *table_name,
522 				 struct devlink_dpipe_table_ops *table_ops,
523 				 void *priv, bool counter_control_extern);
524 void devlink_dpipe_table_unregister(struct devlink *devlink,
525 				    const char *table_name);
526 int devlink_dpipe_headers_register(struct devlink *devlink,
527 				   struct devlink_dpipe_headers *dpipe_headers);
528 void devlink_dpipe_headers_unregister(struct devlink *devlink);
529 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
530 					 const char *table_name);
531 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
532 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
533 				   struct devlink_dpipe_entry *entry);
534 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
535 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
536 int devlink_dpipe_action_put(struct sk_buff *skb,
537 			     struct devlink_dpipe_action *action);
538 int devlink_dpipe_match_put(struct sk_buff *skb,
539 			    struct devlink_dpipe_match *match);
540 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
541 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
542 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
543 
544 int devlink_resource_register(struct devlink *devlink,
545 			      const char *resource_name,
546 			      u64 resource_size,
547 			      u64 resource_id,
548 			      u64 parent_resource_id,
549 			      const struct devlink_resource_size_params *size_params);
550 void devlink_resources_unregister(struct devlink *devlink,
551 				  struct devlink_resource *resource);
552 int devlink_resource_size_get(struct devlink *devlink,
553 			      u64 resource_id,
554 			      u64 *p_resource_size);
555 int devlink_dpipe_table_resource_set(struct devlink *devlink,
556 				     const char *table_name, u64 resource_id,
557 				     u64 resource_units);
558 void devlink_resource_occ_get_register(struct devlink *devlink,
559 				       u64 resource_id,
560 				       devlink_resource_occ_get_t *occ_get,
561 				       void *occ_get_priv);
562 void devlink_resource_occ_get_unregister(struct devlink *devlink,
563 					 u64 resource_id);
564 int devlink_params_register(struct devlink *devlink,
565 			    const struct devlink_param *params,
566 			    size_t params_count);
567 void devlink_params_unregister(struct devlink *devlink,
568 			       const struct devlink_param *params,
569 			       size_t params_count);
570 int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
571 				       union devlink_param_value *init_val);
572 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
573 				       union devlink_param_value init_val);
574 void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
575 void devlink_param_value_str_fill(union devlink_param_value *dst_val,
576 				  const char *src);
577 struct devlink_region *devlink_region_create(struct devlink *devlink,
578 					     const char *region_name,
579 					     u32 region_max_snapshots,
580 					     u64 region_size);
581 void devlink_region_destroy(struct devlink_region *region);
582 u32 devlink_region_shapshot_id_get(struct devlink *devlink);
583 int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
584 				   u8 *data, u32 snapshot_id,
585 				   devlink_snapshot_data_dest_t *data_destructor);
586 
587 #else
588 
589 static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
590 					    size_t priv_size)
591 {
592 	return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
593 }
594 
595 static inline int devlink_register(struct devlink *devlink, struct device *dev)
596 {
597 	return 0;
598 }
599 
600 static inline void devlink_unregister(struct devlink *devlink)
601 {
602 }
603 
604 static inline void devlink_free(struct devlink *devlink)
605 {
606 	kfree(devlink);
607 }
608 
609 static inline int devlink_port_register(struct devlink *devlink,
610 					struct devlink_port *devlink_port,
611 					unsigned int port_index)
612 {
613 	return 0;
614 }
615 
616 static inline void devlink_port_unregister(struct devlink_port *devlink_port)
617 {
618 }
619 
620 static inline void devlink_port_type_eth_set(struct devlink_port *devlink_port,
621 					     struct net_device *netdev)
622 {
623 }
624 
625 static inline void devlink_port_type_ib_set(struct devlink_port *devlink_port,
626 					    struct ib_device *ibdev)
627 {
628 }
629 
630 static inline void devlink_port_type_clear(struct devlink_port *devlink_port)
631 {
632 }
633 
634 static inline void devlink_port_attrs_set(struct devlink_port *devlink_port,
635 					  enum devlink_port_flavour flavour,
636 					  u32 port_number, bool split,
637 					  u32 split_subport_number)
638 {
639 }
640 
641 static inline int
642 devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
643 				char *name, size_t len)
644 {
645 	return -EOPNOTSUPP;
646 }
647 
648 static inline int devlink_sb_register(struct devlink *devlink,
649 				      unsigned int sb_index, u32 size,
650 				      u16 ingress_pools_count,
651 				      u16 egress_pools_count,
652 				      u16 ingress_tc_count,
653 				      u16 egress_tc_count)
654 {
655 	return 0;
656 }
657 
658 static inline void devlink_sb_unregister(struct devlink *devlink,
659 					 unsigned int sb_index)
660 {
661 }
662 
663 static inline int
664 devlink_dpipe_table_register(struct devlink *devlink,
665 			     const char *table_name,
666 			     struct devlink_dpipe_table_ops *table_ops,
667 			     void *priv, bool counter_control_extern)
668 {
669 	return 0;
670 }
671 
672 static inline void devlink_dpipe_table_unregister(struct devlink *devlink,
673 						  const char *table_name)
674 {
675 }
676 
677 static inline int devlink_dpipe_headers_register(struct devlink *devlink,
678 						 struct devlink_dpipe_headers *
679 						 dpipe_headers)
680 {
681 	return 0;
682 }
683 
684 static inline void devlink_dpipe_headers_unregister(struct devlink *devlink)
685 {
686 }
687 
688 static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
689 						       const char *table_name)
690 {
691 	return false;
692 }
693 
694 static inline int
695 devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx)
696 {
697 	return 0;
698 }
699 
700 static inline int
701 devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
702 			       struct devlink_dpipe_entry *entry)
703 {
704 	return 0;
705 }
706 
707 static inline int
708 devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx)
709 {
710 	return 0;
711 }
712 
713 static inline void
714 devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry)
715 {
716 }
717 
718 static inline int
719 devlink_dpipe_action_put(struct sk_buff *skb,
720 			 struct devlink_dpipe_action *action)
721 {
722 	return 0;
723 }
724 
725 static inline int
726 devlink_dpipe_match_put(struct sk_buff *skb,
727 			struct devlink_dpipe_match *match)
728 {
729 	return 0;
730 }
731 
732 static inline int
733 devlink_resource_register(struct devlink *devlink,
734 			  const char *resource_name,
735 			  u64 resource_size,
736 			  u64 resource_id,
737 			  u64 parent_resource_id,
738 			  const struct devlink_resource_size_params *size_params)
739 {
740 	return 0;
741 }
742 
743 static inline void
744 devlink_resources_unregister(struct devlink *devlink,
745 			     struct devlink_resource *resource)
746 {
747 }
748 
749 static inline int
750 devlink_resource_size_get(struct devlink *devlink, u64 resource_id,
751 			  u64 *p_resource_size)
752 {
753 	return -EOPNOTSUPP;
754 }
755 
756 static inline int
757 devlink_dpipe_table_resource_set(struct devlink *devlink,
758 				 const char *table_name, u64 resource_id,
759 				 u64 resource_units)
760 {
761 	return -EOPNOTSUPP;
762 }
763 
764 static inline void
765 devlink_resource_occ_get_register(struct devlink *devlink,
766 				  u64 resource_id,
767 				  devlink_resource_occ_get_t *occ_get,
768 				  void *occ_get_priv)
769 {
770 }
771 
772 static inline void
773 devlink_resource_occ_get_unregister(struct devlink *devlink,
774 				    u64 resource_id)
775 {
776 }
777 
778 static inline int
779 devlink_params_register(struct devlink *devlink,
780 			const struct devlink_param *params,
781 			size_t params_count)
782 {
783 	return 0;
784 }
785 
786 static inline void
787 devlink_params_unregister(struct devlink *devlink,
788 			  const struct devlink_param *params,
789 			  size_t params_count)
790 {
791 
792 }
793 
794 static inline int
795 devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
796 				   union devlink_param_value *init_val)
797 {
798 	return -EOPNOTSUPP;
799 }
800 
801 static inline int
802 devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
803 				   union devlink_param_value init_val)
804 {
805 	return -EOPNOTSUPP;
806 }
807 
808 static inline void
809 devlink_param_value_changed(struct devlink *devlink, u32 param_id)
810 {
811 }
812 
813 static inline void
814 devlink_param_value_str_fill(union devlink_param_value *dst_val,
815 			     const char *src)
816 {
817 }
818 
819 static inline struct devlink_region *
820 devlink_region_create(struct devlink *devlink,
821 		      const char *region_name,
822 		      u32 region_max_snapshots,
823 		      u64 region_size)
824 {
825 	return NULL;
826 }
827 
828 static inline void
829 devlink_region_destroy(struct devlink_region *region)
830 {
831 }
832 
833 static inline u32
834 devlink_region_shapshot_id_get(struct devlink *devlink)
835 {
836 	return 0;
837 }
838 
839 static inline int
840 devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
841 			       u8 *data, u32 snapshot_id,
842 			       devlink_snapshot_data_dest_t *data_destructor)
843 {
844 	return 0;
845 }
846 
847 #endif
848 
849 #endif /* _NET_DEVLINK_H_ */
850