Skip to content

Commit da179a7

Browse files
committed
qdl: make timeout configurable
Unify the timeout value (set default to 30000ms), propagate it through all architectural layers that use the same QDL structure, and make it configurable via a CLI parameter so it can be increased when needed. Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
1 parent 516a75f commit da179a7

File tree

6 files changed

+45
-21
lines changed

6 files changed

+45
-21
lines changed

firehose.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static int firehose_write(struct qdl_device *qdl, xmlDoc *doc)
212212
return -1;
213213
}
214214
if (vip_transfer_status_check_needed(qdl)) {
215-
ret = firehose_read(qdl, 30000, firehose_generic_parser, NULL);
215+
ret = firehose_read(qdl, qdl->timeout_ms, firehose_generic_parser, NULL);
216216
if (ret) {
217217
ux_err("VIP: sending of digest table failed\n");
218218
return -1;
@@ -430,7 +430,7 @@ static int firehose_erase(struct qdl_device *qdl, struct program *program)
430430
goto out;
431431
}
432432

433-
ret = firehose_read(qdl, 30000, firehose_generic_parser, NULL);
433+
ret = firehose_read(qdl, qdl->timeout_ms, firehose_generic_parser, NULL);
434434
if (ret)
435435
ux_err("failed to erase %s+0x%x\n", program->start_sector, program->num_sectors);
436436
else
@@ -445,7 +445,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
445445
{
446446
unsigned int num_sectors;
447447
unsigned int sector_size;
448-
unsigned int zlp_timeout = 10000;
448+
unsigned int zlp_timeout = qdl->timeout_ms;
449449
struct stat sb;
450450
size_t chunk_size;
451451
xmlNode *root;
@@ -460,13 +460,6 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
460460
size_t i;
461461
uint32_t fill_value;
462462

463-
/*
464-
* ZLP has been measured to take up to 15 seconds on SPINOR devices,
465-
* let's double it to be on the safe side...
466-
*/
467-
if (qdl->storage_type == QDL_STORAGE_SPINOR)
468-
zlp_timeout = 30000;
469-
470463
num_sectors = program->num_sectors;
471464
sector_size = program->sector_size ? : qdl->sector_size;
472465

@@ -516,7 +509,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
516509
goto out;
517510
}
518511

519-
ret = firehose_read(qdl, 10000, firehose_generic_parser, NULL);
512+
ret = firehose_read(qdl, qdl->timeout_ms, firehose_generic_parser, NULL);
520513
if (ret) {
521514
ux_err("failed to setup programming\n");
522515
goto out;
@@ -574,7 +567,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
574567
return -1;
575568
}
576569
if (vip_transfer_status_check_needed(qdl)) {
577-
ret = firehose_read(qdl, 30000, firehose_generic_parser, NULL);
570+
ret = firehose_read(qdl, qdl->timeout_ms, firehose_generic_parser, NULL);
578571
if (ret) {
579572
ux_err("VIP: sending of digest table failed\n");
580573
return -1;
@@ -587,7 +580,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
587580
n = qdl_write(qdl, buf, chunk_size * sector_size, zlp_timeout);
588581
if (n < 0) {
589582
ux_err("USB write failed for data chunk\n");
590-
ret = firehose_read(qdl, 30000, firehose_generic_parser, NULL);
583+
ret = firehose_read(qdl, qdl->timeout_ms, firehose_generic_parser, NULL);
591584
if (ret)
592585
ux_err("flashing of chunk failed\n");
593586

@@ -608,7 +601,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
608601

609602
t = time(NULL) - t0;
610603

611-
ret = firehose_read(qdl, 30000, firehose_generic_parser, NULL);
604+
ret = firehose_read(qdl, qdl->timeout_ms, firehose_generic_parser, NULL);
612605
if (ret) {
613606
ux_err("flashing of %s failed\n", program->label);
614607
} else if (t) {
@@ -671,7 +664,7 @@ static int firehose_issue_read(struct qdl_device *qdl, struct read_op *read_op,
671664
goto out;
672665
}
673666

674-
ret = firehose_read(qdl, 10000, firehose_generic_parser, NULL);
667+
ret = firehose_read(qdl, qdl->timeout_ms, firehose_generic_parser, NULL);
675668
if (ret) {
676669
if (!quiet)
677670
ux_err("failed to setup reading operation\n");
@@ -685,7 +678,7 @@ static int firehose_issue_read(struct qdl_device *qdl, struct read_op *read_op,
685678
while (left > 0 || expect_empty) {
686679
chunk_size = MIN(qdl->max_payload_size / sector_size, left);
687680

688-
n = qdl_read(qdl, buf, chunk_size * sector_size, 30000);
681+
n = qdl_read(qdl, buf, chunk_size * sector_size, qdl->timeout_ms);
689682
if (n < 0) {
690683
err(1, "failed to read");
691684
}
@@ -724,7 +717,7 @@ static int firehose_issue_read(struct qdl_device *qdl, struct read_op *read_op,
724717
ux_progress("%s", read_op->num_sectors - left, read_op->num_sectors, read_op->filename);
725718
}
726719

727-
ret = firehose_read(qdl, 10000, firehose_generic_parser, NULL);
720+
ret = firehose_read(qdl, qdl->timeout_ms, firehose_generic_parser, NULL);
728721
if (ret) {
729722
ux_err("read operation failed\n");
730723
goto out;

ks.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static void print_usage(FILE *out)
4545
" -h --help Print this usage info\n"
4646
" -p --port Sahara device node to use\n"
4747
" -s <id:file path> --sahara <id:file path> Sahara protocol file mapping\n"
48+
" -w <timeout> --timeout <timeout> Transfer timeout in ms\n"
4849
"\n"
4950
"One -p instance is required. One or more -s instances are required.\n"
5051
"\n"
@@ -59,6 +60,7 @@ int main(int argc, char **argv)
5960
bool found_mapping = false;
6061
char *dev_node = NULL;
6162
long file_id;
63+
unsigned int timeout = TRANSFER_TIMEOUT;
6264
char *colon;
6365
int opt;
6466
int ret;
@@ -69,10 +71,11 @@ int main(int argc, char **argv)
6971
{"version", no_argument, 0, 'v'},
7072
{"port", required_argument, 0, 'p'},
7173
{"sahara", required_argument, 0, 's'},
74+
{"timeout", required_argument, 0, 'w'},
7275
{0, 0, 0, 0}
7376
};
7477

75-
while ((opt = getopt_long(argc, argv, "dvp:s:h", options, NULL)) != -1) {
78+
while ((opt = getopt_long(argc, argv, "dvp:s:w:h", options, NULL)) != -1) {
7679
switch (opt) {
7780
case 'd':
7881
qdl_debug = true;
@@ -110,6 +113,9 @@ int main(int argc, char **argv)
110113

111114
printf("Created mapping ID:%ld File:%s\n", file_id, filename);
112115
break;
116+
case 'w':
117+
timeout = MAX((unsigned int)strtol(optarg, NULL, 10), TRANSFER_TIMEOUT);
118+
break;
113119
case 'h':
114120
print_usage(stdout);
115121
return 0;
@@ -134,6 +140,8 @@ int main(int argc, char **argv)
134140
return 1;
135141
}
136142

143+
qdl.timeout_ms = timeout;
144+
137145
ret = sahara_run(&qdl, mappings, false, NULL, NULL);
138146
if (ret < 0)
139147
return 1;

qdl.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ static void print_usage(FILE *out)
433433
fprintf(out, " -t, --create-digests=T\t\tGenerate table of digests in the T folder\n");
434434
fprintf(out, " -T, --slot=T\t\t\tSet slot number T for multiple storage devices\n");
435435
fprintf(out, " -D, --vip-table-path=T\t\tUse digest tables in the T folder for VIP\n");
436+
fprintf(out, " -w, --timeout=T\t\tTransfer timeout in milliseconds\n");
436437
fprintf(out, " -h, --help\t\t\tPrint this usage info\n");
437438
fprintf(out, " <program-xml>\txml file containing <program> or <erase> directives\n");
438439
fprintf(out, " <patch-xml>\txml file containing <patch> directives\n");
@@ -460,6 +461,7 @@ int main(int argc, char **argv)
460461
bool allow_fusing = false;
461462
bool allow_missing = false;
462463
long out_chunk_size = 0;
464+
unsigned int timeout = TRANSFER_TIMEOUT;
463465
unsigned int slot = UINT_MAX;
464466
struct qdl_device *qdl = NULL;
465467
enum QDL_DEVICE_TYPE qdl_dev_type = QDL_DEVICE_USB;
@@ -472,6 +474,7 @@ int main(int argc, char **argv)
472474
{"out-chunk-size", required_argument, 0, 'u' },
473475
{"serial", required_argument, 0, 'S'},
474476
{"vip-table-path", required_argument, 0, 'D'},
477+
{"timeout", required_argument, 0, 'w'},
475478
{"storage", required_argument, 0, 's'},
476479
{"allow-missing", no_argument, 0, 'f'},
477480
{"allow-fusing", no_argument, 0, 'c'},
@@ -482,7 +485,7 @@ int main(int argc, char **argv)
482485
{0, 0, 0, 0}
483486
};
484487

485-
while ((opt = getopt_long(argc, argv, "dvi:lu:S:D:s:fcnt:T:h", options, NULL)) != -1) {
488+
while ((opt = getopt_long(argc, argv, "dvi:lu:S:D:w:s:fcnt:T:h", options, NULL)) != -1) {
486489
switch (opt) {
487490
case 'd':
488491
qdl_debug = true;
@@ -513,6 +516,9 @@ int main(int argc, char **argv)
513516
case 'u':
514517
out_chunk_size = strtol(optarg, NULL, 10);
515518
break;
519+
case 'w':
520+
timeout = MAX((unsigned int)strtol(optarg, NULL, 10), 30000u);
521+
break;
516522
case 's':
517523
storage_type = decode_storage(optarg);
518524
break;
@@ -547,6 +553,7 @@ int main(int argc, char **argv)
547553
}
548554

549555
qdl->slot = slot;
556+
qdl->timeout_ms = timeout;
550557

551558
if (vip_table_path) {
552559
if (vip_generate_dir)

qdl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
_x < _y ? _x : _y; \
2121
})
2222

23+
#define MAX(x, y) ({ \
24+
__typeof__(x) _x = (x); \
25+
__typeof__(y) _y = (y); \
26+
_x > _y ? _x : _y; \
27+
})
28+
2329
#define ROUND_UP(x, a) ({ \
2430
__typeof__(x) _x = (x); \
2531
__typeof__(a) _a = (a); \
@@ -36,6 +42,8 @@
3642

3743
#define MAPPING_SZ 64
3844

45+
#define TRANSFER_TIMEOUT 30000u
46+
3947
enum QDL_DEVICE_TYPE {
4048
QDL_DEVICE_USB,
4149
QDL_DEVICE_SIM,
@@ -57,6 +65,7 @@ struct qdl_device {
5765
size_t sector_size;
5866
enum qdl_storage_type storage_type;
5967
unsigned int slot;
68+
unsigned int timeout_ms;
6069

6170
int (*open)(struct qdl_device *qdl, const char *serial);
6271
int (*read)(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout);

ramdump.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ int main(int argc, char **argv)
3232
char *ramdump_path = ".";
3333
char *filter = NULL;
3434
char *serial = NULL;
35+
unsigned int timeout = TRANSFER_TIMEOUT;
3536
int ret = 0;
3637
int opt;
3738

@@ -40,11 +41,12 @@ int main(int argc, char **argv)
4041
{"version", no_argument, 0, 'v'},
4142
{"output", required_argument, 0, 'o'},
4243
{"serial", required_argument, 0, 'S'},
44+
{"timeout", required_argument, 0, 'w'},
4345
{"help", no_argument, 0, 'h'},
4446
{0, 0, 0, 0}
4547
};
4648

47-
while ((opt = getopt_long(argc, argv, "dvo:S:h", options, NULL)) != -1) {
49+
while ((opt = getopt_long(argc, argv, "dvo:S:w:h", options, NULL)) != -1) {
4850
switch (opt) {
4951
case 'd':
5052
qdl_debug = true;
@@ -59,6 +61,9 @@ int main(int argc, char **argv)
5961
case 'S':
6062
serial = optarg;
6163
break;
64+
case 'w':
65+
timeout = MAX((unsigned int)strtol(optarg, NULL, 10), TRANSFER_TIMEOUT);
66+
break;
6267
case 'h':
6368
print_usage(stdout);
6469
return 0;
@@ -79,6 +84,8 @@ int main(int argc, char **argv)
7984
if (qdl_debug)
8085
print_version();
8186

87+
qdl->timeout_ms = timeout;
88+
8289
ret = qdl_open(qdl, serial);
8390
if (ret) {
8491
ret = 1;

sahara.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static ssize_t sahara_debug64_one(struct qdl_device *qdl,
296296
offset = 0;
297297
while (offset < remain) {
298298
buf_offset = 0;
299-
n = qdl_read(qdl, buf, DEBUG_BLOCK_SIZE, 30000);
299+
n = qdl_read(qdl, buf, DEBUG_BLOCK_SIZE, qdl->timeout_ms);
300300
if (n < 0) {
301301
warn("failed to read ramdump chunk");
302302
goto out;

0 commit comments

Comments
 (0)