xref: /openbmc/linux/include/net/devlink.h (revision 7ff836f0)
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 <linux/spinlock.h>
20 #include <linux/workqueue.h>
21 #include <net/net_namespace.h>
22 #include <uapi/linux/devlink.h>
23 
24 struct devlink_ops;
25 
26 struct devlink {
27 	struct list_head list;
28 	struct list_head port_list;
29 	struct list_head sb_list;
30 	struct list_head dpipe_table_list;
31 	struct list_head resource_list;
32 	struct list_head param_list;
33 	struct list_head region_list;
34 	u32 snapshot_id;
35 	struct list_head reporter_list;
36 	struct mutex reporters_lock; /* protects reporter_list */
37 	struct devlink_dpipe_headers *dpipe_headers;
38 	const struct devlink_ops *ops;
39 	struct device *dev;
40 	possible_net_t _net;
41 	struct mutex lock;
42 	char priv[0] __aligned(NETDEV_ALIGN);
43 };
44 
45 struct devlink_port_attrs {
46 	u8 set:1,
47 	   split:1,
48 	   switch_port:1;
49 	enum devlink_port_flavour flavour;
50 	u32 port_number; /* same value as "split group" */
51 	u32 split_subport_number;
52 	struct netdev_phys_item_id switch_id;
53 };
54 
55 struct devlink_port {
56 	struct list_head list;
57 	struct list_head param_list;
58 	struct devlink *devlink;
59 	unsigned index;
60 	bool registered;
61 	spinlock_t type_lock; /* Protects type and type_dev
62 			       * pointer consistency.
63 			       */
64 	enum devlink_port_type type;
65 	enum devlink_port_type desired_type;
66 	void *type_dev;
67 	struct devlink_port_attrs attrs;
68 	struct delayed_work type_warn_dw;
69 };
70 
71 struct devlink_sb_pool_info {
72 	enum devlink_sb_pool_type pool_type;
73 	u32 size;
74 	enum devlink_sb_threshold_type threshold_type;
75 	u32 cell_size;
76 };
77 
78 /**
79  * struct devlink_dpipe_field - dpipe field object
80  * @name: field name
81  * @id: index inside the headers field array
82  * @bitwidth: bitwidth
83  * @mapping_type: mapping type
84  */
85 struct devlink_dpipe_field {
86 	const char *name;
87 	unsigned int id;
88 	unsigned int bitwidth;
89 	enum devlink_dpipe_field_mapping_type mapping_type;
90 };
91 
92 /**
93  * struct devlink_dpipe_header - dpipe header object
94  * @name: header name
95  * @id: index, global/local detrmined by global bit
96  * @fields: fields
97  * @fields_count: number of fields
98  * @global: indicates if header is shared like most protocol header
99  *	    or driver specific
100  */
101 struct devlink_dpipe_header {
102 	const char *name;
103 	unsigned int id;
104 	struct devlink_dpipe_field *fields;
105 	unsigned int fields_count;
106 	bool global;
107 };
108 
109 /**
110  * struct devlink_dpipe_match - represents match operation
111  * @type: type of match
112  * @header_index: header index (packets can have several headers of same
113  *		  type like in case of tunnels)
114  * @header: header
115  * @fieled_id: field index
116  */
117 struct devlink_dpipe_match {
118 	enum devlink_dpipe_match_type type;
119 	unsigned int header_index;
120 	struct devlink_dpipe_header *header;
121 	unsigned int field_id;
122 };
123 
124 /**
125  * struct devlink_dpipe_action - represents action operation
126  * @type: type of action
127  * @header_index: header index (packets can have several headers of same
128  *		  type like in case of tunnels)
129  * @header: header
130  * @fieled_id: field index
131  */
132 struct devlink_dpipe_action {
133 	enum devlink_dpipe_action_type type;
134 	unsigned int header_index;
135 	struct devlink_dpipe_header *header;
136 	unsigned int field_id;
137 };
138 
139 /**
140  * struct devlink_dpipe_value - represents value of match/action
141  * @action: action
142  * @match: match
143  * @mapping_value: in case the field has some mapping this value
144  *                 specified the mapping value
145  * @mapping_valid: specify if mapping value is valid
146  * @value_size: value size
147  * @value: value
148  * @mask: bit mask
149  */
150 struct devlink_dpipe_value {
151 	union {
152 		struct devlink_dpipe_action *action;
153 		struct devlink_dpipe_match *match;
154 	};
155 	unsigned int mapping_value;
156 	bool mapping_valid;
157 	unsigned int value_size;
158 	void *value;
159 	void *mask;
160 };
161 
162 /**
163  * struct devlink_dpipe_entry - table entry object
164  * @index: index of the entry in the table
165  * @match_values: match values
166  * @matche_values_count: count of matches tuples
167  * @action_values: actions values
168  * @action_values_count: count of actions values
169  * @counter: value of counter
170  * @counter_valid: Specify if value is valid from hardware
171  */
172 struct devlink_dpipe_entry {
173 	u64 index;
174 	struct devlink_dpipe_value *match_values;
175 	unsigned int match_values_count;
176 	struct devlink_dpipe_value *action_values;
177 	unsigned int action_values_count;
178 	u64 counter;
179 	bool counter_valid;
180 };
181 
182 /**
183  * struct devlink_dpipe_dump_ctx - context provided to driver in order
184  *				   to dump
185  * @info: info
186  * @cmd: devlink command
187  * @skb: skb
188  * @nest: top attribute
189  * @hdr: hdr
190  */
191 struct devlink_dpipe_dump_ctx {
192 	struct genl_info *info;
193 	enum devlink_command cmd;
194 	struct sk_buff *skb;
195 	struct nlattr *nest;
196 	void *hdr;
197 };
198 
199 struct devlink_dpipe_table_ops;
200 
201 /**
202  * struct devlink_dpipe_table - table object
203  * @priv: private
204  * @name: table name
205  * @counters_enabled: indicates if counters are active
206  * @counter_control_extern: indicates if counter control is in dpipe or
207  *			    external tool
208  * @resource_valid: Indicate that the resource id is valid
209  * @resource_id: relative resource this table is related to
210  * @resource_units: number of resource's unit consumed per table's entry
211  * @table_ops: table operations
212  * @rcu: rcu
213  */
214 struct devlink_dpipe_table {
215 	void *priv;
216 	struct list_head list;
217 	const char *name;
218 	bool counters_enabled;
219 	bool counter_control_extern;
220 	bool resource_valid;
221 	u64 resource_id;
222 	u64 resource_units;
223 	struct devlink_dpipe_table_ops *table_ops;
224 	struct rcu_head rcu;
225 };
226 
227 /**
228  * struct devlink_dpipe_table_ops - dpipe_table ops
229  * @actions_dump - dumps all tables actions
230  * @matches_dump - dumps all tables matches
231  * @entries_dump - dumps all active entries in the table
232  * @counters_set_update - when changing the counter status hardware sync
233  *			  maybe needed to allocate/free counter related
234  *			  resources
235  * @size_get - get size
236  */
237 struct devlink_dpipe_table_ops {
238 	int (*actions_dump)(void *priv, struct sk_buff *skb);
239 	int (*matches_dump)(void *priv, struct sk_buff *skb);
240 	int (*entries_dump)(void *priv, bool counters_enabled,
241 			    struct devlink_dpipe_dump_ctx *dump_ctx);
242 	int (*counters_set_update)(void *priv, bool enable);
243 	u64 (*size_get)(void *priv);
244 };
245 
246 /**
247  * struct devlink_dpipe_headers - dpipe headers
248  * @headers - header array can be shared (global bit) or driver specific
249  * @headers_count - count of headers
250  */
251 struct devlink_dpipe_headers {
252 	struct devlink_dpipe_header **headers;
253 	unsigned int headers_count;
254 };
255 
256 /**
257  * struct devlink_resource_size_params - resource's size parameters
258  * @size_min: minimum size which can be set
259  * @size_max: maximum size which can be set
260  * @size_granularity: size granularity
261  * @size_unit: resource's basic unit
262  */
263 struct devlink_resource_size_params {
264 	u64 size_min;
265 	u64 size_max;
266 	u64 size_granularity;
267 	enum devlink_resource_unit unit;
268 };
269 
270 static inline void
271 devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
272 				  u64 size_min, u64 size_max,
273 				  u64 size_granularity,
274 				  enum devlink_resource_unit unit)
275 {
276 	size_params->size_min = size_min;
277 	size_params->size_max = size_max;
278 	size_params->size_granularity = size_granularity;
279 	size_params->unit = unit;
280 }
281 
282 typedef u64 devlink_resource_occ_get_t(void *priv);
283 
284 /**
285  * struct devlink_resource - devlink resource
286  * @name: name of the resource
287  * @id: id, per devlink instance
288  * @size: size of the resource
289  * @size_new: updated size of the resource, reload is needed
290  * @size_valid: valid in case the total size of the resource is valid
291  *              including its children
292  * @parent: parent resource
293  * @size_params: size parameters
294  * @list: parent list
295  * @resource_list: list of child resources
296  */
297 struct devlink_resource {
298 	const char *name;
299 	u64 id;
300 	u64 size;
301 	u64 size_new;
302 	bool size_valid;
303 	struct devlink_resource *parent;
304 	struct devlink_resource_size_params size_params;
305 	struct list_head list;
306 	struct list_head resource_list;
307 	devlink_resource_occ_get_t *occ_get;
308 	void *occ_get_priv;
309 };
310 
311 #define DEVLINK_RESOURCE_ID_PARENT_TOP 0
312 
313 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32
314 enum devlink_param_type {
315 	DEVLINK_PARAM_TYPE_U8,
316 	DEVLINK_PARAM_TYPE_U16,
317 	DEVLINK_PARAM_TYPE_U32,
318 	DEVLINK_PARAM_TYPE_STRING,
319 	DEVLINK_PARAM_TYPE_BOOL,
320 };
321 
322 union devlink_param_value {
323 	u8 vu8;
324 	u16 vu16;
325 	u32 vu32;
326 	char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
327 	bool vbool;
328 };
329 
330 struct devlink_param_gset_ctx {
331 	union devlink_param_value val;
332 	enum devlink_param_cmode cmode;
333 };
334 
335 /**
336  * struct devlink_param - devlink configuration parameter data
337  * @name: name of the parameter
338  * @generic: indicates if the parameter is generic or driver specific
339  * @type: parameter type
340  * @supported_cmodes: bitmap of supported configuration modes
341  * @get: get parameter value, used for runtime and permanent
342  *       configuration modes
343  * @set: set parameter value, used for runtime and permanent
344  *       configuration modes
345  * @validate: validate input value is applicable (within value range, etc.)
346  *
347  * This struct should be used by the driver to fill the data for
348  * a parameter it registers.
349  */
350 struct devlink_param {
351 	u32 id;
352 	const char *name;
353 	bool generic;
354 	enum devlink_param_type type;
355 	unsigned long supported_cmodes;
356 	int (*get)(struct devlink *devlink, u32 id,
357 		   struct devlink_param_gset_ctx *ctx);
358 	int (*set)(struct devlink *devlink, u32 id,
359 		   struct devlink_param_gset_ctx *ctx);
360 	int (*validate)(struct devlink *devlink, u32 id,
361 			union devlink_param_value val,
362 			struct netlink_ext_ack *extack);
363 };
364 
365 struct devlink_param_item {
366 	struct list_head list;
367 	const struct devlink_param *param;
368 	union devlink_param_value driverinit_value;
369 	bool driverinit_value_valid;
370 	bool published;
371 };
372 
373 enum devlink_param_generic_id {
374 	DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
375 	DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
376 	DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
377 	DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
378 	DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
379 	DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
380 	DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
381 	DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
382 
383 	/* add new param generic ids above here*/
384 	__DEVLINK_PARAM_GENERIC_ID_MAX,
385 	DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
386 };
387 
388 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
389 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
390 
391 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
392 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
393 
394 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
395 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
396 
397 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
398 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
399 
400 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
401 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
402 
403 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
404 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
405 
406 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
407 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
408 
409 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
410 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
411 
412 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate)	\
413 {									\
414 	.id = DEVLINK_PARAM_GENERIC_ID_##_id,				\
415 	.name = DEVLINK_PARAM_GENERIC_##_id##_NAME,			\
416 	.type = DEVLINK_PARAM_GENERIC_##_id##_TYPE,			\
417 	.generic = true,						\
418 	.supported_cmodes = _cmodes,					\
419 	.get = _get,							\
420 	.set = _set,							\
421 	.validate = _validate,						\
422 }
423 
424 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate)	\
425 {									\
426 	.id = _id,							\
427 	.name = _name,							\
428 	.type = _type,							\
429 	.supported_cmodes = _cmodes,					\
430 	.get = _get,							\
431 	.set = _set,							\
432 	.validate = _validate,						\
433 }
434 
435 /* Part number, identifier of board design */
436 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID	"board.id"
437 /* Revision of board design */
438 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV	"board.rev"
439 /* Maker of the board */
440 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE	"board.manufacture"
441 
442 /* Control processor FW version */
443 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT	"fw.mgmt"
444 /* Data path microcode controlling high-speed packet processing */
445 #define DEVLINK_INFO_VERSION_GENERIC_FW_APP	"fw.app"
446 /* UNDI software version */
447 #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI	"fw.undi"
448 /* NCSI support/handler version */
449 #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI	"fw.ncsi"
450 
451 struct devlink_region;
452 struct devlink_info_req;
453 
454 typedef void devlink_snapshot_data_dest_t(const void *data);
455 
456 struct devlink_fmsg;
457 struct devlink_health_reporter;
458 
459 enum devlink_health_reporter_state {
460 	DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
461 	DEVLINK_HEALTH_REPORTER_STATE_ERROR,
462 };
463 
464 /**
465  * struct devlink_health_reporter_ops - Reporter operations
466  * @name: reporter name
467  * @recover: callback to recover from reported error
468  *           if priv_ctx is NULL, run a full recover
469  * @dump: callback to dump an object
470  *        if priv_ctx is NULL, run a full dump
471  * @diagnose: callback to diagnose the current status
472  */
473 
474 struct devlink_health_reporter_ops {
475 	char *name;
476 	int (*recover)(struct devlink_health_reporter *reporter,
477 		       void *priv_ctx);
478 	int (*dump)(struct devlink_health_reporter *reporter,
479 		    struct devlink_fmsg *fmsg, void *priv_ctx);
480 	int (*diagnose)(struct devlink_health_reporter *reporter,
481 			struct devlink_fmsg *fmsg);
482 };
483 
484 struct devlink_ops {
485 	int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
486 	int (*port_type_set)(struct devlink_port *devlink_port,
487 			     enum devlink_port_type port_type);
488 	int (*port_split)(struct devlink *devlink, unsigned int port_index,
489 			  unsigned int count, struct netlink_ext_ack *extack);
490 	int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
491 			    struct netlink_ext_ack *extack);
492 	int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
493 			   u16 pool_index,
494 			   struct devlink_sb_pool_info *pool_info);
495 	int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
496 			   u16 pool_index, u32 size,
497 			   enum devlink_sb_threshold_type threshold_type,
498 			   struct netlink_ext_ack *extack);
499 	int (*sb_port_pool_get)(struct devlink_port *devlink_port,
500 				unsigned int sb_index, u16 pool_index,
501 				u32 *p_threshold);
502 	int (*sb_port_pool_set)(struct devlink_port *devlink_port,
503 				unsigned int sb_index, u16 pool_index,
504 				u32 threshold, struct netlink_ext_ack *extack);
505 	int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
506 				   unsigned int sb_index,
507 				   u16 tc_index,
508 				   enum devlink_sb_pool_type pool_type,
509 				   u16 *p_pool_index, u32 *p_threshold);
510 	int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
511 				   unsigned int sb_index,
512 				   u16 tc_index,
513 				   enum devlink_sb_pool_type pool_type,
514 				   u16 pool_index, u32 threshold,
515 				   struct netlink_ext_ack *extack);
516 	int (*sb_occ_snapshot)(struct devlink *devlink,
517 			       unsigned int sb_index);
518 	int (*sb_occ_max_clear)(struct devlink *devlink,
519 				unsigned int sb_index);
520 	int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
521 				    unsigned int sb_index, u16 pool_index,
522 				    u32 *p_cur, u32 *p_max);
523 	int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
524 				       unsigned int sb_index,
525 				       u16 tc_index,
526 				       enum devlink_sb_pool_type pool_type,
527 				       u32 *p_cur, u32 *p_max);
528 
529 	int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
530 	int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
531 				struct netlink_ext_ack *extack);
532 	int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
533 	int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
534 				       struct netlink_ext_ack *extack);
535 	int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode);
536 	int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode,
537 				      struct netlink_ext_ack *extack);
538 	int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
539 			struct netlink_ext_ack *extack);
540 	int (*flash_update)(struct devlink *devlink, const char *file_name,
541 			    const char *component,
542 			    struct netlink_ext_ack *extack);
543 };
544 
545 static inline void *devlink_priv(struct devlink *devlink)
546 {
547 	BUG_ON(!devlink);
548 	return &devlink->priv;
549 }
550 
551 static inline struct devlink *priv_to_devlink(void *priv)
552 {
553 	BUG_ON(!priv);
554 	return container_of(priv, struct devlink, priv);
555 }
556 
557 static inline struct devlink_port *
558 netdev_to_devlink_port(struct net_device *dev)
559 {
560 	if (dev->netdev_ops->ndo_get_devlink_port)
561 		return dev->netdev_ops->ndo_get_devlink_port(dev);
562 	return NULL;
563 }
564 
565 static inline struct devlink *netdev_to_devlink(struct net_device *dev)
566 {
567 	struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
568 
569 	if (devlink_port)
570 		return devlink_port->devlink;
571 	return NULL;
572 }
573 
574 struct ib_device;
575 
576 struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
577 int devlink_register(struct devlink *devlink, struct device *dev);
578 void devlink_unregister(struct devlink *devlink);
579 void devlink_free(struct devlink *devlink);
580 int devlink_port_register(struct devlink *devlink,
581 			  struct devlink_port *devlink_port,
582 			  unsigned int port_index);
583 void devlink_port_unregister(struct devlink_port *devlink_port);
584 void devlink_port_type_eth_set(struct devlink_port *devlink_port,
585 			       struct net_device *netdev);
586 void devlink_port_type_ib_set(struct devlink_port *devlink_port,
587 			      struct ib_device *ibdev);
588 void devlink_port_type_clear(struct devlink_port *devlink_port);
589 void devlink_port_attrs_set(struct devlink_port *devlink_port,
590 			    enum devlink_port_flavour flavour,
591 			    u32 port_number, bool split,
592 			    u32 split_subport_number,
593 			    const unsigned char *switch_id,
594 			    unsigned char switch_id_len);
595 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
596 			u32 size, u16 ingress_pools_count,
597 			u16 egress_pools_count, u16 ingress_tc_count,
598 			u16 egress_tc_count);
599 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
600 int devlink_dpipe_table_register(struct devlink *devlink,
601 				 const char *table_name,
602 				 struct devlink_dpipe_table_ops *table_ops,
603 				 void *priv, bool counter_control_extern);
604 void devlink_dpipe_table_unregister(struct devlink *devlink,
605 				    const char *table_name);
606 int devlink_dpipe_headers_register(struct devlink *devlink,
607 				   struct devlink_dpipe_headers *dpipe_headers);
608 void devlink_dpipe_headers_unregister(struct devlink *devlink);
609 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
610 					 const char *table_name);
611 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
612 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
613 				   struct devlink_dpipe_entry *entry);
614 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
615 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
616 int devlink_dpipe_action_put(struct sk_buff *skb,
617 			     struct devlink_dpipe_action *action);
618 int devlink_dpipe_match_put(struct sk_buff *skb,
619 			    struct devlink_dpipe_match *match);
620 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
621 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
622 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
623 
624 int devlink_resource_register(struct devlink *devlink,
625 			      const char *resource_name,
626 			      u64 resource_size,
627 			      u64 resource_id,
628 			      u64 parent_resource_id,
629 			      const struct devlink_resource_size_params *size_params);
630 void devlink_resources_unregister(struct devlink *devlink,
631 				  struct devlink_resource *resource);
632 int devlink_resource_size_get(struct devlink *devlink,
633 			      u64 resource_id,
634 			      u64 *p_resource_size);
635 int devlink_dpipe_table_resource_set(struct devlink *devlink,
636 				     const char *table_name, u64 resource_id,
637 				     u64 resource_units);
638 void devlink_resource_occ_get_register(struct devlink *devlink,
639 				       u64 resource_id,
640 				       devlink_resource_occ_get_t *occ_get,
641 				       void *occ_get_priv);
642 void devlink_resource_occ_get_unregister(struct devlink *devlink,
643 					 u64 resource_id);
644 int devlink_params_register(struct devlink *devlink,
645 			    const struct devlink_param *params,
646 			    size_t params_count);
647 void devlink_params_unregister(struct devlink *devlink,
648 			       const struct devlink_param *params,
649 			       size_t params_count);
650 void devlink_params_publish(struct devlink *devlink);
651 void devlink_params_unpublish(struct devlink *devlink);
652 int devlink_port_params_register(struct devlink_port *devlink_port,
653 				 const struct devlink_param *params,
654 				 size_t params_count);
655 void devlink_port_params_unregister(struct devlink_port *devlink_port,
656 				    const struct devlink_param *params,
657 				    size_t params_count);
658 int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
659 				       union devlink_param_value *init_val);
660 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
661 				       union devlink_param_value init_val);
662 int
663 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
664 					u32 param_id,
665 					union devlink_param_value *init_val);
666 int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
667 					    u32 param_id,
668 					    union devlink_param_value init_val);
669 void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
670 void devlink_port_param_value_changed(struct devlink_port *devlink_port,
671 				      u32 param_id);
672 void devlink_param_value_str_fill(union devlink_param_value *dst_val,
673 				  const char *src);
674 struct devlink_region *devlink_region_create(struct devlink *devlink,
675 					     const char *region_name,
676 					     u32 region_max_snapshots,
677 					     u64 region_size);
678 void devlink_region_destroy(struct devlink_region *region);
679 u32 devlink_region_shapshot_id_get(struct devlink *devlink);
680 int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
681 				   u8 *data, u32 snapshot_id,
682 				   devlink_snapshot_data_dest_t *data_destructor);
683 int devlink_info_serial_number_put(struct devlink_info_req *req,
684 				   const char *sn);
685 int devlink_info_driver_name_put(struct devlink_info_req *req,
686 				 const char *name);
687 int devlink_info_version_fixed_put(struct devlink_info_req *req,
688 				   const char *version_name,
689 				   const char *version_value);
690 int devlink_info_version_stored_put(struct devlink_info_req *req,
691 				    const char *version_name,
692 				    const char *version_value);
693 int devlink_info_version_running_put(struct devlink_info_req *req,
694 				     const char *version_name,
695 				     const char *version_value);
696 
697 int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
698 int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
699 
700 int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
701 int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
702 
703 int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
704 				     const char *name);
705 int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
706 
707 int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
708 int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
709 int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
710 int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
711 int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
712 int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
713 			    u16 value_len);
714 
715 int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
716 			       bool value);
717 int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
718 			     u8 value);
719 int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
720 			      u32 value);
721 int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
722 			      u64 value);
723 int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
724 				 const char *value);
725 int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
726 				 const void *value, u16 value_len);
727 
728 struct devlink_health_reporter *
729 devlink_health_reporter_create(struct devlink *devlink,
730 			       const struct devlink_health_reporter_ops *ops,
731 			       u64 graceful_period, bool auto_recover,
732 			       void *priv);
733 void
734 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
735 
736 void *
737 devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
738 int devlink_health_report(struct devlink_health_reporter *reporter,
739 			  const char *msg, void *priv_ctx);
740 void
741 devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
742 				     enum devlink_health_reporter_state state);
743 
744 #if IS_ENABLED(CONFIG_NET_DEVLINK)
745 
746 void devlink_compat_running_version(struct net_device *dev,
747 				    char *buf, size_t len);
748 int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
749 int devlink_compat_phys_port_name_get(struct net_device *dev,
750 				      char *name, size_t len);
751 int devlink_compat_switch_id_get(struct net_device *dev,
752 				 struct netdev_phys_item_id *ppid);
753 
754 #else
755 
756 static inline void
757 devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
758 {
759 }
760 
761 static inline int
762 devlink_compat_flash_update(struct net_device *dev, const char *file_name)
763 {
764 	return -EOPNOTSUPP;
765 }
766 
767 static inline int
768 devlink_compat_phys_port_name_get(struct net_device *dev,
769 				  char *name, size_t len)
770 {
771 	return -EOPNOTSUPP;
772 }
773 
774 static inline int
775 devlink_compat_switch_id_get(struct net_device *dev,
776 			     struct netdev_phys_item_id *ppid)
777 {
778 	return -EOPNOTSUPP;
779 }
780 
781 #endif
782 
783 #endif /* _NET_DEVLINK_H_ */
784