Work to enable SmartMedia/xD support
Subsystems (3)
PATCH v6 1/1 Work to enable SmartMedia/xD support
Hi,
This version fixes few bugs I discovered, especially
place where I forgot to unlock a mutex, another mistake in suspend/resume code that prevented driver from working if card was removed during low power state.
David, merge window will soon open, so could you somehow review this?
Best regards,
Maxim Levitsky
PATCH 1/17 MTD: create lockless versions of {get,put}_mtd_device This will be used to resolve deadlock in block translation layer.
These functions can be used as long as we don't need access to global mtd table, but have a pointer to the mtd device.
--- drivers/mtd/mtdcore.c | 60 ++++++++++++++++++++++++++++++---------------- include/linux/mtd/mtd.h | 3 +- 2 files changed, 41 insertions(+), 22 deletions(-)
drivers/mtd/mtdcore.c +39 -21
@@ -453,27 +453,38 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) ret =NULL ; } -if (!ret) - goto out_unlock; - -if (!try_module_get (ret->owner)) - goto out_unlock; - -if (ret->get_device) { - err = ret->get_device (ret); -if (err) - goto out_put; +if (!ret) { + ret =ERR_PTR (err); + goto out; } - ret->usecount++; + err =__get_mtd_device (ret); +if (err) + ret =ERR_PTR (err); +out:mutex_unlock (&mtd_table_mutex);return ret; +} -out_put: -module_put (ret->owner); -out_unlock: -mutex_unlock (&mtd_table_mutex); -return ERR_PTR (err); + +int __get_mtd_device (struct mtd_info *mtd) +{ +int err; + +if (!try_module_get (mtd->owner)) +return -ENODEV ; + +if (mtd->get_device) { + + err = mtd->get_device (mtd); + +if (err) { +module_put (mtd->owner); +return err; + } + } + mtd->usecount++; +return 0 ; }/**
@@ -524,14 +535,19 @@ out_unlock:void put_mtd_device (struct mtd_info *mtd) { -int c; -mutex_lock (&mtd_table_mutex); - c = --mtd->usecount; +__put_mtd_device (mtd); +mutex_unlock (&mtd_table_mutex); + +} + +void __put_mtd_device (struct mtd_info *mtd) +{ + --mtd->usecount; +BUG_ON (mtd->usecount <0 ); +if (mtd->put_device) mtd->put_device (mtd); -mutex_unlock (&mtd_table_mutex); -BUG_ON (c <0 );module_put (mtd->owner); }
@@ -569,7 +585,9 @@ EXPORT_SYMBOL_GPL(add_mtd_device);EXPORT_SYMBOL_GPL (del_mtd_device);EXPORT_SYMBOL_GPL (get_mtd_device);EXPORT_SYMBOL_GPL (get_mtd_device_nm); +EXPORT_SYMBOL_GPL (__get_mtd_device);EXPORT_SYMBOL_GPL (put_mtd_device); +EXPORT_SYMBOL_GPL (__put_mtd_device);EXPORT_SYMBOL_GPL (register_mtd_user);EXPORT_SYMBOL_GPL (unregister_mtd_user);EXPORT_SYMBOL_GPL (default_mtd_writev);
include/linux/mtd/mtd.h +2 -1
@@ -290,8 +290,9 @@ extern int add_mtd_device(struct mtd_info *mtd);extern int del_mtd_device (struct mtd_info *mtd);extern struct mtd_info *get_mtd_device (struct mtd_info *mtd,int num); +extern int __get_mtd_device (struct mtd_info *mtd); +extern void __put_mtd_device (struct mtd_info *mtd);extern struct mtd_info *get_mtd_device_nm (const char *name); -extern void put_mtd_device (struct mtd_info *mtd);
Signature · 1 line
1.6.3.3
PATCH 2/17 blktrans: nuke mtd_blkcore_priv and make both thread and disk queue be per device
In reply to Maxim LevitskyThis is the biggest change. To make hotplug possible, and this layer clearer, now mtd_blktrans_dev contains everything for a single mtd block translation device. Also removed some very old leftovers
--- drivers/mtd/mtd_blkdevs.c | 123 ++++++++++++++++++++---------------------- include/linux/mtd/blktrans.h | 10 ++-- 2 files changed, 64 insertions(+), 69 deletions(-)
drivers/mtd/mtd_blkdevs.c +59 -64
@@ -26,11 +26,6 @@static LIST_HEAD (blktrans_majors); -struct mtd_blkcore_priv { -struct task_struct *thread; -struct request_queue *rq; -spinlock_t queue_lock; -}; static int do_blktrans_request(struct mtd_blktrans_ops *tr, struct mtd_blktrans_dev *dev,
@@ -80,14 +75,13 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,static int mtd_blktrans_thread (void *arg) { -struct mtd_blktrans_ops *tr = arg; -struct request_queue *rq = tr->blkcore_priv->rq; +struct mtd_blktrans_dev *dev = arg; +struct request_queue *rq = dev->rq;struct request *req =NULL ;spin_lock_irq (rq->queue_lock);while (!kthread_should_stop ()) { -struct mtd_blktrans_dev *dev;int res;if (!req && !(req =blk_fetch_request (rq))) {
@@ -98,13 +92,10 @@ static int mtd_blktrans_thread(void *arg)continue ; } - dev = req->rq_disk->private_data; - tr = dev->tr; -spin_unlock_irq (rq->queue_lock);mutex_lock (&dev->lock); - res =do_blktrans_request (tr, dev, req); + res =do_blktrans_request (dev->tr, dev, req);mutex_unlock (&dev->lock);spin_lock_irq (rq->queue_lock);
@@ -123,8 +114,8 @@ static int mtd_blktrans_thread(void *arg)static void mtd_blktrans_request (struct request_queue *rq) { -struct mtd_blktrans_ops *tr = rq->queuedata; -wake_up_process (tr->blkcore_priv->thread); +struct mtd_blktrans_dev *dev = rq->queuedata; +wake_up_process (dev->thread); }
@@ -214,6 +205,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)struct mtd_blktrans_dev *d;int last_devnum =-1 ;struct gendisk *gd; +int ret;if (mutex_trylock (&mtd_table_mutex)) {mutex_unlock (&mtd_table_mutex);
@@ -239,12 +231,13 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) } last_devnum = d->devnum; } + + ret = -EBUSY ;if (new->devnum ==-1 ) new->devnum = last_devnum+1 ; -if ((new->devnum << tr->part_bits) >256 ) { -return -EBUSY ; - } +if ((new->devnum << tr->part_bits) >256 ) + goto error1;list_add_tail (&new->list, &tr->devs); added:
@@ -252,11 +245,16 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)if (!tr->writesect) new->readonly =1 ; + +/* Create gendisk */ + ret = -ENOMEM ; gd =alloc_disk (1 << tr->part_bits); -if (!gd) { -list_del (&new->list); -return -ENOMEM ; - } + +if (!gd) + goto error2; + + new->disk = gd; + gd->private_data = new; gd->major = tr->major; gd->first_minor = (new->devnum) << tr->part_bits; gd->fops = &mtd_blktrans_ops;
@@ -274,13 +272,33 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)snprintf (gd->disk_name,sizeof (gd->disk_name),"%s%d" , tr->name, new->devnum); -/* 2.5 has capacity in units of 512 bytes while still -having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */ set_capacity (gd, (new->size * tr->blksize) >>9 ); - gd->private_data = new; - new->blkcore_priv = gd; - gd->queue = tr->blkcore_priv->rq; + +/* Create the request queue */ +spin_lock_init (&new->queue_lock); + new->rq =blk_init_queue (mtd_blktrans_request, &new->queue_lock); + +if (!new->rq) + goto error3; + + new->rq->queuedata = new; +blk_queue_logical_block_size (new->rq, tr->blksize); + +if (tr->discard) +queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , + new->rq); + + gd->queue = new->rq; + +/* Create processing thread */ +/* TODO: workqueue ? */ + new->thread =kthread_run (mtd_blktrans_thread, new, +"%s%d" , tr->name, new->mtd->index); +if (IS_ERR (new->thread)) { + ret =PTR_ERR (new->thread); + goto error4; + } gd->driverfs_dev = &new->mtd->dev;if (new->readonly)
@@ -289,6 +307,15 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)add_disk (gd);return 0 ; +error4: +blk_cleanup_queue (new->rq); +error3: +put_disk (new->disk); +error2: +list_del (&new->list); +error1: +kfree (new); +return ret; }int del_mtd_blktrans_dev (struct mtd_blktrans_dev *old)
@@ -300,9 +327,13 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)list_del (&old->list); -del_gendisk (old->blkcore_priv); -put_disk (old->blkcore_priv); +/* stop new requests to arrive */ +del_gendisk (old->disk); + +/* Stop the thread */ +kthread_stop (old->thread); +blk_cleanup_queue (old->rq);return 0 ; }
@@ -343,9 +374,6 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)if (!blktrans_notifier.list.next)register_mtd_user (&blktrans_notifier); - tr->blkcore_priv =kzalloc (sizeof (*tr->blkcore_priv),GFP_KERNEL ); -if (!tr->blkcore_priv) -return -ENOMEM ;mutex_lock (&mtd_table_mutex);
@@ -353,39 +381,12 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)if (ret) {printk (KERN_WARNING "Unable to register %s block device on major %d: %d\n" , tr->name, tr->major, ret); -kfree (tr->blkcore_priv);mutex_unlock (&mtd_table_mutex);return ret; } -spin_lock_init (&tr->blkcore_priv->queue_lock); - - tr->blkcore_priv->rq =blk_init_queue (mtd_blktrans_request, &tr->blkcore_priv->queue_lock); -if (!tr->blkcore_priv->rq) { -unregister_blkdev (tr->major, tr->name); -kfree (tr->blkcore_priv); -mutex_unlock (&mtd_table_mutex); -return -ENOMEM ; - } - - tr->blkcore_priv->rq->queuedata = tr; -blk_queue_logical_block_size (tr->blkcore_priv->rq, tr->blksize); -if (tr->discard) -queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , - tr->blkcore_priv->rq); tr->blkshift =ffs (tr->blksize) -1 ; - tr->blkcore_priv->thread =kthread_run (mtd_blktrans_thread, tr, -"%sd" , tr->name); -if (IS_ERR (tr->blkcore_priv->thread)) { - ret =PTR_ERR (tr->blkcore_priv->thread); -blk_cleanup_queue (tr->blkcore_priv->rq); -unregister_blkdev (tr->major, tr->name); -kfree (tr->blkcore_priv); -mutex_unlock (&mtd_table_mutex); -return ret; - } -INIT_LIST_HEAD (&tr->devs);list_add (&tr->list, &blktrans_majors);
@@ -405,8 +406,6 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)mutex_lock (&mtd_table_mutex); -/* Clean up the kernel thread */ -kthread_stop (tr->blkcore_priv->thread);/* Remove it from the list of active majors */ list_del (&tr->list);
@@ -414,13 +413,9 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)list_for_each_entry_safe (dev, next, &tr->devs, list) tr->remove_dev (dev); -blk_cleanup_queue (tr->blkcore_priv->rq);unregister_blkdev (tr->major, tr->name); -mutex_unlock (&mtd_table_mutex); -kfree (tr->blkcore_priv); -BUG_ON (!list_empty (&tr->devs));return 0 ; }
include/linux/mtd/blktrans.h +5 -5
@@ -24,11 +24,13 @@ struct mtd_blktrans_dev {int devnum;unsigned long size;int readonly; -void *blkcore_priv;/* gendisk in 2.5, devfs_handle in 2.4 */ +struct gendisk *disk; +struct task_struct *thread; +struct request_queue *rq; +spinlock_t queue_lock; +void *priv; }; -struct blkcore_priv ;/* Differs for 2.4 and 2.5 kernels; private */ -struct mtd_blktrans_ops {char *name;int major;
@@ -60,8 +62,6 @@ struct mtd_blktrans_ops {struct list_head devs;struct list_head list;struct module *owner; - -struct mtd_blkcore_priv *blkcore_priv; };extern int register_mtd_blktrans (struct mtd_blktrans_ops *tr);
Signature · 1 line
1.6.3.3
PATCH 3/17 blktrans: track open and close calls.
In reply to Maxim LevitskyThis patch adds tracking for open and close calls. Now trans ->open and ->release are never called twise in a row ->release is also called once before mtd device disappers
Proper locking will be added in follow up patch
--- drivers/mtd/mtd_blkdevs.c | 17 +++++++++++++++++ include/linux/mtd/blktrans.h | 1 + 2 files changed, 18 insertions(+), 0 deletions(-)
drivers/mtd/mtd_blkdevs.c +17 -0
@@ -128,6 +128,9 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)if (!get_mtd_device (NULL , dev->mtd->index)) goto out; +if (dev->open++) + goto out; +if (!try_module_get (tr->owner)) goto out_tr;
@@ -153,6 +156,9 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)struct mtd_blktrans_ops *tr = dev->tr;int ret =0 ; +if (--dev->open) +return 0 ; +if (tr->release) ret = tr->release (dev);
@@ -304,6 +310,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)if (new->readonly)set_disk_ro (gd,1 ); + new->open =0 ;add_disk (gd);return 0 ;
@@ -333,6 +340,16 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)/* Stop the thread */ kthread_stop (old->thread); +if (old->open) { +if (old->tr->release) + old->tr->release (old); +put_mtd_device (old->mtd); + } + +/* From now on, no calls into trans can be made */ +/* Mtd device will be gone real soon now */ + old->mtd =NULL ; +blk_cleanup_queue (old->rq);return 0 ; }
include/linux/mtd/blktrans.h +1 -0
@@ -24,6 +24,7 @@ struct mtd_blktrans_dev {int devnum;unsigned long size;int readonly; +int open;struct gendisk *disk;struct task_struct *thread;struct request_queue *rq;
Signature · 1 line
1.6.3.3
PATCH 4/17 blktrans: don't free mtd_blktrans_dev, core will do that for you
In reply to Maxim LevitskyWe need that structure till last user exits, and that might be years after mtd device disappered.
--- drivers/mtd/ftl.c | 1 - drivers/mtd/inftlcore.c | 1 - drivers/mtd/mtd_blkdevs.c | 13 +++++++++++++ drivers/mtd/mtdblock.c | 1 - drivers/mtd/mtdblock_ro.c | 1 - drivers/mtd/nftlcore.c | 1 - drivers/mtd/rfd_ftl.c | 1 - drivers/mtd/ssfdc.c | 1 - include/linux/mtd/blktrans.h | 1 + 9 files changed, 14 insertions(+), 7 deletions(-)
drivers/mtd/ftl.c +0 -1
@@ -1082,7 +1082,6 @@ static void ftl_remove_dev(struct mtd_blktrans_dev *dev) {del_mtd_blktrans_dev (dev);ftl_freepart ((partition_t *)dev); -kfree (dev); }static struct mtd_blktrans_ops ftl_tr = {
drivers/mtd/inftlcore.c +0 -1
@@ -139,7 +139,6 @@ static void inftl_remove_dev(struct mtd_blktrans_dev *dev)kfree (inftl->PUtable);kfree (inftl->VUtable); -kfree (inftl); }/*
drivers/mtd/mtd_blkdevs.c +13 -0
@@ -131,6 +131,9 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)if (dev->open++) goto out; +if (dev->deleted) + goto out; +if (!try_module_get (tr->owner)) goto out_tr;
@@ -168,6 +171,14 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)module_put (tr->owner); } +/* Free the private data */ +if (dev->deleted) { +module_put (tr->owner); +mutex_unlock (&dev->lock); +kfree (dev); +return 0 ; + } +return ret; }
@@ -337,6 +348,8 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)/* stop new requests to arrive */ del_gendisk (old->disk); + old->deleted =1 ; +/* Stop the thread */ kthread_stop (old->thread);
drivers/mtd/mtdblock.c +0 -1
@@ -368,7 +368,6 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)static void mtdblock_remove_dev (struct mtd_blktrans_dev *dev) {del_mtd_blktrans_dev (dev); -kfree (dev); }static struct mtd_blktrans_ops mtdblock_tr = {
drivers/mtd/mtdblock_ro.c +0 -1
@@ -49,7 +49,6 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)static void mtdblock_remove_dev (struct mtd_blktrans_dev *dev) {del_mtd_blktrans_dev (dev); -kfree (dev); }static struct mtd_blktrans_ops mtdblock_tr = {
drivers/mtd/nftlcore.c +0 -1
@@ -126,7 +126,6 @@ static void nftl_remove_dev(struct mtd_blktrans_dev *dev)del_mtd_blktrans_dev (dev);kfree (nftl->ReplUnitTable);kfree (nftl->EUNtable); -kfree (nftl); }/*
drivers/mtd/rfd_ftl.c +0 -1
@@ -817,7 +817,6 @@ static void rfd_ftl_remove_dev(struct mtd_blktrans_dev *dev)vfree (part->sector_map);kfree (part->header_cache);kfree (part->blocks); -kfree (part); }static struct mtd_blktrans_ops rfd_ftl_tr = {
drivers/mtd/ssfdc.c +0 -1
@@ -375,7 +375,6 @@ static void ssfdcr_remove_dev(struct mtd_blktrans_dev *dev)del_mtd_blktrans_dev (dev);kfree (ssfdc->logic_block_map); -kfree (ssfdc); } static int ssfdcr_readsect(struct mtd_blktrans_dev *dev,
include/linux/mtd/blktrans.h +1 -0
@@ -24,6 +24,7 @@ struct mtd_blktrans_dev {int devnum;unsigned long size;int readonly; +int deleted;int open;struct gendisk *disk;struct task_struct *thread;
Signature · 1 line
1.6.3.3
PATCH 5/17 blktrans: add proper locking
In reply to Maxim LevitskyFirst, use lockless versions of get/put_mtd_device
We don't care what happened to mtd table, because we have a pointer to mtd device. It guaranteed to exist till we do final put_mtd_device
Also add locking to prevent all kinds or races
--- drivers/mtd/mtd_blkdevs.c | 84 ++++++++++++++++++++++++++++---------------- 1 files changed, 53 insertions(+), 31 deletions(-)
drivers/mtd/mtd_blkdevs.c +53 -31
@@ -123,33 +123,33 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) {struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data;struct mtd_blktrans_ops *tr = dev->tr; -int ret = -ENODEV ; - -if (!get_mtd_device (NULL , dev->mtd->index)) - goto out; +int ret =0 ; +mutex_lock (&dev->lock);if (dev->open++) goto out;if (dev->deleted) goto out; + ret = -ENODEV ;if (!try_module_get (tr->owner)) - goto out_tr; + goto out; -/* FIXME: Locking. A hot pluggable device can go away -(del_mtd_device can be called for it) without its module -being unloaded. */ - dev->mtd->usecount++; +if (__get_mtd_device (dev->mtd)) { +module_put (tr->owner); + goto out; + } ret =0 ;if (tr->open && (ret = tr->open (dev))) { - dev->mtd->usecount--; -put_mtd_device (dev->mtd); - out_tr:module_put (tr->owner); +__put_mtd_device (dev->mtd); + goto out; + } out: +mutex_unlock (&dev->lock);return ret; }
@@ -159,17 +159,10 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)struct mtd_blktrans_ops *tr = dev->tr;int ret =0 ; +mutex_lock (&dev->lock);if (--dev->open) -return 0 ; - -if (tr->release) - ret = tr->release (dev); + goto out; -if (!ret) { - dev->mtd->usecount--; -put_mtd_device (dev->mtd); -module_put (tr->owner); - }/* Free the private data */ if (dev->deleted) {
@@ -179,33 +172,59 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)return 0 ; } + ret = tr->release ? tr->release (dev) :0 ; +module_put (tr->owner); + +if (dev->mtd) +__put_mtd_device (dev->mtd); +out: +mutex_unlock (&dev->lock);return ret; }static int blktrans_getgeo (struct block_device *bdev,struct hd_geometry *geo) {struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data; +int error; + +mutex_lock (&dev->lock); + error = -ENODEV ; +if (dev->deleted) + goto out; + + error = -ENOTTY ;if (dev->tr->getgeo) -return dev->tr->getgeo (dev, geo); -return -ENOTTY ; + error = dev->tr->getgeo (dev, geo); +out: +mutex_unlock (&dev->lock); +return error; }static int blktrans_ioctl (struct block_device *bdev,fmode_t mode,unsigned int cmd,unsigned long arg) {struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data; -struct mtd_blktrans_ops *tr = dev->tr; +int error = -ENODEV ; + +mutex_lock (&dev->lock); + +if (dev->deleted) + goto out; + + error = -ENOTTY ;switch (cmd) {case BLKFLSBUF : -if (tr->flush) -return tr->flush (dev); -/* The core code did the work, we had nothing to do. */ -return 0 ; +if (dev->tr->flush) + error = dev->tr->flush (dev); +break ;default : -return -ENOTTY ; +break ; } +out: +mutex_unlock (&dev->lock); +return error; }static const struct block_device_operations mtd_blktrans_ops = {
@@ -353,16 +372,19 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)/* Stop the thread */ kthread_stop (old->thread); +/* Tell trans driver to release the device */ +mutex_lock (&old->lock); +if (old->open) {if (old->tr->release) old->tr->release (old); -put_mtd_device (old->mtd); +__put_mtd_device (old->mtd); }/* From now on, no calls into trans can be made */ /* Mtd device will be gone real soon now */ old->mtd =NULL ; - +mutex_unlock (&old->lock);blk_cleanup_queue (old->rq);return 0 ; }
Signature · 1 line
1.6.3.3
PATCH 6/17 blktrans: flush all requests before we remove the device
In reply to Maxim LevitskyFlush all requests, so we can be sure we don't deadlock the system later when we remove the disk queue.
--- drivers/mtd/mtd_blkdevs.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-)
drivers/mtd/mtd_blkdevs.c +13 -1
@@ -115,7 +115,13 @@ static int mtd_blktrans_thread(void *arg)static void mtd_blktrans_request (struct request_queue *rq) {struct mtd_blktrans_dev *dev = rq->queuedata; -wake_up_process (dev->thread); +struct request *req =NULL ; + +if (dev->deleted) +while ((req =blk_fetch_request (rq)) !=NULL ) +__blk_end_request_all (req, -ENODEV ); +else +wake_up_process (dev->thread); }
@@ -357,6 +363,8 @@ error1:int del_mtd_blktrans_dev (struct mtd_blktrans_dev *old) { +unsigned long flags; +if (mutex_trylock (&mtd_table_mutex)) {mutex_unlock (&mtd_table_mutex);BUG ();
@@ -367,7 +375,11 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)/* stop new requests to arrive */ del_gendisk (old->disk); +/* flush current requests */ +spin_lock_irqsave (&old->queue_lock, flags); old->deleted =1 ; +blk_start_queue (old->rq); +spin_unlock_irqrestore (&old->queue_lock, flags);/* Stop the thread */ kthread_stop (old->thread);
Signature · 1 line
1.6.3.3
PATCH 7/17 blktrans: allow FTL drivers to export sysfs attributes
In reply to Maxim LevitskyThis patch add ability to export sysfs attributes below block disk device.
This can be used to pass UDEV information about the FTL and could include vendor, serial, version, etc...
--- drivers/mtd/mtd_blkdevs.c | 11 ++++++++++- include/linux/mtd/blktrans.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletions(-)
drivers/mtd/mtd_blkdevs.c +10 -1
@@ -316,7 +316,6 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)set_capacity (gd, (new->size * tr->blksize) >>9 ); -/* Create the request queue */ spin_lock_init (&new->queue_lock); new->rq =blk_init_queue (mtd_blktrans_request, &new->queue_lock);
@@ -349,6 +348,11 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) new->open =0 ;add_disk (gd); +if (new->disk_attributes) +sysfs_create_group (&disk_to_dev (gd)->kobj, + new->disk_attributes); + +return 0 ; error4:blk_cleanup_queue (new->rq);
@@ -375,6 +379,11 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)/* stop new requests to arrive */ del_gendisk (old->disk); + +if (old->disk_attributes) +sysfs_remove_group (&disk_to_dev (old->disk)->kobj, + old->disk_attributes); +/* flush current requests */ spin_lock_irqsave (&old->queue_lock, flags); old->deleted =1 ;
include/linux/mtd/blktrans.h +2 -0
@@ -9,6 +9,7 @@#define __MTD_TRANS_H__#include <linux/mutex.h> +#include <linux/sysfs.h> struct hd_geometry ;struct mtd_info ;
@@ -27,6 +28,7 @@ struct mtd_blktrans_dev {int deleted;int open;struct gendisk *disk; +struct attribute_group *disk_attributes;struct task_struct *thread;struct request_queue *rq;spinlock_t queue_lock;
Signature · 1 line
1.6.3.3
PATCH 8/17 MTD: call remove notifiers before removing the device
In reply to Maxim LevitskyNow that mtd block common layer is prepared for proper hotplug support, enable it here Now all users of the mtd device have a chance to put the mtd device
when they are notified to do so, and they have to do so to make hotplug work.
--- drivers/mtd/mtdcore.c | 21 +++++++++++---------- 1 files changed, 11 insertions(+), 10 deletions(-)
drivers/mtd/mtdcore.c +11 -10
@@ -341,31 +341,32 @@ int add_mtd_device(struct mtd_info *mtd)int del_mtd_device (struct mtd_info *mtd) {int ret; +struct mtd_notifier *not;mutex_lock (&mtd_table_mutex);if (mtd_table[mtd->index] != mtd) { ret = -ENODEV ; - }else if (mtd->usecount) { + goto out_error; + } + +/* No need to get a refcount on the module containing +the notifier, since we hold the mtd_table_mutex */ +list_for_each_entry (not, &mtd_notifiers, list) + not->remove (mtd); + +if (mtd->usecount) {printk (KERN_NOTICE "Removing MTD device #%d (%s) with use count %d\n" , mtd->index, mtd->name, mtd->usecount); ret = -EBUSY ; }else { -struct mtd_notifier *not; -device_unregister (&mtd->dev); - -/* No need to get a refcount on the module containing -the notifier, since we hold the mtd_table_mutex */ -list_for_each_entry (not, &mtd_notifiers, list) - not->remove (mtd); - mtd_table[mtd->index] =NULL ; -module_put (THIS_MODULE ); ret =0 ; } +out_error:mutex_unlock (&mtd_table_mutex);return ret; }
Signature · 1 line
1.6.3.3
PATCH 9/17 MTD: nand: make MTD_OOB_PLACE work correctly.
In reply to Maxim LevitskyMTD_OOB_PLACE is supposed to read/write raw oob data similiar to MTD_OOB_RAW however due to a bug, currently its not possible to read more data that specified in oob 'free' regions
--- drivers/mtd/nand/nand_base.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/mtd/nand/nand_base.c +5 -1
@@ -1232,6 +1232,9 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,int ret =0 ;uint32_t readlen = ops->len;uint32_t oobreadlen = ops->ooblen; +uint32_t max_oobsize = ops->mode ==MTD_OOB_AUTO ? + mtd->oobavail : mtd->oobsize; +uint8_t *bufpoi, *oob, *buf; stats = mtd->ecc_stats;
@@ -1282,10 +1285,11 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, buf += bytes;if (unlikely (oob)) { +/* Raw mode does data:oob:data:oob */ if (ops->mode !=MTD_OOB_RAW ) {int toread =min (oobreadlen, - chip->ecc.layout->oobavail); + max_oobsize);if (toread) { oob =nand_transfer_oob (chip, oob, ops, toread);
Signature · 1 line
1.6.3.3
PATCH 10/17 MTD: nand: make reads using MTD_OOB_RAW affect only ECC validation
In reply to Maxim LevitskyThis changes the behavier of MTD_OOB_RAW. It used to read both OOB and data to the data buffer, however you would still need to specify the dummy oob buffer.
This is only used in one place, but makes it hard to read data+oob without ECC test, thus I removed that behavier, and fixed the user.
Now MTD_OOB_RAW behaves like MTD_OOB_PLACE, but doesn't do ECC validation
--- drivers/mtd/nand/nand_base.c | 5 ----- drivers/mtd/nand/nand_bbt.c | 26 ++++++++++++++++++++++---- include/linux/mtd/mtd.h | 4 +--- 3 files changed, 23 insertions(+), 12 deletions(-)
drivers/mtd/nand/nand_base.c +0 -5
@@ -1286,8 +1286,6 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,if (unlikely (oob)) { -/* Raw mode does data:oob:data:oob */ -if (ops->mode !=MTD_OOB_RAW ) {int toread =min (oobreadlen, max_oobsize);if (toread) {
@@ -1295,9 +1293,6 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, oob, ops, toread); oobreadlen -= toread; } - }else - buf =nand_transfer_oob (chip, - buf, ops, mtd->oobsize); }if (!(chip->options &NAND_NO_READRDY )) {
drivers/mtd/nand/nand_bbt.c +22 -4
@@ -237,15 +237,33 @@ static int scan_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t offs, size_t len) {struct mtd_oob_ops ops; +int res; ops.mode =MTD_OOB_RAW ; ops.ooboffs =0 ; ops.ooblen = mtd->oobsize; - ops.oobbuf = buf; - ops.datbuf = buf; - ops.len = len; -return mtd->read_oob (mtd, offs, &ops); + +while (len >0 ) { +if (len <= mtd->writesize) { + ops.oobbuf = buf + len; + ops.datbuf = buf; + ops.len = len; +return mtd->read_oob (mtd, offs, &ops); + }else { + ops.oobbuf = buf + mtd->writesize; + ops.datbuf = buf; + ops.len = mtd->writesize; + res = mtd->read_oob (mtd, offs, &ops); + +if (res) +return res; + } + + buf += mtd->oobsize + mtd->writesize; + len -= mtd->writesize; + } +return 0 ; }/*
include/linux/mtd/mtd.h +1 -3
@@ -61,9 +61,7 @@ struct mtd_erase_region_info {* MTD_OOB_PLACE: oob data are placed at the given offset * MTD_OOB_AUTO: oob data are automatically placed at the free areas * which are defined by the ecclayout -* MTD_OOB_RAW: mode to read raw data+oob in one chunk. The oob data -* is inserted into the data. Thats a raw image of the -* flash contents. +* MTD_OOB_RAW: mode to read oob and data without doing ECC checking */ typedef enum { MTD_OOB_PLACE,
Signature · 1 line
1.6.3.3
Re: [PATCH 10/17] MTD: nand: make reads using MTD_OOB_RAW affect only ECC validation
Quoted 20 lines · Maxim Levitsky
This changes the behavier of
MTD_OOB_RAW. It used to read both OOB and data to the data buffer, however you would still need to specify the dummy oob buffer.This is only used in one place, but makes it hard to read data+oob without ECC test, thus I removed that behavier, and fixed the user.
Now
MTD_OOB_RAWbehaves likeMTD_OOB_PLACE, but doesn't do ECC validationSigned-off-by Maxim Levitsky <[email protected]>--- drivers/mtd/nand/nand_base.c | 5 ----- drivers/mtd/nand/nand_bbt.c | 26 ++++++++++++++++++++++---- include/linux/mtd/mtd.h | 4 +--- 3 files changed, 23 insertions(+), 12 deletions(-)drivers/mtd/nand/nand_base.c +0
-0
drivers/mtd/nand/nand_base.c static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, · line 1289
Quoted 6 lines
drivers/mtd/nand/nand_base.c +0
-2@@ -1286,8 +1286,6 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,if (unlikely (oob)) { -/* Raw mode does data:oob:data:oob */ -if (ops->mode !=MTD_OOB_RAW ) {
I am not sure if it is legal to modify the behavior of MTD_OOB_RAW. But if you remove the "if" command, the following code should be indent again.
Stanley.
Quoted 71 lines
drivers/mtd/nand/nand_base.c +0
-0int toread =min (oobreadlen, max_oobsize);drivers/mtd/nand/nand_base.c +0
-3if (toread) {@@ -1295,9 +1293,6 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, oob, ops, toread); oobreadlen -= toread; } - }else - buf =nand_transfer_oob (chip, - buf, ops, mtd->oobsize); }if (!(chip->options &NAND_NO_READRDY )) {drivers/mtd/nand/nand_bbt.c +22
-4@@ -237,15 +237,33 @@ static int scan_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t offs, size_t len) {struct mtd_oob_ops ops; +int res; ops.mode =MTD_OOB_RAW ; ops.ooboffs =0 ; ops.ooblen = mtd->oobsize; - ops.oobbuf = buf; - ops.datbuf = buf; - ops.len = len; -return mtd->read_oob (mtd, offs, &ops); + +while (len >0 ) { +if (len <= mtd->writesize) { + ops.oobbuf = buf + len; + ops.datbuf = buf; + ops.len = len; +return mtd->read_oob (mtd, offs, &ops); + }else { + ops.oobbuf = buf + mtd->writesize; + ops.datbuf = buf; + ops.len = mtd->writesize; + res = mtd->read_oob (mtd, offs, &ops); + +if (res) +return res; + } + + buf += mtd->oobsize + mtd->writesize; + len -= mtd->writesize; + } +return 0 ; }/* include/linux/mtd/mtd.h +1
-3@@ -61,9 +61,7 @@ struct mtd_erase_region_info {* MTD_OOB_PLACE: oob data are placed at the given offset * MTD_OOB_AUTO: oob data are automatically placed at the free areas * which are defined by the ecclayout -* MTD_OOB_RAW: mode to read raw data+oob in one chunk. The oob data -* is inserted into the data. Thats a raw image of the -* flash contents. +* MTD_OOB_RAW: mode to read oob and data without doing ECC checking */ typedef enum { MTD_OOB_PLACE,
Re: [PATCH 10/17] MTD: nand: make reads using MTD_OOB_RAW affect only ECC validation
In reply to Maxim LevitskyQuoted 6 lines · Maxim Levitsky
This changes the behavier of
MTD_OOB_RAW. It used to read both OOB and data to the data buffer, however you would still need to specify the dummy oob buffer.This is only used in one place, but makes it hard to read data+oob without ECC test, thus I removed that behavier, and fixed the user.
Quoted 8 lines
Now
MTD_OOB_RAWbehaves likeMTD_OOB_PLACE, but doesn't do ECC validationSigned-off-by Maxim Levitsky <[email protected]>---
drivers/mtd/nand/nand_base.c | 5 -----drivers/mtd/nand/nand_bbt.c| 26 ++++++++++++++++++++++----include/linux/mtd/mtd.h| 4 +---3 files changed, 23 insertions(+), 12 deletions(-)
Could you please provide a clearer description of why you think this is necessary?
Thanks,
Vitaly
Re: [PATCH 10/17] MTD: nand: make reads using MTD_OOB_RAW affect only ECC validation
Quoted 16 lines · Vitaly Wool
Quoted 6 lines · Maxim Levitsky
This changes the behavier of
MTD_OOB_RAW. It used to read both OOB and data to the data buffer, however you would still need to specify the dummy oob buffer.This is only used in one place, but makes it hard to read data+oob without ECC test, thus I removed that behavier, and fixed the user.
Quoted 8 lines
Now
MTD_OOB_RAWbehaves likeMTD_OOB_PLACE, but doesn't do ECC validationSigned-off-by Maxim Levitsky <[email protected]>--- drivers/mtd/nand/nand_base.c | 5 ----- drivers/mtd/nand/nand_bbt.c | 26 ++++++++++++++++++++++---- include/linux/mtd/mtd.h | 4 +--- 3 files changed, 23 insertions(+), 12 deletions(-)
Quoted 2 lines
Could you please provide a clearer description of why you think this is necessary?
Sure.
I have two distinct buffers. One holds the data and is 512 bytes long, other is the oob and is 16 bytes long.
I want to write these buffers to flash but without ECC
Currently I would have to allocate new buffer and copy both buffers there.
Why I need it?
To make my SmartMedia FTL complete I need to add support for 256 byte nands. These have 256 bytes per page and 8 bytes of oob. However, pages are always written in pairs, forming 512 bytes sector. Combined oob of first and second page is identical to the one that is written to 512 byte page, thus its layout depends on page number. Also I want the nand driver to have as little as possible smartmedia dependencies, thus allow it to be used with any FTL, UBI, jffs2, etc.. Therefore I decided to make nand driver use standard oob layout and ECC in case of 256 byte flash, but make my FTL bypass it.
It also happens to work with nandsim unmodified... :-)
Also, this makes the interface more orthogonal.
This feature is used in just one place too.
Best regards,
Maxim Levitsky
PATCH 11/17 MTD: nand: fix bug that prevented write of more that one page by ->write_oob
In reply to Maxim LevitskyAlthough nand_do_write_ops intends to allow such mode, it fails do do so Probably this was never tested
--- drivers/mtd/nand/nand_base.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)
drivers/mtd/nand/nand_base.c +9 -7
@@ -1879,11 +1879,9 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,* @oob: oob data buffer * @ops: oob ops structure */ -static uint8_t *nand_fill_oob (struct nand_chip *chip,uint8_t *oob, -struct mtd_oob_ops *ops) +static uint8_t *nand_fill_oob (struct nand_chip *chip,uint8_t *oob,size_t len, +struct mtd_oob_ops *ops) { -size_t len = ops->ooblen; -switch (ops->mode) {case MTD_OOB_PLACE :
@@ -1938,6 +1936,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,int chipnr, realpage, page, blockmask, column;struct nand_chip *chip = mtd->priv;uint32_t writelen = ops->len; +uint32_t oobwritelen = ops->ooblen;uint8_t *oob = ops->oobbuf;uint8_t *buf = ops->datbuf;int ret, subpage;
@@ -1994,8 +1993,11 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, wbuf = chip->buffers->databuf; } -if (unlikely (oob)) - oob =nand_fill_oob (chip, oob, ops); +if (unlikely (oob)) { +size_t len =min (oobwritelen, mtd->oobsize); + oob =nand_fill_oob (chip, oob, len, ops); + oobwritelen -= len; + } ret = chip->write_page (mtd, chip, wbuf, page, cached, (ops->mode ==MTD_OOB_RAW ));
@@ -2169,7 +2171,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, chip->pagebuf =-1 ;memset (chip->oob_poi,0xff , mtd->oobsize); -nand_fill_oob (chip, ops->oobbuf, ops); +nand_fill_oob (chip, ops->oobbuf, ops->ooblen, ops); status = chip->ecc.write_oob (mtd, chip, page & chip->pagemask);memset (chip->oob_poi,0xff , mtd->oobsize);
Signature · 1 line
1.6.3.3
Re: [PATCH 11/17] MTD: nand: fix bug that prevented write of more that one page by ->write_oob
ops->ooblen is the oob bytes to write, you add a argument for nand_fill_oob to do this, it is redundant.
I know the bug you want to fix, the ops->ooblen may be illegal. But this patch can't this problem. If (ops->offset + ops->ooblen) > mtd->oobsize, it still will write beyond a page.
I think the right method is that nand_do_write_ops do the check like nand_do_write_oob, I have the patch yesterday.
http://patchwork.ozlabs.org/patch/44450/
Stanley.
Quoted 13 lines · Maxim Levitsky
Although
nand_do_write_opsintends to allow such mode, it fails do do so Probably this was never testedSigned-off-by Maxim Levitsky <[email protected]>--- drivers/mtd/nand/nand_base.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)drivers/mtd/nand/nand_base.c +0
-0
drivers/mtd/nand/nand_base.c static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, · line 1884
Quoted 8 lines
drivers/mtd/nand/nand_base.c +2
-2@@ -1879,11 +1879,9 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,* @oob: oob data buffer * @ops: oob ops structure */ -static uint8_t *nand_fill_oob (struct nand_chip *chip,uint8_t *oob, -struct mtd_oob_ops *ops) +static uint8_t *nand_fill_oob (struct nand_chip *chip,uint8_t *oob,size_t len, +struct mtd_oob_ops *ops)
ops->ooblen is the oob bytes to write, you add a prara
Quoted 38 lines
drivers/mtd/nand/nand_base.c +0
-2{ -size_t len = ops->ooblen; -switch (ops->mode) {drivers/mtd/nand/nand_base.c +7
-3case MTD_OOB_PLACE :@@ -1938,6 +1936,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,int chipnr, realpage, page, blockmask, column;struct nand_chip *chip = mtd->priv;uint32_t writelen = ops->len; +uint32_t oobwritelen = ops->ooblen;uint8_t *oob = ops->oobbuf;uint8_t *buf = ops->datbuf;int ret, subpage;@@ -1994,8 +1993,11 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, wbuf = chip->buffers->databuf; } -if (unlikely (oob)) - oob =nand_fill_oob (chip, oob, ops); +if (unlikely (oob)) { +size_t len =min (oobwritelen, mtd->oobsize); + oob =nand_fill_oob (chip, oob, len, ops); + oobwritelen -= len; + } ret = chip->write_page (mtd, chip, wbuf, page, cached, (ops->mode ==MTD_OOB_RAW ));@@ -2169,7 +2171,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, chip->pagebuf =-1 ;memset (chip->oob_poi,0xff , mtd->oobsize); -nand_fill_oob (chip, ops->oobbuf, ops); +nand_fill_oob (chip, ops->oobbuf, ops->ooblen, ops); status = chip->ecc.write_oob (mtd, chip, page & chip->pagemask);memset (chip->oob_poi,0xff , mtd->oobsize);
Re: [PATCH 11/17] MTD: nand: fix bug that prevented write of more that one page by ->write_oob
Quoted 3 lines · stanley.miao
ops->ooblenis the oob bytes to write, you add a argument fornand_fill_oobto do this,
it is redundant.
No its not.ops->ooblen can be legitimately larger that mtd->oobsize because user might want to write two or more pages in a row.
I want to be able to write two pages + two oobs in same time.
Quoted 5 lines
I know the bug you want to fix, the
ops->ooblenmay be illegal. But this patch can't this
problem. If (ops->offset+ops->ooblen) >mtd->oobsize, it still will write beyond a page.
This is true, I just didn't use the ops->offset....
Quoted 6 lines
I think the right method is that
nand_do_write_opsdo the check likenand_do_write_oob,
I have the patch yesterday.
This again won't work for multipage writes I have in mind. However if ops->ooboffs is set, I think multipage write shouldn't be allowed
This is:
if (ops->ooboffs && (ops->ooboffs + ops->ooblen) > len))
Also check for 'ops->ooboffs >= len' is almost redundant. Only case it would trigger is when 'ops->ooblen == 0' But this probably can be dealt with, without error.
Best regards,
Maxim Levitsky
Quoted 67 lines
Stanley.
Quoted 13 lines · Maxim Levitsky
Although
nand_do_write_opsintends to allow such mode, it fails do do so Probably this was never testedSigned-off-by Maxim Levitsky <[email protected]>--- drivers/mtd/nand/nand_base.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)drivers/mtd/nand/nand_base.c +0
-0drivers/mtd/nand/nand_base.c static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, · line 1884
Quoted 8 lines
drivers/mtd/nand/nand_base.c +2
-2@@ -1879,11 +1879,9 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,* @oob: oob data buffer * @ops: oob ops structure */ -static uint8_t *nand_fill_oob (struct nand_chip *chip,uint8_t *oob, -struct mtd_oob_ops *ops) +static uint8_t *nand_fill_oob (struct nand_chip *chip,uint8_t *oob,size_t len, +struct mtd_oob_ops *ops)
ops->ooblenis the oob bytes to write, you add a praraQuoted 38 lines
drivers/mtd/nand/nand_base.c +0
-2{ -size_t len = ops->ooblen; -switch (ops->mode) {drivers/mtd/nand/nand_base.c +7
-3case MTD_OOB_PLACE :@@ -1938,6 +1936,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,int chipnr, realpage, page, blockmask, column;struct nand_chip *chip = mtd->priv;uint32_t writelen = ops->len; +uint32_t oobwritelen = ops->ooblen;uint8_t *oob = ops->oobbuf;uint8_t *buf = ops->datbuf;int ret, subpage;@@ -1994,8 +1993,11 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, wbuf = chip->buffers->databuf; } -if (unlikely (oob)) - oob =nand_fill_oob (chip, oob, ops); +if (unlikely (oob)) { +size_t len =min (oobwritelen, mtd->oobsize); + oob =nand_fill_oob (chip, oob, len, ops); + oobwritelen -= len; + } ret = chip->write_page (mtd, chip, wbuf, page, cached, (ops->mode ==MTD_OOB_RAW ));@@ -2169,7 +2171,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, chip->pagebuf =-1 ;memset (chip->oob_poi,0xff , mtd->oobsize); -nand_fill_oob (chip, ops->oobbuf, ops); +nand_fill_oob (chip, ops->oobbuf, ops->ooblen, ops); status = chip->ecc.write_oob (mtd, chip, page & chip->pagemask);memset (chip->oob_poi,0xff , mtd->oobsize);
Re: [PATCH 11/17] MTD: nand: fix bug that prevented write of more that one page by ->write_oob
In reply to Maxim Levitskyops->ooblen is the oob bytes to write, you add a argument for nand_fill_oob to do this, it is redundant.
I know the bug you want to fix, the ops->ooblen may be illegal. But this
patch can't solve this problem. If (ops->offset + ops->ooblen) > mtd->oobsize, it still will write beyond one page.
I think the right method to solve it is that nand_do_write_ops do the check like nand_do_write_oob. I have sent the patch yesterday.
http://patchwork.ozlabs.org/patch/44450/
Stanley.
Quoted 13 lines · Maxim Levitsky
Although
nand_do_write_opsintends to allow such mode, it fails do do so Probably this was never testedSigned-off-by Maxim Levitsky <[email protected]>--- drivers/mtd/nand/nand_base.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)drivers/mtd/nand/nand_base.c +0
-0
drivers/mtd/nand/nand_base.c static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, · line 1884
Quoted 8 lines
drivers/mtd/nand/nand_base.c +2
-2@@ -1879,11 +1879,9 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,* @oob: oob data buffer * @ops: oob ops structure */ -static uint8_t *nand_fill_oob (struct nand_chip *chip,uint8_t *oob, -struct mtd_oob_ops *ops) +static uint8_t *nand_fill_oob (struct nand_chip *chip,uint8_t *oob,size_t len, +struct mtd_oob_ops *ops)
ops->ooblen is the oob bytes to write, you add a prara
Quoted 38 lines
drivers/mtd/nand/nand_base.c +0
-2{ -size_t len = ops->ooblen; -switch (ops->mode) {drivers/mtd/nand/nand_base.c +7
-3case MTD_OOB_PLACE :@@ -1938,6 +1936,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,int chipnr, realpage, page, blockmask, column;struct nand_chip *chip = mtd->priv;uint32_t writelen = ops->len; +uint32_t oobwritelen = ops->ooblen;uint8_t *oob = ops->oobbuf;uint8_t *buf = ops->datbuf;int ret, subpage;@@ -1994,8 +1993,11 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, wbuf = chip->buffers->databuf; } -if (unlikely (oob)) - oob =nand_fill_oob (chip, oob, ops); +if (unlikely (oob)) { +size_t len =min (oobwritelen, mtd->oobsize); + oob =nand_fill_oob (chip, oob, len, ops); + oobwritelen -= len; + } ret = chip->write_page (mtd, chip, wbuf, page, cached, (ops->mode ==MTD_OOB_RAW ));@@ -2169,7 +2171,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, chip->pagebuf =-1 ;memset (chip->oob_poi,0xff , mtd->oobsize); -nand_fill_oob (chip, ops->oobbuf, ops); +nand_fill_oob (chip, ops->oobbuf, ops->ooblen, ops); status = chip->ecc.write_oob (mtd, chip, page & chip->pagemask);memset (chip->oob_poi,0xff , mtd->oobsize);
PATCH 12/17 MTD: nand: make suspend work if device is accessed by kernel threads.
In reply to Maxim LevitskySince all userspace threads are frozen at the time the nand_suspend is called, they aren't inside any nand function.
We don't call try_to_freeze in nand ether. Thus the only user that can be insize the nand functions is an non freezeable kernel thread.
Thus we can safely wait for it to finish.
--- drivers/mtd/nand/nand_base.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
drivers/mtd/nand/nand_base.c +0 -3
@@ -744,9 +744,6 @@ nand_get_device(struct nand_chip *chip, struct mtd_info *mtd, int new_state) chip->state =FL_PM_SUSPENDED ;spin_unlock (lock);return 0 ; - }else { -spin_unlock (lock); -return -EAGAIN ; } }set_current_state (TASK_UNINTERRUPTIBLE );
Signature · 1 line
1.6.3.3
PATCH 13/17 MTD: export few functions from nand_base.c
In reply to Maxim LevitskyThis exports:
nand_do_read_oobnand_do_write_oobnand_get_devicenand_put_device
This functions will be used to implement custom oob based bad block handling in upcoming smartmedia common module
--- drivers/mtd/nand/nand_base.c | 18 +++++++++--------- include/linux/mtd/nand.h | 12 ++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-)
drivers/mtd/nand/nand_base.c +9 -9
@@ -96,11 +96,6 @@ static struct nand_ecclayout nand_oob_128 = { .length = 78}} }; -static int nand_get_device (struct nand_chip *chip,struct mtd_info *mtd, -int new_state); - -static int nand_do_write_oob (struct mtd_info *mtd,loff_t to, -struct mtd_oob_ops *ops);/* * For devices which display every fart in the system on a separate LED. Is
@@ -114,7 +109,7 @@ DEFINE_LED_TRIGGER(nand_led_trigger);* * Deselect, release chip lock and wake up anyone waiting on the device */ -static void nand_release_device (struct mtd_info *mtd) +void nand_release_device (struct mtd_info *mtd) {struct nand_chip *chip = mtd->priv;
@@ -128,6 +123,7 @@ static void nand_release_device(struct mtd_info *mtd)wake_up (&chip->controller->wq);spin_unlock (&chip->controller->lock); } +EXPORT_SYMBOL_GPL (nand_release_device);/** * nand_read_byte - [DEFAULT] read one byte from the chip
@@ -721,7 +717,7 @@ static void panic_nand_get_device(struct nand_chip *chip,* * Get the device and lock it for exclusive access */ -static int +int nand_get_device (struct nand_chip *chip,struct mtd_info *mtd,int new_state) {spinlock_t *lock = &chip->controller->lock;
@@ -753,6 +749,7 @@ nand_get_device(struct nand_chip *chip, struct mtd_info *mtd, int new_state)remove_wait_queue (wq, &wait); goto retry; } +EXPORT_SYMBOL_GPL (nand_get_device);/** * panic_nand_wait - [GENERIC] wait until the command is done
@@ -1532,7 +1529,7 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd,* * NAND read out-of-band data from the spare area */ -static int nand_do_read_oob (struct mtd_info *mtd,loff_t from, +int nand_do_read_oob (struct mtd_info *mtd,loff_t from,struct mtd_oob_ops *ops) {int page, realpage, chipnr, sndcmd =1 ;
@@ -1616,6 +1613,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, ops->oobretlen = ops->ooblen;return 0 ; } +EXPORT_SYMBOL_GPL (nand_do_read_oob);/** * nand_read_oob - [MTD Interface] NAND read data and/or out-of-band
@@ -2108,7 +2106,7 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,* * NAND write out-of-band */ -static int nand_do_write_oob (struct mtd_info *mtd,loff_t to, +int nand_do_write_oob (struct mtd_info *mtd,loff_t to,struct mtd_oob_ops *ops) {int chipnr, page, status, len;
@@ -2179,6 +2177,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,return 0 ; } +EXPORT_SYMBOL_GPL (nand_do_write_oob);/** * nand_write_oob - [MTD Interface] NAND write data and/or out-of-band
@@ -3080,6 +3079,7 @@ EXPORT_SYMBOL_GPL(nand_scan_ident);EXPORT_SYMBOL_GPL (nand_scan_tail);EXPORT_SYMBOL_GPL (nand_release); +static int __init nand_base_init (void ) {led_trigger_register_simple ("nand-disk" , &nand_led_trigger);
include/linux/mtd/nand.h +12 -0
@@ -469,6 +469,18 @@ extern int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,extern int nand_do_read (struct mtd_info *mtd,loff_t from,size_t len,size_t * retlen,uint8_t * buf); +extern int nand_do_read_oob (struct mtd_info *mtd,loff_t from, +struct mtd_oob_ops *ops); + +extern int nand_do_write_oob (struct mtd_info *mtd,loff_t to, +struct mtd_oob_ops *ops); + +extern int nand_get_device (struct nand_chip *chip, +struct mtd_info *mtd,int new_state); + +extern void nand_release_device (struct mtd_info *mtd); + +/** * struct platform_nand_chip - chip level device structure * @nr_chips: max. number of chips to scan for
Signature · 1 line
1.6.3.3
Re: [PATCH 13/17] MTD: export few functions from nand_base.c
Quoted 5 lines · Maxim Levitsky
This exports:
nand_do_read_oobnand_do_write_oob
nand_do_read_oob and nand_do_write_oob can't be exported. They are internal functions in NAND subsystem. If you want use them, please use mtd->read_oob and mtd->write_oob.
Stanley.
Quoted 128 lines
nand_get_devicenand_put_deviceThis functions will be used to implement custom oob based bad block handling in upcoming smartmedia common module
Signed-off-by Maxim Levitsky <[email protected]>--- drivers/mtd/nand/nand_base.c | 18 +++++++++--------- include/linux/mtd/nand.h | 12 ++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-)drivers/mtd/nand/nand_base.c +9
-9@@ -96,11 +96,6 @@ static struct nand_ecclayout nand_oob_128 = { .length = 78}} }; -static int nand_get_device (struct nand_chip *chip,struct mtd_info *mtd, -int new_state); - -static int nand_do_write_oob (struct mtd_info *mtd,loff_t to, -struct mtd_oob_ops *ops);/* * For devices which display every fart in the system on a separate LED. Is @@ -114,7 +109,7 @@ DEFINE_LED_TRIGGER(nand_led_trigger);* * Deselect, release chip lock and wake up anyone waiting on the device */ -static void nand_release_device (struct mtd_info *mtd) +void nand_release_device (struct mtd_info *mtd) {struct nand_chip *chip = mtd->priv;@@ -128,6 +123,7 @@ static void nand_release_device(struct mtd_info *mtd)wake_up (&chip->controller->wq);spin_unlock (&chip->controller->lock); } +EXPORT_SYMBOL_GPL (nand_release_device);/** * nand_read_byte - [DEFAULT] read one byte from the chip @@ -721,7 +717,7 @@ static void panic_nand_get_device(struct nand_chip *chip,* * Get the device and lock it for exclusive access */ -static int +int nand_get_device (struct nand_chip *chip,struct mtd_info *mtd,int new_state) {spinlock_t *lock = &chip->controller->lock;@@ -753,6 +749,7 @@ nand_get_device(struct nand_chip *chip, struct mtd_info *mtd, int new_state)remove_wait_queue (wq, &wait); goto retry; } +EXPORT_SYMBOL_GPL (nand_get_device);/** * panic_nand_wait - [GENERIC] wait until the command is done @@ -1532,7 +1529,7 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd,* * NAND read out-of-band data from the spare area */ -static int nand_do_read_oob (struct mtd_info *mtd,loff_t from, +int nand_do_read_oob (struct mtd_info *mtd,loff_t from,struct mtd_oob_ops *ops) {int page, realpage, chipnr, sndcmd =1 ;@@ -1616,6 +1613,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, ops->oobretlen = ops->ooblen;return 0 ; } +EXPORT_SYMBOL_GPL (nand_do_read_oob);/** * nand_read_oob - [MTD Interface] NAND read data and/or out-of-band @@ -2108,7 +2106,7 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,* * NAND write out-of-band */ -static int nand_do_write_oob (struct mtd_info *mtd,loff_t to, +int nand_do_write_oob (struct mtd_info *mtd,loff_t to,struct mtd_oob_ops *ops) {int chipnr, page, status, len;@@ -2179,6 +2177,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,return 0 ; } +EXPORT_SYMBOL_GPL (nand_do_write_oob);/** * nand_write_oob - [MTD Interface] NAND write data and/or out-of-band @@ -3080,6 +3079,7 @@ EXPORT_SYMBOL_GPL(nand_scan_ident);EXPORT_SYMBOL_GPL (nand_scan_tail);EXPORT_SYMBOL_GPL (nand_release); +static int __init nand_base_init (void ) {led_trigger_register_simple ("nand-disk" , &nand_led_trigger);include/linux/mtd/nand.h +12
-0@@ -469,6 +469,18 @@ extern int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,extern int nand_do_read (struct mtd_info *mtd,loff_t from,size_t len,size_t * retlen,uint8_t * buf); +extern int nand_do_read_oob (struct mtd_info *mtd,loff_t from, +struct mtd_oob_ops *ops); + +extern int nand_do_write_oob (struct mtd_info *mtd,loff_t to, +struct mtd_oob_ops *ops); + +extern int nand_get_device (struct nand_chip *chip, +struct mtd_info *mtd,int new_state); + +extern void nand_release_device (struct mtd_info *mtd); + +/** * struct platform_nand_chip - chip level device structure * @nr_chips: max. number of chips to scan for
Re: [PATCH 13/17] MTD: export few functions from nand_base.c
Quoted 10 lines · stanley.miao
Quoted 5 lines · Maxim Levitsky
This exports:
nand_do_read_oobnand_do_write_oob
nand_do_read_oobandnand_do_write_oobcan't be exported. They are internal functions in NAND subsystem. If you want use them, please usemtd->read_oobandmtd->write_oob.
I would be happy to use these, and I tried to do so.
However this leads to deadlock, because ->block_bad can (and is) called with controller lock (nand_get_device), thus if I call ->read_oob I will get deadlock.
Best regards,
Maxim Levitsky
Re: [PATCH 13/17] MTD: export few functions from nand_base.c
In reply to stanley.miaoQuoted 7 lines · stanley.miao
Quoted 5 lines · Maxim Levitsky
This exports:
nand_do_read_oobnand_do_write_oob
Quoted 12 lines
nand_do_read_oobandnand_do_write_oobcan't be exported. They are internal functions in NAND subsystem. If you want use them, please usemtd->read_oobandmtd->write_oob.Stanley.
Quoted 6 lines
nand_get_devicenand_put_deviceThis functions will be used to implement custom oob based bad block handling in upcoming smartmedia common module
Actually I don't like this patch ether.
The problem is that nand_erase_nand first takes the lock, and then calls the ->block_bad.
I could make the ->block_bad always take the lock (and this will allow using ->read_oob) by first checking that all erase blocks are good, and then doing the erase.
This would change the behavior slightly (Now if you attempt to erase several erase blocks and one of them is marked as bad, erase stops at first bad block. With the change, erase will fail completely. Is this ok?
Best regards,
Maxim Levitsky
PATCH 14/17 MTD: common module for smartmedia/xD support
In reply to Maxim LevitskyThis small module implements few helpers that are usefull for nand drivers for SmartMedia/xD card readers.
--- drivers/mtd/nand/Kconfig | 9 +++ drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/sm_common.c | 126 ++++++++++++++++++++++++++++++++++++++++++ drivers/mtd/nand/sm_common.h | 61 ++++++++++++++++++++ 4 files changed, 197 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/nand/sm_common.c create mode 100644 drivers/mtd/nand/sm_common.h
drivers/mtd/nand/Kconfig +9 -0
@@ -18,6 +18,10 @@ config MTD_NAND_VERIFY_WRITE device thinks the write was successful, a bit could have been flipped accidentally due to device wear or something else. +config MTD_NAND_SMARTMEDIA + boolean + default n + config MTD_NAND_ECC_SMC bool "NAND ECC Smart Media byte order" default n
@@ -25,6 +29,11 @@ config MTD_NAND_ECC_SMC Software ECC according to the Smart Media Specification. The original Linux implementation had byte 0 and 1 swapped. +config MTD_SM_COMMON + select MTD_NAND_SMARTMEDIA + tristate + default n + config MTD_NAND_MUSEUM_IDS bool "Enable chip ids for obsolete ancient NAND devices" depends on MTD_NAND
drivers/mtd/nand/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_MTD_NAND) += nand.o nand_ecc.o obj-$(CONFIG_MTD_NAND_IDS) += nand_ids.o +obj-$(CONFIG_MTD_SM_COMMON) += sm_common.o obj-$(CONFIG_MTD_NAND_CAFE) += cafe_nand.o obj-$(CONFIG_MTD_NAND_SPIA) += spia.o
drivers/mtd/nand/sm_common.c new file +126 -0
126 lines not on this page · raw message
drivers/mtd/nand/sm_common.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
1.6.3.3
PATCH 15/17 MTD: add few workarounds to nand system for SmartMedia/xD chips.
In reply to Maxim Levitsky* Add an option NAND_SMARTMEDIA that can be set by nand driver If set, it will cause separate ID table to be used, which includes mask rom devices and new xD cards
* Workaround for wrong write protect status on some xD cards
--- drivers/mtd/nand/nand_base.c | 30 ++++++++++++++++++++++-------- drivers/mtd/nand/nand_ids.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/mtd/nand.h | 11 +++++++++++ 3 files changed, 72 insertions(+), 8 deletions(-)
drivers/mtd/nand/nand_base.c +22 -8
@@ -397,9 +397,18 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)static int nand_check_wp (struct mtd_info *mtd) {struct nand_chip *chip = mtd->priv; +int wp; + +/* broken xD cards report WP despite beeing writable */ +if (chip->options &NAND_BROKEN_XD ) +return 0 ; +/* Check the WP bit */ chip->cmdfunc (mtd,NAND_CMD_STATUS ,-1 ,-1 ); -return (chip->read_byte (mtd) &NAND_STATUS_WP ) ?0 :1 ; + wp = (chip->read_byte (mtd) &NAND_STATUS_WP ) ?0 :1 ; + + +return wp; }/**
@@ -2622,14 +2631,18 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, }/* Lookup the flash id */ -for (i =0 ; nand_flash_ids[i].name !=NULL ; i++) { -if (dev_id == nand_flash_ids[i].id) { - type = &nand_flash_ids[i]; +#ifdef CONFIG_MTD_NAND_SMARTMEDIA +if (chip->options &NAND_SMARTMEDIA ) + type = nand_smartmedia_flash_ids; + else +#endif + type = nand_flash_ids; + +for (i =0 ; type->name !=NULL ; type++) +if (dev_id == type->id)break ; - } - } -if (!type) +if (!type->name)return ERR_PTR (-ENODEV );if (!mtd->name)
@@ -2986,7 +2999,8 @@ int nand_scan_tail(struct mtd_info *mtd)/* Fill in remaining MTD driver data */ mtd->type =MTD_NANDFLASH ; - mtd->flags =MTD_CAP_NANDFLASH ; + mtd->flags = chip->options &NAND_ROM ?MTD_CAP_ROM : +MTD_CAP_NANDFLASH ; mtd->erase = nand_erase; mtd->point =NULL ; mtd->unpoint =NULL ;
drivers/mtd/nand/nand_ids.c +39 -0
@@ -127,6 +127,45 @@ struct nand_flash_dev nand_flash_ids[] = { {NULL,} }; +#ifdef CONFIG_MTD_NAND_SMARTMEDIA +struct nand_flash_dev nand_smartmedia_flash_ids[] = { + +/* SmartMedia */ + {"SmartMedia 1MiB 5V" ,0x6e ,256 ,1 ,0x1000 ,0 }, + {"SmartMedia 1MiB 3,3V" ,0xe8 ,256 ,1 ,0x1000 ,0 }, + {"SmartMedia 1MiB 3,3V" ,0xec ,256 ,1 ,0x1000 ,0 }, + {"SmartMedia 2MiB 3,3V" ,0xea ,256 ,2 ,0x1000 ,0 }, + {"SmartMedia 2MiB 5V" ,0x64 ,256 ,2 ,0x1000 ,0 }, + {"SmartMedia 2MiB 3,3V ROM" ,0x5d ,512 ,2 ,0x2000 ,NAND_ROM }, + {"SmartMedia 4MiB 3,3V" ,0xe3 ,512 ,4 ,0x2000 ,0 }, + {"SmartMedia 4MiB 3,3/5V" ,0xe5 ,512 ,4 ,0x2000 ,0 }, + {"SmartMedia 4MiB 5V" ,0x6b ,512 ,4 ,0x2000 ,0 }, + {"SmartMedia 4MiB 3,3V ROM" ,0xd5 ,512 ,4 ,0x2000 ,NAND_ROM }, + {"SmartMedia 8MiB 3,3V" ,0xe6 ,512 ,8 ,0x2000 ,0 }, + {"SmartMedia 8MiB 3,3V ROM" ,0xd6 ,512 ,8 ,0x2000 ,NAND_ROM }, + +#define XD_TYPEM (NAND_NO_AUTOINCR | NAND_BROKEN_XD) +/* xD / SmartMedia */ + {"SmartMedia/xD 16MiB 3,3V" ,0x73 ,512 ,16 ,0x4000 ,0 }, + {"SmartMedia 16MiB 3,3V ROM" ,0x57 ,512 ,16 ,0x4000 ,NAND_ROM }, + {"SmartMedia/xD 32MiB 3,3V" ,0x75 ,512 ,32 ,0x4000 ,0 }, + {"SmartMedia 32MiB 3,3V ROM" ,0x58 ,512 ,32 ,0x4000 ,NAND_ROM }, + {"SmartMedia/xD 64MiB 3,3V" ,0x76 ,512 ,64 ,0x4000 ,0 }, + {"SmartMedia 64MiB 3,3V ROM" ,0xd9 ,512 ,64 ,0x4000 ,NAND_ROM }, + {"SmartMedia/xD 128MiB 3,3V" ,0x79 ,512 ,128 ,0x4000 ,0 }, + {"SmartMedia 128MiB 3,3V ROM" ,0xda ,512 ,128 ,0x4000 ,NAND_ROM }, + {"SmartMedia/xD 256MiB 3,3V" ,0x71 ,512 ,256 ,0x4000 ,XD_TYPEM }, + {"SmartMedia 256MiB 3,3V ROM" ,0x5b ,512 ,256 ,0x4000 ,NAND_ROM }, + +/* xD only */ + {"xD 512MiB 3,3V" ,0xDC ,512 ,512 ,0x4000 ,XD_TYPEM }, + {"xD 1GiB 3,3V" ,0xD3 ,512 ,1024 ,0x4000 ,XD_TYPEM }, + {"xD 2GiB 3,3V" ,0xD5 ,512 ,2048 ,0x4000 ,XD_TYPEM }, + {NULL ,} +}; +EXPORT_SYMBOL (nand_smartmedia_flash_ids); +#endif +/* * Manufacturer ID list */
include/linux/mtd/nand.h +11 -0
@@ -170,6 +170,12 @@ typedef enum {/* Chip does not allow subpage writes */ #define NAND_NO_SUBPAGE_WRITE 0x00000200 +/* Device is one of 'new' xD cards that expose fake nand command set */ +#define NAND_BROKEN_XD 0x00000400 + +/* Device behaves just like nand, but is readonly */ +#define NAND_ROM 0x00000800 +/* Options valid for Samsung large page devices */ #define NAND_SAMSUNG_LP_OPTIONS \ (NAND_NO_PADDING | NAND_CACHEPRG | NAND_COPYBACK)
@@ -195,9 +201,13 @@ typedef enum {/* This option is defined if the board driver allocates its own buffers (e.g. because it needs them DMA-coherent */ #define NAND_OWN_BUFFERS 0x00040000 +/* Chip may not exist, so silence any errors in scan */ #define NAND_SCAN_SILENT_NODEV 0x00080000 +/* controller supports only xD/SmartMedia cards*/ +#define NAND_SMARTMEDIA 0x00100000 +/* Options set by nand scan */ /* Nand scan has allocated controller struct */ #define NAND_CONTROLLER_ALLOC 0x80000000
@@ -458,6 +468,7 @@ struct nand_manufacturers { };extern struct nand_flash_dev nand_flash_ids[]; +extern struct nand_flash_dev nand_smartmedia_flash_ids[];extern struct nand_manufacturers nand_manuf_ids[];extern int nand_scan_bbt (struct mtd_info *mtd,struct nand_bbt_descr *bd);
Signature · 1 line
1.6.3.3
PATCH 16/17 MTD: Add nand driver for ricoh xD/SmartMedia reader
In reply to Maxim LevitskyThis adds a driver for Ricoh xD card reader with PCI id 0x0852
Since the reader is a part of larger mulifunction chip, it is hard to determine the correct model name. Might be R5C852.
Driver is complete, but bewere of the fact that some (probably only type M) xD cards are 'fake' which means that they have an on board CPU and expose emulated nand command set
These cards don't even store the oob area on the flash, but generate it on the fly from something else.
Thus they demand to have proper values written in the oob area, and therefore only useful with SmartMedia FTL.
--- MAINTAINERS | 6 + drivers/mtd/nand/Kconfig | 11 + drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/r822.c | 1110 +++++++++++++++++++++++++++++++++++++++++++++ drivers/mtd/nand/r822.h | 154 +++++++ include/linux/pci_ids.h | 2 + 6 files changed, 1284 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/nand/r822.c create mode 100644 drivers/mtd/nand/r822.h
MAINTAINERS +6 -0
@@ -4574,6 +4574,12 @@ S: Maintained F: Documentation/rfkill.txt F: net/rfkill/ +RICOH SMARTMEDIA/XD DRIVER +M: Maxim Levitsky <[email protected]> +S: Maintained +F: drivers/mtd/nand/r822.c +F: drivers/mtd/nand/r822.h + RISCOM8 DRIVER S: Orphan F: Documentation/serial/riscom8.txt
drivers/mtd/nand/Kconfig +11 -0
@@ -113,6 +113,17 @@ config MTD_NAND_TS7250 config MTD_NAND_IDS tristate +config MTD_NAND_RICOH + tristate "Ricoh xD card reader" + default n + select MTD_SM_COMMON + help + Enable support for Ricoh xD card reader + You also need to enable ether + NAND SSFDC (SmartMedia) read only translation layer' or new + expermental, readwrite + 'SmartMedia/xD new translation layer' + config MTD_NAND_AU1550 tristate "Au1550/1200 NAND support" depends on SOC_AU1200 || SOC_AU1550
drivers/mtd/nand/Makefile +1 -0
@@ -43,5 +43,6 @@ obj-$(CONFIG_MTD_NAND_TXX9NDFMC) += txx9ndfmc.o obj-$(CONFIG_MTD_NAND_W90P910) += w90p910_nand.o obj-$(CONFIG_MTD_NAND_NOMADIK) += nomadik_nand.o obj-$(CONFIG_MTD_NAND_BCM_UMI) += bcm_umi_nand.o nand_bcm_umi.o +obj-$(CONFIG_MTD_NAND_RICOH) += r822.o nand-objs := nand_base.o nand_bbt.o
drivers/mtd/nand/r822.c new file +1110 -0
1,110 lines not on this page · raw message
drivers/mtd/nand/r822.h new file +154 -0
154 lines not on this page · raw message
include/linux/pci_ids.h +2 -0
@@ -1523,6 +1523,8 @@#define PCI_DEVICE_ID_RICOH_R5C822 0x0822#define PCI_DEVICE_ID_RICOH_R5C832 0x0832#define PCI_DEVICE_ID_RICOH_R5C843 0x0843 +#define PCI_DEVICE_ID_RICOH_R5C852 0x0852 +#define PCI_VENDOR_ID_DLINK 0x1186#define PCI_DEVICE_ID_DLINK_DGE510T 0x4c00
Signature · 1 line
1.6.3.3
PATCH 17/17 MTD: Add new SmartMedia/xD FTL
In reply to Maxim LevitskyThis implements new readwrite SmartMedia/xd FTL.
mtd driver must have support proper ECC and badblock vertification based on oob parts for 512 bytes nand.
Also mtd driver must define read_oob and write_oob, which are used to read and write both data and oob together.
--- drivers/mtd/Kconfig | 21 + drivers/mtd/Makefile | 1 + drivers/mtd/sm_ftl.c | 1264 ++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/mtd/sm_ftl.h | 92 ++++ 4 files changed, 1378 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/sm_ftl.c create mode 100644 drivers/mtd/sm_ftl.h
drivers/mtd/Kconfig +21 -0
@@ -304,6 +304,27 @@ config SSFDC This enables read only access to SmartMedia formatted NAND flash. You can mount it with FAT file system. + +config SM_FTL + tristate "SmartMedia/xD new translation layer" + depends on EXPERIMENTAL && BLOCK + select MTD_BLKDEVS + help + This enables new and very EXPERMENTAL support for SmartMedia/xD + FTL (Flash tanslation layer) + Write support isn't yet well tested, therefore this code IS likely to + eat your card, so please don't use it together with valuable data. + Use readonly driver (CONFIG_SSFDC) instead. + +config SM_FTL_MUSEUM + boolean "Additional Support for 1MB and 2MB SmartMedia cards" + depends on SM_FTL && MTD_NAND + select MTD_NAND_ECC_SMC + help + Very old SmartMedia cards need ECC to be caluculated in the FTL + Such cards are very rare, thus enabling this option is mostly useless + Also this support is completely UNTESTED. + config MTD_OOPS tristate "Log panic/oops to an MTD buffer" depends on MTD
drivers/mtd/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_NFTL) += nftl.o obj-$(CONFIG_INFTL) += inftl.o obj-$(CONFIG_RFD_FTL) += rfd_ftl.o obj-$(CONFIG_SSFDC) += ssfdc.o +obj-$(CONFIG_SM_FTL) += sm_ftl.o obj-$(CONFIG_MTD_OOPS) += mtdoops.o nftl-objs := nftlcore.o nftlmount.o
drivers/mtd/sm_ftl.c new file +1264 -0
1,264 lines not on this page · raw message
drivers/mtd/sm_ftl.h new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
1.6.3.3