Lines Matching full:mtd
8 #include <linux/mtd/mtd.h>
16 struct mtd_info *mtd; member
30 struct mtd_info *mtd = cxt->mtd; in mtdpstore_block_isbad() local
33 off = ALIGN_DOWN(off, mtd->erasesize); in mtdpstore_block_isbad()
34 blknum = div_u64(off, mtd->erasesize); in mtdpstore_block_isbad()
38 ret = mtd_block_isbad(mtd, off); in mtdpstore_block_isbad()
40 dev_err(&mtd->dev, "mtd_block_isbad failed, aborting\n"); in mtdpstore_block_isbad()
52 struct mtd_info *mtd = cxt->mtd; in mtdpstore_panic_block_isbad() local
55 off = ALIGN_DOWN(off, mtd->erasesize); in mtdpstore_panic_block_isbad()
56 blknum = div_u64(off, mtd->erasesize); in mtdpstore_panic_block_isbad()
63 struct mtd_info *mtd = cxt->mtd; in mtdpstore_mark_used() local
66 dev_dbg(&mtd->dev, "mark zone %llu used\n", zonenum); in mtdpstore_mark_used()
73 struct mtd_info *mtd = cxt->mtd; in mtdpstore_mark_unused() local
76 dev_dbg(&mtd->dev, "mark zone %llu unused\n", zonenum); in mtdpstore_mark_unused()
83 struct mtd_info *mtd = cxt->mtd; in mtdpstore_block_mark_unused() local
84 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size; in mtdpstore_block_mark_unused()
87 off = ALIGN_DOWN(off, mtd->erasesize); in mtdpstore_block_mark_unused()
90 dev_dbg(&mtd->dev, "mark zone %llu unused\n", zonenum); in mtdpstore_block_mark_unused()
100 u64 blknum = div_u64(off, cxt->mtd->erasesize); in mtdpstore_is_used()
110 struct mtd_info *mtd = cxt->mtd; in mtdpstore_block_is_used() local
111 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size; in mtdpstore_block_is_used()
114 off = ALIGN_DOWN(off, mtd->erasesize); in mtdpstore_block_is_used()
128 struct mtd_info *mtd = cxt->mtd; in mtdpstore_is_empty() local
132 sz = min_t(uint32_t, size, mtd->writesize / 4); in mtdpstore_is_empty()
142 struct mtd_info *mtd = cxt->mtd; in mtdpstore_mark_removed() local
145 dev_dbg(&mtd->dev, "mark zone %llu removed\n", zonenum); in mtdpstore_mark_removed()
152 struct mtd_info *mtd = cxt->mtd; in mtdpstore_block_clear_removed() local
153 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size; in mtdpstore_block_clear_removed()
156 off = ALIGN_DOWN(off, mtd->erasesize); in mtdpstore_block_clear_removed()
168 struct mtd_info *mtd = cxt->mtd; in mtdpstore_block_is_removed() local
169 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size; in mtdpstore_block_is_removed()
172 off = ALIGN_DOWN(off, mtd->erasesize); in mtdpstore_block_is_removed()
185 struct mtd_info *mtd = cxt->mtd; in mtdpstore_erase_do() local
189 off = ALIGN_DOWN(off, cxt->mtd->erasesize); in mtdpstore_erase_do()
190 dev_dbg(&mtd->dev, "try to erase off 0x%llx\n", off); in mtdpstore_erase_do()
191 erase.len = cxt->mtd->erasesize; in mtdpstore_erase_do()
193 ret = mtd_erase(cxt->mtd, &erase); in mtdpstore_erase_do()
197 dev_err(&mtd->dev, "erase of region [0x%llx, 0x%llx] on \"%s\" failed\n", in mtdpstore_erase_do()
240 struct mtd_info *mtd = cxt->mtd; in mtdpstore_security() local
242 u32 zonecnt = (u32)div_u64(cxt->mtd->size, cxt->info.kmsg_size); in mtdpstore_security()
243 u32 blkcnt = (u32)div_u64(cxt->mtd->size, cxt->mtd->erasesize); in mtdpstore_security()
244 u32 erasesize = cxt->mtd->erasesize; in mtdpstore_security()
256 div64_u64_rem(off + erasesize, cxt->mtd->size, (u64 *)&off); in mtdpstore_security()
269 dev_err(&mtd->dev, "all blocks bad!\n"); in mtdpstore_security()
270 dev_dbg(&mtd->dev, "end security\n"); in mtdpstore_security()
277 struct mtd_info *mtd = cxt->mtd; in mtdpstore_write() local
288 dev_dbg(&mtd->dev, "try to write off 0x%llx size %zu\n", off, size); in mtdpstore_write()
289 ret = mtd_write(cxt->mtd, off, size, &retlen, (u_char *)buf); in mtdpstore_write()
291 dev_err(&mtd->dev, "write failure at %lld (%zu of %zu written), err %d\n", in mtdpstore_write()
313 struct mtd_info *mtd = cxt->mtd; in mtdpstore_read() local
320 dev_dbg(&mtd->dev, "try to read off 0x%llx size %zu\n", off, size); in mtdpstore_read()
324 ret = mtd_read(cxt->mtd, off + done, size - done, &retlen, in mtdpstore_read()
327 dev_err(&mtd->dev, "read failure at %lld (%zu of %zu read), err %d\n", in mtdpstore_read()
340 dev_err(&mtd->dev, "ecc error at %lld (%zu of %zu read), err %d\n", in mtdpstore_read()
359 struct mtd_info *mtd = cxt->mtd; in mtdpstore_panic_write() local
370 ret = mtd_panic_write(cxt->mtd, off, size, &retlen, (u_char *)buf); in mtdpstore_panic_write()
372 dev_err(&mtd->dev, "panic write failure at %lld (%zu of %zu read), err %d\n", in mtdpstore_panic_write()
381 static void mtdpstore_notify_add(struct mtd_info *mtd) in mtdpstore_notify_add() argument
388 if (!strcmp(mtd->name, info->device)) in mtdpstore_notify_add()
389 cxt->index = mtd->index; in mtdpstore_notify_add()
391 if (mtd->index != cxt->index || cxt->index < 0) in mtdpstore_notify_add()
394 dev_dbg(&mtd->dev, "found matching MTD device %s\n", mtd->name); in mtdpstore_notify_add()
396 if (mtd->size < info->kmsg_size * 2) { in mtdpstore_notify_add()
397 dev_err(&mtd->dev, "MTD partition %d not big enough\n", in mtdpstore_notify_add()
398 mtd->index); in mtdpstore_notify_add()
407 if (mtd->erasesize < info->kmsg_size) { in mtdpstore_notify_add()
408 dev_err(&mtd->dev, "eraseblock size of MTD partition %d too small\n", in mtdpstore_notify_add()
409 mtd->index); in mtdpstore_notify_add()
412 if (unlikely(info->kmsg_size % mtd->writesize)) { in mtdpstore_notify_add()
413 dev_err(&mtd->dev, "record size %lu KB must align to write size %d KB\n", in mtdpstore_notify_add()
415 mtd->writesize / 1024); in mtdpstore_notify_add()
419 longcnt = BITS_TO_LONGS(div_u64(mtd->size, info->kmsg_size)); in mtdpstore_notify_add()
423 longcnt = BITS_TO_LONGS(div_u64(mtd->size, mtd->erasesize)); in mtdpstore_notify_add()
426 cxt->dev.total_size = mtd->size; in mtdpstore_notify_add()
436 dev_err(&mtd->dev, "mtd%d register to psblk failed\n", in mtdpstore_notify_add()
437 mtd->index); in mtdpstore_notify_add()
440 cxt->mtd = mtd; in mtdpstore_notify_add()
441 dev_info(&mtd->dev, "Attached to MTD device %d\n", mtd->index); in mtdpstore_notify_add()
447 struct mtd_info *mtd = cxt->mtd; in mtdpstore_flush_removed_do() local
453 buf = kmalloc(mtd->erasesize, GFP_KERNEL); in mtdpstore_flush_removed_do()
458 ret = mtd_read(mtd, off, mtd->erasesize, &retlen, buf); in mtdpstore_flush_removed_do()
463 erase.len = mtd->erasesize; in mtdpstore_flush_removed_do()
465 ret = mtd_erase(mtd, &erase); in mtdpstore_flush_removed_do()
475 ret = mtd_write(mtd, off, zonesize, &retlen, buf); in mtdpstore_flush_removed_do()
477 dev_err(&mtd->dev, "write failure at %lld (%zu of %u written), err %d\n", in mtdpstore_flush_removed_do()
499 struct mtd_info *mtd = cxt->mtd; in mtdpstore_flush_removed() local
502 u32 blkcnt = (u32)div_u64(mtd->size, mtd->erasesize); in mtdpstore_flush_removed()
504 for (off = 0; blkcnt > 0; blkcnt--, off += mtd->erasesize) { in mtdpstore_flush_removed()
513 ret = mtdpstore_flush_removed_do(cxt, off, mtd->erasesize); in mtdpstore_flush_removed()
520 static void mtdpstore_notify_remove(struct mtd_info *mtd) in mtdpstore_notify_remove() argument
524 if (mtd->index != cxt->index || cxt->index < 0) in mtdpstore_notify_remove()
533 cxt->mtd = NULL; in mtdpstore_notify_remove()
553 pr_err("mtd device must be supplied (device name is empty)\n"); in mtdpstore_init()
561 /* Setup the MTD device to use */ in mtdpstore_init()
579 MODULE_DESCRIPTION("MTD backend for pstore/blk");