UBI: incorporate maximum write size
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Sun, 30 Jan 2011 16:37:33 +0000 (18:37 +0200)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Tue, 8 Mar 2011 08:12:48 +0000 (10:12 +0200)
Incorporate MTD write buffer size into UBI device information
because UBIFS needs this field. UBI does not use it ATM, just
provides to upper layers in 'struct ubi_device_info'.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
drivers/mtd/ubi/build.c
drivers/mtd/ubi/kapi.c
drivers/mtd/ubi/ubi.h
include/linux/mtd/ubi.h

index 5ebe280225d60a69f28bc81c5c4593a47e017365..f38e8de818112790ebc1bd5627a71c0e6b63854a 100644 (file)
@@ -690,11 +690,25 @@ static int io_init(struct ubi_device *ubi)
        ubi_assert(ubi->hdrs_min_io_size <= ubi->min_io_size);
        ubi_assert(ubi->min_io_size % ubi->hdrs_min_io_size == 0);
 
+       ubi->max_write_size = ubi->mtd->writebufsize;
+       /*
+        * Maximum write size has to be greater or equivalent to min. I/O
+        * size, and be multiple of min. I/O size.
+        */
+       if (ubi->max_write_size < ubi->min_io_size ||
+           ubi->max_write_size % ubi->min_io_size ||
+           !is_power_of_2(ubi->max_write_size)) {
+               ubi_err("bad write buffer size %d for %d min. I/O unit",
+                       ubi->max_write_size, ubi->min_io_size);
+               return -EINVAL;
+       }
+
        /* Calculate default aligned sizes of EC and VID headers */
        ubi->ec_hdr_alsize = ALIGN(UBI_EC_HDR_SIZE, ubi->hdrs_min_io_size);
        ubi->vid_hdr_alsize = ALIGN(UBI_VID_HDR_SIZE, ubi->hdrs_min_io_size);
 
        dbg_msg("min_io_size      %d", ubi->min_io_size);
+       dbg_msg("max_write_size   %d", ubi->max_write_size);
        dbg_msg("hdrs_min_io_size %d", ubi->hdrs_min_io_size);
        dbg_msg("ec_hdr_alsize    %d", ubi->ec_hdr_alsize);
        dbg_msg("vid_hdr_alsize   %d", ubi->vid_hdr_alsize);
index 69fa4ef03c53fcf43e4dc2d785121aac40fbca81..701df4f848f66045b4747fc214ea41b2497828c6 100644 (file)
@@ -41,6 +41,7 @@ void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di)
        di->ubi_num = ubi->ubi_num;
        di->leb_size = ubi->leb_size;
        di->min_io_size = ubi->min_io_size;
+       di->max_write_size = ubi->max_write_size;
        di->ro_mode = ubi->ro_mode;
        di->cdev = ubi->cdev.dev;
 }
index 0b0149c41fe3c7da9fd0b393b9a76c3cb90996c3..b78994330ebc8d4e6cdff9fbeae023e5ce10de26 100644 (file)
@@ -381,6 +381,8 @@ struct ubi_wl_entry;
  * @bad_allowed: whether the MTD device admits of bad physical eraseblocks or
  *               not
  * @nor_flash: non-zero if working on top of NOR flash
+ * @max_write_size: maximum amount of bytes the underlying flash can write at a
+ *                  time (MTD write buffer size)
  * @mtd: MTD device descriptor
  *
  * @peb_buf1: a buffer of PEB size used for different purposes
@@ -464,6 +466,7 @@ struct ubi_device {
        int vid_hdr_shift;
        unsigned int bad_allowed:1;
        unsigned int nor_flash:1;
+       int max_write_size;
        struct mtd_info *mtd;
 
        void *peb_buf1;
index b31bd9e9bca3a062c391b17354dc1b828f0ea555..36c70593ae627e6b8bfd3c183c6e16fd5c4a6fef 100644 (file)
@@ -117,17 +117,36 @@ struct ubi_volume_info {
  * @ubi_num: ubi device number
  * @leb_size: logical eraseblock size on this UBI device
  * @min_io_size: minimal I/O unit size
+ * @max_write_size: maximum amount of bytes the underlying flash can write at a
+ *                  time (MTD write buffer size)
  * @ro_mode: if this device is in read-only mode
  * @cdev: UBI character device major and minor numbers
  *
  * Note, @leb_size is the logical eraseblock size offered by the UBI device.
  * Volumes of this UBI device may have smaller logical eraseblock size if their
  * alignment is not equivalent to %1.
+ *
+ * The @max_write_size field describes flash write maximum write unit. For
+ * example, NOR flash allows for changing individual bytes, so @min_io_size is
+ * %1. However, it does not mean than NOR flash has to write data byte-by-byte.
+ * Instead, CFI NOR flashes have a write-buffer of, e.g., 64 bytes, and when
+ * writing large chunks of data, they write 64-bytes at a time. Obviously, this
+ * improves write throughput.
+ *
+ * Also, the MTD device may have N interleaved (striped) flash chips
+ * underneath, in which case @min_io_size can be physical min. I/O size of
+ * single flash chip, while @max_write_size can be N * @min_io_size.
+ *
+ * The @max_write_size field is always greater or equivalent to @min_io_size.
+ * E.g., some NOR flashes may have (@min_io_size = 1, @max_write_size = 64). In
+ * contrast, NAND flashes usually have @min_io_size = @max_write_size = NAND
+ * page size.
  */
 struct ubi_device_info {
        int ubi_num;
        int leb_size;
        int min_io_size;
+       int max_write_size;
        int ro_mode;
        dev_t cdev;
 };