Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev Fix badblock checking



details:   https://anonhg.NetBSD.org/src/rev/f96f15fc3d66
branches:  trunk
changeset: 763789:f96f15fc3d66
user:      ahoka <ahoka%NetBSD.org@localhost>
date:      Mon Apr 04 14:25:09 2011 +0000

description:
Fix badblock checking
Replace flash_addr_t with flash_off_t and use it to address flash everywhere

diffstat:

 sys/dev/flash/flash.c   |  31 ++++++++++++---------------
 sys/dev/flash/flash.h   |  30 +++++++++++++-------------
 sys/dev/nand/nand.c     |  53 ++++++++++++++++++++++++------------------------
 sys/dev/nand/nand.h     |  18 ++++++++--------
 sys/dev/nand/nand_bbt.c |  18 ++++++++--------
 sys/dev/nand/nand_bbt.h |  10 ++++----
 sys/dev/nand/nand_io.c  |   4 +-
 7 files changed, 81 insertions(+), 83 deletions(-)

diffs (truncated from 531 to 300 lines):

diff -r 4e7ba4c762f9 -r f96f15fc3d66 sys/dev/flash/flash.c
--- a/sys/dev/flash/flash.c     Mon Apr 04 11:32:25 2011 +0000
+++ b/sys/dev/flash/flash.c     Mon Apr 04 14:25:09 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: flash.c,v 1.2 2011/03/30 14:34:26 uebayasi Exp $       */
+/*     $NetBSD: flash.c,v 1.3 2011/04/04 14:25:09 ahoka Exp $  */
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: flash.c,v 1.2 2011/03/30 14:34:26 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: flash.c,v 1.3 2011/04/04 14:25:09 ahoka Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -88,7 +88,7 @@
 int flash_nsectors(struct buf *bp);
 int flash_sector(struct buf *bp);
 
-static inline off_t flash_get_part_offset(struct flash_softc *fl,
+static inline flash_off_t flash_get_part_offset(struct flash_softc *fl,
     size_t poffset);
 
 int flash_match(device_t parent, cfdata_t match, void *aux);
@@ -405,7 +405,8 @@
        struct flash_softc *sc;
        int unit, err;
        size_t retlen;
-       flash_addr_t offset;
+       flash_off_t offset;
+       bool bad;
 
        unit = minor(dev);
        if ((sc = device_lookup_private(&flash_cd, unit)) == NULL)
@@ -441,15 +442,11 @@
                 */
                bbp = data;
 
-               err = flash_block_isbad(sc->sc_dev, bbp->bbp_addr);
-               if (err == EIO) {
-                       bbp->bbp_isbad = true;
-                       err = 0;
-               } else if (err) {
+               err = flash_block_isbad(sc->sc_dev, bbp->bbp_addr, &bad);
+               if (err) {
                        return err;
-               } else {
-                       bbp->bbp_isbad = false;
                }
+               bbp->bbp_isbad = bad;
 
                break;
        case FLASH_BLOCK_MARKBAD:
@@ -548,7 +545,7 @@
        return sc->sc_dev;
 }
 
-static inline off_t
+static inline flash_off_t
 flash_get_part_offset(struct flash_softc *fl, size_t poffset)
 {
        return fl->flash_if->partition.part_offset + poffset;
@@ -577,7 +574,7 @@
 
 int
 flash_read(device_t self,
-    off_t offset, size_t len, size_t *retlen, uint8_t *buf)
+    flash_off_t offset, size_t len, size_t *retlen, uint8_t *buf)
 {
        struct flash_softc *sc = device_private(self);
 
@@ -593,7 +590,7 @@
 
 int
 flash_write(device_t self,
-    off_t offset, size_t len, size_t *retlen, const uint8_t *buf)
+    flash_off_t offset, size_t len, size_t *retlen, const uint8_t *buf)
 {
        struct flash_softc *sc = device_private(self);
 
@@ -611,7 +608,7 @@
 }
 
 int
-flash_block_markbad(device_t self, uint64_t offset)
+flash_block_markbad(device_t self, flash_off_t offset)
 {
        struct flash_softc *sc = device_private(self);
 
@@ -629,7 +626,7 @@
 }
 
 int
-flash_block_isbad(device_t self, uint64_t offset)
+flash_block_isbad(device_t self, flash_off_t offset, bool *bad)
 {
        struct flash_softc *sc = device_private(self);
        
@@ -640,7 +637,7 @@
            sc->flash_if->partition.part_offset)
                return EINVAL;
 
-       return sc->flash_if->block_isbad(device_parent(self), offset);
+       return sc->flash_if->block_isbad(device_parent(self), offset, bad);
 }
 
 int
diff -r 4e7ba4c762f9 -r f96f15fc3d66 sys/dev/flash/flash.h
--- a/sys/dev/flash/flash.h     Mon Apr 04 11:32:25 2011 +0000
+++ b/sys/dev/flash/flash.h     Mon Apr 04 14:25:09 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: flash.h,v 1.2 2011/03/30 14:34:26 uebayasi Exp $       */
+/*     $NetBSD: flash.h,v 1.3 2011/04/04 14:25:09 ahoka Exp $  */
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -73,8 +73,8 @@
  * @state: the erase operation's result
  */
 struct flash_erase_instruction {
-       flash_addr_t ei_addr;
-       flash_addr_t ei_len;
+       flash_off_t ei_addr;
+       flash_off_t ei_len;
        void (*ei_callback)(struct flash_erase_instruction *);
        u_long ei_priv;
        u_char ei_state;
@@ -86,8 +86,8 @@
 };
 
 struct flash_partition {
-       flash_addr_t part_offset;
-       flash_addr_t part_size;
+       flash_off_t part_offset;
+       flash_off_t part_size;
        int part_flags;
 };
 
@@ -107,10 +107,10 @@
  */
 struct flash_interface {
        int (*erase)(device_t, struct flash_erase_instruction *);
-       int (*read)(device_t, off_t, size_t, size_t *, uint8_t *);
-       int (*write)(device_t, off_t, size_t, size_t *, const uint8_t *);
-       int (*block_markbad)(device_t, uint64_t);
-       int (*block_isbad)(device_t, uint64_t);
+       int (*read)(device_t, flash_off_t, size_t, size_t *, uint8_t *);
+       int (*write)(device_t, flash_off_t, size_t, size_t *, const uint8_t *);
+       int (*block_markbad)(device_t, flash_off_t);
+       int (*block_isbad)(device_t, flash_off_t, bool *);
        int (*sync)(device_t);
 
        int (*submit)(device_t, struct buf *);
@@ -119,7 +119,7 @@
        struct flash_partition partition;
 
        /* total size of mtd */
-       flash_addr_t size;       
+       flash_size_t size;       
        uint32_t page_size;
        uint32_t erasesize;
        uint32_t writesize;
@@ -132,16 +132,16 @@
  */
 struct flash_cache {
        size_t fc_len;
-       flash_addr_t fc_block;
+       flash_off_t fc_block;
        uint8_t *fc_data;
 };
 
 /* flash operations should be used through these */
 int flash_erase(device_t, struct flash_erase_instruction *);
-int flash_read(device_t, off_t, size_t, size_t *, uint8_t *);
-int flash_write(device_t, off_t, size_t, size_t *, const uint8_t *);
-int flash_block_markbad(device_t, uint64_t);
-int flash_block_isbad(device_t, uint64_t);
+int flash_read(device_t, flash_off_t, size_t, size_t *, uint8_t *);
+int flash_write(device_t, flash_off_t, size_t, size_t *, const uint8_t *);
+int flash_block_markbad(device_t, flash_off_t);
+int flash_block_isbad(device_t, flash_off_t, bool *);
 int flash_sync(device_t);
 
 /*
diff -r 4e7ba4c762f9 -r f96f15fc3d66 sys/dev/nand/nand.c
--- a/sys/dev/nand/nand.c       Mon Apr 04 11:32:25 2011 +0000
+++ b/sys/dev/nand/nand.c       Mon Apr 04 14:25:09 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nand.c,v 1.6 2011/03/27 13:33:04 ahoka Exp $   */
+/*     $NetBSD: nand.c,v 1.7 2011/04/04 14:25:10 ahoka Exp $   */
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.6 2011/03/27 13:33:04 ahoka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.7 2011/04/04 14:25:10 ahoka Exp $");
 
 #include "locators.h"
 
@@ -615,7 +615,7 @@
 {
        struct nand_softc *sc = device_private(self);
        struct nand_chip *chip = &sc->sc_chip;
-       off_t i;
+       int i;
 
        /* XXX TODO */
        row >>= chip->nc_page_shift;
@@ -647,7 +647,7 @@
 }
 
 static void
-nand_prepare_read(device_t self, flash_addr_t row, flash_addr_t column)
+nand_prepare_read(device_t self, flash_off_t row, flash_off_t column)
 {
        nand_command(self, ONFI_READ);
        nand_address_column(self, row, column);
@@ -865,9 +865,9 @@
 {
        struct nand_softc *sc = device_private(self);
        struct nand_chip *chip = &sc->sc_chip;
-       flash_addr_t blockoffset, marker;
+       flash_off_t blockoffset, marker;
 #ifdef NAND_BBT
-       flash_addr_t block;
+       flash_off_t block;
 
        block = offset / chip->nc_block_size;
 
@@ -889,11 +889,11 @@
 }
 
 bool
-nand_isfactorybad(device_t self, flash_addr_t offset)
+nand_isfactorybad(device_t self, flash_off_t offset)
 {
        struct nand_softc *sc = device_private(self);
        struct nand_chip *chip = &sc->sc_chip;
-       flash_addr_t block, first_page, last_page, page;
+       flash_off_t block, first_page, last_page, page;
        int i;
 
        /* Check for factory bad blocks first
@@ -926,11 +926,11 @@
 }
 
 bool
-nand_iswornoutbad(device_t self, flash_addr_t offset)
+nand_iswornoutbad(device_t self, flash_off_t offset)
 {
        struct nand_softc *sc = device_private(self);
        struct nand_chip *chip = &sc->sc_chip;
-       flash_addr_t block;
+       flash_off_t block;
 
        /* we inspect the first page of the block */
        block = offset & chip->nc_block_mask;
@@ -963,12 +963,12 @@
 }
 
 bool
-nand_isbad(device_t self, flash_addr_t offset)
+nand_isbad(device_t self, flash_off_t offset)
 {
 #ifdef NAND_BBT
        struct nand_softc *sc = device_private(self);
        struct nand_chip *chip = &sc->sc_chip;
-       flash_addr_t block;
+       flash_off_t block;
 
        block = offset / chip->nc_block_size;
 
@@ -1041,14 +1041,14 @@
  * handle (page) unaligned write to nand
  */
 static int
-nand_flash_write_unaligned(device_t self, off_t offset, size_t len,
+nand_flash_write_unaligned(device_t self, flash_off_t offset, size_t len,
     size_t *retlen, const uint8_t *buf)
 {
        struct nand_softc *sc = device_private(self);
        struct nand_chip *chip = &sc->sc_chip;
-       flash_addr_t first, last, firstoff;
+       flash_off_t first, last, firstoff;
        const uint8_t *bufp;
-       flash_addr_t addr;
+       flash_off_t addr;
        size_t left, count;
        int error, i;
 
@@ -1155,7 +1155,7 @@
 }
 
 int



Home | Main Index | Thread Index | Old Index