Lines Matching +full:fw +full:- +full:cfg

1 // SPDX-License-Identifier: GPL-2.0-only
32 #define TEST_FIRMWARE_NAME "test-firmware.bin"
46 const struct firmware *fw; member
55 * struct test_config - represents configuration for the test for different triggers
81 * found so we can only assume -ENOENT on async calls if the firmware is
89 * -EINVAL: invalid parameters or request
90 * -ENOENT: files not found
94 * -ENOMEM: memory pressure on system
95 * -ENODEV: out of number of devices to test
96 * -EINVAL: an unexpected error has occurred
118 int (*req_firmware)(const struct firmware **fw, const char *name,
144 if (strncmp(name, tst->name, strlen(tst->name)) == 0) in upload_lookup_name()
158 test_firmware->data, in test_fw_misc_read()
159 test_firmware->size); in test_fw_misc_read()
174 if (!test_fw_config->reqs) in __test_release_all_firmware()
177 for (i = 0; i < test_fw_config->num_requests; i++) { in __test_release_all_firmware()
178 req = &test_fw_config->reqs[i]; in __test_release_all_firmware()
179 if (req->fw) { in __test_release_all_firmware()
180 if (req->fw_buf) { in __test_release_all_firmware()
181 kfree_const(req->fw_buf); in __test_release_all_firmware()
182 req->fw_buf = NULL; in __test_release_all_firmware()
184 release_firmware(req->fw); in __test_release_all_firmware()
185 req->fw = NULL; in __test_release_all_firmware()
189 vfree(test_fw_config->reqs); in __test_release_all_firmware()
190 test_fw_config->reqs = NULL; in __test_release_all_firmware()
204 kfree_const(test_fw_config->name); in __test_firmware_config_free()
205 test_fw_config->name = NULL; in __test_firmware_config_free()
217 return -ENOMEM; in __kstrncpy()
225 ret = __kstrncpy(&test_fw_config->name, TEST_FIRMWARE_NAME, in __test_firmware_config_init()
230 test_fw_config->num_requests = TEST_FIRMWARE_NUM_REQS; in __test_firmware_config_init()
231 test_fw_config->send_uevent = true; in __test_firmware_config_init()
232 test_fw_config->into_buf = false; in __test_firmware_config_init()
233 test_fw_config->buf_size = TEST_FIRMWARE_BUF_SIZE; in __test_firmware_config_init()
234 test_fw_config->file_offset = 0; in __test_firmware_config_init()
235 test_fw_config->partial = false; in __test_firmware_config_init()
236 test_fw_config->sync_direct = false; in __test_firmware_config_init()
237 test_fw_config->req_firmware = request_firmware; in __test_firmware_config_init()
238 test_fw_config->test_result = 0; in __test_firmware_config_init()
239 test_fw_config->reqs = NULL; in __test_firmware_config_init()
240 test_fw_config->upload_name = NULL; in __test_firmware_config_init()
261 ret = -ENOMEM; in reset_store()
285 len += scnprintf(buf, PAGE_SIZE - len, in config_show()
289 if (test_fw_config->name) in config_show()
290 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
292 test_fw_config->name); in config_show()
294 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
297 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
298 "num_requests:\t%u\n", test_fw_config->num_requests); in config_show()
300 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
302 test_fw_config->send_uevent ? in config_show()
305 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
307 test_fw_config->into_buf ? "true" : "false"); in config_show()
308 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
309 "buf_size:\t%zu\n", test_fw_config->buf_size); in config_show()
310 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
311 "file_offset:\t%zu\n", test_fw_config->file_offset); in config_show()
312 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
314 test_fw_config->partial ? "true" : "false"); in config_show()
315 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
317 test_fw_config->sync_direct ? "true" : "false"); in config_show()
318 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
319 "read_fw_idx:\t%u\n", test_fw_config->read_fw_idx); in config_show()
320 if (test_fw_config->upload_name) in config_show()
321 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
323 test_fw_config->upload_name); in config_show()
325 len += scnprintf(buf + len, PAGE_SIZE - len, in config_show()
341 kfree_const(test_fw_config->name); in config_name_store()
342 ret = __kstrncpy(&test_fw_config->name, buf, count, GFP_KERNEL); in config_name_store()
364 bool *cfg) in __test_dev_config_update_bool() argument
368 if (kstrtobool(buf, cfg) < 0) in __test_dev_config_update_bool()
369 ret = -EINVAL; in __test_dev_config_update_bool()
377 bool *cfg) in test_dev_config_update_bool() argument
382 ret = __test_dev_config_update_bool(buf, size, cfg); in test_dev_config_update_bool()
396 size_t *cfg) in __test_dev_config_update_size_t() argument
405 *(size_t *)cfg = new; in __test_dev_config_update_size_t()
421 static int __test_dev_config_update_u8(const char *buf, size_t size, u8 *cfg) in __test_dev_config_update_u8() argument
430 *(u8 *)cfg = val; in __test_dev_config_update_u8()
436 static int test_dev_config_update_u8(const char *buf, size_t size, u8 *cfg) in test_dev_config_update_u8() argument
441 ret = __test_dev_config_update_u8(buf, size, cfg); in test_dev_config_update_u8()
456 return config_test_show_str(buf, test_fw_config->name); in config_name_show()
470 test_fw_config->upload_name = tst->name; in config_upload_name_store()
472 ret = -EINVAL; in config_upload_name_store()
482 return config_test_show_str(buf, test_fw_config->upload_name); in config_upload_name_show()
493 if (test_fw_config->reqs) { in config_num_requests_store()
495 rc = -EINVAL; in config_num_requests_store()
501 &test_fw_config->num_requests); in config_num_requests_store()
512 return test_dev_config_show_u8(buf, test_fw_config->num_requests); in config_num_requests_show()
522 &test_fw_config->into_buf); in config_into_buf_store()
529 return test_dev_config_show_bool(buf, test_fw_config->into_buf); in config_into_buf_show()
540 if (test_fw_config->reqs) { in config_buf_size_store()
542 rc = -EINVAL; in config_buf_size_store()
548 &test_fw_config->buf_size); in config_buf_size_store()
559 return test_dev_config_show_size_t(buf, test_fw_config->buf_size); in config_buf_size_show()
570 if (test_fw_config->reqs) { in config_file_offset_store()
572 rc = -EINVAL; in config_file_offset_store()
578 &test_fw_config->file_offset); in config_file_offset_store()
589 return test_dev_config_show_size_t(buf, test_fw_config->file_offset); in config_file_offset_show()
599 &test_fw_config->partial); in config_partial_store()
606 return test_dev_config_show_bool(buf, test_fw_config->partial); in config_partial_show()
615 &test_fw_config->sync_direct); in config_sync_direct_store()
618 test_fw_config->req_firmware = test_fw_config->sync_direct ? in config_sync_direct_store()
628 return test_dev_config_show_bool(buf, test_fw_config->sync_direct); in config_sync_direct_show()
637 &test_fw_config->send_uevent); in config_send_uevent_store()
644 return test_dev_config_show_bool(buf, test_fw_config->send_uevent); in config_send_uevent_show()
653 &test_fw_config->read_fw_idx); in config_read_fw_idx_store()
660 return test_dev_config_show_u8(buf, test_fw_config->read_fw_idx); in config_read_fw_idx_show()
674 return -ENOMEM; in trigger_request_store()
680 if (test_fw_config->reqs) in trigger_request_store()
688 pr_info("loaded: %zu\n", test_firmware->size); in trigger_request_store()
722 return -ENOMEM; in trigger_request_platform_store()
724 pr_info("inserting test platform fw '%s'\n", name); in trigger_request_platform_store()
738 if (firmware->size != sizeof(test_data) || in trigger_request_platform_store()
739 memcmp(firmware->data, test_data, sizeof(test_data)) != 0) { in trigger_request_platform_store()
741 rc = -EINVAL; in trigger_request_platform_store()
744 pr_info("loaded: %zu\n", firmware->size); in trigger_request_platform_store()
760 static void trigger_async_request_cb(const struct firmware *fw, void *context) in trigger_async_request_cb() argument
762 test_firmware = fw; in trigger_async_request_cb()
775 return -ENOMEM; in trigger_async_request_store()
782 if (test_fw_config->reqs) in trigger_async_request_store()
797 pr_info("loaded: %zu\n", test_firmware->size); in trigger_async_request_store()
801 rc = -ENOMEM; in trigger_async_request_store()
820 return -ENOMEM; in trigger_custom_fallback_store()
826 if (test_fw_config->reqs) in trigger_custom_fallback_store()
843 pr_info("loaded: %zu\n", test_firmware->size); in trigger_custom_fallback_store()
847 rc = -ENODEV; in trigger_custom_fallback_store()
862 test_fw_config->test_result = -EINVAL; in test_fw_run_batch_request()
863 return -EINVAL; in test_fw_run_batch_request()
866 if (test_fw_config->into_buf) { in test_fw_run_batch_request()
871 return -ENOMEM; in test_fw_run_batch_request()
873 if (test_fw_config->partial) in test_fw_run_batch_request()
874 req->rc = request_partial_firmware_into_buf in test_fw_run_batch_request()
875 (&req->fw, in test_fw_run_batch_request()
876 req->name, in test_fw_run_batch_request()
877 req->dev, in test_fw_run_batch_request()
879 test_fw_config->buf_size, in test_fw_run_batch_request()
880 test_fw_config->file_offset); in test_fw_run_batch_request()
882 req->rc = request_firmware_into_buf in test_fw_run_batch_request()
883 (&req->fw, in test_fw_run_batch_request()
884 req->name, in test_fw_run_batch_request()
885 req->dev, in test_fw_run_batch_request()
887 test_fw_config->buf_size); in test_fw_run_batch_request()
888 if (!req->fw) in test_fw_run_batch_request()
891 req->fw_buf = test_buf; in test_fw_run_batch_request()
893 req->rc = test_fw_config->req_firmware(&req->fw, in test_fw_run_batch_request()
894 req->name, in test_fw_run_batch_request()
895 req->dev); in test_fw_run_batch_request()
898 if (req->rc) { in test_fw_run_batch_request()
900 req->idx, req->rc); in test_fw_run_batch_request()
901 if (!test_fw_config->test_result) in test_fw_run_batch_request()
902 test_fw_config->test_result = req->rc; in test_fw_run_batch_request()
903 } else if (req->fw) { in test_fw_run_batch_request()
904 req->sent = true; in test_fw_run_batch_request()
906 req->idx, req->fw->size); in test_fw_run_batch_request()
908 complete(&req->completion); in test_fw_run_batch_request()
910 req->task = NULL; in test_fw_run_batch_request()
931 if (test_fw_config->reqs) { in trigger_batched_requests_store()
932 rc = -EBUSY; in trigger_batched_requests_store()
936 test_fw_config->reqs = in trigger_batched_requests_store()
938 test_fw_config->num_requests, 2)); in trigger_batched_requests_store()
939 if (!test_fw_config->reqs) { in trigger_batched_requests_store()
940 rc = -ENOMEM; in trigger_batched_requests_store()
945 test_fw_config->name, test_fw_config->num_requests); in trigger_batched_requests_store()
947 for (i = 0; i < test_fw_config->num_requests; i++) { in trigger_batched_requests_store()
948 req = &test_fw_config->reqs[i]; in trigger_batched_requests_store()
949 req->fw = NULL; in trigger_batched_requests_store()
950 req->idx = i; in trigger_batched_requests_store()
951 req->name = test_fw_config->name; in trigger_batched_requests_store()
952 req->fw_buf = NULL; in trigger_batched_requests_store()
953 req->dev = dev; in trigger_batched_requests_store()
954 init_completion(&req->completion); in trigger_batched_requests_store()
955 req->task = kthread_run(test_fw_run_batch_request, req, in trigger_batched_requests_store()
956 "%s-%u", KBUILD_MODNAME, req->idx); in trigger_batched_requests_store()
957 if (!req->task || IS_ERR(req->task)) { in trigger_batched_requests_store()
958 pr_err("Setting up thread %u failed\n", req->idx); in trigger_batched_requests_store()
959 req->task = NULL; in trigger_batched_requests_store()
960 rc = -ENOMEM; in trigger_batched_requests_store()
976 for (i = 0; i < test_fw_config->num_requests; i++) { in trigger_batched_requests_store()
977 req = &test_fw_config->reqs[i]; in trigger_batched_requests_store()
978 if (req->task || req->sent) in trigger_batched_requests_store()
979 wait_for_completion(&req->completion); in trigger_batched_requests_store()
984 test_fw_config->test_result = rc; in trigger_batched_requests_store()
996 static void trigger_batched_cb(const struct firmware *fw, void *context) in trigger_batched_cb() argument
1001 test_fw_config->test_result = -EINVAL; in trigger_batched_cb()
1006 if (!req->idx) in trigger_batched_cb()
1009 req->fw = fw; in trigger_batched_cb()
1012 * Unfortunately the firmware API gives us nothing other than a null FW in trigger_batched_cb()
1014 * just assume -ENOENT. A better API would pass the actual return in trigger_batched_cb()
1017 if (!fw && !test_fw_config->test_result) in trigger_batched_cb()
1018 test_fw_config->test_result = -ENOENT; in trigger_batched_cb()
1020 complete(&req->completion); in trigger_batched_cb()
1035 if (test_fw_config->reqs) { in trigger_batched_requests_async_store()
1036 rc = -EBUSY; in trigger_batched_requests_async_store()
1040 test_fw_config->reqs = in trigger_batched_requests_async_store()
1042 test_fw_config->num_requests, 2)); in trigger_batched_requests_async_store()
1043 if (!test_fw_config->reqs) { in trigger_batched_requests_async_store()
1044 rc = -ENOMEM; in trigger_batched_requests_async_store()
1049 test_fw_config->name, test_fw_config->num_requests); in trigger_batched_requests_async_store()
1051 send_uevent = test_fw_config->send_uevent ? FW_ACTION_UEVENT : in trigger_batched_requests_async_store()
1054 for (i = 0; i < test_fw_config->num_requests; i++) { in trigger_batched_requests_async_store()
1055 req = &test_fw_config->reqs[i]; in trigger_batched_requests_async_store()
1056 req->name = test_fw_config->name; in trigger_batched_requests_async_store()
1057 req->fw_buf = NULL; in trigger_batched_requests_async_store()
1058 req->fw = NULL; in trigger_batched_requests_async_store()
1059 req->idx = i; in trigger_batched_requests_async_store()
1060 init_completion(&req->completion); in trigger_batched_requests_async_store()
1062 req->name, in trigger_batched_requests_async_store()
1068 req->rc = rc; in trigger_batched_requests_async_store()
1071 req->sent = true; in trigger_batched_requests_async_store()
1086 for (i = 0; i < test_fw_config->num_requests; i++) { in trigger_batched_requests_async_store()
1087 req = &test_fw_config->reqs[i]; in trigger_batched_requests_async_store()
1088 if (req->sent) in trigger_batched_requests_async_store()
1089 wait_for_completion(&req->completion); in trigger_batched_requests_async_store()
1094 test_fw_config->test_result = rc; in trigger_batched_requests_async_store()
1105 firmware_upload_unregister(tst->fwl); in upload_release()
1106 kfree(tst->buf); in upload_release()
1107 kfree(tst->name); in upload_release()
1116 list_del(&tst->node); in upload_release_all()
1119 test_fw_config->upload_name = NULL; in upload_release_all()
1128 [FW_UPLOAD_ERR_HW_ERROR] = "hw-error",
1130 [FW_UPLOAD_ERR_CANCELED] = "user-abort",
1131 [FW_UPLOAD_ERR_BUSY] = "device-busy",
1132 [FW_UPLOAD_ERR_INVALID_SIZE] = "invalid-file-size",
1133 [FW_UPLOAD_ERR_RW_ERROR] = "read-write-error",
1134 [FW_UPLOAD_ERR_WEAROUT] = "flash-wearout",
1135 [FW_UPLOAD_ERR_FW_INVALID] = "firmware-invalid",
1146 tst->inject.prog = prog; in upload_err_inject_error()
1147 tst->inject.err_code = err; in upload_err_inject_error()
1178 if (tst->cancel_request) in fw_upload_wait_on_cancel()
1187 struct test_firmware_upload *tst = fwl->dd_handle; in test_fw_upload_prepare()
1191 tst->cancel_request = false; in test_fw_upload_prepare()
1201 memset(tst->buf, 0, TEST_UPLOAD_MAX_SIZE); in test_fw_upload_prepare()
1202 tst->size = size; in test_fw_upload_prepare()
1204 if (tst->inject.err_code == FW_UPLOAD_ERR_NONE || in test_fw_upload_prepare()
1205 strncmp(tst->inject.prog, progress, strlen(progress)) != 0) in test_fw_upload_prepare()
1208 if (tst->inject.err_code == FW_UPLOAD_ERR_CANCELED) in test_fw_upload_prepare()
1211 ret = tst->inject.err_code; in test_fw_upload_prepare()
1216 * If the prepare op fails, it must do it's own clean-up. in test_fw_upload_prepare()
1218 tst->inject.err_code = FW_UPLOAD_ERR_NONE; in test_fw_upload_prepare()
1219 tst->inject.prog = NULL; in test_fw_upload_prepare()
1228 struct test_firmware_upload *tst = fwl->dd_handle; in test_fw_upload_write()
1232 if (tst->cancel_request) in test_fw_upload_write()
1236 memcpy(tst->buf + offset, data + offset, blk_size); in test_fw_upload_write()
1240 if (tst->inject.err_code == FW_UPLOAD_ERR_NONE || in test_fw_upload_write()
1241 strncmp(tst->inject.prog, progress, strlen(progress)) != 0) in test_fw_upload_write()
1244 if (tst->inject.err_code == FW_UPLOAD_ERR_CANCELED) in test_fw_upload_write()
1247 return tst->inject.err_code; in test_fw_upload_write()
1252 struct test_firmware_upload *tst = fwl->dd_handle; in test_fw_upload_complete()
1255 if (tst->cancel_request) in test_fw_upload_complete()
1258 if (tst->inject.err_code == FW_UPLOAD_ERR_NONE || in test_fw_upload_complete()
1259 strncmp(tst->inject.prog, progress, strlen(progress)) != 0) in test_fw_upload_complete()
1262 if (tst->inject.err_code == FW_UPLOAD_ERR_CANCELED) in test_fw_upload_complete()
1265 return tst->inject.err_code; in test_fw_upload_complete()
1270 struct test_firmware_upload *tst = fwl->dd_handle; in test_fw_upload_cancel()
1272 tst->cancel_request = true; in test_fw_upload_cancel()
1277 struct test_firmware_upload *tst = fwl->dd_handle; in test_fw_cleanup()
1279 tst->inject.err_code = FW_UPLOAD_ERR_NONE; in test_fw_cleanup()
1280 tst->inject.prog = NULL; in test_fw_cleanup()
1302 return -ENOMEM; in upload_register_store()
1307 ret = -EEXIST; in upload_register_store()
1313 ret = -ENOMEM; in upload_register_store()
1317 tst->name = name; in upload_register_store()
1318 tst->buf = kzalloc(TEST_UPLOAD_MAX_SIZE, GFP_KERNEL); in upload_register_store()
1319 if (!tst->buf) { in upload_register_store()
1320 ret = -ENOMEM; in upload_register_store()
1324 fwl = firmware_upload_register(THIS_MODULE, dev, tst->name, in upload_register_store()
1331 tst->fwl = fwl; in upload_register_store()
1332 list_add_tail(&tst->node, &test_upload_list); in upload_register_store()
1337 kfree(tst->buf); in upload_register_store()
1360 ret = -EINVAL; in upload_unregister_store()
1364 if (test_fw_config->upload_name == tst->name) in upload_unregister_store()
1365 test_fw_config->upload_name = NULL; in upload_unregister_store()
1367 list_del(&tst->node); in upload_unregister_store()
1380 return test_dev_config_show_int(buf, test_fw_config->test_result); in test_result_show()
1403 idx = test_fw_config->read_fw_idx; in read_firmware_show()
1404 if (idx >= test_fw_config->num_requests) { in read_firmware_show()
1405 rc = -ERANGE; in read_firmware_show()
1409 if (!test_fw_config->reqs) { in read_firmware_show()
1410 rc = -EINVAL; in read_firmware_show()
1414 req = &test_fw_config->reqs[idx]; in read_firmware_show()
1415 if (!req->fw) { in read_firmware_show()
1417 rc = -ENOENT; in read_firmware_show()
1421 pr_info("#%u: loaded %zu\n", idx, req->fw->size); in read_firmware_show()
1423 if (req->fw->size > PAGE_SIZE) { in read_firmware_show()
1425 rc = -EINVAL; in read_firmware_show()
1428 memcpy(buf, req->fw->data, req->fw->size); in read_firmware_show()
1430 rc = req->fw->size; in read_firmware_show()
1444 int ret = -EINVAL; in upload_read_show()
1446 if (!test_fw_config->upload_name) { in upload_read_show()
1448 return -EINVAL; in upload_read_show()
1453 if (tst_iter->name == test_fw_config->upload_name) { in upload_read_show()
1460 test_fw_config->upload_name); in upload_read_show()
1464 if (tst->size > PAGE_SIZE) { in upload_read_show()
1469 memcpy(buf, tst->buf, tst->size); in upload_read_show()
1470 ret = tst->size; in upload_read_show()
1494 /* These don't use the config at all - they could be ported! */
1530 return -ENOMEM; in test_firmware_init()