xref: /openbmc/linux/include/net/devlink.h (revision 0c874100)
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 
369 	/* add new param generic ids above here*/
370 	__DEVLINK_PARAM_GENERIC_ID_MAX,
371 	DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
372 };
373 
374 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
375 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
376 
377 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
378 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
379 
380 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
381 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
382 
383 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
384 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
385 
386 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
387 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
388 
389 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
390 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
391 
392 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
393 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
394 
395 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate)	\
396 {									\
397 	.id = DEVLINK_PARAM_GENERIC_ID_##_id,				\
398 	.name = DEVLINK_PARAM_GENERIC_##_id##_NAME,			\
399 	.type = DEVLINK_PARAM_GENERIC_##_id##_TYPE,			\
400 	.generic = true,						\
401 	.supported_cmodes = _cmodes,					\
402 	.get = _get,							\
403 	.set = _set,							\
404 	.validate = _validate,						\
405 }
406 
407 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate)	\
408 {									\
409 	.id = _id,							\
410 	.name = _name,							\
411 	.type = _type,							\
412 	.supported_cmodes = _cmodes,					\
413 	.get = _get,							\
414 	.set = _set,							\
415 	.validate = _validate,						\
416 }
417 
418 struct devlink_region;
419 
420 typedef void devlink_snapshot_data_dest_t(const void *data);
421 
422 struct devlink_ops {
423 	int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
424 	int (*port_type_set)(struct devlink_port *devlink_port,
425 			     enum devlink_port_type port_type);
426 	int (*port_split)(struct devlink *devlink, unsigned int port_index,
427 			  unsigned int count, struct netlink_ext_ack *extack);
428 	int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
429 			    struct netlink_ext_ack *extack);
430 	int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
431 			   u16 pool_index,
432 			   struct devlink_sb_pool_info *pool_info);
433 	int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
434 			   u16 pool_index, u32 size,
435 			   enum devlink_sb_threshold_type threshold_type);
436 	int (*sb_port_pool_get)(struct devlink_port *devlink_port,
437 				unsigned int sb_index, u16 pool_index,
438 				u32 *p_threshold);
439 	int (*sb_port_pool_set)(struct devlink_port *devlink_port,
440 				unsigned int sb_index, u16 pool_index,
441 				u32 threshold);
442 	int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
443 				   unsigned int sb_index,
444 				   u16 tc_index,
445 				   enum devlink_sb_pool_type pool_type,
446 				   u16 *p_pool_index, u32 *p_threshold);
447 	int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
448 				   unsigned int sb_index,
449 				   u16 tc_index,
450 				   enum devlink_sb_pool_type pool_type,
451 				   u16 pool_index, u32 threshold);
452 	int (*sb_occ_snapshot)(struct devlink *devlink,
453 			       unsigned int sb_index);
454 	int (*sb_occ_max_clear)(struct devlink *devlink,
455 				unsigned int sb_index);
456 	int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
457 				    unsigned int sb_index, u16 pool_index,
458 				    u32 *p_cur, u32 *p_max);
459 	int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
460 				       unsigned int sb_index,
461 				       u16 tc_index,
462 				       enum devlink_sb_pool_type pool_type,
463 				       u32 *p_cur, u32 *p_max);
464 
465 	int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
466 	int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
467 				struct netlink_ext_ack *extack);
468 	int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
469 	int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
470 				       struct netlink_ext_ack *extack);
471 	int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode);
472 	int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode,
473 				      struct netlink_ext_ack *extack);
474 };
475 
476 static inline void *devlink_priv(struct devlink *devlink)
477 {
478 	BUG_ON(!devlink);
479 	return &devlink->priv;
480 }
481 
482 static inline struct devlink *priv_to_devlink(void *priv)
483 {
484 	BUG_ON(!priv);
485 	return container_of(priv, struct devlink, priv);
486 }
487 
488 struct ib_device;
489 
490 #if IS_ENABLED(CONFIG_NET_DEVLINK)
491 
492 struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
493 int devlink_register(struct devlink *devlink, struct device *dev);
494 void devlink_unregister(struct devlink *devlink);
495 void devlink_free(struct devlink *devlink);
496 int devlink_port_register(struct devlink *devlink,
497 			  struct devlink_port *devlink_port,
498 			  unsigned int port_index);
499 void devlink_port_unregister(struct devlink_port *devlink_port);
500 void devlink_port_type_eth_set(struct devlink_port *devlink_port,
501 			       struct net_device *netdev);
502 void devlink_port_type_ib_set(struct devlink_port *devlink_port,
503 			      struct ib_device *ibdev);
504 void devlink_port_type_clear(struct devlink_port *devlink_port);
505 void devlink_port_attrs_set(struct devlink_port *devlink_port,
506 			    enum devlink_port_flavour flavour,
507 			    u32 port_number, bool split,
508 			    u32 split_subport_number);
509 int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
510 				    char *name, size_t len);
511 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
512 			u32 size, u16 ingress_pools_count,
513 			u16 egress_pools_count, u16 ingress_tc_count,
514 			u16 egress_tc_count);
515 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
516 int devlink_dpipe_table_register(struct devlink *devlink,
517 				 const char *table_name,
518 				 struct devlink_dpipe_table_ops *table_ops,
519 				 void *priv, bool counter_control_extern);
520 void devlink_dpipe_table_unregister(struct devlink *devlink,
521 				    const char *table_name);
522 int devlink_dpipe_headers_register(struct devlink *devlink,
523 				   struct devlink_dpipe_headers *dpipe_headers);
524 void devlink_dpipe_headers_unregister(struct devlink *devlink);
525 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
526 					 const char *table_name);
527 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
528 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
529 				   struct devlink_dpipe_entry *entry);
530 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
531 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
532 int devlink_dpipe_action_put(struct sk_buff *skb,
533 			     struct devlink_dpipe_action *action);
534 int devlink_dpipe_match_put(struct sk_buff *skb,
535 			    struct devlink_dpipe_match *match);
536 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
537 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
538 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
539 
540 int devlink_resource_register(struct devlink *devlink,
541 			      const char *resource_name,
542 			      u64 resource_size,
543 			      u64 resource_id,
544 			      u64 parent_resource_id,
545 			      const struct devlink_resource_size_params *size_params);
546 void devlink_resources_unregister(struct devlink *devlink,
547 				  struct devlink_resource *resource);
548 int devlink_resource_size_get(struct devlink *devlink,
549 			      u64 resource_id,
550 			      u64 *p_resource_size);
551 int devlink_dpipe_table_resource_set(struct devlink *devlink,
552 				     const char *table_name, u64 resource_id,
553 				     u64 resource_units);
554 void devlink_resource_occ_get_register(struct devlink *devlink,
555 				       u64 resource_id,
556 				       devlink_resource_occ_get_t *occ_get,
557 				       void *occ_get_priv);
558 void devlink_resource_occ_get_unregister(struct devlink *devlink,
559 					 u64 resource_id);
560 int devlink_params_register(struct devlink *devlink,
561 			    const struct devlink_param *params,
562 			    size_t params_count);
563 void devlink_params_unregister(struct devlink *devlink,
564 			       const struct devlink_param *params,
565 			       size_t params_count);
566 int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
567 				       union devlink_param_value *init_val);
568 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
569 				       union devlink_param_value init_val);
570 void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
571 void devlink_param_value_str_fill(union devlink_param_value *dst_val,
572 				  const char *src);
573 struct devlink_region *devlink_region_create(struct devlink *devlink,
574 					     const char *region_name,
575 					     u32 region_max_snapshots,
576 					     u64 region_size);
577 void devlink_region_destroy(struct devlink_region *region);
578 u32 devlink_region_shapshot_id_get(struct devlink *devlink);
579 int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
580 				   u8 *data, u32 snapshot_id,
581 				   devlink_snapshot_data_dest_t *data_destructor);
582 
583 #else
584 
585 static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
586 					    size_t priv_size)
587 {
588 	return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
589 }
590 
591 static inline int devlink_register(struct devlink *devlink, struct device *dev)
592 {
593 	return 0;
594 }
595 
596 static inline void devlink_unregister(struct devlink *devlink)
597 {
598 }
599 
600 static inline void devlink_free(struct devlink *devlink)
601 {
602 	kfree(devlink);
603 }
604 
605 static inline int devlink_port_register(struct devlink *devlink,
606 					struct devlink_port *devlink_port,
607 					unsigned int port_index)
608 {
609 	return 0;
610 }
611 
612 static inline void devlink_port_unregister(struct devlink_port *devlink_port)
613 {
614 }
615 
616 static inline void devlink_port_type_eth_set(struct devlink_port *devlink_port,
617 					     struct net_device *netdev)
618 {
619 }
620 
621 static inline void devlink_port_type_ib_set(struct devlink_port *devlink_port,
622 					    struct ib_device *ibdev)
623 {
624 }
625 
626 static inline void devlink_port_type_clear(struct devlink_port *devlink_port)
627 {
628 }
629 
630 static inline void devlink_port_attrs_set(struct devlink_port *devlink_port,
631 					  enum devlink_port_flavour flavour,
632 					  u32 port_number, bool split,
633 					  u32 split_subport_number)
634 {
635 }
636 
637 static inline int
638 devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
639 				char *name, size_t len)
640 {
641 	return -EOPNOTSUPP;
642 }
643 
644 static inline int devlink_sb_register(struct devlink *devlink,
645 				      unsigned int sb_index, u32 size,
646 				      u16 ingress_pools_count,
647 				      u16 egress_pools_count,
648 				      u16 ingress_tc_count,
649 				      u16 egress_tc_count)
650 {
651 	return 0;
652 }
653 
654 static inline void devlink_sb_unregister(struct devlink *devlink,
655 					 unsigned int sb_index)
656 {
657 }
658 
659 static inline int
660 devlink_dpipe_table_register(struct devlink *devlink,
661 			     const char *table_name,
662 			     struct devlink_dpipe_table_ops *table_ops,
663 			     void *priv, bool counter_control_extern)
664 {
665 	return 0;
666 }
667 
668 static inline void devlink_dpipe_table_unregister(struct devlink *devlink,
669 						  const char *table_name)
670 {
671 }
672 
673 static inline int devlink_dpipe_headers_register(struct devlink *devlink,
674 						 struct devlink_dpipe_headers *
675 						 dpipe_headers)
676 {
677 	return 0;
678 }
679 
680 static inline void devlink_dpipe_headers_unregister(struct devlink *devlink)
681 {
682 }
683 
684 static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
685 						       const char *table_name)
686 {
687 	return false;
688 }
689 
690 static inline int
691 devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx)
692 {
693 	return 0;
694 }
695 
696 static inline int
697 devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
698 			       struct devlink_dpipe_entry *entry)
699 {
700 	return 0;
701 }
702 
703 static inline int
704 devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx)
705 {
706 	return 0;
707 }
708 
709 static inline void
710 devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry)
711 {
712 }
713 
714 static inline int
715 devlink_dpipe_action_put(struct sk_buff *skb,
716 			 struct devlink_dpipe_action *action)
717 {
718 	return 0;
719 }
720 
721 static inline int
722 devlink_dpipe_match_put(struct sk_buff *skb,
723 			struct devlink_dpipe_match *match)
724 {
725 	return 0;
726 }
727 
728 static inline int
729 devlink_resource_register(struct devlink *devlink,
730 			  const char *resource_name,
731 			  u64 resource_size,
732 			  u64 resource_id,
733 			  u64 parent_resource_id,
734 			  const struct devlink_resource_size_params *size_params)
735 {
736 	return 0;
737 }
738 
739 static inline void
740 devlink_resources_unregister(struct devlink *devlink,
741 			     struct devlink_resource *resource)
742 {
743 }
744 
745 static inline int
746 devlink_resource_size_get(struct devlink *devlink, u64 resource_id,
747 			  u64 *p_resource_size)
748 {
749 	return -EOPNOTSUPP;
750 }
751 
752 static inline int
753 devlink_dpipe_table_resource_set(struct devlink *devlink,
754 				 const char *table_name, u64 resource_id,
755 				 u64 resource_units)
756 {
757 	return -EOPNOTSUPP;
758 }
759 
760 static inline void
761 devlink_resource_occ_get_register(struct devlink *devlink,
762 				  u64 resource_id,
763 				  devlink_resource_occ_get_t *occ_get,
764 				  void *occ_get_priv)
765 {
766 }
767 
768 static inline void
769 devlink_resource_occ_get_unregister(struct devlink *devlink,
770 				    u64 resource_id)
771 {
772 }
773 
774 static inline int
775 devlink_params_register(struct devlink *devlink,
776 			const struct devlink_param *params,
777 			size_t params_count)
778 {
779 	return 0;
780 }
781 
782 static inline void
783 devlink_params_unregister(struct devlink *devlink,
784 			  const struct devlink_param *params,
785 			  size_t params_count)
786 {
787 
788 }
789 
790 static inline int
791 devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
792 				   union devlink_param_value *init_val)
793 {
794 	return -EOPNOTSUPP;
795 }
796 
797 static inline int
798 devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
799 				   union devlink_param_value init_val)
800 {
801 	return -EOPNOTSUPP;
802 }
803 
804 static inline void
805 devlink_param_value_changed(struct devlink *devlink, u32 param_id)
806 {
807 }
808 
809 static inline void
810 devlink_param_value_str_fill(union devlink_param_value *dst_val,
811 			     const char *src)
812 {
813 }
814 
815 static inline struct devlink_region *
816 devlink_region_create(struct devlink *devlink,
817 		      const char *region_name,
818 		      u32 region_max_snapshots,
819 		      u64 region_size)
820 {
821 	return NULL;
822 }
823 
824 static inline void
825 devlink_region_destroy(struct devlink_region *region)
826 {
827 }
828 
829 static inline u32
830 devlink_region_shapshot_id_get(struct devlink *devlink)
831 {
832 	return 0;
833 }
834 
835 static inline int
836 devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
837 			       u8 *data, u32 snapshot_id,
838 			       devlink_snapshot_data_dest_t *data_destructor)
839 {
840 	return 0;
841 }
842 
843 #endif
844 
845 #endif /* _NET_DEVLINK_H_ */
846