@@ -52,6 +52,9 @@ struct test_batched_req {
52
52
* @name: the name of the firmware file to look for
53
53
* @into_buf: when the into_buf is used if this is true
54
54
* 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
55
58
* @sync_direct: when the sync trigger is used if this is true
56
59
* request_firmware_direct() will be used instead.
57
60
* @send_uevent: whether or not to send a uevent for async requests
@@ -91,6 +94,9 @@ struct test_batched_req {
91
94
struct test_config {
92
95
char * name ;
93
96
bool into_buf ;
97
+ size_t buf_size ;
98
+ size_t file_offset ;
99
+ bool partial ;
94
100
bool sync_direct ;
95
101
bool send_uevent ;
96
102
u8 num_requests ;
@@ -185,6 +191,9 @@ static int __test_firmware_config_init(void)
185
191
test_fw_config -> num_requests = TEST_FIRMWARE_NUM_REQS ;
186
192
test_fw_config -> send_uevent = true;
187
193
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;
188
197
test_fw_config -> sync_direct = false;
189
198
test_fw_config -> req_firmware = request_firmware ;
190
199
test_fw_config -> test_result = 0 ;
@@ -238,28 +247,35 @@ static ssize_t config_show(struct device *dev,
238
247
dev_name (dev ));
239
248
240
249
if (test_fw_config -> name )
241
- len += scnprintf (buf + len , PAGE_SIZE - len ,
250
+ len += scnprintf (buf + len , PAGE_SIZE - len ,
242
251
"name:\t%s\n" ,
243
252
test_fw_config -> name );
244
253
else
245
- len += scnprintf (buf + len , PAGE_SIZE - len ,
254
+ len += scnprintf (buf + len , PAGE_SIZE - len ,
246
255
"name:\tEMTPY\n" );
247
256
248
- len += scnprintf (buf + len , PAGE_SIZE - len ,
257
+ len += scnprintf (buf + len , PAGE_SIZE - len ,
249
258
"num_requests:\t%u\n" , test_fw_config -> num_requests );
250
259
251
- len += scnprintf (buf + len , PAGE_SIZE - len ,
260
+ len += scnprintf (buf + len , PAGE_SIZE - len ,
252
261
"send_uevent:\t\t%s\n" ,
253
262
test_fw_config -> send_uevent ?
254
263
"FW_ACTION_HOTPLUG" :
255
264
"FW_ACTION_NOHOTPLUG" );
256
- len += scnprintf (buf + len , PAGE_SIZE - len ,
265
+ len += scnprintf (buf + len , PAGE_SIZE - len ,
257
266
"into_buf:\t\t%s\n" ,
258
267
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 ,
260
276
"sync_direct:\t\t%s\n" ,
261
277
test_fw_config -> sync_direct ? "true" : "false" );
262
- len += scnprintf (buf + len , PAGE_SIZE - len ,
278
+ len += scnprintf (buf + len , PAGE_SIZE - len ,
263
279
"read_fw_idx:\t%u\n" , test_fw_config -> read_fw_idx );
264
280
265
281
mutex_unlock (& test_fw_mutex );
@@ -317,6 +333,30 @@ static ssize_t test_dev_config_show_bool(char *buf, bool val)
317
333
return snprintf (buf , PAGE_SIZE , "%d\n" , val );
318
334
}
319
335
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
+
320
360
static ssize_t test_dev_config_show_int (char * buf , int val )
321
361
{
322
362
return snprintf (buf , PAGE_SIZE , "%d\n" , val );
@@ -402,6 +442,83 @@ static ssize_t config_into_buf_show(struct device *dev,
402
442
}
403
443
static DEVICE_ATTR_RW (config_into_buf );
404
444
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
+
405
522
static ssize_t config_sync_direct_store (struct device * dev ,
406
523
struct device_attribute * attr ,
407
524
const char * buf , size_t count )
@@ -659,11 +776,21 @@ static int test_fw_run_batch_request(void *data)
659
776
if (!test_buf )
660
777
return - ENOSPC ;
661
778
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 );
667
794
if (!req -> fw )
668
795
kfree (test_buf );
669
796
} else {
@@ -936,6 +1063,9 @@ static struct attribute *test_dev_attrs[] = {
936
1063
TEST_FW_DEV_ATTR (config_name ),
937
1064
TEST_FW_DEV_ATTR (config_num_requests ),
938
1065
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 ),
939
1069
TEST_FW_DEV_ATTR (config_sync_direct ),
940
1070
TEST_FW_DEV_ATTR (config_send_uevent ),
941
1071
TEST_FW_DEV_ATTR (config_read_fw_idx ),
0 commit comments