mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
PCI: epf-test: Simplify DMA support checks
[ Upstream commit 2566cbea69 ]
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/20230415023542.77601-13-dlemoal@kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Stable-dep-of: 235c2b197a8d ("PCI: endpoint: pci-epf-test: Fix check for DMA MEMCPY test")
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
f12f548cc4
commit
b5d46ca8bd
@@ -328,7 +328,6 @@ static void pci_epf_test_print_rate(const char *ops, u64 size,
|
|||||||
static int pci_epf_test_copy(struct pci_epf_test *epf_test)
|
static int pci_epf_test_copy(struct pci_epf_test *epf_test)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
bool use_dma;
|
|
||||||
void __iomem *src_addr;
|
void __iomem *src_addr;
|
||||||
void __iomem *dst_addr;
|
void __iomem *dst_addr;
|
||||||
phys_addr_t src_phys_addr;
|
phys_addr_t src_phys_addr;
|
||||||
@@ -373,14 +372,7 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ktime_get_ts64(&start);
|
ktime_get_ts64(&start);
|
||||||
use_dma = !!(reg->flags & FLAG_USE_DMA);
|
if (reg->flags & FLAG_USE_DMA) {
|
||||||
if (use_dma) {
|
|
||||||
if (!epf_test->dma_supported) {
|
|
||||||
dev_err(dev, "Cannot transfer data using DMA\n");
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto err_map_addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (epf_test->dma_private) {
|
if (epf_test->dma_private) {
|
||||||
dev_err(dev, "Cannot transfer data using DMA\n");
|
dev_err(dev, "Cannot transfer data using DMA\n");
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
@@ -406,7 +398,8 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test)
|
|||||||
kfree(buf);
|
kfree(buf);
|
||||||
}
|
}
|
||||||
ktime_get_ts64(&end);
|
ktime_get_ts64(&end);
|
||||||
pci_epf_test_print_rate("COPY", reg->size, &start, &end, use_dma);
|
pci_epf_test_print_rate("COPY", reg->size, &start, &end,
|
||||||
|
reg->flags & FLAG_USE_DMA);
|
||||||
|
|
||||||
err_map_addr:
|
err_map_addr:
|
||||||
pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, dst_phys_addr);
|
pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, dst_phys_addr);
|
||||||
@@ -430,7 +423,6 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test)
|
|||||||
void __iomem *src_addr;
|
void __iomem *src_addr;
|
||||||
void *buf;
|
void *buf;
|
||||||
u32 crc32;
|
u32 crc32;
|
||||||
bool use_dma;
|
|
||||||
phys_addr_t phys_addr;
|
phys_addr_t phys_addr;
|
||||||
phys_addr_t dst_phys_addr;
|
phys_addr_t dst_phys_addr;
|
||||||
struct timespec64 start, end;
|
struct timespec64 start, end;
|
||||||
@@ -463,14 +455,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test)
|
|||||||
goto err_map_addr;
|
goto err_map_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
use_dma = !!(reg->flags & FLAG_USE_DMA);
|
if (reg->flags & FLAG_USE_DMA) {
|
||||||
if (use_dma) {
|
|
||||||
if (!epf_test->dma_supported) {
|
|
||||||
dev_err(dev, "Cannot transfer data using DMA\n");
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto err_dma_map;
|
|
||||||
}
|
|
||||||
|
|
||||||
dst_phys_addr = dma_map_single(dma_dev, buf, reg->size,
|
dst_phys_addr = dma_map_single(dma_dev, buf, reg->size,
|
||||||
DMA_FROM_DEVICE);
|
DMA_FROM_DEVICE);
|
||||||
if (dma_mapping_error(dma_dev, dst_phys_addr)) {
|
if (dma_mapping_error(dma_dev, dst_phys_addr)) {
|
||||||
@@ -495,7 +480,8 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test)
|
|||||||
ktime_get_ts64(&end);
|
ktime_get_ts64(&end);
|
||||||
}
|
}
|
||||||
|
|
||||||
pci_epf_test_print_rate("READ", reg->size, &start, &end, use_dma);
|
pci_epf_test_print_rate("READ", reg->size, &start, &end,
|
||||||
|
reg->flags & FLAG_USE_DMA);
|
||||||
|
|
||||||
crc32 = crc32_le(~0, buf, reg->size);
|
crc32 = crc32_le(~0, buf, reg->size);
|
||||||
if (crc32 != reg->checksum)
|
if (crc32 != reg->checksum)
|
||||||
@@ -519,7 +505,6 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test)
|
|||||||
int ret;
|
int ret;
|
||||||
void __iomem *dst_addr;
|
void __iomem *dst_addr;
|
||||||
void *buf;
|
void *buf;
|
||||||
bool use_dma;
|
|
||||||
phys_addr_t phys_addr;
|
phys_addr_t phys_addr;
|
||||||
phys_addr_t src_phys_addr;
|
phys_addr_t src_phys_addr;
|
||||||
struct timespec64 start, end;
|
struct timespec64 start, end;
|
||||||
@@ -555,14 +540,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test)
|
|||||||
get_random_bytes(buf, reg->size);
|
get_random_bytes(buf, reg->size);
|
||||||
reg->checksum = crc32_le(~0, buf, reg->size);
|
reg->checksum = crc32_le(~0, buf, reg->size);
|
||||||
|
|
||||||
use_dma = !!(reg->flags & FLAG_USE_DMA);
|
if (reg->flags & FLAG_USE_DMA) {
|
||||||
if (use_dma) {
|
|
||||||
if (!epf_test->dma_supported) {
|
|
||||||
dev_err(dev, "Cannot transfer data using DMA\n");
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto err_dma_map;
|
|
||||||
}
|
|
||||||
|
|
||||||
src_phys_addr = dma_map_single(dma_dev, buf, reg->size,
|
src_phys_addr = dma_map_single(dma_dev, buf, reg->size,
|
||||||
DMA_TO_DEVICE);
|
DMA_TO_DEVICE);
|
||||||
if (dma_mapping_error(dma_dev, src_phys_addr)) {
|
if (dma_mapping_error(dma_dev, src_phys_addr)) {
|
||||||
@@ -589,7 +567,8 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test)
|
|||||||
ktime_get_ts64(&end);
|
ktime_get_ts64(&end);
|
||||||
}
|
}
|
||||||
|
|
||||||
pci_epf_test_print_rate("WRITE", reg->size, &start, &end, use_dma);
|
pci_epf_test_print_rate("WRITE", reg->size, &start, &end,
|
||||||
|
reg->flags & FLAG_USE_DMA);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* wait 1ms inorder for the write to complete. Without this delay L3
|
* wait 1ms inorder for the write to complete. Without this delay L3
|
||||||
@@ -660,6 +639,12 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
|
|||||||
reg->command = 0;
|
reg->command = 0;
|
||||||
reg->status = 0;
|
reg->status = 0;
|
||||||
|
|
||||||
|
if ((READ_ONCE(reg->flags) & FLAG_USE_DMA) &&
|
||||||
|
!epf_test->dma_supported) {
|
||||||
|
dev_err(dev, "Cannot transfer data using DMA\n");
|
||||||
|
goto reset_handler;
|
||||||
|
}
|
||||||
|
|
||||||
if (reg->irq_type > IRQ_TYPE_MSIX) {
|
if (reg->irq_type > IRQ_TYPE_MSIX) {
|
||||||
dev_err(dev, "Failed to detect IRQ type\n");
|
dev_err(dev, "Failed to detect IRQ type\n");
|
||||||
goto reset_handler;
|
goto reset_handler;
|
||||||
|
|||||||
Reference in New Issue
Block a user