medaitek: convert the NAND target to UBI
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.4 / 0072-mtd-backport-v4.7-0day-patches-from-Boris.patch
index ccbf8d0fb23b3b2421031993cfe97300dc58deb2..7e7a5de1c834b9651d52e397ee75c21c38d48e80 100644 (file)
@@ -31,11 +31,6 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  drivers/mtd/tests/mtd_nandecctest.c |    2 +-
  drivers/mtd/tests/oobtest.c         |   49 ++-
  drivers/mtd/tests/pagetest.c        |    3 +-
- drivers/mtd/ubi/cdev.c              |    4 +-
- drivers/mtd/ubi/misc.c              |   49 +++
- drivers/mtd/ubi/ubi.h               |   16 +-
- drivers/mtd/ubi/upd.c               |    2 +-
- drivers/mtd/ubi/wl.c                |   21 +-
  include/linux/mtd/bbm.h             |    1 -
  include/linux/mtd/fsmc.h            |   18 --
  include/linux/mtd/inftl.h           |    1 -
@@ -4654,178 +4649,6 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        addr0 = 0;
        for (i = 0; i < ebcnt && bbt[i]; ++i)
---- a/drivers/mtd/ubi/cdev.c
-+++ b/drivers/mtd/ubi/cdev.c
-@@ -174,9 +174,9 @@ static int vol_cdev_fsync(struct file *f
-       struct ubi_device *ubi = desc->vol->ubi;
-       struct inode *inode = file_inode(file);
-       int err;
--      mutex_lock(&inode->i_mutex);
-+      inode_lock(inode);
-       err = ubi_sync(ubi->ubi_num);
--      mutex_unlock(&inode->i_mutex);
-+      inode_unlock(inode);
-       return err;
- }
---- a/drivers/mtd/ubi/misc.c
-+++ b/drivers/mtd/ubi/misc.c
-@@ -153,3 +153,52 @@ int ubi_check_pattern(const void *buf, u
-                       return 0;
-       return 1;
- }
-+
-+/* Normal UBI messages */
-+void ubi_msg(const struct ubi_device *ubi, const char *fmt, ...)
-+{
-+      struct va_format vaf;
-+      va_list args;
-+
-+      va_start(args, fmt);
-+
-+      vaf.fmt = fmt;
-+      vaf.va = &args;
-+
-+      pr_notice(UBI_NAME_STR "%d: %pV\n", ubi->ubi_num, &vaf);
-+
-+      va_end(args);
-+}
-+
-+/* UBI warning messages */
-+void ubi_warn(const struct ubi_device *ubi, const char *fmt, ...)
-+{
-+      struct va_format vaf;
-+      va_list args;
-+
-+      va_start(args, fmt);
-+
-+      vaf.fmt = fmt;
-+      vaf.va = &args;
-+
-+      pr_warn(UBI_NAME_STR "%d warning: %ps: %pV\n",
-+              ubi->ubi_num, __builtin_return_address(0), &vaf);
-+
-+      va_end(args);
-+}
-+
-+/* UBI error messages */
-+void ubi_err(const struct ubi_device *ubi, const char *fmt, ...)
-+{
-+      struct va_format vaf;
-+      va_list args;
-+
-+      va_start(args, fmt);
-+
-+      vaf.fmt = fmt;
-+      vaf.va = &args;
-+
-+      pr_err(UBI_NAME_STR "%d error: %ps: %pV\n",
-+             ubi->ubi_num, __builtin_return_address(0), &vaf);
-+      va_end(args);
-+}
---- a/drivers/mtd/ubi/ubi.h
-+++ b/drivers/mtd/ubi/ubi.h
-@@ -49,15 +49,19 @@
- /* UBI name used for character devices, sysfs, etc */
- #define UBI_NAME_STR "ubi"
-+struct ubi_device;
-+
- /* Normal UBI messages */
--#define ubi_msg(ubi, fmt, ...) pr_notice(UBI_NAME_STR "%d: " fmt "\n", \
--                                       ubi->ubi_num, ##__VA_ARGS__)
-+__printf(2, 3)
-+void ubi_msg(const struct ubi_device *ubi, const char *fmt, ...);
-+
- /* UBI warning messages */
--#define ubi_warn(ubi, fmt, ...) pr_warn(UBI_NAME_STR "%d warning: %s: " fmt "\n", \
--                                      ubi->ubi_num, __func__, ##__VA_ARGS__)
-+__printf(2, 3)
-+void ubi_warn(const struct ubi_device *ubi, const char *fmt, ...);
-+
- /* UBI error messages */
--#define ubi_err(ubi, fmt, ...) pr_err(UBI_NAME_STR "%d error: %s: " fmt "\n", \
--                                    ubi->ubi_num, __func__, ##__VA_ARGS__)
-+__printf(2, 3)
-+void ubi_err(const struct ubi_device *ubi, const char *fmt, ...);
- /* Background thread name pattern */
- #define UBI_BGT_NAME_PATTERN "ubi_bgt%dd"
---- a/drivers/mtd/ubi/wl.c
-+++ b/drivers/mtd/ubi/wl.c
-@@ -628,6 +628,7 @@ static int do_sync_erase(struct ubi_devi
-       return __erase_worker(ubi, &wl_wrk);
- }
-+static int ensure_wear_leveling(struct ubi_device *ubi, int nested);
- /**
-  * wear_leveling_worker - wear-leveling worker function.
-  * @ubi: UBI device description object
-@@ -649,6 +650,7 @@ static int wear_leveling_worker(struct u
- #endif
-       struct ubi_wl_entry *e1, *e2;
-       struct ubi_vid_hdr *vid_hdr;
-+      int dst_leb_clean = 0;
-       kfree(wrk);
-       if (shutdown)
-@@ -753,6 +755,7 @@ static int wear_leveling_worker(struct u
-       err = ubi_io_read_vid_hdr(ubi, e1->pnum, vid_hdr, 0);
-       if (err && err != UBI_IO_BITFLIPS) {
-+              dst_leb_clean = 1;
-               if (err == UBI_IO_FF) {
-                       /*
-                        * We are trying to move PEB without a VID header. UBI
-@@ -798,10 +801,12 @@ static int wear_leveling_worker(struct u
-                        * protection queue.
-                        */
-                       protect = 1;
-+                      dst_leb_clean = 1;
-                       goto out_not_moved;
-               }
-               if (err == MOVE_RETRY) {
-                       scrubbing = 1;
-+                      dst_leb_clean = 1;
-                       goto out_not_moved;
-               }
-               if (err == MOVE_TARGET_BITFLIPS || err == MOVE_TARGET_WR_ERR ||
-@@ -827,6 +832,7 @@ static int wear_leveling_worker(struct u
-                                       ubi->erroneous_peb_count);
-                               goto out_error;
-                       }
-+                      dst_leb_clean = 1;
-                       erroneous = 1;
-                       goto out_not_moved;
-               }
-@@ -897,15 +903,24 @@ out_not_moved:
-               wl_tree_add(e1, &ubi->scrub);
-       else
-               wl_tree_add(e1, &ubi->used);
-+      if (dst_leb_clean) {
-+              wl_tree_add(e2, &ubi->free);
-+              ubi->free_count++;
-+      }
-+
-       ubi_assert(!ubi->move_to_put);
-       ubi->move_from = ubi->move_to = NULL;
-       ubi->wl_scheduled = 0;
-       spin_unlock(&ubi->wl_lock);
-       ubi_free_vid_hdr(ubi, vid_hdr);
--      err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
--      if (err)
--              goto out_ro;
-+      if (dst_leb_clean) {
-+              ensure_wear_leveling(ubi, 1);
-+      } else {
-+              err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
-+              if (err)
-+                      goto out_ro;
-+      }
-       mutex_unlock(&ubi->move_mutex);
-       return 0;
 --- a/include/linux/mtd/bbm.h
 +++ b/include/linux/mtd/bbm.h
 @@ -166,7 +166,6 @@ struct bbm_info {