Skip to content

Commit 2566cbe

Browse files
damien-lemoalbjorn-helgaas
authored andcommitted
PCI: epf-test: Simplify DMA support checks
There is no need to have each read, write and copy test functions check for the FLAG_USE_DMA flag against the DMA support status indicated by epf_test->dma_supported. Move this test to the command handler function pci_epf_test_cmd_handler() to check once for all cases. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Damien Le Moal <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]>
1 parent 2eec4be commit 2566cbe

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

drivers/pci/endpoint/functions/pci-epf-test.c

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ static void pci_epf_test_copy(struct pci_epf_test *epf_test,
329329
struct pci_epf_test_reg *reg)
330330
{
331331
int ret;
332-
bool use_dma;
333332
void __iomem *src_addr;
334333
void __iomem *dst_addr;
335334
phys_addr_t src_phys_addr;
@@ -372,14 +371,7 @@ static void pci_epf_test_copy(struct pci_epf_test *epf_test,
372371
}
373372

374373
ktime_get_ts64(&start);
375-
use_dma = !!(reg->flags & FLAG_USE_DMA);
376-
if (use_dma) {
377-
if (!epf_test->dma_supported) {
378-
dev_err(dev, "Cannot transfer data using DMA\n");
379-
ret = -EINVAL;
380-
goto err_map_addr;
381-
}
382-
374+
if (reg->flags & FLAG_USE_DMA) {
383375
if (epf_test->dma_private) {
384376
dev_err(dev, "Cannot transfer data using DMA\n");
385377
ret = -EINVAL;
@@ -405,7 +397,8 @@ static void pci_epf_test_copy(struct pci_epf_test *epf_test,
405397
kfree(buf);
406398
}
407399
ktime_get_ts64(&end);
408-
pci_epf_test_print_rate("COPY", reg->size, &start, &end, use_dma);
400+
pci_epf_test_print_rate("COPY", reg->size, &start, &end,
401+
reg->flags & FLAG_USE_DMA);
409402

410403
err_map_addr:
411404
pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, dst_phys_addr);
@@ -433,7 +426,6 @@ static void pci_epf_test_read(struct pci_epf_test *epf_test,
433426
void __iomem *src_addr;
434427
void *buf;
435428
u32 crc32;
436-
bool use_dma;
437429
phys_addr_t phys_addr;
438430
phys_addr_t dst_phys_addr;
439431
struct timespec64 start, end;
@@ -464,14 +456,7 @@ static void pci_epf_test_read(struct pci_epf_test *epf_test,
464456
goto err_map_addr;
465457
}
466458

467-
use_dma = !!(reg->flags & FLAG_USE_DMA);
468-
if (use_dma) {
469-
if (!epf_test->dma_supported) {
470-
dev_err(dev, "Cannot transfer data using DMA\n");
471-
ret = -EINVAL;
472-
goto err_dma_map;
473-
}
474-
459+
if (reg->flags & FLAG_USE_DMA) {
475460
dst_phys_addr = dma_map_single(dma_dev, buf, reg->size,
476461
DMA_FROM_DEVICE);
477462
if (dma_mapping_error(dma_dev, dst_phys_addr)) {
@@ -496,7 +481,8 @@ static void pci_epf_test_read(struct pci_epf_test *epf_test,
496481
ktime_get_ts64(&end);
497482
}
498483

499-
pci_epf_test_print_rate("READ", reg->size, &start, &end, use_dma);
484+
pci_epf_test_print_rate("READ", reg->size, &start, &end,
485+
reg->flags & FLAG_USE_DMA);
500486

501487
crc32 = crc32_le(~0, buf, reg->size);
502488
if (crc32 != reg->checksum)
@@ -524,7 +510,6 @@ static void pci_epf_test_write(struct pci_epf_test *epf_test,
524510
int ret;
525511
void __iomem *dst_addr;
526512
void *buf;
527-
bool use_dma;
528513
phys_addr_t phys_addr;
529514
phys_addr_t src_phys_addr;
530515
struct timespec64 start, end;
@@ -558,14 +543,7 @@ static void pci_epf_test_write(struct pci_epf_test *epf_test,
558543
get_random_bytes(buf, reg->size);
559544
reg->checksum = crc32_le(~0, buf, reg->size);
560545

561-
use_dma = !!(reg->flags & FLAG_USE_DMA);
562-
if (use_dma) {
563-
if (!epf_test->dma_supported) {
564-
dev_err(dev, "Cannot transfer data using DMA\n");
565-
ret = -EINVAL;
566-
goto err_dma_map;
567-
}
568-
546+
if (reg->flags & FLAG_USE_DMA) {
569547
src_phys_addr = dma_map_single(dma_dev, buf, reg->size,
570548
DMA_TO_DEVICE);
571549
if (dma_mapping_error(dma_dev, src_phys_addr)) {
@@ -592,7 +570,8 @@ static void pci_epf_test_write(struct pci_epf_test *epf_test,
592570
ktime_get_ts64(&end);
593571
}
594572

595-
pci_epf_test_print_rate("WRITE", reg->size, &start, &end, use_dma);
573+
pci_epf_test_print_rate("WRITE", reg->size, &start, &end,
574+
reg->flags & FLAG_USE_DMA);
596575

597576
/*
598577
* wait 1ms inorder for the write to complete. Without this delay L3
@@ -679,6 +658,12 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
679658
WRITE_ONCE(reg->command, 0);
680659
WRITE_ONCE(reg->status, 0);
681660

661+
if ((READ_ONCE(reg->flags) & FLAG_USE_DMA) &&
662+
!epf_test->dma_supported) {
663+
dev_err(dev, "Cannot transfer data using DMA\n");
664+
goto reset_handler;
665+
}
666+
682667
if (reg->irq_type > IRQ_TYPE_MSIX) {
683668
dev_err(dev, "Failed to detect IRQ type\n");
684669
goto reset_handler;

0 commit comments

Comments
 (0)