Lines Matching full:mtd
8 #include <linux/mtd/mtd.h>
16 struct mtd_info *mtd;
30 struct mtd_info *mtd = cxt->mtd;
33 off = ALIGN_DOWN(off, mtd->erasesize);
34 blknum = div_u64(off, mtd->erasesize);
38 ret = mtd_block_isbad(mtd, off);
40 dev_err(&mtd->dev, "mtd_block_isbad failed, aborting\n");
52 struct mtd_info *mtd = cxt->mtd;
55 off = ALIGN_DOWN(off, mtd->erasesize);
56 blknum = div_u64(off, mtd->erasesize);
63 struct mtd_info *mtd = cxt->mtd;
66 dev_dbg(&mtd->dev, "mark zone %llu used\n", zonenum);
73 struct mtd_info *mtd = cxt->mtd;
76 dev_dbg(&mtd->dev, "mark zone %llu unused\n", zonenum);
83 struct mtd_info *mtd = cxt->mtd;
84 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size;
87 off = ALIGN_DOWN(off, mtd->erasesize);
90 dev_dbg(&mtd->dev, "mark zone %llu unused\n", zonenum);
100 u64 blknum = div_u64(off, cxt->mtd->erasesize);
110 struct mtd_info *mtd = cxt->mtd;
111 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size;
114 off = ALIGN_DOWN(off, mtd->erasesize);
128 struct mtd_info *mtd = cxt->mtd;
132 sz = min_t(uint32_t, size, mtd->writesize / 4);
142 struct mtd_info *mtd = cxt->mtd;
145 dev_dbg(&mtd->dev, "mark zone %llu removed\n", zonenum);
152 struct mtd_info *mtd = cxt->mtd;
153 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size;
156 off = ALIGN_DOWN(off, mtd->erasesize);
168 struct mtd_info *mtd = cxt->mtd;
169 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size;
172 off = ALIGN_DOWN(off, mtd->erasesize);
185 struct mtd_info *mtd = cxt->mtd;
189 off = ALIGN_DOWN(off, cxt->mtd->erasesize);
190 dev_dbg(&mtd->dev, "try to erase off 0x%llx\n", off);
191 erase.len = cxt->mtd->erasesize;
193 ret = mtd_erase(cxt->mtd, &erase);
197 dev_err(&mtd->dev, "erase of region [0x%llx, 0x%llx] on \"%s\" failed\n",
240 struct mtd_info *mtd = cxt->mtd;
242 u32 zonecnt = (u32)div_u64(cxt->mtd->size, cxt->info.kmsg_size);
243 u32 blkcnt = (u32)div_u64(cxt->mtd->size, cxt->mtd->erasesize);
244 u32 erasesize = cxt->mtd->erasesize;
256 div64_u64_rem(off + erasesize, cxt->mtd->size, (u64 *)&off);
269 dev_err(&mtd->dev, "all blocks bad!\n");
270 dev_dbg(&mtd->dev, "end security\n");
277 struct mtd_info *mtd = cxt->mtd;
288 dev_dbg(&mtd->dev, "try to write off 0x%llx size %zu\n", off, size);
289 ret = mtd_write(cxt->mtd, off, size, &retlen, (u_char *)buf);
291 dev_err(&mtd->dev, "write failure at %lld (%zu of %zu written), err %d\n",
313 struct mtd_info *mtd = cxt->mtd;
320 dev_dbg(&mtd->dev, "try to read off 0x%llx size %zu\n", off, size);
324 ret = mtd_read(cxt->mtd, off + done, size - done, &retlen,
327 dev_err(&mtd->dev, "read failure at %lld (%zu of %zu read), err %d\n",
340 dev_err(&mtd->dev, "ecc error at %lld (%zu of %zu read), err %d\n",
359 struct mtd_info *mtd = cxt->mtd;
370 ret = mtd_panic_write(cxt->mtd, off, size, &retlen, (u_char *)buf);
372 dev_err(&mtd->dev, "panic write failure at %lld (%zu of %zu read), err %d\n",
381 static void mtdpstore_notify_add(struct mtd_info *mtd)
388 if (!strcmp(mtd->name, info->device))
389 cxt->index = mtd->index;
391 if (mtd->index != cxt->index || cxt->index < 0)
394 dev_dbg(&mtd->dev, "found matching MTD device %s\n", mtd->name);
396 if (mtd->size < info->kmsg_size * 2) {
397 dev_err(&mtd->dev, "MTD partition %d not big enough\n",
398 mtd->index);
407 if (mtd->erasesize < info->kmsg_size) {
408 dev_err(&mtd->dev, "eraseblock size of MTD partition %d too small\n",
409 mtd->index);
412 if (unlikely(info->kmsg_size % mtd->writesize)) {
413 dev_err(&mtd->dev, "record size %lu KB must align to write size %d KB\n",
415 mtd->writesize / 1024);
419 longcnt = BITS_TO_LONGS(div_u64(mtd->size, info->kmsg_size));
420 cxt->rmmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL);
421 cxt->usedmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL);
423 longcnt = BITS_TO_LONGS(div_u64(mtd->size, mtd->erasesize));
424 cxt->badmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL);
435 cxt->dev.zone.total_size = mtd->size;
439 dev_err(&mtd->dev, "mtd%d register to psblk failed\n",
440 mtd->index);
443 cxt->mtd = mtd;
444 dev_info(&mtd->dev, "Attached to MTD device %d\n", mtd->index);
450 struct mtd_info *mtd = cxt->mtd;
456 buf = kmalloc(mtd->erasesize, GFP_KERNEL);
461 ret = mtd_read(mtd, off, mtd->erasesize, &retlen, buf);
466 erase.len = mtd->erasesize;
468 ret = mtd_erase(mtd, &erase);
478 ret = mtd_write(mtd, off, zonesize, &retlen, buf);
480 dev_err(&mtd->dev, "write failure at %lld (%zu of %u written), err %d\n",
502 struct mtd_info *mtd = cxt->mtd;
505 u32 blkcnt = (u32)div_u64(mtd->size, mtd->erasesize);
507 for (off = 0; blkcnt > 0; blkcnt--, off += mtd->erasesize) {
516 ret = mtdpstore_flush_removed_do(cxt, off, mtd->erasesize);
523 static void mtdpstore_notify_remove(struct mtd_info *mtd)
527 if (mtd->index != cxt->index || cxt->index < 0)
533 cxt->mtd = NULL;
553 pr_err("mtd device must be supplied (device name is empty)\n");
561 /* Setup the MTD device to use */
579 MODULE_DESCRIPTION("MTD backend for pstore/blk");