interconnect: qcom: icc-rpm: Fix peak rate calculation
[linux-2.6-microblaze.git] / tools / net / ynl / generated / devlink-user.c
1 // SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
2 /* Do not edit directly, auto-generated from: */
3 /*      Documentation/netlink/specs/devlink.yaml */
4 /* YNL-GEN user source */
5
6 #include <stdlib.h>
7 #include <string.h>
8 #include "devlink-user.h"
9 #include "ynl.h"
10 #include <linux/devlink.h>
11
12 #include <libmnl/libmnl.h>
13 #include <linux/genetlink.h>
14
15 /* Enums */
16 static const char * const devlink_op_strmap[] = {
17         [3] = "get",
18         [7] = "port-get",
19         [DEVLINK_CMD_PORT_NEW] = "port-new",
20         [13] = "sb-get",
21         [17] = "sb-pool-get",
22         [21] = "sb-port-pool-get",
23         [25] = "sb-tc-pool-bind-get",
24         [DEVLINK_CMD_ESWITCH_GET] = "eswitch-get",
25         [DEVLINK_CMD_DPIPE_TABLE_GET] = "dpipe-table-get",
26         [DEVLINK_CMD_DPIPE_ENTRIES_GET] = "dpipe-entries-get",
27         [DEVLINK_CMD_DPIPE_HEADERS_GET] = "dpipe-headers-get",
28         [DEVLINK_CMD_RESOURCE_DUMP] = "resource-dump",
29         [DEVLINK_CMD_RELOAD] = "reload",
30         [DEVLINK_CMD_PARAM_GET] = "param-get",
31         [DEVLINK_CMD_REGION_GET] = "region-get",
32         [DEVLINK_CMD_REGION_NEW] = "region-new",
33         [DEVLINK_CMD_REGION_READ] = "region-read",
34         [DEVLINK_CMD_PORT_PARAM_GET] = "port-param-get",
35         [DEVLINK_CMD_INFO_GET] = "info-get",
36         [DEVLINK_CMD_HEALTH_REPORTER_GET] = "health-reporter-get",
37         [DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET] = "health-reporter-dump-get",
38         [63] = "trap-get",
39         [67] = "trap-group-get",
40         [71] = "trap-policer-get",
41         [76] = "rate-get",
42         [80] = "linecard-get",
43         [DEVLINK_CMD_SELFTESTS_GET] = "selftests-get",
44 };
45
46 const char *devlink_op_str(int op)
47 {
48         if (op < 0 || op >= (int)MNL_ARRAY_SIZE(devlink_op_strmap))
49                 return NULL;
50         return devlink_op_strmap[op];
51 }
52
53 static const char * const devlink_sb_pool_type_strmap[] = {
54         [0] = "ingress",
55         [1] = "egress",
56 };
57
58 const char *devlink_sb_pool_type_str(enum devlink_sb_pool_type value)
59 {
60         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_sb_pool_type_strmap))
61                 return NULL;
62         return devlink_sb_pool_type_strmap[value];
63 }
64
65 static const char * const devlink_port_type_strmap[] = {
66         [0] = "notset",
67         [1] = "auto",
68         [2] = "eth",
69         [3] = "ib",
70 };
71
72 const char *devlink_port_type_str(enum devlink_port_type value)
73 {
74         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_port_type_strmap))
75                 return NULL;
76         return devlink_port_type_strmap[value];
77 }
78
79 static const char * const devlink_port_flavour_strmap[] = {
80         [0] = "physical",
81         [1] = "cpu",
82         [2] = "dsa",
83         [3] = "pci_pf",
84         [4] = "pci_vf",
85         [5] = "virtual",
86         [6] = "unused",
87         [7] = "pci_sf",
88 };
89
90 const char *devlink_port_flavour_str(enum devlink_port_flavour value)
91 {
92         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_port_flavour_strmap))
93                 return NULL;
94         return devlink_port_flavour_strmap[value];
95 }
96
97 static const char * const devlink_port_fn_state_strmap[] = {
98         [0] = "inactive",
99         [1] = "active",
100 };
101
102 const char *devlink_port_fn_state_str(enum devlink_port_fn_state value)
103 {
104         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_port_fn_state_strmap))
105                 return NULL;
106         return devlink_port_fn_state_strmap[value];
107 }
108
109 static const char * const devlink_port_fn_opstate_strmap[] = {
110         [0] = "detached",
111         [1] = "attached",
112 };
113
114 const char *devlink_port_fn_opstate_str(enum devlink_port_fn_opstate value)
115 {
116         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_port_fn_opstate_strmap))
117                 return NULL;
118         return devlink_port_fn_opstate_strmap[value];
119 }
120
121 static const char * const devlink_port_fn_attr_cap_strmap[] = {
122         [0] = "roce-bit",
123         [1] = "migratable-bit",
124         [2] = "ipsec-crypto-bit",
125         [3] = "ipsec-packet-bit",
126 };
127
128 const char *devlink_port_fn_attr_cap_str(enum devlink_port_fn_attr_cap value)
129 {
130         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_port_fn_attr_cap_strmap))
131                 return NULL;
132         return devlink_port_fn_attr_cap_strmap[value];
133 }
134
135 static const char * const devlink_sb_threshold_type_strmap[] = {
136         [0] = "static",
137         [1] = "dynamic",
138 };
139
140 const char *devlink_sb_threshold_type_str(enum devlink_sb_threshold_type value)
141 {
142         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_sb_threshold_type_strmap))
143                 return NULL;
144         return devlink_sb_threshold_type_strmap[value];
145 }
146
147 static const char * const devlink_eswitch_mode_strmap[] = {
148         [0] = "legacy",
149         [1] = "switchdev",
150 };
151
152 const char *devlink_eswitch_mode_str(enum devlink_eswitch_mode value)
153 {
154         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_eswitch_mode_strmap))
155                 return NULL;
156         return devlink_eswitch_mode_strmap[value];
157 }
158
159 static const char * const devlink_eswitch_inline_mode_strmap[] = {
160         [0] = "none",
161         [1] = "link",
162         [2] = "network",
163         [3] = "transport",
164 };
165
166 const char *
167 devlink_eswitch_inline_mode_str(enum devlink_eswitch_inline_mode value)
168 {
169         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_eswitch_inline_mode_strmap))
170                 return NULL;
171         return devlink_eswitch_inline_mode_strmap[value];
172 }
173
174 static const char * const devlink_eswitch_encap_mode_strmap[] = {
175         [0] = "none",
176         [1] = "basic",
177 };
178
179 const char *
180 devlink_eswitch_encap_mode_str(enum devlink_eswitch_encap_mode value)
181 {
182         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_eswitch_encap_mode_strmap))
183                 return NULL;
184         return devlink_eswitch_encap_mode_strmap[value];
185 }
186
187 static const char * const devlink_dpipe_match_type_strmap[] = {
188         [0] = "field-exact",
189 };
190
191 const char *devlink_dpipe_match_type_str(enum devlink_dpipe_match_type value)
192 {
193         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_dpipe_match_type_strmap))
194                 return NULL;
195         return devlink_dpipe_match_type_strmap[value];
196 }
197
198 static const char * const devlink_dpipe_action_type_strmap[] = {
199         [0] = "field-modify",
200 };
201
202 const char *devlink_dpipe_action_type_str(enum devlink_dpipe_action_type value)
203 {
204         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_dpipe_action_type_strmap))
205                 return NULL;
206         return devlink_dpipe_action_type_strmap[value];
207 }
208
209 static const char * const devlink_dpipe_field_mapping_type_strmap[] = {
210         [0] = "none",
211         [1] = "ifindex",
212 };
213
214 const char *
215 devlink_dpipe_field_mapping_type_str(enum devlink_dpipe_field_mapping_type value)
216 {
217         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_dpipe_field_mapping_type_strmap))
218                 return NULL;
219         return devlink_dpipe_field_mapping_type_strmap[value];
220 }
221
222 static const char * const devlink_resource_unit_strmap[] = {
223         [0] = "entry",
224 };
225
226 const char *devlink_resource_unit_str(enum devlink_resource_unit value)
227 {
228         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_resource_unit_strmap))
229                 return NULL;
230         return devlink_resource_unit_strmap[value];
231 }
232
233 static const char * const devlink_reload_action_strmap[] = {
234         [1] = "driver-reinit",
235         [2] = "fw-activate",
236 };
237
238 const char *devlink_reload_action_str(enum devlink_reload_action value)
239 {
240         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_reload_action_strmap))
241                 return NULL;
242         return devlink_reload_action_strmap[value];
243 }
244
245 static const char * const devlink_param_cmode_strmap[] = {
246         [0] = "runtime",
247         [1] = "driverinit",
248         [2] = "permanent",
249 };
250
251 const char *devlink_param_cmode_str(enum devlink_param_cmode value)
252 {
253         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_param_cmode_strmap))
254                 return NULL;
255         return devlink_param_cmode_strmap[value];
256 }
257
258 static const char * const devlink_flash_overwrite_strmap[] = {
259         [0] = "settings-bit",
260         [1] = "identifiers-bit",
261 };
262
263 const char *devlink_flash_overwrite_str(enum devlink_flash_overwrite value)
264 {
265         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_flash_overwrite_strmap))
266                 return NULL;
267         return devlink_flash_overwrite_strmap[value];
268 }
269
270 static const char * const devlink_trap_action_strmap[] = {
271         [0] = "drop",
272         [1] = "trap",
273         [2] = "mirror",
274 };
275
276 const char *devlink_trap_action_str(enum devlink_trap_action value)
277 {
278         if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_trap_action_strmap))
279                 return NULL;
280         return devlink_trap_action_strmap[value];
281 }
282
283 /* Policies */
284 struct ynl_policy_attr devlink_dl_dpipe_match_policy[DEVLINK_ATTR_MAX + 1] = {
285         [DEVLINK_ATTR_DPIPE_MATCH_TYPE] = { .name = "dpipe-match-type", .type = YNL_PT_U32, },
286         [DEVLINK_ATTR_DPIPE_HEADER_ID] = { .name = "dpipe-header-id", .type = YNL_PT_U32, },
287         [DEVLINK_ATTR_DPIPE_HEADER_GLOBAL] = { .name = "dpipe-header-global", .type = YNL_PT_U8, },
288         [DEVLINK_ATTR_DPIPE_HEADER_INDEX] = { .name = "dpipe-header-index", .type = YNL_PT_U32, },
289         [DEVLINK_ATTR_DPIPE_FIELD_ID] = { .name = "dpipe-field-id", .type = YNL_PT_U32, },
290 };
291
292 struct ynl_policy_nest devlink_dl_dpipe_match_nest = {
293         .max_attr = DEVLINK_ATTR_MAX,
294         .table = devlink_dl_dpipe_match_policy,
295 };
296
297 struct ynl_policy_attr devlink_dl_dpipe_match_value_policy[DEVLINK_ATTR_MAX + 1] = {
298         [DEVLINK_ATTR_DPIPE_MATCH] = { .name = "dpipe-match", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_match_nest, },
299         [DEVLINK_ATTR_DPIPE_VALUE] = { .name = "dpipe-value", .type = YNL_PT_BINARY,},
300         [DEVLINK_ATTR_DPIPE_VALUE_MASK] = { .name = "dpipe-value-mask", .type = YNL_PT_BINARY,},
301         [DEVLINK_ATTR_DPIPE_VALUE_MAPPING] = { .name = "dpipe-value-mapping", .type = YNL_PT_U32, },
302 };
303
304 struct ynl_policy_nest devlink_dl_dpipe_match_value_nest = {
305         .max_attr = DEVLINK_ATTR_MAX,
306         .table = devlink_dl_dpipe_match_value_policy,
307 };
308
309 struct ynl_policy_attr devlink_dl_dpipe_action_policy[DEVLINK_ATTR_MAX + 1] = {
310         [DEVLINK_ATTR_DPIPE_ACTION_TYPE] = { .name = "dpipe-action-type", .type = YNL_PT_U32, },
311         [DEVLINK_ATTR_DPIPE_HEADER_ID] = { .name = "dpipe-header-id", .type = YNL_PT_U32, },
312         [DEVLINK_ATTR_DPIPE_HEADER_GLOBAL] = { .name = "dpipe-header-global", .type = YNL_PT_U8, },
313         [DEVLINK_ATTR_DPIPE_HEADER_INDEX] = { .name = "dpipe-header-index", .type = YNL_PT_U32, },
314         [DEVLINK_ATTR_DPIPE_FIELD_ID] = { .name = "dpipe-field-id", .type = YNL_PT_U32, },
315 };
316
317 struct ynl_policy_nest devlink_dl_dpipe_action_nest = {
318         .max_attr = DEVLINK_ATTR_MAX,
319         .table = devlink_dl_dpipe_action_policy,
320 };
321
322 struct ynl_policy_attr devlink_dl_dpipe_action_value_policy[DEVLINK_ATTR_MAX + 1] = {
323         [DEVLINK_ATTR_DPIPE_ACTION] = { .name = "dpipe-action", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_action_nest, },
324         [DEVLINK_ATTR_DPIPE_VALUE] = { .name = "dpipe-value", .type = YNL_PT_BINARY,},
325         [DEVLINK_ATTR_DPIPE_VALUE_MASK] = { .name = "dpipe-value-mask", .type = YNL_PT_BINARY,},
326         [DEVLINK_ATTR_DPIPE_VALUE_MAPPING] = { .name = "dpipe-value-mapping", .type = YNL_PT_U32, },
327 };
328
329 struct ynl_policy_nest devlink_dl_dpipe_action_value_nest = {
330         .max_attr = DEVLINK_ATTR_MAX,
331         .table = devlink_dl_dpipe_action_value_policy,
332 };
333
334 struct ynl_policy_attr devlink_dl_dpipe_field_policy[DEVLINK_ATTR_MAX + 1] = {
335         [DEVLINK_ATTR_DPIPE_FIELD_NAME] = { .name = "dpipe-field-name", .type = YNL_PT_NUL_STR, },
336         [DEVLINK_ATTR_DPIPE_FIELD_ID] = { .name = "dpipe-field-id", .type = YNL_PT_U32, },
337         [DEVLINK_ATTR_DPIPE_FIELD_BITWIDTH] = { .name = "dpipe-field-bitwidth", .type = YNL_PT_U32, },
338         [DEVLINK_ATTR_DPIPE_FIELD_MAPPING_TYPE] = { .name = "dpipe-field-mapping-type", .type = YNL_PT_U32, },
339 };
340
341 struct ynl_policy_nest devlink_dl_dpipe_field_nest = {
342         .max_attr = DEVLINK_ATTR_MAX,
343         .table = devlink_dl_dpipe_field_policy,
344 };
345
346 struct ynl_policy_attr devlink_dl_resource_policy[DEVLINK_ATTR_MAX + 1] = {
347         [DEVLINK_ATTR_RESOURCE_NAME] = { .name = "resource-name", .type = YNL_PT_NUL_STR, },
348         [DEVLINK_ATTR_RESOURCE_ID] = { .name = "resource-id", .type = YNL_PT_U64, },
349         [DEVLINK_ATTR_RESOURCE_SIZE] = { .name = "resource-size", .type = YNL_PT_U64, },
350         [DEVLINK_ATTR_RESOURCE_SIZE_NEW] = { .name = "resource-size-new", .type = YNL_PT_U64, },
351         [DEVLINK_ATTR_RESOURCE_SIZE_VALID] = { .name = "resource-size-valid", .type = YNL_PT_U8, },
352         [DEVLINK_ATTR_RESOURCE_SIZE_MIN] = { .name = "resource-size-min", .type = YNL_PT_U64, },
353         [DEVLINK_ATTR_RESOURCE_SIZE_MAX] = { .name = "resource-size-max", .type = YNL_PT_U64, },
354         [DEVLINK_ATTR_RESOURCE_SIZE_GRAN] = { .name = "resource-size-gran", .type = YNL_PT_U64, },
355         [DEVLINK_ATTR_RESOURCE_UNIT] = { .name = "resource-unit", .type = YNL_PT_U8, },
356         [DEVLINK_ATTR_RESOURCE_OCC] = { .name = "resource-occ", .type = YNL_PT_U64, },
357 };
358
359 struct ynl_policy_nest devlink_dl_resource_nest = {
360         .max_attr = DEVLINK_ATTR_MAX,
361         .table = devlink_dl_resource_policy,
362 };
363
364 struct ynl_policy_attr devlink_dl_info_version_policy[DEVLINK_ATTR_MAX + 1] = {
365         [DEVLINK_ATTR_INFO_VERSION_NAME] = { .name = "info-version-name", .type = YNL_PT_NUL_STR, },
366         [DEVLINK_ATTR_INFO_VERSION_VALUE] = { .name = "info-version-value", .type = YNL_PT_NUL_STR, },
367 };
368
369 struct ynl_policy_nest devlink_dl_info_version_nest = {
370         .max_attr = DEVLINK_ATTR_MAX,
371         .table = devlink_dl_info_version_policy,
372 };
373
374 struct ynl_policy_attr devlink_dl_fmsg_policy[DEVLINK_ATTR_MAX + 1] = {
375         [DEVLINK_ATTR_FMSG_OBJ_NEST_START] = { .name = "fmsg-obj-nest-start", .type = YNL_PT_FLAG, },
376         [DEVLINK_ATTR_FMSG_PAIR_NEST_START] = { .name = "fmsg-pair-nest-start", .type = YNL_PT_FLAG, },
377         [DEVLINK_ATTR_FMSG_ARR_NEST_START] = { .name = "fmsg-arr-nest-start", .type = YNL_PT_FLAG, },
378         [DEVLINK_ATTR_FMSG_NEST_END] = { .name = "fmsg-nest-end", .type = YNL_PT_FLAG, },
379         [DEVLINK_ATTR_FMSG_OBJ_NAME] = { .name = "fmsg-obj-name", .type = YNL_PT_NUL_STR, },
380 };
381
382 struct ynl_policy_nest devlink_dl_fmsg_nest = {
383         .max_attr = DEVLINK_ATTR_MAX,
384         .table = devlink_dl_fmsg_policy,
385 };
386
387 struct ynl_policy_attr devlink_dl_port_function_policy[DEVLINK_PORT_FUNCTION_ATTR_MAX + 1] = {
388         [DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR] = { .name = "hw-addr", .type = YNL_PT_BINARY,},
389         [DEVLINK_PORT_FN_ATTR_STATE] = { .name = "state", .type = YNL_PT_U8, },
390         [DEVLINK_PORT_FN_ATTR_OPSTATE] = { .name = "opstate", .type = YNL_PT_U8, },
391         [DEVLINK_PORT_FN_ATTR_CAPS] = { .name = "caps", .type = YNL_PT_BITFIELD32, },
392 };
393
394 struct ynl_policy_nest devlink_dl_port_function_nest = {
395         .max_attr = DEVLINK_PORT_FUNCTION_ATTR_MAX,
396         .table = devlink_dl_port_function_policy,
397 };
398
399 struct ynl_policy_attr devlink_dl_reload_stats_entry_policy[DEVLINK_ATTR_MAX + 1] = {
400         [DEVLINK_ATTR_RELOAD_STATS_LIMIT] = { .name = "reload-stats-limit", .type = YNL_PT_U8, },
401         [DEVLINK_ATTR_RELOAD_STATS_VALUE] = { .name = "reload-stats-value", .type = YNL_PT_U32, },
402 };
403
404 struct ynl_policy_nest devlink_dl_reload_stats_entry_nest = {
405         .max_attr = DEVLINK_ATTR_MAX,
406         .table = devlink_dl_reload_stats_entry_policy,
407 };
408
409 struct ynl_policy_attr devlink_dl_reload_act_stats_policy[DEVLINK_ATTR_MAX + 1] = {
410         [DEVLINK_ATTR_RELOAD_STATS_ENTRY] = { .name = "reload-stats-entry", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_entry_nest, },
411 };
412
413 struct ynl_policy_nest devlink_dl_reload_act_stats_nest = {
414         .max_attr = DEVLINK_ATTR_MAX,
415         .table = devlink_dl_reload_act_stats_policy,
416 };
417
418 struct ynl_policy_attr devlink_dl_selftest_id_policy[DEVLINK_ATTR_SELFTEST_ID_MAX + 1] = {
419         [DEVLINK_ATTR_SELFTEST_ID_FLASH] = { .name = "flash", .type = YNL_PT_FLAG, },
420 };
421
422 struct ynl_policy_nest devlink_dl_selftest_id_nest = {
423         .max_attr = DEVLINK_ATTR_SELFTEST_ID_MAX,
424         .table = devlink_dl_selftest_id_policy,
425 };
426
427 struct ynl_policy_attr devlink_dl_dpipe_table_matches_policy[DEVLINK_ATTR_MAX + 1] = {
428         [DEVLINK_ATTR_DPIPE_MATCH] = { .name = "dpipe-match", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_match_nest, },
429 };
430
431 struct ynl_policy_nest devlink_dl_dpipe_table_matches_nest = {
432         .max_attr = DEVLINK_ATTR_MAX,
433         .table = devlink_dl_dpipe_table_matches_policy,
434 };
435
436 struct ynl_policy_attr devlink_dl_dpipe_table_actions_policy[DEVLINK_ATTR_MAX + 1] = {
437         [DEVLINK_ATTR_DPIPE_ACTION] = { .name = "dpipe-action", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_action_nest, },
438 };
439
440 struct ynl_policy_nest devlink_dl_dpipe_table_actions_nest = {
441         .max_attr = DEVLINK_ATTR_MAX,
442         .table = devlink_dl_dpipe_table_actions_policy,
443 };
444
445 struct ynl_policy_attr devlink_dl_dpipe_entry_match_values_policy[DEVLINK_ATTR_MAX + 1] = {
446         [DEVLINK_ATTR_DPIPE_MATCH_VALUE] = { .name = "dpipe-match-value", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_match_value_nest, },
447 };
448
449 struct ynl_policy_nest devlink_dl_dpipe_entry_match_values_nest = {
450         .max_attr = DEVLINK_ATTR_MAX,
451         .table = devlink_dl_dpipe_entry_match_values_policy,
452 };
453
454 struct ynl_policy_attr devlink_dl_dpipe_entry_action_values_policy[DEVLINK_ATTR_MAX + 1] = {
455         [DEVLINK_ATTR_DPIPE_ACTION_VALUE] = { .name = "dpipe-action-value", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_action_value_nest, },
456 };
457
458 struct ynl_policy_nest devlink_dl_dpipe_entry_action_values_nest = {
459         .max_attr = DEVLINK_ATTR_MAX,
460         .table = devlink_dl_dpipe_entry_action_values_policy,
461 };
462
463 struct ynl_policy_attr devlink_dl_dpipe_header_fields_policy[DEVLINK_ATTR_MAX + 1] = {
464         [DEVLINK_ATTR_DPIPE_FIELD] = { .name = "dpipe-field", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_field_nest, },
465 };
466
467 struct ynl_policy_nest devlink_dl_dpipe_header_fields_nest = {
468         .max_attr = DEVLINK_ATTR_MAX,
469         .table = devlink_dl_dpipe_header_fields_policy,
470 };
471
472 struct ynl_policy_attr devlink_dl_resource_list_policy[DEVLINK_ATTR_MAX + 1] = {
473         [DEVLINK_ATTR_RESOURCE] = { .name = "resource", .type = YNL_PT_NEST, .nest = &devlink_dl_resource_nest, },
474 };
475
476 struct ynl_policy_nest devlink_dl_resource_list_nest = {
477         .max_attr = DEVLINK_ATTR_MAX,
478         .table = devlink_dl_resource_list_policy,
479 };
480
481 struct ynl_policy_attr devlink_dl_reload_act_info_policy[DEVLINK_ATTR_MAX + 1] = {
482         [DEVLINK_ATTR_RELOAD_ACTION] = { .name = "reload-action", .type = YNL_PT_U8, },
483         [DEVLINK_ATTR_RELOAD_ACTION_STATS] = { .name = "reload-action-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_stats_nest, },
484 };
485
486 struct ynl_policy_nest devlink_dl_reload_act_info_nest = {
487         .max_attr = DEVLINK_ATTR_MAX,
488         .table = devlink_dl_reload_act_info_policy,
489 };
490
491 struct ynl_policy_attr devlink_dl_dpipe_table_policy[DEVLINK_ATTR_MAX + 1] = {
492         [DEVLINK_ATTR_DPIPE_TABLE_NAME] = { .name = "dpipe-table-name", .type = YNL_PT_NUL_STR, },
493         [DEVLINK_ATTR_DPIPE_TABLE_SIZE] = { .name = "dpipe-table-size", .type = YNL_PT_U64, },
494         [DEVLINK_ATTR_DPIPE_TABLE_MATCHES] = { .name = "dpipe-table-matches", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_table_matches_nest, },
495         [DEVLINK_ATTR_DPIPE_TABLE_ACTIONS] = { .name = "dpipe-table-actions", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_table_actions_nest, },
496         [DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED] = { .name = "dpipe-table-counters-enabled", .type = YNL_PT_U8, },
497         [DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID] = { .name = "dpipe-table-resource-id", .type = YNL_PT_U64, },
498         [DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS] = { .name = "dpipe-table-resource-units", .type = YNL_PT_U64, },
499 };
500
501 struct ynl_policy_nest devlink_dl_dpipe_table_nest = {
502         .max_attr = DEVLINK_ATTR_MAX,
503         .table = devlink_dl_dpipe_table_policy,
504 };
505
506 struct ynl_policy_attr devlink_dl_dpipe_entry_policy[DEVLINK_ATTR_MAX + 1] = {
507         [DEVLINK_ATTR_DPIPE_ENTRY_INDEX] = { .name = "dpipe-entry-index", .type = YNL_PT_U64, },
508         [DEVLINK_ATTR_DPIPE_ENTRY_MATCH_VALUES] = { .name = "dpipe-entry-match-values", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_entry_match_values_nest, },
509         [DEVLINK_ATTR_DPIPE_ENTRY_ACTION_VALUES] = { .name = "dpipe-entry-action-values", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_entry_action_values_nest, },
510         [DEVLINK_ATTR_DPIPE_ENTRY_COUNTER] = { .name = "dpipe-entry-counter", .type = YNL_PT_U64, },
511 };
512
513 struct ynl_policy_nest devlink_dl_dpipe_entry_nest = {
514         .max_attr = DEVLINK_ATTR_MAX,
515         .table = devlink_dl_dpipe_entry_policy,
516 };
517
518 struct ynl_policy_attr devlink_dl_dpipe_header_policy[DEVLINK_ATTR_MAX + 1] = {
519         [DEVLINK_ATTR_DPIPE_HEADER_NAME] = { .name = "dpipe-header-name", .type = YNL_PT_NUL_STR, },
520         [DEVLINK_ATTR_DPIPE_HEADER_ID] = { .name = "dpipe-header-id", .type = YNL_PT_U32, },
521         [DEVLINK_ATTR_DPIPE_HEADER_GLOBAL] = { .name = "dpipe-header-global", .type = YNL_PT_U8, },
522         [DEVLINK_ATTR_DPIPE_HEADER_FIELDS] = { .name = "dpipe-header-fields", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_header_fields_nest, },
523 };
524
525 struct ynl_policy_nest devlink_dl_dpipe_header_nest = {
526         .max_attr = DEVLINK_ATTR_MAX,
527         .table = devlink_dl_dpipe_header_policy,
528 };
529
530 struct ynl_policy_attr devlink_dl_reload_stats_policy[DEVLINK_ATTR_MAX + 1] = {
531         [DEVLINK_ATTR_RELOAD_ACTION_INFO] = { .name = "reload-action-info", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_info_nest, },
532 };
533
534 struct ynl_policy_nest devlink_dl_reload_stats_nest = {
535         .max_attr = DEVLINK_ATTR_MAX,
536         .table = devlink_dl_reload_stats_policy,
537 };
538
539 struct ynl_policy_attr devlink_dl_dpipe_tables_policy[DEVLINK_ATTR_MAX + 1] = {
540         [DEVLINK_ATTR_DPIPE_TABLE] = { .name = "dpipe-table", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_table_nest, },
541 };
542
543 struct ynl_policy_nest devlink_dl_dpipe_tables_nest = {
544         .max_attr = DEVLINK_ATTR_MAX,
545         .table = devlink_dl_dpipe_tables_policy,
546 };
547
548 struct ynl_policy_attr devlink_dl_dpipe_entries_policy[DEVLINK_ATTR_MAX + 1] = {
549         [DEVLINK_ATTR_DPIPE_ENTRY] = { .name = "dpipe-entry", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_entry_nest, },
550 };
551
552 struct ynl_policy_nest devlink_dl_dpipe_entries_nest = {
553         .max_attr = DEVLINK_ATTR_MAX,
554         .table = devlink_dl_dpipe_entries_policy,
555 };
556
557 struct ynl_policy_attr devlink_dl_dpipe_headers_policy[DEVLINK_ATTR_MAX + 1] = {
558         [DEVLINK_ATTR_DPIPE_HEADER] = { .name = "dpipe-header", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_header_nest, },
559 };
560
561 struct ynl_policy_nest devlink_dl_dpipe_headers_nest = {
562         .max_attr = DEVLINK_ATTR_MAX,
563         .table = devlink_dl_dpipe_headers_policy,
564 };
565
566 struct ynl_policy_attr devlink_dl_dev_stats_policy[DEVLINK_ATTR_MAX + 1] = {
567         [DEVLINK_ATTR_RELOAD_STATS] = { .name = "reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
568         [DEVLINK_ATTR_REMOTE_RELOAD_STATS] = { .name = "remote-reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
569 };
570
571 struct ynl_policy_nest devlink_dl_dev_stats_nest = {
572         .max_attr = DEVLINK_ATTR_MAX,
573         .table = devlink_dl_dev_stats_policy,
574 };
575
576 struct ynl_policy_attr devlink_policy[DEVLINK_ATTR_MAX + 1] = {
577         [DEVLINK_ATTR_BUS_NAME] = { .name = "bus-name", .type = YNL_PT_NUL_STR, },
578         [DEVLINK_ATTR_DEV_NAME] = { .name = "dev-name", .type = YNL_PT_NUL_STR, },
579         [DEVLINK_ATTR_PORT_INDEX] = { .name = "port-index", .type = YNL_PT_U32, },
580         [DEVLINK_ATTR_PORT_TYPE] = { .name = "port-type", .type = YNL_PT_U16, },
581         [DEVLINK_ATTR_PORT_SPLIT_COUNT] = { .name = "port-split-count", .type = YNL_PT_U32, },
582         [DEVLINK_ATTR_SB_INDEX] = { .name = "sb-index", .type = YNL_PT_U32, },
583         [DEVLINK_ATTR_SB_POOL_INDEX] = { .name = "sb-pool-index", .type = YNL_PT_U16, },
584         [DEVLINK_ATTR_SB_POOL_TYPE] = { .name = "sb-pool-type", .type = YNL_PT_U8, },
585         [DEVLINK_ATTR_SB_POOL_SIZE] = { .name = "sb-pool-size", .type = YNL_PT_U32, },
586         [DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE] = { .name = "sb-pool-threshold-type", .type = YNL_PT_U8, },
587         [DEVLINK_ATTR_SB_THRESHOLD] = { .name = "sb-threshold", .type = YNL_PT_U32, },
588         [DEVLINK_ATTR_SB_TC_INDEX] = { .name = "sb-tc-index", .type = YNL_PT_U16, },
589         [DEVLINK_ATTR_ESWITCH_MODE] = { .name = "eswitch-mode", .type = YNL_PT_U16, },
590         [DEVLINK_ATTR_ESWITCH_INLINE_MODE] = { .name = "eswitch-inline-mode", .type = YNL_PT_U16, },
591         [DEVLINK_ATTR_DPIPE_TABLES] = { .name = "dpipe-tables", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_tables_nest, },
592         [DEVLINK_ATTR_DPIPE_TABLE] = { .name = "dpipe-table", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_table_nest, },
593         [DEVLINK_ATTR_DPIPE_TABLE_NAME] = { .name = "dpipe-table-name", .type = YNL_PT_NUL_STR, },
594         [DEVLINK_ATTR_DPIPE_TABLE_SIZE] = { .name = "dpipe-table-size", .type = YNL_PT_U64, },
595         [DEVLINK_ATTR_DPIPE_TABLE_MATCHES] = { .name = "dpipe-table-matches", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_table_matches_nest, },
596         [DEVLINK_ATTR_DPIPE_TABLE_ACTIONS] = { .name = "dpipe-table-actions", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_table_actions_nest, },
597         [DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED] = { .name = "dpipe-table-counters-enabled", .type = YNL_PT_U8, },
598         [DEVLINK_ATTR_DPIPE_ENTRIES] = { .name = "dpipe-entries", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_entries_nest, },
599         [DEVLINK_ATTR_DPIPE_ENTRY] = { .name = "dpipe-entry", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_entry_nest, },
600         [DEVLINK_ATTR_DPIPE_ENTRY_INDEX] = { .name = "dpipe-entry-index", .type = YNL_PT_U64, },
601         [DEVLINK_ATTR_DPIPE_ENTRY_MATCH_VALUES] = { .name = "dpipe-entry-match-values", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_entry_match_values_nest, },
602         [DEVLINK_ATTR_DPIPE_ENTRY_ACTION_VALUES] = { .name = "dpipe-entry-action-values", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_entry_action_values_nest, },
603         [DEVLINK_ATTR_DPIPE_ENTRY_COUNTER] = { .name = "dpipe-entry-counter", .type = YNL_PT_U64, },
604         [DEVLINK_ATTR_DPIPE_MATCH] = { .name = "dpipe-match", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_match_nest, },
605         [DEVLINK_ATTR_DPIPE_MATCH_VALUE] = { .name = "dpipe-match-value", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_match_value_nest, },
606         [DEVLINK_ATTR_DPIPE_MATCH_TYPE] = { .name = "dpipe-match-type", .type = YNL_PT_U32, },
607         [DEVLINK_ATTR_DPIPE_ACTION] = { .name = "dpipe-action", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_action_nest, },
608         [DEVLINK_ATTR_DPIPE_ACTION_VALUE] = { .name = "dpipe-action-value", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_action_value_nest, },
609         [DEVLINK_ATTR_DPIPE_ACTION_TYPE] = { .name = "dpipe-action-type", .type = YNL_PT_U32, },
610         [DEVLINK_ATTR_DPIPE_VALUE] = { .name = "dpipe-value", .type = YNL_PT_BINARY,},
611         [DEVLINK_ATTR_DPIPE_VALUE_MASK] = { .name = "dpipe-value-mask", .type = YNL_PT_BINARY,},
612         [DEVLINK_ATTR_DPIPE_VALUE_MAPPING] = { .name = "dpipe-value-mapping", .type = YNL_PT_U32, },
613         [DEVLINK_ATTR_DPIPE_HEADERS] = { .name = "dpipe-headers", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_headers_nest, },
614         [DEVLINK_ATTR_DPIPE_HEADER] = { .name = "dpipe-header", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_header_nest, },
615         [DEVLINK_ATTR_DPIPE_HEADER_NAME] = { .name = "dpipe-header-name", .type = YNL_PT_NUL_STR, },
616         [DEVLINK_ATTR_DPIPE_HEADER_ID] = { .name = "dpipe-header-id", .type = YNL_PT_U32, },
617         [DEVLINK_ATTR_DPIPE_HEADER_FIELDS] = { .name = "dpipe-header-fields", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_header_fields_nest, },
618         [DEVLINK_ATTR_DPIPE_HEADER_GLOBAL] = { .name = "dpipe-header-global", .type = YNL_PT_U8, },
619         [DEVLINK_ATTR_DPIPE_HEADER_INDEX] = { .name = "dpipe-header-index", .type = YNL_PT_U32, },
620         [DEVLINK_ATTR_DPIPE_FIELD] = { .name = "dpipe-field", .type = YNL_PT_NEST, .nest = &devlink_dl_dpipe_field_nest, },
621         [DEVLINK_ATTR_DPIPE_FIELD_NAME] = { .name = "dpipe-field-name", .type = YNL_PT_NUL_STR, },
622         [DEVLINK_ATTR_DPIPE_FIELD_ID] = { .name = "dpipe-field-id", .type = YNL_PT_U32, },
623         [DEVLINK_ATTR_DPIPE_FIELD_BITWIDTH] = { .name = "dpipe-field-bitwidth", .type = YNL_PT_U32, },
624         [DEVLINK_ATTR_DPIPE_FIELD_MAPPING_TYPE] = { .name = "dpipe-field-mapping-type", .type = YNL_PT_U32, },
625         [DEVLINK_ATTR_PAD] = { .name = "pad", .type = YNL_PT_IGNORE, },
626         [DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = { .name = "eswitch-encap-mode", .type = YNL_PT_U8, },
627         [DEVLINK_ATTR_RESOURCE_LIST] = { .name = "resource-list", .type = YNL_PT_NEST, .nest = &devlink_dl_resource_list_nest, },
628         [DEVLINK_ATTR_RESOURCE] = { .name = "resource", .type = YNL_PT_NEST, .nest = &devlink_dl_resource_nest, },
629         [DEVLINK_ATTR_RESOURCE_NAME] = { .name = "resource-name", .type = YNL_PT_NUL_STR, },
630         [DEVLINK_ATTR_RESOURCE_ID] = { .name = "resource-id", .type = YNL_PT_U64, },
631         [DEVLINK_ATTR_RESOURCE_SIZE] = { .name = "resource-size", .type = YNL_PT_U64, },
632         [DEVLINK_ATTR_RESOURCE_SIZE_NEW] = { .name = "resource-size-new", .type = YNL_PT_U64, },
633         [DEVLINK_ATTR_RESOURCE_SIZE_VALID] = { .name = "resource-size-valid", .type = YNL_PT_U8, },
634         [DEVLINK_ATTR_RESOURCE_SIZE_MIN] = { .name = "resource-size-min", .type = YNL_PT_U64, },
635         [DEVLINK_ATTR_RESOURCE_SIZE_MAX] = { .name = "resource-size-max", .type = YNL_PT_U64, },
636         [DEVLINK_ATTR_RESOURCE_SIZE_GRAN] = { .name = "resource-size-gran", .type = YNL_PT_U64, },
637         [DEVLINK_ATTR_RESOURCE_UNIT] = { .name = "resource-unit", .type = YNL_PT_U8, },
638         [DEVLINK_ATTR_RESOURCE_OCC] = { .name = "resource-occ", .type = YNL_PT_U64, },
639         [DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID] = { .name = "dpipe-table-resource-id", .type = YNL_PT_U64, },
640         [DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS] = { .name = "dpipe-table-resource-units", .type = YNL_PT_U64, },
641         [DEVLINK_ATTR_PORT_FLAVOUR] = { .name = "port-flavour", .type = YNL_PT_U16, },
642         [DEVLINK_ATTR_PARAM_NAME] = { .name = "param-name", .type = YNL_PT_NUL_STR, },
643         [DEVLINK_ATTR_PARAM_TYPE] = { .name = "param-type", .type = YNL_PT_U8, },
644         [DEVLINK_ATTR_PARAM_VALUE_CMODE] = { .name = "param-value-cmode", .type = YNL_PT_U8, },
645         [DEVLINK_ATTR_REGION_NAME] = { .name = "region-name", .type = YNL_PT_NUL_STR, },
646         [DEVLINK_ATTR_REGION_SNAPSHOT_ID] = { .name = "region-snapshot-id", .type = YNL_PT_U32, },
647         [DEVLINK_ATTR_REGION_CHUNK_ADDR] = { .name = "region-chunk-addr", .type = YNL_PT_U64, },
648         [DEVLINK_ATTR_REGION_CHUNK_LEN] = { .name = "region-chunk-len", .type = YNL_PT_U64, },
649         [DEVLINK_ATTR_INFO_DRIVER_NAME] = { .name = "info-driver-name", .type = YNL_PT_NUL_STR, },
650         [DEVLINK_ATTR_INFO_SERIAL_NUMBER] = { .name = "info-serial-number", .type = YNL_PT_NUL_STR, },
651         [DEVLINK_ATTR_INFO_VERSION_FIXED] = { .name = "info-version-fixed", .type = YNL_PT_NEST, .nest = &devlink_dl_info_version_nest, },
652         [DEVLINK_ATTR_INFO_VERSION_RUNNING] = { .name = "info-version-running", .type = YNL_PT_NEST, .nest = &devlink_dl_info_version_nest, },
653         [DEVLINK_ATTR_INFO_VERSION_STORED] = { .name = "info-version-stored", .type = YNL_PT_NEST, .nest = &devlink_dl_info_version_nest, },
654         [DEVLINK_ATTR_INFO_VERSION_NAME] = { .name = "info-version-name", .type = YNL_PT_NUL_STR, },
655         [DEVLINK_ATTR_INFO_VERSION_VALUE] = { .name = "info-version-value", .type = YNL_PT_NUL_STR, },
656         [DEVLINK_ATTR_FMSG] = { .name = "fmsg", .type = YNL_PT_NEST, .nest = &devlink_dl_fmsg_nest, },
657         [DEVLINK_ATTR_FMSG_OBJ_NEST_START] = { .name = "fmsg-obj-nest-start", .type = YNL_PT_FLAG, },
658         [DEVLINK_ATTR_FMSG_PAIR_NEST_START] = { .name = "fmsg-pair-nest-start", .type = YNL_PT_FLAG, },
659         [DEVLINK_ATTR_FMSG_ARR_NEST_START] = { .name = "fmsg-arr-nest-start", .type = YNL_PT_FLAG, },
660         [DEVLINK_ATTR_FMSG_NEST_END] = { .name = "fmsg-nest-end", .type = YNL_PT_FLAG, },
661         [DEVLINK_ATTR_FMSG_OBJ_NAME] = { .name = "fmsg-obj-name", .type = YNL_PT_NUL_STR, },
662         [DEVLINK_ATTR_HEALTH_REPORTER_NAME] = { .name = "health-reporter-name", .type = YNL_PT_NUL_STR, },
663         [DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] = { .name = "health-reporter-graceful-period", .type = YNL_PT_U64, },
664         [DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER] = { .name = "health-reporter-auto-recover", .type = YNL_PT_U8, },
665         [DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME] = { .name = "flash-update-file-name", .type = YNL_PT_NUL_STR, },
666         [DEVLINK_ATTR_FLASH_UPDATE_COMPONENT] = { .name = "flash-update-component", .type = YNL_PT_NUL_STR, },
667         [DEVLINK_ATTR_PORT_PCI_PF_NUMBER] = { .name = "port-pci-pf-number", .type = YNL_PT_U16, },
668         [DEVLINK_ATTR_TRAP_NAME] = { .name = "trap-name", .type = YNL_PT_NUL_STR, },
669         [DEVLINK_ATTR_TRAP_ACTION] = { .name = "trap-action", .type = YNL_PT_U8, },
670         [DEVLINK_ATTR_TRAP_GROUP_NAME] = { .name = "trap-group-name", .type = YNL_PT_NUL_STR, },
671         [DEVLINK_ATTR_RELOAD_FAILED] = { .name = "reload-failed", .type = YNL_PT_U8, },
672         [DEVLINK_ATTR_NETNS_FD] = { .name = "netns-fd", .type = YNL_PT_U32, },
673         [DEVLINK_ATTR_NETNS_PID] = { .name = "netns-pid", .type = YNL_PT_U32, },
674         [DEVLINK_ATTR_NETNS_ID] = { .name = "netns-id", .type = YNL_PT_U32, },
675         [DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP] = { .name = "health-reporter-auto-dump", .type = YNL_PT_U8, },
676         [DEVLINK_ATTR_TRAP_POLICER_ID] = { .name = "trap-policer-id", .type = YNL_PT_U32, },
677         [DEVLINK_ATTR_TRAP_POLICER_RATE] = { .name = "trap-policer-rate", .type = YNL_PT_U64, },
678         [DEVLINK_ATTR_TRAP_POLICER_BURST] = { .name = "trap-policer-burst", .type = YNL_PT_U64, },
679         [DEVLINK_ATTR_PORT_FUNCTION] = { .name = "port-function", .type = YNL_PT_NEST, .nest = &devlink_dl_port_function_nest, },
680         [DEVLINK_ATTR_PORT_CONTROLLER_NUMBER] = { .name = "port-controller-number", .type = YNL_PT_U32, },
681         [DEVLINK_ATTR_FLASH_UPDATE_OVERWRITE_MASK] = { .name = "flash-update-overwrite-mask", .type = YNL_PT_BITFIELD32, },
682         [DEVLINK_ATTR_RELOAD_ACTION] = { .name = "reload-action", .type = YNL_PT_U8, },
683         [DEVLINK_ATTR_RELOAD_ACTIONS_PERFORMED] = { .name = "reload-actions-performed", .type = YNL_PT_BITFIELD32, },
684         [DEVLINK_ATTR_RELOAD_LIMITS] = { .name = "reload-limits", .type = YNL_PT_BITFIELD32, },
685         [DEVLINK_ATTR_DEV_STATS] = { .name = "dev-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_dev_stats_nest, },
686         [DEVLINK_ATTR_RELOAD_STATS] = { .name = "reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
687         [DEVLINK_ATTR_RELOAD_STATS_ENTRY] = { .name = "reload-stats-entry", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_entry_nest, },
688         [DEVLINK_ATTR_RELOAD_STATS_LIMIT] = { .name = "reload-stats-limit", .type = YNL_PT_U8, },
689         [DEVLINK_ATTR_RELOAD_STATS_VALUE] = { .name = "reload-stats-value", .type = YNL_PT_U32, },
690         [DEVLINK_ATTR_REMOTE_RELOAD_STATS] = { .name = "remote-reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
691         [DEVLINK_ATTR_RELOAD_ACTION_INFO] = { .name = "reload-action-info", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_info_nest, },
692         [DEVLINK_ATTR_RELOAD_ACTION_STATS] = { .name = "reload-action-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_stats_nest, },
693         [DEVLINK_ATTR_PORT_PCI_SF_NUMBER] = { .name = "port-pci-sf-number", .type = YNL_PT_U32, },
694         [DEVLINK_ATTR_RATE_TX_SHARE] = { .name = "rate-tx-share", .type = YNL_PT_U64, },
695         [DEVLINK_ATTR_RATE_TX_MAX] = { .name = "rate-tx-max", .type = YNL_PT_U64, },
696         [DEVLINK_ATTR_RATE_NODE_NAME] = { .name = "rate-node-name", .type = YNL_PT_NUL_STR, },
697         [DEVLINK_ATTR_RATE_PARENT_NODE_NAME] = { .name = "rate-parent-node-name", .type = YNL_PT_NUL_STR, },
698         [DEVLINK_ATTR_LINECARD_INDEX] = { .name = "linecard-index", .type = YNL_PT_U32, },
699         [DEVLINK_ATTR_LINECARD_TYPE] = { .name = "linecard-type", .type = YNL_PT_NUL_STR, },
700         [DEVLINK_ATTR_SELFTESTS] = { .name = "selftests", .type = YNL_PT_NEST, .nest = &devlink_dl_selftest_id_nest, },
701         [DEVLINK_ATTR_RATE_TX_PRIORITY] = { .name = "rate-tx-priority", .type = YNL_PT_U32, },
702         [DEVLINK_ATTR_RATE_TX_WEIGHT] = { .name = "rate-tx-weight", .type = YNL_PT_U32, },
703         [DEVLINK_ATTR_REGION_DIRECT] = { .name = "region-direct", .type = YNL_PT_FLAG, },
704 };
705
706 struct ynl_policy_nest devlink_nest = {
707         .max_attr = DEVLINK_ATTR_MAX,
708         .table = devlink_policy,
709 };
710
711 /* Common nested types */
712 void devlink_dl_dpipe_match_free(struct devlink_dl_dpipe_match *obj)
713 {
714 }
715
716 int devlink_dl_dpipe_match_parse(struct ynl_parse_arg *yarg,
717                                  const struct nlattr *nested)
718 {
719         struct devlink_dl_dpipe_match *dst = yarg->data;
720         const struct nlattr *attr;
721
722         mnl_attr_for_each_nested(attr, nested) {
723                 unsigned int type = mnl_attr_get_type(attr);
724
725                 if (type == DEVLINK_ATTR_DPIPE_MATCH_TYPE) {
726                         if (ynl_attr_validate(yarg, attr))
727                                 return MNL_CB_ERROR;
728                         dst->_present.dpipe_match_type = 1;
729                         dst->dpipe_match_type = mnl_attr_get_u32(attr);
730                 } else if (type == DEVLINK_ATTR_DPIPE_HEADER_ID) {
731                         if (ynl_attr_validate(yarg, attr))
732                                 return MNL_CB_ERROR;
733                         dst->_present.dpipe_header_id = 1;
734                         dst->dpipe_header_id = mnl_attr_get_u32(attr);
735                 } else if (type == DEVLINK_ATTR_DPIPE_HEADER_GLOBAL) {
736                         if (ynl_attr_validate(yarg, attr))
737                                 return MNL_CB_ERROR;
738                         dst->_present.dpipe_header_global = 1;
739                         dst->dpipe_header_global = mnl_attr_get_u8(attr);
740                 } else if (type == DEVLINK_ATTR_DPIPE_HEADER_INDEX) {
741                         if (ynl_attr_validate(yarg, attr))
742                                 return MNL_CB_ERROR;
743                         dst->_present.dpipe_header_index = 1;
744                         dst->dpipe_header_index = mnl_attr_get_u32(attr);
745                 } else if (type == DEVLINK_ATTR_DPIPE_FIELD_ID) {
746                         if (ynl_attr_validate(yarg, attr))
747                                 return MNL_CB_ERROR;
748                         dst->_present.dpipe_field_id = 1;
749                         dst->dpipe_field_id = mnl_attr_get_u32(attr);
750                 }
751         }
752
753         return 0;
754 }
755
756 void
757 devlink_dl_dpipe_match_value_free(struct devlink_dl_dpipe_match_value *obj)
758 {
759         unsigned int i;
760
761         for (i = 0; i < obj->n_dpipe_match; i++)
762                 devlink_dl_dpipe_match_free(&obj->dpipe_match[i]);
763         free(obj->dpipe_match);
764         free(obj->dpipe_value);
765         free(obj->dpipe_value_mask);
766 }
767
768 int devlink_dl_dpipe_match_value_parse(struct ynl_parse_arg *yarg,
769                                        const struct nlattr *nested)
770 {
771         struct devlink_dl_dpipe_match_value *dst = yarg->data;
772         unsigned int n_dpipe_match = 0;
773         const struct nlattr *attr;
774         struct ynl_parse_arg parg;
775         int i;
776
777         parg.ys = yarg->ys;
778
779         if (dst->dpipe_match)
780                 return ynl_error_parse(yarg, "attribute already present (dl-dpipe-match-value.dpipe-match)");
781
782         mnl_attr_for_each_nested(attr, nested) {
783                 unsigned int type = mnl_attr_get_type(attr);
784
785                 if (type == DEVLINK_ATTR_DPIPE_MATCH) {
786                         n_dpipe_match++;
787                 } else if (type == DEVLINK_ATTR_DPIPE_VALUE) {
788                         unsigned int len;
789
790                         if (ynl_attr_validate(yarg, attr))
791                                 return MNL_CB_ERROR;
792
793                         len = mnl_attr_get_payload_len(attr);
794                         dst->_present.dpipe_value_len = len;
795                         dst->dpipe_value = malloc(len);
796                         memcpy(dst->dpipe_value, mnl_attr_get_payload(attr), len);
797                 } else if (type == DEVLINK_ATTR_DPIPE_VALUE_MASK) {
798                         unsigned int len;
799
800                         if (ynl_attr_validate(yarg, attr))
801                                 return MNL_CB_ERROR;
802
803                         len = mnl_attr_get_payload_len(attr);
804                         dst->_present.dpipe_value_mask_len = len;
805                         dst->dpipe_value_mask = malloc(len);
806                         memcpy(dst->dpipe_value_mask, mnl_attr_get_payload(attr), len);
807                 } else if (type == DEVLINK_ATTR_DPIPE_VALUE_MAPPING) {
808                         if (ynl_attr_validate(yarg, attr))
809                                 return MNL_CB_ERROR;
810                         dst->_present.dpipe_value_mapping = 1;
811                         dst->dpipe_value_mapping = mnl_attr_get_u32(attr);
812                 }
813         }
814
815         if (n_dpipe_match) {
816                 dst->dpipe_match = calloc(n_dpipe_match, sizeof(*dst->dpipe_match));
817                 dst->n_dpipe_match = n_dpipe_match;
818                 i = 0;
819                 parg.rsp_policy = &devlink_dl_dpipe_match_nest;
820                 mnl_attr_for_each_nested(attr, nested) {
821                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DPIPE_MATCH) {
822                                 parg.data = &dst->dpipe_match[i];
823                                 if (devlink_dl_dpipe_match_parse(&parg, attr))
824                                         return MNL_CB_ERROR;
825                                 i++;
826                         }
827                 }
828         }
829
830         return 0;
831 }
832
833 void devlink_dl_dpipe_action_free(struct devlink_dl_dpipe_action *obj)
834 {
835 }
836
837 int devlink_dl_dpipe_action_parse(struct ynl_parse_arg *yarg,
838                                   const struct nlattr *nested)
839 {
840         struct devlink_dl_dpipe_action *dst = yarg->data;
841         const struct nlattr *attr;
842
843         mnl_attr_for_each_nested(attr, nested) {
844                 unsigned int type = mnl_attr_get_type(attr);
845
846                 if (type == DEVLINK_ATTR_DPIPE_ACTION_TYPE) {
847                         if (ynl_attr_validate(yarg, attr))
848                                 return MNL_CB_ERROR;
849                         dst->_present.dpipe_action_type = 1;
850                         dst->dpipe_action_type = mnl_attr_get_u32(attr);
851                 } else if (type == DEVLINK_ATTR_DPIPE_HEADER_ID) {
852                         if (ynl_attr_validate(yarg, attr))
853                                 return MNL_CB_ERROR;
854                         dst->_present.dpipe_header_id = 1;
855                         dst->dpipe_header_id = mnl_attr_get_u32(attr);
856                 } else if (type == DEVLINK_ATTR_DPIPE_HEADER_GLOBAL) {
857                         if (ynl_attr_validate(yarg, attr))
858                                 return MNL_CB_ERROR;
859                         dst->_present.dpipe_header_global = 1;
860                         dst->dpipe_header_global = mnl_attr_get_u8(attr);
861                 } else if (type == DEVLINK_ATTR_DPIPE_HEADER_INDEX) {
862                         if (ynl_attr_validate(yarg, attr))
863                                 return MNL_CB_ERROR;
864                         dst->_present.dpipe_header_index = 1;
865                         dst->dpipe_header_index = mnl_attr_get_u32(attr);
866                 } else if (type == DEVLINK_ATTR_DPIPE_FIELD_ID) {
867                         if (ynl_attr_validate(yarg, attr))
868                                 return MNL_CB_ERROR;
869                         dst->_present.dpipe_field_id = 1;
870                         dst->dpipe_field_id = mnl_attr_get_u32(attr);
871                 }
872         }
873
874         return 0;
875 }
876
877 void
878 devlink_dl_dpipe_action_value_free(struct devlink_dl_dpipe_action_value *obj)
879 {
880         unsigned int i;
881
882         for (i = 0; i < obj->n_dpipe_action; i++)
883                 devlink_dl_dpipe_action_free(&obj->dpipe_action[i]);
884         free(obj->dpipe_action);
885         free(obj->dpipe_value);
886         free(obj->dpipe_value_mask);
887 }
888
889 int devlink_dl_dpipe_action_value_parse(struct ynl_parse_arg *yarg,
890                                         const struct nlattr *nested)
891 {
892         struct devlink_dl_dpipe_action_value *dst = yarg->data;
893         unsigned int n_dpipe_action = 0;
894         const struct nlattr *attr;
895         struct ynl_parse_arg parg;
896         int i;
897
898         parg.ys = yarg->ys;
899
900         if (dst->dpipe_action)
901                 return ynl_error_parse(yarg, "attribute already present (dl-dpipe-action-value.dpipe-action)");
902
903         mnl_attr_for_each_nested(attr, nested) {
904                 unsigned int type = mnl_attr_get_type(attr);
905
906                 if (type == DEVLINK_ATTR_DPIPE_ACTION) {
907                         n_dpipe_action++;
908                 } else if (type == DEVLINK_ATTR_DPIPE_VALUE) {
909                         unsigned int len;
910
911                         if (ynl_attr_validate(yarg, attr))
912                                 return MNL_CB_ERROR;
913
914                         len = mnl_attr_get_payload_len(attr);
915                         dst->_present.dpipe_value_len = len;
916                         dst->dpipe_value = malloc(len);
917                         memcpy(dst->dpipe_value, mnl_attr_get_payload(attr), len);
918                 } else if (type == DEVLINK_ATTR_DPIPE_VALUE_MASK) {
919                         unsigned int len;
920
921                         if (ynl_attr_validate(yarg, attr))
922                                 return MNL_CB_ERROR;
923
924                         len = mnl_attr_get_payload_len(attr);
925                         dst->_present.dpipe_value_mask_len = len;
926                         dst->dpipe_value_mask = malloc(len);
927                         memcpy(dst->dpipe_value_mask, mnl_attr_get_payload(attr), len);
928                 } else if (type == DEVLINK_ATTR_DPIPE_VALUE_MAPPING) {
929                         if (ynl_attr_validate(yarg, attr))
930                                 return MNL_CB_ERROR;
931                         dst->_present.dpipe_value_mapping = 1;
932                         dst->dpipe_value_mapping = mnl_attr_get_u32(attr);
933                 }
934         }
935
936         if (n_dpipe_action) {
937                 dst->dpipe_action = calloc(n_dpipe_action, sizeof(*dst->dpipe_action));
938                 dst->n_dpipe_action = n_dpipe_action;
939                 i = 0;
940                 parg.rsp_policy = &devlink_dl_dpipe_action_nest;
941                 mnl_attr_for_each_nested(attr, nested) {
942                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DPIPE_ACTION) {
943                                 parg.data = &dst->dpipe_action[i];
944                                 if (devlink_dl_dpipe_action_parse(&parg, attr))
945                                         return MNL_CB_ERROR;
946                                 i++;
947                         }
948                 }
949         }
950
951         return 0;
952 }
953
954 void devlink_dl_dpipe_field_free(struct devlink_dl_dpipe_field *obj)
955 {
956         free(obj->dpipe_field_name);
957 }
958
959 int devlink_dl_dpipe_field_parse(struct ynl_parse_arg *yarg,
960                                  const struct nlattr *nested)
961 {
962         struct devlink_dl_dpipe_field *dst = yarg->data;
963         const struct nlattr *attr;
964
965         mnl_attr_for_each_nested(attr, nested) {
966                 unsigned int type = mnl_attr_get_type(attr);
967
968                 if (type == DEVLINK_ATTR_DPIPE_FIELD_NAME) {
969                         unsigned int len;
970
971                         if (ynl_attr_validate(yarg, attr))
972                                 return MNL_CB_ERROR;
973
974                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
975                         dst->_present.dpipe_field_name_len = len;
976                         dst->dpipe_field_name = malloc(len + 1);
977                         memcpy(dst->dpipe_field_name, mnl_attr_get_str(attr), len);
978                         dst->dpipe_field_name[len] = 0;
979                 } else if (type == DEVLINK_ATTR_DPIPE_FIELD_ID) {
980                         if (ynl_attr_validate(yarg, attr))
981                                 return MNL_CB_ERROR;
982                         dst->_present.dpipe_field_id = 1;
983                         dst->dpipe_field_id = mnl_attr_get_u32(attr);
984                 } else if (type == DEVLINK_ATTR_DPIPE_FIELD_BITWIDTH) {
985                         if (ynl_attr_validate(yarg, attr))
986                                 return MNL_CB_ERROR;
987                         dst->_present.dpipe_field_bitwidth = 1;
988                         dst->dpipe_field_bitwidth = mnl_attr_get_u32(attr);
989                 } else if (type == DEVLINK_ATTR_DPIPE_FIELD_MAPPING_TYPE) {
990                         if (ynl_attr_validate(yarg, attr))
991                                 return MNL_CB_ERROR;
992                         dst->_present.dpipe_field_mapping_type = 1;
993                         dst->dpipe_field_mapping_type = mnl_attr_get_u32(attr);
994                 }
995         }
996
997         return 0;
998 }
999
1000 void devlink_dl_resource_free(struct devlink_dl_resource *obj)
1001 {
1002         free(obj->resource_name);
1003 }
1004
1005 int devlink_dl_resource_parse(struct ynl_parse_arg *yarg,
1006                               const struct nlattr *nested)
1007 {
1008         struct devlink_dl_resource *dst = yarg->data;
1009         const struct nlattr *attr;
1010
1011         mnl_attr_for_each_nested(attr, nested) {
1012                 unsigned int type = mnl_attr_get_type(attr);
1013
1014                 if (type == DEVLINK_ATTR_RESOURCE_NAME) {
1015                         unsigned int len;
1016
1017                         if (ynl_attr_validate(yarg, attr))
1018                                 return MNL_CB_ERROR;
1019
1020                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1021                         dst->_present.resource_name_len = len;
1022                         dst->resource_name = malloc(len + 1);
1023                         memcpy(dst->resource_name, mnl_attr_get_str(attr), len);
1024                         dst->resource_name[len] = 0;
1025                 } else if (type == DEVLINK_ATTR_RESOURCE_ID) {
1026                         if (ynl_attr_validate(yarg, attr))
1027                                 return MNL_CB_ERROR;
1028                         dst->_present.resource_id = 1;
1029                         dst->resource_id = mnl_attr_get_u64(attr);
1030                 } else if (type == DEVLINK_ATTR_RESOURCE_SIZE) {
1031                         if (ynl_attr_validate(yarg, attr))
1032                                 return MNL_CB_ERROR;
1033                         dst->_present.resource_size = 1;
1034                         dst->resource_size = mnl_attr_get_u64(attr);
1035                 } else if (type == DEVLINK_ATTR_RESOURCE_SIZE_NEW) {
1036                         if (ynl_attr_validate(yarg, attr))
1037                                 return MNL_CB_ERROR;
1038                         dst->_present.resource_size_new = 1;
1039                         dst->resource_size_new = mnl_attr_get_u64(attr);
1040                 } else if (type == DEVLINK_ATTR_RESOURCE_SIZE_VALID) {
1041                         if (ynl_attr_validate(yarg, attr))
1042                                 return MNL_CB_ERROR;
1043                         dst->_present.resource_size_valid = 1;
1044                         dst->resource_size_valid = mnl_attr_get_u8(attr);
1045                 } else if (type == DEVLINK_ATTR_RESOURCE_SIZE_MIN) {
1046                         if (ynl_attr_validate(yarg, attr))
1047                                 return MNL_CB_ERROR;
1048                         dst->_present.resource_size_min = 1;
1049                         dst->resource_size_min = mnl_attr_get_u64(attr);
1050                 } else if (type == DEVLINK_ATTR_RESOURCE_SIZE_MAX) {
1051                         if (ynl_attr_validate(yarg, attr))
1052                                 return MNL_CB_ERROR;
1053                         dst->_present.resource_size_max = 1;
1054                         dst->resource_size_max = mnl_attr_get_u64(attr);
1055                 } else if (type == DEVLINK_ATTR_RESOURCE_SIZE_GRAN) {
1056                         if (ynl_attr_validate(yarg, attr))
1057                                 return MNL_CB_ERROR;
1058                         dst->_present.resource_size_gran = 1;
1059                         dst->resource_size_gran = mnl_attr_get_u64(attr);
1060                 } else if (type == DEVLINK_ATTR_RESOURCE_UNIT) {
1061                         if (ynl_attr_validate(yarg, attr))
1062                                 return MNL_CB_ERROR;
1063                         dst->_present.resource_unit = 1;
1064                         dst->resource_unit = mnl_attr_get_u8(attr);
1065                 } else if (type == DEVLINK_ATTR_RESOURCE_OCC) {
1066                         if (ynl_attr_validate(yarg, attr))
1067                                 return MNL_CB_ERROR;
1068                         dst->_present.resource_occ = 1;
1069                         dst->resource_occ = mnl_attr_get_u64(attr);
1070                 }
1071         }
1072
1073         return 0;
1074 }
1075
1076 void devlink_dl_info_version_free(struct devlink_dl_info_version *obj)
1077 {
1078         free(obj->info_version_name);
1079         free(obj->info_version_value);
1080 }
1081
1082 int devlink_dl_info_version_parse(struct ynl_parse_arg *yarg,
1083                                   const struct nlattr *nested)
1084 {
1085         struct devlink_dl_info_version *dst = yarg->data;
1086         const struct nlattr *attr;
1087
1088         mnl_attr_for_each_nested(attr, nested) {
1089                 unsigned int type = mnl_attr_get_type(attr);
1090
1091                 if (type == DEVLINK_ATTR_INFO_VERSION_NAME) {
1092                         unsigned int len;
1093
1094                         if (ynl_attr_validate(yarg, attr))
1095                                 return MNL_CB_ERROR;
1096
1097                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1098                         dst->_present.info_version_name_len = len;
1099                         dst->info_version_name = malloc(len + 1);
1100                         memcpy(dst->info_version_name, mnl_attr_get_str(attr), len);
1101                         dst->info_version_name[len] = 0;
1102                 } else if (type == DEVLINK_ATTR_INFO_VERSION_VALUE) {
1103                         unsigned int len;
1104
1105                         if (ynl_attr_validate(yarg, attr))
1106                                 return MNL_CB_ERROR;
1107
1108                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1109                         dst->_present.info_version_value_len = len;
1110                         dst->info_version_value = malloc(len + 1);
1111                         memcpy(dst->info_version_value, mnl_attr_get_str(attr), len);
1112                         dst->info_version_value[len] = 0;
1113                 }
1114         }
1115
1116         return 0;
1117 }
1118
1119 void devlink_dl_fmsg_free(struct devlink_dl_fmsg *obj)
1120 {
1121         free(obj->fmsg_obj_name);
1122 }
1123
1124 int devlink_dl_fmsg_parse(struct ynl_parse_arg *yarg,
1125                           const struct nlattr *nested)
1126 {
1127         struct devlink_dl_fmsg *dst = yarg->data;
1128         const struct nlattr *attr;
1129
1130         mnl_attr_for_each_nested(attr, nested) {
1131                 unsigned int type = mnl_attr_get_type(attr);
1132
1133                 if (type == DEVLINK_ATTR_FMSG_OBJ_NEST_START) {
1134                         if (ynl_attr_validate(yarg, attr))
1135                                 return MNL_CB_ERROR;
1136                         dst->_present.fmsg_obj_nest_start = 1;
1137                 } else if (type == DEVLINK_ATTR_FMSG_PAIR_NEST_START) {
1138                         if (ynl_attr_validate(yarg, attr))
1139                                 return MNL_CB_ERROR;
1140                         dst->_present.fmsg_pair_nest_start = 1;
1141                 } else if (type == DEVLINK_ATTR_FMSG_ARR_NEST_START) {
1142                         if (ynl_attr_validate(yarg, attr))
1143                                 return MNL_CB_ERROR;
1144                         dst->_present.fmsg_arr_nest_start = 1;
1145                 } else if (type == DEVLINK_ATTR_FMSG_NEST_END) {
1146                         if (ynl_attr_validate(yarg, attr))
1147                                 return MNL_CB_ERROR;
1148                         dst->_present.fmsg_nest_end = 1;
1149                 } else if (type == DEVLINK_ATTR_FMSG_OBJ_NAME) {
1150                         unsigned int len;
1151
1152                         if (ynl_attr_validate(yarg, attr))
1153                                 return MNL_CB_ERROR;
1154
1155                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1156                         dst->_present.fmsg_obj_name_len = len;
1157                         dst->fmsg_obj_name = malloc(len + 1);
1158                         memcpy(dst->fmsg_obj_name, mnl_attr_get_str(attr), len);
1159                         dst->fmsg_obj_name[len] = 0;
1160                 }
1161         }
1162
1163         return 0;
1164 }
1165
1166 void devlink_dl_port_function_free(struct devlink_dl_port_function *obj)
1167 {
1168         free(obj->hw_addr);
1169 }
1170
1171 int devlink_dl_port_function_put(struct nlmsghdr *nlh, unsigned int attr_type,
1172                                  struct devlink_dl_port_function *obj)
1173 {
1174         struct nlattr *nest;
1175
1176         nest = mnl_attr_nest_start(nlh, attr_type);
1177         if (obj->_present.hw_addr_len)
1178                 mnl_attr_put(nlh, DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR, obj->_present.hw_addr_len, obj->hw_addr);
1179         if (obj->_present.state)
1180                 mnl_attr_put_u8(nlh, DEVLINK_PORT_FN_ATTR_STATE, obj->state);
1181         if (obj->_present.opstate)
1182                 mnl_attr_put_u8(nlh, DEVLINK_PORT_FN_ATTR_OPSTATE, obj->opstate);
1183         if (obj->_present.caps)
1184                 mnl_attr_put(nlh, DEVLINK_PORT_FN_ATTR_CAPS, sizeof(struct nla_bitfield32), &obj->caps);
1185         mnl_attr_nest_end(nlh, nest);
1186
1187         return 0;
1188 }
1189
1190 void
1191 devlink_dl_reload_stats_entry_free(struct devlink_dl_reload_stats_entry *obj)
1192 {
1193 }
1194
1195 int devlink_dl_reload_stats_entry_parse(struct ynl_parse_arg *yarg,
1196                                         const struct nlattr *nested)
1197 {
1198         struct devlink_dl_reload_stats_entry *dst = yarg->data;
1199         const struct nlattr *attr;
1200
1201         mnl_attr_for_each_nested(attr, nested) {
1202                 unsigned int type = mnl_attr_get_type(attr);
1203
1204                 if (type == DEVLINK_ATTR_RELOAD_STATS_LIMIT) {
1205                         if (ynl_attr_validate(yarg, attr))
1206                                 return MNL_CB_ERROR;
1207                         dst->_present.reload_stats_limit = 1;
1208                         dst->reload_stats_limit = mnl_attr_get_u8(attr);
1209                 } else if (type == DEVLINK_ATTR_RELOAD_STATS_VALUE) {
1210                         if (ynl_attr_validate(yarg, attr))
1211                                 return MNL_CB_ERROR;
1212                         dst->_present.reload_stats_value = 1;
1213                         dst->reload_stats_value = mnl_attr_get_u32(attr);
1214                 }
1215         }
1216
1217         return 0;
1218 }
1219
1220 void devlink_dl_reload_act_stats_free(struct devlink_dl_reload_act_stats *obj)
1221 {
1222         unsigned int i;
1223
1224         for (i = 0; i < obj->n_reload_stats_entry; i++)
1225                 devlink_dl_reload_stats_entry_free(&obj->reload_stats_entry[i]);
1226         free(obj->reload_stats_entry);
1227 }
1228
1229 int devlink_dl_reload_act_stats_parse(struct ynl_parse_arg *yarg,
1230                                       const struct nlattr *nested)
1231 {
1232         struct devlink_dl_reload_act_stats *dst = yarg->data;
1233         unsigned int n_reload_stats_entry = 0;
1234         const struct nlattr *attr;
1235         struct ynl_parse_arg parg;
1236         int i;
1237
1238         parg.ys = yarg->ys;
1239
1240         if (dst->reload_stats_entry)
1241                 return ynl_error_parse(yarg, "attribute already present (dl-reload-act-stats.reload-stats-entry)");
1242
1243         mnl_attr_for_each_nested(attr, nested) {
1244                 unsigned int type = mnl_attr_get_type(attr);
1245
1246                 if (type == DEVLINK_ATTR_RELOAD_STATS_ENTRY) {
1247                         n_reload_stats_entry++;
1248                 }
1249         }
1250
1251         if (n_reload_stats_entry) {
1252                 dst->reload_stats_entry = calloc(n_reload_stats_entry, sizeof(*dst->reload_stats_entry));
1253                 dst->n_reload_stats_entry = n_reload_stats_entry;
1254                 i = 0;
1255                 parg.rsp_policy = &devlink_dl_reload_stats_entry_nest;
1256                 mnl_attr_for_each_nested(attr, nested) {
1257                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_STATS_ENTRY) {
1258                                 parg.data = &dst->reload_stats_entry[i];
1259                                 if (devlink_dl_reload_stats_entry_parse(&parg, attr))
1260                                         return MNL_CB_ERROR;
1261                                 i++;
1262                         }
1263                 }
1264         }
1265
1266         return 0;
1267 }
1268
1269 void devlink_dl_selftest_id_free(struct devlink_dl_selftest_id *obj)
1270 {
1271 }
1272
1273 int devlink_dl_selftest_id_put(struct nlmsghdr *nlh, unsigned int attr_type,
1274                                struct devlink_dl_selftest_id *obj)
1275 {
1276         struct nlattr *nest;
1277
1278         nest = mnl_attr_nest_start(nlh, attr_type);
1279         if (obj->_present.flash)
1280                 mnl_attr_put(nlh, DEVLINK_ATTR_SELFTEST_ID_FLASH, 0, NULL);
1281         mnl_attr_nest_end(nlh, nest);
1282
1283         return 0;
1284 }
1285
1286 void
1287 devlink_dl_dpipe_table_matches_free(struct devlink_dl_dpipe_table_matches *obj)
1288 {
1289         unsigned int i;
1290
1291         for (i = 0; i < obj->n_dpipe_match; i++)
1292                 devlink_dl_dpipe_match_free(&obj->dpipe_match[i]);
1293         free(obj->dpipe_match);
1294 }
1295
1296 int devlink_dl_dpipe_table_matches_parse(struct ynl_parse_arg *yarg,
1297                                          const struct nlattr *nested)
1298 {
1299         struct devlink_dl_dpipe_table_matches *dst = yarg->data;
1300         unsigned int n_dpipe_match = 0;
1301         const struct nlattr *attr;
1302         struct ynl_parse_arg parg;
1303         int i;
1304
1305         parg.ys = yarg->ys;
1306
1307         if (dst->dpipe_match)
1308                 return ynl_error_parse(yarg, "attribute already present (dl-dpipe-table-matches.dpipe-match)");
1309
1310         mnl_attr_for_each_nested(attr, nested) {
1311                 unsigned int type = mnl_attr_get_type(attr);
1312
1313                 if (type == DEVLINK_ATTR_DPIPE_MATCH) {
1314                         n_dpipe_match++;
1315                 }
1316         }
1317
1318         if (n_dpipe_match) {
1319                 dst->dpipe_match = calloc(n_dpipe_match, sizeof(*dst->dpipe_match));
1320                 dst->n_dpipe_match = n_dpipe_match;
1321                 i = 0;
1322                 parg.rsp_policy = &devlink_dl_dpipe_match_nest;
1323                 mnl_attr_for_each_nested(attr, nested) {
1324                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DPIPE_MATCH) {
1325                                 parg.data = &dst->dpipe_match[i];
1326                                 if (devlink_dl_dpipe_match_parse(&parg, attr))
1327                                         return MNL_CB_ERROR;
1328                                 i++;
1329                         }
1330                 }
1331         }
1332
1333         return 0;
1334 }
1335
1336 void
1337 devlink_dl_dpipe_table_actions_free(struct devlink_dl_dpipe_table_actions *obj)
1338 {
1339         unsigned int i;
1340
1341         for (i = 0; i < obj->n_dpipe_action; i++)
1342                 devlink_dl_dpipe_action_free(&obj->dpipe_action[i]);
1343         free(obj->dpipe_action);
1344 }
1345
1346 int devlink_dl_dpipe_table_actions_parse(struct ynl_parse_arg *yarg,
1347                                          const struct nlattr *nested)
1348 {
1349         struct devlink_dl_dpipe_table_actions *dst = yarg->data;
1350         unsigned int n_dpipe_action = 0;
1351         const struct nlattr *attr;
1352         struct ynl_parse_arg parg;
1353         int i;
1354
1355         parg.ys = yarg->ys;
1356
1357         if (dst->dpipe_action)
1358                 return ynl_error_parse(yarg, "attribute already present (dl-dpipe-table-actions.dpipe-action)");
1359
1360         mnl_attr_for_each_nested(attr, nested) {
1361                 unsigned int type = mnl_attr_get_type(attr);
1362
1363                 if (type == DEVLINK_ATTR_DPIPE_ACTION) {
1364                         n_dpipe_action++;
1365                 }
1366         }
1367
1368         if (n_dpipe_action) {
1369                 dst->dpipe_action = calloc(n_dpipe_action, sizeof(*dst->dpipe_action));
1370                 dst->n_dpipe_action = n_dpipe_action;
1371                 i = 0;
1372                 parg.rsp_policy = &devlink_dl_dpipe_action_nest;
1373                 mnl_attr_for_each_nested(attr, nested) {
1374                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DPIPE_ACTION) {
1375                                 parg.data = &dst->dpipe_action[i];
1376                                 if (devlink_dl_dpipe_action_parse(&parg, attr))
1377                                         return MNL_CB_ERROR;
1378                                 i++;
1379                         }
1380                 }
1381         }
1382
1383         return 0;
1384 }
1385
1386 void
1387 devlink_dl_dpipe_entry_match_values_free(struct devlink_dl_dpipe_entry_match_values *obj)
1388 {
1389         unsigned int i;
1390
1391         for (i = 0; i < obj->n_dpipe_match_value; i++)
1392                 devlink_dl_dpipe_match_value_free(&obj->dpipe_match_value[i]);
1393         free(obj->dpipe_match_value);
1394 }
1395
1396 int devlink_dl_dpipe_entry_match_values_parse(struct ynl_parse_arg *yarg,
1397                                               const struct nlattr *nested)
1398 {
1399         struct devlink_dl_dpipe_entry_match_values *dst = yarg->data;
1400         unsigned int n_dpipe_match_value = 0;
1401         const struct nlattr *attr;
1402         struct ynl_parse_arg parg;
1403         int i;
1404
1405         parg.ys = yarg->ys;
1406
1407         if (dst->dpipe_match_value)
1408                 return ynl_error_parse(yarg, "attribute already present (dl-dpipe-entry-match-values.dpipe-match-value)");
1409
1410         mnl_attr_for_each_nested(attr, nested) {
1411                 unsigned int type = mnl_attr_get_type(attr);
1412
1413                 if (type == DEVLINK_ATTR_DPIPE_MATCH_VALUE) {
1414                         n_dpipe_match_value++;
1415                 }
1416         }
1417
1418         if (n_dpipe_match_value) {
1419                 dst->dpipe_match_value = calloc(n_dpipe_match_value, sizeof(*dst->dpipe_match_value));
1420                 dst->n_dpipe_match_value = n_dpipe_match_value;
1421                 i = 0;
1422                 parg.rsp_policy = &devlink_dl_dpipe_match_value_nest;
1423                 mnl_attr_for_each_nested(attr, nested) {
1424                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DPIPE_MATCH_VALUE) {
1425                                 parg.data = &dst->dpipe_match_value[i];
1426                                 if (devlink_dl_dpipe_match_value_parse(&parg, attr))
1427                                         return MNL_CB_ERROR;
1428                                 i++;
1429                         }
1430                 }
1431         }
1432
1433         return 0;
1434 }
1435
1436 void
1437 devlink_dl_dpipe_entry_action_values_free(struct devlink_dl_dpipe_entry_action_values *obj)
1438 {
1439         unsigned int i;
1440
1441         for (i = 0; i < obj->n_dpipe_action_value; i++)
1442                 devlink_dl_dpipe_action_value_free(&obj->dpipe_action_value[i]);
1443         free(obj->dpipe_action_value);
1444 }
1445
1446 int devlink_dl_dpipe_entry_action_values_parse(struct ynl_parse_arg *yarg,
1447                                                const struct nlattr *nested)
1448 {
1449         struct devlink_dl_dpipe_entry_action_values *dst = yarg->data;
1450         unsigned int n_dpipe_action_value = 0;
1451         const struct nlattr *attr;
1452         struct ynl_parse_arg parg;
1453         int i;
1454
1455         parg.ys = yarg->ys;
1456
1457         if (dst->dpipe_action_value)
1458                 return ynl_error_parse(yarg, "attribute already present (dl-dpipe-entry-action-values.dpipe-action-value)");
1459
1460         mnl_attr_for_each_nested(attr, nested) {
1461                 unsigned int type = mnl_attr_get_type(attr);
1462
1463                 if (type == DEVLINK_ATTR_DPIPE_ACTION_VALUE) {
1464                         n_dpipe_action_value++;
1465                 }
1466         }
1467
1468         if (n_dpipe_action_value) {
1469                 dst->dpipe_action_value = calloc(n_dpipe_action_value, sizeof(*dst->dpipe_action_value));
1470                 dst->n_dpipe_action_value = n_dpipe_action_value;
1471                 i = 0;
1472                 parg.rsp_policy = &devlink_dl_dpipe_action_value_nest;
1473                 mnl_attr_for_each_nested(attr, nested) {
1474                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DPIPE_ACTION_VALUE) {
1475                                 parg.data = &dst->dpipe_action_value[i];
1476                                 if (devlink_dl_dpipe_action_value_parse(&parg, attr))
1477                                         return MNL_CB_ERROR;
1478                                 i++;
1479                         }
1480                 }
1481         }
1482
1483         return 0;
1484 }
1485
1486 void
1487 devlink_dl_dpipe_header_fields_free(struct devlink_dl_dpipe_header_fields *obj)
1488 {
1489         unsigned int i;
1490
1491         for (i = 0; i < obj->n_dpipe_field; i++)
1492                 devlink_dl_dpipe_field_free(&obj->dpipe_field[i]);
1493         free(obj->dpipe_field);
1494 }
1495
1496 int devlink_dl_dpipe_header_fields_parse(struct ynl_parse_arg *yarg,
1497                                          const struct nlattr *nested)
1498 {
1499         struct devlink_dl_dpipe_header_fields *dst = yarg->data;
1500         unsigned int n_dpipe_field = 0;
1501         const struct nlattr *attr;
1502         struct ynl_parse_arg parg;
1503         int i;
1504
1505         parg.ys = yarg->ys;
1506
1507         if (dst->dpipe_field)
1508                 return ynl_error_parse(yarg, "attribute already present (dl-dpipe-header-fields.dpipe-field)");
1509
1510         mnl_attr_for_each_nested(attr, nested) {
1511                 unsigned int type = mnl_attr_get_type(attr);
1512
1513                 if (type == DEVLINK_ATTR_DPIPE_FIELD) {
1514                         n_dpipe_field++;
1515                 }
1516         }
1517
1518         if (n_dpipe_field) {
1519                 dst->dpipe_field = calloc(n_dpipe_field, sizeof(*dst->dpipe_field));
1520                 dst->n_dpipe_field = n_dpipe_field;
1521                 i = 0;
1522                 parg.rsp_policy = &devlink_dl_dpipe_field_nest;
1523                 mnl_attr_for_each_nested(attr, nested) {
1524                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DPIPE_FIELD) {
1525                                 parg.data = &dst->dpipe_field[i];
1526                                 if (devlink_dl_dpipe_field_parse(&parg, attr))
1527                                         return MNL_CB_ERROR;
1528                                 i++;
1529                         }
1530                 }
1531         }
1532
1533         return 0;
1534 }
1535
1536 void devlink_dl_resource_list_free(struct devlink_dl_resource_list *obj)
1537 {
1538         unsigned int i;
1539
1540         for (i = 0; i < obj->n_resource; i++)
1541                 devlink_dl_resource_free(&obj->resource[i]);
1542         free(obj->resource);
1543 }
1544
1545 int devlink_dl_resource_list_parse(struct ynl_parse_arg *yarg,
1546                                    const struct nlattr *nested)
1547 {
1548         struct devlink_dl_resource_list *dst = yarg->data;
1549         unsigned int n_resource = 0;
1550         const struct nlattr *attr;
1551         struct ynl_parse_arg parg;
1552         int i;
1553
1554         parg.ys = yarg->ys;
1555
1556         if (dst->resource)
1557                 return ynl_error_parse(yarg, "attribute already present (dl-resource-list.resource)");
1558
1559         mnl_attr_for_each_nested(attr, nested) {
1560                 unsigned int type = mnl_attr_get_type(attr);
1561
1562                 if (type == DEVLINK_ATTR_RESOURCE) {
1563                         n_resource++;
1564                 }
1565         }
1566
1567         if (n_resource) {
1568                 dst->resource = calloc(n_resource, sizeof(*dst->resource));
1569                 dst->n_resource = n_resource;
1570                 i = 0;
1571                 parg.rsp_policy = &devlink_dl_resource_nest;
1572                 mnl_attr_for_each_nested(attr, nested) {
1573                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RESOURCE) {
1574                                 parg.data = &dst->resource[i];
1575                                 if (devlink_dl_resource_parse(&parg, attr))
1576                                         return MNL_CB_ERROR;
1577                                 i++;
1578                         }
1579                 }
1580         }
1581
1582         return 0;
1583 }
1584
1585 void devlink_dl_reload_act_info_free(struct devlink_dl_reload_act_info *obj)
1586 {
1587         unsigned int i;
1588
1589         for (i = 0; i < obj->n_reload_action_stats; i++)
1590                 devlink_dl_reload_act_stats_free(&obj->reload_action_stats[i]);
1591         free(obj->reload_action_stats);
1592 }
1593
1594 int devlink_dl_reload_act_info_parse(struct ynl_parse_arg *yarg,
1595                                      const struct nlattr *nested)
1596 {
1597         struct devlink_dl_reload_act_info *dst = yarg->data;
1598         unsigned int n_reload_action_stats = 0;
1599         const struct nlattr *attr;
1600         struct ynl_parse_arg parg;
1601         int i;
1602
1603         parg.ys = yarg->ys;
1604
1605         if (dst->reload_action_stats)
1606                 return ynl_error_parse(yarg, "attribute already present (dl-reload-act-info.reload-action-stats)");
1607
1608         mnl_attr_for_each_nested(attr, nested) {
1609                 unsigned int type = mnl_attr_get_type(attr);
1610
1611                 if (type == DEVLINK_ATTR_RELOAD_ACTION) {
1612                         if (ynl_attr_validate(yarg, attr))
1613                                 return MNL_CB_ERROR;
1614                         dst->_present.reload_action = 1;
1615                         dst->reload_action = mnl_attr_get_u8(attr);
1616                 } else if (type == DEVLINK_ATTR_RELOAD_ACTION_STATS) {
1617                         n_reload_action_stats++;
1618                 }
1619         }
1620
1621         if (n_reload_action_stats) {
1622                 dst->reload_action_stats = calloc(n_reload_action_stats, sizeof(*dst->reload_action_stats));
1623                 dst->n_reload_action_stats = n_reload_action_stats;
1624                 i = 0;
1625                 parg.rsp_policy = &devlink_dl_reload_act_stats_nest;
1626                 mnl_attr_for_each_nested(attr, nested) {
1627                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_ACTION_STATS) {
1628                                 parg.data = &dst->reload_action_stats[i];
1629                                 if (devlink_dl_reload_act_stats_parse(&parg, attr))
1630                                         return MNL_CB_ERROR;
1631                                 i++;
1632                         }
1633                 }
1634         }
1635
1636         return 0;
1637 }
1638
1639 void devlink_dl_dpipe_table_free(struct devlink_dl_dpipe_table *obj)
1640 {
1641         free(obj->dpipe_table_name);
1642         devlink_dl_dpipe_table_matches_free(&obj->dpipe_table_matches);
1643         devlink_dl_dpipe_table_actions_free(&obj->dpipe_table_actions);
1644 }
1645
1646 int devlink_dl_dpipe_table_parse(struct ynl_parse_arg *yarg,
1647                                  const struct nlattr *nested)
1648 {
1649         struct devlink_dl_dpipe_table *dst = yarg->data;
1650         const struct nlattr *attr;
1651         struct ynl_parse_arg parg;
1652
1653         parg.ys = yarg->ys;
1654
1655         mnl_attr_for_each_nested(attr, nested) {
1656                 unsigned int type = mnl_attr_get_type(attr);
1657
1658                 if (type == DEVLINK_ATTR_DPIPE_TABLE_NAME) {
1659                         unsigned int len;
1660
1661                         if (ynl_attr_validate(yarg, attr))
1662                                 return MNL_CB_ERROR;
1663
1664                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1665                         dst->_present.dpipe_table_name_len = len;
1666                         dst->dpipe_table_name = malloc(len + 1);
1667                         memcpy(dst->dpipe_table_name, mnl_attr_get_str(attr), len);
1668                         dst->dpipe_table_name[len] = 0;
1669                 } else if (type == DEVLINK_ATTR_DPIPE_TABLE_SIZE) {
1670                         if (ynl_attr_validate(yarg, attr))
1671                                 return MNL_CB_ERROR;
1672                         dst->_present.dpipe_table_size = 1;
1673                         dst->dpipe_table_size = mnl_attr_get_u64(attr);
1674                 } else if (type == DEVLINK_ATTR_DPIPE_TABLE_MATCHES) {
1675                         if (ynl_attr_validate(yarg, attr))
1676                                 return MNL_CB_ERROR;
1677                         dst->_present.dpipe_table_matches = 1;
1678
1679                         parg.rsp_policy = &devlink_dl_dpipe_table_matches_nest;
1680                         parg.data = &dst->dpipe_table_matches;
1681                         if (devlink_dl_dpipe_table_matches_parse(&parg, attr))
1682                                 return MNL_CB_ERROR;
1683                 } else if (type == DEVLINK_ATTR_DPIPE_TABLE_ACTIONS) {
1684                         if (ynl_attr_validate(yarg, attr))
1685                                 return MNL_CB_ERROR;
1686                         dst->_present.dpipe_table_actions = 1;
1687
1688                         parg.rsp_policy = &devlink_dl_dpipe_table_actions_nest;
1689                         parg.data = &dst->dpipe_table_actions;
1690                         if (devlink_dl_dpipe_table_actions_parse(&parg, attr))
1691                                 return MNL_CB_ERROR;
1692                 } else if (type == DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED) {
1693                         if (ynl_attr_validate(yarg, attr))
1694                                 return MNL_CB_ERROR;
1695                         dst->_present.dpipe_table_counters_enabled = 1;
1696                         dst->dpipe_table_counters_enabled = mnl_attr_get_u8(attr);
1697                 } else if (type == DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID) {
1698                         if (ynl_attr_validate(yarg, attr))
1699                                 return MNL_CB_ERROR;
1700                         dst->_present.dpipe_table_resource_id = 1;
1701                         dst->dpipe_table_resource_id = mnl_attr_get_u64(attr);
1702                 } else if (type == DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS) {
1703                         if (ynl_attr_validate(yarg, attr))
1704                                 return MNL_CB_ERROR;
1705                         dst->_present.dpipe_table_resource_units = 1;
1706                         dst->dpipe_table_resource_units = mnl_attr_get_u64(attr);
1707                 }
1708         }
1709
1710         return 0;
1711 }
1712
1713 void devlink_dl_dpipe_entry_free(struct devlink_dl_dpipe_entry *obj)
1714 {
1715         devlink_dl_dpipe_entry_match_values_free(&obj->dpipe_entry_match_values);
1716         devlink_dl_dpipe_entry_action_values_free(&obj->dpipe_entry_action_values);
1717 }
1718
1719 int devlink_dl_dpipe_entry_parse(struct ynl_parse_arg *yarg,
1720                                  const struct nlattr *nested)
1721 {
1722         struct devlink_dl_dpipe_entry *dst = yarg->data;
1723         const struct nlattr *attr;
1724         struct ynl_parse_arg parg;
1725
1726         parg.ys = yarg->ys;
1727
1728         mnl_attr_for_each_nested(attr, nested) {
1729                 unsigned int type = mnl_attr_get_type(attr);
1730
1731                 if (type == DEVLINK_ATTR_DPIPE_ENTRY_INDEX) {
1732                         if (ynl_attr_validate(yarg, attr))
1733                                 return MNL_CB_ERROR;
1734                         dst->_present.dpipe_entry_index = 1;
1735                         dst->dpipe_entry_index = mnl_attr_get_u64(attr);
1736                 } else if (type == DEVLINK_ATTR_DPIPE_ENTRY_MATCH_VALUES) {
1737                         if (ynl_attr_validate(yarg, attr))
1738                                 return MNL_CB_ERROR;
1739                         dst->_present.dpipe_entry_match_values = 1;
1740
1741                         parg.rsp_policy = &devlink_dl_dpipe_entry_match_values_nest;
1742                         parg.data = &dst->dpipe_entry_match_values;
1743                         if (devlink_dl_dpipe_entry_match_values_parse(&parg, attr))
1744                                 return MNL_CB_ERROR;
1745                 } else if (type == DEVLINK_ATTR_DPIPE_ENTRY_ACTION_VALUES) {
1746                         if (ynl_attr_validate(yarg, attr))
1747                                 return MNL_CB_ERROR;
1748                         dst->_present.dpipe_entry_action_values = 1;
1749
1750                         parg.rsp_policy = &devlink_dl_dpipe_entry_action_values_nest;
1751                         parg.data = &dst->dpipe_entry_action_values;
1752                         if (devlink_dl_dpipe_entry_action_values_parse(&parg, attr))
1753                                 return MNL_CB_ERROR;
1754                 } else if (type == DEVLINK_ATTR_DPIPE_ENTRY_COUNTER) {
1755                         if (ynl_attr_validate(yarg, attr))
1756                                 return MNL_CB_ERROR;
1757                         dst->_present.dpipe_entry_counter = 1;
1758                         dst->dpipe_entry_counter = mnl_attr_get_u64(attr);
1759                 }
1760         }
1761
1762         return 0;
1763 }
1764
1765 void devlink_dl_dpipe_header_free(struct devlink_dl_dpipe_header *obj)
1766 {
1767         free(obj->dpipe_header_name);
1768         devlink_dl_dpipe_header_fields_free(&obj->dpipe_header_fields);
1769 }
1770
1771 int devlink_dl_dpipe_header_parse(struct ynl_parse_arg *yarg,
1772                                   const struct nlattr *nested)
1773 {
1774         struct devlink_dl_dpipe_header *dst = yarg->data;
1775         const struct nlattr *attr;
1776         struct ynl_parse_arg parg;
1777
1778         parg.ys = yarg->ys;
1779
1780         mnl_attr_for_each_nested(attr, nested) {
1781                 unsigned int type = mnl_attr_get_type(attr);
1782
1783                 if (type == DEVLINK_ATTR_DPIPE_HEADER_NAME) {
1784                         unsigned int len;
1785
1786                         if (ynl_attr_validate(yarg, attr))
1787                                 return MNL_CB_ERROR;
1788
1789                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1790                         dst->_present.dpipe_header_name_len = len;
1791                         dst->dpipe_header_name = malloc(len + 1);
1792                         memcpy(dst->dpipe_header_name, mnl_attr_get_str(attr), len);
1793                         dst->dpipe_header_name[len] = 0;
1794                 } else if (type == DEVLINK_ATTR_DPIPE_HEADER_ID) {
1795                         if (ynl_attr_validate(yarg, attr))
1796                                 return MNL_CB_ERROR;
1797                         dst->_present.dpipe_header_id = 1;
1798                         dst->dpipe_header_id = mnl_attr_get_u32(attr);
1799                 } else if (type == DEVLINK_ATTR_DPIPE_HEADER_GLOBAL) {
1800                         if (ynl_attr_validate(yarg, attr))
1801                                 return MNL_CB_ERROR;
1802                         dst->_present.dpipe_header_global = 1;
1803                         dst->dpipe_header_global = mnl_attr_get_u8(attr);
1804                 } else if (type == DEVLINK_ATTR_DPIPE_HEADER_FIELDS) {
1805                         if (ynl_attr_validate(yarg, attr))
1806                                 return MNL_CB_ERROR;
1807                         dst->_present.dpipe_header_fields = 1;
1808
1809                         parg.rsp_policy = &devlink_dl_dpipe_header_fields_nest;
1810                         parg.data = &dst->dpipe_header_fields;
1811                         if (devlink_dl_dpipe_header_fields_parse(&parg, attr))
1812                                 return MNL_CB_ERROR;
1813                 }
1814         }
1815
1816         return 0;
1817 }
1818
1819 void devlink_dl_reload_stats_free(struct devlink_dl_reload_stats *obj)
1820 {
1821         unsigned int i;
1822
1823         for (i = 0; i < obj->n_reload_action_info; i++)
1824                 devlink_dl_reload_act_info_free(&obj->reload_action_info[i]);
1825         free(obj->reload_action_info);
1826 }
1827
1828 int devlink_dl_reload_stats_parse(struct ynl_parse_arg *yarg,
1829                                   const struct nlattr *nested)
1830 {
1831         struct devlink_dl_reload_stats *dst = yarg->data;
1832         unsigned int n_reload_action_info = 0;
1833         const struct nlattr *attr;
1834         struct ynl_parse_arg parg;
1835         int i;
1836
1837         parg.ys = yarg->ys;
1838
1839         if (dst->reload_action_info)
1840                 return ynl_error_parse(yarg, "attribute already present (dl-reload-stats.reload-action-info)");
1841
1842         mnl_attr_for_each_nested(attr, nested) {
1843                 unsigned int type = mnl_attr_get_type(attr);
1844
1845                 if (type == DEVLINK_ATTR_RELOAD_ACTION_INFO) {
1846                         n_reload_action_info++;
1847                 }
1848         }
1849
1850         if (n_reload_action_info) {
1851                 dst->reload_action_info = calloc(n_reload_action_info, sizeof(*dst->reload_action_info));
1852                 dst->n_reload_action_info = n_reload_action_info;
1853                 i = 0;
1854                 parg.rsp_policy = &devlink_dl_reload_act_info_nest;
1855                 mnl_attr_for_each_nested(attr, nested) {
1856                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_ACTION_INFO) {
1857                                 parg.data = &dst->reload_action_info[i];
1858                                 if (devlink_dl_reload_act_info_parse(&parg, attr))
1859                                         return MNL_CB_ERROR;
1860                                 i++;
1861                         }
1862                 }
1863         }
1864
1865         return 0;
1866 }
1867
1868 void devlink_dl_dpipe_tables_free(struct devlink_dl_dpipe_tables *obj)
1869 {
1870         unsigned int i;
1871
1872         for (i = 0; i < obj->n_dpipe_table; i++)
1873                 devlink_dl_dpipe_table_free(&obj->dpipe_table[i]);
1874         free(obj->dpipe_table);
1875 }
1876
1877 int devlink_dl_dpipe_tables_parse(struct ynl_parse_arg *yarg,
1878                                   const struct nlattr *nested)
1879 {
1880         struct devlink_dl_dpipe_tables *dst = yarg->data;
1881         unsigned int n_dpipe_table = 0;
1882         const struct nlattr *attr;
1883         struct ynl_parse_arg parg;
1884         int i;
1885
1886         parg.ys = yarg->ys;
1887
1888         if (dst->dpipe_table)
1889                 return ynl_error_parse(yarg, "attribute already present (dl-dpipe-tables.dpipe-table)");
1890
1891         mnl_attr_for_each_nested(attr, nested) {
1892                 unsigned int type = mnl_attr_get_type(attr);
1893
1894                 if (type == DEVLINK_ATTR_DPIPE_TABLE) {
1895                         n_dpipe_table++;
1896                 }
1897         }
1898
1899         if (n_dpipe_table) {
1900                 dst->dpipe_table = calloc(n_dpipe_table, sizeof(*dst->dpipe_table));
1901                 dst->n_dpipe_table = n_dpipe_table;
1902                 i = 0;
1903                 parg.rsp_policy = &devlink_dl_dpipe_table_nest;
1904                 mnl_attr_for_each_nested(attr, nested) {
1905                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DPIPE_TABLE) {
1906                                 parg.data = &dst->dpipe_table[i];
1907                                 if (devlink_dl_dpipe_table_parse(&parg, attr))
1908                                         return MNL_CB_ERROR;
1909                                 i++;
1910                         }
1911                 }
1912         }
1913
1914         return 0;
1915 }
1916
1917 void devlink_dl_dpipe_entries_free(struct devlink_dl_dpipe_entries *obj)
1918 {
1919         unsigned int i;
1920
1921         for (i = 0; i < obj->n_dpipe_entry; i++)
1922                 devlink_dl_dpipe_entry_free(&obj->dpipe_entry[i]);
1923         free(obj->dpipe_entry);
1924 }
1925
1926 int devlink_dl_dpipe_entries_parse(struct ynl_parse_arg *yarg,
1927                                    const struct nlattr *nested)
1928 {
1929         struct devlink_dl_dpipe_entries *dst = yarg->data;
1930         unsigned int n_dpipe_entry = 0;
1931         const struct nlattr *attr;
1932         struct ynl_parse_arg parg;
1933         int i;
1934
1935         parg.ys = yarg->ys;
1936
1937         if (dst->dpipe_entry)
1938                 return ynl_error_parse(yarg, "attribute already present (dl-dpipe-entries.dpipe-entry)");
1939
1940         mnl_attr_for_each_nested(attr, nested) {
1941                 unsigned int type = mnl_attr_get_type(attr);
1942
1943                 if (type == DEVLINK_ATTR_DPIPE_ENTRY) {
1944                         n_dpipe_entry++;
1945                 }
1946         }
1947
1948         if (n_dpipe_entry) {
1949                 dst->dpipe_entry = calloc(n_dpipe_entry, sizeof(*dst->dpipe_entry));
1950                 dst->n_dpipe_entry = n_dpipe_entry;
1951                 i = 0;
1952                 parg.rsp_policy = &devlink_dl_dpipe_entry_nest;
1953                 mnl_attr_for_each_nested(attr, nested) {
1954                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DPIPE_ENTRY) {
1955                                 parg.data = &dst->dpipe_entry[i];
1956                                 if (devlink_dl_dpipe_entry_parse(&parg, attr))
1957                                         return MNL_CB_ERROR;
1958                                 i++;
1959                         }
1960                 }
1961         }
1962
1963         return 0;
1964 }
1965
1966 void devlink_dl_dpipe_headers_free(struct devlink_dl_dpipe_headers *obj)
1967 {
1968         unsigned int i;
1969
1970         for (i = 0; i < obj->n_dpipe_header; i++)
1971                 devlink_dl_dpipe_header_free(&obj->dpipe_header[i]);
1972         free(obj->dpipe_header);
1973 }
1974
1975 int devlink_dl_dpipe_headers_parse(struct ynl_parse_arg *yarg,
1976                                    const struct nlattr *nested)
1977 {
1978         struct devlink_dl_dpipe_headers *dst = yarg->data;
1979         unsigned int n_dpipe_header = 0;
1980         const struct nlattr *attr;
1981         struct ynl_parse_arg parg;
1982         int i;
1983
1984         parg.ys = yarg->ys;
1985
1986         if (dst->dpipe_header)
1987                 return ynl_error_parse(yarg, "attribute already present (dl-dpipe-headers.dpipe-header)");
1988
1989         mnl_attr_for_each_nested(attr, nested) {
1990                 unsigned int type = mnl_attr_get_type(attr);
1991
1992                 if (type == DEVLINK_ATTR_DPIPE_HEADER) {
1993                         n_dpipe_header++;
1994                 }
1995         }
1996
1997         if (n_dpipe_header) {
1998                 dst->dpipe_header = calloc(n_dpipe_header, sizeof(*dst->dpipe_header));
1999                 dst->n_dpipe_header = n_dpipe_header;
2000                 i = 0;
2001                 parg.rsp_policy = &devlink_dl_dpipe_header_nest;
2002                 mnl_attr_for_each_nested(attr, nested) {
2003                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DPIPE_HEADER) {
2004                                 parg.data = &dst->dpipe_header[i];
2005                                 if (devlink_dl_dpipe_header_parse(&parg, attr))
2006                                         return MNL_CB_ERROR;
2007                                 i++;
2008                         }
2009                 }
2010         }
2011
2012         return 0;
2013 }
2014
2015 void devlink_dl_dev_stats_free(struct devlink_dl_dev_stats *obj)
2016 {
2017         devlink_dl_reload_stats_free(&obj->reload_stats);
2018         devlink_dl_reload_stats_free(&obj->remote_reload_stats);
2019 }
2020
2021 int devlink_dl_dev_stats_parse(struct ynl_parse_arg *yarg,
2022                                const struct nlattr *nested)
2023 {
2024         struct devlink_dl_dev_stats *dst = yarg->data;
2025         const struct nlattr *attr;
2026         struct ynl_parse_arg parg;
2027
2028         parg.ys = yarg->ys;
2029
2030         mnl_attr_for_each_nested(attr, nested) {
2031                 unsigned int type = mnl_attr_get_type(attr);
2032
2033                 if (type == DEVLINK_ATTR_RELOAD_STATS) {
2034                         if (ynl_attr_validate(yarg, attr))
2035                                 return MNL_CB_ERROR;
2036                         dst->_present.reload_stats = 1;
2037
2038                         parg.rsp_policy = &devlink_dl_reload_stats_nest;
2039                         parg.data = &dst->reload_stats;
2040                         if (devlink_dl_reload_stats_parse(&parg, attr))
2041                                 return MNL_CB_ERROR;
2042                 } else if (type == DEVLINK_ATTR_REMOTE_RELOAD_STATS) {
2043                         if (ynl_attr_validate(yarg, attr))
2044                                 return MNL_CB_ERROR;
2045                         dst->_present.remote_reload_stats = 1;
2046
2047                         parg.rsp_policy = &devlink_dl_reload_stats_nest;
2048                         parg.data = &dst->remote_reload_stats;
2049                         if (devlink_dl_reload_stats_parse(&parg, attr))
2050                                 return MNL_CB_ERROR;
2051                 }
2052         }
2053
2054         return 0;
2055 }
2056
2057 /* ============== DEVLINK_CMD_GET ============== */
2058 /* DEVLINK_CMD_GET - do */
2059 void devlink_get_req_free(struct devlink_get_req *req)
2060 {
2061         free(req->bus_name);
2062         free(req->dev_name);
2063         free(req);
2064 }
2065
2066 void devlink_get_rsp_free(struct devlink_get_rsp *rsp)
2067 {
2068         free(rsp->bus_name);
2069         free(rsp->dev_name);
2070         devlink_dl_dev_stats_free(&rsp->dev_stats);
2071         free(rsp);
2072 }
2073
2074 int devlink_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
2075 {
2076         struct ynl_parse_arg *yarg = data;
2077         struct devlink_get_rsp *dst;
2078         const struct nlattr *attr;
2079         struct ynl_parse_arg parg;
2080
2081         dst = yarg->data;
2082         parg.ys = yarg->ys;
2083
2084         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2085                 unsigned int type = mnl_attr_get_type(attr);
2086
2087                 if (type == DEVLINK_ATTR_BUS_NAME) {
2088                         unsigned int len;
2089
2090                         if (ynl_attr_validate(yarg, attr))
2091                                 return MNL_CB_ERROR;
2092
2093                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2094                         dst->_present.bus_name_len = len;
2095                         dst->bus_name = malloc(len + 1);
2096                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2097                         dst->bus_name[len] = 0;
2098                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2099                         unsigned int len;
2100
2101                         if (ynl_attr_validate(yarg, attr))
2102                                 return MNL_CB_ERROR;
2103
2104                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2105                         dst->_present.dev_name_len = len;
2106                         dst->dev_name = malloc(len + 1);
2107                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2108                         dst->dev_name[len] = 0;
2109                 } else if (type == DEVLINK_ATTR_RELOAD_FAILED) {
2110                         if (ynl_attr_validate(yarg, attr))
2111                                 return MNL_CB_ERROR;
2112                         dst->_present.reload_failed = 1;
2113                         dst->reload_failed = mnl_attr_get_u8(attr);
2114                 } else if (type == DEVLINK_ATTR_DEV_STATS) {
2115                         if (ynl_attr_validate(yarg, attr))
2116                                 return MNL_CB_ERROR;
2117                         dst->_present.dev_stats = 1;
2118
2119                         parg.rsp_policy = &devlink_dl_dev_stats_nest;
2120                         parg.data = &dst->dev_stats;
2121                         if (devlink_dl_dev_stats_parse(&parg, attr))
2122                                 return MNL_CB_ERROR;
2123                 }
2124         }
2125
2126         return MNL_CB_OK;
2127 }
2128
2129 struct devlink_get_rsp *
2130 devlink_get(struct ynl_sock *ys, struct devlink_get_req *req)
2131 {
2132         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2133         struct devlink_get_rsp *rsp;
2134         struct nlmsghdr *nlh;
2135         int err;
2136
2137         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_GET, 1);
2138         ys->req_policy = &devlink_nest;
2139         yrs.yarg.rsp_policy = &devlink_nest;
2140
2141         if (req->_present.bus_name_len)
2142                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2143         if (req->_present.dev_name_len)
2144                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2145
2146         rsp = calloc(1, sizeof(*rsp));
2147         yrs.yarg.data = rsp;
2148         yrs.cb = devlink_get_rsp_parse;
2149         yrs.rsp_cmd = 3;
2150
2151         err = ynl_exec(ys, nlh, &yrs);
2152         if (err < 0)
2153                 goto err_free;
2154
2155         return rsp;
2156
2157 err_free:
2158         devlink_get_rsp_free(rsp);
2159         return NULL;
2160 }
2161
2162 /* DEVLINK_CMD_GET - dump */
2163 void devlink_get_list_free(struct devlink_get_list *rsp)
2164 {
2165         struct devlink_get_list *next = rsp;
2166
2167         while ((void *)next != YNL_LIST_END) {
2168                 rsp = next;
2169                 next = rsp->next;
2170
2171                 free(rsp->obj.bus_name);
2172                 free(rsp->obj.dev_name);
2173                 devlink_dl_dev_stats_free(&rsp->obj.dev_stats);
2174                 free(rsp);
2175         }
2176 }
2177
2178 struct devlink_get_list *devlink_get_dump(struct ynl_sock *ys)
2179 {
2180         struct ynl_dump_state yds = {};
2181         struct nlmsghdr *nlh;
2182         int err;
2183
2184         yds.ys = ys;
2185         yds.alloc_sz = sizeof(struct devlink_get_list);
2186         yds.cb = devlink_get_rsp_parse;
2187         yds.rsp_cmd = 3;
2188         yds.rsp_policy = &devlink_nest;
2189
2190         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_GET, 1);
2191
2192         err = ynl_exec_dump(ys, nlh, &yds);
2193         if (err < 0)
2194                 goto free_list;
2195
2196         return yds.first;
2197
2198 free_list:
2199         devlink_get_list_free(yds.first);
2200         return NULL;
2201 }
2202
2203 /* ============== DEVLINK_CMD_PORT_GET ============== */
2204 /* DEVLINK_CMD_PORT_GET - do */
2205 void devlink_port_get_req_free(struct devlink_port_get_req *req)
2206 {
2207         free(req->bus_name);
2208         free(req->dev_name);
2209         free(req);
2210 }
2211
2212 void devlink_port_get_rsp_free(struct devlink_port_get_rsp *rsp)
2213 {
2214         free(rsp->bus_name);
2215         free(rsp->dev_name);
2216         free(rsp);
2217 }
2218
2219 int devlink_port_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
2220 {
2221         struct ynl_parse_arg *yarg = data;
2222         struct devlink_port_get_rsp *dst;
2223         const struct nlattr *attr;
2224
2225         dst = yarg->data;
2226
2227         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2228                 unsigned int type = mnl_attr_get_type(attr);
2229
2230                 if (type == DEVLINK_ATTR_BUS_NAME) {
2231                         unsigned int len;
2232
2233                         if (ynl_attr_validate(yarg, attr))
2234                                 return MNL_CB_ERROR;
2235
2236                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2237                         dst->_present.bus_name_len = len;
2238                         dst->bus_name = malloc(len + 1);
2239                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2240                         dst->bus_name[len] = 0;
2241                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2242                         unsigned int len;
2243
2244                         if (ynl_attr_validate(yarg, attr))
2245                                 return MNL_CB_ERROR;
2246
2247                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2248                         dst->_present.dev_name_len = len;
2249                         dst->dev_name = malloc(len + 1);
2250                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2251                         dst->dev_name[len] = 0;
2252                 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
2253                         if (ynl_attr_validate(yarg, attr))
2254                                 return MNL_CB_ERROR;
2255                         dst->_present.port_index = 1;
2256                         dst->port_index = mnl_attr_get_u32(attr);
2257                 }
2258         }
2259
2260         return MNL_CB_OK;
2261 }
2262
2263 struct devlink_port_get_rsp *
2264 devlink_port_get(struct ynl_sock *ys, struct devlink_port_get_req *req)
2265 {
2266         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2267         struct devlink_port_get_rsp *rsp;
2268         struct nlmsghdr *nlh;
2269         int err;
2270
2271         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PORT_GET, 1);
2272         ys->req_policy = &devlink_nest;
2273         yrs.yarg.rsp_policy = &devlink_nest;
2274
2275         if (req->_present.bus_name_len)
2276                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2277         if (req->_present.dev_name_len)
2278                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2279         if (req->_present.port_index)
2280                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
2281
2282         rsp = calloc(1, sizeof(*rsp));
2283         yrs.yarg.data = rsp;
2284         yrs.cb = devlink_port_get_rsp_parse;
2285         yrs.rsp_cmd = 7;
2286
2287         err = ynl_exec(ys, nlh, &yrs);
2288         if (err < 0)
2289                 goto err_free;
2290
2291         return rsp;
2292
2293 err_free:
2294         devlink_port_get_rsp_free(rsp);
2295         return NULL;
2296 }
2297
2298 /* DEVLINK_CMD_PORT_GET - dump */
2299 int devlink_port_get_rsp_dump_parse(const struct nlmsghdr *nlh, void *data)
2300 {
2301         struct devlink_port_get_rsp_dump *dst;
2302         struct ynl_parse_arg *yarg = data;
2303         const struct nlattr *attr;
2304
2305         dst = yarg->data;
2306
2307         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2308                 unsigned int type = mnl_attr_get_type(attr);
2309
2310                 if (type == DEVLINK_ATTR_BUS_NAME) {
2311                         unsigned int len;
2312
2313                         if (ynl_attr_validate(yarg, attr))
2314                                 return MNL_CB_ERROR;
2315
2316                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2317                         dst->_present.bus_name_len = len;
2318                         dst->bus_name = malloc(len + 1);
2319                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2320                         dst->bus_name[len] = 0;
2321                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2322                         unsigned int len;
2323
2324                         if (ynl_attr_validate(yarg, attr))
2325                                 return MNL_CB_ERROR;
2326
2327                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2328                         dst->_present.dev_name_len = len;
2329                         dst->dev_name = malloc(len + 1);
2330                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2331                         dst->dev_name[len] = 0;
2332                 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
2333                         if (ynl_attr_validate(yarg, attr))
2334                                 return MNL_CB_ERROR;
2335                         dst->_present.port_index = 1;
2336                         dst->port_index = mnl_attr_get_u32(attr);
2337                 }
2338         }
2339
2340         return MNL_CB_OK;
2341 }
2342
2343 void devlink_port_get_rsp_list_free(struct devlink_port_get_rsp_list *rsp)
2344 {
2345         struct devlink_port_get_rsp_list *next = rsp;
2346
2347         while ((void *)next != YNL_LIST_END) {
2348                 rsp = next;
2349                 next = rsp->next;
2350
2351                 free(rsp->obj.bus_name);
2352                 free(rsp->obj.dev_name);
2353                 free(rsp);
2354         }
2355 }
2356
2357 struct devlink_port_get_rsp_list *
2358 devlink_port_get_dump(struct ynl_sock *ys,
2359                       struct devlink_port_get_req_dump *req)
2360 {
2361         struct ynl_dump_state yds = {};
2362         struct nlmsghdr *nlh;
2363         int err;
2364
2365         yds.ys = ys;
2366         yds.alloc_sz = sizeof(struct devlink_port_get_rsp_list);
2367         yds.cb = devlink_port_get_rsp_dump_parse;
2368         yds.rsp_cmd = 7;
2369         yds.rsp_policy = &devlink_nest;
2370
2371         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_PORT_GET, 1);
2372         ys->req_policy = &devlink_nest;
2373
2374         if (req->_present.bus_name_len)
2375                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2376         if (req->_present.dev_name_len)
2377                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2378
2379         err = ynl_exec_dump(ys, nlh, &yds);
2380         if (err < 0)
2381                 goto free_list;
2382
2383         return yds.first;
2384
2385 free_list:
2386         devlink_port_get_rsp_list_free(yds.first);
2387         return NULL;
2388 }
2389
2390 /* ============== DEVLINK_CMD_PORT_SET ============== */
2391 /* DEVLINK_CMD_PORT_SET - do */
2392 void devlink_port_set_req_free(struct devlink_port_set_req *req)
2393 {
2394         free(req->bus_name);
2395         free(req->dev_name);
2396         devlink_dl_port_function_free(&req->port_function);
2397         free(req);
2398 }
2399
2400 int devlink_port_set(struct ynl_sock *ys, struct devlink_port_set_req *req)
2401 {
2402         struct nlmsghdr *nlh;
2403         int err;
2404
2405         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PORT_SET, 1);
2406         ys->req_policy = &devlink_nest;
2407
2408         if (req->_present.bus_name_len)
2409                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2410         if (req->_present.dev_name_len)
2411                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2412         if (req->_present.port_index)
2413                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
2414         if (req->_present.port_type)
2415                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_TYPE, req->port_type);
2416         if (req->_present.port_function)
2417                 devlink_dl_port_function_put(nlh, DEVLINK_ATTR_PORT_FUNCTION, &req->port_function);
2418
2419         err = ynl_exec(ys, nlh, NULL);
2420         if (err < 0)
2421                 return -1;
2422
2423         return 0;
2424 }
2425
2426 /* ============== DEVLINK_CMD_PORT_NEW ============== */
2427 /* DEVLINK_CMD_PORT_NEW - do */
2428 void devlink_port_new_req_free(struct devlink_port_new_req *req)
2429 {
2430         free(req->bus_name);
2431         free(req->dev_name);
2432         free(req);
2433 }
2434
2435 void devlink_port_new_rsp_free(struct devlink_port_new_rsp *rsp)
2436 {
2437         free(rsp->bus_name);
2438         free(rsp->dev_name);
2439         free(rsp);
2440 }
2441
2442 int devlink_port_new_rsp_parse(const struct nlmsghdr *nlh, void *data)
2443 {
2444         struct ynl_parse_arg *yarg = data;
2445         struct devlink_port_new_rsp *dst;
2446         const struct nlattr *attr;
2447
2448         dst = yarg->data;
2449
2450         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2451                 unsigned int type = mnl_attr_get_type(attr);
2452
2453                 if (type == DEVLINK_ATTR_BUS_NAME) {
2454                         unsigned int len;
2455
2456                         if (ynl_attr_validate(yarg, attr))
2457                                 return MNL_CB_ERROR;
2458
2459                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2460                         dst->_present.bus_name_len = len;
2461                         dst->bus_name = malloc(len + 1);
2462                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2463                         dst->bus_name[len] = 0;
2464                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2465                         unsigned int len;
2466
2467                         if (ynl_attr_validate(yarg, attr))
2468                                 return MNL_CB_ERROR;
2469
2470                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2471                         dst->_present.dev_name_len = len;
2472                         dst->dev_name = malloc(len + 1);
2473                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2474                         dst->dev_name[len] = 0;
2475                 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
2476                         if (ynl_attr_validate(yarg, attr))
2477                                 return MNL_CB_ERROR;
2478                         dst->_present.port_index = 1;
2479                         dst->port_index = mnl_attr_get_u32(attr);
2480                 }
2481         }
2482
2483         return MNL_CB_OK;
2484 }
2485
2486 struct devlink_port_new_rsp *
2487 devlink_port_new(struct ynl_sock *ys, struct devlink_port_new_req *req)
2488 {
2489         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2490         struct devlink_port_new_rsp *rsp;
2491         struct nlmsghdr *nlh;
2492         int err;
2493
2494         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PORT_NEW, 1);
2495         ys->req_policy = &devlink_nest;
2496         yrs.yarg.rsp_policy = &devlink_nest;
2497
2498         if (req->_present.bus_name_len)
2499                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2500         if (req->_present.dev_name_len)
2501                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2502         if (req->_present.port_index)
2503                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
2504         if (req->_present.port_flavour)
2505                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_FLAVOUR, req->port_flavour);
2506         if (req->_present.port_pci_pf_number)
2507                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_PCI_PF_NUMBER, req->port_pci_pf_number);
2508         if (req->_present.port_pci_sf_number)
2509                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_PCI_SF_NUMBER, req->port_pci_sf_number);
2510         if (req->_present.port_controller_number)
2511                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_CONTROLLER_NUMBER, req->port_controller_number);
2512
2513         rsp = calloc(1, sizeof(*rsp));
2514         yrs.yarg.data = rsp;
2515         yrs.cb = devlink_port_new_rsp_parse;
2516         yrs.rsp_cmd = DEVLINK_CMD_PORT_NEW;
2517
2518         err = ynl_exec(ys, nlh, &yrs);
2519         if (err < 0)
2520                 goto err_free;
2521
2522         return rsp;
2523
2524 err_free:
2525         devlink_port_new_rsp_free(rsp);
2526         return NULL;
2527 }
2528
2529 /* ============== DEVLINK_CMD_PORT_DEL ============== */
2530 /* DEVLINK_CMD_PORT_DEL - do */
2531 void devlink_port_del_req_free(struct devlink_port_del_req *req)
2532 {
2533         free(req->bus_name);
2534         free(req->dev_name);
2535         free(req);
2536 }
2537
2538 int devlink_port_del(struct ynl_sock *ys, struct devlink_port_del_req *req)
2539 {
2540         struct nlmsghdr *nlh;
2541         int err;
2542
2543         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PORT_DEL, 1);
2544         ys->req_policy = &devlink_nest;
2545
2546         if (req->_present.bus_name_len)
2547                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2548         if (req->_present.dev_name_len)
2549                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2550         if (req->_present.port_index)
2551                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
2552
2553         err = ynl_exec(ys, nlh, NULL);
2554         if (err < 0)
2555                 return -1;
2556
2557         return 0;
2558 }
2559
2560 /* ============== DEVLINK_CMD_PORT_SPLIT ============== */
2561 /* DEVLINK_CMD_PORT_SPLIT - do */
2562 void devlink_port_split_req_free(struct devlink_port_split_req *req)
2563 {
2564         free(req->bus_name);
2565         free(req->dev_name);
2566         free(req);
2567 }
2568
2569 int devlink_port_split(struct ynl_sock *ys, struct devlink_port_split_req *req)
2570 {
2571         struct nlmsghdr *nlh;
2572         int err;
2573
2574         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PORT_SPLIT, 1);
2575         ys->req_policy = &devlink_nest;
2576
2577         if (req->_present.bus_name_len)
2578                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2579         if (req->_present.dev_name_len)
2580                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2581         if (req->_present.port_index)
2582                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
2583         if (req->_present.port_split_count)
2584                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_SPLIT_COUNT, req->port_split_count);
2585
2586         err = ynl_exec(ys, nlh, NULL);
2587         if (err < 0)
2588                 return -1;
2589
2590         return 0;
2591 }
2592
2593 /* ============== DEVLINK_CMD_PORT_UNSPLIT ============== */
2594 /* DEVLINK_CMD_PORT_UNSPLIT - do */
2595 void devlink_port_unsplit_req_free(struct devlink_port_unsplit_req *req)
2596 {
2597         free(req->bus_name);
2598         free(req->dev_name);
2599         free(req);
2600 }
2601
2602 int devlink_port_unsplit(struct ynl_sock *ys,
2603                          struct devlink_port_unsplit_req *req)
2604 {
2605         struct nlmsghdr *nlh;
2606         int err;
2607
2608         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PORT_UNSPLIT, 1);
2609         ys->req_policy = &devlink_nest;
2610
2611         if (req->_present.bus_name_len)
2612                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2613         if (req->_present.dev_name_len)
2614                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2615         if (req->_present.port_index)
2616                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
2617
2618         err = ynl_exec(ys, nlh, NULL);
2619         if (err < 0)
2620                 return -1;
2621
2622         return 0;
2623 }
2624
2625 /* ============== DEVLINK_CMD_SB_GET ============== */
2626 /* DEVLINK_CMD_SB_GET - do */
2627 void devlink_sb_get_req_free(struct devlink_sb_get_req *req)
2628 {
2629         free(req->bus_name);
2630         free(req->dev_name);
2631         free(req);
2632 }
2633
2634 void devlink_sb_get_rsp_free(struct devlink_sb_get_rsp *rsp)
2635 {
2636         free(rsp->bus_name);
2637         free(rsp->dev_name);
2638         free(rsp);
2639 }
2640
2641 int devlink_sb_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
2642 {
2643         struct ynl_parse_arg *yarg = data;
2644         struct devlink_sb_get_rsp *dst;
2645         const struct nlattr *attr;
2646
2647         dst = yarg->data;
2648
2649         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2650                 unsigned int type = mnl_attr_get_type(attr);
2651
2652                 if (type == DEVLINK_ATTR_BUS_NAME) {
2653                         unsigned int len;
2654
2655                         if (ynl_attr_validate(yarg, attr))
2656                                 return MNL_CB_ERROR;
2657
2658                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2659                         dst->_present.bus_name_len = len;
2660                         dst->bus_name = malloc(len + 1);
2661                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2662                         dst->bus_name[len] = 0;
2663                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2664                         unsigned int len;
2665
2666                         if (ynl_attr_validate(yarg, attr))
2667                                 return MNL_CB_ERROR;
2668
2669                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2670                         dst->_present.dev_name_len = len;
2671                         dst->dev_name = malloc(len + 1);
2672                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2673                         dst->dev_name[len] = 0;
2674                 } else if (type == DEVLINK_ATTR_SB_INDEX) {
2675                         if (ynl_attr_validate(yarg, attr))
2676                                 return MNL_CB_ERROR;
2677                         dst->_present.sb_index = 1;
2678                         dst->sb_index = mnl_attr_get_u32(attr);
2679                 }
2680         }
2681
2682         return MNL_CB_OK;
2683 }
2684
2685 struct devlink_sb_get_rsp *
2686 devlink_sb_get(struct ynl_sock *ys, struct devlink_sb_get_req *req)
2687 {
2688         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2689         struct devlink_sb_get_rsp *rsp;
2690         struct nlmsghdr *nlh;
2691         int err;
2692
2693         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_GET, 1);
2694         ys->req_policy = &devlink_nest;
2695         yrs.yarg.rsp_policy = &devlink_nest;
2696
2697         if (req->_present.bus_name_len)
2698                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2699         if (req->_present.dev_name_len)
2700                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2701         if (req->_present.sb_index)
2702                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
2703
2704         rsp = calloc(1, sizeof(*rsp));
2705         yrs.yarg.data = rsp;
2706         yrs.cb = devlink_sb_get_rsp_parse;
2707         yrs.rsp_cmd = 13;
2708
2709         err = ynl_exec(ys, nlh, &yrs);
2710         if (err < 0)
2711                 goto err_free;
2712
2713         return rsp;
2714
2715 err_free:
2716         devlink_sb_get_rsp_free(rsp);
2717         return NULL;
2718 }
2719
2720 /* DEVLINK_CMD_SB_GET - dump */
2721 void devlink_sb_get_list_free(struct devlink_sb_get_list *rsp)
2722 {
2723         struct devlink_sb_get_list *next = rsp;
2724
2725         while ((void *)next != YNL_LIST_END) {
2726                 rsp = next;
2727                 next = rsp->next;
2728
2729                 free(rsp->obj.bus_name);
2730                 free(rsp->obj.dev_name);
2731                 free(rsp);
2732         }
2733 }
2734
2735 struct devlink_sb_get_list *
2736 devlink_sb_get_dump(struct ynl_sock *ys, struct devlink_sb_get_req_dump *req)
2737 {
2738         struct ynl_dump_state yds = {};
2739         struct nlmsghdr *nlh;
2740         int err;
2741
2742         yds.ys = ys;
2743         yds.alloc_sz = sizeof(struct devlink_sb_get_list);
2744         yds.cb = devlink_sb_get_rsp_parse;
2745         yds.rsp_cmd = 13;
2746         yds.rsp_policy = &devlink_nest;
2747
2748         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_GET, 1);
2749         ys->req_policy = &devlink_nest;
2750
2751         if (req->_present.bus_name_len)
2752                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2753         if (req->_present.dev_name_len)
2754                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2755
2756         err = ynl_exec_dump(ys, nlh, &yds);
2757         if (err < 0)
2758                 goto free_list;
2759
2760         return yds.first;
2761
2762 free_list:
2763         devlink_sb_get_list_free(yds.first);
2764         return NULL;
2765 }
2766
2767 /* ============== DEVLINK_CMD_SB_POOL_GET ============== */
2768 /* DEVLINK_CMD_SB_POOL_GET - do */
2769 void devlink_sb_pool_get_req_free(struct devlink_sb_pool_get_req *req)
2770 {
2771         free(req->bus_name);
2772         free(req->dev_name);
2773         free(req);
2774 }
2775
2776 void devlink_sb_pool_get_rsp_free(struct devlink_sb_pool_get_rsp *rsp)
2777 {
2778         free(rsp->bus_name);
2779         free(rsp->dev_name);
2780         free(rsp);
2781 }
2782
2783 int devlink_sb_pool_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
2784 {
2785         struct devlink_sb_pool_get_rsp *dst;
2786         struct ynl_parse_arg *yarg = data;
2787         const struct nlattr *attr;
2788
2789         dst = yarg->data;
2790
2791         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2792                 unsigned int type = mnl_attr_get_type(attr);
2793
2794                 if (type == DEVLINK_ATTR_BUS_NAME) {
2795                         unsigned int len;
2796
2797                         if (ynl_attr_validate(yarg, attr))
2798                                 return MNL_CB_ERROR;
2799
2800                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2801                         dst->_present.bus_name_len = len;
2802                         dst->bus_name = malloc(len + 1);
2803                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2804                         dst->bus_name[len] = 0;
2805                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2806                         unsigned int len;
2807
2808                         if (ynl_attr_validate(yarg, attr))
2809                                 return MNL_CB_ERROR;
2810
2811                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2812                         dst->_present.dev_name_len = len;
2813                         dst->dev_name = malloc(len + 1);
2814                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2815                         dst->dev_name[len] = 0;
2816                 } else if (type == DEVLINK_ATTR_SB_INDEX) {
2817                         if (ynl_attr_validate(yarg, attr))
2818                                 return MNL_CB_ERROR;
2819                         dst->_present.sb_index = 1;
2820                         dst->sb_index = mnl_attr_get_u32(attr);
2821                 } else if (type == DEVLINK_ATTR_SB_POOL_INDEX) {
2822                         if (ynl_attr_validate(yarg, attr))
2823                                 return MNL_CB_ERROR;
2824                         dst->_present.sb_pool_index = 1;
2825                         dst->sb_pool_index = mnl_attr_get_u16(attr);
2826                 }
2827         }
2828
2829         return MNL_CB_OK;
2830 }
2831
2832 struct devlink_sb_pool_get_rsp *
2833 devlink_sb_pool_get(struct ynl_sock *ys, struct devlink_sb_pool_get_req *req)
2834 {
2835         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2836         struct devlink_sb_pool_get_rsp *rsp;
2837         struct nlmsghdr *nlh;
2838         int err;
2839
2840         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_POOL_GET, 1);
2841         ys->req_policy = &devlink_nest;
2842         yrs.yarg.rsp_policy = &devlink_nest;
2843
2844         if (req->_present.bus_name_len)
2845                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2846         if (req->_present.dev_name_len)
2847                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2848         if (req->_present.sb_index)
2849                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
2850         if (req->_present.sb_pool_index)
2851                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_POOL_INDEX, req->sb_pool_index);
2852
2853         rsp = calloc(1, sizeof(*rsp));
2854         yrs.yarg.data = rsp;
2855         yrs.cb = devlink_sb_pool_get_rsp_parse;
2856         yrs.rsp_cmd = 17;
2857
2858         err = ynl_exec(ys, nlh, &yrs);
2859         if (err < 0)
2860                 goto err_free;
2861
2862         return rsp;
2863
2864 err_free:
2865         devlink_sb_pool_get_rsp_free(rsp);
2866         return NULL;
2867 }
2868
2869 /* DEVLINK_CMD_SB_POOL_GET - dump */
2870 void devlink_sb_pool_get_list_free(struct devlink_sb_pool_get_list *rsp)
2871 {
2872         struct devlink_sb_pool_get_list *next = rsp;
2873
2874         while ((void *)next != YNL_LIST_END) {
2875                 rsp = next;
2876                 next = rsp->next;
2877
2878                 free(rsp->obj.bus_name);
2879                 free(rsp->obj.dev_name);
2880                 free(rsp);
2881         }
2882 }
2883
2884 struct devlink_sb_pool_get_list *
2885 devlink_sb_pool_get_dump(struct ynl_sock *ys,
2886                          struct devlink_sb_pool_get_req_dump *req)
2887 {
2888         struct ynl_dump_state yds = {};
2889         struct nlmsghdr *nlh;
2890         int err;
2891
2892         yds.ys = ys;
2893         yds.alloc_sz = sizeof(struct devlink_sb_pool_get_list);
2894         yds.cb = devlink_sb_pool_get_rsp_parse;
2895         yds.rsp_cmd = 17;
2896         yds.rsp_policy = &devlink_nest;
2897
2898         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_POOL_GET, 1);
2899         ys->req_policy = &devlink_nest;
2900
2901         if (req->_present.bus_name_len)
2902                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2903         if (req->_present.dev_name_len)
2904                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2905
2906         err = ynl_exec_dump(ys, nlh, &yds);
2907         if (err < 0)
2908                 goto free_list;
2909
2910         return yds.first;
2911
2912 free_list:
2913         devlink_sb_pool_get_list_free(yds.first);
2914         return NULL;
2915 }
2916
2917 /* ============== DEVLINK_CMD_SB_POOL_SET ============== */
2918 /* DEVLINK_CMD_SB_POOL_SET - do */
2919 void devlink_sb_pool_set_req_free(struct devlink_sb_pool_set_req *req)
2920 {
2921         free(req->bus_name);
2922         free(req->dev_name);
2923         free(req);
2924 }
2925
2926 int devlink_sb_pool_set(struct ynl_sock *ys,
2927                         struct devlink_sb_pool_set_req *req)
2928 {
2929         struct nlmsghdr *nlh;
2930         int err;
2931
2932         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_POOL_SET, 1);
2933         ys->req_policy = &devlink_nest;
2934
2935         if (req->_present.bus_name_len)
2936                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2937         if (req->_present.dev_name_len)
2938                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2939         if (req->_present.sb_index)
2940                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
2941         if (req->_present.sb_pool_index)
2942                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_POOL_INDEX, req->sb_pool_index);
2943         if (req->_present.sb_pool_threshold_type)
2944                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE, req->sb_pool_threshold_type);
2945         if (req->_present.sb_pool_size)
2946                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_POOL_SIZE, req->sb_pool_size);
2947
2948         err = ynl_exec(ys, nlh, NULL);
2949         if (err < 0)
2950                 return -1;
2951
2952         return 0;
2953 }
2954
2955 /* ============== DEVLINK_CMD_SB_PORT_POOL_GET ============== */
2956 /* DEVLINK_CMD_SB_PORT_POOL_GET - do */
2957 void
2958 devlink_sb_port_pool_get_req_free(struct devlink_sb_port_pool_get_req *req)
2959 {
2960         free(req->bus_name);
2961         free(req->dev_name);
2962         free(req);
2963 }
2964
2965 void
2966 devlink_sb_port_pool_get_rsp_free(struct devlink_sb_port_pool_get_rsp *rsp)
2967 {
2968         free(rsp->bus_name);
2969         free(rsp->dev_name);
2970         free(rsp);
2971 }
2972
2973 int devlink_sb_port_pool_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
2974 {
2975         struct devlink_sb_port_pool_get_rsp *dst;
2976         struct ynl_parse_arg *yarg = data;
2977         const struct nlattr *attr;
2978
2979         dst = yarg->data;
2980
2981         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2982                 unsigned int type = mnl_attr_get_type(attr);
2983
2984                 if (type == DEVLINK_ATTR_BUS_NAME) {
2985                         unsigned int len;
2986
2987                         if (ynl_attr_validate(yarg, attr))
2988                                 return MNL_CB_ERROR;
2989
2990                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2991                         dst->_present.bus_name_len = len;
2992                         dst->bus_name = malloc(len + 1);
2993                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2994                         dst->bus_name[len] = 0;
2995                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2996                         unsigned int len;
2997
2998                         if (ynl_attr_validate(yarg, attr))
2999                                 return MNL_CB_ERROR;
3000
3001                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3002                         dst->_present.dev_name_len = len;
3003                         dst->dev_name = malloc(len + 1);
3004                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
3005                         dst->dev_name[len] = 0;
3006                 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
3007                         if (ynl_attr_validate(yarg, attr))
3008                                 return MNL_CB_ERROR;
3009                         dst->_present.port_index = 1;
3010                         dst->port_index = mnl_attr_get_u32(attr);
3011                 } else if (type == DEVLINK_ATTR_SB_INDEX) {
3012                         if (ynl_attr_validate(yarg, attr))
3013                                 return MNL_CB_ERROR;
3014                         dst->_present.sb_index = 1;
3015                         dst->sb_index = mnl_attr_get_u32(attr);
3016                 } else if (type == DEVLINK_ATTR_SB_POOL_INDEX) {
3017                         if (ynl_attr_validate(yarg, attr))
3018                                 return MNL_CB_ERROR;
3019                         dst->_present.sb_pool_index = 1;
3020                         dst->sb_pool_index = mnl_attr_get_u16(attr);
3021                 }
3022         }
3023
3024         return MNL_CB_OK;
3025 }
3026
3027 struct devlink_sb_port_pool_get_rsp *
3028 devlink_sb_port_pool_get(struct ynl_sock *ys,
3029                          struct devlink_sb_port_pool_get_req *req)
3030 {
3031         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
3032         struct devlink_sb_port_pool_get_rsp *rsp;
3033         struct nlmsghdr *nlh;
3034         int err;
3035
3036         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_PORT_POOL_GET, 1);
3037         ys->req_policy = &devlink_nest;
3038         yrs.yarg.rsp_policy = &devlink_nest;
3039
3040         if (req->_present.bus_name_len)
3041                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3042         if (req->_present.dev_name_len)
3043                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3044         if (req->_present.port_index)
3045                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
3046         if (req->_present.sb_index)
3047                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
3048         if (req->_present.sb_pool_index)
3049                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_POOL_INDEX, req->sb_pool_index);
3050
3051         rsp = calloc(1, sizeof(*rsp));
3052         yrs.yarg.data = rsp;
3053         yrs.cb = devlink_sb_port_pool_get_rsp_parse;
3054         yrs.rsp_cmd = 21;
3055
3056         err = ynl_exec(ys, nlh, &yrs);
3057         if (err < 0)
3058                 goto err_free;
3059
3060         return rsp;
3061
3062 err_free:
3063         devlink_sb_port_pool_get_rsp_free(rsp);
3064         return NULL;
3065 }
3066
3067 /* DEVLINK_CMD_SB_PORT_POOL_GET - dump */
3068 void
3069 devlink_sb_port_pool_get_list_free(struct devlink_sb_port_pool_get_list *rsp)
3070 {
3071         struct devlink_sb_port_pool_get_list *next = rsp;
3072
3073         while ((void *)next != YNL_LIST_END) {
3074                 rsp = next;
3075                 next = rsp->next;
3076
3077                 free(rsp->obj.bus_name);
3078                 free(rsp->obj.dev_name);
3079                 free(rsp);
3080         }
3081 }
3082
3083 struct devlink_sb_port_pool_get_list *
3084 devlink_sb_port_pool_get_dump(struct ynl_sock *ys,
3085                               struct devlink_sb_port_pool_get_req_dump *req)
3086 {
3087         struct ynl_dump_state yds = {};
3088         struct nlmsghdr *nlh;
3089         int err;
3090
3091         yds.ys = ys;
3092         yds.alloc_sz = sizeof(struct devlink_sb_port_pool_get_list);
3093         yds.cb = devlink_sb_port_pool_get_rsp_parse;
3094         yds.rsp_cmd = 21;
3095         yds.rsp_policy = &devlink_nest;
3096
3097         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_PORT_POOL_GET, 1);
3098         ys->req_policy = &devlink_nest;
3099
3100         if (req->_present.bus_name_len)
3101                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3102         if (req->_present.dev_name_len)
3103                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3104
3105         err = ynl_exec_dump(ys, nlh, &yds);
3106         if (err < 0)
3107                 goto free_list;
3108
3109         return yds.first;
3110
3111 free_list:
3112         devlink_sb_port_pool_get_list_free(yds.first);
3113         return NULL;
3114 }
3115
3116 /* ============== DEVLINK_CMD_SB_PORT_POOL_SET ============== */
3117 /* DEVLINK_CMD_SB_PORT_POOL_SET - do */
3118 void
3119 devlink_sb_port_pool_set_req_free(struct devlink_sb_port_pool_set_req *req)
3120 {
3121         free(req->bus_name);
3122         free(req->dev_name);
3123         free(req);
3124 }
3125
3126 int devlink_sb_port_pool_set(struct ynl_sock *ys,
3127                              struct devlink_sb_port_pool_set_req *req)
3128 {
3129         struct nlmsghdr *nlh;
3130         int err;
3131
3132         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_PORT_POOL_SET, 1);
3133         ys->req_policy = &devlink_nest;
3134
3135         if (req->_present.bus_name_len)
3136                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3137         if (req->_present.dev_name_len)
3138                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3139         if (req->_present.port_index)
3140                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
3141         if (req->_present.sb_index)
3142                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
3143         if (req->_present.sb_pool_index)
3144                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_POOL_INDEX, req->sb_pool_index);
3145         if (req->_present.sb_threshold)
3146                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_THRESHOLD, req->sb_threshold);
3147
3148         err = ynl_exec(ys, nlh, NULL);
3149         if (err < 0)
3150                 return -1;
3151
3152         return 0;
3153 }
3154
3155 /* ============== DEVLINK_CMD_SB_TC_POOL_BIND_GET ============== */
3156 /* DEVLINK_CMD_SB_TC_POOL_BIND_GET - do */
3157 void
3158 devlink_sb_tc_pool_bind_get_req_free(struct devlink_sb_tc_pool_bind_get_req *req)
3159 {
3160         free(req->bus_name);
3161         free(req->dev_name);
3162         free(req);
3163 }
3164
3165 void
3166 devlink_sb_tc_pool_bind_get_rsp_free(struct devlink_sb_tc_pool_bind_get_rsp *rsp)
3167 {
3168         free(rsp->bus_name);
3169         free(rsp->dev_name);
3170         free(rsp);
3171 }
3172
3173 int devlink_sb_tc_pool_bind_get_rsp_parse(const struct nlmsghdr *nlh,
3174                                           void *data)
3175 {
3176         struct devlink_sb_tc_pool_bind_get_rsp *dst;
3177         struct ynl_parse_arg *yarg = data;
3178         const struct nlattr *attr;
3179
3180         dst = yarg->data;
3181
3182         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
3183                 unsigned int type = mnl_attr_get_type(attr);
3184
3185                 if (type == DEVLINK_ATTR_BUS_NAME) {
3186                         unsigned int len;
3187
3188                         if (ynl_attr_validate(yarg, attr))
3189                                 return MNL_CB_ERROR;
3190
3191                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3192                         dst->_present.bus_name_len = len;
3193                         dst->bus_name = malloc(len + 1);
3194                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
3195                         dst->bus_name[len] = 0;
3196                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
3197                         unsigned int len;
3198
3199                         if (ynl_attr_validate(yarg, attr))
3200                                 return MNL_CB_ERROR;
3201
3202                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3203                         dst->_present.dev_name_len = len;
3204                         dst->dev_name = malloc(len + 1);
3205                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
3206                         dst->dev_name[len] = 0;
3207                 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
3208                         if (ynl_attr_validate(yarg, attr))
3209                                 return MNL_CB_ERROR;
3210                         dst->_present.port_index = 1;
3211                         dst->port_index = mnl_attr_get_u32(attr);
3212                 } else if (type == DEVLINK_ATTR_SB_INDEX) {
3213                         if (ynl_attr_validate(yarg, attr))
3214                                 return MNL_CB_ERROR;
3215                         dst->_present.sb_index = 1;
3216                         dst->sb_index = mnl_attr_get_u32(attr);
3217                 } else if (type == DEVLINK_ATTR_SB_POOL_TYPE) {
3218                         if (ynl_attr_validate(yarg, attr))
3219                                 return MNL_CB_ERROR;
3220                         dst->_present.sb_pool_type = 1;
3221                         dst->sb_pool_type = mnl_attr_get_u8(attr);
3222                 } else if (type == DEVLINK_ATTR_SB_TC_INDEX) {
3223                         if (ynl_attr_validate(yarg, attr))
3224                                 return MNL_CB_ERROR;
3225                         dst->_present.sb_tc_index = 1;
3226                         dst->sb_tc_index = mnl_attr_get_u16(attr);
3227                 }
3228         }
3229
3230         return MNL_CB_OK;
3231 }
3232
3233 struct devlink_sb_tc_pool_bind_get_rsp *
3234 devlink_sb_tc_pool_bind_get(struct ynl_sock *ys,
3235                             struct devlink_sb_tc_pool_bind_get_req *req)
3236 {
3237         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
3238         struct devlink_sb_tc_pool_bind_get_rsp *rsp;
3239         struct nlmsghdr *nlh;
3240         int err;
3241
3242         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_TC_POOL_BIND_GET, 1);
3243         ys->req_policy = &devlink_nest;
3244         yrs.yarg.rsp_policy = &devlink_nest;
3245
3246         if (req->_present.bus_name_len)
3247                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3248         if (req->_present.dev_name_len)
3249                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3250         if (req->_present.port_index)
3251                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
3252         if (req->_present.sb_index)
3253                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
3254         if (req->_present.sb_pool_type)
3255                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_SB_POOL_TYPE, req->sb_pool_type);
3256         if (req->_present.sb_tc_index)
3257                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_TC_INDEX, req->sb_tc_index);
3258
3259         rsp = calloc(1, sizeof(*rsp));
3260         yrs.yarg.data = rsp;
3261         yrs.cb = devlink_sb_tc_pool_bind_get_rsp_parse;
3262         yrs.rsp_cmd = 25;
3263
3264         err = ynl_exec(ys, nlh, &yrs);
3265         if (err < 0)
3266                 goto err_free;
3267
3268         return rsp;
3269
3270 err_free:
3271         devlink_sb_tc_pool_bind_get_rsp_free(rsp);
3272         return NULL;
3273 }
3274
3275 /* DEVLINK_CMD_SB_TC_POOL_BIND_GET - dump */
3276 void
3277 devlink_sb_tc_pool_bind_get_list_free(struct devlink_sb_tc_pool_bind_get_list *rsp)
3278 {
3279         struct devlink_sb_tc_pool_bind_get_list *next = rsp;
3280
3281         while ((void *)next != YNL_LIST_END) {
3282                 rsp = next;
3283                 next = rsp->next;
3284
3285                 free(rsp->obj.bus_name);
3286                 free(rsp->obj.dev_name);
3287                 free(rsp);
3288         }
3289 }
3290
3291 struct devlink_sb_tc_pool_bind_get_list *
3292 devlink_sb_tc_pool_bind_get_dump(struct ynl_sock *ys,
3293                                  struct devlink_sb_tc_pool_bind_get_req_dump *req)
3294 {
3295         struct ynl_dump_state yds = {};
3296         struct nlmsghdr *nlh;
3297         int err;
3298
3299         yds.ys = ys;
3300         yds.alloc_sz = sizeof(struct devlink_sb_tc_pool_bind_get_list);
3301         yds.cb = devlink_sb_tc_pool_bind_get_rsp_parse;
3302         yds.rsp_cmd = 25;
3303         yds.rsp_policy = &devlink_nest;
3304
3305         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_TC_POOL_BIND_GET, 1);
3306         ys->req_policy = &devlink_nest;
3307
3308         if (req->_present.bus_name_len)
3309                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3310         if (req->_present.dev_name_len)
3311                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3312
3313         err = ynl_exec_dump(ys, nlh, &yds);
3314         if (err < 0)
3315                 goto free_list;
3316
3317         return yds.first;
3318
3319 free_list:
3320         devlink_sb_tc_pool_bind_get_list_free(yds.first);
3321         return NULL;
3322 }
3323
3324 /* ============== DEVLINK_CMD_SB_TC_POOL_BIND_SET ============== */
3325 /* DEVLINK_CMD_SB_TC_POOL_BIND_SET - do */
3326 void
3327 devlink_sb_tc_pool_bind_set_req_free(struct devlink_sb_tc_pool_bind_set_req *req)
3328 {
3329         free(req->bus_name);
3330         free(req->dev_name);
3331         free(req);
3332 }
3333
3334 int devlink_sb_tc_pool_bind_set(struct ynl_sock *ys,
3335                                 struct devlink_sb_tc_pool_bind_set_req *req)
3336 {
3337         struct nlmsghdr *nlh;
3338         int err;
3339
3340         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_TC_POOL_BIND_SET, 1);
3341         ys->req_policy = &devlink_nest;
3342
3343         if (req->_present.bus_name_len)
3344                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3345         if (req->_present.dev_name_len)
3346                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3347         if (req->_present.port_index)
3348                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
3349         if (req->_present.sb_index)
3350                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
3351         if (req->_present.sb_pool_index)
3352                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_POOL_INDEX, req->sb_pool_index);
3353         if (req->_present.sb_pool_type)
3354                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_SB_POOL_TYPE, req->sb_pool_type);
3355         if (req->_present.sb_tc_index)
3356                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_TC_INDEX, req->sb_tc_index);
3357         if (req->_present.sb_threshold)
3358                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_THRESHOLD, req->sb_threshold);
3359
3360         err = ynl_exec(ys, nlh, NULL);
3361         if (err < 0)
3362                 return -1;
3363
3364         return 0;
3365 }
3366
3367 /* ============== DEVLINK_CMD_SB_OCC_SNAPSHOT ============== */
3368 /* DEVLINK_CMD_SB_OCC_SNAPSHOT - do */
3369 void devlink_sb_occ_snapshot_req_free(struct devlink_sb_occ_snapshot_req *req)
3370 {
3371         free(req->bus_name);
3372         free(req->dev_name);
3373         free(req);
3374 }
3375
3376 int devlink_sb_occ_snapshot(struct ynl_sock *ys,
3377                             struct devlink_sb_occ_snapshot_req *req)
3378 {
3379         struct nlmsghdr *nlh;
3380         int err;
3381
3382         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_OCC_SNAPSHOT, 1);
3383         ys->req_policy = &devlink_nest;
3384
3385         if (req->_present.bus_name_len)
3386                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3387         if (req->_present.dev_name_len)
3388                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3389         if (req->_present.sb_index)
3390                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
3391
3392         err = ynl_exec(ys, nlh, NULL);
3393         if (err < 0)
3394                 return -1;
3395
3396         return 0;
3397 }
3398
3399 /* ============== DEVLINK_CMD_SB_OCC_MAX_CLEAR ============== */
3400 /* DEVLINK_CMD_SB_OCC_MAX_CLEAR - do */
3401 void
3402 devlink_sb_occ_max_clear_req_free(struct devlink_sb_occ_max_clear_req *req)
3403 {
3404         free(req->bus_name);
3405         free(req->dev_name);
3406         free(req);
3407 }
3408
3409 int devlink_sb_occ_max_clear(struct ynl_sock *ys,
3410                              struct devlink_sb_occ_max_clear_req *req)
3411 {
3412         struct nlmsghdr *nlh;
3413         int err;
3414
3415         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_OCC_MAX_CLEAR, 1);
3416         ys->req_policy = &devlink_nest;
3417
3418         if (req->_present.bus_name_len)
3419                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3420         if (req->_present.dev_name_len)
3421                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3422         if (req->_present.sb_index)
3423                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
3424
3425         err = ynl_exec(ys, nlh, NULL);
3426         if (err < 0)
3427                 return -1;
3428
3429         return 0;
3430 }
3431
3432 /* ============== DEVLINK_CMD_ESWITCH_GET ============== */
3433 /* DEVLINK_CMD_ESWITCH_GET - do */
3434 void devlink_eswitch_get_req_free(struct devlink_eswitch_get_req *req)
3435 {
3436         free(req->bus_name);
3437         free(req->dev_name);
3438         free(req);
3439 }
3440
3441 void devlink_eswitch_get_rsp_free(struct devlink_eswitch_get_rsp *rsp)
3442 {
3443         free(rsp->bus_name);
3444         free(rsp->dev_name);
3445         free(rsp);
3446 }
3447
3448 int devlink_eswitch_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
3449 {
3450         struct devlink_eswitch_get_rsp *dst;
3451         struct ynl_parse_arg *yarg = data;
3452         const struct nlattr *attr;
3453
3454         dst = yarg->data;
3455
3456         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
3457                 unsigned int type = mnl_attr_get_type(attr);
3458
3459                 if (type == DEVLINK_ATTR_BUS_NAME) {
3460                         unsigned int len;
3461
3462                         if (ynl_attr_validate(yarg, attr))
3463                                 return MNL_CB_ERROR;
3464
3465                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3466                         dst->_present.bus_name_len = len;
3467                         dst->bus_name = malloc(len + 1);
3468                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
3469                         dst->bus_name[len] = 0;
3470                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
3471                         unsigned int len;
3472
3473                         if (ynl_attr_validate(yarg, attr))
3474                                 return MNL_CB_ERROR;
3475
3476                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3477                         dst->_present.dev_name_len = len;
3478                         dst->dev_name = malloc(len + 1);
3479                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
3480                         dst->dev_name[len] = 0;
3481                 } else if (type == DEVLINK_ATTR_ESWITCH_MODE) {
3482                         if (ynl_attr_validate(yarg, attr))
3483                                 return MNL_CB_ERROR;
3484                         dst->_present.eswitch_mode = 1;
3485                         dst->eswitch_mode = mnl_attr_get_u16(attr);
3486                 } else if (type == DEVLINK_ATTR_ESWITCH_INLINE_MODE) {
3487                         if (ynl_attr_validate(yarg, attr))
3488                                 return MNL_CB_ERROR;
3489                         dst->_present.eswitch_inline_mode = 1;
3490                         dst->eswitch_inline_mode = mnl_attr_get_u16(attr);
3491                 } else if (type == DEVLINK_ATTR_ESWITCH_ENCAP_MODE) {
3492                         if (ynl_attr_validate(yarg, attr))
3493                                 return MNL_CB_ERROR;
3494                         dst->_present.eswitch_encap_mode = 1;
3495                         dst->eswitch_encap_mode = mnl_attr_get_u8(attr);
3496                 }
3497         }
3498
3499         return MNL_CB_OK;
3500 }
3501
3502 struct devlink_eswitch_get_rsp *
3503 devlink_eswitch_get(struct ynl_sock *ys, struct devlink_eswitch_get_req *req)
3504 {
3505         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
3506         struct devlink_eswitch_get_rsp *rsp;
3507         struct nlmsghdr *nlh;
3508         int err;
3509
3510         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_ESWITCH_GET, 1);
3511         ys->req_policy = &devlink_nest;
3512         yrs.yarg.rsp_policy = &devlink_nest;
3513
3514         if (req->_present.bus_name_len)
3515                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3516         if (req->_present.dev_name_len)
3517                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3518
3519         rsp = calloc(1, sizeof(*rsp));
3520         yrs.yarg.data = rsp;
3521         yrs.cb = devlink_eswitch_get_rsp_parse;
3522         yrs.rsp_cmd = DEVLINK_CMD_ESWITCH_GET;
3523
3524         err = ynl_exec(ys, nlh, &yrs);
3525         if (err < 0)
3526                 goto err_free;
3527
3528         return rsp;
3529
3530 err_free:
3531         devlink_eswitch_get_rsp_free(rsp);
3532         return NULL;
3533 }
3534
3535 /* ============== DEVLINK_CMD_ESWITCH_SET ============== */
3536 /* DEVLINK_CMD_ESWITCH_SET - do */
3537 void devlink_eswitch_set_req_free(struct devlink_eswitch_set_req *req)
3538 {
3539         free(req->bus_name);
3540         free(req->dev_name);
3541         free(req);
3542 }
3543
3544 int devlink_eswitch_set(struct ynl_sock *ys,
3545                         struct devlink_eswitch_set_req *req)
3546 {
3547         struct nlmsghdr *nlh;
3548         int err;
3549
3550         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_ESWITCH_SET, 1);
3551         ys->req_policy = &devlink_nest;
3552
3553         if (req->_present.bus_name_len)
3554                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3555         if (req->_present.dev_name_len)
3556                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3557         if (req->_present.eswitch_mode)
3558                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_ESWITCH_MODE, req->eswitch_mode);
3559         if (req->_present.eswitch_inline_mode)
3560                 mnl_attr_put_u16(nlh, DEVLINK_ATTR_ESWITCH_INLINE_MODE, req->eswitch_inline_mode);
3561         if (req->_present.eswitch_encap_mode)
3562                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_ESWITCH_ENCAP_MODE, req->eswitch_encap_mode);
3563
3564         err = ynl_exec(ys, nlh, NULL);
3565         if (err < 0)
3566                 return -1;
3567
3568         return 0;
3569 }
3570
3571 /* ============== DEVLINK_CMD_DPIPE_TABLE_GET ============== */
3572 /* DEVLINK_CMD_DPIPE_TABLE_GET - do */
3573 void devlink_dpipe_table_get_req_free(struct devlink_dpipe_table_get_req *req)
3574 {
3575         free(req->bus_name);
3576         free(req->dev_name);
3577         free(req->dpipe_table_name);
3578         free(req);
3579 }
3580
3581 void devlink_dpipe_table_get_rsp_free(struct devlink_dpipe_table_get_rsp *rsp)
3582 {
3583         free(rsp->bus_name);
3584         free(rsp->dev_name);
3585         devlink_dl_dpipe_tables_free(&rsp->dpipe_tables);
3586         free(rsp);
3587 }
3588
3589 int devlink_dpipe_table_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
3590 {
3591         struct devlink_dpipe_table_get_rsp *dst;
3592         struct ynl_parse_arg *yarg = data;
3593         const struct nlattr *attr;
3594         struct ynl_parse_arg parg;
3595
3596         dst = yarg->data;
3597         parg.ys = yarg->ys;
3598
3599         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
3600                 unsigned int type = mnl_attr_get_type(attr);
3601
3602                 if (type == DEVLINK_ATTR_BUS_NAME) {
3603                         unsigned int len;
3604
3605                         if (ynl_attr_validate(yarg, attr))
3606                                 return MNL_CB_ERROR;
3607
3608                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3609                         dst->_present.bus_name_len = len;
3610                         dst->bus_name = malloc(len + 1);
3611                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
3612                         dst->bus_name[len] = 0;
3613                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
3614                         unsigned int len;
3615
3616                         if (ynl_attr_validate(yarg, attr))
3617                                 return MNL_CB_ERROR;
3618
3619                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3620                         dst->_present.dev_name_len = len;
3621                         dst->dev_name = malloc(len + 1);
3622                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
3623                         dst->dev_name[len] = 0;
3624                 } else if (type == DEVLINK_ATTR_DPIPE_TABLES) {
3625                         if (ynl_attr_validate(yarg, attr))
3626                                 return MNL_CB_ERROR;
3627                         dst->_present.dpipe_tables = 1;
3628
3629                         parg.rsp_policy = &devlink_dl_dpipe_tables_nest;
3630                         parg.data = &dst->dpipe_tables;
3631                         if (devlink_dl_dpipe_tables_parse(&parg, attr))
3632                                 return MNL_CB_ERROR;
3633                 }
3634         }
3635
3636         return MNL_CB_OK;
3637 }
3638
3639 struct devlink_dpipe_table_get_rsp *
3640 devlink_dpipe_table_get(struct ynl_sock *ys,
3641                         struct devlink_dpipe_table_get_req *req)
3642 {
3643         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
3644         struct devlink_dpipe_table_get_rsp *rsp;
3645         struct nlmsghdr *nlh;
3646         int err;
3647
3648         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_DPIPE_TABLE_GET, 1);
3649         ys->req_policy = &devlink_nest;
3650         yrs.yarg.rsp_policy = &devlink_nest;
3651
3652         if (req->_present.bus_name_len)
3653                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3654         if (req->_present.dev_name_len)
3655                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3656         if (req->_present.dpipe_table_name_len)
3657                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DPIPE_TABLE_NAME, req->dpipe_table_name);
3658
3659         rsp = calloc(1, sizeof(*rsp));
3660         yrs.yarg.data = rsp;
3661         yrs.cb = devlink_dpipe_table_get_rsp_parse;
3662         yrs.rsp_cmd = DEVLINK_CMD_DPIPE_TABLE_GET;
3663
3664         err = ynl_exec(ys, nlh, &yrs);
3665         if (err < 0)
3666                 goto err_free;
3667
3668         return rsp;
3669
3670 err_free:
3671         devlink_dpipe_table_get_rsp_free(rsp);
3672         return NULL;
3673 }
3674
3675 /* ============== DEVLINK_CMD_DPIPE_ENTRIES_GET ============== */
3676 /* DEVLINK_CMD_DPIPE_ENTRIES_GET - do */
3677 void
3678 devlink_dpipe_entries_get_req_free(struct devlink_dpipe_entries_get_req *req)
3679 {
3680         free(req->bus_name);
3681         free(req->dev_name);
3682         free(req->dpipe_table_name);
3683         free(req);
3684 }
3685
3686 void
3687 devlink_dpipe_entries_get_rsp_free(struct devlink_dpipe_entries_get_rsp *rsp)
3688 {
3689         free(rsp->bus_name);
3690         free(rsp->dev_name);
3691         devlink_dl_dpipe_entries_free(&rsp->dpipe_entries);
3692         free(rsp);
3693 }
3694
3695 int devlink_dpipe_entries_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
3696 {
3697         struct devlink_dpipe_entries_get_rsp *dst;
3698         struct ynl_parse_arg *yarg = data;
3699         const struct nlattr *attr;
3700         struct ynl_parse_arg parg;
3701
3702         dst = yarg->data;
3703         parg.ys = yarg->ys;
3704
3705         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
3706                 unsigned int type = mnl_attr_get_type(attr);
3707
3708                 if (type == DEVLINK_ATTR_BUS_NAME) {
3709                         unsigned int len;
3710
3711                         if (ynl_attr_validate(yarg, attr))
3712                                 return MNL_CB_ERROR;
3713
3714                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3715                         dst->_present.bus_name_len = len;
3716                         dst->bus_name = malloc(len + 1);
3717                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
3718                         dst->bus_name[len] = 0;
3719                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
3720                         unsigned int len;
3721
3722                         if (ynl_attr_validate(yarg, attr))
3723                                 return MNL_CB_ERROR;
3724
3725                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3726                         dst->_present.dev_name_len = len;
3727                         dst->dev_name = malloc(len + 1);
3728                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
3729                         dst->dev_name[len] = 0;
3730                 } else if (type == DEVLINK_ATTR_DPIPE_ENTRIES) {
3731                         if (ynl_attr_validate(yarg, attr))
3732                                 return MNL_CB_ERROR;
3733                         dst->_present.dpipe_entries = 1;
3734
3735                         parg.rsp_policy = &devlink_dl_dpipe_entries_nest;
3736                         parg.data = &dst->dpipe_entries;
3737                         if (devlink_dl_dpipe_entries_parse(&parg, attr))
3738                                 return MNL_CB_ERROR;
3739                 }
3740         }
3741
3742         return MNL_CB_OK;
3743 }
3744
3745 struct devlink_dpipe_entries_get_rsp *
3746 devlink_dpipe_entries_get(struct ynl_sock *ys,
3747                           struct devlink_dpipe_entries_get_req *req)
3748 {
3749         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
3750         struct devlink_dpipe_entries_get_rsp *rsp;
3751         struct nlmsghdr *nlh;
3752         int err;
3753
3754         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_DPIPE_ENTRIES_GET, 1);
3755         ys->req_policy = &devlink_nest;
3756         yrs.yarg.rsp_policy = &devlink_nest;
3757
3758         if (req->_present.bus_name_len)
3759                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3760         if (req->_present.dev_name_len)
3761                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3762         if (req->_present.dpipe_table_name_len)
3763                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DPIPE_TABLE_NAME, req->dpipe_table_name);
3764
3765         rsp = calloc(1, sizeof(*rsp));
3766         yrs.yarg.data = rsp;
3767         yrs.cb = devlink_dpipe_entries_get_rsp_parse;
3768         yrs.rsp_cmd = DEVLINK_CMD_DPIPE_ENTRIES_GET;
3769
3770         err = ynl_exec(ys, nlh, &yrs);
3771         if (err < 0)
3772                 goto err_free;
3773
3774         return rsp;
3775
3776 err_free:
3777         devlink_dpipe_entries_get_rsp_free(rsp);
3778         return NULL;
3779 }
3780
3781 /* ============== DEVLINK_CMD_DPIPE_HEADERS_GET ============== */
3782 /* DEVLINK_CMD_DPIPE_HEADERS_GET - do */
3783 void
3784 devlink_dpipe_headers_get_req_free(struct devlink_dpipe_headers_get_req *req)
3785 {
3786         free(req->bus_name);
3787         free(req->dev_name);
3788         free(req);
3789 }
3790
3791 void
3792 devlink_dpipe_headers_get_rsp_free(struct devlink_dpipe_headers_get_rsp *rsp)
3793 {
3794         free(rsp->bus_name);
3795         free(rsp->dev_name);
3796         devlink_dl_dpipe_headers_free(&rsp->dpipe_headers);
3797         free(rsp);
3798 }
3799
3800 int devlink_dpipe_headers_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
3801 {
3802         struct devlink_dpipe_headers_get_rsp *dst;
3803         struct ynl_parse_arg *yarg = data;
3804         const struct nlattr *attr;
3805         struct ynl_parse_arg parg;
3806
3807         dst = yarg->data;
3808         parg.ys = yarg->ys;
3809
3810         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
3811                 unsigned int type = mnl_attr_get_type(attr);
3812
3813                 if (type == DEVLINK_ATTR_BUS_NAME) {
3814                         unsigned int len;
3815
3816                         if (ynl_attr_validate(yarg, attr))
3817                                 return MNL_CB_ERROR;
3818
3819                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3820                         dst->_present.bus_name_len = len;
3821                         dst->bus_name = malloc(len + 1);
3822                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
3823                         dst->bus_name[len] = 0;
3824                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
3825                         unsigned int len;
3826
3827                         if (ynl_attr_validate(yarg, attr))
3828                                 return MNL_CB_ERROR;
3829
3830                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3831                         dst->_present.dev_name_len = len;
3832                         dst->dev_name = malloc(len + 1);
3833                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
3834                         dst->dev_name[len] = 0;
3835                 } else if (type == DEVLINK_ATTR_DPIPE_HEADERS) {
3836                         if (ynl_attr_validate(yarg, attr))
3837                                 return MNL_CB_ERROR;
3838                         dst->_present.dpipe_headers = 1;
3839
3840                         parg.rsp_policy = &devlink_dl_dpipe_headers_nest;
3841                         parg.data = &dst->dpipe_headers;
3842                         if (devlink_dl_dpipe_headers_parse(&parg, attr))
3843                                 return MNL_CB_ERROR;
3844                 }
3845         }
3846
3847         return MNL_CB_OK;
3848 }
3849
3850 struct devlink_dpipe_headers_get_rsp *
3851 devlink_dpipe_headers_get(struct ynl_sock *ys,
3852                           struct devlink_dpipe_headers_get_req *req)
3853 {
3854         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
3855         struct devlink_dpipe_headers_get_rsp *rsp;
3856         struct nlmsghdr *nlh;
3857         int err;
3858
3859         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_DPIPE_HEADERS_GET, 1);
3860         ys->req_policy = &devlink_nest;
3861         yrs.yarg.rsp_policy = &devlink_nest;
3862
3863         if (req->_present.bus_name_len)
3864                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3865         if (req->_present.dev_name_len)
3866                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3867
3868         rsp = calloc(1, sizeof(*rsp));
3869         yrs.yarg.data = rsp;
3870         yrs.cb = devlink_dpipe_headers_get_rsp_parse;
3871         yrs.rsp_cmd = DEVLINK_CMD_DPIPE_HEADERS_GET;
3872
3873         err = ynl_exec(ys, nlh, &yrs);
3874         if (err < 0)
3875                 goto err_free;
3876
3877         return rsp;
3878
3879 err_free:
3880         devlink_dpipe_headers_get_rsp_free(rsp);
3881         return NULL;
3882 }
3883
3884 /* ============== DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET ============== */
3885 /* DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET - do */
3886 void
3887 devlink_dpipe_table_counters_set_req_free(struct devlink_dpipe_table_counters_set_req *req)
3888 {
3889         free(req->bus_name);
3890         free(req->dev_name);
3891         free(req->dpipe_table_name);
3892         free(req);
3893 }
3894
3895 int devlink_dpipe_table_counters_set(struct ynl_sock *ys,
3896                                      struct devlink_dpipe_table_counters_set_req *req)
3897 {
3898         struct nlmsghdr *nlh;
3899         int err;
3900
3901         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET, 1);
3902         ys->req_policy = &devlink_nest;
3903
3904         if (req->_present.bus_name_len)
3905                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3906         if (req->_present.dev_name_len)
3907                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3908         if (req->_present.dpipe_table_name_len)
3909                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DPIPE_TABLE_NAME, req->dpipe_table_name);
3910         if (req->_present.dpipe_table_counters_enabled)
3911                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED, req->dpipe_table_counters_enabled);
3912
3913         err = ynl_exec(ys, nlh, NULL);
3914         if (err < 0)
3915                 return -1;
3916
3917         return 0;
3918 }
3919
3920 /* ============== DEVLINK_CMD_RESOURCE_SET ============== */
3921 /* DEVLINK_CMD_RESOURCE_SET - do */
3922 void devlink_resource_set_req_free(struct devlink_resource_set_req *req)
3923 {
3924         free(req->bus_name);
3925         free(req->dev_name);
3926         free(req);
3927 }
3928
3929 int devlink_resource_set(struct ynl_sock *ys,
3930                          struct devlink_resource_set_req *req)
3931 {
3932         struct nlmsghdr *nlh;
3933         int err;
3934
3935         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_RESOURCE_SET, 1);
3936         ys->req_policy = &devlink_nest;
3937
3938         if (req->_present.bus_name_len)
3939                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
3940         if (req->_present.dev_name_len)
3941                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
3942         if (req->_present.resource_id)
3943                 mnl_attr_put_u64(nlh, DEVLINK_ATTR_RESOURCE_ID, req->resource_id);
3944         if (req->_present.resource_size)
3945                 mnl_attr_put_u64(nlh, DEVLINK_ATTR_RESOURCE_SIZE, req->resource_size);
3946
3947         err = ynl_exec(ys, nlh, NULL);
3948         if (err < 0)
3949                 return -1;
3950
3951         return 0;
3952 }
3953
3954 /* ============== DEVLINK_CMD_RESOURCE_DUMP ============== */
3955 /* DEVLINK_CMD_RESOURCE_DUMP - do */
3956 void devlink_resource_dump_req_free(struct devlink_resource_dump_req *req)
3957 {
3958         free(req->bus_name);
3959         free(req->dev_name);
3960         free(req);
3961 }
3962
3963 void devlink_resource_dump_rsp_free(struct devlink_resource_dump_rsp *rsp)
3964 {
3965         free(rsp->bus_name);
3966         free(rsp->dev_name);
3967         devlink_dl_resource_list_free(&rsp->resource_list);
3968         free(rsp);
3969 }
3970
3971 int devlink_resource_dump_rsp_parse(const struct nlmsghdr *nlh, void *data)
3972 {
3973         struct devlink_resource_dump_rsp *dst;
3974         struct ynl_parse_arg *yarg = data;
3975         const struct nlattr *attr;
3976         struct ynl_parse_arg parg;
3977
3978         dst = yarg->data;
3979         parg.ys = yarg->ys;
3980
3981         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
3982                 unsigned int type = mnl_attr_get_type(attr);
3983
3984                 if (type == DEVLINK_ATTR_BUS_NAME) {
3985                         unsigned int len;
3986
3987                         if (ynl_attr_validate(yarg, attr))
3988                                 return MNL_CB_ERROR;
3989
3990                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
3991                         dst->_present.bus_name_len = len;
3992                         dst->bus_name = malloc(len + 1);
3993                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
3994                         dst->bus_name[len] = 0;
3995                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
3996                         unsigned int len;
3997
3998                         if (ynl_attr_validate(yarg, attr))
3999                                 return MNL_CB_ERROR;
4000
4001                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4002                         dst->_present.dev_name_len = len;
4003                         dst->dev_name = malloc(len + 1);
4004                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
4005                         dst->dev_name[len] = 0;
4006                 } else if (type == DEVLINK_ATTR_RESOURCE_LIST) {
4007                         if (ynl_attr_validate(yarg, attr))
4008                                 return MNL_CB_ERROR;
4009                         dst->_present.resource_list = 1;
4010
4011                         parg.rsp_policy = &devlink_dl_resource_list_nest;
4012                         parg.data = &dst->resource_list;
4013                         if (devlink_dl_resource_list_parse(&parg, attr))
4014                                 return MNL_CB_ERROR;
4015                 }
4016         }
4017
4018         return MNL_CB_OK;
4019 }
4020
4021 struct devlink_resource_dump_rsp *
4022 devlink_resource_dump(struct ynl_sock *ys,
4023                       struct devlink_resource_dump_req *req)
4024 {
4025         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
4026         struct devlink_resource_dump_rsp *rsp;
4027         struct nlmsghdr *nlh;
4028         int err;
4029
4030         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_RESOURCE_DUMP, 1);
4031         ys->req_policy = &devlink_nest;
4032         yrs.yarg.rsp_policy = &devlink_nest;
4033
4034         if (req->_present.bus_name_len)
4035                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4036         if (req->_present.dev_name_len)
4037                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4038
4039         rsp = calloc(1, sizeof(*rsp));
4040         yrs.yarg.data = rsp;
4041         yrs.cb = devlink_resource_dump_rsp_parse;
4042         yrs.rsp_cmd = DEVLINK_CMD_RESOURCE_DUMP;
4043
4044         err = ynl_exec(ys, nlh, &yrs);
4045         if (err < 0)
4046                 goto err_free;
4047
4048         return rsp;
4049
4050 err_free:
4051         devlink_resource_dump_rsp_free(rsp);
4052         return NULL;
4053 }
4054
4055 /* ============== DEVLINK_CMD_RELOAD ============== */
4056 /* DEVLINK_CMD_RELOAD - do */
4057 void devlink_reload_req_free(struct devlink_reload_req *req)
4058 {
4059         free(req->bus_name);
4060         free(req->dev_name);
4061         free(req);
4062 }
4063
4064 void devlink_reload_rsp_free(struct devlink_reload_rsp *rsp)
4065 {
4066         free(rsp->bus_name);
4067         free(rsp->dev_name);
4068         free(rsp);
4069 }
4070
4071 int devlink_reload_rsp_parse(const struct nlmsghdr *nlh, void *data)
4072 {
4073         struct ynl_parse_arg *yarg = data;
4074         struct devlink_reload_rsp *dst;
4075         const struct nlattr *attr;
4076
4077         dst = yarg->data;
4078
4079         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
4080                 unsigned int type = mnl_attr_get_type(attr);
4081
4082                 if (type == DEVLINK_ATTR_BUS_NAME) {
4083                         unsigned int len;
4084
4085                         if (ynl_attr_validate(yarg, attr))
4086                                 return MNL_CB_ERROR;
4087
4088                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4089                         dst->_present.bus_name_len = len;
4090                         dst->bus_name = malloc(len + 1);
4091                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
4092                         dst->bus_name[len] = 0;
4093                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
4094                         unsigned int len;
4095
4096                         if (ynl_attr_validate(yarg, attr))
4097                                 return MNL_CB_ERROR;
4098
4099                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4100                         dst->_present.dev_name_len = len;
4101                         dst->dev_name = malloc(len + 1);
4102                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
4103                         dst->dev_name[len] = 0;
4104                 } else if (type == DEVLINK_ATTR_RELOAD_ACTIONS_PERFORMED) {
4105                         if (ynl_attr_validate(yarg, attr))
4106                                 return MNL_CB_ERROR;
4107                         dst->_present.reload_actions_performed = 1;
4108                         memcpy(&dst->reload_actions_performed, mnl_attr_get_payload(attr), sizeof(struct nla_bitfield32));
4109                 }
4110         }
4111
4112         return MNL_CB_OK;
4113 }
4114
4115 struct devlink_reload_rsp *
4116 devlink_reload(struct ynl_sock *ys, struct devlink_reload_req *req)
4117 {
4118         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
4119         struct devlink_reload_rsp *rsp;
4120         struct nlmsghdr *nlh;
4121         int err;
4122
4123         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_RELOAD, 1);
4124         ys->req_policy = &devlink_nest;
4125         yrs.yarg.rsp_policy = &devlink_nest;
4126
4127         if (req->_present.bus_name_len)
4128                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4129         if (req->_present.dev_name_len)
4130                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4131         if (req->_present.reload_action)
4132                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_RELOAD_ACTION, req->reload_action);
4133         if (req->_present.reload_limits)
4134                 mnl_attr_put(nlh, DEVLINK_ATTR_RELOAD_LIMITS, sizeof(struct nla_bitfield32), &req->reload_limits);
4135         if (req->_present.netns_pid)
4136                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_NETNS_PID, req->netns_pid);
4137         if (req->_present.netns_fd)
4138                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_NETNS_FD, req->netns_fd);
4139         if (req->_present.netns_id)
4140                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_NETNS_ID, req->netns_id);
4141
4142         rsp = calloc(1, sizeof(*rsp));
4143         yrs.yarg.data = rsp;
4144         yrs.cb = devlink_reload_rsp_parse;
4145         yrs.rsp_cmd = DEVLINK_CMD_RELOAD;
4146
4147         err = ynl_exec(ys, nlh, &yrs);
4148         if (err < 0)
4149                 goto err_free;
4150
4151         return rsp;
4152
4153 err_free:
4154         devlink_reload_rsp_free(rsp);
4155         return NULL;
4156 }
4157
4158 /* ============== DEVLINK_CMD_PARAM_GET ============== */
4159 /* DEVLINK_CMD_PARAM_GET - do */
4160 void devlink_param_get_req_free(struct devlink_param_get_req *req)
4161 {
4162         free(req->bus_name);
4163         free(req->dev_name);
4164         free(req->param_name);
4165         free(req);
4166 }
4167
4168 void devlink_param_get_rsp_free(struct devlink_param_get_rsp *rsp)
4169 {
4170         free(rsp->bus_name);
4171         free(rsp->dev_name);
4172         free(rsp->param_name);
4173         free(rsp);
4174 }
4175
4176 int devlink_param_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
4177 {
4178         struct devlink_param_get_rsp *dst;
4179         struct ynl_parse_arg *yarg = data;
4180         const struct nlattr *attr;
4181
4182         dst = yarg->data;
4183
4184         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
4185                 unsigned int type = mnl_attr_get_type(attr);
4186
4187                 if (type == DEVLINK_ATTR_BUS_NAME) {
4188                         unsigned int len;
4189
4190                         if (ynl_attr_validate(yarg, attr))
4191                                 return MNL_CB_ERROR;
4192
4193                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4194                         dst->_present.bus_name_len = len;
4195                         dst->bus_name = malloc(len + 1);
4196                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
4197                         dst->bus_name[len] = 0;
4198                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
4199                         unsigned int len;
4200
4201                         if (ynl_attr_validate(yarg, attr))
4202                                 return MNL_CB_ERROR;
4203
4204                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4205                         dst->_present.dev_name_len = len;
4206                         dst->dev_name = malloc(len + 1);
4207                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
4208                         dst->dev_name[len] = 0;
4209                 } else if (type == DEVLINK_ATTR_PARAM_NAME) {
4210                         unsigned int len;
4211
4212                         if (ynl_attr_validate(yarg, attr))
4213                                 return MNL_CB_ERROR;
4214
4215                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4216                         dst->_present.param_name_len = len;
4217                         dst->param_name = malloc(len + 1);
4218                         memcpy(dst->param_name, mnl_attr_get_str(attr), len);
4219                         dst->param_name[len] = 0;
4220                 }
4221         }
4222
4223         return MNL_CB_OK;
4224 }
4225
4226 struct devlink_param_get_rsp *
4227 devlink_param_get(struct ynl_sock *ys, struct devlink_param_get_req *req)
4228 {
4229         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
4230         struct devlink_param_get_rsp *rsp;
4231         struct nlmsghdr *nlh;
4232         int err;
4233
4234         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PARAM_GET, 1);
4235         ys->req_policy = &devlink_nest;
4236         yrs.yarg.rsp_policy = &devlink_nest;
4237
4238         if (req->_present.bus_name_len)
4239                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4240         if (req->_present.dev_name_len)
4241                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4242         if (req->_present.param_name_len)
4243                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_PARAM_NAME, req->param_name);
4244
4245         rsp = calloc(1, sizeof(*rsp));
4246         yrs.yarg.data = rsp;
4247         yrs.cb = devlink_param_get_rsp_parse;
4248         yrs.rsp_cmd = DEVLINK_CMD_PARAM_GET;
4249
4250         err = ynl_exec(ys, nlh, &yrs);
4251         if (err < 0)
4252                 goto err_free;
4253
4254         return rsp;
4255
4256 err_free:
4257         devlink_param_get_rsp_free(rsp);
4258         return NULL;
4259 }
4260
4261 /* DEVLINK_CMD_PARAM_GET - dump */
4262 void devlink_param_get_list_free(struct devlink_param_get_list *rsp)
4263 {
4264         struct devlink_param_get_list *next = rsp;
4265
4266         while ((void *)next != YNL_LIST_END) {
4267                 rsp = next;
4268                 next = rsp->next;
4269
4270                 free(rsp->obj.bus_name);
4271                 free(rsp->obj.dev_name);
4272                 free(rsp->obj.param_name);
4273                 free(rsp);
4274         }
4275 }
4276
4277 struct devlink_param_get_list *
4278 devlink_param_get_dump(struct ynl_sock *ys,
4279                        struct devlink_param_get_req_dump *req)
4280 {
4281         struct ynl_dump_state yds = {};
4282         struct nlmsghdr *nlh;
4283         int err;
4284
4285         yds.ys = ys;
4286         yds.alloc_sz = sizeof(struct devlink_param_get_list);
4287         yds.cb = devlink_param_get_rsp_parse;
4288         yds.rsp_cmd = DEVLINK_CMD_PARAM_GET;
4289         yds.rsp_policy = &devlink_nest;
4290
4291         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_PARAM_GET, 1);
4292         ys->req_policy = &devlink_nest;
4293
4294         if (req->_present.bus_name_len)
4295                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4296         if (req->_present.dev_name_len)
4297                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4298
4299         err = ynl_exec_dump(ys, nlh, &yds);
4300         if (err < 0)
4301                 goto free_list;
4302
4303         return yds.first;
4304
4305 free_list:
4306         devlink_param_get_list_free(yds.first);
4307         return NULL;
4308 }
4309
4310 /* ============== DEVLINK_CMD_PARAM_SET ============== */
4311 /* DEVLINK_CMD_PARAM_SET - do */
4312 void devlink_param_set_req_free(struct devlink_param_set_req *req)
4313 {
4314         free(req->bus_name);
4315         free(req->dev_name);
4316         free(req->param_name);
4317         free(req);
4318 }
4319
4320 int devlink_param_set(struct ynl_sock *ys, struct devlink_param_set_req *req)
4321 {
4322         struct nlmsghdr *nlh;
4323         int err;
4324
4325         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PARAM_SET, 1);
4326         ys->req_policy = &devlink_nest;
4327
4328         if (req->_present.bus_name_len)
4329                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4330         if (req->_present.dev_name_len)
4331                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4332         if (req->_present.param_name_len)
4333                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_PARAM_NAME, req->param_name);
4334         if (req->_present.param_type)
4335                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_PARAM_TYPE, req->param_type);
4336         if (req->_present.param_value_cmode)
4337                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_PARAM_VALUE_CMODE, req->param_value_cmode);
4338
4339         err = ynl_exec(ys, nlh, NULL);
4340         if (err < 0)
4341                 return -1;
4342
4343         return 0;
4344 }
4345
4346 /* ============== DEVLINK_CMD_REGION_GET ============== */
4347 /* DEVLINK_CMD_REGION_GET - do */
4348 void devlink_region_get_req_free(struct devlink_region_get_req *req)
4349 {
4350         free(req->bus_name);
4351         free(req->dev_name);
4352         free(req->region_name);
4353         free(req);
4354 }
4355
4356 void devlink_region_get_rsp_free(struct devlink_region_get_rsp *rsp)
4357 {
4358         free(rsp->bus_name);
4359         free(rsp->dev_name);
4360         free(rsp->region_name);
4361         free(rsp);
4362 }
4363
4364 int devlink_region_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
4365 {
4366         struct devlink_region_get_rsp *dst;
4367         struct ynl_parse_arg *yarg = data;
4368         const struct nlattr *attr;
4369
4370         dst = yarg->data;
4371
4372         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
4373                 unsigned int type = mnl_attr_get_type(attr);
4374
4375                 if (type == DEVLINK_ATTR_BUS_NAME) {
4376                         unsigned int len;
4377
4378                         if (ynl_attr_validate(yarg, attr))
4379                                 return MNL_CB_ERROR;
4380
4381                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4382                         dst->_present.bus_name_len = len;
4383                         dst->bus_name = malloc(len + 1);
4384                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
4385                         dst->bus_name[len] = 0;
4386                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
4387                         unsigned int len;
4388
4389                         if (ynl_attr_validate(yarg, attr))
4390                                 return MNL_CB_ERROR;
4391
4392                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4393                         dst->_present.dev_name_len = len;
4394                         dst->dev_name = malloc(len + 1);
4395                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
4396                         dst->dev_name[len] = 0;
4397                 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
4398                         if (ynl_attr_validate(yarg, attr))
4399                                 return MNL_CB_ERROR;
4400                         dst->_present.port_index = 1;
4401                         dst->port_index = mnl_attr_get_u32(attr);
4402                 } else if (type == DEVLINK_ATTR_REGION_NAME) {
4403                         unsigned int len;
4404
4405                         if (ynl_attr_validate(yarg, attr))
4406                                 return MNL_CB_ERROR;
4407
4408                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4409                         dst->_present.region_name_len = len;
4410                         dst->region_name = malloc(len + 1);
4411                         memcpy(dst->region_name, mnl_attr_get_str(attr), len);
4412                         dst->region_name[len] = 0;
4413                 }
4414         }
4415
4416         return MNL_CB_OK;
4417 }
4418
4419 struct devlink_region_get_rsp *
4420 devlink_region_get(struct ynl_sock *ys, struct devlink_region_get_req *req)
4421 {
4422         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
4423         struct devlink_region_get_rsp *rsp;
4424         struct nlmsghdr *nlh;
4425         int err;
4426
4427         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_REGION_GET, 1);
4428         ys->req_policy = &devlink_nest;
4429         yrs.yarg.rsp_policy = &devlink_nest;
4430
4431         if (req->_present.bus_name_len)
4432                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4433         if (req->_present.dev_name_len)
4434                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4435         if (req->_present.port_index)
4436                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
4437         if (req->_present.region_name_len)
4438                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_REGION_NAME, req->region_name);
4439
4440         rsp = calloc(1, sizeof(*rsp));
4441         yrs.yarg.data = rsp;
4442         yrs.cb = devlink_region_get_rsp_parse;
4443         yrs.rsp_cmd = DEVLINK_CMD_REGION_GET;
4444
4445         err = ynl_exec(ys, nlh, &yrs);
4446         if (err < 0)
4447                 goto err_free;
4448
4449         return rsp;
4450
4451 err_free:
4452         devlink_region_get_rsp_free(rsp);
4453         return NULL;
4454 }
4455
4456 /* DEVLINK_CMD_REGION_GET - dump */
4457 void devlink_region_get_list_free(struct devlink_region_get_list *rsp)
4458 {
4459         struct devlink_region_get_list *next = rsp;
4460
4461         while ((void *)next != YNL_LIST_END) {
4462                 rsp = next;
4463                 next = rsp->next;
4464
4465                 free(rsp->obj.bus_name);
4466                 free(rsp->obj.dev_name);
4467                 free(rsp->obj.region_name);
4468                 free(rsp);
4469         }
4470 }
4471
4472 struct devlink_region_get_list *
4473 devlink_region_get_dump(struct ynl_sock *ys,
4474                         struct devlink_region_get_req_dump *req)
4475 {
4476         struct ynl_dump_state yds = {};
4477         struct nlmsghdr *nlh;
4478         int err;
4479
4480         yds.ys = ys;
4481         yds.alloc_sz = sizeof(struct devlink_region_get_list);
4482         yds.cb = devlink_region_get_rsp_parse;
4483         yds.rsp_cmd = DEVLINK_CMD_REGION_GET;
4484         yds.rsp_policy = &devlink_nest;
4485
4486         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_REGION_GET, 1);
4487         ys->req_policy = &devlink_nest;
4488
4489         if (req->_present.bus_name_len)
4490                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4491         if (req->_present.dev_name_len)
4492                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4493
4494         err = ynl_exec_dump(ys, nlh, &yds);
4495         if (err < 0)
4496                 goto free_list;
4497
4498         return yds.first;
4499
4500 free_list:
4501         devlink_region_get_list_free(yds.first);
4502         return NULL;
4503 }
4504
4505 /* ============== DEVLINK_CMD_REGION_NEW ============== */
4506 /* DEVLINK_CMD_REGION_NEW - do */
4507 void devlink_region_new_req_free(struct devlink_region_new_req *req)
4508 {
4509         free(req->bus_name);
4510         free(req->dev_name);
4511         free(req->region_name);
4512         free(req);
4513 }
4514
4515 void devlink_region_new_rsp_free(struct devlink_region_new_rsp *rsp)
4516 {
4517         free(rsp->bus_name);
4518         free(rsp->dev_name);
4519         free(rsp->region_name);
4520         free(rsp);
4521 }
4522
4523 int devlink_region_new_rsp_parse(const struct nlmsghdr *nlh, void *data)
4524 {
4525         struct devlink_region_new_rsp *dst;
4526         struct ynl_parse_arg *yarg = data;
4527         const struct nlattr *attr;
4528
4529         dst = yarg->data;
4530
4531         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
4532                 unsigned int type = mnl_attr_get_type(attr);
4533
4534                 if (type == DEVLINK_ATTR_BUS_NAME) {
4535                         unsigned int len;
4536
4537                         if (ynl_attr_validate(yarg, attr))
4538                                 return MNL_CB_ERROR;
4539
4540                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4541                         dst->_present.bus_name_len = len;
4542                         dst->bus_name = malloc(len + 1);
4543                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
4544                         dst->bus_name[len] = 0;
4545                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
4546                         unsigned int len;
4547
4548                         if (ynl_attr_validate(yarg, attr))
4549                                 return MNL_CB_ERROR;
4550
4551                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4552                         dst->_present.dev_name_len = len;
4553                         dst->dev_name = malloc(len + 1);
4554                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
4555                         dst->dev_name[len] = 0;
4556                 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
4557                         if (ynl_attr_validate(yarg, attr))
4558                                 return MNL_CB_ERROR;
4559                         dst->_present.port_index = 1;
4560                         dst->port_index = mnl_attr_get_u32(attr);
4561                 } else if (type == DEVLINK_ATTR_REGION_NAME) {
4562                         unsigned int len;
4563
4564                         if (ynl_attr_validate(yarg, attr))
4565                                 return MNL_CB_ERROR;
4566
4567                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4568                         dst->_present.region_name_len = len;
4569                         dst->region_name = malloc(len + 1);
4570                         memcpy(dst->region_name, mnl_attr_get_str(attr), len);
4571                         dst->region_name[len] = 0;
4572                 } else if (type == DEVLINK_ATTR_REGION_SNAPSHOT_ID) {
4573                         if (ynl_attr_validate(yarg, attr))
4574                                 return MNL_CB_ERROR;
4575                         dst->_present.region_snapshot_id = 1;
4576                         dst->region_snapshot_id = mnl_attr_get_u32(attr);
4577                 }
4578         }
4579
4580         return MNL_CB_OK;
4581 }
4582
4583 struct devlink_region_new_rsp *
4584 devlink_region_new(struct ynl_sock *ys, struct devlink_region_new_req *req)
4585 {
4586         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
4587         struct devlink_region_new_rsp *rsp;
4588         struct nlmsghdr *nlh;
4589         int err;
4590
4591         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_REGION_NEW, 1);
4592         ys->req_policy = &devlink_nest;
4593         yrs.yarg.rsp_policy = &devlink_nest;
4594
4595         if (req->_present.bus_name_len)
4596                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4597         if (req->_present.dev_name_len)
4598                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4599         if (req->_present.port_index)
4600                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
4601         if (req->_present.region_name_len)
4602                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_REGION_NAME, req->region_name);
4603         if (req->_present.region_snapshot_id)
4604                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_REGION_SNAPSHOT_ID, req->region_snapshot_id);
4605
4606         rsp = calloc(1, sizeof(*rsp));
4607         yrs.yarg.data = rsp;
4608         yrs.cb = devlink_region_new_rsp_parse;
4609         yrs.rsp_cmd = DEVLINK_CMD_REGION_NEW;
4610
4611         err = ynl_exec(ys, nlh, &yrs);
4612         if (err < 0)
4613                 goto err_free;
4614
4615         return rsp;
4616
4617 err_free:
4618         devlink_region_new_rsp_free(rsp);
4619         return NULL;
4620 }
4621
4622 /* ============== DEVLINK_CMD_REGION_DEL ============== */
4623 /* DEVLINK_CMD_REGION_DEL - do */
4624 void devlink_region_del_req_free(struct devlink_region_del_req *req)
4625 {
4626         free(req->bus_name);
4627         free(req->dev_name);
4628         free(req->region_name);
4629         free(req);
4630 }
4631
4632 int devlink_region_del(struct ynl_sock *ys, struct devlink_region_del_req *req)
4633 {
4634         struct nlmsghdr *nlh;
4635         int err;
4636
4637         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_REGION_DEL, 1);
4638         ys->req_policy = &devlink_nest;
4639
4640         if (req->_present.bus_name_len)
4641                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4642         if (req->_present.dev_name_len)
4643                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4644         if (req->_present.port_index)
4645                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
4646         if (req->_present.region_name_len)
4647                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_REGION_NAME, req->region_name);
4648         if (req->_present.region_snapshot_id)
4649                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_REGION_SNAPSHOT_ID, req->region_snapshot_id);
4650
4651         err = ynl_exec(ys, nlh, NULL);
4652         if (err < 0)
4653                 return -1;
4654
4655         return 0;
4656 }
4657
4658 /* ============== DEVLINK_CMD_REGION_READ ============== */
4659 /* DEVLINK_CMD_REGION_READ - dump */
4660 int devlink_region_read_rsp_dump_parse(const struct nlmsghdr *nlh, void *data)
4661 {
4662         struct devlink_region_read_rsp_dump *dst;
4663         struct ynl_parse_arg *yarg = data;
4664         const struct nlattr *attr;
4665
4666         dst = yarg->data;
4667
4668         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
4669                 unsigned int type = mnl_attr_get_type(attr);
4670
4671                 if (type == DEVLINK_ATTR_BUS_NAME) {
4672                         unsigned int len;
4673
4674                         if (ynl_attr_validate(yarg, attr))
4675                                 return MNL_CB_ERROR;
4676
4677                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4678                         dst->_present.bus_name_len = len;
4679                         dst->bus_name = malloc(len + 1);
4680                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
4681                         dst->bus_name[len] = 0;
4682                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
4683                         unsigned int len;
4684
4685                         if (ynl_attr_validate(yarg, attr))
4686                                 return MNL_CB_ERROR;
4687
4688                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4689                         dst->_present.dev_name_len = len;
4690                         dst->dev_name = malloc(len + 1);
4691                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
4692                         dst->dev_name[len] = 0;
4693                 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
4694                         if (ynl_attr_validate(yarg, attr))
4695                                 return MNL_CB_ERROR;
4696                         dst->_present.port_index = 1;
4697                         dst->port_index = mnl_attr_get_u32(attr);
4698                 } else if (type == DEVLINK_ATTR_REGION_NAME) {
4699                         unsigned int len;
4700
4701                         if (ynl_attr_validate(yarg, attr))
4702                                 return MNL_CB_ERROR;
4703
4704                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4705                         dst->_present.region_name_len = len;
4706                         dst->region_name = malloc(len + 1);
4707                         memcpy(dst->region_name, mnl_attr_get_str(attr), len);
4708                         dst->region_name[len] = 0;
4709                 }
4710         }
4711
4712         return MNL_CB_OK;
4713 }
4714
4715 void
4716 devlink_region_read_rsp_list_free(struct devlink_region_read_rsp_list *rsp)
4717 {
4718         struct devlink_region_read_rsp_list *next = rsp;
4719
4720         while ((void *)next != YNL_LIST_END) {
4721                 rsp = next;
4722                 next = rsp->next;
4723
4724                 free(rsp->obj.bus_name);
4725                 free(rsp->obj.dev_name);
4726                 free(rsp->obj.region_name);
4727                 free(rsp);
4728         }
4729 }
4730
4731 struct devlink_region_read_rsp_list *
4732 devlink_region_read_dump(struct ynl_sock *ys,
4733                          struct devlink_region_read_req_dump *req)
4734 {
4735         struct ynl_dump_state yds = {};
4736         struct nlmsghdr *nlh;
4737         int err;
4738
4739         yds.ys = ys;
4740         yds.alloc_sz = sizeof(struct devlink_region_read_rsp_list);
4741         yds.cb = devlink_region_read_rsp_dump_parse;
4742         yds.rsp_cmd = DEVLINK_CMD_REGION_READ;
4743         yds.rsp_policy = &devlink_nest;
4744
4745         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_REGION_READ, 1);
4746         ys->req_policy = &devlink_nest;
4747
4748         if (req->_present.bus_name_len)
4749                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4750         if (req->_present.dev_name_len)
4751                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4752         if (req->_present.port_index)
4753                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
4754         if (req->_present.region_name_len)
4755                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_REGION_NAME, req->region_name);
4756         if (req->_present.region_snapshot_id)
4757                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_REGION_SNAPSHOT_ID, req->region_snapshot_id);
4758         if (req->_present.region_direct)
4759                 mnl_attr_put(nlh, DEVLINK_ATTR_REGION_DIRECT, 0, NULL);
4760         if (req->_present.region_chunk_addr)
4761                 mnl_attr_put_u64(nlh, DEVLINK_ATTR_REGION_CHUNK_ADDR, req->region_chunk_addr);
4762         if (req->_present.region_chunk_len)
4763                 mnl_attr_put_u64(nlh, DEVLINK_ATTR_REGION_CHUNK_LEN, req->region_chunk_len);
4764
4765         err = ynl_exec_dump(ys, nlh, &yds);
4766         if (err < 0)
4767                 goto free_list;
4768
4769         return yds.first;
4770
4771 free_list:
4772         devlink_region_read_rsp_list_free(yds.first);
4773         return NULL;
4774 }
4775
4776 /* ============== DEVLINK_CMD_PORT_PARAM_GET ============== */
4777 /* DEVLINK_CMD_PORT_PARAM_GET - do */
4778 void devlink_port_param_get_req_free(struct devlink_port_param_get_req *req)
4779 {
4780         free(req->bus_name);
4781         free(req->dev_name);
4782         free(req);
4783 }
4784
4785 void devlink_port_param_get_rsp_free(struct devlink_port_param_get_rsp *rsp)
4786 {
4787         free(rsp->bus_name);
4788         free(rsp->dev_name);
4789         free(rsp);
4790 }
4791
4792 int devlink_port_param_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
4793 {
4794         struct devlink_port_param_get_rsp *dst;
4795         struct ynl_parse_arg *yarg = data;
4796         const struct nlattr *attr;
4797
4798         dst = yarg->data;
4799
4800         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
4801                 unsigned int type = mnl_attr_get_type(attr);
4802
4803                 if (type == DEVLINK_ATTR_BUS_NAME) {
4804                         unsigned int len;
4805
4806                         if (ynl_attr_validate(yarg, attr))
4807                                 return MNL_CB_ERROR;
4808
4809                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4810                         dst->_present.bus_name_len = len;
4811                         dst->bus_name = malloc(len + 1);
4812                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
4813                         dst->bus_name[len] = 0;
4814                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
4815                         unsigned int len;
4816
4817                         if (ynl_attr_validate(yarg, attr))
4818                                 return MNL_CB_ERROR;
4819
4820                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4821                         dst->_present.dev_name_len = len;
4822                         dst->dev_name = malloc(len + 1);
4823                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
4824                         dst->dev_name[len] = 0;
4825                 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
4826                         if (ynl_attr_validate(yarg, attr))
4827                                 return MNL_CB_ERROR;
4828                         dst->_present.port_index = 1;
4829                         dst->port_index = mnl_attr_get_u32(attr);
4830                 }
4831         }
4832
4833         return MNL_CB_OK;
4834 }
4835
4836 struct devlink_port_param_get_rsp *
4837 devlink_port_param_get(struct ynl_sock *ys,
4838                        struct devlink_port_param_get_req *req)
4839 {
4840         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
4841         struct devlink_port_param_get_rsp *rsp;
4842         struct nlmsghdr *nlh;
4843         int err;
4844
4845         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PORT_PARAM_GET, 1);
4846         ys->req_policy = &devlink_nest;
4847         yrs.yarg.rsp_policy = &devlink_nest;
4848
4849         if (req->_present.bus_name_len)
4850                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4851         if (req->_present.dev_name_len)
4852                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4853         if (req->_present.port_index)
4854                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
4855
4856         rsp = calloc(1, sizeof(*rsp));
4857         yrs.yarg.data = rsp;
4858         yrs.cb = devlink_port_param_get_rsp_parse;
4859         yrs.rsp_cmd = DEVLINK_CMD_PORT_PARAM_GET;
4860
4861         err = ynl_exec(ys, nlh, &yrs);
4862         if (err < 0)
4863                 goto err_free;
4864
4865         return rsp;
4866
4867 err_free:
4868         devlink_port_param_get_rsp_free(rsp);
4869         return NULL;
4870 }
4871
4872 /* DEVLINK_CMD_PORT_PARAM_GET - dump */
4873 void devlink_port_param_get_list_free(struct devlink_port_param_get_list *rsp)
4874 {
4875         struct devlink_port_param_get_list *next = rsp;
4876
4877         while ((void *)next != YNL_LIST_END) {
4878                 rsp = next;
4879                 next = rsp->next;
4880
4881                 free(rsp->obj.bus_name);
4882                 free(rsp->obj.dev_name);
4883                 free(rsp);
4884         }
4885 }
4886
4887 struct devlink_port_param_get_list *
4888 devlink_port_param_get_dump(struct ynl_sock *ys)
4889 {
4890         struct ynl_dump_state yds = {};
4891         struct nlmsghdr *nlh;
4892         int err;
4893
4894         yds.ys = ys;
4895         yds.alloc_sz = sizeof(struct devlink_port_param_get_list);
4896         yds.cb = devlink_port_param_get_rsp_parse;
4897         yds.rsp_cmd = DEVLINK_CMD_PORT_PARAM_GET;
4898         yds.rsp_policy = &devlink_nest;
4899
4900         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_PORT_PARAM_GET, 1);
4901
4902         err = ynl_exec_dump(ys, nlh, &yds);
4903         if (err < 0)
4904                 goto free_list;
4905
4906         return yds.first;
4907
4908 free_list:
4909         devlink_port_param_get_list_free(yds.first);
4910         return NULL;
4911 }
4912
4913 /* ============== DEVLINK_CMD_PORT_PARAM_SET ============== */
4914 /* DEVLINK_CMD_PORT_PARAM_SET - do */
4915 void devlink_port_param_set_req_free(struct devlink_port_param_set_req *req)
4916 {
4917         free(req->bus_name);
4918         free(req->dev_name);
4919         free(req);
4920 }
4921
4922 int devlink_port_param_set(struct ynl_sock *ys,
4923                            struct devlink_port_param_set_req *req)
4924 {
4925         struct nlmsghdr *nlh;
4926         int err;
4927
4928         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PORT_PARAM_SET, 1);
4929         ys->req_policy = &devlink_nest;
4930
4931         if (req->_present.bus_name_len)
4932                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
4933         if (req->_present.dev_name_len)
4934                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
4935         if (req->_present.port_index)
4936                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
4937
4938         err = ynl_exec(ys, nlh, NULL);
4939         if (err < 0)
4940                 return -1;
4941
4942         return 0;
4943 }
4944
4945 /* ============== DEVLINK_CMD_INFO_GET ============== */
4946 /* DEVLINK_CMD_INFO_GET - do */
4947 void devlink_info_get_req_free(struct devlink_info_get_req *req)
4948 {
4949         free(req->bus_name);
4950         free(req->dev_name);
4951         free(req);
4952 }
4953
4954 void devlink_info_get_rsp_free(struct devlink_info_get_rsp *rsp)
4955 {
4956         unsigned int i;
4957
4958         free(rsp->bus_name);
4959         free(rsp->dev_name);
4960         free(rsp->info_driver_name);
4961         free(rsp->info_serial_number);
4962         for (i = 0; i < rsp->n_info_version_fixed; i++)
4963                 devlink_dl_info_version_free(&rsp->info_version_fixed[i]);
4964         free(rsp->info_version_fixed);
4965         for (i = 0; i < rsp->n_info_version_running; i++)
4966                 devlink_dl_info_version_free(&rsp->info_version_running[i]);
4967         free(rsp->info_version_running);
4968         for (i = 0; i < rsp->n_info_version_stored; i++)
4969                 devlink_dl_info_version_free(&rsp->info_version_stored[i]);
4970         free(rsp->info_version_stored);
4971         free(rsp);
4972 }
4973
4974 int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
4975 {
4976         unsigned int n_info_version_running = 0;
4977         unsigned int n_info_version_stored = 0;
4978         unsigned int n_info_version_fixed = 0;
4979         struct ynl_parse_arg *yarg = data;
4980         struct devlink_info_get_rsp *dst;
4981         const struct nlattr *attr;
4982         struct ynl_parse_arg parg;
4983         int i;
4984
4985         dst = yarg->data;
4986         parg.ys = yarg->ys;
4987
4988         if (dst->info_version_fixed)
4989                 return ynl_error_parse(yarg, "attribute already present (devlink.info-version-fixed)");
4990         if (dst->info_version_running)
4991                 return ynl_error_parse(yarg, "attribute already present (devlink.info-version-running)");
4992         if (dst->info_version_stored)
4993                 return ynl_error_parse(yarg, "attribute already present (devlink.info-version-stored)");
4994
4995         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
4996                 unsigned int type = mnl_attr_get_type(attr);
4997
4998                 if (type == DEVLINK_ATTR_BUS_NAME) {
4999                         unsigned int len;
5000
5001                         if (ynl_attr_validate(yarg, attr))
5002                                 return MNL_CB_ERROR;
5003
5004                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5005                         dst->_present.bus_name_len = len;
5006                         dst->bus_name = malloc(len + 1);
5007                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
5008                         dst->bus_name[len] = 0;
5009                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
5010                         unsigned int len;
5011
5012                         if (ynl_attr_validate(yarg, attr))
5013                                 return MNL_CB_ERROR;
5014
5015                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5016                         dst->_present.dev_name_len = len;
5017                         dst->dev_name = malloc(len + 1);
5018                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
5019                         dst->dev_name[len] = 0;
5020                 } else if (type == DEVLINK_ATTR_INFO_DRIVER_NAME) {
5021                         unsigned int len;
5022
5023                         if (ynl_attr_validate(yarg, attr))
5024                                 return MNL_CB_ERROR;
5025
5026                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5027                         dst->_present.info_driver_name_len = len;
5028                         dst->info_driver_name = malloc(len + 1);
5029                         memcpy(dst->info_driver_name, mnl_attr_get_str(attr), len);
5030                         dst->info_driver_name[len] = 0;
5031                 } else if (type == DEVLINK_ATTR_INFO_SERIAL_NUMBER) {
5032                         unsigned int len;
5033
5034                         if (ynl_attr_validate(yarg, attr))
5035                                 return MNL_CB_ERROR;
5036
5037                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5038                         dst->_present.info_serial_number_len = len;
5039                         dst->info_serial_number = malloc(len + 1);
5040                         memcpy(dst->info_serial_number, mnl_attr_get_str(attr), len);
5041                         dst->info_serial_number[len] = 0;
5042                 } else if (type == DEVLINK_ATTR_INFO_VERSION_FIXED) {
5043                         n_info_version_fixed++;
5044                 } else if (type == DEVLINK_ATTR_INFO_VERSION_RUNNING) {
5045                         n_info_version_running++;
5046                 } else if (type == DEVLINK_ATTR_INFO_VERSION_STORED) {
5047                         n_info_version_stored++;
5048                 }
5049         }
5050
5051         if (n_info_version_fixed) {
5052                 dst->info_version_fixed = calloc(n_info_version_fixed, sizeof(*dst->info_version_fixed));
5053                 dst->n_info_version_fixed = n_info_version_fixed;
5054                 i = 0;
5055                 parg.rsp_policy = &devlink_dl_info_version_nest;
5056                 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
5057                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_FIXED) {
5058                                 parg.data = &dst->info_version_fixed[i];
5059                                 if (devlink_dl_info_version_parse(&parg, attr))
5060                                         return MNL_CB_ERROR;
5061                                 i++;
5062                         }
5063                 }
5064         }
5065         if (n_info_version_running) {
5066                 dst->info_version_running = calloc(n_info_version_running, sizeof(*dst->info_version_running));
5067                 dst->n_info_version_running = n_info_version_running;
5068                 i = 0;
5069                 parg.rsp_policy = &devlink_dl_info_version_nest;
5070                 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
5071                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_RUNNING) {
5072                                 parg.data = &dst->info_version_running[i];
5073                                 if (devlink_dl_info_version_parse(&parg, attr))
5074                                         return MNL_CB_ERROR;
5075                                 i++;
5076                         }
5077                 }
5078         }
5079         if (n_info_version_stored) {
5080                 dst->info_version_stored = calloc(n_info_version_stored, sizeof(*dst->info_version_stored));
5081                 dst->n_info_version_stored = n_info_version_stored;
5082                 i = 0;
5083                 parg.rsp_policy = &devlink_dl_info_version_nest;
5084                 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
5085                         if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_STORED) {
5086                                 parg.data = &dst->info_version_stored[i];
5087                                 if (devlink_dl_info_version_parse(&parg, attr))
5088                                         return MNL_CB_ERROR;
5089                                 i++;
5090                         }
5091                 }
5092         }
5093
5094         return MNL_CB_OK;
5095 }
5096
5097 struct devlink_info_get_rsp *
5098 devlink_info_get(struct ynl_sock *ys, struct devlink_info_get_req *req)
5099 {
5100         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
5101         struct devlink_info_get_rsp *rsp;
5102         struct nlmsghdr *nlh;
5103         int err;
5104
5105         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_INFO_GET, 1);
5106         ys->req_policy = &devlink_nest;
5107         yrs.yarg.rsp_policy = &devlink_nest;
5108
5109         if (req->_present.bus_name_len)
5110                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5111         if (req->_present.dev_name_len)
5112                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5113
5114         rsp = calloc(1, sizeof(*rsp));
5115         yrs.yarg.data = rsp;
5116         yrs.cb = devlink_info_get_rsp_parse;
5117         yrs.rsp_cmd = DEVLINK_CMD_INFO_GET;
5118
5119         err = ynl_exec(ys, nlh, &yrs);
5120         if (err < 0)
5121                 goto err_free;
5122
5123         return rsp;
5124
5125 err_free:
5126         devlink_info_get_rsp_free(rsp);
5127         return NULL;
5128 }
5129
5130 /* DEVLINK_CMD_INFO_GET - dump */
5131 void devlink_info_get_list_free(struct devlink_info_get_list *rsp)
5132 {
5133         struct devlink_info_get_list *next = rsp;
5134
5135         while ((void *)next != YNL_LIST_END) {
5136                 unsigned int i;
5137
5138                 rsp = next;
5139                 next = rsp->next;
5140
5141                 free(rsp->obj.bus_name);
5142                 free(rsp->obj.dev_name);
5143                 free(rsp->obj.info_driver_name);
5144                 free(rsp->obj.info_serial_number);
5145                 for (i = 0; i < rsp->obj.n_info_version_fixed; i++)
5146                         devlink_dl_info_version_free(&rsp->obj.info_version_fixed[i]);
5147                 free(rsp->obj.info_version_fixed);
5148                 for (i = 0; i < rsp->obj.n_info_version_running; i++)
5149                         devlink_dl_info_version_free(&rsp->obj.info_version_running[i]);
5150                 free(rsp->obj.info_version_running);
5151                 for (i = 0; i < rsp->obj.n_info_version_stored; i++)
5152                         devlink_dl_info_version_free(&rsp->obj.info_version_stored[i]);
5153                 free(rsp->obj.info_version_stored);
5154                 free(rsp);
5155         }
5156 }
5157
5158 struct devlink_info_get_list *devlink_info_get_dump(struct ynl_sock *ys)
5159 {
5160         struct ynl_dump_state yds = {};
5161         struct nlmsghdr *nlh;
5162         int err;
5163
5164         yds.ys = ys;
5165         yds.alloc_sz = sizeof(struct devlink_info_get_list);
5166         yds.cb = devlink_info_get_rsp_parse;
5167         yds.rsp_cmd = DEVLINK_CMD_INFO_GET;
5168         yds.rsp_policy = &devlink_nest;
5169
5170         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_INFO_GET, 1);
5171
5172         err = ynl_exec_dump(ys, nlh, &yds);
5173         if (err < 0)
5174                 goto free_list;
5175
5176         return yds.first;
5177
5178 free_list:
5179         devlink_info_get_list_free(yds.first);
5180         return NULL;
5181 }
5182
5183 /* ============== DEVLINK_CMD_HEALTH_REPORTER_GET ============== */
5184 /* DEVLINK_CMD_HEALTH_REPORTER_GET - do */
5185 void
5186 devlink_health_reporter_get_req_free(struct devlink_health_reporter_get_req *req)
5187 {
5188         free(req->bus_name);
5189         free(req->dev_name);
5190         free(req->health_reporter_name);
5191         free(req);
5192 }
5193
5194 void
5195 devlink_health_reporter_get_rsp_free(struct devlink_health_reporter_get_rsp *rsp)
5196 {
5197         free(rsp->bus_name);
5198         free(rsp->dev_name);
5199         free(rsp->health_reporter_name);
5200         free(rsp);
5201 }
5202
5203 int devlink_health_reporter_get_rsp_parse(const struct nlmsghdr *nlh,
5204                                           void *data)
5205 {
5206         struct devlink_health_reporter_get_rsp *dst;
5207         struct ynl_parse_arg *yarg = data;
5208         const struct nlattr *attr;
5209
5210         dst = yarg->data;
5211
5212         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
5213                 unsigned int type = mnl_attr_get_type(attr);
5214
5215                 if (type == DEVLINK_ATTR_BUS_NAME) {
5216                         unsigned int len;
5217
5218                         if (ynl_attr_validate(yarg, attr))
5219                                 return MNL_CB_ERROR;
5220
5221                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5222                         dst->_present.bus_name_len = len;
5223                         dst->bus_name = malloc(len + 1);
5224                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
5225                         dst->bus_name[len] = 0;
5226                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
5227                         unsigned int len;
5228
5229                         if (ynl_attr_validate(yarg, attr))
5230                                 return MNL_CB_ERROR;
5231
5232                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5233                         dst->_present.dev_name_len = len;
5234                         dst->dev_name = malloc(len + 1);
5235                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
5236                         dst->dev_name[len] = 0;
5237                 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
5238                         if (ynl_attr_validate(yarg, attr))
5239                                 return MNL_CB_ERROR;
5240                         dst->_present.port_index = 1;
5241                         dst->port_index = mnl_attr_get_u32(attr);
5242                 } else if (type == DEVLINK_ATTR_HEALTH_REPORTER_NAME) {
5243                         unsigned int len;
5244
5245                         if (ynl_attr_validate(yarg, attr))
5246                                 return MNL_CB_ERROR;
5247
5248                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5249                         dst->_present.health_reporter_name_len = len;
5250                         dst->health_reporter_name = malloc(len + 1);
5251                         memcpy(dst->health_reporter_name, mnl_attr_get_str(attr), len);
5252                         dst->health_reporter_name[len] = 0;
5253                 }
5254         }
5255
5256         return MNL_CB_OK;
5257 }
5258
5259 struct devlink_health_reporter_get_rsp *
5260 devlink_health_reporter_get(struct ynl_sock *ys,
5261                             struct devlink_health_reporter_get_req *req)
5262 {
5263         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
5264         struct devlink_health_reporter_get_rsp *rsp;
5265         struct nlmsghdr *nlh;
5266         int err;
5267
5268         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_GET, 1);
5269         ys->req_policy = &devlink_nest;
5270         yrs.yarg.rsp_policy = &devlink_nest;
5271
5272         if (req->_present.bus_name_len)
5273                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5274         if (req->_present.dev_name_len)
5275                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5276         if (req->_present.port_index)
5277                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
5278         if (req->_present.health_reporter_name_len)
5279                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME, req->health_reporter_name);
5280
5281         rsp = calloc(1, sizeof(*rsp));
5282         yrs.yarg.data = rsp;
5283         yrs.cb = devlink_health_reporter_get_rsp_parse;
5284         yrs.rsp_cmd = DEVLINK_CMD_HEALTH_REPORTER_GET;
5285
5286         err = ynl_exec(ys, nlh, &yrs);
5287         if (err < 0)
5288                 goto err_free;
5289
5290         return rsp;
5291
5292 err_free:
5293         devlink_health_reporter_get_rsp_free(rsp);
5294         return NULL;
5295 }
5296
5297 /* DEVLINK_CMD_HEALTH_REPORTER_GET - dump */
5298 void
5299 devlink_health_reporter_get_list_free(struct devlink_health_reporter_get_list *rsp)
5300 {
5301         struct devlink_health_reporter_get_list *next = rsp;
5302
5303         while ((void *)next != YNL_LIST_END) {
5304                 rsp = next;
5305                 next = rsp->next;
5306
5307                 free(rsp->obj.bus_name);
5308                 free(rsp->obj.dev_name);
5309                 free(rsp->obj.health_reporter_name);
5310                 free(rsp);
5311         }
5312 }
5313
5314 struct devlink_health_reporter_get_list *
5315 devlink_health_reporter_get_dump(struct ynl_sock *ys,
5316                                  struct devlink_health_reporter_get_req_dump *req)
5317 {
5318         struct ynl_dump_state yds = {};
5319         struct nlmsghdr *nlh;
5320         int err;
5321
5322         yds.ys = ys;
5323         yds.alloc_sz = sizeof(struct devlink_health_reporter_get_list);
5324         yds.cb = devlink_health_reporter_get_rsp_parse;
5325         yds.rsp_cmd = DEVLINK_CMD_HEALTH_REPORTER_GET;
5326         yds.rsp_policy = &devlink_nest;
5327
5328         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_GET, 1);
5329         ys->req_policy = &devlink_nest;
5330
5331         if (req->_present.bus_name_len)
5332                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5333         if (req->_present.dev_name_len)
5334                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5335         if (req->_present.port_index)
5336                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
5337
5338         err = ynl_exec_dump(ys, nlh, &yds);
5339         if (err < 0)
5340                 goto free_list;
5341
5342         return yds.first;
5343
5344 free_list:
5345         devlink_health_reporter_get_list_free(yds.first);
5346         return NULL;
5347 }
5348
5349 /* ============== DEVLINK_CMD_HEALTH_REPORTER_SET ============== */
5350 /* DEVLINK_CMD_HEALTH_REPORTER_SET - do */
5351 void
5352 devlink_health_reporter_set_req_free(struct devlink_health_reporter_set_req *req)
5353 {
5354         free(req->bus_name);
5355         free(req->dev_name);
5356         free(req->health_reporter_name);
5357         free(req);
5358 }
5359
5360 int devlink_health_reporter_set(struct ynl_sock *ys,
5361                                 struct devlink_health_reporter_set_req *req)
5362 {
5363         struct nlmsghdr *nlh;
5364         int err;
5365
5366         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_SET, 1);
5367         ys->req_policy = &devlink_nest;
5368
5369         if (req->_present.bus_name_len)
5370                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5371         if (req->_present.dev_name_len)
5372                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5373         if (req->_present.port_index)
5374                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
5375         if (req->_present.health_reporter_name_len)
5376                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME, req->health_reporter_name);
5377         if (req->_present.health_reporter_graceful_period)
5378                 mnl_attr_put_u64(nlh, DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD, req->health_reporter_graceful_period);
5379         if (req->_present.health_reporter_auto_recover)
5380                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER, req->health_reporter_auto_recover);
5381         if (req->_present.health_reporter_auto_dump)
5382                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP, req->health_reporter_auto_dump);
5383
5384         err = ynl_exec(ys, nlh, NULL);
5385         if (err < 0)
5386                 return -1;
5387
5388         return 0;
5389 }
5390
5391 /* ============== DEVLINK_CMD_HEALTH_REPORTER_RECOVER ============== */
5392 /* DEVLINK_CMD_HEALTH_REPORTER_RECOVER - do */
5393 void
5394 devlink_health_reporter_recover_req_free(struct devlink_health_reporter_recover_req *req)
5395 {
5396         free(req->bus_name);
5397         free(req->dev_name);
5398         free(req->health_reporter_name);
5399         free(req);
5400 }
5401
5402 int devlink_health_reporter_recover(struct ynl_sock *ys,
5403                                     struct devlink_health_reporter_recover_req *req)
5404 {
5405         struct nlmsghdr *nlh;
5406         int err;
5407
5408         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_RECOVER, 1);
5409         ys->req_policy = &devlink_nest;
5410
5411         if (req->_present.bus_name_len)
5412                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5413         if (req->_present.dev_name_len)
5414                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5415         if (req->_present.port_index)
5416                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
5417         if (req->_present.health_reporter_name_len)
5418                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME, req->health_reporter_name);
5419
5420         err = ynl_exec(ys, nlh, NULL);
5421         if (err < 0)
5422                 return -1;
5423
5424         return 0;
5425 }
5426
5427 /* ============== DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE ============== */
5428 /* DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE - do */
5429 void
5430 devlink_health_reporter_diagnose_req_free(struct devlink_health_reporter_diagnose_req *req)
5431 {
5432         free(req->bus_name);
5433         free(req->dev_name);
5434         free(req->health_reporter_name);
5435         free(req);
5436 }
5437
5438 int devlink_health_reporter_diagnose(struct ynl_sock *ys,
5439                                      struct devlink_health_reporter_diagnose_req *req)
5440 {
5441         struct nlmsghdr *nlh;
5442         int err;
5443
5444         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, 1);
5445         ys->req_policy = &devlink_nest;
5446
5447         if (req->_present.bus_name_len)
5448                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5449         if (req->_present.dev_name_len)
5450                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5451         if (req->_present.port_index)
5452                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
5453         if (req->_present.health_reporter_name_len)
5454                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME, req->health_reporter_name);
5455
5456         err = ynl_exec(ys, nlh, NULL);
5457         if (err < 0)
5458                 return -1;
5459
5460         return 0;
5461 }
5462
5463 /* ============== DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET ============== */
5464 /* DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET - dump */
5465 int devlink_health_reporter_dump_get_rsp_dump_parse(const struct nlmsghdr *nlh,
5466                                                     void *data)
5467 {
5468         struct devlink_health_reporter_dump_get_rsp_dump *dst;
5469         struct ynl_parse_arg *yarg = data;
5470         const struct nlattr *attr;
5471         struct ynl_parse_arg parg;
5472
5473         dst = yarg->data;
5474         parg.ys = yarg->ys;
5475
5476         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
5477                 unsigned int type = mnl_attr_get_type(attr);
5478
5479                 if (type == DEVLINK_ATTR_FMSG) {
5480                         if (ynl_attr_validate(yarg, attr))
5481                                 return MNL_CB_ERROR;
5482                         dst->_present.fmsg = 1;
5483
5484                         parg.rsp_policy = &devlink_dl_fmsg_nest;
5485                         parg.data = &dst->fmsg;
5486                         if (devlink_dl_fmsg_parse(&parg, attr))
5487                                 return MNL_CB_ERROR;
5488                 }
5489         }
5490
5491         return MNL_CB_OK;
5492 }
5493
5494 void
5495 devlink_health_reporter_dump_get_rsp_list_free(struct devlink_health_reporter_dump_get_rsp_list *rsp)
5496 {
5497         struct devlink_health_reporter_dump_get_rsp_list *next = rsp;
5498
5499         while ((void *)next != YNL_LIST_END) {
5500                 rsp = next;
5501                 next = rsp->next;
5502
5503                 devlink_dl_fmsg_free(&rsp->obj.fmsg);
5504                 free(rsp);
5505         }
5506 }
5507
5508 struct devlink_health_reporter_dump_get_rsp_list *
5509 devlink_health_reporter_dump_get_dump(struct ynl_sock *ys,
5510                                       struct devlink_health_reporter_dump_get_req_dump *req)
5511 {
5512         struct ynl_dump_state yds = {};
5513         struct nlmsghdr *nlh;
5514         int err;
5515
5516         yds.ys = ys;
5517         yds.alloc_sz = sizeof(struct devlink_health_reporter_dump_get_rsp_list);
5518         yds.cb = devlink_health_reporter_dump_get_rsp_dump_parse;
5519         yds.rsp_cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET;
5520         yds.rsp_policy = &devlink_nest;
5521
5522         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET, 1);
5523         ys->req_policy = &devlink_nest;
5524
5525         if (req->_present.bus_name_len)
5526                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5527         if (req->_present.dev_name_len)
5528                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5529         if (req->_present.port_index)
5530                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
5531         if (req->_present.health_reporter_name_len)
5532                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME, req->health_reporter_name);
5533
5534         err = ynl_exec_dump(ys, nlh, &yds);
5535         if (err < 0)
5536                 goto free_list;
5537
5538         return yds.first;
5539
5540 free_list:
5541         devlink_health_reporter_dump_get_rsp_list_free(yds.first);
5542         return NULL;
5543 }
5544
5545 /* ============== DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR ============== */
5546 /* DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR - do */
5547 void
5548 devlink_health_reporter_dump_clear_req_free(struct devlink_health_reporter_dump_clear_req *req)
5549 {
5550         free(req->bus_name);
5551         free(req->dev_name);
5552         free(req->health_reporter_name);
5553         free(req);
5554 }
5555
5556 int devlink_health_reporter_dump_clear(struct ynl_sock *ys,
5557                                        struct devlink_health_reporter_dump_clear_req *req)
5558 {
5559         struct nlmsghdr *nlh;
5560         int err;
5561
5562         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR, 1);
5563         ys->req_policy = &devlink_nest;
5564
5565         if (req->_present.bus_name_len)
5566                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5567         if (req->_present.dev_name_len)
5568                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5569         if (req->_present.port_index)
5570                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
5571         if (req->_present.health_reporter_name_len)
5572                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME, req->health_reporter_name);
5573
5574         err = ynl_exec(ys, nlh, NULL);
5575         if (err < 0)
5576                 return -1;
5577
5578         return 0;
5579 }
5580
5581 /* ============== DEVLINK_CMD_FLASH_UPDATE ============== */
5582 /* DEVLINK_CMD_FLASH_UPDATE - do */
5583 void devlink_flash_update_req_free(struct devlink_flash_update_req *req)
5584 {
5585         free(req->bus_name);
5586         free(req->dev_name);
5587         free(req->flash_update_file_name);
5588         free(req->flash_update_component);
5589         free(req);
5590 }
5591
5592 int devlink_flash_update(struct ynl_sock *ys,
5593                          struct devlink_flash_update_req *req)
5594 {
5595         struct nlmsghdr *nlh;
5596         int err;
5597
5598         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_FLASH_UPDATE, 1);
5599         ys->req_policy = &devlink_nest;
5600
5601         if (req->_present.bus_name_len)
5602                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5603         if (req->_present.dev_name_len)
5604                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5605         if (req->_present.flash_update_file_name_len)
5606                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME, req->flash_update_file_name);
5607         if (req->_present.flash_update_component_len)
5608                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_FLASH_UPDATE_COMPONENT, req->flash_update_component);
5609         if (req->_present.flash_update_overwrite_mask)
5610                 mnl_attr_put(nlh, DEVLINK_ATTR_FLASH_UPDATE_OVERWRITE_MASK, sizeof(struct nla_bitfield32), &req->flash_update_overwrite_mask);
5611
5612         err = ynl_exec(ys, nlh, NULL);
5613         if (err < 0)
5614                 return -1;
5615
5616         return 0;
5617 }
5618
5619 /* ============== DEVLINK_CMD_TRAP_GET ============== */
5620 /* DEVLINK_CMD_TRAP_GET - do */
5621 void devlink_trap_get_req_free(struct devlink_trap_get_req *req)
5622 {
5623         free(req->bus_name);
5624         free(req->dev_name);
5625         free(req->trap_name);
5626         free(req);
5627 }
5628
5629 void devlink_trap_get_rsp_free(struct devlink_trap_get_rsp *rsp)
5630 {
5631         free(rsp->bus_name);
5632         free(rsp->dev_name);
5633         free(rsp->trap_name);
5634         free(rsp);
5635 }
5636
5637 int devlink_trap_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
5638 {
5639         struct ynl_parse_arg *yarg = data;
5640         struct devlink_trap_get_rsp *dst;
5641         const struct nlattr *attr;
5642
5643         dst = yarg->data;
5644
5645         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
5646                 unsigned int type = mnl_attr_get_type(attr);
5647
5648                 if (type == DEVLINK_ATTR_BUS_NAME) {
5649                         unsigned int len;
5650
5651                         if (ynl_attr_validate(yarg, attr))
5652                                 return MNL_CB_ERROR;
5653
5654                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5655                         dst->_present.bus_name_len = len;
5656                         dst->bus_name = malloc(len + 1);
5657                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
5658                         dst->bus_name[len] = 0;
5659                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
5660                         unsigned int len;
5661
5662                         if (ynl_attr_validate(yarg, attr))
5663                                 return MNL_CB_ERROR;
5664
5665                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5666                         dst->_present.dev_name_len = len;
5667                         dst->dev_name = malloc(len + 1);
5668                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
5669                         dst->dev_name[len] = 0;
5670                 } else if (type == DEVLINK_ATTR_TRAP_NAME) {
5671                         unsigned int len;
5672
5673                         if (ynl_attr_validate(yarg, attr))
5674                                 return MNL_CB_ERROR;
5675
5676                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5677                         dst->_present.trap_name_len = len;
5678                         dst->trap_name = malloc(len + 1);
5679                         memcpy(dst->trap_name, mnl_attr_get_str(attr), len);
5680                         dst->trap_name[len] = 0;
5681                 }
5682         }
5683
5684         return MNL_CB_OK;
5685 }
5686
5687 struct devlink_trap_get_rsp *
5688 devlink_trap_get(struct ynl_sock *ys, struct devlink_trap_get_req *req)
5689 {
5690         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
5691         struct devlink_trap_get_rsp *rsp;
5692         struct nlmsghdr *nlh;
5693         int err;
5694
5695         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_GET, 1);
5696         ys->req_policy = &devlink_nest;
5697         yrs.yarg.rsp_policy = &devlink_nest;
5698
5699         if (req->_present.bus_name_len)
5700                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5701         if (req->_present.dev_name_len)
5702                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5703         if (req->_present.trap_name_len)
5704                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_NAME, req->trap_name);
5705
5706         rsp = calloc(1, sizeof(*rsp));
5707         yrs.yarg.data = rsp;
5708         yrs.cb = devlink_trap_get_rsp_parse;
5709         yrs.rsp_cmd = 63;
5710
5711         err = ynl_exec(ys, nlh, &yrs);
5712         if (err < 0)
5713                 goto err_free;
5714
5715         return rsp;
5716
5717 err_free:
5718         devlink_trap_get_rsp_free(rsp);
5719         return NULL;
5720 }
5721
5722 /* DEVLINK_CMD_TRAP_GET - dump */
5723 void devlink_trap_get_list_free(struct devlink_trap_get_list *rsp)
5724 {
5725         struct devlink_trap_get_list *next = rsp;
5726
5727         while ((void *)next != YNL_LIST_END) {
5728                 rsp = next;
5729                 next = rsp->next;
5730
5731                 free(rsp->obj.bus_name);
5732                 free(rsp->obj.dev_name);
5733                 free(rsp->obj.trap_name);
5734                 free(rsp);
5735         }
5736 }
5737
5738 struct devlink_trap_get_list *
5739 devlink_trap_get_dump(struct ynl_sock *ys,
5740                       struct devlink_trap_get_req_dump *req)
5741 {
5742         struct ynl_dump_state yds = {};
5743         struct nlmsghdr *nlh;
5744         int err;
5745
5746         yds.ys = ys;
5747         yds.alloc_sz = sizeof(struct devlink_trap_get_list);
5748         yds.cb = devlink_trap_get_rsp_parse;
5749         yds.rsp_cmd = 63;
5750         yds.rsp_policy = &devlink_nest;
5751
5752         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_TRAP_GET, 1);
5753         ys->req_policy = &devlink_nest;
5754
5755         if (req->_present.bus_name_len)
5756                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5757         if (req->_present.dev_name_len)
5758                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5759
5760         err = ynl_exec_dump(ys, nlh, &yds);
5761         if (err < 0)
5762                 goto free_list;
5763
5764         return yds.first;
5765
5766 free_list:
5767         devlink_trap_get_list_free(yds.first);
5768         return NULL;
5769 }
5770
5771 /* ============== DEVLINK_CMD_TRAP_SET ============== */
5772 /* DEVLINK_CMD_TRAP_SET - do */
5773 void devlink_trap_set_req_free(struct devlink_trap_set_req *req)
5774 {
5775         free(req->bus_name);
5776         free(req->dev_name);
5777         free(req->trap_name);
5778         free(req);
5779 }
5780
5781 int devlink_trap_set(struct ynl_sock *ys, struct devlink_trap_set_req *req)
5782 {
5783         struct nlmsghdr *nlh;
5784         int err;
5785
5786         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_SET, 1);
5787         ys->req_policy = &devlink_nest;
5788
5789         if (req->_present.bus_name_len)
5790                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5791         if (req->_present.dev_name_len)
5792                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5793         if (req->_present.trap_name_len)
5794                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_NAME, req->trap_name);
5795         if (req->_present.trap_action)
5796                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_TRAP_ACTION, req->trap_action);
5797
5798         err = ynl_exec(ys, nlh, NULL);
5799         if (err < 0)
5800                 return -1;
5801
5802         return 0;
5803 }
5804
5805 /* ============== DEVLINK_CMD_TRAP_GROUP_GET ============== */
5806 /* DEVLINK_CMD_TRAP_GROUP_GET - do */
5807 void devlink_trap_group_get_req_free(struct devlink_trap_group_get_req *req)
5808 {
5809         free(req->bus_name);
5810         free(req->dev_name);
5811         free(req->trap_group_name);
5812         free(req);
5813 }
5814
5815 void devlink_trap_group_get_rsp_free(struct devlink_trap_group_get_rsp *rsp)
5816 {
5817         free(rsp->bus_name);
5818         free(rsp->dev_name);
5819         free(rsp->trap_group_name);
5820         free(rsp);
5821 }
5822
5823 int devlink_trap_group_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
5824 {
5825         struct devlink_trap_group_get_rsp *dst;
5826         struct ynl_parse_arg *yarg = data;
5827         const struct nlattr *attr;
5828
5829         dst = yarg->data;
5830
5831         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
5832                 unsigned int type = mnl_attr_get_type(attr);
5833
5834                 if (type == DEVLINK_ATTR_BUS_NAME) {
5835                         unsigned int len;
5836
5837                         if (ynl_attr_validate(yarg, attr))
5838                                 return MNL_CB_ERROR;
5839
5840                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5841                         dst->_present.bus_name_len = len;
5842                         dst->bus_name = malloc(len + 1);
5843                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
5844                         dst->bus_name[len] = 0;
5845                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
5846                         unsigned int len;
5847
5848                         if (ynl_attr_validate(yarg, attr))
5849                                 return MNL_CB_ERROR;
5850
5851                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5852                         dst->_present.dev_name_len = len;
5853                         dst->dev_name = malloc(len + 1);
5854                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
5855                         dst->dev_name[len] = 0;
5856                 } else if (type == DEVLINK_ATTR_TRAP_GROUP_NAME) {
5857                         unsigned int len;
5858
5859                         if (ynl_attr_validate(yarg, attr))
5860                                 return MNL_CB_ERROR;
5861
5862                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
5863                         dst->_present.trap_group_name_len = len;
5864                         dst->trap_group_name = malloc(len + 1);
5865                         memcpy(dst->trap_group_name, mnl_attr_get_str(attr), len);
5866                         dst->trap_group_name[len] = 0;
5867                 }
5868         }
5869
5870         return MNL_CB_OK;
5871 }
5872
5873 struct devlink_trap_group_get_rsp *
5874 devlink_trap_group_get(struct ynl_sock *ys,
5875                        struct devlink_trap_group_get_req *req)
5876 {
5877         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
5878         struct devlink_trap_group_get_rsp *rsp;
5879         struct nlmsghdr *nlh;
5880         int err;
5881
5882         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_GROUP_GET, 1);
5883         ys->req_policy = &devlink_nest;
5884         yrs.yarg.rsp_policy = &devlink_nest;
5885
5886         if (req->_present.bus_name_len)
5887                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5888         if (req->_present.dev_name_len)
5889                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5890         if (req->_present.trap_group_name_len)
5891                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_GROUP_NAME, req->trap_group_name);
5892
5893         rsp = calloc(1, sizeof(*rsp));
5894         yrs.yarg.data = rsp;
5895         yrs.cb = devlink_trap_group_get_rsp_parse;
5896         yrs.rsp_cmd = 67;
5897
5898         err = ynl_exec(ys, nlh, &yrs);
5899         if (err < 0)
5900                 goto err_free;
5901
5902         return rsp;
5903
5904 err_free:
5905         devlink_trap_group_get_rsp_free(rsp);
5906         return NULL;
5907 }
5908
5909 /* DEVLINK_CMD_TRAP_GROUP_GET - dump */
5910 void devlink_trap_group_get_list_free(struct devlink_trap_group_get_list *rsp)
5911 {
5912         struct devlink_trap_group_get_list *next = rsp;
5913
5914         while ((void *)next != YNL_LIST_END) {
5915                 rsp = next;
5916                 next = rsp->next;
5917
5918                 free(rsp->obj.bus_name);
5919                 free(rsp->obj.dev_name);
5920                 free(rsp->obj.trap_group_name);
5921                 free(rsp);
5922         }
5923 }
5924
5925 struct devlink_trap_group_get_list *
5926 devlink_trap_group_get_dump(struct ynl_sock *ys,
5927                             struct devlink_trap_group_get_req_dump *req)
5928 {
5929         struct ynl_dump_state yds = {};
5930         struct nlmsghdr *nlh;
5931         int err;
5932
5933         yds.ys = ys;
5934         yds.alloc_sz = sizeof(struct devlink_trap_group_get_list);
5935         yds.cb = devlink_trap_group_get_rsp_parse;
5936         yds.rsp_cmd = 67;
5937         yds.rsp_policy = &devlink_nest;
5938
5939         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_TRAP_GROUP_GET, 1);
5940         ys->req_policy = &devlink_nest;
5941
5942         if (req->_present.bus_name_len)
5943                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5944         if (req->_present.dev_name_len)
5945                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5946
5947         err = ynl_exec_dump(ys, nlh, &yds);
5948         if (err < 0)
5949                 goto free_list;
5950
5951         return yds.first;
5952
5953 free_list:
5954         devlink_trap_group_get_list_free(yds.first);
5955         return NULL;
5956 }
5957
5958 /* ============== DEVLINK_CMD_TRAP_GROUP_SET ============== */
5959 /* DEVLINK_CMD_TRAP_GROUP_SET - do */
5960 void devlink_trap_group_set_req_free(struct devlink_trap_group_set_req *req)
5961 {
5962         free(req->bus_name);
5963         free(req->dev_name);
5964         free(req->trap_group_name);
5965         free(req);
5966 }
5967
5968 int devlink_trap_group_set(struct ynl_sock *ys,
5969                            struct devlink_trap_group_set_req *req)
5970 {
5971         struct nlmsghdr *nlh;
5972         int err;
5973
5974         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_GROUP_SET, 1);
5975         ys->req_policy = &devlink_nest;
5976
5977         if (req->_present.bus_name_len)
5978                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5979         if (req->_present.dev_name_len)
5980                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5981         if (req->_present.trap_group_name_len)
5982                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_GROUP_NAME, req->trap_group_name);
5983         if (req->_present.trap_action)
5984                 mnl_attr_put_u8(nlh, DEVLINK_ATTR_TRAP_ACTION, req->trap_action);
5985         if (req->_present.trap_policer_id)
5986                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_TRAP_POLICER_ID, req->trap_policer_id);
5987
5988         err = ynl_exec(ys, nlh, NULL);
5989         if (err < 0)
5990                 return -1;
5991
5992         return 0;
5993 }
5994
5995 /* ============== DEVLINK_CMD_TRAP_POLICER_GET ============== */
5996 /* DEVLINK_CMD_TRAP_POLICER_GET - do */
5997 void
5998 devlink_trap_policer_get_req_free(struct devlink_trap_policer_get_req *req)
5999 {
6000         free(req->bus_name);
6001         free(req->dev_name);
6002         free(req);
6003 }
6004
6005 void
6006 devlink_trap_policer_get_rsp_free(struct devlink_trap_policer_get_rsp *rsp)
6007 {
6008         free(rsp->bus_name);
6009         free(rsp->dev_name);
6010         free(rsp);
6011 }
6012
6013 int devlink_trap_policer_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
6014 {
6015         struct devlink_trap_policer_get_rsp *dst;
6016         struct ynl_parse_arg *yarg = data;
6017         const struct nlattr *attr;
6018
6019         dst = yarg->data;
6020
6021         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
6022                 unsigned int type = mnl_attr_get_type(attr);
6023
6024                 if (type == DEVLINK_ATTR_BUS_NAME) {
6025                         unsigned int len;
6026
6027                         if (ynl_attr_validate(yarg, attr))
6028                                 return MNL_CB_ERROR;
6029
6030                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6031                         dst->_present.bus_name_len = len;
6032                         dst->bus_name = malloc(len + 1);
6033                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
6034                         dst->bus_name[len] = 0;
6035                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
6036                         unsigned int len;
6037
6038                         if (ynl_attr_validate(yarg, attr))
6039                                 return MNL_CB_ERROR;
6040
6041                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6042                         dst->_present.dev_name_len = len;
6043                         dst->dev_name = malloc(len + 1);
6044                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
6045                         dst->dev_name[len] = 0;
6046                 } else if (type == DEVLINK_ATTR_TRAP_POLICER_ID) {
6047                         if (ynl_attr_validate(yarg, attr))
6048                                 return MNL_CB_ERROR;
6049                         dst->_present.trap_policer_id = 1;
6050                         dst->trap_policer_id = mnl_attr_get_u32(attr);
6051                 }
6052         }
6053
6054         return MNL_CB_OK;
6055 }
6056
6057 struct devlink_trap_policer_get_rsp *
6058 devlink_trap_policer_get(struct ynl_sock *ys,
6059                          struct devlink_trap_policer_get_req *req)
6060 {
6061         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
6062         struct devlink_trap_policer_get_rsp *rsp;
6063         struct nlmsghdr *nlh;
6064         int err;
6065
6066         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_POLICER_GET, 1);
6067         ys->req_policy = &devlink_nest;
6068         yrs.yarg.rsp_policy = &devlink_nest;
6069
6070         if (req->_present.bus_name_len)
6071                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6072         if (req->_present.dev_name_len)
6073                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6074         if (req->_present.trap_policer_id)
6075                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_TRAP_POLICER_ID, req->trap_policer_id);
6076
6077         rsp = calloc(1, sizeof(*rsp));
6078         yrs.yarg.data = rsp;
6079         yrs.cb = devlink_trap_policer_get_rsp_parse;
6080         yrs.rsp_cmd = 71;
6081
6082         err = ynl_exec(ys, nlh, &yrs);
6083         if (err < 0)
6084                 goto err_free;
6085
6086         return rsp;
6087
6088 err_free:
6089         devlink_trap_policer_get_rsp_free(rsp);
6090         return NULL;
6091 }
6092
6093 /* DEVLINK_CMD_TRAP_POLICER_GET - dump */
6094 void
6095 devlink_trap_policer_get_list_free(struct devlink_trap_policer_get_list *rsp)
6096 {
6097         struct devlink_trap_policer_get_list *next = rsp;
6098
6099         while ((void *)next != YNL_LIST_END) {
6100                 rsp = next;
6101                 next = rsp->next;
6102
6103                 free(rsp->obj.bus_name);
6104                 free(rsp->obj.dev_name);
6105                 free(rsp);
6106         }
6107 }
6108
6109 struct devlink_trap_policer_get_list *
6110 devlink_trap_policer_get_dump(struct ynl_sock *ys,
6111                               struct devlink_trap_policer_get_req_dump *req)
6112 {
6113         struct ynl_dump_state yds = {};
6114         struct nlmsghdr *nlh;
6115         int err;
6116
6117         yds.ys = ys;
6118         yds.alloc_sz = sizeof(struct devlink_trap_policer_get_list);
6119         yds.cb = devlink_trap_policer_get_rsp_parse;
6120         yds.rsp_cmd = 71;
6121         yds.rsp_policy = &devlink_nest;
6122
6123         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_TRAP_POLICER_GET, 1);
6124         ys->req_policy = &devlink_nest;
6125
6126         if (req->_present.bus_name_len)
6127                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6128         if (req->_present.dev_name_len)
6129                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6130
6131         err = ynl_exec_dump(ys, nlh, &yds);
6132         if (err < 0)
6133                 goto free_list;
6134
6135         return yds.first;
6136
6137 free_list:
6138         devlink_trap_policer_get_list_free(yds.first);
6139         return NULL;
6140 }
6141
6142 /* ============== DEVLINK_CMD_TRAP_POLICER_SET ============== */
6143 /* DEVLINK_CMD_TRAP_POLICER_SET - do */
6144 void
6145 devlink_trap_policer_set_req_free(struct devlink_trap_policer_set_req *req)
6146 {
6147         free(req->bus_name);
6148         free(req->dev_name);
6149         free(req);
6150 }
6151
6152 int devlink_trap_policer_set(struct ynl_sock *ys,
6153                              struct devlink_trap_policer_set_req *req)
6154 {
6155         struct nlmsghdr *nlh;
6156         int err;
6157
6158         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_POLICER_SET, 1);
6159         ys->req_policy = &devlink_nest;
6160
6161         if (req->_present.bus_name_len)
6162                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6163         if (req->_present.dev_name_len)
6164                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6165         if (req->_present.trap_policer_id)
6166                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_TRAP_POLICER_ID, req->trap_policer_id);
6167         if (req->_present.trap_policer_rate)
6168                 mnl_attr_put_u64(nlh, DEVLINK_ATTR_TRAP_POLICER_RATE, req->trap_policer_rate);
6169         if (req->_present.trap_policer_burst)
6170                 mnl_attr_put_u64(nlh, DEVLINK_ATTR_TRAP_POLICER_BURST, req->trap_policer_burst);
6171
6172         err = ynl_exec(ys, nlh, NULL);
6173         if (err < 0)
6174                 return -1;
6175
6176         return 0;
6177 }
6178
6179 /* ============== DEVLINK_CMD_HEALTH_REPORTER_TEST ============== */
6180 /* DEVLINK_CMD_HEALTH_REPORTER_TEST - do */
6181 void
6182 devlink_health_reporter_test_req_free(struct devlink_health_reporter_test_req *req)
6183 {
6184         free(req->bus_name);
6185         free(req->dev_name);
6186         free(req->health_reporter_name);
6187         free(req);
6188 }
6189
6190 int devlink_health_reporter_test(struct ynl_sock *ys,
6191                                  struct devlink_health_reporter_test_req *req)
6192 {
6193         struct nlmsghdr *nlh;
6194         int err;
6195
6196         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_TEST, 1);
6197         ys->req_policy = &devlink_nest;
6198
6199         if (req->_present.bus_name_len)
6200                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6201         if (req->_present.dev_name_len)
6202                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6203         if (req->_present.port_index)
6204                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
6205         if (req->_present.health_reporter_name_len)
6206                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME, req->health_reporter_name);
6207
6208         err = ynl_exec(ys, nlh, NULL);
6209         if (err < 0)
6210                 return -1;
6211
6212         return 0;
6213 }
6214
6215 /* ============== DEVLINK_CMD_RATE_GET ============== */
6216 /* DEVLINK_CMD_RATE_GET - do */
6217 void devlink_rate_get_req_free(struct devlink_rate_get_req *req)
6218 {
6219         free(req->bus_name);
6220         free(req->dev_name);
6221         free(req->rate_node_name);
6222         free(req);
6223 }
6224
6225 void devlink_rate_get_rsp_free(struct devlink_rate_get_rsp *rsp)
6226 {
6227         free(rsp->bus_name);
6228         free(rsp->dev_name);
6229         free(rsp->rate_node_name);
6230         free(rsp);
6231 }
6232
6233 int devlink_rate_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
6234 {
6235         struct ynl_parse_arg *yarg = data;
6236         struct devlink_rate_get_rsp *dst;
6237         const struct nlattr *attr;
6238
6239         dst = yarg->data;
6240
6241         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
6242                 unsigned int type = mnl_attr_get_type(attr);
6243
6244                 if (type == DEVLINK_ATTR_BUS_NAME) {
6245                         unsigned int len;
6246
6247                         if (ynl_attr_validate(yarg, attr))
6248                                 return MNL_CB_ERROR;
6249
6250                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6251                         dst->_present.bus_name_len = len;
6252                         dst->bus_name = malloc(len + 1);
6253                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
6254                         dst->bus_name[len] = 0;
6255                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
6256                         unsigned int len;
6257
6258                         if (ynl_attr_validate(yarg, attr))
6259                                 return MNL_CB_ERROR;
6260
6261                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6262                         dst->_present.dev_name_len = len;
6263                         dst->dev_name = malloc(len + 1);
6264                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
6265                         dst->dev_name[len] = 0;
6266                 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
6267                         if (ynl_attr_validate(yarg, attr))
6268                                 return MNL_CB_ERROR;
6269                         dst->_present.port_index = 1;
6270                         dst->port_index = mnl_attr_get_u32(attr);
6271                 } else if (type == DEVLINK_ATTR_RATE_NODE_NAME) {
6272                         unsigned int len;
6273
6274                         if (ynl_attr_validate(yarg, attr))
6275                                 return MNL_CB_ERROR;
6276
6277                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6278                         dst->_present.rate_node_name_len = len;
6279                         dst->rate_node_name = malloc(len + 1);
6280                         memcpy(dst->rate_node_name, mnl_attr_get_str(attr), len);
6281                         dst->rate_node_name[len] = 0;
6282                 }
6283         }
6284
6285         return MNL_CB_OK;
6286 }
6287
6288 struct devlink_rate_get_rsp *
6289 devlink_rate_get(struct ynl_sock *ys, struct devlink_rate_get_req *req)
6290 {
6291         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
6292         struct devlink_rate_get_rsp *rsp;
6293         struct nlmsghdr *nlh;
6294         int err;
6295
6296         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_RATE_GET, 1);
6297         ys->req_policy = &devlink_nest;
6298         yrs.yarg.rsp_policy = &devlink_nest;
6299
6300         if (req->_present.bus_name_len)
6301                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6302         if (req->_present.dev_name_len)
6303                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6304         if (req->_present.port_index)
6305                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
6306         if (req->_present.rate_node_name_len)
6307                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_RATE_NODE_NAME, req->rate_node_name);
6308
6309         rsp = calloc(1, sizeof(*rsp));
6310         yrs.yarg.data = rsp;
6311         yrs.cb = devlink_rate_get_rsp_parse;
6312         yrs.rsp_cmd = 76;
6313
6314         err = ynl_exec(ys, nlh, &yrs);
6315         if (err < 0)
6316                 goto err_free;
6317
6318         return rsp;
6319
6320 err_free:
6321         devlink_rate_get_rsp_free(rsp);
6322         return NULL;
6323 }
6324
6325 /* DEVLINK_CMD_RATE_GET - dump */
6326 void devlink_rate_get_list_free(struct devlink_rate_get_list *rsp)
6327 {
6328         struct devlink_rate_get_list *next = rsp;
6329
6330         while ((void *)next != YNL_LIST_END) {
6331                 rsp = next;
6332                 next = rsp->next;
6333
6334                 free(rsp->obj.bus_name);
6335                 free(rsp->obj.dev_name);
6336                 free(rsp->obj.rate_node_name);
6337                 free(rsp);
6338         }
6339 }
6340
6341 struct devlink_rate_get_list *
6342 devlink_rate_get_dump(struct ynl_sock *ys,
6343                       struct devlink_rate_get_req_dump *req)
6344 {
6345         struct ynl_dump_state yds = {};
6346         struct nlmsghdr *nlh;
6347         int err;
6348
6349         yds.ys = ys;
6350         yds.alloc_sz = sizeof(struct devlink_rate_get_list);
6351         yds.cb = devlink_rate_get_rsp_parse;
6352         yds.rsp_cmd = 76;
6353         yds.rsp_policy = &devlink_nest;
6354
6355         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_RATE_GET, 1);
6356         ys->req_policy = &devlink_nest;
6357
6358         if (req->_present.bus_name_len)
6359                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6360         if (req->_present.dev_name_len)
6361                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6362
6363         err = ynl_exec_dump(ys, nlh, &yds);
6364         if (err < 0)
6365                 goto free_list;
6366
6367         return yds.first;
6368
6369 free_list:
6370         devlink_rate_get_list_free(yds.first);
6371         return NULL;
6372 }
6373
6374 /* ============== DEVLINK_CMD_RATE_SET ============== */
6375 /* DEVLINK_CMD_RATE_SET - do */
6376 void devlink_rate_set_req_free(struct devlink_rate_set_req *req)
6377 {
6378         free(req->bus_name);
6379         free(req->dev_name);
6380         free(req->rate_node_name);
6381         free(req->rate_parent_node_name);
6382         free(req);
6383 }
6384
6385 int devlink_rate_set(struct ynl_sock *ys, struct devlink_rate_set_req *req)
6386 {
6387         struct nlmsghdr *nlh;
6388         int err;
6389
6390         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_RATE_SET, 1);
6391         ys->req_policy = &devlink_nest;
6392
6393         if (req->_present.bus_name_len)
6394                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6395         if (req->_present.dev_name_len)
6396                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6397         if (req->_present.rate_node_name_len)
6398                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_RATE_NODE_NAME, req->rate_node_name);
6399         if (req->_present.rate_tx_share)
6400                 mnl_attr_put_u64(nlh, DEVLINK_ATTR_RATE_TX_SHARE, req->rate_tx_share);
6401         if (req->_present.rate_tx_max)
6402                 mnl_attr_put_u64(nlh, DEVLINK_ATTR_RATE_TX_MAX, req->rate_tx_max);
6403         if (req->_present.rate_tx_priority)
6404                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_RATE_TX_PRIORITY, req->rate_tx_priority);
6405         if (req->_present.rate_tx_weight)
6406                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_RATE_TX_WEIGHT, req->rate_tx_weight);
6407         if (req->_present.rate_parent_node_name_len)
6408                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_RATE_PARENT_NODE_NAME, req->rate_parent_node_name);
6409
6410         err = ynl_exec(ys, nlh, NULL);
6411         if (err < 0)
6412                 return -1;
6413
6414         return 0;
6415 }
6416
6417 /* ============== DEVLINK_CMD_RATE_NEW ============== */
6418 /* DEVLINK_CMD_RATE_NEW - do */
6419 void devlink_rate_new_req_free(struct devlink_rate_new_req *req)
6420 {
6421         free(req->bus_name);
6422         free(req->dev_name);
6423         free(req->rate_node_name);
6424         free(req->rate_parent_node_name);
6425         free(req);
6426 }
6427
6428 int devlink_rate_new(struct ynl_sock *ys, struct devlink_rate_new_req *req)
6429 {
6430         struct nlmsghdr *nlh;
6431         int err;
6432
6433         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_RATE_NEW, 1);
6434         ys->req_policy = &devlink_nest;
6435
6436         if (req->_present.bus_name_len)
6437                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6438         if (req->_present.dev_name_len)
6439                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6440         if (req->_present.rate_node_name_len)
6441                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_RATE_NODE_NAME, req->rate_node_name);
6442         if (req->_present.rate_tx_share)
6443                 mnl_attr_put_u64(nlh, DEVLINK_ATTR_RATE_TX_SHARE, req->rate_tx_share);
6444         if (req->_present.rate_tx_max)
6445                 mnl_attr_put_u64(nlh, DEVLINK_ATTR_RATE_TX_MAX, req->rate_tx_max);
6446         if (req->_present.rate_tx_priority)
6447                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_RATE_TX_PRIORITY, req->rate_tx_priority);
6448         if (req->_present.rate_tx_weight)
6449                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_RATE_TX_WEIGHT, req->rate_tx_weight);
6450         if (req->_present.rate_parent_node_name_len)
6451                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_RATE_PARENT_NODE_NAME, req->rate_parent_node_name);
6452
6453         err = ynl_exec(ys, nlh, NULL);
6454         if (err < 0)
6455                 return -1;
6456
6457         return 0;
6458 }
6459
6460 /* ============== DEVLINK_CMD_RATE_DEL ============== */
6461 /* DEVLINK_CMD_RATE_DEL - do */
6462 void devlink_rate_del_req_free(struct devlink_rate_del_req *req)
6463 {
6464         free(req->bus_name);
6465         free(req->dev_name);
6466         free(req->rate_node_name);
6467         free(req);
6468 }
6469
6470 int devlink_rate_del(struct ynl_sock *ys, struct devlink_rate_del_req *req)
6471 {
6472         struct nlmsghdr *nlh;
6473         int err;
6474
6475         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_RATE_DEL, 1);
6476         ys->req_policy = &devlink_nest;
6477
6478         if (req->_present.bus_name_len)
6479                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6480         if (req->_present.dev_name_len)
6481                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6482         if (req->_present.rate_node_name_len)
6483                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_RATE_NODE_NAME, req->rate_node_name);
6484
6485         err = ynl_exec(ys, nlh, NULL);
6486         if (err < 0)
6487                 return -1;
6488
6489         return 0;
6490 }
6491
6492 /* ============== DEVLINK_CMD_LINECARD_GET ============== */
6493 /* DEVLINK_CMD_LINECARD_GET - do */
6494 void devlink_linecard_get_req_free(struct devlink_linecard_get_req *req)
6495 {
6496         free(req->bus_name);
6497         free(req->dev_name);
6498         free(req);
6499 }
6500
6501 void devlink_linecard_get_rsp_free(struct devlink_linecard_get_rsp *rsp)
6502 {
6503         free(rsp->bus_name);
6504         free(rsp->dev_name);
6505         free(rsp);
6506 }
6507
6508 int devlink_linecard_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
6509 {
6510         struct devlink_linecard_get_rsp *dst;
6511         struct ynl_parse_arg *yarg = data;
6512         const struct nlattr *attr;
6513
6514         dst = yarg->data;
6515
6516         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
6517                 unsigned int type = mnl_attr_get_type(attr);
6518
6519                 if (type == DEVLINK_ATTR_BUS_NAME) {
6520                         unsigned int len;
6521
6522                         if (ynl_attr_validate(yarg, attr))
6523                                 return MNL_CB_ERROR;
6524
6525                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6526                         dst->_present.bus_name_len = len;
6527                         dst->bus_name = malloc(len + 1);
6528                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
6529                         dst->bus_name[len] = 0;
6530                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
6531                         unsigned int len;
6532
6533                         if (ynl_attr_validate(yarg, attr))
6534                                 return MNL_CB_ERROR;
6535
6536                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6537                         dst->_present.dev_name_len = len;
6538                         dst->dev_name = malloc(len + 1);
6539                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
6540                         dst->dev_name[len] = 0;
6541                 } else if (type == DEVLINK_ATTR_LINECARD_INDEX) {
6542                         if (ynl_attr_validate(yarg, attr))
6543                                 return MNL_CB_ERROR;
6544                         dst->_present.linecard_index = 1;
6545                         dst->linecard_index = mnl_attr_get_u32(attr);
6546                 }
6547         }
6548
6549         return MNL_CB_OK;
6550 }
6551
6552 struct devlink_linecard_get_rsp *
6553 devlink_linecard_get(struct ynl_sock *ys, struct devlink_linecard_get_req *req)
6554 {
6555         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
6556         struct devlink_linecard_get_rsp *rsp;
6557         struct nlmsghdr *nlh;
6558         int err;
6559
6560         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_LINECARD_GET, 1);
6561         ys->req_policy = &devlink_nest;
6562         yrs.yarg.rsp_policy = &devlink_nest;
6563
6564         if (req->_present.bus_name_len)
6565                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6566         if (req->_present.dev_name_len)
6567                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6568         if (req->_present.linecard_index)
6569                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_LINECARD_INDEX, req->linecard_index);
6570
6571         rsp = calloc(1, sizeof(*rsp));
6572         yrs.yarg.data = rsp;
6573         yrs.cb = devlink_linecard_get_rsp_parse;
6574         yrs.rsp_cmd = 80;
6575
6576         err = ynl_exec(ys, nlh, &yrs);
6577         if (err < 0)
6578                 goto err_free;
6579
6580         return rsp;
6581
6582 err_free:
6583         devlink_linecard_get_rsp_free(rsp);
6584         return NULL;
6585 }
6586
6587 /* DEVLINK_CMD_LINECARD_GET - dump */
6588 void devlink_linecard_get_list_free(struct devlink_linecard_get_list *rsp)
6589 {
6590         struct devlink_linecard_get_list *next = rsp;
6591
6592         while ((void *)next != YNL_LIST_END) {
6593                 rsp = next;
6594                 next = rsp->next;
6595
6596                 free(rsp->obj.bus_name);
6597                 free(rsp->obj.dev_name);
6598                 free(rsp);
6599         }
6600 }
6601
6602 struct devlink_linecard_get_list *
6603 devlink_linecard_get_dump(struct ynl_sock *ys,
6604                           struct devlink_linecard_get_req_dump *req)
6605 {
6606         struct ynl_dump_state yds = {};
6607         struct nlmsghdr *nlh;
6608         int err;
6609
6610         yds.ys = ys;
6611         yds.alloc_sz = sizeof(struct devlink_linecard_get_list);
6612         yds.cb = devlink_linecard_get_rsp_parse;
6613         yds.rsp_cmd = 80;
6614         yds.rsp_policy = &devlink_nest;
6615
6616         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_LINECARD_GET, 1);
6617         ys->req_policy = &devlink_nest;
6618
6619         if (req->_present.bus_name_len)
6620                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6621         if (req->_present.dev_name_len)
6622                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6623
6624         err = ynl_exec_dump(ys, nlh, &yds);
6625         if (err < 0)
6626                 goto free_list;
6627
6628         return yds.first;
6629
6630 free_list:
6631         devlink_linecard_get_list_free(yds.first);
6632         return NULL;
6633 }
6634
6635 /* ============== DEVLINK_CMD_LINECARD_SET ============== */
6636 /* DEVLINK_CMD_LINECARD_SET - do */
6637 void devlink_linecard_set_req_free(struct devlink_linecard_set_req *req)
6638 {
6639         free(req->bus_name);
6640         free(req->dev_name);
6641         free(req->linecard_type);
6642         free(req);
6643 }
6644
6645 int devlink_linecard_set(struct ynl_sock *ys,
6646                          struct devlink_linecard_set_req *req)
6647 {
6648         struct nlmsghdr *nlh;
6649         int err;
6650
6651         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_LINECARD_SET, 1);
6652         ys->req_policy = &devlink_nest;
6653
6654         if (req->_present.bus_name_len)
6655                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6656         if (req->_present.dev_name_len)
6657                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6658         if (req->_present.linecard_index)
6659                 mnl_attr_put_u32(nlh, DEVLINK_ATTR_LINECARD_INDEX, req->linecard_index);
6660         if (req->_present.linecard_type_len)
6661                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_LINECARD_TYPE, req->linecard_type);
6662
6663         err = ynl_exec(ys, nlh, NULL);
6664         if (err < 0)
6665                 return -1;
6666
6667         return 0;
6668 }
6669
6670 /* ============== DEVLINK_CMD_SELFTESTS_GET ============== */
6671 /* DEVLINK_CMD_SELFTESTS_GET - do */
6672 void devlink_selftests_get_req_free(struct devlink_selftests_get_req *req)
6673 {
6674         free(req->bus_name);
6675         free(req->dev_name);
6676         free(req);
6677 }
6678
6679 void devlink_selftests_get_rsp_free(struct devlink_selftests_get_rsp *rsp)
6680 {
6681         free(rsp->bus_name);
6682         free(rsp->dev_name);
6683         free(rsp);
6684 }
6685
6686 int devlink_selftests_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
6687 {
6688         struct devlink_selftests_get_rsp *dst;
6689         struct ynl_parse_arg *yarg = data;
6690         const struct nlattr *attr;
6691
6692         dst = yarg->data;
6693
6694         mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
6695                 unsigned int type = mnl_attr_get_type(attr);
6696
6697                 if (type == DEVLINK_ATTR_BUS_NAME) {
6698                         unsigned int len;
6699
6700                         if (ynl_attr_validate(yarg, attr))
6701                                 return MNL_CB_ERROR;
6702
6703                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6704                         dst->_present.bus_name_len = len;
6705                         dst->bus_name = malloc(len + 1);
6706                         memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
6707                         dst->bus_name[len] = 0;
6708                 } else if (type == DEVLINK_ATTR_DEV_NAME) {
6709                         unsigned int len;
6710
6711                         if (ynl_attr_validate(yarg, attr))
6712                                 return MNL_CB_ERROR;
6713
6714                         len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6715                         dst->_present.dev_name_len = len;
6716                         dst->dev_name = malloc(len + 1);
6717                         memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
6718                         dst->dev_name[len] = 0;
6719                 }
6720         }
6721
6722         return MNL_CB_OK;
6723 }
6724
6725 struct devlink_selftests_get_rsp *
6726 devlink_selftests_get(struct ynl_sock *ys,
6727                       struct devlink_selftests_get_req *req)
6728 {
6729         struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
6730         struct devlink_selftests_get_rsp *rsp;
6731         struct nlmsghdr *nlh;
6732         int err;
6733
6734         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SELFTESTS_GET, 1);
6735         ys->req_policy = &devlink_nest;
6736         yrs.yarg.rsp_policy = &devlink_nest;
6737
6738         if (req->_present.bus_name_len)
6739                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6740         if (req->_present.dev_name_len)
6741                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6742
6743         rsp = calloc(1, sizeof(*rsp));
6744         yrs.yarg.data = rsp;
6745         yrs.cb = devlink_selftests_get_rsp_parse;
6746         yrs.rsp_cmd = DEVLINK_CMD_SELFTESTS_GET;
6747
6748         err = ynl_exec(ys, nlh, &yrs);
6749         if (err < 0)
6750                 goto err_free;
6751
6752         return rsp;
6753
6754 err_free:
6755         devlink_selftests_get_rsp_free(rsp);
6756         return NULL;
6757 }
6758
6759 /* DEVLINK_CMD_SELFTESTS_GET - dump */
6760 void devlink_selftests_get_list_free(struct devlink_selftests_get_list *rsp)
6761 {
6762         struct devlink_selftests_get_list *next = rsp;
6763
6764         while ((void *)next != YNL_LIST_END) {
6765                 rsp = next;
6766                 next = rsp->next;
6767
6768                 free(rsp->obj.bus_name);
6769                 free(rsp->obj.dev_name);
6770                 free(rsp);
6771         }
6772 }
6773
6774 struct devlink_selftests_get_list *
6775 devlink_selftests_get_dump(struct ynl_sock *ys)
6776 {
6777         struct ynl_dump_state yds = {};
6778         struct nlmsghdr *nlh;
6779         int err;
6780
6781         yds.ys = ys;
6782         yds.alloc_sz = sizeof(struct devlink_selftests_get_list);
6783         yds.cb = devlink_selftests_get_rsp_parse;
6784         yds.rsp_cmd = DEVLINK_CMD_SELFTESTS_GET;
6785         yds.rsp_policy = &devlink_nest;
6786
6787         nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SELFTESTS_GET, 1);
6788
6789         err = ynl_exec_dump(ys, nlh, &yds);
6790         if (err < 0)
6791                 goto free_list;
6792
6793         return yds.first;
6794
6795 free_list:
6796         devlink_selftests_get_list_free(yds.first);
6797         return NULL;
6798 }
6799
6800 /* ============== DEVLINK_CMD_SELFTESTS_RUN ============== */
6801 /* DEVLINK_CMD_SELFTESTS_RUN - do */
6802 void devlink_selftests_run_req_free(struct devlink_selftests_run_req *req)
6803 {
6804         free(req->bus_name);
6805         free(req->dev_name);
6806         devlink_dl_selftest_id_free(&req->selftests);
6807         free(req);
6808 }
6809
6810 int devlink_selftests_run(struct ynl_sock *ys,
6811                           struct devlink_selftests_run_req *req)
6812 {
6813         struct nlmsghdr *nlh;
6814         int err;
6815
6816         nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SELFTESTS_RUN, 1);
6817         ys->req_policy = &devlink_nest;
6818
6819         if (req->_present.bus_name_len)
6820                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6821         if (req->_present.dev_name_len)
6822                 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6823         if (req->_present.selftests)
6824                 devlink_dl_selftest_id_put(nlh, DEVLINK_ATTR_SELFTESTS, &req->selftests);
6825
6826         err = ynl_exec(ys, nlh, NULL);
6827         if (err < 0)
6828                 return -1;
6829
6830         return 0;
6831 }
6832
6833 const struct ynl_family ynl_devlink_family =  {
6834         .name           = "devlink",
6835 };