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