xref: /linux/include/net/devlink.h (revision 3b165c2a29cfb6453f26e1ac833ca6afd28d28cf)
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 <linux/refcount.h>
18 #include <net/net_namespace.h>
19 #include <net/flow_offload.h>
20 #include <uapi/linux/devlink.h>
21 #include <linux/xarray.h>
22 #include <linux/firmware.h>
23 
24 struct devlink;
25 struct devlink_linecard;
26 
27 struct devlink_port_phys_attrs {
28 	u32 port_number; /* Same value as "split group".
29 			  * A physical port which is visible to the user
30 			  * for a given port flavour.
31 			  */
32 	u32 split_subport_number; /* If the port is split, this is the number of subport. */
33 };
34 
35 /**
36  * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes
37  * @controller: Associated controller number
38  * @pf: associated PCI function number for the devlink port instance
39  * @external: when set, indicates if a port is for an external controller
40  */
41 struct devlink_port_pci_pf_attrs {
42 	u32 controller;
43 	u16 pf;
44 	u8 external:1;
45 };
46 
47 /**
48  * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes
49  * @controller: Associated controller number
50  * @pf: associated PCI function number for the devlink port instance
51  * @vf: associated PCI VF number of a PF for the devlink port instance;
52  *	VF number starts from 0 for the first PCI virtual function
53  * @external: when set, indicates if a port is for an external controller
54  */
55 struct devlink_port_pci_vf_attrs {
56 	u32 controller;
57 	u16 pf;
58 	u16 vf;
59 	u8 external:1;
60 };
61 
62 /**
63  * struct devlink_port_pci_sf_attrs - devlink port's PCI SF attributes
64  * @controller: Associated controller number
65  * @sf: associated SF number of a PF for the devlink port instance
66  * @pf: associated PCI function number for the devlink port instance
67  * @external: when set, indicates if a port is for an external controller
68  */
69 struct devlink_port_pci_sf_attrs {
70 	u32 controller;
71 	u32 sf;
72 	u16 pf;
73 	u8 external:1;
74 };
75 
76 /**
77  * struct devlink_port_attrs - devlink port object
78  * @flavour: flavour of the port
79  * @split: indicates if this is split port
80  * @splittable: indicates if the port can be split.
81  * @no_phys_port_name: skip automatic phys_port_name generation; for
82  *		       compatibility only, newly added driver/port instance
83  *		       should never set this.
84  * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink.
85  * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL
86  * @phys: physical port attributes
87  * @pci_pf: PCI PF port attributes
88  * @pci_vf: PCI VF port attributes
89  * @pci_sf: PCI SF port attributes
90  */
91 struct devlink_port_attrs {
92 	u8 split:1,
93 	   splittable:1,
94 	   no_phys_port_name:1;
95 	u32 lanes;
96 	enum devlink_port_flavour flavour;
97 	struct netdev_phys_item_id switch_id;
98 	union {
99 		struct devlink_port_phys_attrs phys;
100 		struct devlink_port_pci_pf_attrs pci_pf;
101 		struct devlink_port_pci_vf_attrs pci_vf;
102 		struct devlink_port_pci_sf_attrs pci_sf;
103 	};
104 };
105 
106 struct devlink_rate {
107 	struct list_head list;
108 	enum devlink_rate_type type;
109 	struct devlink *devlink;
110 	void *priv;
111 	u64 tx_share;
112 	u64 tx_max;
113 
114 	struct devlink_rate *parent;
115 	union {
116 		struct devlink_port *devlink_port;
117 		struct {
118 			char *name;
119 			refcount_t refcnt;
120 		};
121 	};
122 
123 	u32 tx_priority;
124 	u32 tx_weight;
125 
126 	u32 tc_bw[DEVLINK_RATE_TCS_MAX];
127 };
128 
129 struct devlink_port {
130 	struct list_head list;
131 	struct list_head region_list;
132 	struct list_head resource_list;
133 	struct devlink *devlink;
134 	const struct devlink_port_ops *ops;
135 	unsigned int index;
136 	spinlock_t type_lock; /* Protects type and type_eth/ib
137 			       * structures consistency.
138 			       */
139 	enum devlink_port_type type;
140 	enum devlink_port_type desired_type;
141 	union {
142 		struct {
143 			struct net_device *netdev;
144 			int ifindex;
145 			char ifname[IFNAMSIZ];
146 		} type_eth;
147 		struct {
148 			struct ib_device *ibdev;
149 		} type_ib;
150 	};
151 	struct devlink_port_attrs attrs;
152 	u8 attrs_set:1,
153 	   switch_port:1,
154 	   registered:1,
155 	   initialized:1;
156 	struct delayed_work type_warn_dw;
157 	struct list_head reporter_list;
158 
159 	struct devlink_rate *devlink_rate;
160 	struct devlink_linecard *linecard;
161 	u32 rel_index;
162 };
163 
164 struct devlink_port_new_attrs {
165 	enum devlink_port_flavour flavour;
166 	unsigned int port_index;
167 	u32 controller;
168 	u32 sfnum;
169 	u16 pfnum;
170 	u8 port_index_valid:1,
171 	   controller_valid:1,
172 	   sfnum_valid:1;
173 };
174 
175 /**
176  * struct devlink_linecard_ops - Linecard operations
177  * @provision: callback to provision the linecard slot with certain
178  *	       type of linecard. As a result of this operation,
179  *	       driver is expected to eventually (could be after
180  *	       the function call returns) call one of:
181  *	       devlink_linecard_provision_set()
182  *	       devlink_linecard_provision_fail()
183  * @unprovision: callback to unprovision the linecard slot. As a result
184  *		 of this operation, driver is expected to eventually
185  *		 (could be after the function call returns) call
186  *	         devlink_linecard_provision_clear()
187  *	         devlink_linecard_provision_fail()
188  * @same_provision: callback to ask the driver if linecard is already
189  *                  provisioned in the same way user asks this linecard to be
190  *                  provisioned.
191  * @types_count: callback to get number of supported types
192  * @types_get: callback to get next type in list
193  */
194 struct devlink_linecard_ops {
195 	int (*provision)(struct devlink_linecard *linecard, void *priv,
196 			 const char *type, const void *type_priv,
197 			 struct netlink_ext_ack *extack);
198 	int (*unprovision)(struct devlink_linecard *linecard, void *priv,
199 			   struct netlink_ext_ack *extack);
200 	bool (*same_provision)(struct devlink_linecard *linecard, void *priv,
201 			       const char *type, const void *type_priv);
202 	unsigned int (*types_count)(struct devlink_linecard *linecard,
203 				    void *priv);
204 	void (*types_get)(struct devlink_linecard *linecard,
205 			  void *priv, unsigned int index, const char **type,
206 			  const void **type_priv);
207 };
208 
209 struct devlink_sb_pool_info {
210 	enum devlink_sb_pool_type pool_type;
211 	u32 size;
212 	enum devlink_sb_threshold_type threshold_type;
213 	u32 cell_size;
214 };
215 
216 /**
217  * struct devlink_dpipe_field - dpipe field object
218  * @name: field name
219  * @id: index inside the headers field array
220  * @bitwidth: bitwidth
221  * @mapping_type: mapping type
222  */
223 struct devlink_dpipe_field {
224 	const char *name;
225 	unsigned int id;
226 	unsigned int bitwidth;
227 	enum devlink_dpipe_field_mapping_type mapping_type;
228 };
229 
230 /**
231  * struct devlink_dpipe_header - dpipe header object
232  * @name: header name
233  * @id: index, global/local determined by global bit
234  * @fields: fields
235  * @fields_count: number of fields
236  * @global: indicates if header is shared like most protocol header
237  *	    or driver specific
238  */
239 struct devlink_dpipe_header {
240 	const char *name;
241 	unsigned int id;
242 	struct devlink_dpipe_field *fields;
243 	unsigned int fields_count;
244 	bool global;
245 };
246 
247 /**
248  * struct devlink_dpipe_match - represents match operation
249  * @type: type of match
250  * @header_index: header index (packets can have several headers of same
251  *		  type like in case of tunnels)
252  * @header: header
253  * @field_id: field index
254  */
255 struct devlink_dpipe_match {
256 	enum devlink_dpipe_match_type type;
257 	unsigned int header_index;
258 	struct devlink_dpipe_header *header;
259 	unsigned int field_id;
260 };
261 
262 /**
263  * struct devlink_dpipe_action - represents action operation
264  * @type: type of action
265  * @header_index: header index (packets can have several headers of same
266  *		  type like in case of tunnels)
267  * @header: header
268  * @field_id: field index
269  */
270 struct devlink_dpipe_action {
271 	enum devlink_dpipe_action_type type;
272 	unsigned int header_index;
273 	struct devlink_dpipe_header *header;
274 	unsigned int field_id;
275 };
276 
277 /**
278  * struct devlink_dpipe_value - represents value of match/action
279  * @action: action
280  * @match: match
281  * @mapping_value: in case the field has some mapping this value
282  *                 specified the mapping value
283  * @mapping_valid: specify if mapping value is valid
284  * @value_size: value size
285  * @value: value
286  * @mask: bit mask
287  */
288 struct devlink_dpipe_value {
289 	union {
290 		struct devlink_dpipe_action *action;
291 		struct devlink_dpipe_match *match;
292 	};
293 	unsigned int mapping_value;
294 	bool mapping_valid;
295 	unsigned int value_size;
296 	void *value;
297 	void *mask;
298 };
299 
300 /**
301  * struct devlink_dpipe_entry - table entry object
302  * @index: index of the entry in the table
303  * @match_values: match values
304  * @match_values_count: count of matches tuples
305  * @action_values: actions values
306  * @action_values_count: count of actions values
307  * @counter: value of counter
308  * @counter_valid: Specify if value is valid from hardware
309  */
310 struct devlink_dpipe_entry {
311 	u64 index;
312 	struct devlink_dpipe_value *match_values;
313 	unsigned int match_values_count;
314 	struct devlink_dpipe_value *action_values;
315 	unsigned int action_values_count;
316 	u64 counter;
317 	bool counter_valid;
318 };
319 
320 /**
321  * struct devlink_dpipe_dump_ctx - context provided to driver in order
322  *				   to dump
323  * @info: info
324  * @cmd: devlink command
325  * @skb: skb
326  * @nest: top attribute
327  * @hdr: hdr
328  */
329 struct devlink_dpipe_dump_ctx {
330 	struct genl_info *info;
331 	enum devlink_command cmd;
332 	struct sk_buff *skb;
333 	struct nlattr *nest;
334 	void *hdr;
335 };
336 
337 struct devlink_dpipe_table_ops;
338 
339 /**
340  * struct devlink_dpipe_table - table object
341  * @priv: private
342  * @name: table name
343  * @counters_enabled: indicates if counters are active
344  * @counter_control_extern: indicates if counter control is in dpipe or
345  *			    external tool
346  * @resource_valid: Indicate that the resource id is valid
347  * @resource_id: relative resource this table is related to
348  * @resource_units: number of resource's unit consumed per table's entry
349  * @table_ops: table operations
350  * @rcu: rcu
351  */
352 struct devlink_dpipe_table {
353 	void *priv;
354 	/* private: */
355 	struct list_head list;
356 	/* public: */
357 	const char *name;
358 	bool counters_enabled;
359 	bool counter_control_extern;
360 	bool resource_valid;
361 	u64 resource_id;
362 	u64 resource_units;
363 	const struct devlink_dpipe_table_ops *table_ops;
364 	struct rcu_head rcu;
365 };
366 
367 /**
368  * struct devlink_dpipe_table_ops - dpipe_table ops
369  * @actions_dump: dumps all tables actions
370  * @matches_dump: dumps all tables matches
371  * @entries_dump: dumps all active entries in the table
372  * @counters_set_update:  when changing the counter status hardware sync
373  *			  maybe needed to allocate/free counter related
374  *			  resources
375  * @size_get: get size
376  */
377 struct devlink_dpipe_table_ops {
378 	int (*actions_dump)(void *priv, struct sk_buff *skb);
379 	int (*matches_dump)(void *priv, struct sk_buff *skb);
380 	int (*entries_dump)(void *priv, bool counters_enabled,
381 			    struct devlink_dpipe_dump_ctx *dump_ctx);
382 	int (*counters_set_update)(void *priv, bool enable);
383 	u64 (*size_get)(void *priv);
384 };
385 
386 /**
387  * struct devlink_dpipe_headers - dpipe headers
388  * @headers: header array can be shared (global bit) or driver specific
389  * @headers_count: count of headers
390  */
391 struct devlink_dpipe_headers {
392 	struct devlink_dpipe_header **headers;
393 	unsigned int headers_count;
394 };
395 
396 /**
397  * struct devlink_resource_size_params - resource's size parameters
398  * @size_min: minimum size which can be set
399  * @size_max: maximum size which can be set
400  * @size_granularity: size granularity
401  * @unit: resource's basic unit
402  */
403 struct devlink_resource_size_params {
404 	u64 size_min;
405 	u64 size_max;
406 	u64 size_granularity;
407 	enum devlink_resource_unit unit;
408 };
409 
410 static inline void
411 devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
412 				  u64 size_min, u64 size_max,
413 				  u64 size_granularity,
414 				  enum devlink_resource_unit unit)
415 {
416 	size_params->size_min = size_min;
417 	size_params->size_max = size_max;
418 	size_params->size_granularity = size_granularity;
419 	size_params->unit = unit;
420 }
421 
422 typedef u64 devlink_resource_occ_get_t(void *priv);
423 
424 #define DEVLINK_RESOURCE_ID_PARENT_TOP 0
425 
426 #define DEVLINK_RESOURCE_GENERIC_NAME_PORTS "physical_ports"
427 
428 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32
429 enum devlink_param_type {
430 	DEVLINK_PARAM_TYPE_U8 = DEVLINK_VAR_ATTR_TYPE_U8,
431 	DEVLINK_PARAM_TYPE_U16 = DEVLINK_VAR_ATTR_TYPE_U16,
432 	DEVLINK_PARAM_TYPE_U32 = DEVLINK_VAR_ATTR_TYPE_U32,
433 	DEVLINK_PARAM_TYPE_U64 = DEVLINK_VAR_ATTR_TYPE_U64,
434 	DEVLINK_PARAM_TYPE_STRING = DEVLINK_VAR_ATTR_TYPE_STRING,
435 	DEVLINK_PARAM_TYPE_BOOL = DEVLINK_VAR_ATTR_TYPE_FLAG,
436 	DEVLINK_PARAM_TYPE_U64_ARRAY = DEVLINK_VAR_ATTR_TYPE_U64_ARRAY,
437 };
438 
439 #define __DEVLINK_PARAM_MAX_ARRAY_SIZE 32
440 struct devlink_param_u64_array {
441 	u64 size;
442 	u64 val[__DEVLINK_PARAM_MAX_ARRAY_SIZE];
443 };
444 
445 union devlink_param_value {
446 	u8 vu8;
447 	u16 vu16;
448 	u32 vu32;
449 	u64 vu64;
450 	char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
451 	bool vbool;
452 	struct devlink_param_u64_array u64arr;
453 };
454 
455 struct devlink_param_gset_ctx {
456 	union devlink_param_value val;
457 	enum devlink_param_cmode cmode;
458 };
459 
460 /**
461  * struct devlink_flash_notify - devlink dev flash notify data
462  * @status_msg: current status string
463  * @component: firmware component being updated
464  * @done: amount of work completed of total amount
465  * @total: amount of work expected to be done
466  * @timeout: expected max timeout in seconds
467  *
468  * These are values to be given to userland to be displayed in order
469  * to show current activity in a firmware update process.
470  */
471 struct devlink_flash_notify {
472 	const char *status_msg;
473 	const char *component;
474 	unsigned long done;
475 	unsigned long total;
476 	unsigned long timeout;
477 };
478 
479 /**
480  * struct devlink_param - devlink configuration parameter data
481  * @id: devlink parameter id number
482  * @name: name of the parameter
483  * @generic: indicates if the parameter is generic or driver specific
484  * @type: parameter type
485  * @supported_cmodes: bitmap of supported configuration modes
486  * @get: get parameter value, used for runtime and permanent
487  *       configuration modes
488  * @set: set parameter value, used for runtime and permanent
489  *       configuration modes
490  * @validate: validate input value is applicable (within value range, etc.)
491  * @get_default: get parameter default value, used for runtime and permanent
492  *               configuration modes
493  * @reset_default: reset parameter to default value, used for runtime and permanent
494  *                 configuration modes
495  *
496  * This struct should be used by the driver to fill the data for
497  * a parameter it registers.
498  */
499 struct devlink_param {
500 	u32 id;
501 	const char *name;
502 	bool generic;
503 	enum devlink_param_type type;
504 	unsigned long supported_cmodes;
505 	int (*get)(struct devlink *devlink, u32 id,
506 		   struct devlink_param_gset_ctx *ctx,
507 		   struct netlink_ext_ack *extack);
508 	int (*set)(struct devlink *devlink, u32 id,
509 		   struct devlink_param_gset_ctx *ctx,
510 		   struct netlink_ext_ack *extack);
511 	int (*validate)(struct devlink *devlink, u32 id,
512 			union devlink_param_value *val,
513 			struct netlink_ext_ack *extack);
514 	int (*get_default)(struct devlink *devlink, u32 id,
515 			   struct devlink_param_gset_ctx *ctx,
516 			   struct netlink_ext_ack *extack);
517 	int (*reset_default)(struct devlink *devlink, u32 id,
518 			     enum devlink_param_cmode cmode,
519 			     struct netlink_ext_ack *extack);
520 };
521 
522 struct devlink_param_item {
523 	struct list_head list;
524 	const struct devlink_param *param;
525 	union devlink_param_value driverinit_value;
526 	bool driverinit_value_valid;
527 	union devlink_param_value driverinit_value_new; /* Not reachable
528 							 * until reload.
529 							 */
530 	bool driverinit_value_new_valid;
531 	union devlink_param_value driverinit_default;
532 };
533 
534 enum devlink_param_generic_id {
535 	DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
536 	DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
537 	DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
538 	DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
539 	DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
540 	DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
541 	DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
542 	DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
543 	DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
544 	DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
545 	DEVLINK_PARAM_GENERIC_ID_ENABLE_REMOTE_DEV_RESET,
546 	DEVLINK_PARAM_GENERIC_ID_ENABLE_ETH,
547 	DEVLINK_PARAM_GENERIC_ID_ENABLE_RDMA,
548 	DEVLINK_PARAM_GENERIC_ID_ENABLE_VNET,
549 	DEVLINK_PARAM_GENERIC_ID_ENABLE_IWARP,
550 	DEVLINK_PARAM_GENERIC_ID_IO_EQ_SIZE,
551 	DEVLINK_PARAM_GENERIC_ID_EVENT_EQ_SIZE,
552 	DEVLINK_PARAM_GENERIC_ID_ENABLE_PHC,
553 	DEVLINK_PARAM_GENERIC_ID_CLOCK_ID,
554 	DEVLINK_PARAM_GENERIC_ID_TOTAL_VFS,
555 	DEVLINK_PARAM_GENERIC_ID_NUM_DOORBELLS,
556 	DEVLINK_PARAM_GENERIC_ID_MAX_MAC_PER_VF,
557 
558 	/* add new param generic ids above here*/
559 	__DEVLINK_PARAM_GENERIC_ID_MAX,
560 	DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
561 };
562 
563 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
564 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
565 
566 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
567 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
568 
569 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
570 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
571 
572 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
573 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
574 
575 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
576 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
577 
578 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
579 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
580 
581 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
582 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
583 
584 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
585 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
586 
587 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
588 	"reset_dev_on_drv_probe"
589 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
590 
591 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
592 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
593 
594 #define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_NAME "enable_remote_dev_reset"
595 #define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
596 
597 #define DEVLINK_PARAM_GENERIC_ENABLE_ETH_NAME "enable_eth"
598 #define DEVLINK_PARAM_GENERIC_ENABLE_ETH_TYPE DEVLINK_PARAM_TYPE_BOOL
599 
600 #define DEVLINK_PARAM_GENERIC_ENABLE_RDMA_NAME "enable_rdma"
601 #define DEVLINK_PARAM_GENERIC_ENABLE_RDMA_TYPE DEVLINK_PARAM_TYPE_BOOL
602 
603 #define DEVLINK_PARAM_GENERIC_ENABLE_VNET_NAME "enable_vnet"
604 #define DEVLINK_PARAM_GENERIC_ENABLE_VNET_TYPE DEVLINK_PARAM_TYPE_BOOL
605 
606 #define DEVLINK_PARAM_GENERIC_ENABLE_IWARP_NAME "enable_iwarp"
607 #define DEVLINK_PARAM_GENERIC_ENABLE_IWARP_TYPE DEVLINK_PARAM_TYPE_BOOL
608 
609 #define DEVLINK_PARAM_GENERIC_IO_EQ_SIZE_NAME "io_eq_size"
610 #define DEVLINK_PARAM_GENERIC_IO_EQ_SIZE_TYPE DEVLINK_PARAM_TYPE_U32
611 
612 #define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_NAME "event_eq_size"
613 #define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_TYPE DEVLINK_PARAM_TYPE_U32
614 
615 #define DEVLINK_PARAM_GENERIC_ENABLE_PHC_NAME "enable_phc"
616 #define DEVLINK_PARAM_GENERIC_ENABLE_PHC_TYPE DEVLINK_PARAM_TYPE_BOOL
617 
618 #define DEVLINK_PARAM_GENERIC_CLOCK_ID_NAME "clock_id"
619 #define DEVLINK_PARAM_GENERIC_CLOCK_ID_TYPE DEVLINK_PARAM_TYPE_U64
620 
621 #define DEVLINK_PARAM_GENERIC_TOTAL_VFS_NAME "total_vfs"
622 #define DEVLINK_PARAM_GENERIC_TOTAL_VFS_TYPE DEVLINK_PARAM_TYPE_U32
623 
624 #define DEVLINK_PARAM_GENERIC_NUM_DOORBELLS_NAME "num_doorbells"
625 #define DEVLINK_PARAM_GENERIC_NUM_DOORBELLS_TYPE DEVLINK_PARAM_TYPE_U32
626 
627 #define DEVLINK_PARAM_GENERIC_MAX_MAC_PER_VF_NAME "max_mac_per_vf"
628 #define DEVLINK_PARAM_GENERIC_MAX_MAC_PER_VF_TYPE DEVLINK_PARAM_TYPE_U32
629 
630 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate)	\
631 {									\
632 	.id = DEVLINK_PARAM_GENERIC_ID_##_id,				\
633 	.name = DEVLINK_PARAM_GENERIC_##_id##_NAME,			\
634 	.type = DEVLINK_PARAM_GENERIC_##_id##_TYPE,			\
635 	.generic = true,						\
636 	.supported_cmodes = _cmodes,					\
637 	.get = _get,							\
638 	.set = _set,							\
639 	.validate = _validate,						\
640 }
641 
642 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate)	\
643 {									\
644 	.id = _id,							\
645 	.name = _name,							\
646 	.type = _type,							\
647 	.supported_cmodes = _cmodes,					\
648 	.get = _get,							\
649 	.set = _set,							\
650 	.validate = _validate,						\
651 }
652 
653 #define DEVLINK_PARAM_GENERIC_WITH_DEFAULTS(_id, _cmodes, _get, _set,	      \
654 					    _validate, _get_default,	      \
655 					    _reset_default)		      \
656 {									      \
657 	.id = DEVLINK_PARAM_GENERIC_ID_##_id,				      \
658 	.name = DEVLINK_PARAM_GENERIC_##_id##_NAME,			      \
659 	.type = DEVLINK_PARAM_GENERIC_##_id##_TYPE,			      \
660 	.generic = true,						      \
661 	.supported_cmodes = _cmodes,					      \
662 	.get = _get,							      \
663 	.set = _set,							      \
664 	.validate = _validate,						      \
665 	.get_default = _get_default,					      \
666 	.reset_default = _reset_default,				      \
667 }
668 
669 #define DEVLINK_PARAM_DRIVER_WITH_DEFAULTS(_id, _name, _type, _cmodes,	      \
670 					   _get, _set, _validate,	      \
671 					   _get_default, _reset_default)      \
672 {									      \
673 	.id = _id,							      \
674 	.name = _name,							      \
675 	.type = _type,							      \
676 	.supported_cmodes = _cmodes,					      \
677 	.get = _get,							      \
678 	.set = _set,							      \
679 	.validate = _validate,						      \
680 	.get_default = _get_default,					      \
681 	.reset_default = _reset_default,				      \
682 }
683 
684 /* Identifier of board design */
685 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID	"board.id"
686 /* Revision of board design */
687 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV	"board.rev"
688 /* Maker of the board */
689 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE	"board.manufacture"
690 /* Part number of the board and its components */
691 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_PART_NUMBER	"board.part_number"
692 
693 /* Part number, identifier of asic design */
694 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID	"asic.id"
695 /* Revision of asic design */
696 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV	"asic.rev"
697 
698 /* Overall FW version */
699 #define DEVLINK_INFO_VERSION_GENERIC_FW		"fw"
700 /* Control processor FW version */
701 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT	"fw.mgmt"
702 /* FW interface specification version */
703 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API	"fw.mgmt.api"
704 /* Data path microcode controlling high-speed packet processing */
705 #define DEVLINK_INFO_VERSION_GENERIC_FW_APP	"fw.app"
706 /* UNDI software version */
707 #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI	"fw.undi"
708 /* NCSI support/handler version */
709 #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI	"fw.ncsi"
710 /* FW parameter set id */
711 #define DEVLINK_INFO_VERSION_GENERIC_FW_PSID	"fw.psid"
712 /* RoCE FW version */
713 #define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE	"fw.roce"
714 /* Firmware bundle identifier */
715 #define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID	"fw.bundle_id"
716 /* Bootloader */
717 #define DEVLINK_INFO_VERSION_GENERIC_FW_BOOTLOADER	"fw.bootloader"
718 
719 /**
720  * struct devlink_flash_update_params - Flash Update parameters
721  * @fw: pointer to the firmware data to update from
722  * @component: the flash component to update
723  * @overwrite_mask: which types of flash update are supported (may be %0)
724  *
725  * With the exception of fw, drivers must opt-in to parameters by
726  * setting the appropriate bit in the supported_flash_update_params field in
727  * their devlink_ops structure.
728  */
729 struct devlink_flash_update_params {
730 	const struct firmware *fw;
731 	const char *component;
732 	u32 overwrite_mask;
733 };
734 
735 #define DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK	BIT(0)
736 
737 struct devlink_region;
738 struct devlink_info_req;
739 
740 /**
741  * struct devlink_region_ops - Region operations
742  * @name: region name
743  * @destructor: callback used to free snapshot memory when deleting
744  * @snapshot: callback to request an immediate snapshot. On success,
745  *            the data variable must be updated to point to the snapshot data.
746  *            The function will be called while the devlink instance lock is
747  *            held.
748  * @read: callback to directly read a portion of the region. On success,
749  *        the data pointer will be updated with the contents of the
750  *        requested portion of the region. The function will be called
751  *        while the devlink instance lock is held.
752  * @priv: Pointer to driver private data for the region operation
753  */
754 struct devlink_region_ops {
755 	const char *name;
756 	void (*destructor)(const void *data);
757 	int (*snapshot)(struct devlink *devlink,
758 			const struct devlink_region_ops *ops,
759 			struct netlink_ext_ack *extack,
760 			u8 **data);
761 	int (*read)(struct devlink *devlink,
762 		    const struct devlink_region_ops *ops,
763 		    struct netlink_ext_ack *extack,
764 		    u64 offset, u32 size, u8 *data);
765 	void *priv;
766 };
767 
768 /**
769  * struct devlink_port_region_ops - Region operations for a port
770  * @name: region name
771  * @destructor: callback used to free snapshot memory when deleting
772  * @snapshot: callback to request an immediate snapshot. On success,
773  *            the data variable must be updated to point to the snapshot data.
774  *            The function will be called while the devlink instance lock is
775  *            held.
776  * @read: callback to directly read a portion of the region. On success,
777  *        the data pointer will be updated with the contents of the
778  *        requested portion of the region. The function will be called
779  *        while the devlink instance lock is held.
780  * @priv: Pointer to driver private data for the region operation
781  */
782 struct devlink_port_region_ops {
783 	const char *name;
784 	void (*destructor)(const void *data);
785 	int (*snapshot)(struct devlink_port *port,
786 			const struct devlink_port_region_ops *ops,
787 			struct netlink_ext_ack *extack,
788 			u8 **data);
789 	int (*read)(struct devlink_port *port,
790 		    const struct devlink_port_region_ops *ops,
791 		    struct netlink_ext_ack *extack,
792 		    u64 offset, u32 size, u8 *data);
793 	void *priv;
794 };
795 
796 struct devlink_fmsg;
797 struct devlink_health_reporter;
798 
799 enum devlink_health_reporter_state {
800 	DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
801 	DEVLINK_HEALTH_REPORTER_STATE_ERROR,
802 };
803 
804 /**
805  * struct devlink_health_reporter_ops - Reporter operations
806  * @name: reporter name
807  * @recover: callback to recover from reported error
808  *           if priv_ctx is NULL, run a full recover
809  * @dump: callback to dump an object
810  *        if priv_ctx is NULL, run a full dump
811  * @diagnose: callback to diagnose the current status
812  * @test: callback to trigger a test event
813  * @default_graceful_period: default min time (in msec)
814  *	between recovery attempts
815  * @default_burst_period: default time (in msec) for
816  *	error recoveries before starting the grace period
817  */
818 
819 struct devlink_health_reporter_ops {
820 	char *name;
821 	int (*recover)(struct devlink_health_reporter *reporter,
822 		       void *priv_ctx, struct netlink_ext_ack *extack);
823 	int (*dump)(struct devlink_health_reporter *reporter,
824 		    struct devlink_fmsg *fmsg, void *priv_ctx,
825 		    struct netlink_ext_ack *extack);
826 	int (*diagnose)(struct devlink_health_reporter *reporter,
827 			struct devlink_fmsg *fmsg,
828 			struct netlink_ext_ack *extack);
829 	int (*test)(struct devlink_health_reporter *reporter,
830 		    struct netlink_ext_ack *extack);
831 	u64 default_graceful_period;
832 	u64 default_burst_period;
833 };
834 
835 /**
836  * struct devlink_trap_metadata - Packet trap metadata.
837  * @trap_name: Trap name.
838  * @trap_group_name: Trap group name.
839  * @input_dev: Input netdevice.
840  * @dev_tracker: refcount tracker for @input_dev.
841  * @fa_cookie: Flow action user cookie.
842  * @trap_type: Trap type.
843  */
844 struct devlink_trap_metadata {
845 	const char *trap_name;
846 	const char *trap_group_name;
847 
848 	struct net_device *input_dev;
849 	netdevice_tracker dev_tracker;
850 
851 	const struct flow_action_cookie *fa_cookie;
852 	enum devlink_trap_type trap_type;
853 };
854 
855 /**
856  * struct devlink_trap_policer - Immutable packet trap policer attributes.
857  * @id: Policer identifier.
858  * @init_rate: Initial rate in packets / sec.
859  * @init_burst: Initial burst size in packets.
860  * @max_rate: Maximum rate.
861  * @min_rate: Minimum rate.
862  * @max_burst: Maximum burst size.
863  * @min_burst: Minimum burst size.
864  *
865  * Describes immutable attributes of packet trap policers that drivers register
866  * with devlink.
867  */
868 struct devlink_trap_policer {
869 	u32 id;
870 	u64 init_rate;
871 	u64 init_burst;
872 	u64 max_rate;
873 	u64 min_rate;
874 	u64 max_burst;
875 	u64 min_burst;
876 };
877 
878 /**
879  * struct devlink_trap_group - Immutable packet trap group attributes.
880  * @name: Trap group name.
881  * @id: Trap group identifier.
882  * @generic: Whether the trap group is generic or not.
883  * @init_policer_id: Initial policer identifier.
884  *
885  * Describes immutable attributes of packet trap groups that drivers register
886  * with devlink.
887  */
888 struct devlink_trap_group {
889 	const char *name;
890 	u16 id;
891 	bool generic;
892 	u32 init_policer_id;
893 };
894 
895 #define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT	BIT(0)
896 #define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE	BIT(1)
897 
898 /**
899  * struct devlink_trap - Immutable packet trap attributes.
900  * @type: Trap type.
901  * @init_action: Initial trap action.
902  * @generic: Whether the trap is generic or not.
903  * @id: Trap identifier.
904  * @name: Trap name.
905  * @init_group_id: Initial group identifier.
906  * @metadata_cap: Metadata types that can be provided by the trap.
907  *
908  * Describes immutable attributes of packet traps that drivers register with
909  * devlink.
910  */
911 struct devlink_trap {
912 	enum devlink_trap_type type;
913 	enum devlink_trap_action init_action;
914 	bool generic;
915 	u16 id;
916 	const char *name;
917 	u16 init_group_id;
918 	u32 metadata_cap;
919 };
920 
921 /* All traps must be documented in
922  * Documentation/networking/devlink/devlink-trap.rst
923  */
924 enum devlink_trap_generic_id {
925 	DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
926 	DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
927 	DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
928 	DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
929 	DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
930 	DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
931 	DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
932 	DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
933 	DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
934 	DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
935 	DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
936 	DEVLINK_TRAP_GENERIC_ID_DIP_LB,
937 	DEVLINK_TRAP_GENERIC_ID_SIP_MC,
938 	DEVLINK_TRAP_GENERIC_ID_SIP_LB,
939 	DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
940 	DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
941 	DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
942 	DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
943 	DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
944 	DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
945 	DEVLINK_TRAP_GENERIC_ID_RPF,
946 	DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
947 	DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
948 	DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
949 	DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
950 	DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
951 	DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
952 	DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
953 	DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
954 	DEVLINK_TRAP_GENERIC_ID_STP,
955 	DEVLINK_TRAP_GENERIC_ID_LACP,
956 	DEVLINK_TRAP_GENERIC_ID_LLDP,
957 	DEVLINK_TRAP_GENERIC_ID_IGMP_QUERY,
958 	DEVLINK_TRAP_GENERIC_ID_IGMP_V1_REPORT,
959 	DEVLINK_TRAP_GENERIC_ID_IGMP_V2_REPORT,
960 	DEVLINK_TRAP_GENERIC_ID_IGMP_V3_REPORT,
961 	DEVLINK_TRAP_GENERIC_ID_IGMP_V2_LEAVE,
962 	DEVLINK_TRAP_GENERIC_ID_MLD_QUERY,
963 	DEVLINK_TRAP_GENERIC_ID_MLD_V1_REPORT,
964 	DEVLINK_TRAP_GENERIC_ID_MLD_V2_REPORT,
965 	DEVLINK_TRAP_GENERIC_ID_MLD_V1_DONE,
966 	DEVLINK_TRAP_GENERIC_ID_IPV4_DHCP,
967 	DEVLINK_TRAP_GENERIC_ID_IPV6_DHCP,
968 	DEVLINK_TRAP_GENERIC_ID_ARP_REQUEST,
969 	DEVLINK_TRAP_GENERIC_ID_ARP_RESPONSE,
970 	DEVLINK_TRAP_GENERIC_ID_ARP_OVERLAY,
971 	DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_SOLICIT,
972 	DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_ADVERT,
973 	DEVLINK_TRAP_GENERIC_ID_IPV4_BFD,
974 	DEVLINK_TRAP_GENERIC_ID_IPV6_BFD,
975 	DEVLINK_TRAP_GENERIC_ID_IPV4_OSPF,
976 	DEVLINK_TRAP_GENERIC_ID_IPV6_OSPF,
977 	DEVLINK_TRAP_GENERIC_ID_IPV4_BGP,
978 	DEVLINK_TRAP_GENERIC_ID_IPV6_BGP,
979 	DEVLINK_TRAP_GENERIC_ID_IPV4_VRRP,
980 	DEVLINK_TRAP_GENERIC_ID_IPV6_VRRP,
981 	DEVLINK_TRAP_GENERIC_ID_IPV4_PIM,
982 	DEVLINK_TRAP_GENERIC_ID_IPV6_PIM,
983 	DEVLINK_TRAP_GENERIC_ID_UC_LB,
984 	DEVLINK_TRAP_GENERIC_ID_LOCAL_ROUTE,
985 	DEVLINK_TRAP_GENERIC_ID_EXTERNAL_ROUTE,
986 	DEVLINK_TRAP_GENERIC_ID_IPV6_UC_DIP_LINK_LOCAL_SCOPE,
987 	DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_NODES,
988 	DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_ROUTERS,
989 	DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_SOLICIT,
990 	DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ADVERT,
991 	DEVLINK_TRAP_GENERIC_ID_IPV6_REDIRECT,
992 	DEVLINK_TRAP_GENERIC_ID_IPV4_ROUTER_ALERT,
993 	DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ALERT,
994 	DEVLINK_TRAP_GENERIC_ID_PTP_EVENT,
995 	DEVLINK_TRAP_GENERIC_ID_PTP_GENERAL,
996 	DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_SAMPLE,
997 	DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_TRAP,
998 	DEVLINK_TRAP_GENERIC_ID_EARLY_DROP,
999 	DEVLINK_TRAP_GENERIC_ID_VXLAN_PARSING,
1000 	DEVLINK_TRAP_GENERIC_ID_LLC_SNAP_PARSING,
1001 	DEVLINK_TRAP_GENERIC_ID_VLAN_PARSING,
1002 	DEVLINK_TRAP_GENERIC_ID_PPPOE_PPP_PARSING,
1003 	DEVLINK_TRAP_GENERIC_ID_MPLS_PARSING,
1004 	DEVLINK_TRAP_GENERIC_ID_ARP_PARSING,
1005 	DEVLINK_TRAP_GENERIC_ID_IP_1_PARSING,
1006 	DEVLINK_TRAP_GENERIC_ID_IP_N_PARSING,
1007 	DEVLINK_TRAP_GENERIC_ID_GRE_PARSING,
1008 	DEVLINK_TRAP_GENERIC_ID_UDP_PARSING,
1009 	DEVLINK_TRAP_GENERIC_ID_TCP_PARSING,
1010 	DEVLINK_TRAP_GENERIC_ID_IPSEC_PARSING,
1011 	DEVLINK_TRAP_GENERIC_ID_SCTP_PARSING,
1012 	DEVLINK_TRAP_GENERIC_ID_DCCP_PARSING,
1013 	DEVLINK_TRAP_GENERIC_ID_GTP_PARSING,
1014 	DEVLINK_TRAP_GENERIC_ID_ESP_PARSING,
1015 	DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_NEXTHOP,
1016 	DEVLINK_TRAP_GENERIC_ID_DMAC_FILTER,
1017 	DEVLINK_TRAP_GENERIC_ID_EAPOL,
1018 	DEVLINK_TRAP_GENERIC_ID_LOCKED_PORT,
1019 
1020 	/* Add new generic trap IDs above */
1021 	__DEVLINK_TRAP_GENERIC_ID_MAX,
1022 	DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
1023 };
1024 
1025 /* All trap groups must be documented in
1026  * Documentation/networking/devlink/devlink-trap.rst
1027  */
1028 enum devlink_trap_group_generic_id {
1029 	DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
1030 	DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
1031 	DEVLINK_TRAP_GROUP_GENERIC_ID_L3_EXCEPTIONS,
1032 	DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
1033 	DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
1034 	DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
1035 	DEVLINK_TRAP_GROUP_GENERIC_ID_STP,
1036 	DEVLINK_TRAP_GROUP_GENERIC_ID_LACP,
1037 	DEVLINK_TRAP_GROUP_GENERIC_ID_LLDP,
1038 	DEVLINK_TRAP_GROUP_GENERIC_ID_MC_SNOOPING,
1039 	DEVLINK_TRAP_GROUP_GENERIC_ID_DHCP,
1040 	DEVLINK_TRAP_GROUP_GENERIC_ID_NEIGH_DISCOVERY,
1041 	DEVLINK_TRAP_GROUP_GENERIC_ID_BFD,
1042 	DEVLINK_TRAP_GROUP_GENERIC_ID_OSPF,
1043 	DEVLINK_TRAP_GROUP_GENERIC_ID_BGP,
1044 	DEVLINK_TRAP_GROUP_GENERIC_ID_VRRP,
1045 	DEVLINK_TRAP_GROUP_GENERIC_ID_PIM,
1046 	DEVLINK_TRAP_GROUP_GENERIC_ID_UC_LB,
1047 	DEVLINK_TRAP_GROUP_GENERIC_ID_LOCAL_DELIVERY,
1048 	DEVLINK_TRAP_GROUP_GENERIC_ID_EXTERNAL_DELIVERY,
1049 	DEVLINK_TRAP_GROUP_GENERIC_ID_IPV6,
1050 	DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_EVENT,
1051 	DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_GENERAL,
1052 	DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_SAMPLE,
1053 	DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_TRAP,
1054 	DEVLINK_TRAP_GROUP_GENERIC_ID_PARSER_ERROR_DROPS,
1055 	DEVLINK_TRAP_GROUP_GENERIC_ID_EAPOL,
1056 
1057 	/* Add new generic trap group IDs above */
1058 	__DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
1059 	DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
1060 		__DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
1061 };
1062 
1063 #define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
1064 	"source_mac_is_multicast"
1065 #define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
1066 	"vlan_tag_mismatch"
1067 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
1068 	"ingress_vlan_filter"
1069 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
1070 	"ingress_spanning_tree_filter"
1071 #define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
1072 	"port_list_is_empty"
1073 #define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
1074 	"port_loopback_filter"
1075 #define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
1076 	"blackhole_route"
1077 #define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
1078 	"ttl_value_is_too_small"
1079 #define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
1080 	"tail_drop"
1081 #define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
1082 	"non_ip"
1083 #define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
1084 	"uc_dip_over_mc_dmac"
1085 #define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
1086 	"dip_is_loopback_address"
1087 #define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
1088 	"sip_is_mc"
1089 #define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
1090 	"sip_is_loopback_address"
1091 #define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
1092 	"ip_header_corrupted"
1093 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
1094 	"ipv4_sip_is_limited_bc"
1095 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
1096 	"ipv6_mc_dip_reserved_scope"
1097 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
1098 	"ipv6_mc_dip_interface_local_scope"
1099 #define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
1100 	"mtu_value_is_too_small"
1101 #define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
1102 	"unresolved_neigh"
1103 #define DEVLINK_TRAP_GENERIC_NAME_RPF \
1104 	"mc_reverse_path_forwarding"
1105 #define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
1106 	"reject_route"
1107 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
1108 	"ipv4_lpm_miss"
1109 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
1110 	"ipv6_lpm_miss"
1111 #define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
1112 	"non_routable_packet"
1113 #define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
1114 	"decap_error"
1115 #define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
1116 	"overlay_smac_is_mc"
1117 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
1118 	"ingress_flow_action_drop"
1119 #define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
1120 	"egress_flow_action_drop"
1121 #define DEVLINK_TRAP_GENERIC_NAME_STP \
1122 	"stp"
1123 #define DEVLINK_TRAP_GENERIC_NAME_LACP \
1124 	"lacp"
1125 #define DEVLINK_TRAP_GENERIC_NAME_LLDP \
1126 	"lldp"
1127 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_QUERY \
1128 	"igmp_query"
1129 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V1_REPORT \
1130 	"igmp_v1_report"
1131 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_REPORT \
1132 	"igmp_v2_report"
1133 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V3_REPORT \
1134 	"igmp_v3_report"
1135 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_LEAVE \
1136 	"igmp_v2_leave"
1137 #define DEVLINK_TRAP_GENERIC_NAME_MLD_QUERY \
1138 	"mld_query"
1139 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_REPORT \
1140 	"mld_v1_report"
1141 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V2_REPORT \
1142 	"mld_v2_report"
1143 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_DONE \
1144 	"mld_v1_done"
1145 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_DHCP \
1146 	"ipv4_dhcp"
1147 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DHCP \
1148 	"ipv6_dhcp"
1149 #define DEVLINK_TRAP_GENERIC_NAME_ARP_REQUEST \
1150 	"arp_request"
1151 #define DEVLINK_TRAP_GENERIC_NAME_ARP_RESPONSE \
1152 	"arp_response"
1153 #define DEVLINK_TRAP_GENERIC_NAME_ARP_OVERLAY \
1154 	"arp_overlay"
1155 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_SOLICIT \
1156 	"ipv6_neigh_solicit"
1157 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_ADVERT \
1158 	"ipv6_neigh_advert"
1159 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_BFD \
1160 	"ipv4_bfd"
1161 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_BFD \
1162 	"ipv6_bfd"
1163 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_OSPF \
1164 	"ipv4_ospf"
1165 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_OSPF \
1166 	"ipv6_ospf"
1167 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_BGP \
1168 	"ipv4_bgp"
1169 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_BGP \
1170 	"ipv6_bgp"
1171 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_VRRP \
1172 	"ipv4_vrrp"
1173 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_VRRP \
1174 	"ipv6_vrrp"
1175 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_PIM \
1176 	"ipv4_pim"
1177 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_PIM \
1178 	"ipv6_pim"
1179 #define DEVLINK_TRAP_GENERIC_NAME_UC_LB \
1180 	"uc_loopback"
1181 #define DEVLINK_TRAP_GENERIC_NAME_LOCAL_ROUTE \
1182 	"local_route"
1183 #define DEVLINK_TRAP_GENERIC_NAME_EXTERNAL_ROUTE \
1184 	"external_route"
1185 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_UC_DIP_LINK_LOCAL_SCOPE \
1186 	"ipv6_uc_dip_link_local_scope"
1187 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_NODES \
1188 	"ipv6_dip_all_nodes"
1189 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_ROUTERS \
1190 	"ipv6_dip_all_routers"
1191 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_SOLICIT \
1192 	"ipv6_router_solicit"
1193 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ADVERT \
1194 	"ipv6_router_advert"
1195 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_REDIRECT \
1196 	"ipv6_redirect"
1197 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_ROUTER_ALERT \
1198 	"ipv4_router_alert"
1199 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ALERT \
1200 	"ipv6_router_alert"
1201 #define DEVLINK_TRAP_GENERIC_NAME_PTP_EVENT \
1202 	"ptp_event"
1203 #define DEVLINK_TRAP_GENERIC_NAME_PTP_GENERAL \
1204 	"ptp_general"
1205 #define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_SAMPLE \
1206 	"flow_action_sample"
1207 #define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_TRAP \
1208 	"flow_action_trap"
1209 #define DEVLINK_TRAP_GENERIC_NAME_EARLY_DROP \
1210 	"early_drop"
1211 #define DEVLINK_TRAP_GENERIC_NAME_VXLAN_PARSING \
1212 	"vxlan_parsing"
1213 #define DEVLINK_TRAP_GENERIC_NAME_LLC_SNAP_PARSING \
1214 	"llc_snap_parsing"
1215 #define DEVLINK_TRAP_GENERIC_NAME_VLAN_PARSING \
1216 	"vlan_parsing"
1217 #define DEVLINK_TRAP_GENERIC_NAME_PPPOE_PPP_PARSING \
1218 	"pppoe_ppp_parsing"
1219 #define DEVLINK_TRAP_GENERIC_NAME_MPLS_PARSING \
1220 	"mpls_parsing"
1221 #define DEVLINK_TRAP_GENERIC_NAME_ARP_PARSING \
1222 	"arp_parsing"
1223 #define DEVLINK_TRAP_GENERIC_NAME_IP_1_PARSING \
1224 	"ip_1_parsing"
1225 #define DEVLINK_TRAP_GENERIC_NAME_IP_N_PARSING \
1226 	"ip_n_parsing"
1227 #define DEVLINK_TRAP_GENERIC_NAME_GRE_PARSING \
1228 	"gre_parsing"
1229 #define DEVLINK_TRAP_GENERIC_NAME_UDP_PARSING \
1230 	"udp_parsing"
1231 #define DEVLINK_TRAP_GENERIC_NAME_TCP_PARSING \
1232 	"tcp_parsing"
1233 #define DEVLINK_TRAP_GENERIC_NAME_IPSEC_PARSING \
1234 	"ipsec_parsing"
1235 #define DEVLINK_TRAP_GENERIC_NAME_SCTP_PARSING \
1236 	"sctp_parsing"
1237 #define DEVLINK_TRAP_GENERIC_NAME_DCCP_PARSING \
1238 	"dccp_parsing"
1239 #define DEVLINK_TRAP_GENERIC_NAME_GTP_PARSING \
1240 	"gtp_parsing"
1241 #define DEVLINK_TRAP_GENERIC_NAME_ESP_PARSING \
1242 	"esp_parsing"
1243 #define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_NEXTHOP \
1244 	"blackhole_nexthop"
1245 #define DEVLINK_TRAP_GENERIC_NAME_DMAC_FILTER \
1246 	"dmac_filter"
1247 #define DEVLINK_TRAP_GENERIC_NAME_EAPOL \
1248 	"eapol"
1249 #define DEVLINK_TRAP_GENERIC_NAME_LOCKED_PORT \
1250 	"locked_port"
1251 
1252 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
1253 	"l2_drops"
1254 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
1255 	"l3_drops"
1256 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_EXCEPTIONS \
1257 	"l3_exceptions"
1258 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
1259 	"buffer_drops"
1260 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
1261 	"tunnel_drops"
1262 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
1263 	"acl_drops"
1264 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_STP \
1265 	"stp"
1266 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LACP \
1267 	"lacp"
1268 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LLDP \
1269 	"lldp"
1270 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_MC_SNOOPING  \
1271 	"mc_snooping"
1272 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_DHCP \
1273 	"dhcp"
1274 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_NEIGH_DISCOVERY \
1275 	"neigh_discovery"
1276 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BFD \
1277 	"bfd"
1278 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_OSPF \
1279 	"ospf"
1280 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BGP \
1281 	"bgp"
1282 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_VRRP \
1283 	"vrrp"
1284 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PIM \
1285 	"pim"
1286 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_UC_LB \
1287 	"uc_loopback"
1288 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LOCAL_DELIVERY \
1289 	"local_delivery"
1290 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_EXTERNAL_DELIVERY \
1291 	"external_delivery"
1292 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_IPV6 \
1293 	"ipv6"
1294 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_EVENT \
1295 	"ptp_event"
1296 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_GENERAL \
1297 	"ptp_general"
1298 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_SAMPLE \
1299 	"acl_sample"
1300 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_TRAP \
1301 	"acl_trap"
1302 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PARSER_ERROR_DROPS \
1303 	"parser_error_drops"
1304 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_EAPOL \
1305 	"eapol"
1306 
1307 #define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id,	      \
1308 			     _metadata_cap)				      \
1309 	{								      \
1310 		.type = DEVLINK_TRAP_TYPE_##_type,			      \
1311 		.init_action = DEVLINK_TRAP_ACTION_##_init_action,	      \
1312 		.generic = true,					      \
1313 		.id = DEVLINK_TRAP_GENERIC_ID_##_id,			      \
1314 		.name = DEVLINK_TRAP_GENERIC_NAME_##_id,		      \
1315 		.init_group_id = _group_id,				      \
1316 		.metadata_cap = _metadata_cap,				      \
1317 	}
1318 
1319 #define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id,	      \
1320 			    _metadata_cap)				      \
1321 	{								      \
1322 		.type = DEVLINK_TRAP_TYPE_##_type,			      \
1323 		.init_action = DEVLINK_TRAP_ACTION_##_init_action,	      \
1324 		.generic = false,					      \
1325 		.id = _id,						      \
1326 		.name = _name,						      \
1327 		.init_group_id = _group_id,				      \
1328 		.metadata_cap = _metadata_cap,				      \
1329 	}
1330 
1331 #define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id)			      \
1332 	{								      \
1333 		.name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id,		      \
1334 		.id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id,		      \
1335 		.generic = true,					      \
1336 		.init_policer_id = _policer_id,				      \
1337 	}
1338 
1339 #define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate,	      \
1340 			     _max_burst, _min_burst)			      \
1341 	{								      \
1342 		.id = _id,						      \
1343 		.init_rate = _rate,					      \
1344 		.init_burst = _burst,					      \
1345 		.max_rate = _max_rate,					      \
1346 		.min_rate = _min_rate,					      \
1347 		.max_burst = _max_burst,				      \
1348 		.min_burst = _min_burst,				      \
1349 	}
1350 
1351 #define devlink_fmsg_put(fmsg, name, value) (			\
1352 	_Generic((value),					\
1353 		bool :		devlink_fmsg_bool_pair_put,	\
1354 		u8 :		devlink_fmsg_u8_pair_put,	\
1355 		u16 :		devlink_fmsg_u32_pair_put,	\
1356 		u32 :		devlink_fmsg_u32_pair_put,	\
1357 		u64 :		devlink_fmsg_u64_pair_put,	\
1358 		int :		devlink_fmsg_u32_pair_put,	\
1359 		char * :	devlink_fmsg_string_pair_put,	\
1360 		const char * :	devlink_fmsg_string_pair_put)	\
1361 	(fmsg, name, (value)))
1362 
1363 enum {
1364 	/* device supports reload operations */
1365 	DEVLINK_F_RELOAD = 1UL << 0,
1366 };
1367 
1368 struct devlink_ops {
1369 	/**
1370 	 * @supported_flash_update_params:
1371 	 * mask of parameters supported by the driver's .flash_update
1372 	 * implementation.
1373 	 */
1374 	u32 supported_flash_update_params;
1375 	unsigned long reload_actions;
1376 	unsigned long reload_limits;
1377 	int (*reload_down)(struct devlink *devlink, bool netns_change,
1378 			   enum devlink_reload_action action,
1379 			   enum devlink_reload_limit limit,
1380 			   struct netlink_ext_ack *extack);
1381 	int (*reload_up)(struct devlink *devlink, enum devlink_reload_action action,
1382 			 enum devlink_reload_limit limit, u32 *actions_performed,
1383 			 struct netlink_ext_ack *extack);
1384 	int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
1385 			   u16 pool_index,
1386 			   struct devlink_sb_pool_info *pool_info);
1387 	int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
1388 			   u16 pool_index, u32 size,
1389 			   enum devlink_sb_threshold_type threshold_type,
1390 			   struct netlink_ext_ack *extack);
1391 	int (*sb_port_pool_get)(struct devlink_port *devlink_port,
1392 				unsigned int sb_index, u16 pool_index,
1393 				u32 *p_threshold);
1394 	int (*sb_port_pool_set)(struct devlink_port *devlink_port,
1395 				unsigned int sb_index, u16 pool_index,
1396 				u32 threshold, struct netlink_ext_ack *extack);
1397 	int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
1398 				   unsigned int sb_index,
1399 				   u16 tc_index,
1400 				   enum devlink_sb_pool_type pool_type,
1401 				   u16 *p_pool_index, u32 *p_threshold);
1402 	int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
1403 				   unsigned int sb_index,
1404 				   u16 tc_index,
1405 				   enum devlink_sb_pool_type pool_type,
1406 				   u16 pool_index, u32 threshold,
1407 				   struct netlink_ext_ack *extack);
1408 	int (*sb_occ_snapshot)(struct devlink *devlink,
1409 			       unsigned int sb_index);
1410 	int (*sb_occ_max_clear)(struct devlink *devlink,
1411 				unsigned int sb_index);
1412 	int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
1413 				    unsigned int sb_index, u16 pool_index,
1414 				    u32 *p_cur, u32 *p_max);
1415 	int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
1416 				       unsigned int sb_index,
1417 				       u16 tc_index,
1418 				       enum devlink_sb_pool_type pool_type,
1419 				       u32 *p_cur, u32 *p_max);
1420 
1421 	int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
1422 	int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
1423 				struct netlink_ext_ack *extack);
1424 	int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
1425 	int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
1426 				       struct netlink_ext_ack *extack);
1427 	int (*eswitch_encap_mode_get)(struct devlink *devlink,
1428 				      enum devlink_eswitch_encap_mode *p_encap_mode);
1429 	int (*eswitch_encap_mode_set)(struct devlink *devlink,
1430 				      enum devlink_eswitch_encap_mode encap_mode,
1431 				      struct netlink_ext_ack *extack);
1432 	int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
1433 			struct netlink_ext_ack *extack);
1434 	/**
1435 	 * @flash_update: Device flash update function
1436 	 *
1437 	 * Used to perform a flash update for the device. The set of
1438 	 * parameters supported by the driver should be set in
1439 	 * supported_flash_update_params.
1440 	 */
1441 	int (*flash_update)(struct devlink *devlink,
1442 			    struct devlink_flash_update_params *params,
1443 			    struct netlink_ext_ack *extack);
1444 	/**
1445 	 * @trap_init: Trap initialization function.
1446 	 *
1447 	 * Should be used by device drivers to initialize the trap in the
1448 	 * underlying device. Drivers should also store the provided trap
1449 	 * context, so that they could efficiently pass it to
1450 	 * devlink_trap_report() when the trap is triggered.
1451 	 */
1452 	int (*trap_init)(struct devlink *devlink,
1453 			 const struct devlink_trap *trap, void *trap_ctx);
1454 	/**
1455 	 * @trap_fini: Trap de-initialization function.
1456 	 *
1457 	 * Should be used by device drivers to de-initialize the trap in the
1458 	 * underlying device.
1459 	 */
1460 	void (*trap_fini)(struct devlink *devlink,
1461 			  const struct devlink_trap *trap, void *trap_ctx);
1462 	/**
1463 	 * @trap_action_set: Trap action set function.
1464 	 */
1465 	int (*trap_action_set)(struct devlink *devlink,
1466 			       const struct devlink_trap *trap,
1467 			       enum devlink_trap_action action,
1468 			       struct netlink_ext_ack *extack);
1469 	/**
1470 	 * @trap_group_init: Trap group initialization function.
1471 	 *
1472 	 * Should be used by device drivers to initialize the trap group in the
1473 	 * underlying device.
1474 	 */
1475 	int (*trap_group_init)(struct devlink *devlink,
1476 			       const struct devlink_trap_group *group);
1477 	/**
1478 	 * @trap_group_set: Trap group parameters set function.
1479 	 *
1480 	 * Note: @policer can be NULL when a policer is being unbound from
1481 	 * @group.
1482 	 */
1483 	int (*trap_group_set)(struct devlink *devlink,
1484 			      const struct devlink_trap_group *group,
1485 			      const struct devlink_trap_policer *policer,
1486 			      struct netlink_ext_ack *extack);
1487 	/**
1488 	 * @trap_group_action_set: Trap group action set function.
1489 	 *
1490 	 * If this callback is populated, it will take precedence over looping
1491 	 * over all traps in a group and calling .trap_action_set().
1492 	 */
1493 	int (*trap_group_action_set)(struct devlink *devlink,
1494 				     const struct devlink_trap_group *group,
1495 				     enum devlink_trap_action action,
1496 				     struct netlink_ext_ack *extack);
1497 	/**
1498 	 * @trap_drop_counter_get: Trap drop counter get function.
1499 	 *
1500 	 * Should be used by device drivers to report number of packets
1501 	 * that have been dropped, and cannot be passed to the devlink
1502 	 * subsystem by the underlying device.
1503 	 */
1504 	int (*trap_drop_counter_get)(struct devlink *devlink,
1505 				     const struct devlink_trap *trap,
1506 				     u64 *p_drops);
1507 	/**
1508 	 * @trap_policer_init: Trap policer initialization function.
1509 	 *
1510 	 * Should be used by device drivers to initialize the trap policer in
1511 	 * the underlying device.
1512 	 */
1513 	int (*trap_policer_init)(struct devlink *devlink,
1514 				 const struct devlink_trap_policer *policer);
1515 	/**
1516 	 * @trap_policer_fini: Trap policer de-initialization function.
1517 	 *
1518 	 * Should be used by device drivers to de-initialize the trap policer
1519 	 * in the underlying device.
1520 	 */
1521 	void (*trap_policer_fini)(struct devlink *devlink,
1522 				  const struct devlink_trap_policer *policer);
1523 	/**
1524 	 * @trap_policer_set: Trap policer parameters set function.
1525 	 */
1526 	int (*trap_policer_set)(struct devlink *devlink,
1527 				const struct devlink_trap_policer *policer,
1528 				u64 rate, u64 burst,
1529 				struct netlink_ext_ack *extack);
1530 	/**
1531 	 * @trap_policer_counter_get: Trap policer counter get function.
1532 	 *
1533 	 * Should be used by device drivers to report number of packets dropped
1534 	 * by the policer.
1535 	 */
1536 	int (*trap_policer_counter_get)(struct devlink *devlink,
1537 					const struct devlink_trap_policer *policer,
1538 					u64 *p_drops);
1539 	/**
1540 	 * port_new() - Add a new port function of a specified flavor
1541 	 * @devlink: Devlink instance
1542 	 * @attrs: attributes of the new port
1543 	 * @extack: extack for reporting error messages
1544 	 * @devlink_port: pointer to store new devlink port pointer
1545 	 *
1546 	 * Devlink core will call this device driver function upon user request
1547 	 * to create a new port function of a specified flavor and optional
1548 	 * attributes
1549 	 *
1550 	 * Notes:
1551 	 *	- On success, drivers must register a port with devlink core
1552 	 *
1553 	 * Return: 0 on success, negative value otherwise.
1554 	 */
1555 	int (*port_new)(struct devlink *devlink,
1556 			const struct devlink_port_new_attrs *attrs,
1557 			struct netlink_ext_ack *extack,
1558 			struct devlink_port **devlink_port);
1559 
1560 	/**
1561 	 * Rate control callbacks.
1562 	 */
1563 	int (*rate_leaf_tx_share_set)(struct devlink_rate *devlink_rate, void *priv,
1564 				      u64 tx_share, struct netlink_ext_ack *extack);
1565 	int (*rate_leaf_tx_max_set)(struct devlink_rate *devlink_rate, void *priv,
1566 				    u64 tx_max, struct netlink_ext_ack *extack);
1567 	int (*rate_leaf_tx_priority_set)(struct devlink_rate *devlink_rate, void *priv,
1568 					 u32 tx_priority, struct netlink_ext_ack *extack);
1569 	int (*rate_leaf_tx_weight_set)(struct devlink_rate *devlink_rate, void *priv,
1570 				       u32 tx_weight, struct netlink_ext_ack *extack);
1571 	int (*rate_leaf_tc_bw_set)(struct devlink_rate *devlink_rate,
1572 				   void *priv, u32 *tc_bw,
1573 				   struct netlink_ext_ack *extack);
1574 	int (*rate_node_tx_share_set)(struct devlink_rate *devlink_rate, void *priv,
1575 				      u64 tx_share, struct netlink_ext_ack *extack);
1576 	int (*rate_node_tx_max_set)(struct devlink_rate *devlink_rate, void *priv,
1577 				    u64 tx_max, struct netlink_ext_ack *extack);
1578 	int (*rate_node_tx_priority_set)(struct devlink_rate *devlink_rate, void *priv,
1579 					 u32 tx_priority, struct netlink_ext_ack *extack);
1580 	int (*rate_node_tx_weight_set)(struct devlink_rate *devlink_rate, void *priv,
1581 				       u32 tx_weight, struct netlink_ext_ack *extack);
1582 	int (*rate_node_tc_bw_set)(struct devlink_rate *devlink_rate,
1583 				   void *priv, u32 *tc_bw,
1584 				   struct netlink_ext_ack *extack);
1585 	int (*rate_node_new)(struct devlink_rate *rate_node, void **priv,
1586 			     struct netlink_ext_ack *extack);
1587 	int (*rate_node_del)(struct devlink_rate *rate_node, void *priv,
1588 			     struct netlink_ext_ack *extack);
1589 	int (*rate_leaf_parent_set)(struct devlink_rate *child,
1590 				    struct devlink_rate *parent,
1591 				    void *priv_child, void *priv_parent,
1592 				    struct netlink_ext_ack *extack);
1593 	int (*rate_node_parent_set)(struct devlink_rate *child,
1594 				    struct devlink_rate *parent,
1595 				    void *priv_child, void *priv_parent,
1596 				    struct netlink_ext_ack *extack);
1597 	/**
1598 	 * selftests_check() - queries if selftest is supported
1599 	 * @devlink: devlink instance
1600 	 * @id: test index
1601 	 * @extack: extack for reporting error messages
1602 	 *
1603 	 * Return: true if test is supported by the driver
1604 	 */
1605 	bool (*selftest_check)(struct devlink *devlink, unsigned int id,
1606 			       struct netlink_ext_ack *extack);
1607 	/**
1608 	 * selftest_run() - Runs a selftest
1609 	 * @devlink: devlink instance
1610 	 * @id: test index
1611 	 * @extack: extack for reporting error messages
1612 	 *
1613 	 * Return: status of the test
1614 	 */
1615 	enum devlink_selftest_status
1616 	(*selftest_run)(struct devlink *devlink, unsigned int id,
1617 			struct netlink_ext_ack *extack);
1618 };
1619 
1620 void *devlink_priv(struct devlink *devlink);
1621 struct devlink *priv_to_devlink(void *priv);
1622 struct device *devlink_to_dev(const struct devlink *devlink);
1623 const char *devlink_bus_name(const struct devlink *devlink);
1624 const char *devlink_dev_name(const struct devlink *devlink);
1625 const char *devlink_dev_driver_name(const struct devlink *devlink);
1626 
1627 /* Devlink instance explicit locking */
1628 void devl_lock(struct devlink *devlink);
1629 int devl_trylock(struct devlink *devlink);
1630 void devl_unlock(struct devlink *devlink);
1631 void devl_assert_locked(struct devlink *devlink);
1632 bool devl_lock_is_held(struct devlink *devlink);
1633 DEFINE_GUARD(devl, struct devlink *, devl_lock(_T), devl_unlock(_T));
1634 
1635 struct ib_device;
1636 
1637 struct net *devlink_net(const struct devlink *devlink);
1638 /* This call is intended for software devices that can create
1639  * devlink instances in other namespaces than init_net.
1640  *
1641  * Drivers that operate on real HW must use devlink_alloc() instead.
1642  */
1643 struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
1644 				 size_t priv_size, struct net *net,
1645 				 struct device *dev);
1646 static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
1647 					    size_t priv_size,
1648 					    struct device *dev)
1649 {
1650 	return devlink_alloc_ns(ops, priv_size, &init_net, dev);
1651 }
1652 
1653 int devl_register(struct devlink *devlink);
1654 void devl_unregister(struct devlink *devlink);
1655 void devlink_register(struct devlink *devlink);
1656 void devlink_unregister(struct devlink *devlink);
1657 void devlink_free(struct devlink *devlink);
1658 
1659 struct devlink *devlink_shd_get(const char *id,
1660 				const struct devlink_ops *ops,
1661 				size_t priv_size,
1662 				const struct device_driver *driver);
1663 void devlink_shd_put(struct devlink *devlink);
1664 void *devlink_shd_get_priv(struct devlink *devlink);
1665 
1666 /**
1667  * struct devlink_port_ops - Port operations
1668  * @port_split: Callback used to split the port into multiple ones.
1669  * @port_unsplit: Callback used to unsplit the port group back into
1670  *		  a single port.
1671  * @port_type_set: Callback used to set a type of a port.
1672  * @port_del: Callback used to delete selected port along with related function.
1673  *	      Devlink core calls this upon user request to delete
1674  *	      a port previously created by devlink_ops->port_new().
1675  * @port_fn_hw_addr_get: Callback used to set port function's hardware address.
1676  *			 Should be used by device drivers to report
1677  *			 the hardware address of a function managed
1678  *			 by the devlink port.
1679  * @port_fn_hw_addr_set: Callback used to set port function's hardware address.
1680  *			 Should be used by device drivers to set the hardware
1681  *			 address of a function managed by the devlink port.
1682  * @port_fn_roce_get: Callback used to get port function's RoCE capability.
1683  *		      Should be used by device drivers to report
1684  *		      the current state of RoCE capability of a function
1685  *		      managed by the devlink port.
1686  * @port_fn_roce_set: Callback used to set port function's RoCE capability.
1687  *		      Should be used by device drivers to enable/disable
1688  *		      RoCE capability of a function managed
1689  *		      by the devlink port.
1690  * @port_fn_migratable_get: Callback used to get port function's migratable
1691  *			    capability. Should be used by device drivers
1692  *			    to report the current state of migratable capability
1693  *			    of a function managed by the devlink port.
1694  * @port_fn_migratable_set: Callback used to set port function's migratable
1695  *			    capability. Should be used by device drivers
1696  *			    to enable/disable migratable capability of
1697  *			    a function managed by the devlink port.
1698  * @port_fn_state_get: Callback used to get port function's state.
1699  *		       Should be used by device drivers to report
1700  *		       the current admin and operational state of a
1701  *		       function managed by the devlink port.
1702  * @port_fn_state_set: Callback used to get port function's state.
1703  *		       Should be used by device drivers set
1704  *		       the admin state of a function managed
1705  *		       by the devlink port.
1706  * @port_fn_ipsec_crypto_get: Callback used to get port function's ipsec_crypto
1707  *			      capability. Should be used by device drivers
1708  *			      to report the current state of ipsec_crypto
1709  *			      capability of a function managed by the devlink
1710  *			      port.
1711  * @port_fn_ipsec_crypto_set: Callback used to set port function's ipsec_crypto
1712  *			      capability. Should be used by device drivers to
1713  *			      enable/disable ipsec_crypto capability of a
1714  *			      function managed by the devlink port.
1715  * @port_fn_ipsec_packet_get: Callback used to get port function's ipsec_packet
1716  *			      capability. Should be used by device drivers
1717  *			      to report the current state of ipsec_packet
1718  *			      capability of a function managed by the devlink
1719  *			      port.
1720  * @port_fn_ipsec_packet_set: Callback used to set port function's ipsec_packet
1721  *			      capability. Should be used by device drivers to
1722  *			      enable/disable ipsec_packet capability of a
1723  *			      function managed by the devlink port.
1724  * @port_fn_max_io_eqs_get: Callback used to get port function's maximum number
1725  *			    of event queues. Should be used by device drivers to
1726  *			    report the maximum event queues of a function
1727  *			    managed by the devlink port.
1728  * @port_fn_max_io_eqs_set: Callback used to set port function's maximum number
1729  *			    of event queues. Should be used by device drivers to
1730  *			    configure maximum number of event queues
1731  *			    of a function managed by the devlink port.
1732  *
1733  * Note: Driver should return -EOPNOTSUPP if it doesn't support
1734  * port function (@port_fn_*) handling for a particular port.
1735  */
1736 struct devlink_port_ops {
1737 	int (*port_split)(struct devlink *devlink, struct devlink_port *port,
1738 			  unsigned int count, struct netlink_ext_ack *extack);
1739 	int (*port_unsplit)(struct devlink *devlink, struct devlink_port *port,
1740 			    struct netlink_ext_ack *extack);
1741 	int (*port_type_set)(struct devlink_port *devlink_port,
1742 			     enum devlink_port_type port_type);
1743 	int (*port_del)(struct devlink *devlink, struct devlink_port *port,
1744 			struct netlink_ext_ack *extack);
1745 	int (*port_fn_hw_addr_get)(struct devlink_port *port, u8 *hw_addr,
1746 				   int *hw_addr_len,
1747 				   struct netlink_ext_ack *extack);
1748 	int (*port_fn_hw_addr_set)(struct devlink_port *port,
1749 				   const u8 *hw_addr, int hw_addr_len,
1750 				   struct netlink_ext_ack *extack);
1751 	int (*port_fn_roce_get)(struct devlink_port *devlink_port,
1752 				bool *is_enable,
1753 				struct netlink_ext_ack *extack);
1754 	int (*port_fn_roce_set)(struct devlink_port *devlink_port,
1755 				bool enable, struct netlink_ext_ack *extack);
1756 	int (*port_fn_migratable_get)(struct devlink_port *devlink_port,
1757 				      bool *is_enable,
1758 				      struct netlink_ext_ack *extack);
1759 	int (*port_fn_migratable_set)(struct devlink_port *devlink_port,
1760 				      bool enable,
1761 				      struct netlink_ext_ack *extack);
1762 	int (*port_fn_state_get)(struct devlink_port *port,
1763 				 enum devlink_port_fn_state *state,
1764 				 enum devlink_port_fn_opstate *opstate,
1765 				 struct netlink_ext_ack *extack);
1766 	int (*port_fn_state_set)(struct devlink_port *port,
1767 				 enum devlink_port_fn_state state,
1768 				 struct netlink_ext_ack *extack);
1769 	int (*port_fn_ipsec_crypto_get)(struct devlink_port *devlink_port,
1770 					bool *is_enable,
1771 					struct netlink_ext_ack *extack);
1772 	int (*port_fn_ipsec_crypto_set)(struct devlink_port *devlink_port,
1773 					bool enable,
1774 					struct netlink_ext_ack *extack);
1775 	int (*port_fn_ipsec_packet_get)(struct devlink_port *devlink_port,
1776 					bool *is_enable,
1777 					struct netlink_ext_ack *extack);
1778 	int (*port_fn_ipsec_packet_set)(struct devlink_port *devlink_port,
1779 					bool enable,
1780 					struct netlink_ext_ack *extack);
1781 	int (*port_fn_max_io_eqs_get)(struct devlink_port *devlink_port,
1782 				      u32 *max_eqs,
1783 				      struct netlink_ext_ack *extack);
1784 	int (*port_fn_max_io_eqs_set)(struct devlink_port *devlink_port,
1785 				      u32 max_eqs,
1786 				      struct netlink_ext_ack *extack);
1787 };
1788 
1789 void devlink_port_init(struct devlink *devlink,
1790 		       struct devlink_port *devlink_port);
1791 void devlink_port_fini(struct devlink_port *devlink_port);
1792 
1793 int devl_port_register_with_ops(struct devlink *devlink,
1794 				struct devlink_port *devlink_port,
1795 				unsigned int port_index,
1796 				const struct devlink_port_ops *ops);
1797 
1798 static inline int devl_port_register(struct devlink *devlink,
1799 				     struct devlink_port *devlink_port,
1800 				     unsigned int port_index)
1801 {
1802 	return devl_port_register_with_ops(devlink, devlink_port,
1803 					   port_index, NULL);
1804 }
1805 
1806 int devlink_port_register_with_ops(struct devlink *devlink,
1807 				   struct devlink_port *devlink_port,
1808 				   unsigned int port_index,
1809 				   const struct devlink_port_ops *ops);
1810 
1811 static inline int devlink_port_register(struct devlink *devlink,
1812 					struct devlink_port *devlink_port,
1813 					unsigned int port_index)
1814 {
1815 	return devlink_port_register_with_ops(devlink, devlink_port,
1816 					      port_index, NULL);
1817 }
1818 
1819 void devl_port_unregister(struct devlink_port *devlink_port);
1820 void devlink_port_unregister(struct devlink_port *devlink_port);
1821 void devlink_port_type_eth_set(struct devlink_port *devlink_port);
1822 void devlink_port_type_ib_set(struct devlink_port *devlink_port,
1823 			      struct ib_device *ibdev);
1824 void devlink_port_type_clear(struct devlink_port *devlink_port);
1825 void devlink_port_attrs_set(struct devlink_port *devlink_port,
1826 			    const struct devlink_port_attrs *attrs);
1827 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller,
1828 				   u16 pf, bool external);
1829 void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
1830 				   u16 pf, u16 vf, bool external);
1831 void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port,
1832 				   u32 controller, u16 pf, u32 sf,
1833 				   bool external);
1834 int devl_port_fn_devlink_set(struct devlink_port *devlink_port,
1835 			     struct devlink *fn_devlink);
1836 struct devlink_rate *
1837 devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,
1838 		      struct devlink_rate *parent);
1839 int
1840 devl_rate_leaf_create(struct devlink_port *devlink_port, void *priv,
1841 		      struct devlink_rate *parent);
1842 void devl_rate_leaf_destroy(struct devlink_port *devlink_port);
1843 void devl_rate_nodes_destroy(struct devlink *devlink);
1844 void devlink_port_linecard_set(struct devlink_port *devlink_port,
1845 			       struct devlink_linecard *linecard);
1846 struct devlink_linecard *
1847 devl_linecard_create(struct devlink *devlink, unsigned int linecard_index,
1848 		     const struct devlink_linecard_ops *ops, void *priv);
1849 void devl_linecard_destroy(struct devlink_linecard *linecard);
1850 void devlink_linecard_provision_set(struct devlink_linecard *linecard,
1851 				    const char *type);
1852 void devlink_linecard_provision_clear(struct devlink_linecard *linecard);
1853 void devlink_linecard_provision_fail(struct devlink_linecard *linecard);
1854 void devlink_linecard_activate(struct devlink_linecard *linecard);
1855 void devlink_linecard_deactivate(struct devlink_linecard *linecard);
1856 int devlink_linecard_nested_dl_set(struct devlink_linecard *linecard,
1857 				   struct devlink *nested_devlink);
1858 int devl_sb_register(struct devlink *devlink, unsigned int sb_index,
1859 		     u32 size, u16 ingress_pools_count,
1860 		     u16 egress_pools_count, u16 ingress_tc_count,
1861 		     u16 egress_tc_count);
1862 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
1863 			u32 size, u16 ingress_pools_count,
1864 			u16 egress_pools_count, u16 ingress_tc_count,
1865 			u16 egress_tc_count);
1866 void devl_sb_unregister(struct devlink *devlink, unsigned int sb_index);
1867 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
1868 int devl_dpipe_table_register(struct devlink *devlink,
1869 			      const char *table_name,
1870 			      const struct devlink_dpipe_table_ops *table_ops,
1871 			      void *priv, bool counter_control_extern);
1872 void devl_dpipe_table_unregister(struct devlink *devlink,
1873 				 const char *table_name);
1874 void devl_dpipe_headers_register(struct devlink *devlink,
1875 				 struct devlink_dpipe_headers *dpipe_headers);
1876 void devl_dpipe_headers_unregister(struct devlink *devlink);
1877 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
1878 					 const char *table_name);
1879 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
1880 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
1881 				   struct devlink_dpipe_entry *entry);
1882 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
1883 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
1884 int devlink_dpipe_action_put(struct sk_buff *skb,
1885 			     struct devlink_dpipe_action *action);
1886 int devlink_dpipe_match_put(struct sk_buff *skb,
1887 			    struct devlink_dpipe_match *match);
1888 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
1889 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
1890 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
1891 
1892 int devl_resource_register(struct devlink *devlink,
1893 			   const char *resource_name,
1894 			   u64 resource_size,
1895 			   u64 resource_id,
1896 			   u64 parent_resource_id,
1897 			   const struct devlink_resource_size_params *params);
1898 void devl_resources_unregister(struct devlink *devlink);
1899 void devlink_resources_unregister(struct devlink *devlink);
1900 int devl_resource_size_get(struct devlink *devlink,
1901 			   u64 resource_id,
1902 			   u64 *p_resource_size);
1903 int
1904 devl_port_resource_register(struct devlink_port *devlink_port,
1905 			    const char *resource_name,
1906 			    u64 resource_size, u64 resource_id,
1907 			    u64 parent_resource_id,
1908 			    const struct devlink_resource_size_params *params);
1909 void devl_port_resources_unregister(struct devlink_port *devlink_port);
1910 int devl_dpipe_table_resource_set(struct devlink *devlink,
1911 				  const char *table_name, u64 resource_id,
1912 				  u64 resource_units);
1913 void devl_resource_occ_get_register(struct devlink *devlink,
1914 				    u64 resource_id,
1915 				    devlink_resource_occ_get_t *occ_get,
1916 				    void *occ_get_priv);
1917 void devl_resource_occ_get_unregister(struct devlink *devlink,
1918 				      u64 resource_id);
1919 int devl_params_register(struct devlink *devlink,
1920 			 const struct devlink_param *params,
1921 			 size_t params_count);
1922 int devlink_params_register(struct devlink *devlink,
1923 			    const struct devlink_param *params,
1924 			    size_t params_count);
1925 void devl_params_unregister(struct devlink *devlink,
1926 			    const struct devlink_param *params,
1927 			    size_t params_count);
1928 void devlink_params_unregister(struct devlink *devlink,
1929 			       const struct devlink_param *params,
1930 			       size_t params_count);
1931 int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
1932 				    union devlink_param_value *val);
1933 void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
1934 				     union devlink_param_value *init_val);
1935 void devl_param_value_changed(struct devlink *devlink, u32 param_id);
1936 struct devlink_region *devl_region_create(struct devlink *devlink,
1937 					  const struct devlink_region_ops *ops,
1938 					  u32 region_max_snapshots,
1939 					  u64 region_size);
1940 struct devlink_region *
1941 devlink_region_create(struct devlink *devlink,
1942 		      const struct devlink_region_ops *ops,
1943 		      u32 region_max_snapshots, u64 region_size);
1944 struct devlink_region *
1945 devlink_port_region_create(struct devlink_port *port,
1946 			   const struct devlink_port_region_ops *ops,
1947 			   u32 region_max_snapshots, u64 region_size);
1948 void devl_region_destroy(struct devlink_region *region);
1949 void devlink_region_destroy(struct devlink_region *region);
1950 int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
1951 void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
1952 int devlink_region_snapshot_create(struct devlink_region *region,
1953 				   u8 *data, u32 snapshot_id);
1954 int devlink_info_serial_number_put(struct devlink_info_req *req,
1955 				   const char *sn);
1956 int devlink_info_board_serial_number_put(struct devlink_info_req *req,
1957 					 const char *bsn);
1958 
1959 enum devlink_info_version_type {
1960 	DEVLINK_INFO_VERSION_TYPE_NONE,
1961 	DEVLINK_INFO_VERSION_TYPE_COMPONENT, /* May be used as flash update
1962 					      * component by name.
1963 					      */
1964 };
1965 
1966 int devlink_info_version_fixed_put(struct devlink_info_req *req,
1967 				   const char *version_name,
1968 				   const char *version_value);
1969 int devlink_info_version_stored_put(struct devlink_info_req *req,
1970 				    const char *version_name,
1971 				    const char *version_value);
1972 int devlink_info_version_stored_put_ext(struct devlink_info_req *req,
1973 					const char *version_name,
1974 					const char *version_value,
1975 					enum devlink_info_version_type version_type);
1976 int devlink_info_version_running_put(struct devlink_info_req *req,
1977 				     const char *version_name,
1978 				     const char *version_value);
1979 int devlink_info_version_running_put_ext(struct devlink_info_req *req,
1980 					 const char *version_name,
1981 					 const char *version_value,
1982 					 enum devlink_info_version_type version_type);
1983 
1984 void devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
1985 void devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
1986 
1987 void devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1988 void devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1989 
1990 void devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1991 				      const char *name);
1992 void devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
1993 void devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1994 					 const char *name);
1995 void devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
1996 
1997 void devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1998 void devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
1999 void devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
2000 			     u16 value_len);
2001 
2002 void devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
2003 				bool value);
2004 void devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
2005 			      u8 value);
2006 void devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
2007 			       u32 value);
2008 void devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
2009 			       u64 value);
2010 void devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
2011 				  const char *value);
2012 void devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
2013 				  const void *value, u32 value_len);
2014 
2015 struct devlink_health_reporter *
2016 devl_port_health_reporter_create(struct devlink_port *port,
2017 				 const struct devlink_health_reporter_ops *ops,
2018 				 void *priv);
2019 
2020 struct devlink_health_reporter *
2021 devlink_port_health_reporter_create(struct devlink_port *port,
2022 				    const struct devlink_health_reporter_ops *ops,
2023 				    void *priv);
2024 
2025 struct devlink_health_reporter *
2026 devl_health_reporter_create(struct devlink *devlink,
2027 			    const struct devlink_health_reporter_ops *ops,
2028 			    void *priv);
2029 
2030 struct devlink_health_reporter *
2031 devlink_health_reporter_create(struct devlink *devlink,
2032 			       const struct devlink_health_reporter_ops *ops,
2033 			       void *priv);
2034 
2035 void
2036 devl_health_reporter_destroy(struct devlink_health_reporter *reporter);
2037 
2038 void
2039 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
2040 
2041 void *
2042 devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
2043 int devlink_health_report(struct devlink_health_reporter *reporter,
2044 			  const char *msg, void *priv_ctx);
2045 void
2046 devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
2047 				     enum devlink_health_reporter_state state);
2048 void
2049 devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
2050 
2051 int devl_nested_devlink_set(struct devlink *devlink,
2052 			    struct devlink *nested_devlink);
2053 bool devlink_is_reload_failed(const struct devlink *devlink);
2054 void devlink_remote_reload_actions_performed(struct devlink *devlink,
2055 					     enum devlink_reload_limit limit,
2056 					     u32 actions_performed);
2057 
2058 void devlink_flash_update_status_notify(struct devlink *devlink,
2059 					const char *status_msg,
2060 					const char *component,
2061 					unsigned long done,
2062 					unsigned long total);
2063 void devlink_flash_update_timeout_notify(struct devlink *devlink,
2064 					 const char *status_msg,
2065 					 const char *component,
2066 					 unsigned long timeout);
2067 
2068 int devl_traps_register(struct devlink *devlink,
2069 			const struct devlink_trap *traps,
2070 			size_t traps_count, void *priv);
2071 int devlink_traps_register(struct devlink *devlink,
2072 			   const struct devlink_trap *traps,
2073 			   size_t traps_count, void *priv);
2074 void devl_traps_unregister(struct devlink *devlink,
2075 			   const struct devlink_trap *traps,
2076 			   size_t traps_count);
2077 void devlink_traps_unregister(struct devlink *devlink,
2078 			      const struct devlink_trap *traps,
2079 			      size_t traps_count);
2080 void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
2081 			 void *trap_ctx, struct devlink_port *in_devlink_port,
2082 			 const struct flow_action_cookie *fa_cookie);
2083 void *devlink_trap_ctx_priv(void *trap_ctx);
2084 int devl_trap_groups_register(struct devlink *devlink,
2085 			      const struct devlink_trap_group *groups,
2086 			      size_t groups_count);
2087 int devlink_trap_groups_register(struct devlink *devlink,
2088 				 const struct devlink_trap_group *groups,
2089 				 size_t groups_count);
2090 void devl_trap_groups_unregister(struct devlink *devlink,
2091 				 const struct devlink_trap_group *groups,
2092 				 size_t groups_count);
2093 void devlink_trap_groups_unregister(struct devlink *devlink,
2094 				    const struct devlink_trap_group *groups,
2095 				    size_t groups_count);
2096 int
2097 devl_trap_policers_register(struct devlink *devlink,
2098 			    const struct devlink_trap_policer *policers,
2099 			    size_t policers_count);
2100 void
2101 devl_trap_policers_unregister(struct devlink *devlink,
2102 			      const struct devlink_trap_policer *policers,
2103 			      size_t policers_count);
2104 
2105 #if IS_ENABLED(CONFIG_NET_DEVLINK)
2106 
2107 struct devlink *__must_check devlink_try_get(struct devlink *devlink);
2108 void devlink_put(struct devlink *devlink);
2109 
2110 void devlink_compat_running_version(struct devlink *devlink,
2111 				    char *buf, size_t len);
2112 int devlink_compat_flash_update(struct devlink *devlink, const char *file_name);
2113 int devlink_compat_phys_port_name_get(struct net_device *dev,
2114 				      char *name, size_t len);
2115 int devlink_compat_switch_id_get(struct net_device *dev,
2116 				 struct netdev_phys_item_id *ppid);
2117 
2118 int devlink_nl_port_handle_fill(struct sk_buff *msg, struct devlink_port *devlink_port);
2119 size_t devlink_nl_port_handle_size(struct devlink_port *devlink_port);
2120 void devlink_fmsg_dump_skb(struct devlink_fmsg *fmsg, const struct sk_buff *skb);
2121 
2122 #else
2123 
2124 static inline struct devlink *devlink_try_get(struct devlink *devlink)
2125 {
2126 	return NULL;
2127 }
2128 
2129 static inline void devlink_put(struct devlink *devlink)
2130 {
2131 }
2132 
2133 static inline void
2134 devlink_compat_running_version(struct devlink *devlink, char *buf, size_t len)
2135 {
2136 }
2137 
2138 static inline int
2139 devlink_compat_flash_update(struct devlink *devlink, const char *file_name)
2140 {
2141 	return -EOPNOTSUPP;
2142 }
2143 
2144 static inline int
2145 devlink_compat_phys_port_name_get(struct net_device *dev,
2146 				  char *name, size_t len)
2147 {
2148 	return -EOPNOTSUPP;
2149 }
2150 
2151 static inline int
2152 devlink_compat_switch_id_get(struct net_device *dev,
2153 			     struct netdev_phys_item_id *ppid)
2154 {
2155 	return -EOPNOTSUPP;
2156 }
2157 
2158 static inline int
2159 devlink_nl_port_handle_fill(struct sk_buff *msg, struct devlink_port *devlink_port)
2160 {
2161 	return 0;
2162 }
2163 
2164 static inline size_t devlink_nl_port_handle_size(struct devlink_port *devlink_port)
2165 {
2166 	return 0;
2167 }
2168 
2169 #endif
2170 
2171 #endif /* _NET_DEVLINK_H_ */
2172