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 header */
5 
6 #ifndef _LINUX_DEVLINK_GEN_H
7 #define _LINUX_DEVLINK_GEN_H
8 
9 #include <stdlib.h>
10 #include <string.h>
11 #include <linux/types.h>
12 #include <linux/devlink.h>
13 
14 struct ynl_sock;
15 
16 extern const struct ynl_family ynl_devlink_family;
17 
18 /* Enums */
19 const char *devlink_op_str(int op);
20 
21 /* Common nested types */
22 struct devlink_dl_info_version {
23 	struct {
24 		__u32 info_version_name_len;
25 		__u32 info_version_value_len;
26 	} _present;
27 
28 	char *info_version_name;
29 	char *info_version_value;
30 };
31 
32 struct devlink_dl_reload_stats_entry {
33 	struct {
34 		__u32 reload_stats_limit:1;
35 		__u32 reload_stats_value:1;
36 	} _present;
37 
38 	__u8 reload_stats_limit;
39 	__u32 reload_stats_value;
40 };
41 
42 struct devlink_dl_reload_act_stats {
43 	unsigned int n_reload_stats_entry;
44 	struct devlink_dl_reload_stats_entry *reload_stats_entry;
45 };
46 
47 struct devlink_dl_reload_act_info {
48 	struct {
49 		__u32 reload_action:1;
50 	} _present;
51 
52 	__u8 reload_action;
53 	unsigned int n_reload_action_stats;
54 	struct devlink_dl_reload_act_stats *reload_action_stats;
55 };
56 
57 struct devlink_dl_reload_stats {
58 	unsigned int n_reload_action_info;
59 	struct devlink_dl_reload_act_info *reload_action_info;
60 };
61 
62 struct devlink_dl_dev_stats {
63 	struct {
64 		__u32 reload_stats:1;
65 		__u32 remote_reload_stats:1;
66 	} _present;
67 
68 	struct devlink_dl_reload_stats reload_stats;
69 	struct devlink_dl_reload_stats remote_reload_stats;
70 };
71 
72 /* ============== DEVLINK_CMD_GET ============== */
73 /* DEVLINK_CMD_GET - do */
74 struct devlink_get_req {
75 	struct {
76 		__u32 bus_name_len;
77 		__u32 dev_name_len;
78 	} _present;
79 
80 	char *bus_name;
81 	char *dev_name;
82 };
83 
84 static inline struct devlink_get_req *devlink_get_req_alloc(void)
85 {
86 	return calloc(1, sizeof(struct devlink_get_req));
87 }
88 void devlink_get_req_free(struct devlink_get_req *req);
89 
90 static inline void
91 devlink_get_req_set_bus_name(struct devlink_get_req *req, const char *bus_name)
92 {
93 	free(req->bus_name);
94 	req->_present.bus_name_len = strlen(bus_name);
95 	req->bus_name = malloc(req->_present.bus_name_len + 1);
96 	memcpy(req->bus_name, bus_name, req->_present.bus_name_len);
97 	req->bus_name[req->_present.bus_name_len] = 0;
98 }
99 static inline void
100 devlink_get_req_set_dev_name(struct devlink_get_req *req, const char *dev_name)
101 {
102 	free(req->dev_name);
103 	req->_present.dev_name_len = strlen(dev_name);
104 	req->dev_name = malloc(req->_present.dev_name_len + 1);
105 	memcpy(req->dev_name, dev_name, req->_present.dev_name_len);
106 	req->dev_name[req->_present.dev_name_len] = 0;
107 }
108 
109 struct devlink_get_rsp {
110 	struct {
111 		__u32 bus_name_len;
112 		__u32 dev_name_len;
113 		__u32 reload_failed:1;
114 		__u32 reload_action:1;
115 		__u32 dev_stats:1;
116 	} _present;
117 
118 	char *bus_name;
119 	char *dev_name;
120 	__u8 reload_failed;
121 	__u8 reload_action;
122 	struct devlink_dl_dev_stats dev_stats;
123 };
124 
125 void devlink_get_rsp_free(struct devlink_get_rsp *rsp);
126 
127 /*
128  * Get devlink instances.
129  */
130 struct devlink_get_rsp *
131 devlink_get(struct ynl_sock *ys, struct devlink_get_req *req);
132 
133 /* DEVLINK_CMD_GET - dump */
134 struct devlink_get_list {
135 	struct devlink_get_list *next;
136 	struct devlink_get_rsp obj __attribute__ ((aligned (8)));
137 };
138 
139 void devlink_get_list_free(struct devlink_get_list *rsp);
140 
141 struct devlink_get_list *devlink_get_dump(struct ynl_sock *ys);
142 
143 /* ============== DEVLINK_CMD_INFO_GET ============== */
144 /* DEVLINK_CMD_INFO_GET - do */
145 struct devlink_info_get_req {
146 	struct {
147 		__u32 bus_name_len;
148 		__u32 dev_name_len;
149 	} _present;
150 
151 	char *bus_name;
152 	char *dev_name;
153 };
154 
155 static inline struct devlink_info_get_req *devlink_info_get_req_alloc(void)
156 {
157 	return calloc(1, sizeof(struct devlink_info_get_req));
158 }
159 void devlink_info_get_req_free(struct devlink_info_get_req *req);
160 
161 static inline void
162 devlink_info_get_req_set_bus_name(struct devlink_info_get_req *req,
163 				  const char *bus_name)
164 {
165 	free(req->bus_name);
166 	req->_present.bus_name_len = strlen(bus_name);
167 	req->bus_name = malloc(req->_present.bus_name_len + 1);
168 	memcpy(req->bus_name, bus_name, req->_present.bus_name_len);
169 	req->bus_name[req->_present.bus_name_len] = 0;
170 }
171 static inline void
172 devlink_info_get_req_set_dev_name(struct devlink_info_get_req *req,
173 				  const char *dev_name)
174 {
175 	free(req->dev_name);
176 	req->_present.dev_name_len = strlen(dev_name);
177 	req->dev_name = malloc(req->_present.dev_name_len + 1);
178 	memcpy(req->dev_name, dev_name, req->_present.dev_name_len);
179 	req->dev_name[req->_present.dev_name_len] = 0;
180 }
181 
182 struct devlink_info_get_rsp {
183 	struct {
184 		__u32 bus_name_len;
185 		__u32 dev_name_len;
186 		__u32 info_driver_name_len;
187 		__u32 info_serial_number_len;
188 	} _present;
189 
190 	char *bus_name;
191 	char *dev_name;
192 	char *info_driver_name;
193 	char *info_serial_number;
194 	unsigned int n_info_version_fixed;
195 	struct devlink_dl_info_version *info_version_fixed;
196 	unsigned int n_info_version_running;
197 	struct devlink_dl_info_version *info_version_running;
198 	unsigned int n_info_version_stored;
199 	struct devlink_dl_info_version *info_version_stored;
200 };
201 
202 void devlink_info_get_rsp_free(struct devlink_info_get_rsp *rsp);
203 
204 /*
205  * Get device information, like driver name, hardware and firmware versions etc.
206  */
207 struct devlink_info_get_rsp *
208 devlink_info_get(struct ynl_sock *ys, struct devlink_info_get_req *req);
209 
210 #endif /* _LINUX_DEVLINK_GEN_H */
211