All of lore.kernel.org
 help / color / mirror / Atom feed
From: stillcompiling@gmail.com (Joshua Clayton)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 08/10] dma: imx-sdma: extract common sdma prep code
Date: Mon, 15 Jun 2015 09:19:03 -0700	[thread overview]
Message-ID: <1434385144-4432-9-git-send-email-stillcompiling@gmail.com> (raw)
In-Reply-To: <1434385144-4432-1-git-send-email-stillcompiling@gmail.com>

Extract the code that is equivalent between
the slave and cyclic sdma functions.
Add some better errors for failure conditions.

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
---
 drivers/dma/imx-sdma.c | 76 +++++++++++++++++++++-----------------------------
 1 file changed, 32 insertions(+), 44 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index c9badd4..4d447be 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -1018,6 +1018,34 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan)
 	return 0;
 }
 
+int sdma_prep_common(struct sdma_channel *sdmac, int buf_count,
+			enum dma_transfer_direction direction)
+{
+	struct sdma_engine *sdma = to_sdma_engine(sdmac);
+
+	if (sdmac->status == DMA_IN_PROGRESS) {
+		dev_err(sdma->dev, "SDMA channel %d: dma already in progress\n",
+				sdmac->channel);
+		return -EBUSY;
+	}
+
+	sdmac->status = DMA_IN_PROGRESS;
+	sdmac->buf_tail = 0;
+	sdmac->direction = direction;
+
+	dev_dbg(sdma->dev, "setting up %d entries for channel %d.\n",
+			buf_count, sdmac->channel);
+
+	if (buf_count > NUM_BD) {
+		dev_err(sdma->dev, "SDMA channel %d: maximum number of buffers exceeded: %d > %d\n",
+				sdmac->channel, buf_count, NUM_BD);
+		return -EINVAL;
+	}
+	sdmac->num_bd = buf_count;
+
+	return sdma_load_context(sdmac);
+}
+
 static void sdma_free_chan_resources(struct dma_chan *chan)
 {
 	struct sdma_channel *sdmac = to_sdma_chan(chan);
@@ -1053,28 +1081,12 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
 	int channel = sdmac->channel;
 	struct scatterlist *sg;
 
-	if (sdmac->status == DMA_IN_PROGRESS)
-		return NULL;
-	sdmac->status = DMA_IN_PROGRESS;
-
-	sdmac->flags = 0;
-
-	sdmac->buf_tail = 0;
-
-	dev_dbg(sdma->dev, "setting up %d entries for channel %d.\n",
-			sg_len, channel);
-
-	sdmac->direction = direction;
-	ret = sdma_load_context(sdmac);
+	ret = sdma_prep_common(sdmac, sg_len, direction);
 	if (ret)
 		goto err_out;
 
-	if (sg_len > NUM_BD) {
-		dev_err(sdma->dev, "SDMA channel %d: maximum number of sg exceeded: %d > %d\n",
-				channel, sg_len, NUM_BD);
-		ret = -EINVAL;
-		goto err_out;
-	}
+	sdmac->flags = 0;
+
 
 	sdmac->chn_count = 0;
 	for_each_sg(sgl, sg, sg_len, i) {
@@ -1129,7 +1141,6 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
 		bd->mode.status = param;
 	}
 
-	sdmac->num_bd = sg_len;
 	sdma->channel_control[channel].current_bd_ptr = sdmac->bd_phys;
 
 	return &sdmac->desc;
@@ -1149,33 +1160,11 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic(
 	int channel = sdmac->channel;
 	int ret, i = 0, buf = 0;
 
-	dev_dbg(sdma->dev, "%s channel: %d\n", __func__, channel);
-
-	if (sdmac->status == DMA_IN_PROGRESS)
-		return NULL;
-
-	sdmac->status = DMA_IN_PROGRESS;
+	sdma_prep_common(sdmac, buf_len / period_len, direction);
 
-	sdmac->buf_tail = 0;
 	sdmac->period_len = period_len;
 
 	sdmac->flags |= IMX_DMA_SG_LOOP;
-	sdmac->direction = direction;
-	ret = sdma_load_context(sdmac);
-	if (ret)
-		goto err_out;
-
-	if (num_periods > NUM_BD) {
-		dev_err(sdma->dev, "SDMA channel %d: maximum number of sg exceeded: %d > %d\n",
-				channel, num_periods, NUM_BD);
-		goto err_out;
-	}
-
-	if (period_len > 0xffff) {
-		dev_err(sdma->dev, "SDMA channel %d: maximum period size exceeded: %d > %d\n",
-				channel, period_len, 0xffff);
-		goto err_out;
-	}
 
 	while (buf < buf_len) {
 		struct sdma_buffer_descriptor *bd = &sdmac->bd[i];
@@ -1207,7 +1196,6 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic(
 		i++;
 	}
 
-	sdmac->num_bd = num_periods;
 	sdma->channel_control[channel].current_bd_ptr = sdmac->bd_phys;
 
 	return &sdmac->desc;
-- 
2.1.4

WARNING: multiple messages have this Message-ID (diff)
From: Joshua Clayton <stillcompiling@gmail.com>
To: Vinod Koul <vinod.koul@intel.com>
Cc: Joshua Clayton <stillcompiling@gmail.com>,
	Dan Williams <dan.j.williams@intel.com>,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Shawn Guo <shawn.guo@linaro.org>
Subject: [PATCH 08/10] dma: imx-sdma: extract common sdma prep code
Date: Mon, 15 Jun 2015 09:19:03 -0700	[thread overview]
Message-ID: <1434385144-4432-9-git-send-email-stillcompiling@gmail.com> (raw)
In-Reply-To: <1434385144-4432-1-git-send-email-stillcompiling@gmail.com>

Extract the code that is equivalent between
the slave and cyclic sdma functions.
Add some better errors for failure conditions.

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
---
 drivers/dma/imx-sdma.c | 76 +++++++++++++++++++++-----------------------------
 1 file changed, 32 insertions(+), 44 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index c9badd4..4d447be 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -1018,6 +1018,34 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan)
 	return 0;
 }
 
+int sdma_prep_common(struct sdma_channel *sdmac, int buf_count,
+			enum dma_transfer_direction direction)
+{
+	struct sdma_engine *sdma = to_sdma_engine(sdmac);
+
+	if (sdmac->status == DMA_IN_PROGRESS) {
+		dev_err(sdma->dev, "SDMA channel %d: dma already in progress\n",
+				sdmac->channel);
+		return -EBUSY;
+	}
+
+	sdmac->status = DMA_IN_PROGRESS;
+	sdmac->buf_tail = 0;
+	sdmac->direction = direction;
+
+	dev_dbg(sdma->dev, "setting up %d entries for channel %d.\n",
+			buf_count, sdmac->channel);
+
+	if (buf_count > NUM_BD) {
+		dev_err(sdma->dev, "SDMA channel %d: maximum number of buffers exceeded: %d > %d\n",
+				sdmac->channel, buf_count, NUM_BD);
+		return -EINVAL;
+	}
+	sdmac->num_bd = buf_count;
+
+	return sdma_load_context(sdmac);
+}
+
 static void sdma_free_chan_resources(struct dma_chan *chan)
 {
 	struct sdma_channel *sdmac = to_sdma_chan(chan);
@@ -1053,28 +1081,12 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
 	int channel = sdmac->channel;
 	struct scatterlist *sg;
 
-	if (sdmac->status == DMA_IN_PROGRESS)
-		return NULL;
-	sdmac->status = DMA_IN_PROGRESS;
-
-	sdmac->flags = 0;
-
-	sdmac->buf_tail = 0;
-
-	dev_dbg(sdma->dev, "setting up %d entries for channel %d.\n",
-			sg_len, channel);
-
-	sdmac->direction = direction;
-	ret = sdma_load_context(sdmac);
+	ret = sdma_prep_common(sdmac, sg_len, direction);
 	if (ret)
 		goto err_out;
 
-	if (sg_len > NUM_BD) {
-		dev_err(sdma->dev, "SDMA channel %d: maximum number of sg exceeded: %d > %d\n",
-				channel, sg_len, NUM_BD);
-		ret = -EINVAL;
-		goto err_out;
-	}
+	sdmac->flags = 0;
+
 
 	sdmac->chn_count = 0;
 	for_each_sg(sgl, sg, sg_len, i) {
@@ -1129,7 +1141,6 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
 		bd->mode.status = param;
 	}
 
-	sdmac->num_bd = sg_len;
 	sdma->channel_control[channel].current_bd_ptr = sdmac->bd_phys;
 
 	return &sdmac->desc;
@@ -1149,33 +1160,11 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic(
 	int channel = sdmac->channel;
 	int ret, i = 0, buf = 0;
 
-	dev_dbg(sdma->dev, "%s channel: %d\n", __func__, channel);
-
-	if (sdmac->status == DMA_IN_PROGRESS)
-		return NULL;
-
-	sdmac->status = DMA_IN_PROGRESS;
+	sdma_prep_common(sdmac, buf_len / period_len, direction);
 
-	sdmac->buf_tail = 0;
 	sdmac->period_len = period_len;
 
 	sdmac->flags |= IMX_DMA_SG_LOOP;
-	sdmac->direction = direction;
-	ret = sdma_load_context(sdmac);
-	if (ret)
-		goto err_out;
-
-	if (num_periods > NUM_BD) {
-		dev_err(sdma->dev, "SDMA channel %d: maximum number of sg exceeded: %d > %d\n",
-				channel, num_periods, NUM_BD);
-		goto err_out;
-	}
-
-	if (period_len > 0xffff) {
-		dev_err(sdma->dev, "SDMA channel %d: maximum period size exceeded: %d > %d\n",
-				channel, period_len, 0xffff);
-		goto err_out;
-	}
 
 	while (buf < buf_len) {
 		struct sdma_buffer_descriptor *bd = &sdmac->bd[i];
@@ -1207,7 +1196,6 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic(
 		i++;
 	}
 
-	sdmac->num_bd = num_periods;
 	sdma->channel_control[channel].current_bd_ptr = sdmac->bd_phys;
 
 	return &sdmac->desc;
-- 
2.1.4


  parent reply	other threads:[~2015-06-15 16:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-15 16:18 [PATCH 00/10] imx-sdma cleanup Joshua Clayton
2015-06-15 16:18 ` Joshua Clayton
2015-06-15 16:18 ` [PATCH 01/10] dma: imx-sdma: constify local structs Joshua Clayton
2015-06-15 16:18   ` Joshua Clayton
2015-06-15 16:18 ` [PATCH 02/10] dma: imx-sdma: pass sdma engine into functions Joshua Clayton
2015-06-15 16:18   ` Joshua Clayton
2015-06-15 16:18 ` [PATCH 03/10] dma: imx-sdma: use a container_of function Joshua Clayton
2015-06-15 16:18   ` Joshua Clayton
2015-06-15 16:18 ` [PATCH 04/10] dma: sdma-imx set dma script address directly Joshua Clayton
2015-06-15 16:18   ` Joshua Clayton
2015-06-15 16:19 ` [PATCH 05/10] dma: sdma-imx: print an error when context load fails Joshua Clayton
2015-06-15 16:19   ` Joshua Clayton
2015-06-15 16:19 ` [PATCH 06/10] dma: imx-sdma: config in sdma_config_channel() Joshua Clayton
2015-06-15 16:19   ` Joshua Clayton
2015-06-15 16:19 ` [PATCH 07/10] dma: imx-sdma: validate word size when set Joshua Clayton
2015-06-15 16:19   ` Joshua Clayton
2015-06-15 16:19 ` Joshua Clayton [this message]
2015-06-15 16:19   ` [PATCH 08/10] dma: imx-sdma: extract common sdma prep code Joshua Clayton
2015-06-15 16:19 ` [PATCH 09/10] dma: imx-sdma: use a for loop Joshua Clayton
2015-06-15 16:19   ` Joshua Clayton
2015-06-16 14:57 ` [PATCH 00/10] imx-sdma cleanup Joshua Clayton
2015-06-16 14:57   ` Joshua Clayton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434385144-4432-9-git-send-email-stillcompiling@gmail.com \
    --to=stillcompiling@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.