• Home
  • Raw
  • Download

Lines Matching +full:firmware +full:- +full:name

2  * This module provides an interface to trigger and test firmware loading.
4 * It is designed to be used for basic evaluation of the firmware loading
5 * subsystem (for example when validating firmware verification). It lacks
7 * unless explicitly requested by name.
16 #include <linux/firmware.h>
26 #define TEST_FIRMWARE_NAME "test-firmware.bin"
30 static const struct firmware *test_firmware;
36 const struct firmware *fw;
37 const char *name; member
44 * test_config - represents configuration for the test for different triggers
46 * @name: the name of the firmware file to look for
53 * @read_fw_idx: index of thread from which we want to read firmware results
63 * information passed today on error is the fact that no firmware was
64 * found so we can only assume -ENOENT on async calls if the firmware is
72 * -EINVAL: invalid parameters or request
73 * -ENOENT: files not found
77 * -ENOMEM: memory pressure on system
78 * -ENODEV: out of number of devices to test
79 * -EINVAL: an unexpected error has occurred
84 char *name; member
96 int (*req_firmware)(const struct firmware **fw, const char *name,
110 test_firmware->data, in test_fw_misc_read()
111 test_firmware->size); in test_fw_misc_read()
126 if (!test_fw_config->reqs) in __test_release_all_firmware()
129 for (i = 0; i < test_fw_config->num_requests; i++) { in __test_release_all_firmware()
130 req = &test_fw_config->reqs[i]; in __test_release_all_firmware()
131 if (req->fw) in __test_release_all_firmware()
132 release_firmware(req->fw); in __test_release_all_firmware()
135 vfree(test_fw_config->reqs); in __test_release_all_firmware()
136 test_fw_config->reqs = NULL; in __test_release_all_firmware()
150 kfree_const(test_fw_config->name); in __test_firmware_config_free()
151 test_fw_config->name = NULL; in __test_firmware_config_free()
159 static int __kstrncpy(char **dst, const char *name, size_t count, gfp_t gfp) in __kstrncpy() argument
161 *dst = kstrndup(name, count, gfp); in __kstrncpy()
163 return -ENOSPC; in __kstrncpy()
171 ret = __kstrncpy(&test_fw_config->name, TEST_FIRMWARE_NAME, in __test_firmware_config_init()
176 test_fw_config->num_requests = TEST_FIRMWARE_NUM_REQS; in __test_firmware_config_init()
177 test_fw_config->send_uevent = true; in __test_firmware_config_init()
178 test_fw_config->sync_direct = false; in __test_firmware_config_init()
179 test_fw_config->req_firmware = request_firmware; in __test_firmware_config_init()
180 test_fw_config->test_result = 0; in __test_firmware_config_init()
181 test_fw_config->reqs = NULL; in __test_firmware_config_init()
202 ret = -ENOMEM; in reset_store()
226 len += scnprintf(buf, PAGE_SIZE - len, in config_show()
230 if (test_fw_config->name) in config_show()
231 len += scnprintf(buf+len, PAGE_SIZE - len, in config_show()
232 "name:\t%s\n", in config_show()
233 test_fw_config->name); in config_show()
235 len += scnprintf(buf+len, PAGE_SIZE - len, in config_show()
236 "name:\tEMTPY\n"); in config_show()
238 len += scnprintf(buf+len, PAGE_SIZE - len, in config_show()
239 "num_requests:\t%u\n", test_fw_config->num_requests); in config_show()
241 len += scnprintf(buf+len, PAGE_SIZE - len, in config_show()
243 test_fw_config->send_uevent ? in config_show()
246 len += scnprintf(buf+len, PAGE_SIZE - len, in config_show()
248 test_fw_config->sync_direct ? "true" : "false"); in config_show()
249 len += scnprintf(buf+len, PAGE_SIZE - len, in config_show()
250 "read_fw_idx:\t%u\n", test_fw_config->read_fw_idx); in config_show()
265 kfree_const(test_fw_config->name); in config_name_store()
266 ret = __kstrncpy(&test_fw_config->name, buf, count, GFP_KERNEL); in config_name_store()
294 ret = -EINVAL; in test_dev_config_update_bool()
336 return -EINVAL; in test_dev_config_update_u8()
361 return config_test_show_str(buf, test_fw_config->name); in config_name_show()
372 if (test_fw_config->reqs) { in config_num_requests_store()
374 rc = -EINVAL; in config_num_requests_store()
381 &test_fw_config->num_requests); in config_num_requests_store()
391 return test_dev_config_show_u8(buf, test_fw_config->num_requests); in config_num_requests_show()
400 &test_fw_config->sync_direct); in config_sync_direct_store()
403 test_fw_config->req_firmware = test_fw_config->sync_direct ? in config_sync_direct_store()
413 return test_dev_config_show_bool(buf, test_fw_config->sync_direct); in config_sync_direct_show()
422 &test_fw_config->send_uevent); in config_send_uevent_store()
429 return test_dev_config_show_bool(buf, test_fw_config->send_uevent); in config_send_uevent_show()
438 &test_fw_config->read_fw_idx); in config_read_fw_idx_store()
445 return test_dev_config_show_u8(buf, test_fw_config->read_fw_idx); in config_read_fw_idx_show()
455 char *name; in trigger_request_store() local
457 name = kstrndup(buf, count, GFP_KERNEL); in trigger_request_store()
458 if (!name) in trigger_request_store()
459 return -ENOSPC; in trigger_request_store()
461 pr_info("loading '%s'\n", name); in trigger_request_store()
466 rc = request_firmware(&test_firmware, name, dev); in trigger_request_store()
468 pr_info("load of '%s' failed: %d\n", name, rc); in trigger_request_store()
471 pr_info("loaded: %zu\n", test_firmware->size); in trigger_request_store()
477 kfree(name); in trigger_request_store()
485 static void trigger_async_request_cb(const struct firmware *fw, void *context) in trigger_async_request_cb()
496 char *name; in trigger_async_request_store() local
498 name = kstrndup(buf, count, GFP_KERNEL); in trigger_async_request_store()
499 if (!name) in trigger_async_request_store()
500 return -ENOSPC; in trigger_async_request_store()
502 pr_info("loading '%s'\n", name); in trigger_async_request_store()
507 rc = request_firmware_nowait(THIS_MODULE, 1, name, dev, GFP_KERNEL, in trigger_async_request_store()
510 pr_info("async load of '%s' failed: %d\n", name, rc); in trigger_async_request_store()
511 kfree(name); in trigger_async_request_store()
514 /* Free 'name' ASAP, to test for race conditions */ in trigger_async_request_store()
515 kfree(name); in trigger_async_request_store()
520 pr_info("loaded: %zu\n", test_firmware->size); in trigger_async_request_store()
523 pr_err("failed to async load firmware\n"); in trigger_async_request_store()
524 rc = -ENODEV; in trigger_async_request_store()
539 char *name; in trigger_custom_fallback_store() local
541 name = kstrndup(buf, count, GFP_KERNEL); in trigger_custom_fallback_store()
542 if (!name) in trigger_custom_fallback_store()
543 return -ENOSPC; in trigger_custom_fallback_store()
545 pr_info("loading '%s' using custom fallback mechanism\n", name); in trigger_custom_fallback_store()
550 rc = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG, name, in trigger_custom_fallback_store()
554 pr_info("async load of '%s' failed: %d\n", name, rc); in trigger_custom_fallback_store()
555 kfree(name); in trigger_custom_fallback_store()
558 /* Free 'name' ASAP, to test for race conditions */ in trigger_custom_fallback_store()
559 kfree(name); in trigger_custom_fallback_store()
564 pr_info("loaded: %zu\n", test_firmware->size); in trigger_custom_fallback_store()
567 pr_err("failed to async load firmware\n"); in trigger_custom_fallback_store()
568 rc = -ENODEV; in trigger_custom_fallback_store()
583 test_fw_config->test_result = -EINVAL; in test_fw_run_batch_request()
584 return -EINVAL; in test_fw_run_batch_request()
587 req->rc = test_fw_config->req_firmware(&req->fw, req->name, req->dev); in test_fw_run_batch_request()
588 if (req->rc) { in test_fw_run_batch_request()
590 req->idx, req->rc); in test_fw_run_batch_request()
591 if (!test_fw_config->test_result) in test_fw_run_batch_request()
592 test_fw_config->test_result = req->rc; in test_fw_run_batch_request()
593 } else if (req->fw) { in test_fw_run_batch_request()
594 req->sent = true; in test_fw_run_batch_request()
596 req->idx, req->fw->size); in test_fw_run_batch_request()
598 complete(&req->completion); in test_fw_run_batch_request()
600 req->task = NULL; in test_fw_run_batch_request()
609 * multiple cards are used and firmware loading happens outside of probe.
621 test_fw_config->reqs = in trigger_batched_requests_store()
623 test_fw_config->num_requests, 2)); in trigger_batched_requests_store()
624 if (!test_fw_config->reqs) { in trigger_batched_requests_store()
625 rc = -ENOMEM; in trigger_batched_requests_store()
629 pr_info("batched sync firmware loading '%s' %u times\n", in trigger_batched_requests_store()
630 test_fw_config->name, test_fw_config->num_requests); in trigger_batched_requests_store()
632 for (i = 0; i < test_fw_config->num_requests; i++) { in trigger_batched_requests_store()
633 req = &test_fw_config->reqs[i]; in trigger_batched_requests_store()
636 rc = -ENOMEM; in trigger_batched_requests_store()
639 req->fw = NULL; in trigger_batched_requests_store()
640 req->idx = i; in trigger_batched_requests_store()
641 req->name = test_fw_config->name; in trigger_batched_requests_store()
642 req->dev = dev; in trigger_batched_requests_store()
643 init_completion(&req->completion); in trigger_batched_requests_store()
644 req->task = kthread_run(test_fw_run_batch_request, req, in trigger_batched_requests_store()
645 "%s-%u", KBUILD_MODNAME, req->idx); in trigger_batched_requests_store()
646 if (!req->task || IS_ERR(req->task)) { in trigger_batched_requests_store()
647 pr_err("Setting up thread %u failed\n", req->idx); in trigger_batched_requests_store()
648 req->task = NULL; in trigger_batched_requests_store()
649 rc = -ENOMEM; in trigger_batched_requests_store()
660 * then we might miss on an opportunity of having a successful firmware in trigger_batched_requests_store()
665 for (i = 0; i < test_fw_config->num_requests; i++) { in trigger_batched_requests_store()
666 req = &test_fw_config->reqs[i]; in trigger_batched_requests_store()
667 if (req->task || req->sent) in trigger_batched_requests_store()
668 wait_for_completion(&req->completion); in trigger_batched_requests_store()
673 test_fw_config->test_result = rc; in trigger_batched_requests_store()
685 static void trigger_batched_cb(const struct firmware *fw, void *context) in trigger_batched_cb()
690 test_fw_config->test_result = -EINVAL; in trigger_batched_cb()
695 if (!req->idx) in trigger_batched_cb()
698 req->fw = fw; in trigger_batched_cb()
701 * Unfortunately the firmware API gives us nothing other than a null FW in trigger_batched_cb()
702 * if the firmware was not found on async requests. Best we can do is in trigger_batched_cb()
703 * just assume -ENOENT. A better API would pass the actual return in trigger_batched_cb()
706 if (!fw && !test_fw_config->test_result) in trigger_batched_cb()
707 test_fw_config->test_result = -ENOENT; in trigger_batched_cb()
709 complete(&req->completion); in trigger_batched_cb()
724 test_fw_config->reqs = in trigger_batched_requests_async_store()
726 test_fw_config->num_requests, 2)); in trigger_batched_requests_async_store()
727 if (!test_fw_config->reqs) { in trigger_batched_requests_async_store()
728 rc = -ENOMEM; in trigger_batched_requests_async_store()
733 test_fw_config->name, test_fw_config->num_requests); in trigger_batched_requests_async_store()
735 send_uevent = test_fw_config->send_uevent ? FW_ACTION_HOTPLUG : in trigger_batched_requests_async_store()
738 for (i = 0; i < test_fw_config->num_requests; i++) { in trigger_batched_requests_async_store()
739 req = &test_fw_config->reqs[i]; in trigger_batched_requests_async_store()
744 req->name = test_fw_config->name; in trigger_batched_requests_async_store()
745 req->fw = NULL; in trigger_batched_requests_async_store()
746 req->idx = i; in trigger_batched_requests_async_store()
747 init_completion(&req->completion); in trigger_batched_requests_async_store()
749 req->name, in trigger_batched_requests_async_store()
755 req->rc = rc; in trigger_batched_requests_async_store()
758 req->sent = true; in trigger_batched_requests_async_store()
769 * then we might miss on an opportunity of having a successful firmware in trigger_batched_requests_async_store()
773 for (i = 0; i < test_fw_config->num_requests; i++) { in trigger_batched_requests_async_store()
774 req = &test_fw_config->reqs[i]; in trigger_batched_requests_async_store()
775 if (req->sent) in trigger_batched_requests_async_store()
776 wait_for_completion(&req->completion); in trigger_batched_requests_async_store()
781 test_fw_config->test_result = rc; in trigger_batched_requests_async_store()
794 return test_dev_config_show_int(buf, test_fw_config->test_result); in test_result_show()
817 idx = test_fw_config->read_fw_idx; in read_firmware_show()
818 if (idx >= test_fw_config->num_requests) { in read_firmware_show()
819 rc = -ERANGE; in read_firmware_show()
823 if (!test_fw_config->reqs) { in read_firmware_show()
824 rc = -EINVAL; in read_firmware_show()
828 req = &test_fw_config->reqs[idx]; in read_firmware_show()
829 if (!req->fw) { in read_firmware_show()
830 pr_err("#%u: failed to async load firmware\n", idx); in read_firmware_show()
831 rc = -ENOENT; in read_firmware_show()
835 pr_info("#%u: loaded %zu\n", idx, req->fw->size); in read_firmware_show()
837 if (req->fw->size > PAGE_SIZE) { in read_firmware_show()
838 pr_err("Testing interface must use PAGE_SIZE firmware for now\n"); in read_firmware_show()
839 rc = -EINVAL; in read_firmware_show()
842 memcpy(buf, req->fw->data, req->fw->size); in read_firmware_show()
844 rc = req->fw->size; in read_firmware_show()
852 #define TEST_FW_DEV_ATTR(name) &dev_attr_##name.attr argument
864 /* These don't use the config at all - they could be ported! */
883 .name = "test_firmware",
894 return -ENOMEM; in test_firmware_init()
899 pr_err("could not init firmware test config: %d\n", rc); in test_firmware_init()