xref: /linux-6.15/include/net/devlink.h (revision 257eeded)
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 <[email protected]>
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 list_head reporter_list;
34 	struct devlink_dpipe_headers *dpipe_headers;
35 	const struct devlink_ops *ops;
36 	struct device *dev;
37 	possible_net_t _net;
38 	struct mutex lock;
39 	char priv[0] __aligned(NETDEV_ALIGN);
40 };
41 
42 struct devlink_port_attrs {
43 	bool set;
44 	enum devlink_port_flavour flavour;
45 	u32 port_number; /* same value as "split group" */
46 	bool split;
47 	u32 split_subport_number;
48 };
49 
50 struct devlink_port {
51 	struct list_head list;
52 	struct list_head param_list;
53 	struct devlink *devlink;
54 	unsigned index;
55 	bool registered;
56 	enum devlink_port_type type;
57 	enum devlink_port_type desired_type;
58 	void *type_dev;
59 	struct devlink_port_attrs attrs;
60 };
61 
62 struct devlink_sb_pool_info {
63 	enum devlink_sb_pool_type pool_type;
64 	u32 size;
65 	enum devlink_sb_threshold_type threshold_type;
66 	u32 cell_size;
67 };
68 
69 /**
70  * struct devlink_dpipe_field - dpipe field object
71  * @name: field name
72  * @id: index inside the headers field array
73  * @bitwidth: bitwidth
74  * @mapping_type: mapping type
75  */
76 struct devlink_dpipe_field {
77 	const char *name;
78 	unsigned int id;
79 	unsigned int bitwidth;
80 	enum devlink_dpipe_field_mapping_type mapping_type;
81 };
82 
83 /**
84  * struct devlink_dpipe_header - dpipe header object
85  * @name: header name
86  * @id: index, global/local detrmined by global bit
87  * @fields: fields
88  * @fields_count: number of fields
89  * @global: indicates if header is shared like most protocol header
90  *	    or driver specific
91  */
92 struct devlink_dpipe_header {
93 	const char *name;
94 	unsigned int id;
95 	struct devlink_dpipe_field *fields;
96 	unsigned int fields_count;
97 	bool global;
98 };
99 
100 /**
101  * struct devlink_dpipe_match - represents match operation
102  * @type: type of match
103  * @header_index: header index (packets can have several headers of same
104  *		  type like in case of tunnels)
105  * @header: header
106  * @fieled_id: field index
107  */
108 struct devlink_dpipe_match {
109 	enum devlink_dpipe_match_type type;
110 	unsigned int header_index;
111 	struct devlink_dpipe_header *header;
112 	unsigned int field_id;
113 };
114 
115 /**
116  * struct devlink_dpipe_action - represents action operation
117  * @type: type of action
118  * @header_index: header index (packets can have several headers of same
119  *		  type like in case of tunnels)
120  * @header: header
121  * @fieled_id: field index
122  */
123 struct devlink_dpipe_action {
124 	enum devlink_dpipe_action_type type;
125 	unsigned int header_index;
126 	struct devlink_dpipe_header *header;
127 	unsigned int field_id;
128 };
129 
130 /**
131  * struct devlink_dpipe_value - represents value of match/action
132  * @action: action
133  * @match: match
134  * @mapping_value: in case the field has some mapping this value
135  *                 specified the mapping value
136  * @mapping_valid: specify if mapping value is valid
137  * @value_size: value size
138  * @value: value
139  * @mask: bit mask
140  */
141 struct devlink_dpipe_value {
142 	union {
143 		struct devlink_dpipe_action *action;
144 		struct devlink_dpipe_match *match;
145 	};
146 	unsigned int mapping_value;
147 	bool mapping_valid;
148 	unsigned int value_size;
149 	void *value;
150 	void *mask;
151 };
152 
153 /**
154  * struct devlink_dpipe_entry - table entry object
155  * @index: index of the entry in the table
156  * @match_values: match values
157  * @matche_values_count: count of matches tuples
158  * @action_values: actions values
159  * @action_values_count: count of actions values
160  * @counter: value of counter
161  * @counter_valid: Specify if value is valid from hardware
162  */
163 struct devlink_dpipe_entry {
164 	u64 index;
165 	struct devlink_dpipe_value *match_values;
166 	unsigned int match_values_count;
167 	struct devlink_dpipe_value *action_values;
168 	unsigned int action_values_count;
169 	u64 counter;
170 	bool counter_valid;
171 };
172 
173 /**
174  * struct devlink_dpipe_dump_ctx - context provided to driver in order
175  *				   to dump
176  * @info: info
177  * @cmd: devlink command
178  * @skb: skb
179  * @nest: top attribute
180  * @hdr: hdr
181  */
182 struct devlink_dpipe_dump_ctx {
183 	struct genl_info *info;
184 	enum devlink_command cmd;
185 	struct sk_buff *skb;
186 	struct nlattr *nest;
187 	void *hdr;
188 };
189 
190 struct devlink_dpipe_table_ops;
191 
192 /**
193  * struct devlink_dpipe_table - table object
194  * @priv: private
195  * @name: table name
196  * @counters_enabled: indicates if counters are active
197  * @counter_control_extern: indicates if counter control is in dpipe or
198  *			    external tool
199  * @resource_valid: Indicate that the resource id is valid
200  * @resource_id: relative resource this table is related to
201  * @resource_units: number of resource's unit consumed per table's entry
202  * @table_ops: table operations
203  * @rcu: rcu
204  */
205 struct devlink_dpipe_table {
206 	void *priv;
207 	struct list_head list;
208 	const char *name;
209 	bool counters_enabled;
210 	bool counter_control_extern;
211 	bool resource_valid;
212 	u64 resource_id;
213 	u64 resource_units;
214 	struct devlink_dpipe_table_ops *table_ops;
215 	struct rcu_head rcu;
216 };
217 
218 /**
219  * struct devlink_dpipe_table_ops - dpipe_table ops
220  * @actions_dump - dumps all tables actions
221  * @matches_dump - dumps all tables matches
222  * @entries_dump - dumps all active entries in the table
223  * @counters_set_update - when changing the counter status hardware sync
224  *			  maybe needed to allocate/free counter related
225  *			  resources
226  * @size_get - get size
227  */
228 struct devlink_dpipe_table_ops {
229 	int (*actions_dump)(void *priv, struct sk_buff *skb);
230 	int (*matches_dump)(void *priv, struct sk_buff *skb);
231 	int (*entries_dump)(void *priv, bool counters_enabled,
232 			    struct devlink_dpipe_dump_ctx *dump_ctx);
233 	int (*counters_set_update)(void *priv, bool enable);
234 	u64 (*size_get)(void *priv);
235 };
236 
237 /**
238  * struct devlink_dpipe_headers - dpipe headers
239  * @headers - header array can be shared (global bit) or driver specific
240  * @headers_count - count of headers
241  */
242 struct devlink_dpipe_headers {
243 	struct devlink_dpipe_header **headers;
244 	unsigned int headers_count;
245 };
246 
247 /**
248  * struct devlink_resource_size_params - resource's size parameters
249  * @size_min: minimum size which can be set
250  * @size_max: maximum size which can be set
251  * @size_granularity: size granularity
252  * @size_unit: resource's basic unit
253  */
254 struct devlink_resource_size_params {
255 	u64 size_min;
256 	u64 size_max;
257 	u64 size_granularity;
258 	enum devlink_resource_unit unit;
259 };
260 
261 static inline void
262 devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
263 				  u64 size_min, u64 size_max,
264 				  u64 size_granularity,
265 				  enum devlink_resource_unit unit)
266 {
267 	size_params->size_min = size_min;
268 	size_params->size_max = size_max;
269 	size_params->size_granularity = size_granularity;
270 	size_params->unit = unit;
271 }
272 
273 typedef u64 devlink_resource_occ_get_t(void *priv);
274 
275 /**
276  * struct devlink_resource - devlink resource
277  * @name: name of the resource
278  * @id: id, per devlink instance
279  * @size: size of the resource
280  * @size_new: updated size of the resource, reload is needed
281  * @size_valid: valid in case the total size of the resource is valid
282  *              including its children
283  * @parent: parent resource
284  * @size_params: size parameters
285  * @list: parent list
286  * @resource_list: list of child resources
287  */
288 struct devlink_resource {
289 	const char *name;
290 	u64 id;
291 	u64 size;
292 	u64 size_new;
293 	bool size_valid;
294 	struct devlink_resource *parent;
295 	struct devlink_resource_size_params size_params;
296 	struct list_head list;
297 	struct list_head resource_list;
298 	devlink_resource_occ_get_t *occ_get;
299 	void *occ_get_priv;
300 };
301 
302 #define DEVLINK_RESOURCE_ID_PARENT_TOP 0
303 
304 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32
305 enum devlink_param_type {
306 	DEVLINK_PARAM_TYPE_U8,
307 	DEVLINK_PARAM_TYPE_U16,
308 	DEVLINK_PARAM_TYPE_U32,
309 	DEVLINK_PARAM_TYPE_STRING,
310 	DEVLINK_PARAM_TYPE_BOOL,
311 };
312 
313 union devlink_param_value {
314 	u8 vu8;
315 	u16 vu16;
316 	u32 vu32;
317 	char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
318 	bool vbool;
319 };
320 
321 struct devlink_param_gset_ctx {
322 	union devlink_param_value val;
323 	enum devlink_param_cmode cmode;
324 };
325 
326 /**
327  * struct devlink_param - devlink configuration parameter data
328  * @name: name of the parameter
329  * @generic: indicates if the parameter is generic or driver specific
330  * @type: parameter type
331  * @supported_cmodes: bitmap of supported configuration modes
332  * @get: get parameter value, used for runtime and permanent
333  *       configuration modes
334  * @set: set parameter value, used for runtime and permanent
335  *       configuration modes
336  * @validate: validate input value is applicable (within value range, etc.)
337  *
338  * This struct should be used by the driver to fill the data for
339  * a parameter it registers.
340  */
341 struct devlink_param {
342 	u32 id;
343 	const char *name;
344 	bool generic;
345 	enum devlink_param_type type;
346 	unsigned long supported_cmodes;
347 	int (*get)(struct devlink *devlink, u32 id,
348 		   struct devlink_param_gset_ctx *ctx);
349 	int (*set)(struct devlink *devlink, u32 id,
350 		   struct devlink_param_gset_ctx *ctx);
351 	int (*validate)(struct devlink *devlink, u32 id,
352 			union devlink_param_value val,
353 			struct netlink_ext_ack *extack);
354 };
355 
356 struct devlink_param_item {
357 	struct list_head list;
358 	const struct devlink_param *param;
359 	union devlink_param_value driverinit_value;
360 	bool driverinit_value_valid;
361 	bool published;
362 };
363 
364 enum devlink_param_generic_id {
365 	DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
366 	DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
367 	DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
368 	DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
369 	DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
370 	DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
371 	DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
372 	DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
373 	DEVLINK_PARAM_GENERIC_ID_WOL,
374 
375 	/* add new param generic ids above here*/
376 	__DEVLINK_PARAM_GENERIC_ID_MAX,
377 	DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
378 };
379 
380 enum devlink_param_wol_types {
381 	DEVLINK_PARAM_WAKE_MAGIC = (1 << 0),
382 };
383 
384 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
385 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
386 
387 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
388 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
389 
390 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
391 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
392 
393 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
394 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
395 
396 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
397 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
398 
399 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
400 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
401 
402 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
403 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
404 
405 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
406 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
407 
408 #define DEVLINK_PARAM_GENERIC_WOL_NAME "wake_on_lan"
409 #define DEVLINK_PARAM_GENERIC_WOL_TYPE DEVLINK_PARAM_TYPE_U8
410 
411 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate)	\
412 {									\
413 	.id = DEVLINK_PARAM_GENERIC_ID_##_id,				\
414 	.name = DEVLINK_PARAM_GENERIC_##_id##_NAME,			\
415 	.type = DEVLINK_PARAM_GENERIC_##_id##_TYPE,			\
416 	.generic = true,						\
417 	.supported_cmodes = _cmodes,					\
418 	.get = _get,							\
419 	.set = _set,							\
420 	.validate = _validate,						\
421 }
422 
423 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate)	\
424 {									\
425 	.id = _id,							\
426 	.name = _name,							\
427 	.type = _type,							\
428 	.supported_cmodes = _cmodes,					\
429 	.get = _get,							\
430 	.set = _set,							\
431 	.validate = _validate,						\
432 }
433 
434 /* Part number, identifier of board design */
435 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID	"board.id"
436 /* Revision of board design */
437 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV	"board.rev"
438 
439 /* Control processor FW version */
440 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT	"fw.mgmt"
441 /* Data path microcode controlling high-speed packet processing */
442 #define DEVLINK_INFO_VERSION_GENERIC_FW_APP	"fw.app"
443 /* UNDI software version */
444 #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI	"fw.undi"
445 /* NCSI support/handler version */
446 #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI	"fw.ncsi"
447 
448 struct devlink_region;
449 struct devlink_info_req;
450 
451 typedef void devlink_snapshot_data_dest_t(const void *data);
452 
453 struct devlink_fmsg;
454 struct devlink_health_reporter;
455 
456 /**
457  * struct devlink_health_reporter_ops - Reporter operations
458  * @name: reporter name
459  * @recover: callback to recover from reported error
460  *           if priv_ctx is NULL, run a full recover
461  * @dump: callback to dump an object
462  *        if priv_ctx is NULL, run a full dump
463  * @diagnose: callback to diagnose the current status
464  */
465 
466 struct devlink_health_reporter_ops {
467 	char *name;
468 	int (*recover)(struct devlink_health_reporter *reporter,
469 		       void *priv_ctx);
470 	int (*dump)(struct devlink_health_reporter *reporter,
471 		    struct devlink_fmsg *fmsg, void *priv_ctx);
472 	int (*diagnose)(struct devlink_health_reporter *reporter,
473 			struct devlink_fmsg *fmsg);
474 };
475 
476 struct devlink_ops {
477 	int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
478 	int (*port_type_set)(struct devlink_port *devlink_port,
479 			     enum devlink_port_type port_type);
480 	int (*port_split)(struct devlink *devlink, unsigned int port_index,
481 			  unsigned int count, struct netlink_ext_ack *extack);
482 	int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
483 			    struct netlink_ext_ack *extack);
484 	int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
485 			   u16 pool_index,
486 			   struct devlink_sb_pool_info *pool_info);
487 	int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
488 			   u16 pool_index, u32 size,
489 			   enum devlink_sb_threshold_type threshold_type);
490 	int (*sb_port_pool_get)(struct devlink_port *devlink_port,
491 				unsigned int sb_index, u16 pool_index,
492 				u32 *p_threshold);
493 	int (*sb_port_pool_set)(struct devlink_port *devlink_port,
494 				unsigned int sb_index, u16 pool_index,
495 				u32 threshold);
496 	int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
497 				   unsigned int sb_index,
498 				   u16 tc_index,
499 				   enum devlink_sb_pool_type pool_type,
500 				   u16 *p_pool_index, u32 *p_threshold);
501 	int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
502 				   unsigned int sb_index,
503 				   u16 tc_index,
504 				   enum devlink_sb_pool_type pool_type,
505 				   u16 pool_index, u32 threshold);
506 	int (*sb_occ_snapshot)(struct devlink *devlink,
507 			       unsigned int sb_index);
508 	int (*sb_occ_max_clear)(struct devlink *devlink,
509 				unsigned int sb_index);
510 	int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
511 				    unsigned int sb_index, u16 pool_index,
512 				    u32 *p_cur, u32 *p_max);
513 	int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
514 				       unsigned int sb_index,
515 				       u16 tc_index,
516 				       enum devlink_sb_pool_type pool_type,
517 				       u32 *p_cur, u32 *p_max);
518 
519 	int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
520 	int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
521 				struct netlink_ext_ack *extack);
522 	int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
523 	int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
524 				       struct netlink_ext_ack *extack);
525 	int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode);
526 	int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode,
527 				      struct netlink_ext_ack *extack);
528 	int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
529 			struct netlink_ext_ack *extack);
530 };
531 
532 static inline void *devlink_priv(struct devlink *devlink)
533 {
534 	BUG_ON(!devlink);
535 	return &devlink->priv;
536 }
537 
538 static inline struct devlink *priv_to_devlink(void *priv)
539 {
540 	BUG_ON(!priv);
541 	return container_of(priv, struct devlink, priv);
542 }
543 
544 struct ib_device;
545 
546 #if IS_ENABLED(CONFIG_NET_DEVLINK)
547 
548 struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
549 int devlink_register(struct devlink *devlink, struct device *dev);
550 void devlink_unregister(struct devlink *devlink);
551 void devlink_free(struct devlink *devlink);
552 int devlink_port_register(struct devlink *devlink,
553 			  struct devlink_port *devlink_port,
554 			  unsigned int port_index);
555 void devlink_port_unregister(struct devlink_port *devlink_port);
556 void devlink_port_type_eth_set(struct devlink_port *devlink_port,
557 			       struct net_device *netdev);
558 void devlink_port_type_ib_set(struct devlink_port *devlink_port,
559 			      struct ib_device *ibdev);
560 void devlink_port_type_clear(struct devlink_port *devlink_port);
561 void devlink_port_attrs_set(struct devlink_port *devlink_port,
562 			    enum devlink_port_flavour flavour,
563 			    u32 port_number, bool split,
564 			    u32 split_subport_number);
565 int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
566 				    char *name, size_t len);
567 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
568 			u32 size, u16 ingress_pools_count,
569 			u16 egress_pools_count, u16 ingress_tc_count,
570 			u16 egress_tc_count);
571 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
572 int devlink_dpipe_table_register(struct devlink *devlink,
573 				 const char *table_name,
574 				 struct devlink_dpipe_table_ops *table_ops,
575 				 void *priv, bool counter_control_extern);
576 void devlink_dpipe_table_unregister(struct devlink *devlink,
577 				    const char *table_name);
578 int devlink_dpipe_headers_register(struct devlink *devlink,
579 				   struct devlink_dpipe_headers *dpipe_headers);
580 void devlink_dpipe_headers_unregister(struct devlink *devlink);
581 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
582 					 const char *table_name);
583 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
584 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
585 				   struct devlink_dpipe_entry *entry);
586 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
587 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
588 int devlink_dpipe_action_put(struct sk_buff *skb,
589 			     struct devlink_dpipe_action *action);
590 int devlink_dpipe_match_put(struct sk_buff *skb,
591 			    struct devlink_dpipe_match *match);
592 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
593 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
594 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
595 
596 int devlink_resource_register(struct devlink *devlink,
597 			      const char *resource_name,
598 			      u64 resource_size,
599 			      u64 resource_id,
600 			      u64 parent_resource_id,
601 			      const struct devlink_resource_size_params *size_params);
602 void devlink_resources_unregister(struct devlink *devlink,
603 				  struct devlink_resource *resource);
604 int devlink_resource_size_get(struct devlink *devlink,
605 			      u64 resource_id,
606 			      u64 *p_resource_size);
607 int devlink_dpipe_table_resource_set(struct devlink *devlink,
608 				     const char *table_name, u64 resource_id,
609 				     u64 resource_units);
610 void devlink_resource_occ_get_register(struct devlink *devlink,
611 				       u64 resource_id,
612 				       devlink_resource_occ_get_t *occ_get,
613 				       void *occ_get_priv);
614 void devlink_resource_occ_get_unregister(struct devlink *devlink,
615 					 u64 resource_id);
616 int devlink_params_register(struct devlink *devlink,
617 			    const struct devlink_param *params,
618 			    size_t params_count);
619 void devlink_params_unregister(struct devlink *devlink,
620 			       const struct devlink_param *params,
621 			       size_t params_count);
622 void devlink_params_publish(struct devlink *devlink);
623 void devlink_params_unpublish(struct devlink *devlink);
624 int devlink_port_params_register(struct devlink_port *devlink_port,
625 				 const struct devlink_param *params,
626 				 size_t params_count);
627 void devlink_port_params_unregister(struct devlink_port *devlink_port,
628 				    const struct devlink_param *params,
629 				    size_t params_count);
630 int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
631 				       union devlink_param_value *init_val);
632 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
633 				       union devlink_param_value init_val);
634 int
635 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
636 					u32 param_id,
637 					union devlink_param_value *init_val);
638 int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
639 					    u32 param_id,
640 					    union devlink_param_value init_val);
641 void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
642 void devlink_port_param_value_changed(struct devlink_port *devlink_port,
643 				      u32 param_id);
644 void devlink_param_value_str_fill(union devlink_param_value *dst_val,
645 				  const char *src);
646 struct devlink_region *devlink_region_create(struct devlink *devlink,
647 					     const char *region_name,
648 					     u32 region_max_snapshots,
649 					     u64 region_size);
650 void devlink_region_destroy(struct devlink_region *region);
651 u32 devlink_region_shapshot_id_get(struct devlink *devlink);
652 int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
653 				   u8 *data, u32 snapshot_id,
654 				   devlink_snapshot_data_dest_t *data_destructor);
655 int devlink_info_serial_number_put(struct devlink_info_req *req,
656 				   const char *sn);
657 int devlink_info_driver_name_put(struct devlink_info_req *req,
658 				 const char *name);
659 int devlink_info_version_fixed_put(struct devlink_info_req *req,
660 				   const char *version_name,
661 				   const char *version_value);
662 int devlink_info_version_stored_put(struct devlink_info_req *req,
663 				    const char *version_name,
664 				    const char *version_value);
665 int devlink_info_version_running_put(struct devlink_info_req *req,
666 				     const char *version_name,
667 				     const char *version_value);
668 
669 int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
670 int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
671 
672 int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
673 int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
674 
675 int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
676 				     const char *name);
677 int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
678 
679 int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
680 int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
681 int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
682 int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
683 int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
684 int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
685 			    u16 value_len);
686 
687 int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
688 			       bool value);
689 int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
690 			     u8 value);
691 int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
692 			      u32 value);
693 int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
694 			      u64 value);
695 int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
696 				 const char *value);
697 int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
698 				 const void *value, u16 value_len);
699 
700 struct devlink_health_reporter *
701 devlink_health_reporter_create(struct devlink *devlink,
702 			       const struct devlink_health_reporter_ops *ops,
703 			       u64 graceful_period, bool auto_recover,
704 			       void *priv);
705 void
706 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
707 
708 void *
709 devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
710 int devlink_health_report(struct devlink_health_reporter *reporter,
711 			  const char *msg, void *priv_ctx);
712 
713 #else
714 
715 static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
716 					    size_t priv_size)
717 {
718 	return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
719 }
720 
721 static inline int devlink_register(struct devlink *devlink, struct device *dev)
722 {
723 	return 0;
724 }
725 
726 static inline void devlink_unregister(struct devlink *devlink)
727 {
728 }
729 
730 static inline void devlink_params_publish(struct devlink *devlink)
731 {
732 }
733 
734 static inline void devlink_params_unpublish(struct devlink *devlink)
735 {
736 }
737 
738 static inline void devlink_free(struct devlink *devlink)
739 {
740 	kfree(devlink);
741 }
742 
743 static inline int devlink_port_register(struct devlink *devlink,
744 					struct devlink_port *devlink_port,
745 					unsigned int port_index)
746 {
747 	return 0;
748 }
749 
750 static inline void devlink_port_unregister(struct devlink_port *devlink_port)
751 {
752 }
753 
754 static inline void devlink_port_type_eth_set(struct devlink_port *devlink_port,
755 					     struct net_device *netdev)
756 {
757 }
758 
759 static inline void devlink_port_type_ib_set(struct devlink_port *devlink_port,
760 					    struct ib_device *ibdev)
761 {
762 }
763 
764 static inline void devlink_port_type_clear(struct devlink_port *devlink_port)
765 {
766 }
767 
768 static inline void devlink_port_attrs_set(struct devlink_port *devlink_port,
769 					  enum devlink_port_flavour flavour,
770 					  u32 port_number, bool split,
771 					  u32 split_subport_number)
772 {
773 }
774 
775 static inline int
776 devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
777 				char *name, size_t len)
778 {
779 	return -EOPNOTSUPP;
780 }
781 
782 static inline int devlink_sb_register(struct devlink *devlink,
783 				      unsigned int sb_index, u32 size,
784 				      u16 ingress_pools_count,
785 				      u16 egress_pools_count,
786 				      u16 ingress_tc_count,
787 				      u16 egress_tc_count)
788 {
789 	return 0;
790 }
791 
792 static inline void devlink_sb_unregister(struct devlink *devlink,
793 					 unsigned int sb_index)
794 {
795 }
796 
797 static inline int
798 devlink_dpipe_table_register(struct devlink *devlink,
799 			     const char *table_name,
800 			     struct devlink_dpipe_table_ops *table_ops,
801 			     void *priv, bool counter_control_extern)
802 {
803 	return 0;
804 }
805 
806 static inline void devlink_dpipe_table_unregister(struct devlink *devlink,
807 						  const char *table_name)
808 {
809 }
810 
811 static inline int devlink_dpipe_headers_register(struct devlink *devlink,
812 						 struct devlink_dpipe_headers *
813 						 dpipe_headers)
814 {
815 	return 0;
816 }
817 
818 static inline void devlink_dpipe_headers_unregister(struct devlink *devlink)
819 {
820 }
821 
822 static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
823 						       const char *table_name)
824 {
825 	return false;
826 }
827 
828 static inline int
829 devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx)
830 {
831 	return 0;
832 }
833 
834 static inline int
835 devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
836 			       struct devlink_dpipe_entry *entry)
837 {
838 	return 0;
839 }
840 
841 static inline int
842 devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx)
843 {
844 	return 0;
845 }
846 
847 static inline void
848 devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry)
849 {
850 }
851 
852 static inline int
853 devlink_dpipe_action_put(struct sk_buff *skb,
854 			 struct devlink_dpipe_action *action)
855 {
856 	return 0;
857 }
858 
859 static inline int
860 devlink_dpipe_match_put(struct sk_buff *skb,
861 			struct devlink_dpipe_match *match)
862 {
863 	return 0;
864 }
865 
866 static inline int
867 devlink_resource_register(struct devlink *devlink,
868 			  const char *resource_name,
869 			  u64 resource_size,
870 			  u64 resource_id,
871 			  u64 parent_resource_id,
872 			  const struct devlink_resource_size_params *size_params)
873 {
874 	return 0;
875 }
876 
877 static inline void
878 devlink_resources_unregister(struct devlink *devlink,
879 			     struct devlink_resource *resource)
880 {
881 }
882 
883 static inline int
884 devlink_resource_size_get(struct devlink *devlink, u64 resource_id,
885 			  u64 *p_resource_size)
886 {
887 	return -EOPNOTSUPP;
888 }
889 
890 static inline int
891 devlink_dpipe_table_resource_set(struct devlink *devlink,
892 				 const char *table_name, u64 resource_id,
893 				 u64 resource_units)
894 {
895 	return -EOPNOTSUPP;
896 }
897 
898 static inline void
899 devlink_resource_occ_get_register(struct devlink *devlink,
900 				  u64 resource_id,
901 				  devlink_resource_occ_get_t *occ_get,
902 				  void *occ_get_priv)
903 {
904 }
905 
906 static inline void
907 devlink_resource_occ_get_unregister(struct devlink *devlink,
908 				    u64 resource_id)
909 {
910 }
911 
912 static inline int
913 devlink_params_register(struct devlink *devlink,
914 			const struct devlink_param *params,
915 			size_t params_count)
916 {
917 	return 0;
918 }
919 
920 static inline void
921 devlink_params_unregister(struct devlink *devlink,
922 			  const struct devlink_param *params,
923 			  size_t params_count)
924 {
925 
926 }
927 
928 static inline int
929 devlink_port_params_register(struct devlink_port *devlink_port,
930 			     const struct devlink_param *params,
931 			     size_t params_count)
932 {
933 	return 0;
934 }
935 
936 static inline void
937 devlink_port_params_unregister(struct devlink_port *devlink_port,
938 			       const struct devlink_param *params,
939 			       size_t params_count)
940 {
941 }
942 
943 static inline int
944 devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
945 				   union devlink_param_value *init_val)
946 {
947 	return -EOPNOTSUPP;
948 }
949 
950 static inline int
951 devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
952 				   union devlink_param_value init_val)
953 {
954 	return -EOPNOTSUPP;
955 }
956 
957 static inline int
958 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
959 					u32 param_id,
960 					union devlink_param_value *init_val)
961 {
962 	return -EOPNOTSUPP;
963 }
964 
965 static inline int
966 devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
967 					u32 param_id,
968 					union devlink_param_value init_val)
969 {
970 	return -EOPNOTSUPP;
971 }
972 
973 static inline void
974 devlink_param_value_changed(struct devlink *devlink, u32 param_id)
975 {
976 }
977 
978 static inline void
979 devlink_port_param_value_changed(struct devlink_port *devlink_port,
980 				 u32 param_id)
981 {
982 }
983 
984 static inline void
985 devlink_param_value_str_fill(union devlink_param_value *dst_val,
986 			     const char *src)
987 {
988 }
989 
990 static inline struct devlink_region *
991 devlink_region_create(struct devlink *devlink,
992 		      const char *region_name,
993 		      u32 region_max_snapshots,
994 		      u64 region_size)
995 {
996 	return NULL;
997 }
998 
999 static inline void
1000 devlink_region_destroy(struct devlink_region *region)
1001 {
1002 }
1003 
1004 static inline u32
1005 devlink_region_shapshot_id_get(struct devlink *devlink)
1006 {
1007 	return 0;
1008 }
1009 
1010 static inline int
1011 devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
1012 			       u8 *data, u32 snapshot_id,
1013 			       devlink_snapshot_data_dest_t *data_destructor)
1014 {
1015 	return 0;
1016 }
1017 
1018 static inline int
1019 devlink_info_driver_name_put(struct devlink_info_req *req, const char *name)
1020 {
1021 	return 0;
1022 }
1023 
1024 static inline int
1025 devlink_info_serial_number_put(struct devlink_info_req *req, const char *sn)
1026 {
1027 	return 0;
1028 }
1029 
1030 static inline int
1031 devlink_info_version_fixed_put(struct devlink_info_req *req,
1032 			       const char *version_name,
1033 			       const char *version_value)
1034 {
1035 	return 0;
1036 }
1037 
1038 static inline int
1039 devlink_info_version_stored_put(struct devlink_info_req *req,
1040 				const char *version_name,
1041 				const char *version_value)
1042 {
1043 	return 0;
1044 }
1045 
1046 static inline int
1047 devlink_info_version_running_put(struct devlink_info_req *req,
1048 				 const char *version_name,
1049 				 const char *version_value)
1050 {
1051 	return 0;
1052 }
1053 
1054 static inline int
1055 devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg)
1056 {
1057 	return 0;
1058 }
1059 
1060 static inline int
1061 devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg)
1062 {
1063 	return 0;
1064 }
1065 
1066 static inline int
1067 devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name)
1068 {
1069 	return 0;
1070 }
1071 
1072 static inline int
1073 devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg)
1074 {
1075 	return 0;
1076 }
1077 
1078 static inline int
1079 devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1080 				 const char *name)
1081 {
1082 	return 0;
1083 }
1084 
1085 static inline int
1086 devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg)
1087 {
1088 	return 0;
1089 }
1090 
1091 static inline int
1092 devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value)
1093 {
1094 	return 0;
1095 }
1096 
1097 static inline int
1098 devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value)
1099 {
1100 	return 0;
1101 }
1102 
1103 static inline int
1104 devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value)
1105 {
1106 	return 0;
1107 }
1108 
1109 static inline int
1110 devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value)
1111 {
1112 	return 0;
1113 }
1114 
1115 static inline int
1116 devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value)
1117 {
1118 	return 0;
1119 }
1120 
1121 static inline int
1122 devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1123 			u16 value_len)
1124 {
1125 	return 0;
1126 }
1127 
1128 static inline int
1129 devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1130 			   bool value)
1131 {
1132 	return 0;
1133 }
1134 
1135 static inline int
1136 devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1137 			 u8 value)
1138 {
1139 	return 0;
1140 }
1141 
1142 static inline int
1143 devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1144 			  u32 value)
1145 {
1146 	return 0;
1147 }
1148 
1149 static inline int
1150 devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1151 			  u64 value)
1152 {
1153 	return 0;
1154 }
1155 
1156 static inline int
1157 devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1158 			     const char *value)
1159 {
1160 	return 0;
1161 }
1162 
1163 static inline int
1164 devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
1165 			     const void *value, u16 value_len)
1166 {
1167 	return 0;
1168 }
1169 
1170 static inline struct devlink_health_reporter *
1171 devlink_health_reporter_create(struct devlink *devlink,
1172 			       const struct devlink_health_reporter_ops *ops,
1173 			       u64 graceful_period, bool auto_recover,
1174 			       void *priv)
1175 {
1176 	return NULL;
1177 }
1178 
1179 static inline void
1180 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
1181 {
1182 }
1183 
1184 static inline void *
1185 devlink_health_reporter_priv(struct devlink_health_reporter *reporter)
1186 {
1187 	return NULL;
1188 }
1189 
1190 static inline int
1191 devlink_health_report(struct devlink_health_reporter *reporter,
1192 		      const char *msg, void *priv_ctx)
1193 {
1194 	return 0;
1195 }
1196 #endif
1197 
1198 #if IS_REACHABLE(CONFIG_NET_DEVLINK)
1199 void devlink_compat_running_version(struct net_device *dev,
1200 				    char *buf, size_t len);
1201 #else
1202 static inline void
1203 devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1204 {
1205 }
1206 #endif
1207 
1208 #endif /* _NET_DEVLINK_H_ */
1209