@@ -52,6 +52,9 @@ struct test_batched_req {
5252 * @name: the name of the firmware file to look for
5353 * @into_buf: when the into_buf is used if this is true
5454 * request_firmware_into_buf() will be used instead.
55+ * @buf_size: size of buf to allocate when into_buf is true
56+ * @file_offset: file offset to request when calling request_firmware_into_buf
57+ * @partial: partial read opt when calling request_firmware_into_buf
5558 * @sync_direct: when the sync trigger is used if this is true
5659 * request_firmware_direct() will be used instead.
5760 * @send_uevent: whether or not to send a uevent for async requests
@@ -91,6 +94,9 @@ struct test_batched_req {
9194struct test_config {
9295 char * name ;
9396 bool into_buf ;
97+ size_t buf_size ;
98+ size_t file_offset ;
99+ bool partial ;
94100 bool sync_direct ;
95101 bool send_uevent ;
96102 u8 num_requests ;
@@ -185,6 +191,9 @@ static int __test_firmware_config_init(void)
185191 test_fw_config -> num_requests = TEST_FIRMWARE_NUM_REQS ;
186192 test_fw_config -> send_uevent = true;
187193 test_fw_config -> into_buf = false;
194+ test_fw_config -> buf_size = TEST_FIRMWARE_BUF_SIZE ;
195+ test_fw_config -> file_offset = 0 ;
196+ test_fw_config -> partial = false;
188197 test_fw_config -> sync_direct = false;
189198 test_fw_config -> req_firmware = request_firmware ;
190199 test_fw_config -> test_result = 0 ;
@@ -238,28 +247,35 @@ static ssize_t config_show(struct device *dev,
238247 dev_name (dev ));
239248
240249 if (test_fw_config -> name )
241- len += scnprintf (buf + len , PAGE_SIZE - len ,
250+ len += scnprintf (buf + len , PAGE_SIZE - len ,
242251 "name:\t%s\n" ,
243252 test_fw_config -> name );
244253 else
245- len += scnprintf (buf + len , PAGE_SIZE - len ,
254+ len += scnprintf (buf + len , PAGE_SIZE - len ,
246255 "name:\tEMTPY\n" );
247256
248- len += scnprintf (buf + len , PAGE_SIZE - len ,
257+ len += scnprintf (buf + len , PAGE_SIZE - len ,
249258 "num_requests:\t%u\n" , test_fw_config -> num_requests );
250259
251- len += scnprintf (buf + len , PAGE_SIZE - len ,
260+ len += scnprintf (buf + len , PAGE_SIZE - len ,
252261 "send_uevent:\t\t%s\n" ,
253262 test_fw_config -> send_uevent ?
254263 "FW_ACTION_HOTPLUG" :
255264 "FW_ACTION_NOHOTPLUG" );
256- len += scnprintf (buf + len , PAGE_SIZE - len ,
265+ len += scnprintf (buf + len , PAGE_SIZE - len ,
257266 "into_buf:\t\t%s\n" ,
258267 test_fw_config -> into_buf ? "true" : "false" );
259- len += scnprintf (buf + len , PAGE_SIZE - len ,
268+ len += scnprintf (buf + len , PAGE_SIZE - len ,
269+ "buf_size:\t%zu\n" , test_fw_config -> buf_size );
270+ len += scnprintf (buf + len , PAGE_SIZE - len ,
271+ "file_offset:\t%zu\n" , test_fw_config -> file_offset );
272+ len += scnprintf (buf + len , PAGE_SIZE - len ,
273+ "partial:\t\t%s\n" ,
274+ test_fw_config -> partial ? "true" : "false" );
275+ len += scnprintf (buf + len , PAGE_SIZE - len ,
260276 "sync_direct:\t\t%s\n" ,
261277 test_fw_config -> sync_direct ? "true" : "false" );
262- len += scnprintf (buf + len , PAGE_SIZE - len ,
278+ len += scnprintf (buf + len , PAGE_SIZE - len ,
263279 "read_fw_idx:\t%u\n" , test_fw_config -> read_fw_idx );
264280
265281 mutex_unlock (& test_fw_mutex );
@@ -317,6 +333,30 @@ static ssize_t test_dev_config_show_bool(char *buf, bool val)
317333 return snprintf (buf , PAGE_SIZE , "%d\n" , val );
318334}
319335
336+ static int test_dev_config_update_size_t (const char * buf ,
337+ size_t size ,
338+ size_t * cfg )
339+ {
340+ int ret ;
341+ long new ;
342+
343+ ret = kstrtol (buf , 10 , & new );
344+ if (ret )
345+ return ret ;
346+
347+ mutex_lock (& test_fw_mutex );
348+ * (size_t * )cfg = new ;
349+ mutex_unlock (& test_fw_mutex );
350+
351+ /* Always return full write size even if we didn't consume all */
352+ return size ;
353+ }
354+
355+ static ssize_t test_dev_config_show_size_t (char * buf , size_t val )
356+ {
357+ return snprintf (buf , PAGE_SIZE , "%zu\n" , val );
358+ }
359+
320360static ssize_t test_dev_config_show_int (char * buf , int val )
321361{
322362 return snprintf (buf , PAGE_SIZE , "%d\n" , val );
@@ -402,6 +442,83 @@ static ssize_t config_into_buf_show(struct device *dev,
402442}
403443static DEVICE_ATTR_RW (config_into_buf );
404444
445+ static ssize_t config_buf_size_store (struct device * dev ,
446+ struct device_attribute * attr ,
447+ const char * buf , size_t count )
448+ {
449+ int rc ;
450+
451+ mutex_lock (& test_fw_mutex );
452+ if (test_fw_config -> reqs ) {
453+ pr_err ("Must call release_all_firmware prior to changing config\n" );
454+ rc = - EINVAL ;
455+ mutex_unlock (& test_fw_mutex );
456+ goto out ;
457+ }
458+ mutex_unlock (& test_fw_mutex );
459+
460+ rc = test_dev_config_update_size_t (buf , count ,
461+ & test_fw_config -> buf_size );
462+
463+ out :
464+ return rc ;
465+ }
466+
467+ static ssize_t config_buf_size_show (struct device * dev ,
468+ struct device_attribute * attr ,
469+ char * buf )
470+ {
471+ return test_dev_config_show_size_t (buf , test_fw_config -> buf_size );
472+ }
473+ static DEVICE_ATTR_RW (config_buf_size );
474+
475+ static ssize_t config_file_offset_store (struct device * dev ,
476+ struct device_attribute * attr ,
477+ const char * buf , size_t count )
478+ {
479+ int rc ;
480+
481+ mutex_lock (& test_fw_mutex );
482+ if (test_fw_config -> reqs ) {
483+ pr_err ("Must call release_all_firmware prior to changing config\n" );
484+ rc = - EINVAL ;
485+ mutex_unlock (& test_fw_mutex );
486+ goto out ;
487+ }
488+ mutex_unlock (& test_fw_mutex );
489+
490+ rc = test_dev_config_update_size_t (buf , count ,
491+ & test_fw_config -> file_offset );
492+
493+ out :
494+ return rc ;
495+ }
496+
497+ static ssize_t config_file_offset_show (struct device * dev ,
498+ struct device_attribute * attr ,
499+ char * buf )
500+ {
501+ return test_dev_config_show_size_t (buf , test_fw_config -> file_offset );
502+ }
503+ static DEVICE_ATTR_RW (config_file_offset );
504+
505+ static ssize_t config_partial_store (struct device * dev ,
506+ struct device_attribute * attr ,
507+ const char * buf , size_t count )
508+ {
509+ return test_dev_config_update_bool (buf ,
510+ count ,
511+ & test_fw_config -> partial );
512+ }
513+
514+ static ssize_t config_partial_show (struct device * dev ,
515+ struct device_attribute * attr ,
516+ char * buf )
517+ {
518+ return test_dev_config_show_bool (buf , test_fw_config -> partial );
519+ }
520+ static DEVICE_ATTR_RW (config_partial );
521+
405522static ssize_t config_sync_direct_store (struct device * dev ,
406523 struct device_attribute * attr ,
407524 const char * buf , size_t count )
@@ -659,11 +776,21 @@ static int test_fw_run_batch_request(void *data)
659776 if (!test_buf )
660777 return - ENOSPC ;
661778
662- req -> rc = request_firmware_into_buf (& req -> fw ,
663- req -> name ,
664- req -> dev ,
665- test_buf ,
666- TEST_FIRMWARE_BUF_SIZE );
779+ if (test_fw_config -> partial )
780+ req -> rc = request_partial_firmware_into_buf
781+ (& req -> fw ,
782+ req -> name ,
783+ req -> dev ,
784+ test_buf ,
785+ test_fw_config -> buf_size ,
786+ test_fw_config -> file_offset );
787+ else
788+ req -> rc = request_firmware_into_buf
789+ (& req -> fw ,
790+ req -> name ,
791+ req -> dev ,
792+ test_buf ,
793+ test_fw_config -> buf_size );
667794 if (!req -> fw )
668795 kfree (test_buf );
669796 } else {
@@ -936,6 +1063,9 @@ static struct attribute *test_dev_attrs[] = {
9361063 TEST_FW_DEV_ATTR (config_name ),
9371064 TEST_FW_DEV_ATTR (config_num_requests ),
9381065 TEST_FW_DEV_ATTR (config_into_buf ),
1066+ TEST_FW_DEV_ATTR (config_buf_size ),
1067+ TEST_FW_DEV_ATTR (config_file_offset ),
1068+ TEST_FW_DEV_ATTR (config_partial ),
9391069 TEST_FW_DEV_ATTR (config_sync_direct ),
9401070 TEST_FW_DEV_ATTR (config_send_uevent ),
9411071 TEST_FW_DEV_ATTR (config_read_fw_idx ),
0 commit comments