mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mci multiblock write
@ 2011-11-11 11:38 Sascha Hauer
  2011-11-11 11:38 ` [PATCH 1/2] mci: implement multi block write Sascha Hauer
  2011-11-11 11:38 ` [PATCH 2/2] mci: remove unnecessary loops Sascha Hauer
  0 siblings, 2 replies; 5+ messages in thread
From: Sascha Hauer @ 2011-11-11 11:38 UTC (permalink / raw)
  To: barebox

Two patches I had lying around for some time.

Sascha Hauer (2):
      mci: implement multi block write
      mci: remove unnecessary loops

 drivers/mci/mci-core.c |   81 ++++++++++++++++++++++++++++--------------------
 1 files changed, 47 insertions(+), 34 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] mci: implement multi block write
  2011-11-11 11:38 [PATCH] mci multiblock write Sascha Hauer
@ 2011-11-11 11:38 ` Sascha Hauer
  2011-11-11 11:47   ` Belisko Marek
  2011-11-11 11:38 ` [PATCH 2/2] mci: remove unnecessary loops Sascha Hauer
  1 sibling, 1 reply; 5+ messages in thread
From: Sascha Hauer @ 2011-11-11 11:38 UTC (permalink / raw)
  To: barebox

This speeds up writes to MMC/SD cards significantly.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c |   30 ++++++++++++++++++++++++++----
 1 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 09f7e29..58f7f6d 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -107,12 +107,20 @@ static void *sector_buf;
  * @return Transaction status (0 on success)
  */
 #ifdef CONFIG_MCI_WRITE
-static int mci_block_write(struct device_d *mci_dev, const void *src, unsigned blocknum)
+static int mci_block_write(struct device_d *mci_dev, const void *src, unsigned blocknum,
+	int blocks)
 {
 	struct mci *mci = GET_MCI_DATA(mci_dev);
 	struct mci_cmd cmd;
 	struct mci_data data;
 	const void *buf;
+	unsigned mmccmd;
+	int ret;
+
+	if (blocks > 1)
+		mmccmd = MMC_CMD_WRITE_MULTIPLE_BLOCK;
+	else
+		mmccmd = MMC_CMD_WRITE_SINGLE_BLOCK;
 
 	if ((unsigned long)src & 0x3) {
 		memcpy(sector_buf, src, 512);
@@ -122,16 +130,30 @@ static int mci_block_write(struct device_d *mci_dev, const void *src, unsigned b
 	}
 
 	mci_setup_cmd(&cmd,
-		MMC_CMD_WRITE_SINGLE_BLOCK,
+		mmccmd,
 		mci->high_capacity != 0 ? blocknum : blocknum * mci->write_bl_len,
 		MMC_RSP_R1);
 
 	data.src = buf;
-	data.blocks = 1;
+	data.blocks = blocks;
 	data.blocksize = mci->write_bl_len;
 	data.flags = MMC_DATA_WRITE;
 
-	return mci_send_cmd(mci_dev, &cmd, &data);
+	ret = mci_send_cmd(mci_dev, &cmd, &data);
+	if (ret)
+		return ret;
+
+
+	if (blocks > 1) {
+		mci_setup_cmd(&cmd,
+			MMC_CMD_STOP_TRANSMISSION,
+			0, MMC_RSP_R1b);
+			ret = mci_send_cmd(mci_dev, &cmd, NULL);
+			if (ret)
+				return ret;
+        }
+
+	return ret;
 }
 #endif
 
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] mci: remove unnecessary loops
  2011-11-11 11:38 [PATCH] mci multiblock write Sascha Hauer
  2011-11-11 11:38 ` [PATCH 1/2] mci: implement multi block write Sascha Hauer
@ 2011-11-11 11:38 ` Sascha Hauer
  1 sibling, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2011-11-11 11:38 UTC (permalink / raw)
  To: barebox

We used to loop around the sectors in mci_sd_write/mci_sd_read.
Now that we have multi block read and write this is not necessary
anymore.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c |   51 +++++++++++++++++++----------------------------
 1 files changed, 21 insertions(+), 30 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 58f7f6d..651bcbf 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -988,21 +988,17 @@ static int mci_sd_write(struct device_d *disk_dev, uint64_t sector_start,
 		return -EINVAL;
 	}
 
-	while (sector_count) {
-		/* size of the block number field in the MMC/SD command is 32 bit only */
-		if (sector_start > MAX_BUFFER_NUMBER) {
-			pr_debug("Cannot handle block number %llu. Too large!\n",
-				sector_start);
-			return -EINVAL;
-		}
-		rc = mci_block_write(mci_dev, buffer, sector_start);
-		if (rc != 0) {
-			pr_debug("Writing block %u failed with %d\n", (unsigned)sector_start, rc);
-			return rc;
-		}
-		sector_count--;
-		buffer += mci->write_bl_len;
-		sector_start++;
+	/* size of the block number field in the MMC/SD command is 32 bit only */
+	if (sector_start > MAX_BUFFER_NUMBER) {
+		pr_debug("Cannot handle block number %llu. Too large!\n",
+			sector_start);
+		return -EINVAL;
+	}
+
+	rc = mci_block_write(mci_dev, buffer, sector_start, sector_count);
+	if (rc != 0) {
+		pr_debug("Writing block %u failed with %d\n", (unsigned)sector_start, rc);
+		return rc;
 	}
 
 	return 0;
@@ -1036,21 +1032,16 @@ static int mci_sd_read(struct device_d *disk_dev, uint64_t sector_start,
 		return -EINVAL;
 	}
 
-	while (sector_count) {
-		int now = min(sector_count, 32U);
-		if (sector_start > MAX_BUFFER_NUMBER) {
-			pr_err("Cannot handle block number %u. Too large!\n",
-				(unsigned)sector_start);
-			return -EINVAL;
-		}
-		rc = mci_read_block(mci_dev, buffer, (unsigned)sector_start, now);
-		if (rc != 0) {
-			pr_debug("Reading block %u failed with %d\n", (unsigned)sector_start, rc);
-			return rc;
-		}
-		sector_count -= now;
-		buffer += mci->read_bl_len * now;
-		sector_start += now;
+	if (sector_start > MAX_BUFFER_NUMBER) {
+		pr_err("Cannot handle block number %u. Too large!\n",
+			(unsigned)sector_start);
+		return -EINVAL;
+	}
+
+	rc = mci_read_block(mci_dev, buffer, (unsigned)sector_start, sector_count);
+	if (rc != 0) {
+		pr_debug("Reading block %u failed with %d\n", (unsigned)sector_start, rc);
+		return rc;
 	}
 
 	return 0;
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mci: implement multi block write
  2011-11-11 11:38 ` [PATCH 1/2] mci: implement multi block write Sascha Hauer
@ 2011-11-11 11:47   ` Belisko Marek
  2011-11-11 11:59     ` Sascha Hauer
  0 siblings, 1 reply; 5+ messages in thread
From: Belisko Marek @ 2011-11-11 11:47 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On Fri, Nov 11, 2011 at 12:38 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> This speeds up writes to MMC/SD cards significantly.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/mci/mci-core.c |   30 ++++++++++++++++++++++++++----
>  1 files changed, 26 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> index 09f7e29..58f7f6d 100644
> --- a/drivers/mci/mci-core.c
> +++ b/drivers/mci/mci-core.c
> @@ -107,12 +107,20 @@ static void *sector_buf;
>  * @return Transaction status (0 on success)
>  */
>  #ifdef CONFIG_MCI_WRITE
> -static int mci_block_write(struct device_d *mci_dev, const void *src, unsigned blocknum)
> +static int mci_block_write(struct device_d *mci_dev, const void *src, unsigned blocknum,
> +       int blocks)
>  {
>        struct mci *mci = GET_MCI_DATA(mci_dev);
>        struct mci_cmd cmd;
>        struct mci_data data;
>        const void *buf;
> +       unsigned mmccmd;
> +       int ret;
> +
> +       if (blocks > 1)
> +               mmccmd = MMC_CMD_WRITE_MULTIPLE_BLOCK;
> +       else
> +               mmccmd = MMC_CMD_WRITE_SINGLE_BLOCK;
>
>        if ((unsigned long)src & 0x3) {
>                memcpy(sector_buf, src, 512);
> @@ -122,16 +130,30 @@ static int mci_block_write(struct device_d *mci_dev, const void *src, unsigned b
>        }
>
>        mci_setup_cmd(&cmd,
> -               MMC_CMD_WRITE_SINGLE_BLOCK,
> +               mmccmd,
>                mci->high_capacity != 0 ? blocknum : blocknum * mci->write_bl_len,
>                MMC_RSP_R1);
>
>        data.src = buf;
> -       data.blocks = 1;
> +       data.blocks = blocks;
>        data.blocksize = mci->write_bl_len;
>        data.flags = MMC_DATA_WRITE;
>
> -       return mci_send_cmd(mci_dev, &cmd, &data);
> +       ret = mci_send_cmd(mci_dev, &cmd, &data);
> +       if (ret)
> +               return ret;
> +
> +
Necessary 2 new lines here?
> +       if (blocks > 1) {
> +               mci_setup_cmd(&cmd,
> +                       MMC_CMD_STOP_TRANSMISSION,
> +                       0, MMC_RSP_R1b);
> +                       ret = mci_send_cmd(mci_dev, &cmd, NULL);
> +                       if (ret)
> +                               return ret;
> +        }
> +
> +       return ret;
>  }
>  #endif
>
> --
> 1.7.7.1
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>

regards,

marek

-- 
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
twitter: #opennandra
web: http://open-nandra.com

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mci: implement multi block write
  2011-11-11 11:47   ` Belisko Marek
@ 2011-11-11 11:59     ` Sascha Hauer
  0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2011-11-11 11:59 UTC (permalink / raw)
  To: Belisko Marek; +Cc: barebox

On Fri, Nov 11, 2011 at 12:47:04PM +0100, Belisko Marek wrote:
> >
> > -       return mci_send_cmd(mci_dev, &cmd, &data);
> > +       ret = mci_send_cmd(mci_dev, &cmd, &data);
> > +       if (ret)
> > +               return ret;
> > +
> > +
> Necessary 2 new lines here?

I removed one of them and it still works, so no ;)

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-11-11 11:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-11 11:38 [PATCH] mci multiblock write Sascha Hauer
2011-11-11 11:38 ` [PATCH 1/2] mci: implement multi block write Sascha Hauer
2011-11-11 11:47   ` Belisko Marek
2011-11-11 11:59     ` Sascha Hauer
2011-11-11 11:38 ` [PATCH 2/2] mci: remove unnecessary loops Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox