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