1. Mar 20, 2014
  2. Mar 11, 2014
    • Christian Riesch's avatar
      mtd: Fix the behavior of OTP write if there is not enough room for data · 9a78bc83
      Christian Riesch authored
      If a write to one time programmable memory (OTP) hits the end of this
      memory area, no more data can be written. The count variable in
      mtdchar_write() in drivers/mtd/mtdchar.c is not decreased anymore.
      We are trapped in the loop forever, mtdchar_write() will never return
      in this case.
      
      The desired behavior of a write in such a case is described in [1]:
      - Try to write as much data as possible, truncate the write to fit into
        the available memory and return the number of bytes that actually
        have been written.
      - If no data could be written at all, return -ENOSPC.
      
      This patch fixes the behavior of OTP write if there is not enough space
      for all data:
      
      1) mtd_write_user_prot_reg() in drivers/mtd/mtdcore.c is modified to
         return -ENOSPC if no data could be written at all.
      2) mtdchar_write() is modified to handle -ENOSPC correctly. Exit if a
         write returned -ENOSPC and yield the correct return value, either
         then number of bytes that could be written, or -ENOSPC, if no data
         could be written at all.
      
      Furthermore the patch harmonizes the behavior of the OTP memory write
      in drivers/mtd/devices/mtd_dataflash.c with the other implementations
      and the requirements from [1]. Instead of returning -EINVAL if the data
      does not fit into the OTP memory, we try to write as much data as
      possible/truncate the write.
      
      [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html
      
      
      
      Signed-off-by: default avatarChristian Riesch <christian.riesch@omicron.at>
      Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
      9a78bc83
    • Fabian Frederick's avatar
      mtd: block2mtd: check device size · ea6d833a
      Fabian Frederick authored
      
      
      fixme applied : check device size is a multiple of erasesize.
      
      Signed-off-by: default avatarFabian Frederick <fabf@skynet.be>
      Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
      ea6d833a
    • Herve Codina's avatar
      mtd: atmel_nand: Disable subpage NAND write when using Atmel PMECC · 90445ff6
      Herve Codina authored
      
      
      Crash detected on sam5d35 and its pmecc nand ecc controller.
      
      The problem was a call to chip->ecc.hwctl from nand_write_subpage_hwecc
      (nand_base.c) when we write a sub page.
      chip->ecc.hwctl function is not set when we are using PMECC controller.
      As a workaround, set NAND_NO_SUBPAGE_WRITE for PMECC controller in
      order to disable sub page access in nand_write_page.
      
      Signed-off-by: default avatarHerve Codina <Herve.CODINA@celad.com>
      Acked-by: default avatarJosh Wu <josh.wu@atmel.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
      90445ff6
    • Huang Shijie's avatar
      mtd: gpmi: add subpage read support · b8e2931d
      Huang Shijie authored
      
      
      1) Why add the subpage read support?
        The page size of the nand chip becomes larger and larger, the imx6 has to
        supports the 16K page or even bigger page. But sometimes, the upper layer only
        needs a small part of the page, such as 512 bytes or less.
      
        For example, ubiattach may only read 64 bytes per page.
      
      2) We only enable the subpage read support when it meets the conditions:
         <1> the chip is imx6 (or later chips) which can supports large nand page.
         <2> the size of ECC parity is byte aligned.
             If the size of ECC parity is not byte aligned, the calling of NAND_CMD_RNDOUT
             will fail.
      
      3) What does this patch do?
         This patch will fake a virtual small page for the subpage read, and call the
         gpmi_ecc_read_page() to do the real work.
      
         In order to fake a virtual small page, the patch changes the BCH registers and
         the bch_geometry{}. After the subpage read finished, we will restore them back.
      
      4) Performace:
          4.1) Tested with Toshiba TC58NVG2S0F(4096 + 224) with the following command:
               #ubiattach /dev/ubi_ctrl -m 4
      
             The detail information of /dev/mtd4 shows below:
             --------------------------------------------------------------
             #mtdinfo /dev/mtd4
              mtd4
              Name:                           test
              Type:                           nand
              Eraseblock size:                262144 bytes, 256.0 KiB
              Amount of eraseblocks:          1856 (486539264 bytes, 464.0 MiB)
              Minimum input/output unit size: 4096 bytes
              Sub-page size:                  4096 bytes
              OOB size:                       224 bytes
              Character device major/minor:   90:8
              Bad blocks are allowed:         true
              Device is writable:             true
             --------------------------------------------------------------
      
          4.2) Before this patch:
             --------------------------------------------------------------
             [   94.530495] UBI: attaching mtd4 to ubi0
             [   98.928850] UBI: scanning is finished
             [   98.953594] UBI: attached mtd4 (name "test", size 464 MiB) to ubi0
             [   98.958562] UBI: PEB size: 262144 bytes (256 KiB), LEB size: 253952 bytes
             [   98.964076] UBI: min./max. I/O unit sizes: 4096/4096, sub-page size 4096
             [   98.969518] UBI: VID header offset: 4096 (aligned 4096), data offset: 8192
             [   98.975128] UBI: good PEBs: 1856, bad PEBs: 0, corrupted PEBs: 0
             [   98.979843] UBI: user volume: 1, internal volumes: 1, max. volumes count: 128
             [   98.985878] UBI: max/mean erase counter: 2/1, WL threshold: 4096, image sequence number: 2024916145
             [   98.993635] UBI: available PEBs: 0, total reserved PEBs: 1856, PEBs reserved for bad PEB handling: 40
             [   99.001807] UBI: background thread "ubi_bgt0d" started, PID 831
             --------------------------------------------------------------
             The attach time is about 98.9 - 94.5 = 4.4s
      
          4.3) After this patch:
             --------------------------------------------------------------
             [  286.464906] UBI: attaching mtd4 to ubi0
             [  289.186129] UBI: scanning is finished
             [  289.211416] UBI: attached mtd4 (name "test", size 464 MiB) to ubi0
             [  289.216360] UBI: PEB size: 262144 bytes (256 KiB), LEB size: 253952 bytes
             [  289.221858] UBI: min./max. I/O unit sizes: 4096/4096, sub-page size 4096
             [  289.227293] UBI: VID header offset: 4096 (aligned 4096), data offset: 8192
             [  289.232878] UBI: good PEBs: 1856, bad PEBs: 0, corrupted PEBs: 0
             [  289.237628] UBI: user volume: 0, internal volumes: 1, max. volumes count: 128
             [  289.243553] UBI: max/mean erase counter: 1/1, WL threshold: 4096, image sequence number: 2024916145
             [  289.251348] UBI: available PEBs: 1812, total reserved PEBs: 44, PEBs reserved for bad PEB handling: 40
             [  289.259417] UBI: background thread "ubi_bgt0d" started, PID 847
             --------------------------------------------------------------
             The attach time is about 289.18 - 286.46 = 2.7s
      
           4.4) The conclusion:
             We achieve (4.4 - 2.7) / 4.4 = 38.6% faster in the ubiattach.
      
      Signed-off-by: default avatarHuang Shijie <b32955@freescale.com>
      Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
      b8e2931d
    • Huang Shijie's avatar
      mtd: gpmi: do not use the mtd->writesize · 4a57d670
      Huang Shijie authored
      
      
      The nfc_geo->payload_size is equal to the mtd->writesize now,
      use the nfc_geo->payload_size to replace the mtd->writesize.
      
      This patch makes preparation for the gpmi's subpage read support.
      In the subpage support, the nfc_geo->payload_size maybe smaller then
      the mtd->writesize.
      
      Signed-off-by: default avatarHuang Shijie <b32955@freescale.com>
      Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
      4a57d670
    • Huang Shijie's avatar
      mtd: nand: add "page" argument for read_subpage hook · e004debd
      Huang Shijie authored
      
      
      Add the "page" argument for the read_subpage hook. With this argument,
      the implementation of this hook could prints out more accurate information
      for debugging.
      
      Signed-off-by: default avatarHuang Shijie <b32955@freescale.com>
      Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
      e004debd