From: Baruch Siach <baruch@tkos.co.il> To: David Woodhouse <dwmw2@infradead.org>, Brian Norris <computersforpeace@gmail.com> Cc: "Baruch Siach" <baruch@tkos.co.il>, linux-mtd@lists.infradead.org, "Sascha Hauer" <kernel@pengutronix.de>, "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>, "Shawn Guo" <shawn.guo@linaro.org>, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/4] mtd: nand: mxc_nand: cleanup copy_spare function Date: Sun, 26 Apr 2015 11:16:48 +0300 [thread overview] Message-ID: <15bfff1fdffecb6ca7070504aa8d66dbd40feaee.1430034929.git.baruch@tkos.co.il> (raw) In-Reply-To: <cover.1430034929.git.baruch@tkos.co.il> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> To give people without the reference manual at hand a chance to understand how spare area is handled in the i.MX nand controller, improve commenting, naming of variables and coding style. No functional change intended. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> [baruch: declare oob_chunk_size; update comments; reword commit log] Signed-off-by: Baruch Siach <baruch@tkos.co.il> --- drivers/mtd/nand/mxc_nand.c | 46 ++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index 372e0e38f59b..33b22b9c0b30 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c @@ -807,32 +807,48 @@ static void mxc_nand_select_chip_v2(struct mtd_info *mtd, int chip) } /* - * Function to transfer data to/from spare area. + * The controller splits a page into data chunks of 512 bytes + partial oob. + * There are writesize / 512 such chunks, the size of the partial oob parts is + * oobsize / #chunks rounded down to a multiple of 2. The last oob chunk then + * contains additionally the byte lost by rounding (if any). + * This function handles the needed shuffling between host->data_buf (which + * holds a page in natural order, i.e. writesize bytes data + oobsize bytes + * spare) and the NFC buffer. */ static void copy_spare(struct mtd_info *mtd, bool bfrom) { struct nand_chip *this = mtd->priv; struct mxc_nand_host *host = this->priv; - u16 i, j; - u16 n = mtd->writesize >> 9; + u16 i, oob_chunk_size; + u16 num_chunks = mtd->writesize / 512; + u8 *d = host->data_buf + mtd->writesize; u8 __iomem *s = host->spare0; - u16 t = host->devtype_data->spare_len; + u16 sparebuf_size = host->devtype_data->spare_len; - j = (mtd->oobsize / n >> 1) << 1; + /* size of oob chunk for all but possibly the last one */ + oob_chunk_size = (mtd->oobsize / num_chunks) & ~1; if (bfrom) { - for (i = 0; i < n - 1; i++) - memcpy32_fromio(d + i * j, s + i * t, j); - - /* the last section */ - memcpy32_fromio(d + i * j, s + i * t, mtd->oobsize - i * j); + for (i = 0; i < num_chunks - 1; i++) + memcpy32_fromio(d + i * oob_chunk_size, + s + i * sparebuf_size, + oob_chunk_size); + + /* the last chunk */ + memcpy32_fromio(d + i * oob_chunk_size, + s + i * sparebuf_size, + mtd->oobsize - i * oob_chunk_size); } else { - for (i = 0; i < n - 1; i++) - memcpy32_toio(&s[i * t], &d[i * j], j); - - /* the last section */ - memcpy32_toio(&s[i * t], &d[i * j], mtd->oobsize - i * j); + for (i = 0; i < num_chunks - 1; i++) + memcpy32_toio(&s[i * sparebuf_size], + &d[i * oob_chunk_size], + oob_chunk_size); + + /* the last chunk */ + memcpy32_toio(&s[oob_chunk_size * sparebuf_size], + &d[i * oob_chunk_size], + mtd->oobsize - i * oob_chunk_size); } } -- 2.1.4
WARNING: multiple messages have this Message-ID (diff)
From: baruch@tkos.co.il (Baruch Siach) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/4] mtd: nand: mxc_nand: cleanup copy_spare function Date: Sun, 26 Apr 2015 11:16:48 +0300 [thread overview] Message-ID: <15bfff1fdffecb6ca7070504aa8d66dbd40feaee.1430034929.git.baruch@tkos.co.il> (raw) In-Reply-To: <cover.1430034929.git.baruch@tkos.co.il> From: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de> To give people without the reference manual at hand a chance to understand how spare area is handled in the i.MX nand controller, improve commenting, naming of variables and coding style. No functional change intended. Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de> [baruch: declare oob_chunk_size; update comments; reword commit log] Signed-off-by: Baruch Siach <baruch@tkos.co.il> --- drivers/mtd/nand/mxc_nand.c | 46 ++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index 372e0e38f59b..33b22b9c0b30 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c @@ -807,32 +807,48 @@ static void mxc_nand_select_chip_v2(struct mtd_info *mtd, int chip) } /* - * Function to transfer data to/from spare area. + * The controller splits a page into data chunks of 512 bytes + partial oob. + * There are writesize / 512 such chunks, the size of the partial oob parts is + * oobsize / #chunks rounded down to a multiple of 2. The last oob chunk then + * contains additionally the byte lost by rounding (if any). + * This function handles the needed shuffling between host->data_buf (which + * holds a page in natural order, i.e. writesize bytes data + oobsize bytes + * spare) and the NFC buffer. */ static void copy_spare(struct mtd_info *mtd, bool bfrom) { struct nand_chip *this = mtd->priv; struct mxc_nand_host *host = this->priv; - u16 i, j; - u16 n = mtd->writesize >> 9; + u16 i, oob_chunk_size; + u16 num_chunks = mtd->writesize / 512; + u8 *d = host->data_buf + mtd->writesize; u8 __iomem *s = host->spare0; - u16 t = host->devtype_data->spare_len; + u16 sparebuf_size = host->devtype_data->spare_len; - j = (mtd->oobsize / n >> 1) << 1; + /* size of oob chunk for all but possibly the last one */ + oob_chunk_size = (mtd->oobsize / num_chunks) & ~1; if (bfrom) { - for (i = 0; i < n - 1; i++) - memcpy32_fromio(d + i * j, s + i * t, j); - - /* the last section */ - memcpy32_fromio(d + i * j, s + i * t, mtd->oobsize - i * j); + for (i = 0; i < num_chunks - 1; i++) + memcpy32_fromio(d + i * oob_chunk_size, + s + i * sparebuf_size, + oob_chunk_size); + + /* the last chunk */ + memcpy32_fromio(d + i * oob_chunk_size, + s + i * sparebuf_size, + mtd->oobsize - i * oob_chunk_size); } else { - for (i = 0; i < n - 1; i++) - memcpy32_toio(&s[i * t], &d[i * j], j); - - /* the last section */ - memcpy32_toio(&s[i * t], &d[i * j], mtd->oobsize - i * j); + for (i = 0; i < num_chunks - 1; i++) + memcpy32_toio(&s[i * sparebuf_size], + &d[i * oob_chunk_size], + oob_chunk_size); + + /* the last chunk */ + memcpy32_toio(&s[oob_chunk_size * sparebuf_size], + &d[i * oob_chunk_size], + mtd->oobsize - i * oob_chunk_size); } } -- 2.1.4
next prev parent reply other threads:[~2015-04-26 8:16 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-04-26 8:16 [PATCH 0/4] mtd: mxc_nand: fix 8 bit ECC and large oob Baruch Siach 2015-04-26 8:16 ` Baruch Siach 2015-04-26 8:16 ` Baruch Siach [this message] 2015-04-26 8:16 ` [PATCH 1/4] mtd: nand: mxc_nand: cleanup copy_spare function Baruch Siach 2015-04-26 8:16 ` [PATCH 2/4] mtd: mxc_nand: limit the size of used oob Baruch Siach 2015-04-26 8:16 ` Baruch Siach 2015-04-26 20:07 ` Uwe Kleine-König 2015-04-26 20:07 ` Uwe Kleine-König 2015-04-27 4:39 ` Baruch Siach 2015-04-27 4:39 ` Baruch Siach 2015-04-27 7:12 ` Uwe Kleine-König 2015-04-27 7:12 ` Uwe Kleine-König 2015-04-27 7:20 ` Baruch Siach 2015-04-27 7:20 ` Baruch Siach 2015-04-27 7:50 ` Uwe Kleine-König 2015-04-27 7:50 ` Uwe Kleine-König 2015-04-27 11:43 ` Baruch Siach 2015-04-27 11:43 ` Baruch Siach 2015-04-27 19:31 ` Uwe Kleine-König 2015-04-27 19:31 ` Uwe Kleine-König 2015-04-29 6:18 ` Baruch Siach 2015-04-29 6:18 ` Baruch Siach 2015-04-29 6:35 ` Uwe Kleine-König 2015-04-29 6:35 ` Uwe Kleine-König 2015-04-30 15:20 ` Fabio Estevam 2015-04-30 15:20 ` Fabio Estevam 2015-05-03 7:55 ` Baruch Siach 2015-05-03 7:55 ` Baruch Siach 2015-04-26 8:16 ` [PATCH 3/4] mtd: mxc_nand: fix truncate of unaligned oob copying Baruch Siach 2015-04-26 8:16 ` Baruch Siach 2015-04-26 19:52 ` Uwe Kleine-König 2015-04-26 19:52 ` Uwe Kleine-König 2015-04-27 4:46 ` Baruch Siach 2015-04-27 4:46 ` Baruch Siach 2015-04-27 6:56 ` Uwe Kleine-König 2015-04-27 6:56 ` Uwe Kleine-König 2015-04-26 8:16 ` [PATCH 4/4] mtd: mxc_nand: generate nand_ecclayout for 8 bit ECC Baruch Siach 2015-04-26 8:16 ` Baruch Siach
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=15bfff1fdffecb6ca7070504aa8d66dbd40feaee.1430034929.git.baruch@tkos.co.il \ --to=baruch@tkos.co.il \ --cc=computersforpeace@gmail.com \ --cc=dwmw2@infradead.org \ --cc=kernel@pengutronix.de \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-mtd@lists.infradead.org \ --cc=shawn.guo@linaro.org \ --cc=u.kleine-koenig@pengutronix.de \ /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: linkBe 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.