Skip to content

Commit 30b542e

Browse files
Artem BityutskiyArtem Bityutskiy
authored andcommitted
UBI: incorporate maximum write size
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>
1 parent 10ac279 commit 30b542e

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎drivers/mtd/ubi/build.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,11 +690,25 @@ static int io_init(struct ubi_device *ubi)
690690
ubi_assert(ubi->hdrs_min_io_size <= ubi->min_io_size);
691691
ubi_assert(ubi->min_io_size % ubi->hdrs_min_io_size == 0);
692692

693+
ubi->max_write_size = ubi->mtd->writebufsize;
694+
/*
695+
* Maximum write size has to be greater or equivalent to min. I/O
696+
* size, and be multiple of min. I/O size.
697+
*/
698+
if (ubi->max_write_size < ubi->min_io_size ||
699+
ubi->max_write_size % ubi->min_io_size ||
700+
!is_power_of_2(ubi->max_write_size)) {
701+
ubi_err("bad write buffer size %d for %d min. I/O unit",
702+
ubi->max_write_size, ubi->min_io_size);
703+
return -EINVAL;
704+
}
705+
693706
/* Calculate default aligned sizes of EC and VID headers */
694707
ubi->ec_hdr_alsize = ALIGN(UBI_EC_HDR_SIZE, ubi->hdrs_min_io_size);
695708
ubi->vid_hdr_alsize = ALIGN(UBI_VID_HDR_SIZE, ubi->hdrs_min_io_size);
696709

697710
dbg_msg("min_io_size %d", ubi->min_io_size);
711+
dbg_msg("max_write_size %d", ubi->max_write_size);
698712
dbg_msg("hdrs_min_io_size %d", ubi->hdrs_min_io_size);
699713
dbg_msg("ec_hdr_alsize %d", ubi->ec_hdr_alsize);
700714
dbg_msg("vid_hdr_alsize %d", ubi->vid_hdr_alsize);

‎drivers/mtd/ubi/kapi.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di)
4141
di->ubi_num = ubi->ubi_num;
4242
di->leb_size = ubi->leb_size;
4343
di->min_io_size = ubi->min_io_size;
44+
di->max_write_size = ubi->max_write_size;
4445
di->ro_mode = ubi->ro_mode;
4546
di->cdev = ubi->cdev.dev;
4647
}

‎drivers/mtd/ubi/ubi.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ struct ubi_wl_entry;
381381
* @bad_allowed: whether the MTD device admits of bad physical eraseblocks or
382382
* not
383383
* @nor_flash: non-zero if working on top of NOR flash
384+
* @max_write_size: maximum amount of bytes the underlying flash can write at a
385+
* time (MTD write buffer size)
384386
* @mtd: MTD device descriptor
385387
*
386388
* @peb_buf1: a buffer of PEB size used for different purposes
@@ -464,6 +466,7 @@ struct ubi_device {
464466
int vid_hdr_shift;
465467
unsigned int bad_allowed:1;
466468
unsigned int nor_flash:1;
469+
int max_write_size;
467470
struct mtd_info *mtd;
468471

469472
void *peb_buf1;

‎include/linux/mtd/ubi.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,36 @@ struct ubi_volume_info {
117117
* @ubi_num: ubi device number
118118
* @leb_size: logical eraseblock size on this UBI device
119119
* @min_io_size: minimal I/O unit size
120+
* @max_write_size: maximum amount of bytes the underlying flash can write at a
121+
* time (MTD write buffer size)
120122
* @ro_mode: if this device is in read-only mode
121123
* @cdev: UBI character device major and minor numbers
122124
*
123125
* Note, @leb_size is the logical eraseblock size offered by the UBI device.
124126
* Volumes of this UBI device may have smaller logical eraseblock size if their
125127
* alignment is not equivalent to %1.
128+
*
129+
* The @max_write_size field describes flash write maximum write unit. For
130+
* example, NOR flash allows for changing individual bytes, so @min_io_size is
131+
* %1. However, it does not mean than NOR flash has to write data byte-by-byte.
132+
* Instead, CFI NOR flashes have a write-buffer of, e.g., 64 bytes, and when
133+
* writing large chunks of data, they write 64-bytes at a time. Obviously, this
134+
* improves write throughput.
135+
*
136+
* Also, the MTD device may have N interleaved (striped) flash chips
137+
* underneath, in which case @min_io_size can be physical min. I/O size of
138+
* single flash chip, while @max_write_size can be N * @min_io_size.
139+
*
140+
* The @max_write_size field is always greater or equivalent to @min_io_size.
141+
* E.g., some NOR flashes may have (@min_io_size = 1, @max_write_size = 64). In
142+
* contrast, NAND flashes usually have @min_io_size = @max_write_size = NAND
143+
* page size.
126144
*/
127145
struct ubi_device_info {
128146
int ubi_num;
129147
int leb_size;
130148
int min_io_size;
149+
int max_write_size;
131150
int ro_mode;
132151
dev_t cdev;
133152
};

0 commit comments

Comments
 (0)