Skip to contentSkip to conversation

dmaengine: dmatest: Add support for scatter-gather DMA mode

PATCH Superseded Kedareswara rao Appana 3 participants 5 messages Apr 25, 2016 – Jun 7, 2016 dmaengine

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: dmatest: Add support for scatter-gather DMA mode

This patch updates the dmatest client to support
scatter-gather dma mode.

---
 drivers/dma/dmatest.c | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)
drivers/dma/dmatest.c +36 -2
index b8576fd..6f259d8 100644
@@ -51,6 +51,14 @@ module_param(iterations, uint, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(iterations,
 		"Iterations before stopping test (default: infinite)");
 
+static unsigned int sg_sources = 1;
+module_param(sg_sources, uint, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(sg_sources,
+		"Number of scatter gather buffers (default: 1)");
+static unsigned int dmatest = 1;
+module_param(dmatest, uint, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(dmatest,
+		"dmatest 0-memcpy 1-slave_sg (default: 1)");
 static unsigned int xor_sources = 3;
 module_param(xor_sources, uint, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(xor_sources,
@@ -431,6 +439,8 @@ static int dmatest_func(void *data)
 	dev = chan->device;
 	if (thread->type == DMA_MEMCPY)
 		src_cnt = dst_cnt = 1;
+	else if (thread->type == DMA_SG)
+		src_cnt = dst_cnt = sg_sources;
 	else if (thread->type == DMA_XOR) {
 		/* force odd to ensure dst = src */
 		src_cnt = min_odd(params->xor_sources | 1, dev->max_xor);
@@ -485,6 +495,8 @@ static int dmatest_func(void *data)
 		dma_addr_t *dsts;
 		unsigned int src_off, dst_off, len;
 		u8 align = 0;
+		struct scatterlist tx_sg[src_cnt];
+		struct scatterlist rx_sg[src_cnt];
 
 		total_tests++;
 
@@ -577,10 +589,21 @@ static int dmatest_func(void *data)
 			um->bidi_cnt++;
 		}
 
+		sg_init_table(tx_sg, src_cnt);
+		sg_init_table(rx_sg, dst_cnt);
+		for (i = 0; i < src_cnt; i++) {
+			sg_dma_address(&rx_sg[i]) = srcs[i];
+			sg_dma_address(&tx_sg[i]) = dsts[i] + dst_off;
+			sg_dma_len(&tx_sg[i]) = len;
+			sg_dma_len(&rx_sg[i]) = len;
+		}
 		if (thread->type == DMA_MEMCPY)
 			tx = dev->device_prep_dma_memcpy(chan,
 							 dsts[0] + dst_off,
 							 srcs[0], len, flags);
+		else if (thread->type == DMA_SG)
+			tx = dev->device_prep_dma_sg(chan, tx_sg,
+					dst_cnt, rx_sg, src_cnt, flags);
 		else if (thread->type == DMA_XOR)
 			tx = dev->device_prep_dma_xor(chan,
 						      dsts[0] + dst_off,
@@ -748,6 +771,8 @@ static int dmatest_add_threads(struct dmatest_info *info,
 
 	if (type == DMA_MEMCPY)
 		op = "copy";
+	else if (type == DMA_SG)
+		op = "sg";
 	else if (type == DMA_XOR)
 		op = "xor";
 	else if (type == DMA_PQ)
@@ -802,8 +827,16 @@ static int dmatest_add_channel(struct dmatest_info *info,
 	INIT_LIST_HEAD(&dtc->threads);
 
 	if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
-		cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
-		thread_count += cnt > 0 ? cnt : 0;
+		if (dmatest == 0) {
+			cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
+			thread_count += cnt > 0 ? cnt : 0;
+		}
+	}
+	if (dma_has_cap(DMA_SG, dma_dev->cap_mask)) {
+		if (dmatest == 1) {
+			cnt = dmatest_add_threads(info, dtc, DMA_SG);
+			thread_count += cnt > 0 ? cnt : 0;
+		}
 	}
 	if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
 		cnt = dmatest_add_threads(info, dtc, DMA_XOR);
@@ -877,6 +910,7 @@ static void run_threaded_test(struct dmatest_info *info)
 
 	request_channels(info, DMA_MEMCPY);
 	request_channels(info, DMA_XOR);
+	request_channels(info, DMA_SG);
 	request_channels(info, DMA_PQ);
 }
 
Signature · 1 line
2.1.2
#1 lore raw

Wow. Thanks a lot !

-----Original Message-----
From: Kedareswara rao Appana [mailto:[email protected]]
Sent: Monday, April 25, 2016 11:48 AM
To: [email protected]; [email protected]; Ramon Fried <[email protected]>
Cc: [email protected]; [email protected]; Kedareswara rao Appana <[email protected]>
Subject: [PATCH] dmaengine: dmatest: Add support for scatter-gather DMA mode

This patch updates the dmatest client to support scatter-gather dma mode.

---
 drivers/dma/dmatest.c | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)
drivers/dma/dmatest.c +7 -0
@@ -51,6 +51,14 @@ module_param(iterations, uint, S_IRUGO | S_IWUSR);  MODULE_PARM_DESC(iterations,
 		"Iterations before stopping test (default: infinite)");
 
+static unsigned int sg_sources = 1;
+module_param(sg_sources, uint, S_IRUGO | S_IWUSR); 
+MODULE_PARM_DESC(sg_sources,
+		"Number of scatter gather buffers (default: 1)"); static unsigned int 
+dmatest = 1; module_param(dmatest, uint, S_IRUGO | S_IWUSR); 
+MODULE_PARM_DESC(dmatest,
+		"dmatest 0-memcpy 1-slave_sg (default: 1)");
 static unsigned int xor_sources = 3;
 module_param(xor_sources, uint, S_IRUGO | S_IWUSR);  MODULE_PARM_DESC(xor_sources, @@ -431,6 +439,8 @@ static int dmatest_func(void *data)
 	dev = chan->device;
 	if (thread->type == DMA_MEMCPY)

src_cnt = dst_cnt = 1;
+ else if (thread->type == DMA_SG)
+ src_cnt = dst_cnt = sg_sources;
else if (thread->type == DMA_XOR) {
/* force odd to ensure dst = src */
src_cnt = min_odd(params->xor_sources | 1, dev->max_xor); @@ -485,6 +495,8 @@ static int dmatest_func(void *data) dma_addr_t *dsts;
unsigned int src_off, dst_off, len;
u8 align = 0;
+ struct scatterlist tx_sg[src_cnt];
+ struct scatterlist rx_sg[src_cnt];

total_tests++;

@@ -577,10 +589,21 @@ static int dmatest_func(void *data)
um->bidi_cnt++;
}

+ sg_init_table(tx_sg, src_cnt);
+ sg_init_table(rx_sg, dst_cnt);
+ for (i = 0; i < src_cnt; i++) {
+ sg_dma_address(&rx_sg[i]) = srcs[i];
+ sg_dma_address(&tx_sg[i]) = dsts[i] + dst_off;
+ sg_dma_len(&tx_sg[i]) = len;
+ sg_dma_len(&rx_sg[i]) = len;
+ }
if (thread->type == DMA_MEMCPY)
tx = dev->device_prep_dma_memcpy(chan,
dsts[0] + dst_off, srcs[0], len, flags);
+ else if (thread->type == DMA_SG)
+ tx = dev->device_prep_dma_sg(chan, tx_sg,
+ dst_cnt, rx_sg, src_cnt, flags);
else if (thread->type == DMA_XOR)
tx = dev->device_prep_dma_xor(chan,
dsts[0] + dst_off,
@@ -748,6 +771,8 @@ static int dmatest_add_threads(struct dmatest_info *info,

if (type == DMA_MEMCPY)
op = "copy";
+ else if (type == DMA_SG)
+ op = "sg";
else if (type == DMA_XOR)
op = "xor";
else if (type == DMA_PQ)
@@ -802,8 +827,16 @@ static int dmatest_add_channel(struct dmatest_info *info,
INIT_LIST_HEAD(&dtc->threads);

if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
- cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
- thread_count += cnt > 0 ? cnt : 0;
+ if (dmatest == 0) {
+ cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
+ thread_count += cnt > 0 ? cnt : 0;
+ }
+ }
+ if (dma_has_cap(DMA_SG, dma_dev->cap_mask)) {
+ if (dmatest == 1) {
+ cnt = dmatest_add_threads(info, dtc, DMA_SG);
+ thread_count += cnt > 0 ? cnt : 0;
+ }
}
if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
cnt = dmatest_add_threads(info, dtc, DMA_XOR); @@ -877,6 +910,7 @@ static void run_threaded_test(struct dmatest_info *info)

request_channels(info, DMA_MEMCPY);
request_channels(info, DMA_XOR);
+ request_channels(info, DMA_SG);
request_channels(info, DMA_PQ);
}

--
2.1.2

#2 lore raw
Quoted 1 line · Ramon Fried

Wow. Thanks a lot !

care to give tested-by ?

Signature · 1 line
~Vinod
#3 lore raw
In reply to Kedareswara rao Appana
Quoted 13 lines · Kedareswara rao Appana

This patch updates the dmatest client to support
scatter-gather dma mode.

---
 drivers/dma/dmatest.c | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)
drivers/dma/dmatest.c +0 -0
index b8576fd..6f259d8 100644

drivers/dma/dmatest.c module_param(iterations, uint, S_IRUGO | S_IWUSR); · line 56

Quoted 6 lines
drivers/dma/dmatest.c +3 -0
@@ -51,6 +51,14 @@ module_param(iterations, uint, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(iterations,
 		"Iterations before stopping test (default: infinite)");
 
+static unsigned int sg_sources = 1;
+module_param(sg_sources, uint, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(sg_sources,

sg_buffers rather?

drivers/dma/dmatest.c module_param(iterations, uint, S_IRUGO | S_IWUSR); · line 57

Quoted 1 line
drivers/dma/dmatest.c +1 -0
+		"Number of scatter gather buffers (default: 1)");

blank line please

drivers/dma/dmatest.c module_param(iterations, uint, S_IRUGO | S_IWUSR); · line 61

Quoted 4 lines
drivers/dma/dmatest.c +4 -0
+static unsigned int dmatest = 1;
+module_param(dmatest, uint, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(dmatest,
+		"dmatest 0-memcpy 1-slave_sg (default: 1)");

dmatest? What does this mean!

Quoted 22 lines
drivers/dma/dmatest.c +4 -0
 static unsigned int xor_sources = 3;
 module_param(xor_sources, uint, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(xor_sources,
@@ -431,6 +439,8 @@ static int dmatest_func(void *data)
 	dev = chan->device;
 	if (thread->type == DMA_MEMCPY)
 		src_cnt = dst_cnt = 1;
+	else if (thread->type == DMA_SG)
+		src_cnt = dst_cnt = sg_sources;
 	else if (thread->type == DMA_XOR) {
 		/* force odd to ensure dst = src */
 		src_cnt = min_odd(params->xor_sources | 1, dev->max_xor);
@@ -485,6 +495,8 @@ static int dmatest_func(void *data)
 		dma_addr_t *dsts;
 		unsigned int src_off, dst_off, len;
 		u8 align = 0;
+		struct scatterlist tx_sg[src_cnt];
+		struct scatterlist rx_sg[src_cnt];
 
 		total_tests++;
 

drivers/dma/dmatest.c static int dmatest_func(void *data) · line 593

Quoted 5 lines
drivers/dma/dmatest.c +2 -0
@@ -577,10 +589,21 @@ static int dmatest_func(void *data)
 			um->bidi_cnt++;
 		}
 
+		sg_init_table(tx_sg, src_cnt);
+		sg_init_table(rx_sg, dst_cnt);

why dst_cnt here wheras you used src_cnt to create the list!

drivers/dma/dmatest.c static int dmatest_func(void *data) · line 606

Quoted 13 lines
drivers/dma/dmatest.c +9 -0
+		for (i = 0; i < src_cnt; i++) {
+			sg_dma_address(&rx_sg[i]) = srcs[i];
+			sg_dma_address(&tx_sg[i]) = dsts[i] + dst_off;
+			sg_dma_len(&tx_sg[i]) = len;
+			sg_dma_len(&rx_sg[i]) = len;
+		}
 		if (thread->type == DMA_MEMCPY)
 			tx = dev->device_prep_dma_memcpy(chan,
 							 dsts[0] + dst_off,
 							 srcs[0], len, flags);
+		else if (thread->type == DMA_SG)
+			tx = dev->device_prep_dma_sg(chan, tx_sg,
+					dst_cnt, rx_sg, src_cnt, flags);

again dst_cnt

Quoted 13 lines
drivers/dma/dmatest.c +2 -0
 		else if (thread->type == DMA_XOR)
 			tx = dev->device_prep_dma_xor(chan,
 						      dsts[0] + dst_off,
@@ -748,6 +771,8 @@ static int dmatest_add_threads(struct dmatest_info *info,
 
 	if (type == DMA_MEMCPY)
 		op = "copy";
+	else if (type == DMA_SG)
+		op = "sg";
 	else if (type == DMA_XOR)
 		op = "xor";
 	else if (type == DMA_PQ)

drivers/dma/dmatest.c static int dmatest_add_channel(struct dmatest_info *info, · line 834

Quoted 10 lines
drivers/dma/dmatest.c +5 -2
@@ -802,8 +827,16 @@ static int dmatest_add_channel(struct dmatest_info *info,
 	INIT_LIST_HEAD(&dtc->threads);
 
 	if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
-		cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
-		thread_count += cnt > 0 ? cnt : 0;
+		if (dmatest == 0) {
+			cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
+			thread_count += cnt > 0 ? cnt : 0;
+		}
+	}

blank line

Signature · 1 line
~Vinod
#4 lore raw

Hi Vinod,

Quoted 6 lines

drivers/dma/dmatest.c module_param(iterations, uint, S_IRUGO | S_IWUSR); · line 56

Quoted 4 lines
drivers/dma/dmatest.c +3 -0
+static unsigned int sg_sources = 1;
+module_param(sg_sources, uint, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(sg_sources,

sg_buffers rather?

Ok sure will fix...

Quoted 4 lines

drivers/dma/dmatest.c module_param(iterations, uint, S_IRUGO | S_IWUSR); · line 57

Quoted 2 lines
drivers/dma/dmatest.c +1 -0
+		"Number of scatter gather buffers (default: 1)");

blank line please

Ok

Quoted 7 lines

drivers/dma/dmatest.c module_param(iterations, uint, S_IRUGO | S_IWUSR); · line 61

Quoted 5 lines
drivers/dma/dmatest.c +4 -0
+static unsigned int dmatest = 1;
+module_param(dmatest, uint, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(dmatest,
+		"dmatest 0-memcpy 1-slave_sg (default: 1)");

dmatest? What does this mean!

To differentiate b/w the memcpy and slave_sg transfers using this dmatest Sysfs entry.

Quoted 23 lines

drivers/dma/dmatest.c static int dmatest_func(void *data) · line 446

Quoted 13 lines

static unsigned int xor_sources = 3; module_param(xor_sources, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(xor_sources, @@ -431,6 +439,8 @@ static int dmatest_func(void *data)

drivers/dma/dmatest.c +2 -0
 	dev = chan->device;
 	if (thread->type == DMA_MEMCPY)
 		src_cnt = dst_cnt = 1;
+	else if (thread->type == DMA_SG)
+		src_cnt = dst_cnt = sg_sources;
 	else if (thread->type == DMA_XOR) {
 		/* force odd to ensure dst = src */
 		src_cnt = min_odd(params->xor_sources | 1, dev->max_xor);

@@ -485,6

Quoted 9 lines

+495,8 @@ static int dmatest_func(void *data)

drivers/dma/dmatest.c +2 -0
 		dma_addr_t *dsts;
 		unsigned int src_off, dst_off, len;
 		u8 align = 0;
+		struct scatterlist tx_sg[src_cnt];
+		struct scatterlist rx_sg[src_cnt];
 
 		total_tests++;
Quoted 8 lines

drivers/dma/dmatest.c static int dmatest_func(void *data) · line 593

Quoted 6 lines
drivers/dma/dmatest.c +2 -0
@@ -577,10 +589,21 @@ static int dmatest_func(void *data)
 			um->bidi_cnt++;
 		}
 
+		sg_init_table(tx_sg, src_cnt);
+		sg_init_table(rx_sg, dst_cnt);

why dst_cnt here wheras you used src_cnt to create the list!

dst_cnt is used in prep_dma_sg will use dst_cnt to created list for rx buffers Will fix this in v2.

Quoted 16 lines
Quoted 4 lines
drivers/dma/dmatest.c +3 -0
+		for (i = 0; i < src_cnt; i++) {
+			sg_dma_address(&rx_sg[i]) = srcs[i];
+			sg_dma_address(&tx_sg[i]) = dsts[i] + dst_off;

drivers/dma/dmatest.c static int dmatest_func(void *data) · line 606

Quoted 10 lines
drivers/dma/dmatest.c +6 -0
+			sg_dma_len(&tx_sg[i]) = len;
+			sg_dma_len(&rx_sg[i]) = len;
+		}
 		if (thread->type == DMA_MEMCPY)
 			tx = dev->device_prep_dma_memcpy(chan,
 							 dsts[0] + dst_off,
 							 srcs[0], len, flags);
+		else if (thread->type == DMA_SG)
+			tx = dev->device_prep_dma_sg(chan, tx_sg,
+					dst_cnt, rx_sg, src_cnt, flags);

again dst_cnt

Will fix in v2.

Quoted 18 lines

drivers/dma/dmatest.c static int dmatest_add_channel(struct dmatest_info

Quoted 15 lines
drivers/dma/dmatest.c +2 -0
 		else if (thread->type == DMA_XOR)
 			tx = dev->device_prep_dma_xor(chan,
 						      dsts[0] + dst_off,
@@ -748,6 +771,8 @@ static int dmatest_add_threads(struct dmatest_info
 *info,
 
 	if (type == DMA_MEMCPY)
 		op = "copy";
+	else if (type == DMA_SG)
+		op = "sg";
 	else if (type == DMA_XOR)
 		op = "xor";
drivers/dma/dmatest.c +0 -0
 	else if (type == DMA_PQ)
@@ -802,8 +827,16 @@ static int dmatest_add_channel(struct dmatest_info

*info,

Quoted 2 lines
drivers/dma/dmatest.c +0 -0
 	INIT_LIST_HEAD(&dtc->threads);
 
Quoted 10 lines

drivers/dma/dmatest.c static int dmatest_add_channel(struct dmatest_info *info, · line 834

Quoted 8 lines
drivers/dma/dmatest.c +5 -2
 	if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
-		cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
-		thread_count += cnt > 0 ? cnt : 0;
+		if (dmatest == 0) {
+			cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
+			thread_count += cnt > 0 ? cnt : 0;
+		}
+	}

blank line

Ok sure will fix in v2...

Thanks,
Kedar.

Quoted 3 lines

--
~Vinod