xref: /linux/include/net/devlink.h (revision a5d9265e017f081f0dc133c0e2f45103d027b874)
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 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 
374 	/* add new param generic ids above here*/
375 	__DEVLINK_PARAM_GENERIC_ID_MAX,
376 	DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
377 };
378 
379 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
380 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
381 
382 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
383 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
384 
385 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
386 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
387 
388 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
389 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
390 
391 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
392 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
393 
394 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
395 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
396 
397 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
398 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
399 
400 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
401 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
402 
403 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate)	\
404 {									\
405 	.id = DEVLINK_PARAM_GENERIC_ID_##_id,				\
406 	.name = DEVLINK_PARAM_GENERIC_##_id##_NAME,			\
407 	.type = DEVLINK_PARAM_GENERIC_##_id##_TYPE,			\
408 	.generic = true,						\
409 	.supported_cmodes = _cmodes,					\
410 	.get = _get,							\
411 	.set = _set,							\
412 	.validate = _validate,						\
413 }
414 
415 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate)	\
416 {									\
417 	.id = _id,							\
418 	.name = _name,							\
419 	.type = _type,							\
420 	.supported_cmodes = _cmodes,					\
421 	.get = _get,							\
422 	.set = _set,							\
423 	.validate = _validate,						\
424 }
425 
426 /* Part number, identifier of board design */
427 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID	"board.id"
428 /* Revision of board design */
429 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV	"board.rev"
430 /* Maker of the board */
431 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE	"board.manufacture"
432 
433 /* Control processor FW version */
434 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT	"fw.mgmt"
435 /* Data path microcode controlling high-speed packet processing */
436 #define DEVLINK_INFO_VERSION_GENERIC_FW_APP	"fw.app"
437 /* UNDI software version */
438 #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI	"fw.undi"
439 /* NCSI support/handler version */
440 #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI	"fw.ncsi"
441 
442 struct devlink_region;
443 struct devlink_info_req;
444 
445 typedef void devlink_snapshot_data_dest_t(const void *data);
446 
447 struct devlink_fmsg;
448 struct devlink_health_reporter;
449 
450 /**
451  * struct devlink_health_reporter_ops - Reporter operations
452  * @name: reporter name
453  * @recover: callback to recover from reported error
454  *           if priv_ctx is NULL, run a full recover
455  * @dump: callback to dump an object
456  *        if priv_ctx is NULL, run a full dump
457  * @diagnose: callback to diagnose the current status
458  */
459 
460 struct devlink_health_reporter_ops {
461 	char *name;
462 	int (*recover)(struct devlink_health_reporter *reporter,
463 		       void *priv_ctx);
464 	int (*dump)(struct devlink_health_reporter *reporter,
465 		    struct devlink_fmsg *fmsg, void *priv_ctx);
466 	int (*diagnose)(struct devlink_health_reporter *reporter,
467 			struct devlink_fmsg *fmsg);
468 };
469 
470 struct devlink_ops {
471 	int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
472 	int (*port_type_set)(struct devlink_port *devlink_port,
473 			     enum devlink_port_type port_type);
474 	int (*port_split)(struct devlink *devlink, unsigned int port_index,
475 			  unsigned int count, struct netlink_ext_ack *extack);
476 	int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
477 			    struct netlink_ext_ack *extack);
478 	int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
479 			   u16 pool_index,
480 			   struct devlink_sb_pool_info *pool_info);
481 	int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
482 			   u16 pool_index, u32 size,
483 			   enum devlink_sb_threshold_type threshold_type);
484 	int (*sb_port_pool_get)(struct devlink_port *devlink_port,
485 				unsigned int sb_index, u16 pool_index,
486 				u32 *p_threshold);
487 	int (*sb_port_pool_set)(struct devlink_port *devlink_port,
488 				unsigned int sb_index, u16 pool_index,
489 				u32 threshold);
490 	int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
491 				   unsigned int sb_index,
492 				   u16 tc_index,
493 				   enum devlink_sb_pool_type pool_type,
494 				   u16 *p_pool_index, u32 *p_threshold);
495 	int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
496 				   unsigned int sb_index,
497 				   u16 tc_index,
498 				   enum devlink_sb_pool_type pool_type,
499 				   u16 pool_index, u32 threshold);
500 	int (*sb_occ_snapshot)(struct devlink *devlink,
501 			       unsigned int sb_index);
502 	int (*sb_occ_max_clear)(struct devlink *devlink,
503 				unsigned int sb_index);
504 	int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
505 				    unsigned int sb_index, u16 pool_index,
506 				    u32 *p_cur, u32 *p_max);
507 	int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
508 				       unsigned int sb_index,
509 				       u16 tc_index,
510 				       enum devlink_sb_pool_type pool_type,
511 				       u32 *p_cur, u32 *p_max);
512 
513 	int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
514 	int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
515 				struct netlink_ext_ack *extack);
516 	int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
517 	int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
518 				       struct netlink_ext_ack *extack);
519 	int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode);
520 	int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode,
521 				      struct netlink_ext_ack *extack);
522 	int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
523 			struct netlink_ext_ack *extack);
524 	int (*flash_update)(struct devlink *devlink, const char *file_name,
525 			    const char *component,
526 			    struct netlink_ext_ack *extack);
527 };
528 
529 static inline void *devlink_priv(struct devlink *devlink)
530 {
531 	BUG_ON(!devlink);
532 	return &devlink->priv;
533 }
534 
535 static inline struct devlink *priv_to_devlink(void *priv)
536 {
537 	BUG_ON(!priv);
538 	return container_of(priv, struct devlink, priv);
539 }
540 
541 struct ib_device;
542 
543 #if IS_ENABLED(CONFIG_NET_DEVLINK)
544 
545 struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
546 int devlink_register(struct devlink *devlink, struct device *dev);
547 void devlink_unregister(struct devlink *devlink);
548 void devlink_free(struct devlink *devlink);
549 int devlink_port_register(struct devlink *devlink,
550 			  struct devlink_port *devlink_port,
551 			  unsigned int port_index);
552 void devlink_port_unregister(struct devlink_port *devlink_port);
553 void devlink_port_type_eth_set(struct devlink_port *devlink_port,
554 			       struct net_device *netdev);
555 void devlink_port_type_ib_set(struct devlink_port *devlink_port,
556 			      struct ib_device *ibdev);
557 void devlink_port_type_clear(struct devlink_port *devlink_port);
558 void devlink_port_attrs_set(struct devlink_port *devlink_port,
559 			    enum devlink_port_flavour flavour,
560 			    u32 port_number, bool split,
561 			    u32 split_subport_number);
562 int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
563 				    char *name, size_t len);
564 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
565 			u32 size, u16 ingress_pools_count,
566 			u16 egress_pools_count, u16 ingress_tc_count,
567 			u16 egress_tc_count);
568 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
569 int devlink_dpipe_table_register(struct devlink *devlink,
570 				 const char *table_name,
571 				 struct devlink_dpipe_table_ops *table_ops,
572 				 void *priv, bool counter_control_extern);
573 void devlink_dpipe_table_unregister(struct devlink *devlink,
574 				    const char *table_name);
575 int devlink_dpipe_headers_register(struct devlink *devlink,
576 				   struct devlink_dpipe_headers *dpipe_headers);
577 void devlink_dpipe_headers_unregister(struct devlink *devlink);
578 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
579 					 const char *table_name);
580 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
581 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
582 				   struct devlink_dpipe_entry *entry);
583 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
584 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
585 int devlink_dpipe_action_put(struct sk_buff *skb,
586 			     struct devlink_dpipe_action *action);
587 int devlink_dpipe_match_put(struct sk_buff *skb,
588 			    struct devlink_dpipe_match *match);
589 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
590 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
591 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
592 
593 int devlink_resource_register(struct devlink *devlink,
594 			      const char *resource_name,
595 			      u64 resource_size,
596 			      u64 resource_id,
597 			      u64 parent_resource_id,
598 			      const struct devlink_resource_size_params *size_params);
599 void devlink_resources_unregister(struct devlink *devlink,
600 				  struct devlink_resource *resource);
601 int devlink_resource_size_get(struct devlink *devlink,
602 			      u64 resource_id,
603 			      u64 *p_resource_size);
604 int devlink_dpipe_table_resource_set(struct devlink *devlink,
605 				     const char *table_name, u64 resource_id,
606 				     u64 resource_units);
607 void devlink_resource_occ_get_register(struct devlink *devlink,
608 				       u64 resource_id,
609 				       devlink_resource_occ_get_t *occ_get,
610 				       void *occ_get_priv);
611 void devlink_resource_occ_get_unregister(struct devlink *devlink,
612 					 u64 resource_id);
613 int devlink_params_register(struct devlink *devlink,
614 			    const struct devlink_param *params,
615 			    size_t params_count);
616 void devlink_params_unregister(struct devlink *devlink,
617 			       const struct devlink_param *params,
618 			       size_t params_count);
619 void devlink_params_publish(struct devlink *devlink);
620 void devlink_params_unpublish(struct devlink *devlink);
621 int devlink_port_params_register(struct devlink_port *devlink_port,
622 				 const struct devlink_param *params,
623 				 size_t params_count);
624 void devlink_port_params_unregister(struct devlink_port *devlink_port,
625 				    const struct devlink_param *params,
626 				    size_t params_count);
627 int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
628 				       union devlink_param_value *init_val);
629 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
630 				       union devlink_param_value init_val);
631 int
632 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
633 					u32 param_id,
634 					union devlink_param_value *init_val);
635 int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
636 					    u32 param_id,
637 					    union devlink_param_value init_val);
638 void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
639 void devlink_port_param_value_changed(struct devlink_port *devlink_port,
640 				      u32 param_id);
641 void devlink_param_value_str_fill(union devlink_param_value *dst_val,
642 				  const char *src);
643 struct devlink_region *devlink_region_create(struct devlink *devlink,
644 					     const char *region_name,
645 					     u32 region_max_snapshots,
646 					     u64 region_size);
647 void devlink_region_destroy(struct devlink_region *region);
648 u32 devlink_region_shapshot_id_get(struct devlink *devlink);
649 int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
650 				   u8 *data, u32 snapshot_id,
651 				   devlink_snapshot_data_dest_t *data_destructor);
652 int devlink_info_serial_number_put(struct devlink_info_req *req,
653 				   const char *sn);
654 int devlink_info_driver_name_put(struct devlink_info_req *req,
655 				 const char *name);
656 int devlink_info_version_fixed_put(struct devlink_info_req *req,
657 				   const char *version_name,
658 				   const char *version_value);
659 int devlink_info_version_stored_put(struct devlink_info_req *req,
660 				    const char *version_name,
661 				    const char *version_value);
662 int devlink_info_version_running_put(struct devlink_info_req *req,
663 				     const char *version_name,
664 				     const char *version_value);
665 
666 int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
667 int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
668 
669 int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
670 int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
671 
672 int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
673 				     const char *name);
674 int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
675 
676 int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
677 int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
678 int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
679 int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
680 int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
681 int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
682 			    u16 value_len);
683 
684 int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
685 			       bool value);
686 int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
687 			     u8 value);
688 int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
689 			      u32 value);
690 int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
691 			      u64 value);
692 int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
693 				 const char *value);
694 int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
695 				 const void *value, u16 value_len);
696 
697 struct devlink_health_reporter *
698 devlink_health_reporter_create(struct devlink *devlink,
699 			       const struct devlink_health_reporter_ops *ops,
700 			       u64 graceful_period, bool auto_recover,
701 			       void *priv);
702 void
703 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
704 
705 void *
706 devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
707 int devlink_health_report(struct devlink_health_reporter *reporter,
708 			  const char *msg, void *priv_ctx);
709 
710 #else
711 
712 static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
713 					    size_t priv_size)
714 {
715 	return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
716 }
717 
718 static inline int devlink_register(struct devlink *devlink, struct device *dev)
719 {
720 	return 0;
721 }
722 
723 static inline void devlink_unregister(struct devlink *devlink)
724 {
725 }
726 
727 static inline void devlink_params_publish(struct devlink *devlink)
728 {
729 }
730 
731 static inline void devlink_params_unpublish(struct devlink *devlink)
732 {
733 }
734 
735 static inline void devlink_free(struct devlink *devlink)
736 {
737 	kfree(devlink);
738 }
739 
740 static inline int devlink_port_register(struct devlink *devlink,
741 					struct devlink_port *devlink_port,
742 					unsigned int port_index)
743 {
744 	return 0;
745 }
746 
747 static inline void devlink_port_unregister(struct devlink_port *devlink_port)
748 {
749 }
750 
751 static inline void devlink_port_type_eth_set(struct devlink_port *devlink_port,
752 					     struct net_device *netdev)
753 {
754 }
755 
756 static inline void devlink_port_type_ib_set(struct devlink_port *devlink_port,
757 					    struct ib_device *ibdev)
758 {
759 }
760 
761 static inline void devlink_port_type_clear(struct devlink_port *devlink_port)
762 {
763 }
764 
765 static inline void devlink_port_attrs_set(struct devlink_port *devlink_port,
766 					  enum devlink_port_flavour flavour,
767 					  u32 port_number, bool split,
768 					  u32 split_subport_number)
769 {
770 }
771 
772 static inline int
773 devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
774 				char *name, size_t len)
775 {
776 	return -EOPNOTSUPP;
777 }
778 
779 static inline int devlink_sb_register(struct devlink *devlink,
780 				      unsigned int sb_index, u32 size,
781 				      u16 ingress_pools_count,
782 				      u16 egress_pools_count,
783 				      u16 ingress_tc_count,
784 				      u16 egress_tc_count)
785 {
786 	return 0;
787 }
788 
789 static inline void devlink_sb_unregister(struct devlink *devlink,
790 					 unsigned int sb_index)
791 {
792 }
793 
794 static inline int
795 devlink_dpipe_table_register(struct devlink *devlink,
796 			     const char *table_name,
797 			     struct devlink_dpipe_table_ops *table_ops,
798 			     void *priv, bool counter_control_extern)
799 {
800 	return 0;
801 }
802 
803 static inline void devlink_dpipe_table_unregister(struct devlink *devlink,
804 						  const char *table_name)
805 {
806 }
807 
808 static inline int devlink_dpipe_headers_register(struct devlink *devlink,
809 						 struct devlink_dpipe_headers *
810 						 dpipe_headers)
811 {
812 	return 0;
813 }
814 
815 static inline void devlink_dpipe_headers_unregister(struct devlink *devlink)
816 {
817 }
818 
819 static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
820 						       const char *table_name)
821 {
822 	return false;
823 }
824 
825 static inline int
826 devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx)
827 {
828 	return 0;
829 }
830 
831 static inline int
832 devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
833 			       struct devlink_dpipe_entry *entry)
834 {
835 	return 0;
836 }
837 
838 static inline int
839 devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx)
840 {
841 	return 0;
842 }
843 
844 static inline void
845 devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry)
846 {
847 }
848 
849 static inline int
850 devlink_dpipe_action_put(struct sk_buff *skb,
851 			 struct devlink_dpipe_action *action)
852 {
853 	return 0;
854 }
855 
856 static inline int
857 devlink_dpipe_match_put(struct sk_buff *skb,
858 			struct devlink_dpipe_match *match)
859 {
860 	return 0;
861 }
862 
863 static inline int
864 devlink_resource_register(struct devlink *devlink,
865 			  const char *resource_name,
866 			  u64 resource_size,
867 			  u64 resource_id,
868 			  u64 parent_resource_id,
869 			  const struct devlink_resource_size_params *size_params)
870 {
871 	return 0;
872 }
873 
874 static inline void
875 devlink_resources_unregister(struct devlink *devlink,
876 			     struct devlink_resource *resource)
877 {
878 }
879 
880 static inline int
881 devlink_resource_size_get(struct devlink *devlink, u64 resource_id,
882 			  u64 *p_resource_size)
883 {
884 	return -EOPNOTSUPP;
885 }
886 
887 static inline int
888 devlink_dpipe_table_resource_set(struct devlink *devlink,
889 				 const char *table_name, u64 resource_id,
890 				 u64 resource_units)
891 {
892 	return -EOPNOTSUPP;
893 }
894 
895 static inline void
896 devlink_resource_occ_get_register(struct devlink *devlink,
897 				  u64 resource_id,
898 				  devlink_resource_occ_get_t *occ_get,
899 				  void *occ_get_priv)
900 {
901 }
902 
903 static inline void
904 devlink_resource_occ_get_unregister(struct devlink *devlink,
905 				    u64 resource_id)
906 {
907 }
908 
909 static inline int
910 devlink_params_register(struct devlink *devlink,
911 			const struct devlink_param *params,
912 			size_t params_count)
913 {
914 	return 0;
915 }
916 
917 static inline void
918 devlink_params_unregister(struct devlink *devlink,
919 			  const struct devlink_param *params,
920 			  size_t params_count)
921 {
922 
923 }
924 
925 static inline int
926 devlink_port_params_register(struct devlink_port *devlink_port,
927 			     const struct devlink_param *params,
928 			     size_t params_count)
929 {
930 	return 0;
931 }
932 
933 static inline void
934 devlink_port_params_unregister(struct devlink_port *devlink_port,
935 			       const struct devlink_param *params,
936 			       size_t params_count)
937 {
938 }
939 
940 static inline int
941 devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
942 				   union devlink_param_value *init_val)
943 {
944 	return -EOPNOTSUPP;
945 }
946 
947 static inline int
948 devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
949 				   union devlink_param_value init_val)
950 {
951 	return -EOPNOTSUPP;
952 }
953 
954 static inline int
955 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
956 					u32 param_id,
957 					union devlink_param_value *init_val)
958 {
959 	return -EOPNOTSUPP;
960 }
961 
962 static inline int
963 devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
964 					u32 param_id,
965 					union devlink_param_value init_val)
966 {
967 	return -EOPNOTSUPP;
968 }
969 
970 static inline void
971 devlink_param_value_changed(struct devlink *devlink, u32 param_id)
972 {
973 }
974 
975 static inline void
976 devlink_port_param_value_changed(struct devlink_port *devlink_port,
977 				 u32 param_id)
978 {
979 }
980 
981 static inline void
982 devlink_param_value_str_fill(union devlink_param_value *dst_val,
983 			     const char *src)
984 {
985 }
986 
987 static inline struct devlink_region *
988 devlink_region_create(struct devlink *devlink,
989 		      const char *region_name,
990 		      u32 region_max_snapshots,
991 		      u64 region_size)
992 {
993 	return NULL;
994 }
995 
996 static inline void
997 devlink_region_destroy(struct devlink_region *region)
998 {
999 }
1000 
1001 static inline u32
1002 devlink_region_shapshot_id_get(struct devlink *devlink)
1003 {
1004 	return 0;
1005 }
1006 
1007 static inline int
1008 devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
1009 			       u8 *data, u32 snapshot_id,
1010 			       devlink_snapshot_data_dest_t *data_destructor)
1011 {
1012 	return 0;
1013 }
1014 
1015 static inline int
1016 devlink_info_driver_name_put(struct devlink_info_req *req, const char *name)
1017 {
1018 	return 0;
1019 }
1020 
1021 static inline int
1022 devlink_info_serial_number_put(struct devlink_info_req *req, const char *sn)
1023 {
1024 	return 0;
1025 }
1026 
1027 static inline int
1028 devlink_info_version_fixed_put(struct devlink_info_req *req,
1029 			       const char *version_name,
1030 			       const char *version_value)
1031 {
1032 	return 0;
1033 }
1034 
1035 static inline int
1036 devlink_info_version_stored_put(struct devlink_info_req *req,
1037 				const char *version_name,
1038 				const char *version_value)
1039 {
1040 	return 0;
1041 }
1042 
1043 static inline int
1044 devlink_info_version_running_put(struct devlink_info_req *req,
1045 				 const char *version_name,
1046 				 const char *version_value)
1047 {
1048 	return 0;
1049 }
1050 
1051 static inline int
1052 devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg)
1053 {
1054 	return 0;
1055 }
1056 
1057 static inline int
1058 devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg)
1059 {
1060 	return 0;
1061 }
1062 
1063 static inline int
1064 devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name)
1065 {
1066 	return 0;
1067 }
1068 
1069 static inline int
1070 devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg)
1071 {
1072 	return 0;
1073 }
1074 
1075 static inline int
1076 devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1077 				 const char *name)
1078 {
1079 	return 0;
1080 }
1081 
1082 static inline int
1083 devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg)
1084 {
1085 	return 0;
1086 }
1087 
1088 static inline int
1089 devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value)
1090 {
1091 	return 0;
1092 }
1093 
1094 static inline int
1095 devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value)
1096 {
1097 	return 0;
1098 }
1099 
1100 static inline int
1101 devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value)
1102 {
1103 	return 0;
1104 }
1105 
1106 static inline int
1107 devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value)
1108 {
1109 	return 0;
1110 }
1111 
1112 static inline int
1113 devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value)
1114 {
1115 	return 0;
1116 }
1117 
1118 static inline int
1119 devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1120 			u16 value_len)
1121 {
1122 	return 0;
1123 }
1124 
1125 static inline int
1126 devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1127 			   bool value)
1128 {
1129 	return 0;
1130 }
1131 
1132 static inline int
1133 devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1134 			 u8 value)
1135 {
1136 	return 0;
1137 }
1138 
1139 static inline int
1140 devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1141 			  u32 value)
1142 {
1143 	return 0;
1144 }
1145 
1146 static inline int
1147 devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1148 			  u64 value)
1149 {
1150 	return 0;
1151 }
1152 
1153 static inline int
1154 devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1155 			     const char *value)
1156 {
1157 	return 0;
1158 }
1159 
1160 static inline int
1161 devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
1162 			     const void *value, u16 value_len)
1163 {
1164 	return 0;
1165 }
1166 
1167 static inline struct devlink_health_reporter *
1168 devlink_health_reporter_create(struct devlink *devlink,
1169 			       const struct devlink_health_reporter_ops *ops,
1170 			       u64 graceful_period, bool auto_recover,
1171 			       void *priv)
1172 {
1173 	return NULL;
1174 }
1175 
1176 static inline void
1177 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
1178 {
1179 }
1180 
1181 static inline void *
1182 devlink_health_reporter_priv(struct devlink_health_reporter *reporter)
1183 {
1184 	return NULL;
1185 }
1186 
1187 static inline int
1188 devlink_health_report(struct devlink_health_reporter *reporter,
1189 		      const char *msg, void *priv_ctx)
1190 {
1191 	return 0;
1192 }
1193 #endif
1194 
1195 #if IS_REACHABLE(CONFIG_NET_DEVLINK)
1196 void devlink_compat_running_version(struct net_device *dev,
1197 				    char *buf, size_t len);
1198 int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
1199 #else
1200 static inline void
1201 devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1202 {
1203 }
1204 
1205 static inline int
1206 devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1207 {
1208 	return -EOPNOTSUPP;
1209 }
1210 #endif
1211 
1212 #endif /* _NET_DEVLINK_H_ */
1213