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