Lines Matching +full:erase +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright © 2002-2010 David Woodhouse <dwmw2@infradead.org>
16 #include <linux/backing-dev.h>
36 * how to calculate the size required for the above structure,
61 for (i = 0; i < concat->num_subdev; i++) { in concat_read()
62 struct mtd_info *subdev = concat->subdev[i]; in concat_read()
63 size_t size, retsize; in concat_read() local
65 if (from >= subdev->size) { in concat_read()
67 size = 0; in concat_read()
68 from -= subdev->size; in concat_read()
71 if (from + len > subdev->size) in concat_read()
73 size = subdev->size - from; in concat_read()
76 size = len; in concat_read()
78 err = mtd_read(subdev, from, size, &retsize, buf); in concat_read()
83 mtd->ecc_stats.failed++; in concat_read()
86 mtd->ecc_stats.corrected++; in concat_read()
87 /* Do not overwrite -EBADMSG !! */ in concat_read()
95 len -= size; in concat_read()
99 buf += size; in concat_read()
102 return -EINVAL; in concat_read()
110 int err = -EINVAL; in concat_panic_write()
112 for (i = 0; i < concat->num_subdev; i++) { in concat_panic_write()
113 struct mtd_info *subdev = concat->subdev[i]; in concat_panic_write()
114 size_t size, retsize; in concat_panic_write() local
116 if (to >= subdev->size) { in concat_panic_write()
117 to -= subdev->size; in concat_panic_write()
120 if (to + len > subdev->size) in concat_panic_write()
121 size = subdev->size - to; in concat_panic_write()
123 size = len; in concat_panic_write()
125 err = mtd_panic_write(subdev, to, size, &retsize, buf); in concat_panic_write()
126 if (err == -EOPNOTSUPP) { in concat_panic_write()
134 len -= size; in concat_panic_write()
138 err = -EINVAL; in concat_panic_write()
139 buf += size; in concat_panic_write()
151 int err = -EINVAL; in concat_write()
154 for (i = 0; i < concat->num_subdev; i++) { in concat_write()
155 struct mtd_info *subdev = concat->subdev[i]; in concat_write()
156 size_t size, retsize; in concat_write() local
158 if (to >= subdev->size) { in concat_write()
159 size = 0; in concat_write()
160 to -= subdev->size; in concat_write()
163 if (to + len > subdev->size) in concat_write()
164 size = subdev->size - to; in concat_write()
166 size = len; in concat_write()
168 err = mtd_write(subdev, to, size, &retsize, buf); in concat_write()
173 len -= size; in concat_write()
177 err = -EINVAL; in concat_write()
178 buf += size; in concat_write()
193 int err = -EINVAL; in concat_writev()
200 if (mtd->writesize > 1) { in concat_writev()
202 if (do_div(__to, mtd->writesize) || (total_len % mtd->writesize)) in concat_writev()
203 return -EINVAL; in concat_writev()
209 return -ENOMEM; in concat_writev()
212 for (i = 0; i < concat->num_subdev; i++) { in concat_writev()
213 struct mtd_info *subdev = concat->subdev[i]; in concat_writev()
214 size_t size, wsize, retsize, old_iov_len; in concat_writev() local
216 if (to >= subdev->size) { in concat_writev()
217 to -= subdev->size; in concat_writev()
221 size = min_t(uint64_t, total_len, subdev->size - to); in concat_writev()
222 wsize = size; /* store for future use */ in concat_writev()
226 if (size <= vecs_copy[entry_high].iov_len) in concat_writev()
228 size -= vecs_copy[entry_high++].iov_len; in concat_writev()
232 vecs_copy[entry_high].iov_len = size; in concat_writev()
235 entry_high - entry_low + 1, to, &retsize); in concat_writev()
237 vecs_copy[entry_high].iov_len = old_iov_len - size; in concat_writev()
238 vecs_copy[entry_high].iov_base += size; in concat_writev()
246 total_len -= wsize; in concat_writev()
251 err = -EINVAL; in concat_writev()
266 ops->retlen = ops->oobretlen = 0; in concat_read_oob()
268 for (i = 0; i < concat->num_subdev; i++) { in concat_read_oob()
269 struct mtd_info *subdev = concat->subdev[i]; in concat_read_oob()
271 if (from >= subdev->size) { in concat_read_oob()
272 from -= subdev->size; in concat_read_oob()
277 if (from + devops.len > subdev->size) in concat_read_oob()
278 devops.len = subdev->size - from; in concat_read_oob()
281 ops->retlen += devops.retlen; in concat_read_oob()
282 ops->oobretlen += devops.oobretlen; in concat_read_oob()
287 mtd->ecc_stats.failed++; in concat_read_oob()
290 mtd->ecc_stats.corrected++; in concat_read_oob()
291 /* Do not overwrite -EBADMSG !! */ in concat_read_oob()
299 devops.len = ops->len - ops->retlen; in concat_read_oob()
305 devops.ooblen = ops->ooblen - ops->oobretlen; in concat_read_oob()
308 devops.oobbuf += ops->oobretlen; in concat_read_oob()
313 return -EINVAL; in concat_read_oob()
323 if (!(mtd->flags & MTD_WRITEABLE)) in concat_write_oob()
324 return -EROFS; in concat_write_oob()
326 ops->retlen = ops->oobretlen = 0; in concat_write_oob()
328 for (i = 0; i < concat->num_subdev; i++) { in concat_write_oob()
329 struct mtd_info *subdev = concat->subdev[i]; in concat_write_oob()
331 if (to >= subdev->size) { in concat_write_oob()
332 to -= subdev->size; in concat_write_oob()
337 if (to + devops.len > subdev->size) in concat_write_oob()
338 devops.len = subdev->size - to; in concat_write_oob()
341 ops->retlen += devops.retlen; in concat_write_oob()
342 ops->oobretlen += devops.oobretlen; in concat_write_oob()
347 devops.len = ops->len - ops->retlen; in concat_write_oob()
353 devops.ooblen = ops->ooblen - ops->oobretlen; in concat_write_oob()
360 return -EINVAL; in concat_write_oob()
369 struct erase_info *erase; in concat_erase() local
372 * Check for proper erase block alignment of the to-be-erased area. in concat_erase()
373 * It is easier to do this based on the super device's erase in concat_erase()
374 * region info rather than looking at each particular sub-device in concat_erase()
377 if (!concat->mtd.numeraseregions) { in concat_erase()
378 /* the easy case: device has uniform erase block size */ in concat_erase()
379 if (instr->addr & (concat->mtd.erasesize - 1)) in concat_erase()
380 return -EINVAL; in concat_erase()
381 if (instr->len & (concat->mtd.erasesize - 1)) in concat_erase()
382 return -EINVAL; in concat_erase()
384 /* device has variable erase size */ in concat_erase()
386 concat->mtd.eraseregions; in concat_erase()
389 * Find the erase region where the to-be-erased area begins: in concat_erase()
391 for (i = 0; i < concat->mtd.numeraseregions && in concat_erase()
392 instr->addr >= erase_regions[i].offset; i++) ; in concat_erase()
393 --i; in concat_erase()
397 * to-be-erased area begins. Verify that the starting in concat_erase()
398 * offset is aligned to this region's erase size: in concat_erase()
400 if (i < 0 || instr->addr & (erase_regions[i].erasesize - 1)) in concat_erase()
401 return -EINVAL; in concat_erase()
404 * now find the erase region where the to-be-erased area ends: in concat_erase()
406 for (; i < concat->mtd.numeraseregions && in concat_erase()
407 (instr->addr + instr->len) >= erase_regions[i].offset; in concat_erase()
409 --i; in concat_erase()
411 * check if the ending offset is aligned to this region's erase size in concat_erase()
413 if (i < 0 || ((instr->addr + instr->len) & in concat_erase()
414 (erase_regions[i].erasesize - 1))) in concat_erase()
415 return -EINVAL; in concat_erase()
419 erase = kmalloc(sizeof (struct erase_info), GFP_KERNEL); in concat_erase()
421 if (!erase) in concat_erase()
422 return -ENOMEM; in concat_erase()
424 *erase = *instr; in concat_erase()
425 length = instr->len; in concat_erase()
428 * find the subdevice where the to-be-erased area begins, adjust in concat_erase()
431 for (i = 0; i < concat->num_subdev; i++) { in concat_erase()
432 subdev = concat->subdev[i]; in concat_erase()
433 if (subdev->size <= erase->addr) { in concat_erase()
434 erase->addr -= subdev->size; in concat_erase()
435 offset += subdev->size; in concat_erase()
441 /* must never happen since size limit has been verified above */ in concat_erase()
442 BUG_ON(i >= concat->num_subdev); in concat_erase()
444 /* now do the erase: */ in concat_erase()
448 subdev = concat->subdev[i]; /* get current subdevice */ in concat_erase()
450 /* limit length to subdevice's size: */ in concat_erase()
451 if (erase->addr + length > subdev->size) in concat_erase()
452 erase->len = subdev->size - erase->addr; in concat_erase()
454 erase->len = length; in concat_erase()
456 length -= erase->len; in concat_erase()
457 if ((err = mtd_erase(subdev, erase))) { in concat_erase()
460 BUG_ON(err == -EINVAL); in concat_erase()
461 if (erase->fail_addr != MTD_FAIL_ADDR_UNKNOWN) in concat_erase()
462 instr->fail_addr = erase->fail_addr + offset; in concat_erase()
466 * erase->addr specifies the offset of the area to be in concat_erase()
468 * non-zero only the first time through this loop, i.e. in concat_erase()
473 erase->addr = 0; in concat_erase()
474 offset += subdev->size; in concat_erase()
476 kfree(erase); in concat_erase()
485 int i, err = -EINVAL; in concat_xxlock()
487 for (i = 0; i < concat->num_subdev; i++) { in concat_xxlock()
488 struct mtd_info *subdev = concat->subdev[i]; in concat_xxlock()
489 uint64_t size; in concat_xxlock() local
491 if (ofs >= subdev->size) { in concat_xxlock()
492 size = 0; in concat_xxlock()
493 ofs -= subdev->size; in concat_xxlock()
496 if (ofs + len > subdev->size) in concat_xxlock()
497 size = subdev->size - ofs; in concat_xxlock()
499 size = len; in concat_xxlock()
502 err = mtd_lock(subdev, ofs, size); in concat_xxlock()
504 err = mtd_unlock(subdev, ofs, size); in concat_xxlock()
508 len -= size; in concat_xxlock()
512 err = -EINVAL; in concat_xxlock()
532 int i, err = -EINVAL; in concat_is_locked()
534 for (i = 0; i < concat->num_subdev; i++) { in concat_is_locked()
535 struct mtd_info *subdev = concat->subdev[i]; in concat_is_locked()
537 if (ofs >= subdev->size) { in concat_is_locked()
538 ofs -= subdev->size; in concat_is_locked()
542 if (ofs + len > subdev->size) in concat_is_locked()
556 for (i = 0; i < concat->num_subdev; i++) { in concat_sync()
557 struct mtd_info *subdev = concat->subdev[i]; in concat_sync()
567 for (i = 0; i < concat->num_subdev; i++) { in concat_suspend()
568 struct mtd_info *subdev = concat->subdev[i]; in concat_suspend()
580 for (i = 0; i < concat->num_subdev; i++) { in concat_resume()
581 struct mtd_info *subdev = concat->subdev[i]; in concat_resume()
591 if (!mtd_can_have_bb(concat->subdev[0])) in concat_block_isbad()
594 for (i = 0; i < concat->num_subdev; i++) { in concat_block_isbad()
595 struct mtd_info *subdev = concat->subdev[i]; in concat_block_isbad()
597 if (ofs >= subdev->size) { in concat_block_isbad()
598 ofs -= subdev->size; in concat_block_isbad()
612 int i, err = -EINVAL; in concat_block_markbad()
614 for (i = 0; i < concat->num_subdev; i++) { in concat_block_markbad()
615 struct mtd_info *subdev = concat->subdev[i]; in concat_block_markbad()
617 if (ofs >= subdev->size) { in concat_block_markbad()
618 ofs -= subdev->size; in concat_block_markbad()
624 mtd->ecc_stats.badblocks++; in concat_block_markbad()
642 size_t size; in mtd_concat_create() local
651 printk(KERN_NOTICE "(%d): \"%s\"\n", i, subdev[i]->name); in mtd_concat_create()
655 size = SIZEOF_STRUCT_MTD_CONCAT(num_devs); in mtd_concat_create()
656 concat = kzalloc(size, GFP_KERNEL); in mtd_concat_create()
663 concat->subdev = (struct mtd_info **) (concat + 1); in mtd_concat_create()
669 concat->mtd.type = subdev[0]->type; in mtd_concat_create()
670 concat->mtd.flags = subdev[0]->flags; in mtd_concat_create()
671 concat->mtd.size = subdev[0]->size; in mtd_concat_create()
672 concat->mtd.erasesize = subdev[0]->erasesize; in mtd_concat_create()
673 concat->mtd.writesize = subdev[0]->writesize; in mtd_concat_create()
676 if (max_writebufsize < subdev[i]->writebufsize) in mtd_concat_create()
677 max_writebufsize = subdev[i]->writebufsize; in mtd_concat_create()
678 concat->mtd.writebufsize = max_writebufsize; in mtd_concat_create()
680 concat->mtd.subpage_sft = subdev[0]->subpage_sft; in mtd_concat_create()
681 concat->mtd.oobsize = subdev[0]->oobsize; in mtd_concat_create()
682 concat->mtd.oobavail = subdev[0]->oobavail; in mtd_concat_create()
685 if (subdev_master->_writev) in mtd_concat_create()
686 concat->mtd._writev = concat_writev; in mtd_concat_create()
687 if (subdev_master->_read_oob) in mtd_concat_create()
688 concat->mtd._read_oob = concat_read_oob; in mtd_concat_create()
689 if (subdev_master->_write_oob) in mtd_concat_create()
690 concat->mtd._write_oob = concat_write_oob; in mtd_concat_create()
691 if (subdev_master->_block_isbad) in mtd_concat_create()
692 concat->mtd._block_isbad = concat_block_isbad; in mtd_concat_create()
693 if (subdev_master->_block_markbad) in mtd_concat_create()
694 concat->mtd._block_markbad = concat_block_markbad; in mtd_concat_create()
695 if (subdev_master->_panic_write) in mtd_concat_create()
696 concat->mtd._panic_write = concat_panic_write; in mtd_concat_create()
697 if (subdev_master->_read) in mtd_concat_create()
698 concat->mtd._read = concat_read; in mtd_concat_create()
699 if (subdev_master->_write) in mtd_concat_create()
700 concat->mtd._write = concat_write; in mtd_concat_create()
702 concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks; in mtd_concat_create()
704 concat->subdev[0] = subdev[0]; in mtd_concat_create()
707 if (concat->mtd.type != subdev[i]->type) { in mtd_concat_create()
710 subdev[i]->name); in mtd_concat_create()
713 if (concat->mtd.flags != subdev[i]->flags) { in mtd_concat_create()
718 if ((concat->mtd.flags ^ subdev[i]-> in mtd_concat_create()
722 subdev[i]->name); in mtd_concat_create()
727 concat->mtd.flags |= in mtd_concat_create()
728 subdev[i]->flags & MTD_WRITEABLE; in mtd_concat_create()
732 concat->mtd.size += subdev[i]->size; in mtd_concat_create()
733 concat->mtd.ecc_stats.badblocks += in mtd_concat_create()
734 subdev[i]->ecc_stats.badblocks; in mtd_concat_create()
735 if (concat->mtd.writesize != subdev[i]->writesize || in mtd_concat_create()
736 concat->mtd.subpage_sft != subdev[i]->subpage_sft || in mtd_concat_create()
737 concat->mtd.oobsize != subdev[i]->oobsize || in mtd_concat_create()
738 !concat->mtd._read_oob != !subdev_master->_read_oob || in mtd_concat_create()
739 !concat->mtd._write_oob != !subdev_master->_write_oob) { in mtd_concat_create()
749 subdev[i]->name); in mtd_concat_create()
752 concat->subdev[i] = subdev[i]; in mtd_concat_create()
756 mtd_set_ooblayout(&concat->mtd, subdev[0]->ooblayout); in mtd_concat_create()
758 concat->num_subdev = num_devs; in mtd_concat_create()
759 concat->mtd.name = name; in mtd_concat_create()
761 concat->mtd._erase = concat_erase; in mtd_concat_create()
762 concat->mtd._sync = concat_sync; in mtd_concat_create()
763 concat->mtd._lock = concat_lock; in mtd_concat_create()
764 concat->mtd._unlock = concat_unlock; in mtd_concat_create()
765 concat->mtd._is_locked = concat_is_locked; in mtd_concat_create()
766 concat->mtd._suspend = concat_suspend; in mtd_concat_create()
767 concat->mtd._resume = concat_resume; in mtd_concat_create()
770 * Combine the erase block size info of the subdevices: in mtd_concat_create()
773 * many changes in erase size we have in mtd_concat_create()
775 max_erasesize = curr_erasesize = subdev[0]->erasesize; in mtd_concat_create()
778 if (subdev[i]->numeraseregions == 0) { in mtd_concat_create()
779 /* current subdevice has uniform erase size */ in mtd_concat_create()
780 if (subdev[i]->erasesize != curr_erasesize) { in mtd_concat_create()
781 /* if it differs from the last subdevice's erase size, count it */ in mtd_concat_create()
783 curr_erasesize = subdev[i]->erasesize; in mtd_concat_create()
788 /* current subdevice has variable erase size */ in mtd_concat_create()
790 for (j = 0; j < subdev[i]->numeraseregions; j++) { in mtd_concat_create()
792 /* walk the list of erase regions, count any changes */ in mtd_concat_create()
793 if (subdev[i]->eraseregions[j].erasesize != in mtd_concat_create()
797 subdev[i]->eraseregions[j]. in mtd_concat_create()
808 * All subdevices have the same uniform erase size. in mtd_concat_create()
811 concat->mtd.erasesize = curr_erasesize; in mtd_concat_create()
812 concat->mtd.numeraseregions = 0; in mtd_concat_create()
817 * erase block size varies across the subdevices: allocate in mtd_concat_create()
818 * space to store the data describing the variable erase regions in mtd_concat_create()
823 concat->mtd.erasesize = max_erasesize; in mtd_concat_create()
824 concat->mtd.numeraseregions = num_erase_region; in mtd_concat_create()
825 concat->mtd.eraseregions = erase_region_p = in mtd_concat_create()
832 ("memory allocation error while creating erase region list" in mtd_concat_create()
839 * erase region info: in mtd_concat_create()
841 curr_erasesize = subdev[0]->erasesize; in mtd_concat_create()
844 if (subdev[i]->numeraseregions == 0) { in mtd_concat_create()
845 /* current subdevice has uniform erase size */ in mtd_concat_create()
846 if (subdev[i]->erasesize != curr_erasesize) { in mtd_concat_create()
851 erase_region_p->offset = begin; in mtd_concat_create()
852 erase_region_p->erasesize = in mtd_concat_create()
854 tmp64 = position - begin; in mtd_concat_create()
856 erase_region_p->numblocks = tmp64; in mtd_concat_create()
859 curr_erasesize = subdev[i]->erasesize; in mtd_concat_create()
862 position += subdev[i]->size; in mtd_concat_create()
864 /* current subdevice has variable erase size */ in mtd_concat_create()
866 for (j = 0; j < subdev[i]->numeraseregions; j++) { in mtd_concat_create()
867 /* walk the list of erase regions, count any changes */ in mtd_concat_create()
868 if (subdev[i]->eraseregions[j]. in mtd_concat_create()
870 erase_region_p->offset = begin; in mtd_concat_create()
871 erase_region_p->erasesize = in mtd_concat_create()
873 tmp64 = position - begin; in mtd_concat_create()
875 erase_region_p->numblocks = tmp64; in mtd_concat_create()
879 subdev[i]->eraseregions[j]. in mtd_concat_create()
884 subdev[i]->eraseregions[j]. in mtd_concat_create()
890 erase_region_p->offset = begin; in mtd_concat_create()
891 erase_region_p->erasesize = curr_erasesize; in mtd_concat_create()
892 tmp64 = position - begin; in mtd_concat_create()
894 erase_region_p->numblocks = tmp64; in mtd_concat_create()
897 return &concat->mtd; in mtd_concat_create()
904 if (concat->mtd.numeraseregions) in mtd_concat_destroy()
905 kfree(concat->mtd.eraseregions); in mtd_concat_destroy()