/src/nsmd/libnsm/device-configuration.c
Line | Count | Source |
1 | | /* |
2 | | * SPDX-FileCopyrightText: Copyright (c) 2023-2024 NVIDIA CORPORATION & |
3 | | * AFFILIATES. All rights reserved. SPDX-License-Identifier: Apache-2.0 |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | |
18 | | #include "device-configuration.h" |
19 | | #include "base.h" |
20 | | #include <endian.h> |
21 | | #include <stdio.h> |
22 | | #include <string.h> |
23 | | |
24 | | int encode_set_error_injection_payload_req( |
25 | | uint8_t instance_id, const struct nsm_error_injection_payload *data, |
26 | | struct nsm_msg *msg) |
27 | 0 | { |
28 | 0 | if (msg == NULL) { |
29 | 0 | return NSM_SW_ERROR_NULL; |
30 | 0 | } |
31 | 0 | struct nsm_header_info header = {NSM_REQUEST, instance_id, |
32 | 0 | NSM_TYPE_DEVICE_CONFIGURATION}; |
33 | 0 | uint8_t rc = pack_nsm_header_v2(&header, &(msg->hdr)); |
34 | 0 | if (rc != NSM_SW_SUCCESS) { |
35 | 0 | return rc; |
36 | 0 | } |
37 | 0 | struct nsm_set_error_injection_payload_req *request = |
38 | 0 | (struct nsm_set_error_injection_payload_req *)msg->payload; |
39 | 0 | request->hdr.command = NSM_SET_ERROR_INJECTION_PAYLOAD; |
40 | 0 | request->hdr.data_size = |
41 | 0 | htole16(sizeof(struct nsm_error_injection_payload)); |
42 | 0 | if (data == NULL) { |
43 | 0 | return NSM_SW_ERROR_NULL; |
44 | 0 | } |
45 | 0 | request->data.error_injection_id = htole32(data->error_injection_id); |
46 | 0 | request->data.offset = htole32(data->offset); |
47 | 0 | request->data.fault_reason_bit_map = |
48 | 0 | htole32(data->fault_reason_bit_map); |
49 | 0 | return rc; |
50 | 0 | } |
51 | | |
52 | | int decode_set_error_injection_payload_req( |
53 | | const struct nsm_msg *msg, size_t msg_len, |
54 | | struct nsm_error_injection_payload *data) |
55 | 0 | { |
56 | 0 | int rc = decode_common_req(msg, msg_len); |
57 | 0 | if (rc == NSM_SW_SUCCESS) { |
58 | 0 | if (data == NULL) { |
59 | 0 | return NSM_SW_ERROR_NULL; |
60 | 0 | } |
61 | 0 | if (msg_len < |
62 | 0 | sizeof(struct nsm_msg_hdr) + |
63 | 0 | sizeof(struct nsm_set_error_injection_payload_req)) { |
64 | 0 | return NSM_SW_ERROR_LENGTH; |
65 | 0 | } |
66 | 0 | struct nsm_set_error_injection_payload_req *req = |
67 | 0 | (struct nsm_set_error_injection_payload_req *)msg->payload; |
68 | |
|
69 | 0 | if (req->hdr.data_size != |
70 | 0 | sizeof(struct nsm_error_injection_payload)) { |
71 | 0 | return NSM_SW_ERROR_LENGTH; |
72 | 0 | } |
73 | 0 | data->error_injection_id = |
74 | 0 | le32toh(req->data.error_injection_id); |
75 | 0 | data->offset = le32toh(req->data.offset); |
76 | 0 | data->fault_reason_bit_map = |
77 | 0 | le32toh(req->data.fault_reason_bit_map); |
78 | 0 | } |
79 | 0 | return rc; |
80 | 0 | } |
81 | | |
82 | | int encode_set_error_injection_payload_resp(uint8_t instance_id, uint8_t cc, |
83 | | uint16_t reason_code, |
84 | | struct nsm_msg *msg) |
85 | 0 | { |
86 | 0 | return encode_common_resp(instance_id, cc, reason_code, |
87 | 0 | NSM_TYPE_DEVICE_CONFIGURATION, |
88 | 0 | NSM_SET_ERROR_INJECTION_PAYLOAD, msg); |
89 | 0 | } |
90 | | |
91 | | int decode_set_error_injection_payload_resp(const struct nsm_msg *msg, |
92 | | size_t msg_len, uint8_t *cc, |
93 | | uint16_t *reason_code) |
94 | 0 | { |
95 | 0 | uint16_t data_size = 0; |
96 | 0 | int rc = decode_common_resp(msg, msg_len, cc, &data_size, reason_code); |
97 | 0 | if (data_size != 0) { |
98 | 0 | return NSM_SW_ERROR_LENGTH; |
99 | 0 | } |
100 | 0 | return rc; |
101 | 0 | } |
102 | | |
103 | | int encode_get_error_injection_payload_req(uint8_t instance_id, |
104 | | uint32_t error_injection_id, |
105 | | struct nsm_msg *msg) |
106 | 0 | { |
107 | 0 | if (msg == NULL) { |
108 | 0 | return NSM_SW_ERROR_NULL; |
109 | 0 | } |
110 | 0 | struct nsm_header_info header = {NSM_REQUEST, instance_id, |
111 | 0 | NSM_TYPE_DEVICE_CONFIGURATION}; |
112 | 0 | uint8_t rc = pack_nsm_header_v2(&header, &(msg->hdr)); |
113 | 0 | if (rc != NSM_SW_SUCCESS) { |
114 | 0 | return rc; |
115 | 0 | } |
116 | 0 | struct nsm_get_error_injection_payload_req *request = |
117 | 0 | (struct nsm_get_error_injection_payload_req *)msg->payload; |
118 | 0 | request->hdr.command = NSM_GET_ERROR_INJECTION_PAYLOAD; |
119 | 0 | request->hdr.data_size = htole16(sizeof(uint32_t)); |
120 | 0 | request->error_injection_id = htole32(error_injection_id); |
121 | 0 | return rc; |
122 | 0 | } |
123 | | |
124 | | int decode_get_error_injection_payload_req(const struct nsm_msg *msg, |
125 | | size_t msg_len, |
126 | | uint32_t *error_injection_id) |
127 | 0 | { |
128 | 0 | int rc = decode_common_req(msg, msg_len); |
129 | 0 | if (rc == NSM_SW_SUCCESS) { |
130 | 0 | if (error_injection_id == NULL) { |
131 | 0 | return NSM_SW_ERROR_NULL; |
132 | 0 | } |
133 | 0 | if (msg_len < |
134 | 0 | sizeof(struct nsm_msg_hdr) + |
135 | 0 | sizeof(struct nsm_get_error_injection_payload_req)) { |
136 | 0 | return NSM_SW_ERROR_LENGTH; |
137 | 0 | } |
138 | 0 | struct nsm_get_error_injection_payload_req *req = |
139 | 0 | (struct nsm_get_error_injection_payload_req *)msg->payload; |
140 | 0 | if (req->hdr.data_size != sizeof(uint32_t)) { |
141 | 0 | return NSM_SW_ERROR_LENGTH; |
142 | 0 | } |
143 | 0 | *error_injection_id = le32toh(req->error_injection_id); |
144 | 0 | } |
145 | 0 | return rc; |
146 | 0 | } |
147 | | |
148 | | int encode_get_error_injection_payload_resp( |
149 | | uint8_t instance_id, uint8_t cc, uint16_t reason_code, |
150 | | const struct nsm_error_injection_payload *data, struct nsm_msg *msg) |
151 | 0 | { |
152 | 0 | int rc = encode_common_resp(instance_id, cc, reason_code, |
153 | 0 | NSM_TYPE_DEVICE_CONFIGURATION, |
154 | 0 | NSM_GET_ERROR_INJECTION_PAYLOAD, msg); |
155 | 0 | if (rc == NSM_SW_SUCCESS && cc == NSM_SUCCESS) { |
156 | 0 | if (data == NULL) { |
157 | 0 | return NSM_SW_ERROR_NULL; |
158 | 0 | } |
159 | 0 | struct nsm_get_error_injection_payload_resp *resp = |
160 | 0 | (struct nsm_get_error_injection_payload_resp *)msg->payload; |
161 | 0 | resp->hdr.data_size = |
162 | 0 | htole16(sizeof(struct nsm_error_injection_payload)); |
163 | 0 | resp->data.error_injection_id = |
164 | 0 | htole32(data->error_injection_id); |
165 | 0 | resp->data.offset = htole32(data->offset); |
166 | 0 | resp->data.fault_reason_bit_map = |
167 | 0 | htole32(data->fault_reason_bit_map); |
168 | 0 | } |
169 | 0 | return rc; |
170 | 0 | } |
171 | | |
172 | | int decode_get_error_injection_payload_resp( |
173 | | const struct nsm_msg *msg, size_t msg_len, uint8_t *cc, |
174 | | uint16_t *reason_code, struct nsm_error_injection_payload *data) |
175 | 0 | { |
176 | 0 | uint16_t data_size = 0; |
177 | 0 | int rc = decode_common_resp(msg, msg_len, cc, &data_size, reason_code); |
178 | 0 | if (rc == NSM_SW_SUCCESS && *cc == NSM_SUCCESS) { |
179 | 0 | if (data == NULL) { |
180 | 0 | return NSM_SW_ERROR_NULL; |
181 | 0 | } |
182 | 0 | if (msg_len < |
183 | 0 | sizeof(struct nsm_msg_hdr) + |
184 | 0 | sizeof(struct nsm_get_error_injection_payload_resp)) { |
185 | 0 | return NSM_SW_ERROR_LENGTH; |
186 | 0 | } |
187 | 0 | if (data_size != sizeof(struct nsm_error_injection_payload)) { |
188 | 0 | return NSM_SW_ERROR_LENGTH; |
189 | 0 | } |
190 | 0 | struct nsm_get_error_injection_payload_resp *resp = |
191 | 0 | (struct nsm_get_error_injection_payload_resp *)msg->payload; |
192 | 0 | data->error_injection_id = |
193 | 0 | le32toh(resp->data.error_injection_id); |
194 | 0 | data->offset = le32toh(resp->data.offset); |
195 | 0 | data->fault_reason_bit_map = |
196 | 0 | le32toh(resp->data.fault_reason_bit_map); |
197 | 0 | } |
198 | 0 | return rc; |
199 | 0 | } |
200 | | |
201 | | int encode_activate_error_injection_payload_req(uint8_t instance_id, |
202 | | struct nsm_msg *msg) |
203 | 0 | { |
204 | 0 | if (msg == NULL) { |
205 | 0 | return NSM_SW_ERROR_NULL; |
206 | 0 | } |
207 | 0 | struct nsm_header_info header = {NSM_REQUEST, instance_id, |
208 | 0 | NSM_TYPE_DEVICE_CONFIGURATION}; |
209 | 0 | uint8_t rc = pack_nsm_header_v2(&header, &(msg->hdr)); |
210 | 0 | if (rc != NSM_SW_SUCCESS) { |
211 | 0 | return rc; |
212 | 0 | } |
213 | 0 | struct nsm_common_req_v2 *request = |
214 | 0 | (struct nsm_common_req_v2 *)msg->payload; |
215 | 0 | request->command = NSM_ACTIVATE_ERROR_INJECTION; |
216 | 0 | request->data_size = 0; |
217 | 0 | return rc; |
218 | 0 | } |
219 | | |
220 | | int decode_activate_error_injection_payload_req(const struct nsm_msg *msg, |
221 | | size_t msg_len) |
222 | 0 | { |
223 | 0 | return decode_common_req(msg, msg_len); |
224 | 0 | } |
225 | | |
226 | | int encode_activate_error_injection_payload_resp(uint8_t instance_id, |
227 | | uint8_t cc, |
228 | | uint16_t reason_code, |
229 | | struct nsm_msg *msg) |
230 | 0 | { |
231 | 0 | return encode_common_resp(instance_id, cc, reason_code, |
232 | 0 | NSM_TYPE_DEVICE_CONFIGURATION, |
233 | 0 | NSM_ACTIVATE_ERROR_INJECTION, msg); |
234 | 0 | } |
235 | | |
236 | | int decode_activate_error_injection_payload_resp(const struct nsm_msg *msg, |
237 | | size_t msg_len, uint8_t *cc, |
238 | | uint16_t *reason_code) |
239 | 0 | { |
240 | 0 | uint16_t data_size = 0; |
241 | 0 | int rc = decode_common_resp(msg, msg_len, cc, &data_size, reason_code); |
242 | 0 | if (data_size != 0) { |
243 | 0 | return NSM_SW_ERROR_LENGTH; |
244 | 0 | } |
245 | 0 | return rc; |
246 | 0 | } |
247 | | |
248 | | int encode_set_error_injection_mode_v1_req(uint8_t instance_id, |
249 | | const uint8_t mode, |
250 | | struct nsm_msg *msg) |
251 | 0 | { |
252 | 0 | int rc = encode_common_req(instance_id, NSM_TYPE_DEVICE_CONFIGURATION, |
253 | 0 | NSM_SET_ERROR_INJECTION_MODE_V1, msg); |
254 | 0 | if (rc == NSM_SW_SUCCESS) { |
255 | 0 | struct nsm_set_error_injection_mode_v1_req *req = |
256 | 0 | (struct nsm_set_error_injection_mode_v1_req *)msg->payload; |
257 | 0 | req->hdr.data_size = htole16(sizeof(uint8_t)); |
258 | 0 | req->mode = mode; |
259 | 0 | } |
260 | 0 | return rc; |
261 | 0 | } |
262 | | |
263 | | int decode_set_error_injection_mode_v1_req(const struct nsm_msg *msg, |
264 | | size_t msg_len, uint8_t *mode) |
265 | 0 | { |
266 | 0 | int rc = decode_common_req(msg, msg_len); |
267 | 0 | if (rc == NSM_SW_SUCCESS) { |
268 | 0 | if (mode == NULL) { |
269 | 0 | return NSM_SW_ERROR_NULL; |
270 | 0 | } |
271 | 0 | if (msg_len < |
272 | 0 | sizeof(struct nsm_msg_hdr) + |
273 | 0 | sizeof(struct nsm_set_error_injection_mode_v1_req)) { |
274 | 0 | return NSM_SW_ERROR_LENGTH; |
275 | 0 | } |
276 | 0 | struct nsm_set_error_injection_mode_v1_req *req = |
277 | 0 | (struct nsm_set_error_injection_mode_v1_req *)msg->payload; |
278 | |
|
279 | 0 | if (req->hdr.data_size != sizeof(uint8_t)) { |
280 | 0 | return NSM_SW_ERROR_LENGTH; |
281 | 0 | } |
282 | 0 | *mode = req->mode; |
283 | 0 | } |
284 | 0 | return rc; |
285 | 0 | } |
286 | | |
287 | | int encode_set_error_injection_mode_v1_resp(uint8_t instance_id, uint8_t cc, |
288 | | uint16_t reason_code, |
289 | | struct nsm_msg *msg) |
290 | 0 | { |
291 | 0 | return encode_common_resp(instance_id, cc, reason_code, |
292 | 0 | NSM_TYPE_DEVICE_CONFIGURATION, |
293 | 0 | NSM_SET_ERROR_INJECTION_MODE_V1, msg); |
294 | 0 | } |
295 | | |
296 | | int decode_set_error_injection_mode_v1_resp(const struct nsm_msg *msg, |
297 | | size_t msg_len, uint8_t *cc, |
298 | | uint16_t *reason_code) |
299 | 0 | { |
300 | 0 | uint16_t data_size = 0; |
301 | 0 | int rc = decode_common_resp(msg, msg_len, cc, &data_size, reason_code); |
302 | 0 | if (data_size != 0) { |
303 | 0 | return NSM_SW_ERROR_LENGTH; |
304 | 0 | } |
305 | 0 | return rc; |
306 | 0 | } |
307 | | |
308 | | int encode_get_error_injection_mode_v1_req(uint8_t instance_id, |
309 | | struct nsm_msg *msg) |
310 | 0 | { |
311 | 0 | return encode_common_req(instance_id, NSM_TYPE_DEVICE_CONFIGURATION, |
312 | 0 | NSM_GET_ERROR_INJECTION_MODE_V1, msg); |
313 | 0 | } |
314 | | |
315 | | int decode_get_error_injection_mode_v1_req(const struct nsm_msg *msg, |
316 | | size_t msg_len) |
317 | 0 | { |
318 | 0 | return decode_common_req(msg, msg_len); |
319 | 0 | } |
320 | | |
321 | | int encode_get_error_injection_mode_v1_resp( |
322 | | uint8_t instance_id, uint8_t cc, uint16_t reason_code, |
323 | | const struct nsm_error_injection_mode_v1 *data, struct nsm_msg *msg) |
324 | 0 | { |
325 | 0 | int rc = encode_common_resp(instance_id, cc, reason_code, |
326 | 0 | NSM_TYPE_DEVICE_CONFIGURATION, |
327 | 0 | NSM_GET_ERROR_INJECTION_MODE_V1, msg); |
328 | 0 | if (rc == NSM_SW_SUCCESS && cc == NSM_SUCCESS) { |
329 | 0 | if (data == NULL) { |
330 | 0 | return NSM_SW_ERROR_NULL; |
331 | 0 | } |
332 | 0 | struct nsm_get_error_injection_mode_v1_resp *resp = |
333 | 0 | (struct nsm_get_error_injection_mode_v1_resp *)msg->payload; |
334 | 0 | resp->hdr.data_size = |
335 | 0 | htole16(sizeof(struct nsm_error_injection_mode_v1)); |
336 | 0 | resp->data.mode = data->mode; |
337 | 0 | resp->data.flags.byte = htole32(data->flags.byte); |
338 | 0 | } |
339 | 0 | return rc; |
340 | 0 | } |
341 | | |
342 | | int decode_get_error_injection_mode_v1_resp( |
343 | | const struct nsm_msg *msg, size_t msg_len, uint8_t *cc, |
344 | | uint16_t *reason_code, struct nsm_error_injection_mode_v1 *data) |
345 | 0 | { |
346 | 0 | uint16_t data_size = 0; |
347 | 0 | int rc = decode_common_resp(msg, msg_len, cc, &data_size, reason_code); |
348 | 0 | if (rc == NSM_SW_SUCCESS && *cc == NSM_SUCCESS) { |
349 | 0 | if (data == NULL) { |
350 | 0 | return NSM_SW_ERROR_NULL; |
351 | 0 | } |
352 | 0 | if (msg_len < |
353 | 0 | sizeof(struct nsm_msg_hdr) + |
354 | 0 | sizeof(struct nsm_get_error_injection_mode_v1_resp)) { |
355 | 0 | return NSM_SW_ERROR_LENGTH; |
356 | 0 | } |
357 | 0 | if (data_size != sizeof(struct nsm_error_injection_mode_v1)) { |
358 | 0 | return NSM_SW_ERROR_LENGTH; |
359 | 0 | } |
360 | 0 | struct nsm_get_error_injection_mode_v1_resp *resp = |
361 | 0 | (struct nsm_get_error_injection_mode_v1_resp *)msg->payload; |
362 | 0 | data->mode = resp->data.mode; |
363 | 0 | data->flags.byte = le32toh(resp->data.flags.byte); |
364 | 0 | } |
365 | 0 | return rc; |
366 | 0 | } |
367 | | |
368 | | int encode_set_current_error_injection_types_v1_req( |
369 | | uint8_t instance_id, const struct nsm_error_injection_types_mask *data, |
370 | | struct nsm_msg *msg) |
371 | 0 | { |
372 | 0 | int rc = |
373 | 0 | encode_common_req(instance_id, NSM_TYPE_DEVICE_CONFIGURATION, |
374 | 0 | NSM_SET_CURRENT_ERROR_INJECTION_TYPES_V1, msg); |
375 | 0 | if (rc == NSM_SW_SUCCESS) { |
376 | 0 | if (data == NULL) { |
377 | 0 | return NSM_SW_ERROR_NULL; |
378 | 0 | } |
379 | 0 | struct nsm_set_error_injection_types_mask_req *req = |
380 | 0 | (struct nsm_set_error_injection_types_mask_req *) |
381 | 0 | msg->payload; |
382 | 0 | req->hdr.data_size = |
383 | 0 | htole16(sizeof(struct nsm_error_injection_types_mask)); |
384 | 0 | req->data = *data; |
385 | 0 | } |
386 | 0 | return rc; |
387 | 0 | } |
388 | | |
389 | | int decode_set_current_error_injection_types_v1_req( |
390 | | const struct nsm_msg *msg, size_t msg_len, |
391 | | struct nsm_error_injection_types_mask *data) |
392 | 0 | { |
393 | 0 | int rc = decode_common_req(msg, msg_len); |
394 | 0 | if (rc == NSM_SW_SUCCESS) { |
395 | 0 | if (data == NULL) { |
396 | 0 | return NSM_SW_ERROR_NULL; |
397 | 0 | } |
398 | 0 | if (msg_len < |
399 | 0 | sizeof(struct nsm_msg_hdr) + |
400 | 0 | sizeof(struct nsm_set_error_injection_types_mask_req)) { |
401 | 0 | return NSM_SW_ERROR_LENGTH; |
402 | 0 | } |
403 | 0 | struct nsm_set_error_injection_types_mask_req *req = |
404 | 0 | (struct nsm_set_error_injection_types_mask_req *) |
405 | 0 | msg->payload; |
406 | 0 | if (req->hdr.data_size != |
407 | 0 | sizeof(struct nsm_error_injection_types_mask)) { |
408 | 0 | return NSM_SW_ERROR_LENGTH; |
409 | 0 | } |
410 | 0 | *data = req->data; |
411 | 0 | } |
412 | 0 | return rc; |
413 | 0 | } |
414 | | |
415 | | int encode_set_current_error_injection_types_v1_resp(uint8_t instance_id, |
416 | | uint8_t cc, |
417 | | uint16_t reason_code, |
418 | | struct nsm_msg *msg) |
419 | 0 | { |
420 | 0 | return encode_common_resp( |
421 | 0 | instance_id, cc, reason_code, NSM_TYPE_DEVICE_CONFIGURATION, |
422 | 0 | NSM_SET_CURRENT_ERROR_INJECTION_TYPES_V1, msg); |
423 | 0 | } |
424 | | |
425 | | int decode_set_current_error_injection_types_v1_resp(const struct nsm_msg *msg, |
426 | | size_t msg_len, |
427 | | uint8_t *cc, |
428 | | uint16_t *reason_code) |
429 | 0 | { |
430 | 0 | uint16_t data_size = 0; |
431 | 0 | int rc = decode_common_resp(msg, msg_len, cc, &data_size, reason_code); |
432 | 0 | if (data_size != 0) { |
433 | 0 | return NSM_SW_ERROR_NULL; |
434 | 0 | } |
435 | 0 | return rc; |
436 | 0 | } |
437 | | |
438 | | int encode_get_supported_error_injection_types_v1_req(uint8_t instance_id, |
439 | | struct nsm_msg *msg) |
440 | 0 | { |
441 | 0 | return encode_common_req(instance_id, NSM_TYPE_DEVICE_CONFIGURATION, |
442 | 0 | NSM_GET_SUPPORTED_ERROR_INJECTION_TYPES_V1, |
443 | 0 | msg); |
444 | 0 | } |
445 | | |
446 | | int encode_get_current_error_injection_types_v1_req(uint8_t instance_id, |
447 | | struct nsm_msg *msg) |
448 | 0 | { |
449 | 0 | return encode_common_req(instance_id, NSM_TYPE_DEVICE_CONFIGURATION, |
450 | 0 | NSM_GET_CURRENT_ERROR_INJECTION_TYPES_V1, msg); |
451 | 0 | } |
452 | | |
453 | | int decode_get_error_injection_types_v1_req(const struct nsm_msg *msg, |
454 | | size_t msg_len) |
455 | 0 | { |
456 | 0 | return decode_common_req(msg, msg_len); |
457 | 0 | } |
458 | | |
459 | | static int encode_get_error_injection_types_v1_resp( |
460 | | uint8_t instance_id, uint8_t cc, uint16_t reason_code, uint8_t command, |
461 | | const struct nsm_error_injection_types_mask *data, struct nsm_msg *msg) |
462 | 0 | { |
463 | 0 | int rc = |
464 | 0 | encode_common_resp(instance_id, cc, reason_code, |
465 | 0 | NSM_TYPE_DEVICE_CONFIGURATION, command, msg); |
466 | 0 | if (rc == NSM_SW_SUCCESS && cc == NSM_SUCCESS) { |
467 | 0 | if (data == NULL) { |
468 | 0 | return NSM_SW_ERROR_NULL; |
469 | 0 | } |
470 | 0 | struct nsm_get_error_injection_types_mask_resp *resp = |
471 | 0 | (struct nsm_get_error_injection_types_mask_resp *) |
472 | 0 | msg->payload; |
473 | 0 | resp->hdr.data_size = |
474 | 0 | htole16(sizeof(struct nsm_error_injection_types_mask)); |
475 | 0 | resp->data = *data; |
476 | 0 | } |
477 | 0 | return rc; |
478 | 0 | } |
479 | | |
480 | | int encode_get_supported_error_injection_types_v1_resp( |
481 | | uint8_t instance_id, uint8_t cc, uint16_t reason_code, |
482 | | const struct nsm_error_injection_types_mask *data, struct nsm_msg *msg) |
483 | 0 | { |
484 | 0 | return encode_get_error_injection_types_v1_resp( |
485 | 0 | instance_id, cc, reason_code, |
486 | 0 | NSM_GET_SUPPORTED_ERROR_INJECTION_TYPES_V1, data, msg); |
487 | 0 | } |
488 | | |
489 | | int encode_get_current_error_injection_types_v1_resp( |
490 | | uint8_t instance_id, uint8_t cc, uint16_t reason_code, |
491 | | const struct nsm_error_injection_types_mask *data, struct nsm_msg *msg) |
492 | 0 | { |
493 | 0 | return encode_get_error_injection_types_v1_resp( |
494 | 0 | instance_id, cc, reason_code, |
495 | 0 | NSM_GET_CURRENT_ERROR_INJECTION_TYPES_V1, data, msg); |
496 | 0 | } |
497 | | |
498 | | int decode_get_error_injection_types_v1_resp( |
499 | | const struct nsm_msg *msg, size_t msg_len, uint8_t *cc, |
500 | | uint16_t *reason_code, struct nsm_error_injection_types_mask *data) |
501 | 0 | { |
502 | 0 | uint16_t data_size = 0; |
503 | 0 | int rc = decode_common_resp(msg, msg_len, cc, &data_size, reason_code); |
504 | 0 | if (rc == NSM_SW_SUCCESS && *cc == NSM_SUCCESS) { |
505 | 0 | if (data == NULL) { |
506 | 0 | return NSM_SW_ERROR_NULL; |
507 | 0 | } |
508 | 0 | if (msg_len < |
509 | 0 | sizeof(struct nsm_msg_hdr) + |
510 | 0 | sizeof( |
511 | 0 | struct nsm_get_error_injection_types_mask_resp)) { |
512 | 0 | return NSM_SW_ERROR_LENGTH; |
513 | 0 | } |
514 | 0 | if (data_size != |
515 | 0 | sizeof(struct nsm_error_injection_types_mask)) { |
516 | 0 | return NSM_SW_ERROR_LENGTH; |
517 | 0 | } |
518 | 0 | struct nsm_get_error_injection_types_mask_resp *resp = |
519 | 0 | (struct nsm_get_error_injection_types_mask_resp *) |
520 | 0 | msg->payload; |
521 | 0 | *data = resp->data; |
522 | 0 | } |
523 | 0 | return rc; |
524 | 0 | } |
525 | | |
526 | | int encode_get_fpga_diagnostics_settings_req( |
527 | | uint8_t instance_id, enum fpga_diagnostics_settings_data_index data_index, |
528 | | struct nsm_msg *msg) |
529 | 0 | { |
530 | 0 | if (msg == NULL) { |
531 | 0 | return NSM_SW_ERROR_NULL; |
532 | 0 | } |
533 | | |
534 | 0 | struct nsm_header_info header = {0}; |
535 | 0 | header.nsm_msg_type = NSM_REQUEST; |
536 | 0 | header.instance_id = instance_id; |
537 | 0 | header.nvidia_msg_type = NSM_TYPE_DEVICE_CONFIGURATION; |
538 | |
|
539 | 0 | uint8_t rc = pack_nsm_header(&header, &(msg->hdr)); |
540 | 0 | if (rc != NSM_SW_SUCCESS) { |
541 | 0 | return rc; |
542 | 0 | } |
543 | | |
544 | 0 | struct nsm_get_fpga_diagnostics_settings_req *request = |
545 | 0 | (struct nsm_get_fpga_diagnostics_settings_req *)msg->payload; |
546 | |
|
547 | 0 | request->hdr.command = NSM_GET_FPGA_DIAGNOSTICS_SETTINGS; |
548 | 0 | request->hdr.data_size = 1; |
549 | 0 | request->data_index = data_index; |
550 | |
|
551 | 0 | return NSM_SW_SUCCESS; |
552 | 0 | } |
553 | | |
554 | | int decode_get_fpga_diagnostics_settings_req( |
555 | | const struct nsm_msg *msg, size_t msg_len, |
556 | | enum fpga_diagnostics_settings_data_index *data_index) |
557 | 0 | { |
558 | 0 | if (msg == NULL || data_index == NULL) { |
559 | 0 | return NSM_SW_ERROR_NULL; |
560 | 0 | } |
561 | | |
562 | 0 | if (msg_len < |
563 | 0 | sizeof(struct nsm_msg_hdr) + |
564 | 0 | sizeof(struct nsm_get_fpga_diagnostics_settings_req)) { |
565 | 0 | return NSM_SW_ERROR_LENGTH; |
566 | 0 | } |
567 | | |
568 | 0 | struct nsm_get_fpga_diagnostics_settings_req *request = |
569 | 0 | (struct nsm_get_fpga_diagnostics_settings_req *)msg->payload; |
570 | |
|
571 | 0 | if (request->hdr.data_size < |
572 | 0 | sizeof(struct nsm_get_fpga_diagnostics_settings_req) - |
573 | 0 | NSM_REQUEST_CONVENTION_LEN) { |
574 | 0 | return NSM_SW_ERROR_DATA; |
575 | 0 | } |
576 | | |
577 | 0 | *data_index = request->data_index; |
578 | 0 | return NSM_SW_SUCCESS; |
579 | 0 | } |
580 | | |
581 | | int encode_get_fpga_diagnostics_settings_resp(uint8_t instance_id, uint8_t cc, |
582 | | uint16_t reason_code, |
583 | | const uint16_t data_size, |
584 | | uint8_t *data, |
585 | | struct nsm_msg *msg) |
586 | 0 | { |
587 | 0 | if (msg == NULL || data == NULL) { |
588 | 0 | return NSM_SW_ERROR_NULL; |
589 | 0 | } |
590 | | |
591 | 0 | struct nsm_header_info header = {0}; |
592 | 0 | header.nsm_msg_type = NSM_RESPONSE; |
593 | 0 | header.instance_id = instance_id & 0x1f; |
594 | 0 | header.nvidia_msg_type = NSM_TYPE_DEVICE_CONFIGURATION; |
595 | |
|
596 | 0 | uint8_t rc = pack_nsm_header(&header, &msg->hdr); |
597 | 0 | if (rc != NSM_SW_SUCCESS) { |
598 | 0 | return rc; |
599 | 0 | } |
600 | | |
601 | 0 | if (cc != NSM_SUCCESS) { |
602 | 0 | return encode_reason_code( |
603 | 0 | cc, reason_code, NSM_GET_FPGA_DIAGNOSTICS_SETTINGS, msg); |
604 | 0 | } |
605 | | |
606 | 0 | struct nsm_get_fpga_diagnostics_settings_resp *resp = |
607 | 0 | (struct nsm_get_fpga_diagnostics_settings_resp *)msg->payload; |
608 | |
|
609 | 0 | resp->hdr.command = NSM_GET_FPGA_DIAGNOSTICS_SETTINGS; |
610 | 0 | resp->hdr.completion_code = cc; |
611 | 0 | resp->hdr.data_size = htole16(data_size); |
612 | 0 | memcpy(resp->data, data, data_size); |
613 | 0 | return NSM_SW_SUCCESS; |
614 | 0 | } |
615 | | |
616 | | int decode_get_fpga_diagnostics_settings_resp(const struct nsm_msg *msg, |
617 | | size_t msg_len, uint8_t *cc, |
618 | | uint16_t *data_size, |
619 | | uint16_t *reason_code, |
620 | | uint8_t *data) |
621 | 0 | { |
622 | 0 | if (msg == NULL || cc == NULL || data_size == NULL || |
623 | 0 | reason_code == NULL || data == NULL) { |
624 | 0 | return NSM_SW_ERROR_NULL; |
625 | 0 | } |
626 | 0 | int rc = decode_reason_code_and_cc(msg, msg_len, cc, reason_code); |
627 | 0 | if (rc != NSM_SW_SUCCESS || *cc != NSM_SUCCESS) { |
628 | 0 | return rc; |
629 | 0 | } |
630 | | |
631 | 0 | if (msg_len < |
632 | 0 | sizeof(struct nsm_msg_hdr) + |
633 | 0 | sizeof(struct nsm_get_fpga_diagnostics_settings_resp)) { |
634 | 0 | return NSM_SW_ERROR_LENGTH; |
635 | 0 | } |
636 | | |
637 | 0 | struct nsm_get_fpga_diagnostics_settings_resp *resp = |
638 | 0 | (struct nsm_get_fpga_diagnostics_settings_resp *)msg->payload; |
639 | |
|
640 | 0 | *data_size = le16toh(resp->hdr.data_size); |
641 | 0 | memcpy(data, resp->data, *data_size); |
642 | 0 | return NSM_SW_SUCCESS; |
643 | 0 | } |
644 | | |
645 | | int encode_get_fpga_diagnostics_settings_wp_resp( |
646 | | uint8_t instance_id, uint8_t cc, uint16_t reason_code, |
647 | | struct nsm_fpga_diagnostics_settings_wp *data, struct nsm_msg *msg) |
648 | 0 | { |
649 | 0 | return encode_get_fpga_diagnostics_settings_resp( |
650 | 0 | instance_id, cc, reason_code, |
651 | 0 | sizeof(struct nsm_fpga_diagnostics_settings_wp), (uint8_t *)data, |
652 | 0 | msg); |
653 | 0 | } |
654 | | |
655 | | int decode_get_fpga_diagnostics_settings_wp_resp( |
656 | | const struct nsm_msg *msg, size_t msg_len, uint8_t *cc, |
657 | | uint16_t *reason_code, struct nsm_fpga_diagnostics_settings_wp *data) |
658 | 0 | { |
659 | 0 | uint16_t data_size = 0; |
660 | 0 | int ret = decode_get_fpga_diagnostics_settings_resp( |
661 | 0 | msg, msg_len, cc, &data_size, reason_code, (uint8_t *)data); |
662 | 0 | if (ret != NSM_SW_SUCCESS || *cc != NSM_SUCCESS) |
663 | 0 | return ret; |
664 | 0 | if (data_size < sizeof(struct nsm_fpga_diagnostics_settings_wp)) |
665 | 0 | ret = NSM_SW_ERROR_LENGTH; |
666 | 0 | return ret; |
667 | 0 | } |
668 | | |
669 | | int encode_get_fpga_diagnostics_settings_wp_jumper_resp( |
670 | | uint8_t instance_id, uint8_t cc, uint16_t reason_code, |
671 | | struct nsm_fpga_diagnostics_settings_wp_jumper *data, struct nsm_msg *msg) |
672 | 0 | { |
673 | 0 | return encode_get_fpga_diagnostics_settings_resp( |
674 | 0 | instance_id, cc, reason_code, |
675 | 0 | sizeof(struct nsm_fpga_diagnostics_settings_wp_jumper), |
676 | 0 | (uint8_t *)data, msg); |
677 | 0 | } |
678 | | |
679 | | int decode_get_fpga_diagnostics_settings_wp_jumper_resp( |
680 | | const struct nsm_msg *msg, size_t msg_len, uint8_t *cc, |
681 | | uint16_t *reason_code, struct nsm_fpga_diagnostics_settings_wp_jumper *data) |
682 | 0 | { |
683 | 0 | uint16_t data_size = 0; |
684 | 0 | int ret = decode_get_fpga_diagnostics_settings_resp( |
685 | 0 | msg, msg_len, cc, &data_size, reason_code, (uint8_t *)data); |
686 | 0 | if (ret != NSM_SW_SUCCESS || *cc != NSM_SUCCESS) |
687 | 0 | return ret; |
688 | 0 | if (data_size < sizeof(struct nsm_fpga_diagnostics_settings_wp_jumper)) |
689 | 0 | ret = NSM_SW_ERROR_LENGTH; |
690 | 0 | return ret; |
691 | 0 | } |
692 | | |
693 | | int encode_get_power_supply_status_resp(uint8_t instance_id, uint8_t cc, |
694 | | uint16_t reason_code, |
695 | | uint8_t power_supply_status, |
696 | | struct nsm_msg *msg) |
697 | 0 | { |
698 | 0 | return encode_get_fpga_diagnostics_settings_resp( |
699 | 0 | instance_id, cc, reason_code, sizeof(uint8_t), &power_supply_status, |
700 | 0 | msg); |
701 | 0 | } |
702 | | |
703 | | int decode_get_power_supply_status_resp(const struct nsm_msg *msg, |
704 | | size_t msg_len, uint8_t *cc, |
705 | | uint16_t *reason_code, |
706 | | uint8_t *power_supply_status) |
707 | 0 | { |
708 | 0 | uint16_t data_size = 0; |
709 | 0 | int ret = decode_get_fpga_diagnostics_settings_resp( |
710 | 0 | msg, msg_len, cc, &data_size, reason_code, |
711 | 0 | (uint8_t *)power_supply_status); |
712 | 0 | if (ret != NSM_SW_SUCCESS || *cc != NSM_SUCCESS) |
713 | 0 | return ret; |
714 | 0 | if (data_size < sizeof(uint8_t)) |
715 | 0 | ret = NSM_SW_ERROR_LENGTH; |
716 | 0 | return ret; |
717 | 0 | } |
718 | | |
719 | | int encode_get_gpu_presence_resp(uint8_t instance_id, uint8_t cc, |
720 | | uint16_t reason_code, uint8_t presence, |
721 | | struct nsm_msg *msg) |
722 | 0 | { |
723 | 0 | return encode_get_fpga_diagnostics_settings_resp( |
724 | 0 | instance_id, cc, reason_code, sizeof(uint8_t), &presence, msg); |
725 | 0 | } |
726 | | |
727 | | int decode_get_gpu_presence_resp(const struct nsm_msg *msg, size_t msg_len, |
728 | | uint8_t *cc, uint16_t *reason_code, |
729 | | uint8_t *presence) |
730 | 0 | { |
731 | 0 | uint16_t data_size = 0; |
732 | 0 | int ret = decode_get_fpga_diagnostics_settings_resp( |
733 | 0 | msg, msg_len, cc, &data_size, reason_code, (uint8_t *)presence); |
734 | 0 | if (ret != NSM_SW_SUCCESS || *cc != NSM_SUCCESS) |
735 | 0 | return ret; |
736 | 0 | if (data_size < sizeof(uint8_t)) |
737 | 0 | ret = NSM_SW_ERROR_LENGTH; |
738 | 0 | return ret; |
739 | 0 | } |
740 | | |
741 | | int encode_get_gpu_power_status_resp(uint8_t instance_id, uint8_t cc, |
742 | | uint16_t reason_code, uint8_t power_status, |
743 | | struct nsm_msg *msg) |
744 | 0 | { |
745 | 0 | return encode_get_fpga_diagnostics_settings_resp( |
746 | 0 | instance_id, cc, reason_code, sizeof(uint8_t), &power_status, msg); |
747 | 0 | } |
748 | | |
749 | | int decode_get_gpu_power_status_resp(const struct nsm_msg *msg, size_t msg_len, |
750 | | uint8_t *cc, uint16_t *reason_code, |
751 | | uint8_t *power_status) |
752 | 0 | { |
753 | 0 | uint16_t data_size = 0; |
754 | 0 | int ret = decode_get_fpga_diagnostics_settings_resp( |
755 | 0 | msg, msg_len, cc, &data_size, reason_code, (uint8_t *)power_status); |
756 | 0 | if (ret != NSM_SW_SUCCESS || *cc != NSM_SUCCESS) |
757 | 0 | return ret; |
758 | 0 | if (data_size < sizeof(uint8_t)) |
759 | 0 | ret = NSM_SW_ERROR_LENGTH; |
760 | 0 | return ret; |
761 | 0 | } |
762 | | |
763 | | int encode_get_gpu_ist_mode_resp(uint8_t instance_id, uint8_t cc, |
764 | | uint16_t reason_code, uint8_t mode, |
765 | | struct nsm_msg *msg) |
766 | 0 | { |
767 | 0 | return encode_get_fpga_diagnostics_settings_resp( |
768 | 0 | instance_id, cc, reason_code, sizeof(uint8_t), &mode, msg); |
769 | 0 | } |
770 | | |
771 | | int decode_get_gpu_ist_mode_resp(const struct nsm_msg *msg, size_t msg_len, |
772 | | uint8_t *cc, uint16_t *reason_code, |
773 | | uint8_t *mode) |
774 | 0 | { |
775 | 0 | uint16_t data_size = 0; |
776 | 0 | int ret = decode_get_fpga_diagnostics_settings_resp( |
777 | 0 | msg, msg_len, cc, &data_size, reason_code, mode); |
778 | 0 | if (ret != NSM_SW_SUCCESS || *cc != NSM_SUCCESS) |
779 | 0 | return ret; |
780 | 0 | if (data_size < sizeof(uint8_t)) |
781 | 0 | ret = NSM_SW_ERROR_LENGTH; |
782 | 0 | return ret; |
783 | 0 | } |
784 | | |
785 | | int encode_enable_disable_gpu_ist_mode_req(uint8_t instance_id, |
786 | | uint8_t device_index, uint8_t value, |
787 | | struct nsm_msg *msg) |
788 | 0 | { |
789 | 0 | if (msg == NULL) { |
790 | 0 | return NSM_SW_ERROR_NULL; |
791 | 0 | } |
792 | | |
793 | 0 | struct nsm_header_info header = {0}; |
794 | 0 | header.nsm_msg_type = NSM_REQUEST; |
795 | 0 | header.instance_id = instance_id; |
796 | 0 | header.nvidia_msg_type = NSM_TYPE_DEVICE_CONFIGURATION; |
797 | |
|
798 | 0 | uint8_t rc = pack_nsm_header(&header, &(msg->hdr)); |
799 | 0 | if (rc != NSM_SW_SUCCESS) { |
800 | 0 | return rc; |
801 | 0 | } |
802 | | |
803 | 0 | struct nsm_enable_disable_gpu_ist_mode_req *request = |
804 | 0 | (struct nsm_enable_disable_gpu_ist_mode_req *)msg->payload; |
805 | |
|
806 | 0 | request->hdr.command = NSM_ENABLE_DISABLE_GPU_IST_MODE; |
807 | 0 | request->hdr.data_size = 2; |
808 | 0 | request->device_index = device_index; |
809 | 0 | request->value = value; |
810 | |
|
811 | 0 | return NSM_SW_SUCCESS; |
812 | 0 | } |
813 | | |
814 | | int decode_enable_disable_gpu_ist_mode_req(const struct nsm_msg *msg, |
815 | | size_t msg_len, |
816 | | uint8_t *device_index, |
817 | | uint8_t *value) |
818 | 0 | { |
819 | 0 | if (msg == NULL || device_index == NULL || value == NULL) { |
820 | 0 | return NSM_SW_ERROR_NULL; |
821 | 0 | } |
822 | | |
823 | 0 | if (msg_len < sizeof(struct nsm_msg_hdr) + |
824 | 0 | sizeof(struct nsm_enable_disable_gpu_ist_mode_req)) { |
825 | 0 | return NSM_SW_ERROR_LENGTH; |
826 | 0 | } |
827 | | |
828 | 0 | struct nsm_enable_disable_gpu_ist_mode_req *request = |
829 | 0 | (struct nsm_enable_disable_gpu_ist_mode_req *)msg->payload; |
830 | |
|
831 | 0 | if (request->hdr.data_size < |
832 | 0 | sizeof(struct nsm_enable_disable_gpu_ist_mode_req) - |
833 | 0 | NSM_REQUEST_CONVENTION_LEN) { |
834 | 0 | return NSM_SW_ERROR_DATA; |
835 | 0 | } |
836 | | |
837 | 0 | *device_index = request->device_index; |
838 | 0 | *value = request->value; |
839 | 0 | return NSM_SW_SUCCESS; |
840 | 0 | } |
841 | | |
842 | | int encode_enable_disable_gpu_ist_mode_resp(uint8_t instance_id, uint8_t cc, |
843 | | uint16_t reason_code, |
844 | | struct nsm_msg *msg) |
845 | 0 | { |
846 | 0 | return encode_common_resp(instance_id, cc, reason_code, |
847 | 0 | NSM_TYPE_DEVICE_CONFIGURATION, |
848 | 0 | NSM_ENABLE_DISABLE_GPU_IST_MODE, msg); |
849 | 0 | } |
850 | | |
851 | | int decode_enable_disable_gpu_ist_mode_resp(const struct nsm_msg *msg, |
852 | | size_t msg_len, uint8_t *cc, |
853 | | uint16_t *reason_code) |
854 | 0 | { |
855 | 0 | uint16_t data_size = 0; |
856 | 0 | int rc = decode_common_resp(msg, msg_len, cc, &data_size, reason_code); |
857 | 0 | if (data_size != 0) { |
858 | 0 | return NSM_SW_ERROR_LENGTH; |
859 | 0 | } |
860 | 0 | return rc; |
861 | 0 | } |
862 | | |
863 | | int encode_get_reconfiguration_permissions_v1_req( |
864 | | uint8_t instance_id, |
865 | | enum reconfiguration_permissions_v1_index setting_index, |
866 | | struct nsm_msg *msg) |
867 | 0 | { |
868 | |
|
869 | 0 | if (msg == NULL) { |
870 | 0 | return NSM_SW_ERROR_NULL; |
871 | 0 | } |
872 | | |
873 | 0 | struct nsm_header_info header = {0}; |
874 | 0 | header.nsm_msg_type = NSM_REQUEST; |
875 | 0 | header.instance_id = instance_id; |
876 | 0 | header.nvidia_msg_type = NSM_TYPE_DEVICE_CONFIGURATION; |
877 | |
|
878 | 0 | uint8_t rc = pack_nsm_header(&header, &(msg->hdr)); |
879 | 0 | if (rc != NSM_SW_SUCCESS) { |
880 | 0 | return rc; |
881 | 0 | } |
882 | | |
883 | 0 | struct nsm_get_reconfiguration_permissions_v1_req *request = |
884 | 0 | (struct nsm_get_reconfiguration_permissions_v1_req *)msg->payload; |
885 | |
|
886 | 0 | request->hdr.command = NSM_GET_RECONFIGURATION_PERMISSIONS_V1; |
887 | 0 | request->hdr.data_size = 1; |
888 | 0 | request->setting_index = setting_index; |
889 | |
|
890 | 0 | return NSM_SW_SUCCESS; |
891 | 0 | } |
892 | | int decode_get_reconfiguration_permissions_v1_req( |
893 | | const struct nsm_msg *msg, size_t msg_len, |
894 | | enum reconfiguration_permissions_v1_index *setting_index) |
895 | 0 | { |
896 | 0 | if (msg == NULL || setting_index == NULL) { |
897 | 0 | return NSM_SW_ERROR_NULL; |
898 | 0 | } |
899 | | |
900 | 0 | if (msg_len < |
901 | 0 | sizeof(struct nsm_msg_hdr) + |
902 | 0 | sizeof(struct nsm_get_reconfiguration_permissions_v1_req)) { |
903 | 0 | return NSM_SW_ERROR_LENGTH; |
904 | 0 | } |
905 | | |
906 | 0 | struct nsm_get_reconfiguration_permissions_v1_req *request = |
907 | 0 | (struct nsm_get_reconfiguration_permissions_v1_req *)msg->payload; |
908 | |
|
909 | 0 | if (request->hdr.data_size < |
910 | 0 | sizeof(struct nsm_get_reconfiguration_permissions_v1_req) - |
911 | 0 | NSM_REQUEST_CONVENTION_LEN) { |
912 | 0 | return NSM_SW_ERROR_DATA; |
913 | 0 | } |
914 | | |
915 | 0 | *setting_index = request->setting_index; |
916 | 0 | return NSM_SW_SUCCESS; |
917 | 0 | } |
918 | | |
919 | | int encode_get_reconfiguration_permissions_v1_resp( |
920 | | uint8_t instance_id, uint8_t cc, uint16_t reason_code, |
921 | | struct nsm_reconfiguration_permissions_v1 *data, struct nsm_msg *msg) |
922 | 0 | { |
923 | 0 | if (msg == NULL || data == NULL) { |
924 | 0 | return NSM_SW_ERROR_NULL; |
925 | 0 | } |
926 | | |
927 | 0 | struct nsm_header_info header = {0}; |
928 | 0 | header.nsm_msg_type = NSM_RESPONSE; |
929 | 0 | header.instance_id = instance_id & 0x1f; |
930 | 0 | header.nvidia_msg_type = NSM_TYPE_DEVICE_CONFIGURATION; |
931 | |
|
932 | 0 | uint8_t rc = pack_nsm_header(&header, &msg->hdr); |
933 | 0 | if (rc != NSM_SW_SUCCESS) { |
934 | 0 | return rc; |
935 | 0 | } |
936 | | |
937 | 0 | if (cc != NSM_SUCCESS) { |
938 | 0 | return encode_reason_code( |
939 | 0 | cc, reason_code, NSM_GET_RECONFIGURATION_PERMISSIONS_V1, |
940 | 0 | msg); |
941 | 0 | } |
942 | | |
943 | 0 | struct nsm_get_reconfiguration_permissions_v1_resp *resp = |
944 | 0 | (struct nsm_get_reconfiguration_permissions_v1_resp *)msg->payload; |
945 | |
|
946 | 0 | uint16_t data_size = sizeof(struct nsm_reconfiguration_permissions_v1); |
947 | 0 | resp->hdr.command = NSM_GET_RECONFIGURATION_PERMISSIONS_V1; |
948 | 0 | resp->hdr.completion_code = cc; |
949 | 0 | resp->hdr.data_size = htole16(data_size); |
950 | 0 | resp->data = *data; |
951 | 0 | return NSM_SW_SUCCESS; |
952 | 0 | } |
953 | | |
954 | | int decode_get_reconfiguration_permissions_v1_resp( |
955 | | const struct nsm_msg *msg, size_t msg_len, uint8_t *cc, |
956 | | uint16_t *reason_code, struct nsm_reconfiguration_permissions_v1 *data) |
957 | 0 | { |
958 | 0 | if (msg == NULL || cc == NULL || reason_code == NULL || data == NULL) { |
959 | 0 | return NSM_SW_ERROR_NULL; |
960 | 0 | } |
961 | 0 | int rc = decode_reason_code_and_cc(msg, msg_len, cc, reason_code); |
962 | 0 | if (rc != NSM_SW_SUCCESS || *cc != NSM_SUCCESS) { |
963 | 0 | return rc; |
964 | 0 | } |
965 | | |
966 | 0 | if (msg_len < |
967 | 0 | sizeof(struct nsm_msg_hdr) + |
968 | 0 | sizeof(struct nsm_get_reconfiguration_permissions_v1_resp)) { |
969 | 0 | return NSM_SW_ERROR_LENGTH; |
970 | 0 | } |
971 | | |
972 | 0 | struct nsm_get_reconfiguration_permissions_v1_resp *resp = |
973 | 0 | (struct nsm_get_reconfiguration_permissions_v1_resp *)msg->payload; |
974 | |
|
975 | 0 | *data = resp->data; |
976 | 0 | return NSM_SW_SUCCESS; |
977 | 0 | } |
978 | | |
979 | | int encode_set_reconfiguration_permissions_v1_req( |
980 | | uint8_t instance_id, |
981 | | enum reconfiguration_permissions_v1_index setting_index, |
982 | | enum reconfiguration_permissions_v1_setting configuration, |
983 | | uint8_t permission, struct nsm_msg *msg) |
984 | 0 | { |
985 | |
|
986 | 0 | if (msg == NULL) { |
987 | 0 | return NSM_SW_ERROR_NULL; |
988 | 0 | } |
989 | | |
990 | 0 | struct nsm_header_info header = {0}; |
991 | 0 | header.nsm_msg_type = NSM_REQUEST; |
992 | 0 | header.instance_id = instance_id; |
993 | 0 | header.nvidia_msg_type = NSM_TYPE_DEVICE_CONFIGURATION; |
994 | |
|
995 | 0 | uint8_t rc = pack_nsm_header(&header, &(msg->hdr)); |
996 | 0 | if (rc != NSM_SW_SUCCESS) { |
997 | 0 | return rc; |
998 | 0 | } |
999 | | |
1000 | 0 | struct nsm_set_reconfiguration_permissions_v1_req *request = |
1001 | 0 | (struct nsm_set_reconfiguration_permissions_v1_req *)msg->payload; |
1002 | |
|
1003 | 0 | request->hdr.command = NSM_SET_RECONFIGURATION_PERMISSIONS_V1; |
1004 | 0 | request->hdr.data_size = 3; |
1005 | 0 | request->setting_index = setting_index; |
1006 | 0 | request->configuration = configuration; |
1007 | 0 | request->permission = permission; |
1008 | |
|
1009 | 0 | return NSM_SW_SUCCESS; |
1010 | 0 | } |
1011 | | |
1012 | | int decode_set_reconfiguration_permissions_v1_req( |
1013 | | const struct nsm_msg *msg, size_t msg_len, |
1014 | | enum reconfiguration_permissions_v1_index *setting_index, |
1015 | | enum reconfiguration_permissions_v1_setting *configuration, |
1016 | | uint8_t *permission) |
1017 | 0 | { |
1018 | 0 | if (msg == NULL || setting_index == NULL || configuration == NULL || |
1019 | 0 | permission == NULL) { |
1020 | 0 | return NSM_SW_ERROR_NULL; |
1021 | 0 | } |
1022 | | |
1023 | 0 | if (msg_len < |
1024 | 0 | sizeof(struct nsm_msg_hdr) + |
1025 | 0 | sizeof(struct nsm_set_reconfiguration_permissions_v1_req)) { |
1026 | 0 | return NSM_SW_ERROR_LENGTH; |
1027 | 0 | } |
1028 | | |
1029 | 0 | struct nsm_set_reconfiguration_permissions_v1_req *request = |
1030 | 0 | (struct nsm_set_reconfiguration_permissions_v1_req *)msg->payload; |
1031 | |
|
1032 | 0 | if (request->hdr.data_size < |
1033 | 0 | sizeof(struct nsm_set_reconfiguration_permissions_v1_req) - |
1034 | 0 | NSM_REQUEST_CONVENTION_LEN) { |
1035 | 0 | return NSM_SW_ERROR_DATA; |
1036 | 0 | } |
1037 | | |
1038 | 0 | *setting_index = request->setting_index; |
1039 | 0 | *configuration = request->configuration; |
1040 | 0 | *permission = request->permission; |
1041 | 0 | return NSM_SW_SUCCESS; |
1042 | 0 | } |
1043 | | |
1044 | | int encode_set_reconfiguration_permissions_v1_resp(uint8_t instance_id, |
1045 | | uint8_t cc, |
1046 | | uint16_t reason_code, |
1047 | | struct nsm_msg *msg) |
1048 | 0 | { |
1049 | |
|
1050 | 0 | return encode_common_resp(instance_id, cc, reason_code, |
1051 | 0 | NSM_TYPE_DEVICE_CONFIGURATION, |
1052 | 0 | NSM_SET_RECONFIGURATION_PERMISSIONS_V1, msg); |
1053 | 0 | } |
1054 | | |
1055 | | int decode_set_reconfiguration_permissions_v1_resp(const struct nsm_msg *msg, |
1056 | | size_t msg_len, uint8_t *cc, |
1057 | | uint16_t *reason_code) |
1058 | 0 | { |
1059 | 0 | uint16_t data_size = 0; |
1060 | 0 | int rc = decode_common_resp(msg, msg_len, cc, &data_size, reason_code); |
1061 | 0 | if (data_size != 0) { |
1062 | 0 | return NSM_SW_ERROR_LENGTH; |
1063 | 0 | } |
1064 | 0 | return rc; |
1065 | 0 | } |
1066 | | |
1067 | | int encode_get_confidential_compute_mode_v1_req(uint8_t instance_id, |
1068 | | struct nsm_msg *msg) |
1069 | 0 | { |
1070 | 0 | return encode_common_req(instance_id, NSM_TYPE_DEVICE_CONFIGURATION, |
1071 | 0 | NSM_GET_CONFIDENTIAL_COMPUTE_MODE_V1, msg); |
1072 | 0 | } |
1073 | | |
1074 | | int decode_get_confidential_compute_mode_v1_req(const struct nsm_msg *msg, |
1075 | | size_t msg_len) |
1076 | 0 | { |
1077 | 0 | return decode_common_req(msg, msg_len); |
1078 | 0 | } |
1079 | | |
1080 | | int encode_get_confidential_compute_mode_v1_resp( |
1081 | | uint8_t instance_id, uint8_t cc, uint16_t reason_code, uint8_t current_mode, |
1082 | | uint8_t pending_mode, struct nsm_msg *msg) |
1083 | 0 | { |
1084 | 0 | if (msg == NULL) { |
1085 | 0 | return NSM_SW_ERROR_NULL; |
1086 | 0 | } |
1087 | | |
1088 | 0 | struct nsm_header_info header = {0}; |
1089 | 0 | header.nsm_msg_type = NSM_RESPONSE; |
1090 | 0 | header.instance_id = instance_id & 0x1f; |
1091 | 0 | header.nvidia_msg_type = NSM_TYPE_DEVICE_CONFIGURATION; |
1092 | |
|
1093 | 0 | uint8_t rc = pack_nsm_header(&header, &msg->hdr); |
1094 | 0 | if (rc != NSM_SW_SUCCESS) { |
1095 | 0 | return rc; |
1096 | 0 | } |
1097 | | |
1098 | 0 | if (cc != NSM_SUCCESS) { |
1099 | 0 | return encode_reason_code( |
1100 | 0 | cc, reason_code, NSM_GET_CONFIDENTIAL_COMPUTE_MODE_V1, msg); |
1101 | 0 | } |
1102 | | |
1103 | 0 | struct nsm_get_confidential_compute_mode_v1_resp *resp = |
1104 | 0 | (struct nsm_get_confidential_compute_mode_v1_resp *)msg->payload; |
1105 | |
|
1106 | 0 | resp->hdr.command = NSM_GET_CONFIDENTIAL_COMPUTE_MODE_V1; |
1107 | 0 | resp->hdr.completion_code = cc; |
1108 | 0 | resp->hdr.data_size = |
1109 | 0 | htole16(sizeof(struct nsm_get_confidential_compute_mode_v1_resp) - |
1110 | 0 | sizeof(struct nsm_common_resp)); |
1111 | 0 | resp->current_mode = current_mode; |
1112 | 0 | resp->pending_mode = pending_mode; |
1113 | 0 | return NSM_SW_SUCCESS; |
1114 | 0 | } |
1115 | | |
1116 | | int decode_get_confidential_compute_mode_v1_resp( |
1117 | | const struct nsm_msg *msg, size_t msg_len, uint8_t *cc, uint16_t *data_size, |
1118 | | uint16_t *reason_code, uint8_t *current_mode, uint8_t *pending_mode) |
1119 | 0 | { |
1120 | 0 | if (msg == NULL || cc == NULL || data_size == NULL || |
1121 | 0 | current_mode == NULL || pending_mode == NULL) { |
1122 | 0 | return NSM_SW_ERROR_NULL; |
1123 | 0 | } |
1124 | 0 | int rc = decode_reason_code_and_cc(msg, msg_len, cc, reason_code); |
1125 | 0 | if (rc != NSM_SW_SUCCESS || *cc != NSM_SUCCESS) { |
1126 | 0 | return rc; |
1127 | 0 | } |
1128 | | |
1129 | 0 | if (msg_len != |
1130 | 0 | (sizeof(struct nsm_msg_hdr)) + |
1131 | 0 | sizeof(struct nsm_get_confidential_compute_mode_v1_resp)) { |
1132 | 0 | return NSM_SW_ERROR_LENGTH; |
1133 | 0 | } |
1134 | | |
1135 | 0 | struct nsm_get_confidential_compute_mode_v1_resp *resp = |
1136 | 0 | (struct nsm_get_confidential_compute_mode_v1_resp *)msg->payload; |
1137 | |
|
1138 | 0 | *data_size = le16toh(resp->hdr.data_size); |
1139 | |
|
1140 | 0 | if ((*data_size) != |
1141 | 0 | (sizeof(struct nsm_get_confidential_compute_mode_v1_resp) - |
1142 | 0 | sizeof(struct nsm_common_resp))) { |
1143 | 0 | return NSM_SW_ERROR_DATA; |
1144 | 0 | } |
1145 | 0 | *current_mode = resp->current_mode; |
1146 | 0 | *pending_mode = resp->pending_mode; |
1147 | 0 | return NSM_SW_SUCCESS; |
1148 | 0 | } |
1149 | | |
1150 | | int encode_set_confidential_compute_mode_v1_req(uint8_t instance_id, |
1151 | | uint8_t mode, |
1152 | | struct nsm_msg *msg) |
1153 | 0 | { |
1154 | 0 | int rc = encode_common_req(instance_id, NSM_TYPE_DEVICE_CONFIGURATION, |
1155 | 0 | NSM_SET_CONFIDENTIAL_COMPUTE_MODE_V1, msg); |
1156 | 0 | if (rc == NSM_SW_SUCCESS) { |
1157 | 0 | struct nsm_set_confidential_compute_mode_v1_req *req = |
1158 | 0 | (struct nsm_set_confidential_compute_mode_v1_req *) |
1159 | 0 | msg->payload; |
1160 | 0 | req->hdr.data_size = |
1161 | 0 | sizeof(struct nsm_set_confidential_compute_mode_v1_req) - |
1162 | 0 | sizeof(struct nsm_common_req); |
1163 | 0 | req->mode = mode; |
1164 | 0 | } |
1165 | 0 | return rc; |
1166 | 0 | } |
1167 | | |
1168 | | int decode_set_confidential_compute_mode_v1_req(const struct nsm_msg *msg, |
1169 | | size_t msg_len, uint8_t *mode) |
1170 | 0 | { |
1171 | 0 | if (msg == NULL || mode == NULL) { |
1172 | 0 | return NSM_SW_ERROR_NULL; |
1173 | 0 | } |
1174 | | |
1175 | 0 | if (msg_len != |
1176 | 0 | sizeof(struct nsm_msg_hdr) + |
1177 | 0 | sizeof(struct nsm_set_confidential_compute_mode_v1_req)) { |
1178 | 0 | return NSM_SW_ERROR_LENGTH; |
1179 | 0 | } |
1180 | | |
1181 | 0 | struct nsm_set_confidential_compute_mode_v1_req *request = |
1182 | 0 | (struct nsm_set_confidential_compute_mode_v1_req *)msg->payload; |
1183 | |
|
1184 | 0 | if (request->hdr.data_size != |
1185 | 0 | sizeof(struct nsm_set_confidential_compute_mode_v1_req) - |
1186 | 0 | sizeof(struct nsm_common_req)) { |
1187 | 0 | return NSM_SW_ERROR_DATA; |
1188 | 0 | } |
1189 | | |
1190 | 0 | *mode = request->mode; |
1191 | 0 | return NSM_SW_SUCCESS; |
1192 | 0 | } |
1193 | | |
1194 | | int encode_set_confidential_compute_mode_v1_resp(uint8_t instance_id, |
1195 | | uint8_t cc, |
1196 | | uint16_t reason_code, |
1197 | | struct nsm_msg *msg) |
1198 | 0 | { |
1199 | 0 | return encode_common_resp(instance_id, cc, reason_code, |
1200 | 0 | NSM_TYPE_DEVICE_CONFIGURATION, |
1201 | 0 | NSM_SET_CONFIDENTIAL_COMPUTE_MODE_V1, msg); |
1202 | 0 | } |
1203 | | |
1204 | | int decode_set_confidential_compute_mode_v1_resp(const struct nsm_msg *msg, |
1205 | | size_t msg_len, uint8_t *cc, |
1206 | | uint16_t *data_size, |
1207 | | uint16_t *reason_code) |
1208 | 0 | { |
1209 | 0 | return decode_common_resp(msg, msg_len, cc, data_size, reason_code); |
1210 | 0 | } |
1211 | | |
1212 | | // Get EGM Mode Command, NSM T5 spec |
1213 | | int encode_get_EGM_mode_req(uint8_t instance_id, struct nsm_msg *msg) |
1214 | 0 | { |
1215 | 0 | return encode_common_req(instance_id, NSM_TYPE_DEVICE_CONFIGURATION, |
1216 | 0 | NSM_GET_EGM_MODE, msg); |
1217 | 0 | } |
1218 | | |
1219 | | int decode_get_EGM_mode_req(const struct nsm_msg *msg, size_t msg_len) |
1220 | 0 | { |
1221 | 0 | return decode_common_req(msg, msg_len); |
1222 | 0 | } |
1223 | | |
1224 | | // Get EGM Mode Command, NSM T5 spec |
1225 | | int encode_get_EGM_mode_resp(uint8_t instance_id, uint8_t cc, |
1226 | | uint16_t reason_code, bitfield8_t *flags, |
1227 | | struct nsm_msg *msg) |
1228 | 0 | { |
1229 | 0 | if (msg == NULL || flags == NULL) { |
1230 | 0 | return NSM_SW_ERROR_NULL; |
1231 | 0 | } |
1232 | | |
1233 | 0 | struct nsm_header_info header = {0}; |
1234 | 0 | header.nsm_msg_type = NSM_RESPONSE; |
1235 | 0 | header.instance_id = instance_id & 0x1f; |
1236 | 0 | header.nvidia_msg_type = NSM_TYPE_DEVICE_CONFIGURATION; |
1237 | |
|
1238 | 0 | uint8_t rc = pack_nsm_header(&header, &msg->hdr); |
1239 | 0 | if (rc != NSM_SUCCESS) { |
1240 | 0 | return rc; |
1241 | 0 | } |
1242 | 0 | if (cc != NSM_SUCCESS) { |
1243 | 0 | return encode_reason_code(cc, reason_code, NSM_GET_EGM_MODE, |
1244 | 0 | msg); |
1245 | 0 | } |
1246 | | |
1247 | 0 | struct nsm_get_EGM_mode_resp *resp = |
1248 | 0 | (struct nsm_get_EGM_mode_resp *)msg->payload; |
1249 | 0 | resp->hdr.command = NSM_GET_EGM_MODE; |
1250 | 0 | resp->hdr.completion_code = cc; |
1251 | 0 | uint16_t data_size = htole16(sizeof(struct nsm_get_EGM_mode_resp) - |
1252 | 0 | sizeof(struct nsm_common_resp)); |
1253 | 0 | resp->hdr.data_size = htole16(data_size); |
1254 | 0 | memcpy(&(resp->flags), flags, data_size); |
1255 | |
|
1256 | 0 | return NSM_SW_SUCCESS; |
1257 | 0 | } |
1258 | | |
1259 | | // Get EGM Mode Command, NSM T5 spec |
1260 | | int decode_get_EGM_mode_resp(const struct nsm_msg *msg, size_t msg_len, |
1261 | | uint8_t *cc, uint16_t *data_size, |
1262 | | uint16_t *reason_code, bitfield8_t *flags) |
1263 | 0 | { |
1264 | 0 | if (msg == NULL || cc == NULL || data_size == NULL || flags == NULL) { |
1265 | 0 | return NSM_SW_ERROR_NULL; |
1266 | 0 | } |
1267 | | |
1268 | 0 | int rc = decode_reason_code_and_cc(msg, msg_len, cc, reason_code); |
1269 | 0 | if (rc != NSM_SW_SUCCESS || *cc != NSM_SUCCESS) { |
1270 | 0 | return rc; |
1271 | 0 | } |
1272 | | |
1273 | 0 | if (msg_len != (sizeof(struct nsm_msg_hdr)) + |
1274 | 0 | sizeof(struct nsm_get_EGM_mode_resp)) { |
1275 | 0 | return NSM_SW_ERROR_LENGTH; |
1276 | 0 | } |
1277 | | |
1278 | 0 | struct nsm_get_EGM_mode_resp *resp = |
1279 | 0 | (struct nsm_get_EGM_mode_resp *)msg->payload; |
1280 | |
|
1281 | 0 | if (resp->hdr.command != NSM_GET_EGM_MODE) { |
1282 | 0 | return NSM_SW_ERROR_DATA; |
1283 | 0 | } |
1284 | 0 | *data_size = le16toh(resp->hdr.data_size); |
1285 | |
|
1286 | 0 | if ((*data_size) != (sizeof(struct nsm_get_EGM_mode_resp) - |
1287 | 0 | sizeof(struct nsm_common_resp))) { |
1288 | 0 | return NSM_SW_ERROR_DATA; |
1289 | 0 | } |
1290 | 0 | memcpy(flags, &(resp->flags), sizeof(bitfield8_t)); |
1291 | |
|
1292 | 0 | return NSM_SW_SUCCESS; |
1293 | 0 | } |
1294 | | |
1295 | | // Set EGM Mode Command, NSM T5 spec |
1296 | | int encode_set_EGM_mode_req(uint8_t instance_id, uint8_t requested_mode, |
1297 | | struct nsm_msg *msg) |
1298 | 0 | { |
1299 | 0 | int rc = encode_common_req(instance_id, NSM_TYPE_DEVICE_CONFIGURATION, |
1300 | 0 | NSM_SET_EGM_MODE, msg); |
1301 | |
|
1302 | 0 | if (rc == NSM_SW_SUCCESS) { |
1303 | 0 | struct nsm_set_EGM_mode_req *request = |
1304 | 0 | (struct nsm_set_EGM_mode_req *)msg->payload; |
1305 | 0 | request->hdr.data_size = htole16(sizeof(uint8_t)); |
1306 | 0 | request->requested_mode = requested_mode; |
1307 | 0 | } |
1308 | 0 | return rc; |
1309 | 0 | } |
1310 | | |
1311 | | // Set EGM Mode Command, NSM T5 spec |
1312 | | int decode_set_EGM_mode_req(const struct nsm_msg *msg, size_t msg_len, |
1313 | | uint8_t *requested_mode) |
1314 | 0 | { |
1315 | 0 | if (msg == NULL || requested_mode == NULL) { |
1316 | 0 | return NSM_SW_ERROR_NULL; |
1317 | 0 | } |
1318 | | |
1319 | 0 | if (msg_len != |
1320 | 0 | sizeof(struct nsm_msg_hdr) + sizeof(struct nsm_set_EGM_mode_req)) { |
1321 | 0 | return NSM_SW_ERROR_LENGTH; |
1322 | 0 | } |
1323 | | |
1324 | 0 | struct nsm_set_EGM_mode_req *request = |
1325 | 0 | (struct nsm_set_EGM_mode_req *)msg->payload; |
1326 | |
|
1327 | 0 | if (request->hdr.data_size != sizeof(uint8_t)) { |
1328 | 0 | return NSM_SW_ERROR_DATA; |
1329 | 0 | } |
1330 | | |
1331 | 0 | *requested_mode = request->requested_mode; |
1332 | 0 | return NSM_SW_SUCCESS; |
1333 | 0 | } |
1334 | | |
1335 | | int encode_set_EGM_mode_resp(uint8_t instance_id, uint8_t cc, |
1336 | | uint16_t reason_code, struct nsm_msg *msg) |
1337 | 0 | { |
1338 | 0 | return encode_common_resp(instance_id, cc, reason_code, |
1339 | 0 | NSM_TYPE_DEVICE_CONFIGURATION, |
1340 | 0 | NSM_SET_EGM_MODE, msg); |
1341 | 0 | } |
1342 | | |
1343 | | int decode_set_EGM_mode_resp(const struct nsm_msg *msg, size_t msg_len, |
1344 | | uint8_t *cc, uint16_t *data_size, |
1345 | | uint16_t *reason_code) |
1346 | 0 | { |
1347 | 0 | return decode_common_resp(msg, msg_len, cc, data_size, reason_code); |
1348 | 0 | } |