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