Message ID | 1279591705-7574-5-git-send-email-Mingkai.hu@freescale.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Grant Likely |
Headers | show |
On Tue, Jul 20, 2010 at 10:08:23AM +0800, Mingkai Hu wrote: > For Freescale's eSPI controller, the max transaction length one time > is limitted by the SPCOM[TRANSLEN] field which is 0x10000. When used > mkfs.ext2 command to create ext2 filesystem on the flash, the read > length will exceed the max value of the SPCOM[TRANSLEN] field, so > change the read function to read page by page. > > For other SPI flash driver, also needed to change the read function > if used the eSPI controller. > > Signed-off-by: Mingkai Hu <Mingkai.hu@freescale.com> > --- > drivers/mtd/devices/m25p80.c | 18 ++++++++++++++---- > 1 files changed, 14 insertions(+), 4 deletions(-) > > diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c > index 81e49a9..6cbe6b1 100644 > --- a/drivers/mtd/devices/m25p80.c > +++ b/drivers/mtd/devices/m25p80.c > @@ -317,6 +317,7 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, > struct m25p *flash = mtd_to_m25p(mtd); > struct spi_transfer t[2]; > struct spi_message m; > + u32 i, page_size = 0; > > DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", > dev_name(&flash->spi->dev), __func__, "from", > @@ -341,7 +342,6 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, > spi_message_add_tail(&t[0], &m); > > t[1].rx_buf = buf; > - t[1].len = len; > spi_message_add_tail(&t[1], &m); > > /* Byte count starts at zero. */ > @@ -364,11 +364,21 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, > > /* Set up the write data buffer. */ > flash->command[0] = OPCODE_READ; > - m25p_addr2cmd(flash, from, flash->command); > > - spi_sync(flash->spi, &m); > + for (i = page_size; i < len; i += page_size) { > + page_size = len - i; > + if (page_size > flash->page_size) > + page_size = flash->page_size; > > - *retlen = m.actual_length - m25p_cmdsz(flash) - FAST_READ_DUMMY_BYTE; > + m25p_addr2cmd(flash, from + i, flash->command); > + t[1].len = page_size; > + t[1].rx_buf = buf + i; > + > + spi_sync(flash->spi, &m); > + > + *retlen += m.actual_length - m25p_cmdsz(flash) > + - FAST_READ_DUMMY_BYTE; > + } This patch seems to cripple all users just because eSPI cannot handle it. Am I reading it wrong? > > mutex_unlock(&flash->lock); > > -- > 1.6.4 > >
> -----Original Message----- > From: Grant Likely [mailto:glikely@secretlab.ca] On Behalf Of > Grant Likely > Sent: Monday, July 26, 2010 8:30 AM > To: Hu Mingkai-B21284 > Cc: linuxppc-dev@ozlabs.org; galak@kernel.crashing.org; Zang > Roy-R61911 > Subject: Re: [PATCH 4/6] mtd: m25p80: change the read > function to read page by page > > On Tue, Jul 20, 2010 at 10:08:23AM +0800, Mingkai Hu wrote: > > For Freescale's eSPI controller, the max transaction length > one time > > is limitted by the SPCOM[TRANSLEN] field which is 0x10000. When used > > mkfs.ext2 command to create ext2 filesystem on the flash, the read > > length will exceed the max value of the SPCOM[TRANSLEN] field, so > > change the read function to read page by page. > > > > For other SPI flash driver, also needed to change the read > function if > > used the eSPI controller. > > > > Signed-off-by: Mingkai Hu <Mingkai.hu@freescale.com> > > --- > > drivers/mtd/devices/m25p80.c | 18 ++++++++++++++---- > > 1 files changed, 14 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/mtd/devices/m25p80.c > > b/drivers/mtd/devices/m25p80.c index 81e49a9..6cbe6b1 100644 > > --- a/drivers/mtd/devices/m25p80.c > > +++ b/drivers/mtd/devices/m25p80.c > > @@ -317,6 +317,7 @@ static int m25p80_read(struct mtd_info > *mtd, loff_t from, size_t len, > > struct m25p *flash = mtd_to_m25p(mtd); > > struct spi_transfer t[2]; > > struct spi_message m; > > + u32 i, page_size = 0; > > > > DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", > > dev_name(&flash->spi->dev), __func__, > "from", @@ -341,7 +342,6 @@ > > static int m25p80_read(struct mtd_info *mtd, loff_t from, > size_t len, > > spi_message_add_tail(&t[0], &m); > > > > t[1].rx_buf = buf; > > - t[1].len = len; > > spi_message_add_tail(&t[1], &m); > > > > /* Byte count starts at zero. */ > > @@ -364,11 +364,21 @@ static int m25p80_read(struct mtd_info *mtd, > > loff_t from, size_t len, > > > > /* Set up the write data buffer. */ > > flash->command[0] = OPCODE_READ; > > - m25p_addr2cmd(flash, from, flash->command); > > > > - spi_sync(flash->spi, &m); > > + for (i = page_size; i < len; i += page_size) { > > + page_size = len - i; > > + if (page_size > flash->page_size) > > + page_size = flash->page_size; > > > > - *retlen = m.actual_length - m25p_cmdsz(flash) - > FAST_READ_DUMMY_BYTE; > > + m25p_addr2cmd(flash, from + i, flash->command); > > + t[1].len = page_size; > > + t[1].rx_buf = buf + i; > > + > > + spi_sync(flash->spi, &m); > > + > > + *retlen += m.actual_length - m25p_cmdsz(flash) > > + - FAST_READ_DUMMY_BYTE; > > + } > > This patch seems to cripple all users just because eSPI > cannot handle it. Am I reading it wrong? > You're right, this will cripple all users. At first, I want to contain this specific code with CONFIG_SPI_FSL_ESPI option, or register a specific read function like: #ifdef CONFIG_SPI_FSL_ESPI flash->mtd.read = m25p80_read_espi; #endif but this will make the code looks arguly, are there other ways? Thanks, Mingkai
On Mon, Jul 26, 2010 at 1:33 AM, Hu Mingkai-B21284 <B21284@freescale.com> wrote: > > >> -----Original Message----- >> From: Grant Likely [mailto:glikely@secretlab.ca] On Behalf Of >> Grant Likely >> Sent: Monday, July 26, 2010 8:30 AM >> To: Hu Mingkai-B21284 >> Cc: linuxppc-dev@ozlabs.org; galak@kernel.crashing.org; Zang >> Roy-R61911 >> Subject: Re: [PATCH 4/6] mtd: m25p80: change the read >> function to read page by page >> >> On Tue, Jul 20, 2010 at 10:08:23AM +0800, Mingkai Hu wrote: >> > For Freescale's eSPI controller, the max transaction length >> one time >> > is limitted by the SPCOM[TRANSLEN] field which is 0x10000. When used >> > mkfs.ext2 command to create ext2 filesystem on the flash, the read >> > length will exceed the max value of the SPCOM[TRANSLEN] field, so >> > change the read function to read page by page. >> > >> > For other SPI flash driver, also needed to change the read >> function if >> > used the eSPI controller. >> > >> > Signed-off-by: Mingkai Hu <Mingkai.hu@freescale.com> >> > --- >> > drivers/mtd/devices/m25p80.c | 18 ++++++++++++++---- >> > 1 files changed, 14 insertions(+), 4 deletions(-) >> > >> > diff --git a/drivers/mtd/devices/m25p80.c >> > b/drivers/mtd/devices/m25p80.c index 81e49a9..6cbe6b1 100644 >> > --- a/drivers/mtd/devices/m25p80.c >> > +++ b/drivers/mtd/devices/m25p80.c >> > @@ -317,6 +317,7 @@ static int m25p80_read(struct mtd_info >> *mtd, loff_t from, size_t len, >> > struct m25p *flash = mtd_to_m25p(mtd); >> > struct spi_transfer t[2]; >> > struct spi_message m; >> > + u32 i, page_size = 0; >> > >> > DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", >> > dev_name(&flash->spi->dev), __func__, >> "from", @@ -341,7 +342,6 @@ >> > static int m25p80_read(struct mtd_info *mtd, loff_t from, >> size_t len, >> > spi_message_add_tail(&t[0], &m); >> > >> > t[1].rx_buf = buf; >> > - t[1].len = len; >> > spi_message_add_tail(&t[1], &m); >> > >> > /* Byte count starts at zero. */ >> > @@ -364,11 +364,21 @@ static int m25p80_read(struct mtd_info *mtd, >> > loff_t from, size_t len, >> > >> > /* Set up the write data buffer. */ >> > flash->command[0] = OPCODE_READ; >> > - m25p_addr2cmd(flash, from, flash->command); >> > >> > - spi_sync(flash->spi, &m); >> > + for (i = page_size; i < len; i += page_size) { >> > + page_size = len - i; >> > + if (page_size > flash->page_size) >> > + page_size = flash->page_size; >> > >> > - *retlen = m.actual_length - m25p_cmdsz(flash) - >> FAST_READ_DUMMY_BYTE; >> > + m25p_addr2cmd(flash, from + i, flash->command); >> > + t[1].len = page_size; >> > + t[1].rx_buf = buf + i; >> > + >> > + spi_sync(flash->spi, &m); >> > + >> > + *retlen += m.actual_length - m25p_cmdsz(flash) >> > + - FAST_READ_DUMMY_BYTE; >> > + } >> >> This patch seems to cripple all users just because eSPI >> cannot handle it. Am I reading it wrong? >> > > You're right, this will cripple all users. > > At first, I want to contain this specific code with CONFIG_SPI_FSL_ESPI > option, > or register a specific read function like: > > #ifdef CONFIG_SPI_FSL_ESPI > flash->mtd.read = m25p80_read_espi; > #endif > > but this will make the code looks arguly, And it is multiplatform-unfriendly. > are there other ways? You need to select the correct transfer behaviour at driver probe time. You'll need a way to indicate that the spi_master isn't able to handle your transfer request. I'd need to think about it more to come up with a concrete suggestion. g.
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 81e49a9..6cbe6b1 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -317,6 +317,7 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, struct m25p *flash = mtd_to_m25p(mtd); struct spi_transfer t[2]; struct spi_message m; + u32 i, page_size = 0; DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", dev_name(&flash->spi->dev), __func__, "from", @@ -341,7 +342,6 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, spi_message_add_tail(&t[0], &m); t[1].rx_buf = buf; - t[1].len = len; spi_message_add_tail(&t[1], &m); /* Byte count starts at zero. */ @@ -364,11 +364,21 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, /* Set up the write data buffer. */ flash->command[0] = OPCODE_READ; - m25p_addr2cmd(flash, from, flash->command); - spi_sync(flash->spi, &m); + for (i = page_size; i < len; i += page_size) { + page_size = len - i; + if (page_size > flash->page_size) + page_size = flash->page_size; - *retlen = m.actual_length - m25p_cmdsz(flash) - FAST_READ_DUMMY_BYTE; + m25p_addr2cmd(flash, from + i, flash->command); + t[1].len = page_size; + t[1].rx_buf = buf + i; + + spi_sync(flash->spi, &m); + + *retlen += m.actual_length - m25p_cmdsz(flash) + - FAST_READ_DUMMY_BYTE; + } mutex_unlock(&flash->lock);
For Freescale's eSPI controller, the max transaction length one time is limitted by the SPCOM[TRANSLEN] field which is 0x10000. When used mkfs.ext2 command to create ext2 filesystem on the flash, the read length will exceed the max value of the SPCOM[TRANSLEN] field, so change the read function to read page by page. For other SPI flash driver, also needed to change the read function if used the eSPI controller. Signed-off-by: Mingkai Hu <Mingkai.hu@freescale.com> --- drivers/mtd/devices/m25p80.c | 18 ++++++++++++++---- 1 files changed, 14 insertions(+), 4 deletions(-)