1
2
3
4
5
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
23struct devlink_ops;
24
25struct 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 struct list_head reporter_list;
34 struct mutex reporters_lock;
35 struct devlink_dpipe_headers *dpipe_headers;
36 struct list_head trap_list;
37 struct list_head trap_group_list;
38 struct list_head trap_policer_list;
39 const struct devlink_ops *ops;
40 struct xarray snapshot_ids;
41 struct device *dev;
42 possible_net_t _net;
43 struct mutex lock;
44 u8 reload_failed:1,
45 reload_enabled:1,
46 registered:1;
47 char priv[0] __aligned(NETDEV_ALIGN);
48};
49
50struct devlink_port_phys_attrs {
51 u32 port_number;
52
53
54
55 u32 split_subport_number;
56};
57
58struct devlink_port_pci_pf_attrs {
59 u16 pf;
60};
61
62struct devlink_port_pci_vf_attrs {
63 u16 pf;
64 u16 vf;
65};
66
67struct devlink_port_attrs {
68 u8 set:1,
69 split:1,
70 switch_port:1;
71 enum devlink_port_flavour flavour;
72 struct netdev_phys_item_id switch_id;
73 union {
74 struct devlink_port_phys_attrs phys;
75 struct devlink_port_pci_pf_attrs pci_pf;
76 struct devlink_port_pci_vf_attrs pci_vf;
77 };
78};
79
80struct devlink_port {
81 struct list_head list;
82 struct list_head param_list;
83 struct devlink *devlink;
84 unsigned int index;
85 bool registered;
86 spinlock_t type_lock;
87
88
89 enum devlink_port_type type;
90 enum devlink_port_type desired_type;
91 void *type_dev;
92 struct devlink_port_attrs attrs;
93 struct delayed_work type_warn_dw;
94};
95
96struct devlink_sb_pool_info {
97 enum devlink_sb_pool_type pool_type;
98 u32 size;
99 enum devlink_sb_threshold_type threshold_type;
100 u32 cell_size;
101};
102
103
104
105
106
107
108
109
110struct devlink_dpipe_field {
111 const char *name;
112 unsigned int id;
113 unsigned int bitwidth;
114 enum devlink_dpipe_field_mapping_type mapping_type;
115};
116
117
118
119
120
121
122
123
124
125
126struct devlink_dpipe_header {
127 const char *name;
128 unsigned int id;
129 struct devlink_dpipe_field *fields;
130 unsigned int fields_count;
131 bool global;
132};
133
134
135
136
137
138
139
140
141
142struct devlink_dpipe_match {
143 enum devlink_dpipe_match_type type;
144 unsigned int header_index;
145 struct devlink_dpipe_header *header;
146 unsigned int field_id;
147};
148
149
150
151
152
153
154
155
156
157struct devlink_dpipe_action {
158 enum devlink_dpipe_action_type type;
159 unsigned int header_index;
160 struct devlink_dpipe_header *header;
161 unsigned int field_id;
162};
163
164
165
166
167
168
169
170
171
172
173
174
175struct devlink_dpipe_value {
176 union {
177 struct devlink_dpipe_action *action;
178 struct devlink_dpipe_match *match;
179 };
180 unsigned int mapping_value;
181 bool mapping_valid;
182 unsigned int value_size;
183 void *value;
184 void *mask;
185};
186
187
188
189
190
191
192
193
194
195
196
197struct devlink_dpipe_entry {
198 u64 index;
199 struct devlink_dpipe_value *match_values;
200 unsigned int match_values_count;
201 struct devlink_dpipe_value *action_values;
202 unsigned int action_values_count;
203 u64 counter;
204 bool counter_valid;
205};
206
207
208
209
210
211
212
213
214
215
216struct devlink_dpipe_dump_ctx {
217 struct genl_info *info;
218 enum devlink_command cmd;
219 struct sk_buff *skb;
220 struct nlattr *nest;
221 void *hdr;
222};
223
224struct devlink_dpipe_table_ops;
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239struct devlink_dpipe_table {
240 void *priv;
241 struct list_head list;
242 const char *name;
243 bool counters_enabled;
244 bool counter_control_extern;
245 bool resource_valid;
246 u64 resource_id;
247 u64 resource_units;
248 struct devlink_dpipe_table_ops *table_ops;
249 struct rcu_head rcu;
250};
251
252
253
254
255
256
257
258
259
260
261
262struct devlink_dpipe_table_ops {
263 int (*actions_dump)(void *priv, struct sk_buff *skb);
264 int (*matches_dump)(void *priv, struct sk_buff *skb);
265 int (*entries_dump)(void *priv, bool counters_enabled,
266 struct devlink_dpipe_dump_ctx *dump_ctx);
267 int (*counters_set_update)(void *priv, bool enable);
268 u64 (*size_get)(void *priv);
269};
270
271
272
273
274
275
276struct devlink_dpipe_headers {
277 struct devlink_dpipe_header **headers;
278 unsigned int headers_count;
279};
280
281
282
283
284
285
286
287
288struct devlink_resource_size_params {
289 u64 size_min;
290 u64 size_max;
291 u64 size_granularity;
292 enum devlink_resource_unit unit;
293};
294
295static inline void
296devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
297 u64 size_min, u64 size_max,
298 u64 size_granularity,
299 enum devlink_resource_unit unit)
300{
301 size_params->size_min = size_min;
302 size_params->size_max = size_max;
303 size_params->size_granularity = size_granularity;
304 size_params->unit = unit;
305}
306
307typedef u64 devlink_resource_occ_get_t(void *priv);
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322struct devlink_resource {
323 const char *name;
324 u64 id;
325 u64 size;
326 u64 size_new;
327 bool size_valid;
328 struct devlink_resource *parent;
329 struct devlink_resource_size_params size_params;
330 struct list_head list;
331 struct list_head resource_list;
332 devlink_resource_occ_get_t *occ_get;
333 void *occ_get_priv;
334};
335
336#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
337
338#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
339enum devlink_param_type {
340 DEVLINK_PARAM_TYPE_U8,
341 DEVLINK_PARAM_TYPE_U16,
342 DEVLINK_PARAM_TYPE_U32,
343 DEVLINK_PARAM_TYPE_STRING,
344 DEVLINK_PARAM_TYPE_BOOL,
345};
346
347union devlink_param_value {
348 u8 vu8;
349 u16 vu16;
350 u32 vu32;
351 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
352 bool vbool;
353};
354
355struct devlink_param_gset_ctx {
356 union devlink_param_value val;
357 enum devlink_param_cmode cmode;
358};
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375struct devlink_param {
376 u32 id;
377 const char *name;
378 bool generic;
379 enum devlink_param_type type;
380 unsigned long supported_cmodes;
381 int (*get)(struct devlink *devlink, u32 id,
382 struct devlink_param_gset_ctx *ctx);
383 int (*set)(struct devlink *devlink, u32 id,
384 struct devlink_param_gset_ctx *ctx);
385 int (*validate)(struct devlink *devlink, u32 id,
386 union devlink_param_value val,
387 struct netlink_ext_ack *extack);
388};
389
390struct devlink_param_item {
391 struct list_head list;
392 const struct devlink_param *param;
393 union devlink_param_value driverinit_value;
394 bool driverinit_value_valid;
395 bool published;
396};
397
398enum devlink_param_generic_id {
399 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
400 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
401 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
402 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
403 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
404 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
405 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
406 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
407 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
408 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
409
410
411 __DEVLINK_PARAM_GENERIC_ID_MAX,
412 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
413};
414
415#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
416#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
417
418#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
419#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
420
421#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
422#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
423
424#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
425#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
426
427#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
428#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
429
430#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
431#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
432
433#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
434#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
435
436#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
437#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
438
439#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
440 "reset_dev_on_drv_probe"
441#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
442
443#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
444#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
445
446#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
447{ \
448 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
449 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
450 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
451 .generic = true, \
452 .supported_cmodes = _cmodes, \
453 .get = _get, \
454 .set = _set, \
455 .validate = _validate, \
456}
457
458#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
459{ \
460 .id = _id, \
461 .name = _name, \
462 .type = _type, \
463 .supported_cmodes = _cmodes, \
464 .get = _get, \
465 .set = _set, \
466 .validate = _validate, \
467}
468
469
470#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
471
472#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
473
474#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
475
476
477#define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
478
479#define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
480
481
482#define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
483
484#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
485
486#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API "fw.mgmt.api"
487
488#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
489
490#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
491
492#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
493
494#define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
495
496#define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce"
497
498#define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
499
500struct devlink_region;
501struct devlink_info_req;
502
503
504
505
506
507
508
509
510
511
512struct devlink_region_ops {
513 const char *name;
514 void (*destructor)(const void *data);
515 int (*snapshot)(struct devlink *devlink, struct netlink_ext_ack *extack,
516 u8 **data);
517};
518
519struct devlink_fmsg;
520struct devlink_health_reporter;
521
522enum devlink_health_reporter_state {
523 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
524 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
525};
526
527
528
529
530
531
532
533
534
535
536
537struct devlink_health_reporter_ops {
538 char *name;
539 int (*recover)(struct devlink_health_reporter *reporter,
540 void *priv_ctx, struct netlink_ext_ack *extack);
541 int (*dump)(struct devlink_health_reporter *reporter,
542 struct devlink_fmsg *fmsg, void *priv_ctx,
543 struct netlink_ext_ack *extack);
544 int (*diagnose)(struct devlink_health_reporter *reporter,
545 struct devlink_fmsg *fmsg,
546 struct netlink_ext_ack *extack);
547};
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562struct devlink_trap_policer {
563 u32 id;
564 u64 init_rate;
565 u64 init_burst;
566 u64 max_rate;
567 u64 min_rate;
568 u64 max_burst;
569 u64 min_burst;
570};
571
572
573
574
575
576
577
578
579
580
581
582struct devlink_trap_group {
583 const char *name;
584 u16 id;
585 bool generic;
586 u32 init_policer_id;
587};
588
589#define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
590#define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605struct devlink_trap {
606 enum devlink_trap_type type;
607 enum devlink_trap_action init_action;
608 bool generic;
609 u16 id;
610 const char *name;
611 u16 init_group_id;
612 u32 metadata_cap;
613};
614
615
616
617
618enum devlink_trap_generic_id {
619 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
620 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
621 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
622 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
623 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
624 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
625 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
626 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
627 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
628 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
629 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
630 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
631 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
632 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
633 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
634 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
635 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
636 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
637 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
638 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
639 DEVLINK_TRAP_GENERIC_ID_RPF,
640 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
641 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
642 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
643 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
644 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
645 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
646 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
647 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
648
649
650 __DEVLINK_TRAP_GENERIC_ID_MAX,
651 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
652};
653
654
655
656
657enum devlink_trap_group_generic_id {
658 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
659 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
660 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
661 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
662 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
663
664
665 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
666 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
667 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
668};
669
670#define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
671 "source_mac_is_multicast"
672#define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
673 "vlan_tag_mismatch"
674#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
675 "ingress_vlan_filter"
676#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
677 "ingress_spanning_tree_filter"
678#define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
679 "port_list_is_empty"
680#define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
681 "port_loopback_filter"
682#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
683 "blackhole_route"
684#define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
685 "ttl_value_is_too_small"
686#define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
687 "tail_drop"
688#define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
689 "non_ip"
690#define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
691 "uc_dip_over_mc_dmac"
692#define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
693 "dip_is_loopback_address"
694#define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
695 "sip_is_mc"
696#define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
697 "sip_is_loopback_address"
698#define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
699 "ip_header_corrupted"
700#define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
701 "ipv4_sip_is_limited_bc"
702#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
703 "ipv6_mc_dip_reserved_scope"
704#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
705 "ipv6_mc_dip_interface_local_scope"
706#define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
707 "mtu_value_is_too_small"
708#define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
709 "unresolved_neigh"
710#define DEVLINK_TRAP_GENERIC_NAME_RPF \
711 "mc_reverse_path_forwarding"
712#define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
713 "reject_route"
714#define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
715 "ipv4_lpm_miss"
716#define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
717 "ipv6_lpm_miss"
718#define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
719 "non_routable_packet"
720#define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
721 "decap_error"
722#define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
723 "overlay_smac_is_mc"
724#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
725 "ingress_flow_action_drop"
726#define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
727 "egress_flow_action_drop"
728
729#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
730 "l2_drops"
731#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
732 "l3_drops"
733#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
734 "buffer_drops"
735#define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
736 "tunnel_drops"
737#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
738 "acl_drops"
739
740#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \
741 _metadata_cap) \
742 { \
743 .type = DEVLINK_TRAP_TYPE_##_type, \
744 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
745 .generic = true, \
746 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
747 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
748 .init_group_id = _group_id, \
749 .metadata_cap = _metadata_cap, \
750 }
751
752#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \
753 _metadata_cap) \
754 { \
755 .type = DEVLINK_TRAP_TYPE_##_type, \
756 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
757 .generic = false, \
758 .id = _id, \
759 .name = _name, \
760 .init_group_id = _group_id, \
761 .metadata_cap = _metadata_cap, \
762 }
763
764#define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id) \
765 { \
766 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
767 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
768 .generic = true, \
769 .init_policer_id = _policer_id, \
770 }
771
772#define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate, \
773 _max_burst, _min_burst) \
774 { \
775 .id = _id, \
776 .init_rate = _rate, \
777 .init_burst = _burst, \
778 .max_rate = _max_rate, \
779 .min_rate = _min_rate, \
780 .max_burst = _max_burst, \
781 .min_burst = _min_burst, \
782 }
783
784struct devlink_ops {
785 int (*reload_down)(struct devlink *devlink, bool netns_change,
786 struct netlink_ext_ack *extack);
787 int (*reload_up)(struct devlink *devlink,
788 struct netlink_ext_ack *extack);
789 int (*port_type_set)(struct devlink_port *devlink_port,
790 enum devlink_port_type port_type);
791 int (*port_split)(struct devlink *devlink, unsigned int port_index,
792 unsigned int count, struct netlink_ext_ack *extack);
793 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
794 struct netlink_ext_ack *extack);
795 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
796 u16 pool_index,
797 struct devlink_sb_pool_info *pool_info);
798 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
799 u16 pool_index, u32 size,
800 enum devlink_sb_threshold_type threshold_type,
801 struct netlink_ext_ack *extack);
802 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
803 unsigned int sb_index, u16 pool_index,
804 u32 *p_threshold);
805 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
806 unsigned int sb_index, u16 pool_index,
807 u32 threshold, struct netlink_ext_ack *extack);
808 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
809 unsigned int sb_index,
810 u16 tc_index,
811 enum devlink_sb_pool_type pool_type,
812 u16 *p_pool_index, u32 *p_threshold);
813 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
814 unsigned int sb_index,
815 u16 tc_index,
816 enum devlink_sb_pool_type pool_type,
817 u16 pool_index, u32 threshold,
818 struct netlink_ext_ack *extack);
819 int (*sb_occ_snapshot)(struct devlink *devlink,
820 unsigned int sb_index);
821 int (*sb_occ_max_clear)(struct devlink *devlink,
822 unsigned int sb_index);
823 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
824 unsigned int sb_index, u16 pool_index,
825 u32 *p_cur, u32 *p_max);
826 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
827 unsigned int sb_index,
828 u16 tc_index,
829 enum devlink_sb_pool_type pool_type,
830 u32 *p_cur, u32 *p_max);
831
832 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
833 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
834 struct netlink_ext_ack *extack);
835 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
836 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
837 struct netlink_ext_ack *extack);
838 int (*eswitch_encap_mode_get)(struct devlink *devlink,
839 enum devlink_eswitch_encap_mode *p_encap_mode);
840 int (*eswitch_encap_mode_set)(struct devlink *devlink,
841 enum devlink_eswitch_encap_mode encap_mode,
842 struct netlink_ext_ack *extack);
843 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
844 struct netlink_ext_ack *extack);
845 int (*flash_update)(struct devlink *devlink, const char *file_name,
846 const char *component,
847 struct netlink_ext_ack *extack);
848
849
850
851
852
853
854
855
856 int (*trap_init)(struct devlink *devlink,
857 const struct devlink_trap *trap, void *trap_ctx);
858
859
860
861
862
863
864 void (*trap_fini)(struct devlink *devlink,
865 const struct devlink_trap *trap, void *trap_ctx);
866
867
868
869 int (*trap_action_set)(struct devlink *devlink,
870 const struct devlink_trap *trap,
871 enum devlink_trap_action action);
872
873
874
875
876
877
878 int (*trap_group_init)(struct devlink *devlink,
879 const struct devlink_trap_group *group);
880
881
882
883
884
885
886 int (*trap_group_set)(struct devlink *devlink,
887 const struct devlink_trap_group *group,
888 const struct devlink_trap_policer *policer);
889
890
891
892
893
894
895 int (*trap_policer_init)(struct devlink *devlink,
896 const struct devlink_trap_policer *policer);
897
898
899
900
901
902
903 void (*trap_policer_fini)(struct devlink *devlink,
904 const struct devlink_trap_policer *policer);
905
906
907
908 int (*trap_policer_set)(struct devlink *devlink,
909 const struct devlink_trap_policer *policer,
910 u64 rate, u64 burst,
911 struct netlink_ext_ack *extack);
912
913
914
915
916
917
918 int (*trap_policer_counter_get)(struct devlink *devlink,
919 const struct devlink_trap_policer *policer,
920 u64 *p_drops);
921};
922
923static inline void *devlink_priv(struct devlink *devlink)
924{
925 BUG_ON(!devlink);
926 return &devlink->priv;
927}
928
929static inline struct devlink *priv_to_devlink(void *priv)
930{
931 BUG_ON(!priv);
932 return container_of(priv, struct devlink, priv);
933}
934
935static inline struct devlink_port *
936netdev_to_devlink_port(struct net_device *dev)
937{
938 if (dev->netdev_ops->ndo_get_devlink_port)
939 return dev->netdev_ops->ndo_get_devlink_port(dev);
940 return NULL;
941}
942
943static inline struct devlink *netdev_to_devlink(struct net_device *dev)
944{
945 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
946
947 if (devlink_port)
948 return devlink_port->devlink;
949 return NULL;
950}
951
952struct ib_device;
953
954struct net *devlink_net(const struct devlink *devlink);
955void devlink_net_set(struct devlink *devlink, struct net *net);
956struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
957int devlink_register(struct devlink *devlink, struct device *dev);
958void devlink_unregister(struct devlink *devlink);
959void devlink_reload_enable(struct devlink *devlink);
960void devlink_reload_disable(struct devlink *devlink);
961void devlink_free(struct devlink *devlink);
962int devlink_port_register(struct devlink *devlink,
963 struct devlink_port *devlink_port,
964 unsigned int port_index);
965void devlink_port_unregister(struct devlink_port *devlink_port);
966void devlink_port_type_eth_set(struct devlink_port *devlink_port,
967 struct net_device *netdev);
968void devlink_port_type_ib_set(struct devlink_port *devlink_port,
969 struct ib_device *ibdev);
970void devlink_port_type_clear(struct devlink_port *devlink_port);
971void devlink_port_attrs_set(struct devlink_port *devlink_port,
972 enum devlink_port_flavour flavour,
973 u32 port_number, bool split,
974 u32 split_subport_number,
975 const unsigned char *switch_id,
976 unsigned char switch_id_len);
977void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
978 const unsigned char *switch_id,
979 unsigned char switch_id_len, u16 pf);
980void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
981 const unsigned char *switch_id,
982 unsigned char switch_id_len,
983 u16 pf, u16 vf);
984int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
985 u32 size, u16 ingress_pools_count,
986 u16 egress_pools_count, u16 ingress_tc_count,
987 u16 egress_tc_count);
988void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
989int devlink_dpipe_table_register(struct devlink *devlink,
990 const char *table_name,
991 struct devlink_dpipe_table_ops *table_ops,
992 void *priv, bool counter_control_extern);
993void devlink_dpipe_table_unregister(struct devlink *devlink,
994 const char *table_name);
995int devlink_dpipe_headers_register(struct devlink *devlink,
996 struct devlink_dpipe_headers *dpipe_headers);
997void devlink_dpipe_headers_unregister(struct devlink *devlink);
998bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
999 const char *table_name);
1000int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
1001int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
1002 struct devlink_dpipe_entry *entry);
1003int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
1004void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
1005int devlink_dpipe_action_put(struct sk_buff *skb,
1006 struct devlink_dpipe_action *action);
1007int devlink_dpipe_match_put(struct sk_buff *skb,
1008 struct devlink_dpipe_match *match);
1009extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
1010extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
1011extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
1012
1013int devlink_resource_register(struct devlink *devlink,
1014 const char *resource_name,
1015 u64 resource_size,
1016 u64 resource_id,
1017 u64 parent_resource_id,
1018 const struct devlink_resource_size_params *size_params);
1019void devlink_resources_unregister(struct devlink *devlink,
1020 struct devlink_resource *resource);
1021int devlink_resource_size_get(struct devlink *devlink,
1022 u64 resource_id,
1023 u64 *p_resource_size);
1024int devlink_dpipe_table_resource_set(struct devlink *devlink,
1025 const char *table_name, u64 resource_id,
1026 u64 resource_units);
1027void devlink_resource_occ_get_register(struct devlink *devlink,
1028 u64 resource_id,
1029 devlink_resource_occ_get_t *occ_get,
1030 void *occ_get_priv);
1031void devlink_resource_occ_get_unregister(struct devlink *devlink,
1032 u64 resource_id);
1033int devlink_params_register(struct devlink *devlink,
1034 const struct devlink_param *params,
1035 size_t params_count);
1036void devlink_params_unregister(struct devlink *devlink,
1037 const struct devlink_param *params,
1038 size_t params_count);
1039void devlink_params_publish(struct devlink *devlink);
1040void devlink_params_unpublish(struct devlink *devlink);
1041int devlink_port_params_register(struct devlink_port *devlink_port,
1042 const struct devlink_param *params,
1043 size_t params_count);
1044void devlink_port_params_unregister(struct devlink_port *devlink_port,
1045 const struct devlink_param *params,
1046 size_t params_count);
1047int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
1048 union devlink_param_value *init_val);
1049int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
1050 union devlink_param_value init_val);
1051int
1052devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
1053 u32 param_id,
1054 union devlink_param_value *init_val);
1055int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
1056 u32 param_id,
1057 union devlink_param_value init_val);
1058void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
1059void devlink_port_param_value_changed(struct devlink_port *devlink_port,
1060 u32 param_id);
1061void devlink_param_value_str_fill(union devlink_param_value *dst_val,
1062 const char *src);
1063struct devlink_region *
1064devlink_region_create(struct devlink *devlink,
1065 const struct devlink_region_ops *ops,
1066 u32 region_max_snapshots, u64 region_size);
1067void devlink_region_destroy(struct devlink_region *region);
1068int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
1069void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
1070int devlink_region_snapshot_create(struct devlink_region *region,
1071 u8 *data, u32 snapshot_id);
1072int devlink_info_serial_number_put(struct devlink_info_req *req,
1073 const char *sn);
1074int devlink_info_driver_name_put(struct devlink_info_req *req,
1075 const char *name);
1076int devlink_info_version_fixed_put(struct devlink_info_req *req,
1077 const char *version_name,
1078 const char *version_value);
1079int devlink_info_version_stored_put(struct devlink_info_req *req,
1080 const char *version_name,
1081 const char *version_value);
1082int devlink_info_version_running_put(struct devlink_info_req *req,
1083 const char *version_name,
1084 const char *version_value);
1085
1086int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
1087int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
1088
1089int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1090int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1091
1092int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1093 const char *name);
1094int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
1095int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1096 const char *name);
1097int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
1098
1099int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
1100int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
1101int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1102int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
1103int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
1104int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1105 u16 value_len);
1106
1107int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1108 bool value);
1109int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1110 u8 value);
1111int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1112 u32 value);
1113int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1114 u64 value);
1115int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1116 const char *value);
1117int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
1118 const void *value, u32 value_len);
1119
1120struct devlink_health_reporter *
1121devlink_health_reporter_create(struct devlink *devlink,
1122 const struct devlink_health_reporter_ops *ops,
1123 u64 graceful_period, void *priv);
1124void
1125devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1126
1127void *
1128devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
1129int devlink_health_report(struct devlink_health_reporter *reporter,
1130 const char *msg, void *priv_ctx);
1131void
1132devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1133 enum devlink_health_reporter_state state);
1134void
1135devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
1136
1137bool devlink_is_reload_failed(const struct devlink *devlink);
1138
1139void devlink_flash_update_begin_notify(struct devlink *devlink);
1140void devlink_flash_update_end_notify(struct devlink *devlink);
1141void devlink_flash_update_status_notify(struct devlink *devlink,
1142 const char *status_msg,
1143 const char *component,
1144 unsigned long done,
1145 unsigned long total);
1146
1147int devlink_traps_register(struct devlink *devlink,
1148 const struct devlink_trap *traps,
1149 size_t traps_count, void *priv);
1150void devlink_traps_unregister(struct devlink *devlink,
1151 const struct devlink_trap *traps,
1152 size_t traps_count);
1153void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
1154 void *trap_ctx, struct devlink_port *in_devlink_port,
1155 const struct flow_action_cookie *fa_cookie);
1156void *devlink_trap_ctx_priv(void *trap_ctx);
1157int devlink_trap_groups_register(struct devlink *devlink,
1158 const struct devlink_trap_group *groups,
1159 size_t groups_count);
1160void devlink_trap_groups_unregister(struct devlink *devlink,
1161 const struct devlink_trap_group *groups,
1162 size_t groups_count);
1163int
1164devlink_trap_policers_register(struct devlink *devlink,
1165 const struct devlink_trap_policer *policers,
1166 size_t policers_count);
1167void
1168devlink_trap_policers_unregister(struct devlink *devlink,
1169 const struct devlink_trap_policer *policers,
1170 size_t policers_count);
1171
1172#if IS_ENABLED(CONFIG_NET_DEVLINK)
1173
1174void devlink_compat_running_version(struct net_device *dev,
1175 char *buf, size_t len);
1176int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
1177int devlink_compat_phys_port_name_get(struct net_device *dev,
1178 char *name, size_t len);
1179int devlink_compat_switch_id_get(struct net_device *dev,
1180 struct netdev_phys_item_id *ppid);
1181
1182#else
1183
1184static inline void
1185devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1186{
1187}
1188
1189static inline int
1190devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1191{
1192 return -EOPNOTSUPP;
1193}
1194
1195static inline int
1196devlink_compat_phys_port_name_get(struct net_device *dev,
1197 char *name, size_t len)
1198{
1199 return -EOPNOTSUPP;
1200}
1201
1202static inline int
1203devlink_compat_switch_id_get(struct net_device *dev,
1204 struct netdev_phys_item_id *ppid)
1205{
1206 return -EOPNOTSUPP;
1207}
1208
1209#endif
1210
1211#endif
1212