[v6,02/13] dma/skeleton: add channel status function

Message ID 20210924102942.2878051-3-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series add test suite for DMA drivers |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Bruce Richardson Sept. 24, 2021, 10:29 a.m. UTC
  In order to avoid timing errors with the unit tests, we need to ensure
we have the vchan_status function to report when a channel is idle.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/dma/skeleton/skeleton_dmadev.c | 18 +++++++++++++++++-
 drivers/dma/skeleton/skeleton_dmadev.h |  2 +-
 2 files changed, 18 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/dma/skeleton/skeleton_dmadev.c b/drivers/dma/skeleton/skeleton_dmadev.c
index 876878bb78..ada9a3be68 100644
--- a/drivers/dma/skeleton/skeleton_dmadev.c
+++ b/drivers/dma/skeleton/skeleton_dmadev.c
@@ -80,7 +80,7 @@  cpucopy_thread(void *param)
 
 		hw->zero_req_count = 0;
 		rte_memcpy(desc->dst, desc->src, desc->len);
-		hw->completed_count++;
+		__atomic_add_fetch(&hw->completed_count, 1, __ATOMIC_RELEASE);
 		(void)rte_ring_enqueue(hw->desc_completed, (void *)desc);
 	}
 
@@ -258,6 +258,21 @@  skeldma_vchan_setup(struct rte_dma_dev *dev, uint16_t vchan,
 	return vchan_setup(hw, conf->nb_desc);
 }
 
+static int
+skeldma_vchan_status(const struct rte_dma_dev *dev,
+		uint16_t vchan, enum rte_dma_vchan_status *status)
+{
+	struct skeldma_hw *hw = dev->dev_private;
+
+	RTE_SET_USED(vchan);
+
+	*status = RTE_DMA_VCHAN_IDLE;
+	if (hw->submitted_count != __atomic_load_n(&hw->completed_count, __ATOMIC_ACQUIRE)
+			|| hw->zero_req_count == 0)
+		*status = RTE_DMA_VCHAN_ACTIVE;
+	return 0;
+}
+
 static int
 skeldma_stats_get(const struct rte_dma_dev *dev, uint16_t vchan,
 		  struct rte_dma_stats *stats, uint32_t stats_sz)
@@ -425,6 +440,7 @@  static const struct rte_dma_dev_ops skeldma_ops = {
 	.dev_close     = skeldma_close,
 
 	.vchan_setup   = skeldma_vchan_setup,
+	.vchan_status  = skeldma_vchan_status,
 
 	.stats_get     = skeldma_stats_get,
 	.stats_reset   = skeldma_stats_reset,
diff --git a/drivers/dma/skeleton/skeleton_dmadev.h b/drivers/dma/skeleton/skeleton_dmadev.h
index eaa52364bf..91eb5460fc 100644
--- a/drivers/dma/skeleton/skeleton_dmadev.h
+++ b/drivers/dma/skeleton/skeleton_dmadev.h
@@ -54,7 +54,7 @@  struct skeldma_hw {
 
 	/* Cache delimiter for cpucopy thread's operation data */
 	char cache2 __rte_cache_aligned;
-	uint32_t zero_req_count;
+	volatile uint32_t zero_req_count;
 	uint64_t completed_count;
 };