Skip to content

Commit 9dd3f10

Browse files
ujfalusilgirdwood
authored andcommitted
lib-manager: Add timeout handling in lib_manager_load_data_from_host()
It is better to have some sort of timeout handling while waiting for the DMA transfer of the library from host. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 6ba3436 commit 9dd3f10

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

src/library_manager/lib_manager.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,23 +444,28 @@ static int lib_manager_dma_deinit(struct lib_manager_dma_ext *dma_ext, uint32_t
444444

445445
static int lib_manager_load_data_from_host(struct lib_manager_dma_ext *dma_ext, uint32_t size)
446446
{
447+
uint64_t timeout = k_ms_to_cyc_ceil64(200);
447448
struct dma_status stat;
448449
int ret;
449450

450-
ret = dma_get_status(dma_ext->chan->dma->z_dev, dma_ext->chan->index, &stat);
451-
if (ret < 0)
452-
return ret;
451+
/* Wait till whole data acquired with timeout of 200ms */
452+
timeout += sof_cycle_get_64();
453453

454-
/* Wait till whole data acquired */
455-
while (stat.pending_length < size) {
456-
k_usleep(100);
457-
458-
ret = dma_get_status(dma_ext->chan->dma->z_dev, dma_ext->chan->index, &stat);
459-
if (ret < 0)
454+
for (;;) {
455+
ret = dma_get_status(dma_ext->chan->dma->z_dev,
456+
dma_ext->chan->index, &stat);
457+
if (ret < 0 || stat.pending_length >= size)
460458
return ret;
459+
460+
if (sof_cycle_get_64() > timeout)
461+
break;
462+
463+
k_usleep(100);
461464
}
462465

463-
return 0;
466+
tr_err(&lib_manager_tr,
467+
"lib_manager_load_data_from_host(): timeout during DMA transfer");
468+
return -ETIMEDOUT;
464469
}
465470

466471
static int lib_manager_store_data(struct lib_manager_dma_ext *dma_ext,

0 commit comments

Comments
 (0)