Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * This module provides an interface to trigger and test firmware loading.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * It is designed to be used for basic evaluation of the firmware loading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * subsystem (for example when validating firmware verification). It lacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * any extra dependencies, and will not normally be loaded by the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * unless explicitly requested by name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/printk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/sizes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/efi_embedded_fw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) MODULE_IMPORT_NS(TEST_FIRMWARE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #define TEST_FIRMWARE_NAME	"test-firmware.bin"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #define TEST_FIRMWARE_NUM_REQS	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #define TEST_FIRMWARE_BUF_SIZE	SZ_1K
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) static DEFINE_MUTEX(test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) static const struct firmware *test_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) struct test_batched_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 	u8 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	bool sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	const struct firmware *fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	struct completion completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	struct task_struct *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50)  * test_config - represents configuration for the test for different triggers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52)  * @name: the name of the firmware file to look for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53)  * @into_buf: when the into_buf is used if this is true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54)  *	request_firmware_into_buf() will be used instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55)  * @buf_size: size of buf to allocate when into_buf is true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56)  * @file_offset: file offset to request when calling request_firmware_into_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57)  * @partial: partial read opt when calling request_firmware_into_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  * @sync_direct: when the sync trigger is used if this is true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)  *	request_firmware_direct() will be used instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60)  * @send_uevent: whether or not to send a uevent for async requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61)  * @num_requests: number of requests to try per test case. This is trigger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)  *	specific.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)  * @reqs: stores all requests information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  * @read_fw_idx: index of thread from which we want to read firmware results
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65)  *	from through the read_fw trigger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66)  * @test_result: a test may use this to collect the result from the call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  *	of the request_firmware*() calls used in their tests. In order of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  *	priority we always keep first any setup error. If no setup errors were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  *	found then we move on to the first error encountered while running the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  *	API. Note that for async calls this typically will be a successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  *	result (0) unless of course you've used bogus parameters, or the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  *	is out of memory.  In the async case the callback is expected to do a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)  *	bit more homework to figure out what happened, unfortunately the only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74)  *	information passed today on error is the fact that no firmware was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  *	found so we can only assume -ENOENT on async calls if the firmware is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  *	NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78)  *	Errors you can expect:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)  *	API specific:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)  *	0:		success for sync, for async it means request was sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)  *	-EINVAL:	invalid parameters or request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  *	-ENOENT:	files not found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86)  *	System environment:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88)  *	-ENOMEM:	memory pressure on system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)  *	-ENODEV:	out of number of devices to test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  *	-EINVAL:	an unexpected error has occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * @req_firmware: if @sync_direct is true this is set to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  *	request_firmware_direct(), otherwise request_firmware()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) struct test_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	bool into_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	size_t buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	size_t file_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	bool partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	bool sync_direct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	bool send_uevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	u8 num_requests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	u8 read_fw_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	 * These below don't belong her but we'll move them once we create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	 * a struct fw_test_device and stuff the misc_dev under there later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	struct test_batched_req *reqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	int test_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	int (*req_firmware)(const struct firmware **fw, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 			    struct device *device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) static struct test_config *test_fw_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) static ssize_t test_fw_misc_read(struct file *f, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 				 size_t size, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	ssize_t rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	if (test_firmware)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 		rc = simple_read_from_buffer(buf, size, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 					     test_firmware->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 					     test_firmware->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) static const struct file_operations test_fw_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	.owner          = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	.read           = test_fw_misc_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) static void __test_release_all_firmware(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	struct test_batched_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	u8 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	if (!test_fw_config->reqs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	for (i = 0; i < test_fw_config->num_requests; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		req = &test_fw_config->reqs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 		if (req->fw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 			release_firmware(req->fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	vfree(test_fw_config->reqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	test_fw_config->reqs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) static void test_release_all_firmware(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	__test_release_all_firmware();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) static void __test_firmware_config_free(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	__test_release_all_firmware();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	kfree_const(test_fw_config->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	test_fw_config->name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)  * XXX: move to kstrncpy() once merged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172)  * Users should use kfree_const() when freeing these.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) static int __kstrncpy(char **dst, const char *name, size_t count, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	*dst = kstrndup(name, count, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	if (!*dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) static int __test_firmware_config_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	ret = __kstrncpy(&test_fw_config->name, TEST_FIRMWARE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 			 strlen(TEST_FIRMWARE_NAME), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	test_fw_config->num_requests = TEST_FIRMWARE_NUM_REQS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	test_fw_config->send_uevent = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	test_fw_config->into_buf = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	test_fw_config->buf_size = TEST_FIRMWARE_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	test_fw_config->file_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	test_fw_config->partial = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	test_fw_config->sync_direct = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	test_fw_config->req_firmware = request_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	test_fw_config->test_result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	test_fw_config->reqs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	__test_firmware_config_free();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) static ssize_t reset_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 			   struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 			   const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	__test_firmware_config_free();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	ret = __test_firmware_config_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		pr_err("could not alloc settings for config trigger: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		       ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	pr_info("reset\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	ret = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) static DEVICE_ATTR_WO(reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) static ssize_t config_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 			   struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 			   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	len += scnprintf(buf, PAGE_SIZE - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 			"Custom trigger configuration for: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 			dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	if (test_fw_config->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		len += scnprintf(buf + len, PAGE_SIZE - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 				"name:\t%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 				test_fw_config->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		len += scnprintf(buf + len, PAGE_SIZE - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 				"name:\tEMTPY\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	len += scnprintf(buf + len, PAGE_SIZE - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 			"num_requests:\t%u\n", test_fw_config->num_requests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	len += scnprintf(buf + len, PAGE_SIZE - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 			"send_uevent:\t\t%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 			test_fw_config->send_uevent ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 			"FW_ACTION_HOTPLUG" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 			"FW_ACTION_NOHOTPLUG");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	len += scnprintf(buf + len, PAGE_SIZE - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 			"into_buf:\t\t%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 			test_fw_config->into_buf ? "true" : "false");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	len += scnprintf(buf + len, PAGE_SIZE - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 			"buf_size:\t%zu\n", test_fw_config->buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	len += scnprintf(buf + len, PAGE_SIZE - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 			"file_offset:\t%zu\n", test_fw_config->file_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	len += scnprintf(buf + len, PAGE_SIZE - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 			"partial:\t\t%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 			test_fw_config->partial ? "true" : "false");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	len += scnprintf(buf + len, PAGE_SIZE - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 			"sync_direct:\t\t%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			test_fw_config->sync_direct ? "true" : "false");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	len += scnprintf(buf + len, PAGE_SIZE - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 			"read_fw_idx:\t%u\n", test_fw_config->read_fw_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) static DEVICE_ATTR_RO(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) static ssize_t config_name_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 				 struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 				 const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	kfree_const(test_fw_config->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	ret = __kstrncpy(&test_fw_config->name, buf, count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302)  * As per sysfs_kf_seq_show() the buf is max PAGE_SIZE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) static ssize_t config_test_show_str(char *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 				    char *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	len = snprintf(dst, PAGE_SIZE, "%s\n", src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) static int test_dev_config_update_bool(const char *buf, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 				       bool *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	if (strtobool(buf, cfg) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		ret = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) static ssize_t test_dev_config_show_bool(char *buf, bool val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	return snprintf(buf, PAGE_SIZE, "%d\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) static int test_dev_config_update_size_t(const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 					 size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 					 size_t *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	long new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	ret = kstrtol(buf, 10, &new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	*(size_t *)cfg = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	/* Always return full write size even if we didn't consume all */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) static ssize_t test_dev_config_show_size_t(char *buf, size_t val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	return snprintf(buf, PAGE_SIZE, "%zu\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) static ssize_t test_dev_config_show_int(char *buf, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	return snprintf(buf, PAGE_SIZE, "%d\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) static int test_dev_config_update_u8(const char *buf, size_t size, u8 *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	long new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	ret = kstrtol(buf, 10, &new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	if (new > U8_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	*(u8 *)cfg = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	/* Always return full write size even if we didn't consume all */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) static ssize_t test_dev_config_show_u8(char *buf, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	return snprintf(buf, PAGE_SIZE, "%u\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) static ssize_t config_name_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 				struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 				char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	return config_test_show_str(buf, test_fw_config->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) static DEVICE_ATTR_RW(config_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) static ssize_t config_num_requests_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 					 struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 					 const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	if (test_fw_config->reqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		pr_err("Must call release_all_firmware prior to changing config\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	rc = test_dev_config_update_u8(buf, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 				       &test_fw_config->num_requests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) static ssize_t config_num_requests_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	return test_dev_config_show_u8(buf, test_fw_config->num_requests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) static DEVICE_ATTR_RW(config_num_requests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) static ssize_t config_into_buf_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 				     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 				     const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	return test_dev_config_update_bool(buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 					   count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 					   &test_fw_config->into_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) static ssize_t config_into_buf_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 				    struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 				    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	return test_dev_config_show_bool(buf, test_fw_config->into_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) static DEVICE_ATTR_RW(config_into_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) static ssize_t config_buf_size_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 				     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 				     const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	if (test_fw_config->reqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		pr_err("Must call release_all_firmware prior to changing config\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	rc = test_dev_config_update_size_t(buf, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 					   &test_fw_config->buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) static ssize_t config_buf_size_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 				    struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 				    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	return test_dev_config_show_size_t(buf, test_fw_config->buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) static DEVICE_ATTR_RW(config_buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) static ssize_t config_file_offset_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 					const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	if (test_fw_config->reqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		pr_err("Must call release_all_firmware prior to changing config\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	rc = test_dev_config_update_size_t(buf, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 					   &test_fw_config->file_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) static ssize_t config_file_offset_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 				       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 				       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	return test_dev_config_show_size_t(buf, test_fw_config->file_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) static DEVICE_ATTR_RW(config_file_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) static ssize_t config_partial_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 				    struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 				    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	return test_dev_config_update_bool(buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 					   count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 					   &test_fw_config->partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) static ssize_t config_partial_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 				   struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 				   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	return test_dev_config_show_bool(buf, test_fw_config->partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) static DEVICE_ATTR_RW(config_partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) static ssize_t config_sync_direct_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 					const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	int rc = test_dev_config_update_bool(buf, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 					     &test_fw_config->sync_direct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	if (rc == count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		test_fw_config->req_firmware = test_fw_config->sync_direct ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 				       request_firmware_direct :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 				       request_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) static ssize_t config_sync_direct_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 				       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 				       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	return test_dev_config_show_bool(buf, test_fw_config->sync_direct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) static DEVICE_ATTR_RW(config_sync_direct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) static ssize_t config_send_uevent_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 					const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	return test_dev_config_update_bool(buf, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 					   &test_fw_config->send_uevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) static ssize_t config_send_uevent_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 				       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 				       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	return test_dev_config_show_bool(buf, test_fw_config->send_uevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) static DEVICE_ATTR_RW(config_send_uevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) static ssize_t config_read_fw_idx_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 					const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	return test_dev_config_update_u8(buf, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 					 &test_fw_config->read_fw_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) static ssize_t config_read_fw_idx_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 				       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 				       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	return test_dev_config_show_u8(buf, test_fw_config->read_fw_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) static DEVICE_ATTR_RW(config_read_fw_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) static ssize_t trigger_request_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 				     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 				     const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	name = kstrndup(buf, count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	pr_info("loading '%s'\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	release_firmware(test_firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	test_firmware = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	rc = request_firmware(&test_firmware, name, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		pr_info("load of '%s' failed: %d\n", name, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	pr_info("loaded: %zu\n", test_firmware->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) static DEVICE_ATTR_WO(trigger_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) #ifdef CONFIG_EFI_EMBEDDED_FIRMWARE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) extern struct list_head efi_embedded_fw_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) extern bool efi_embedded_fw_checked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) static ssize_t trigger_request_platform_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 					      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 					      const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	static const u8 test_data[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 		0x55, 0xaa, 0x55, 0xaa, 0x01, 0x02, 0x03, 0x04,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		0x55, 0xaa, 0x55, 0xaa, 0x05, 0x06, 0x07, 0x08,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		0x55, 0xaa, 0x55, 0xaa, 0x10, 0x20, 0x30, 0x40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		0x55, 0xaa, 0x55, 0xaa, 0x50, 0x60, 0x70, 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	struct efi_embedded_fw efi_embedded_fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	const struct firmware *firmware = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	bool saved_efi_embedded_fw_checked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	name = kstrndup(buf, count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	pr_info("inserting test platform fw '%s'\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	efi_embedded_fw.name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	efi_embedded_fw.data = (void *)test_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	efi_embedded_fw.length = sizeof(test_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	list_add(&efi_embedded_fw.list, &efi_embedded_fw_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	saved_efi_embedded_fw_checked = efi_embedded_fw_checked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	efi_embedded_fw_checked = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	pr_info("loading '%s'\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	rc = firmware_request_platform(&firmware, name, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		pr_info("load of '%s' failed: %d\n", name, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	if (firmware->size != sizeof(test_data) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	    memcmp(firmware->data, test_data, sizeof(test_data)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		pr_info("firmware contents mismatch for '%s'\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	pr_info("loaded: %zu\n", firmware->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	efi_embedded_fw_checked = saved_efi_embedded_fw_checked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	release_firmware(firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	list_del(&efi_embedded_fw.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) static DEVICE_ATTR_WO(trigger_request_platform);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) static DECLARE_COMPLETION(async_fw_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) static void trigger_async_request_cb(const struct firmware *fw, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	test_firmware = fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	complete(&async_fw_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) static ssize_t trigger_async_request_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 					   struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 					   const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	name = kstrndup(buf, count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	pr_info("loading '%s'\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	release_firmware(test_firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	test_firmware = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	rc = request_firmware_nowait(THIS_MODULE, 1, name, dev, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 				     NULL, trigger_async_request_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		pr_info("async load of '%s' failed: %d\n", name, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	/* Free 'name' ASAP, to test for race conditions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	wait_for_completion(&async_fw_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	if (test_firmware) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		pr_info("loaded: %zu\n", test_firmware->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		pr_err("failed to async load firmware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) static DEVICE_ATTR_WO(trigger_async_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) static ssize_t trigger_custom_fallback_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 					     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 					     const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	name = kstrndup(buf, count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	pr_info("loading '%s' using custom fallback mechanism\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	release_firmware(test_firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	test_firmware = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	rc = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 				     dev, GFP_KERNEL, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 				     trigger_async_request_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		pr_info("async load of '%s' failed: %d\n", name, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	/* Free 'name' ASAP, to test for race conditions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	wait_for_completion(&async_fw_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	if (test_firmware) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		pr_info("loaded: %zu\n", test_firmware->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		pr_err("failed to async load firmware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) static DEVICE_ATTR_WO(trigger_custom_fallback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) static int test_fw_run_batch_request(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	struct test_batched_req *req = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		test_fw_config->test_result = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	if (test_fw_config->into_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		void *test_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		test_buf = kzalloc(TEST_FIRMWARE_BUF_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		if (!test_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 			return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		if (test_fw_config->partial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			req->rc = request_partial_firmware_into_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 						(&req->fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 						 req->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 						 req->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 						 test_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 						 test_fw_config->buf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 						 test_fw_config->file_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 			req->rc = request_firmware_into_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 						(&req->fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 						 req->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 						 req->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 						 test_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 						 test_fw_config->buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		if (!req->fw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 			kfree(test_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		req->rc = test_fw_config->req_firmware(&req->fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 						       req->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 						       req->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	if (req->rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		pr_info("#%u: batched sync load failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			req->idx, req->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		if (!test_fw_config->test_result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 			test_fw_config->test_result = req->rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	} else if (req->fw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		req->sent = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		pr_info("#%u: batched sync loaded %zu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 			req->idx, req->fw->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	complete(&req->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	req->task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820)  * We use a kthread as otherwise the kernel serializes all our sync requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821)  * and we would not be able to mimic batched requests on a sync call. Batched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822)  * requests on a sync call can for instance happen on a device driver when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823)  * multiple cards are used and firmware loading happens outside of probe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) static ssize_t trigger_batched_requests_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 					      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 					      const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	struct test_batched_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	u8 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	test_fw_config->reqs =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		vzalloc(array3_size(sizeof(struct test_batched_req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 				    test_fw_config->num_requests, 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	if (!test_fw_config->reqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	pr_info("batched sync firmware loading '%s' %u times\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		test_fw_config->name, test_fw_config->num_requests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	for (i = 0; i < test_fw_config->num_requests; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		req = &test_fw_config->reqs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		req->fw = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		req->idx = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		req->name = test_fw_config->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		req->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		init_completion(&req->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		req->task = kthread_run(test_fw_run_batch_request, req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 					     "%s-%u", KBUILD_MODNAME, req->idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		if (!req->task || IS_ERR(req->task)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 			pr_err("Setting up thread %u failed\n", req->idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 			req->task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 			goto out_bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	 * We require an explicit release to enable more time and delay of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	 * calling release_firmware() to improve our chances of forcing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	 * batched request. If we instead called release_firmware() right away
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	 * then we might miss on an opportunity of having a successful firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	 * request pass on the opportunity to be come a batched request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) out_bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	for (i = 0; i < test_fw_config->num_requests; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		req = &test_fw_config->reqs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		if (req->task || req->sent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 			wait_for_completion(&req->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	/* Override any worker error if we had a general setup error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		test_fw_config->test_result = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) static DEVICE_ATTR_WO(trigger_batched_requests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892)  * We wait for each callback to return with the lock held, no need to lock here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) static void trigger_batched_cb(const struct firmware *fw, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	struct test_batched_req *req = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		test_fw_config->test_result = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	/* forces *some* batched requests to queue up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	if (!req->idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		ssleep(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	req->fw = fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	 * Unfortunately the firmware API gives us nothing other than a null FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	 * if the firmware was not found on async requests.  Best we can do is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	 * just assume -ENOENT. A better API would pass the actual return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	 * value to the callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	if (!fw && !test_fw_config->test_result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		test_fw_config->test_result = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	complete(&req->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) ssize_t trigger_batched_requests_async_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 					     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 					     const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	struct test_batched_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	bool send_uevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	u8 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	test_fw_config->reqs =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		vzalloc(array3_size(sizeof(struct test_batched_req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 				    test_fw_config->num_requests, 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	if (!test_fw_config->reqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	pr_info("batched loading '%s' custom fallback mechanism %u times\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		test_fw_config->name, test_fw_config->num_requests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	send_uevent = test_fw_config->send_uevent ? FW_ACTION_HOTPLUG :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		FW_ACTION_NOHOTPLUG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	for (i = 0; i < test_fw_config->num_requests; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		req = &test_fw_config->reqs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		req->name = test_fw_config->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		req->fw = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		req->idx = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		init_completion(&req->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		rc = request_firmware_nowait(THIS_MODULE, send_uevent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 					     req->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 					     dev, GFP_KERNEL, req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 					     trigger_batched_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 			pr_info("#%u: batched async load failed setup: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 				i, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 			req->rc = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 			goto out_bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 			req->sent = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) out_bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	 * We require an explicit release to enable more time and delay of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	 * calling release_firmware() to improve our chances of forcing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	 * batched request. If we instead called release_firmware() right away
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	 * then we might miss on an opportunity of having a successful firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	 * request pass on the opportunity to be come a batched request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	for (i = 0; i < test_fw_config->num_requests; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		req = &test_fw_config->reqs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		if (req->sent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 			wait_for_completion(&req->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	/* Override any worker error if we had a general setup error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		test_fw_config->test_result = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) static DEVICE_ATTR_WO(trigger_batched_requests_async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) static ssize_t test_result_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 				struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 				char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	return test_dev_config_show_int(buf, test_fw_config->test_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) static DEVICE_ATTR_RO(test_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static ssize_t release_all_firmware_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 					  struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 					  const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	test_release_all_firmware();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) static DEVICE_ATTR_WO(release_all_firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) static ssize_t read_firmware_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 				  struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 				  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	struct test_batched_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	u8 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	ssize_t rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	idx = test_fw_config->read_fw_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	if (idx >= test_fw_config->num_requests) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		rc = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	if (!test_fw_config->reqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	req = &test_fw_config->reqs[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	if (!req->fw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		pr_err("#%u: failed to async load firmware\n", idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		rc = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	pr_info("#%u: loaded %zu\n", idx, req->fw->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	if (req->fw->size > PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		pr_err("Testing interface must use PAGE_SIZE firmware for now\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	memcpy(buf, req->fw->data, req->fw->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	rc = req->fw->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) static DEVICE_ATTR_RO(read_firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) #define TEST_FW_DEV_ATTR(name)          &dev_attr_##name.attr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) static struct attribute *test_dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	TEST_FW_DEV_ATTR(reset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	TEST_FW_DEV_ATTR(config),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	TEST_FW_DEV_ATTR(config_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	TEST_FW_DEV_ATTR(config_num_requests),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	TEST_FW_DEV_ATTR(config_into_buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	TEST_FW_DEV_ATTR(config_buf_size),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	TEST_FW_DEV_ATTR(config_file_offset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	TEST_FW_DEV_ATTR(config_partial),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	TEST_FW_DEV_ATTR(config_sync_direct),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	TEST_FW_DEV_ATTR(config_send_uevent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	TEST_FW_DEV_ATTR(config_read_fw_idx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	/* These don't use the config at all - they could be ported! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	TEST_FW_DEV_ATTR(trigger_request),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	TEST_FW_DEV_ATTR(trigger_async_request),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	TEST_FW_DEV_ATTR(trigger_custom_fallback),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) #ifdef CONFIG_EFI_EMBEDDED_FIRMWARE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	TEST_FW_DEV_ATTR(trigger_request_platform),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	/* These use the config and can use the test_result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	TEST_FW_DEV_ATTR(trigger_batched_requests),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	TEST_FW_DEV_ATTR(trigger_batched_requests_async),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	TEST_FW_DEV_ATTR(release_all_firmware),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	TEST_FW_DEV_ATTR(test_result),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	TEST_FW_DEV_ATTR(read_firmware),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) ATTRIBUTE_GROUPS(test_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) static struct miscdevice test_fw_misc_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	.minor          = MISC_DYNAMIC_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	.name           = "test_firmware",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	.fops           = &test_fw_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	.groups 	= test_dev_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) static int __init test_firmware_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	test_fw_config = kzalloc(sizeof(struct test_config), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	if (!test_fw_config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	rc = __test_firmware_config_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		kfree(test_fw_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		pr_err("could not init firmware test config: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	rc = misc_register(&test_fw_misc_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		kfree(test_fw_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		pr_err("could not register misc device: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	pr_warn("interface ready\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) module_init(test_firmware_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) static void __exit test_firmware_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	mutex_lock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	release_firmware(test_firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	misc_deregister(&test_fw_misc_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	__test_firmware_config_free();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	kfree(test_fw_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	mutex_unlock(&test_fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	pr_warn("removed interface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) module_exit(test_firmware_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) MODULE_AUTHOR("Kees Cook <keescook@chromium.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) MODULE_LICENSE("GPL");