Skip to contentSkip to conversation

RFC: [PATCH V2 0/9 Integration of SmartMedia/xD into mtd subsystem

PATCH In review Maxim Levitsky 2 participants 19 messages Jan 8, 2010 – Jan 11, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

This is second version of my patchset.

Changes since V1:

-> Ported to latest kernel revision (2.6.33-rc3) -> Resolved problem with oob layout
-> Resoved all checkpatch.pl issues
-> Tested that indeed all hardware devices of this type have same PCI ID

Remaining issues:

* Write speed is of course still very low, but like I said, it might be hardware problem.

* No support for 256 byte SmartMedia in the FTL. I don't have the hardware to test that, and I think for now there is not much need for that.
(It only applies to 1MB and 2MB SmartMedia devices anyway...)

* Like I said some XD cards are fake, thus have to be used with the FTL, This is a hardware problem too.
If I knew which xD cards are affected, and had a way to know for sure they have an FTL inside, I could implement a fake FTL, thus gain higher write speed (and maybe solve that way issue #1)

Best regards,
Maxim Levitsky

#1 lore raw

PATCH 1/9 MTD: call remove notifiers before removing the device

Quoted 1 line

From 1855da2a21882c803e5dfcfb556fff5bc6989c31 Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Fri, 8 Jan 2010 15:14:20 +0200
Subject: [PATCH 1/9] MTD: call remove notifiers before removing the device

This is first step in implementing proper hotplug support.
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
index c356c0a..87ff83f 100644
@@ -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
#2 lore raw

PATCH 2/9 MTD: create lockless versions of {get,put}_mtd_device

In reply to Maxim Levitsky
Quoted 1 line

From 1531249dd2c0e33d727ed8cbd0719eb4e9af2266 Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Fri, 8 Jan 2010 15:51:22 +0200
Subject: [PATCH 2/9] MTD: create lockless versions of {get,put}_mtd_device

This will be used to resolve deadlock in block translation layer.

---
 drivers/mtd/mtdcore.c   |   61 ++++++++++++++++++++++++++++++-----------------
 include/linux/mtd/mtd.h |    3 +-
 2 files changed, 41 insertions(+), 23 deletions(-)
drivers/mtd/mtdcore.c +39 -22
index 87ff83f..96b4a05 100644
@@ -454,27 +454,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;
 }
 
 /**
@@ -525,18 +536,22 @@ out_unlock:
 
 void put_mtd_device(struct mtd_info *mtd)
 {
-	int c;
-
 	mutex_lock(&mtd_table_mutex);
-	c = --mtd->usecount;
-	if (mtd->put_device)
-		mtd->put_device(mtd);
+	__put_mtd_device(mtd);
 	mutex_unlock(&mtd_table_mutex);
-	BUG_ON(c < 0);
 
 	module_put(mtd->owner);
 }
 
+void __put_mtd_device(struct mtd_info *mtd)
+{
+	--mtd->usecount;
+	BUG_ON(mtd->usecount < 0);
+
+	if (mtd->put_device)
+		mtd->put_device(mtd);
+}
+
 /* default_mtd_writev - default mtd writev method for MTD devices that
  *			don't implement their own
  */
@@ -570,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
index 0f32a9b..662d747 100644
@@ -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
#3 lore raw

Re: [PATCH 2/9] MTD: create lockless versions of {get,put}_mtd_device

drivers/mtd/mtdcore.c struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) · line 462

Quoted 2 lines · Maxim Levitsky
drivers/mtd/mtdcore.c +1 -0
+	err = __get_mtd_device(ret);

Function is called here, afaics not declared and defined...

Quoted 2 lines

[...]
+int __get_mtd_device(struct mtd_info *mtd)

...further below. Didn't gcc complain about this? Or am I missing something?

Jörn

Signature · 2 lines
Luck is when opportunity meets good preparation.
-- Chinese proverb
#4 lore raw

Re: [PATCH 2/9] MTD: create lockless versions of {get,put}_mtd_device

Quoted 6 lines · Jörn Engel

drivers/mtd/mtdcore.c struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) · line 462

Quoted 2 lines · Maxim Levitsky
drivers/mtd/mtdcore.c +1 -0
+	err = __get_mtd_device(ret);

Function is called here, afaics not declared and defined...

Quoted 8 lines
Quoted 2 lines

[...]
+int __get_mtd_device(struct mtd_info *mtd)

...further below. Didn't gcc complain about this? Or am I missing something?

Jörn

Yep, you miss this:

+extern int __get_mtd_device(struct mtd_info *mtd); +extern void __put_mtd_device(struct mtd_info *mtd);

I put that into the header, so these functions can be used outside.

When I compiled the kernel, there were no warnings.

Best regards,
Maxim Levitsky

#5 lore raw

Re: [PATCH 2/9] MTD: create lockless versions of {get,put}_mtd_device

Quoted 9 lines · Maxim Levitsky

Yep, you miss this:

include/linux/mtd/mtd.h +2 -0
+extern int __get_mtd_device(struct mtd_info *mtd);
+extern void __put_mtd_device(struct mtd_info *mtd);

I put that into the header, so these functions can be used outside.

When I compiled the kernel, there were no warnings.

Maxim: 1
Joern: 0

Jörn

Signature · 3 lines
But this is not to say that the main benefit of Linux and other GPL
software is lower-cost. Control is the main benefit--cost is secondary.
-- Bruce Perens
#6 lore raw

PATCH 3/9 MTD: blkdevs: make hotplug work

In reply to Maxim Levitsky
Quoted 1 line

From 427c68fd6cb0fd228dbf8eebc832f63799b119ca Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Fri, 8 Jan 2010 15:52:12 +0200
Subject: [PATCH 3/9] MTD: blkdevs: make hotplug work

This changes the blkdev common module for translation layers to survive when underlying mtd device disappears.

To do so the following conceptual changes were made:

* disk queue and thread are now one per mtd device This was it is easy to flush and destroy the queue

* the struct mtd_blktrans_dev will now be freed automaticly when last user of the device quits.
All existing translation layers are adjusted

* ->open and release function of the translation layer will never be called twise or more in the row.
This makes code simplier.
Also the ->release will be called just before mtd device disappears This and above is the only visable changes on the outside.

Tested with mtdblock, ssfdc and my own sm_ftl on top of physicly hotplugable nand card.

---
 drivers/mtd/ftl.c            |    1 -
 drivers/mtd/inftlcore.c      |    1 -
 drivers/mtd/mtd_blkdevs.c    |  237 ++++++++++++++++++++++++++---------------
 drivers/mtd/mtdblock.c       |    1 -
 drivers/mtd/mtdblock_ro.c    |    1 -
 drivers/mtd/mtdcore.c        |    3 +-
 drivers/mtd/nftlcore.c       |    1 -
 drivers/mtd/rfd_ftl.c        |    1 -
 drivers/mtd/ssfdc.c          |    1 -
 include/linux/mtd/blktrans.h |   13 ++-
 10 files changed, 160 insertions(+), 100 deletions(-)
drivers/mtd/ftl.c +0 -1
index e56d6b4..62da9eb 100644
@@ -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
index 8aca552..015a7fe 100755
@@ -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 +150 -87

400 lines not on this page · raw message

drivers/mtd/mtdblock.c +0 -1
index 9f41b1a..d8322cc 100644
@@ -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
index 852165f..54ff288 100644
@@ -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/mtdcore.c +2 -1
index 96b4a05..0e86208 100644
@@ -540,7 +540,6 @@ void put_mtd_device(struct mtd_info *mtd)
 	__put_mtd_device(mtd);
 	mutex_unlock(&mtd_table_mutex);
 
-	module_put(mtd->owner);
 }
 
 void __put_mtd_device(struct mtd_info *mtd)
@@ -550,6 +549,8 @@ void __put_mtd_device(struct mtd_info *mtd)
 
 	if (mtd->put_device)
 		mtd->put_device(mtd);
+
+	module_put(mtd->owner);
 }
 
 /* default_mtd_writev - default mtd writev method for MTD devices that
drivers/mtd/nftlcore.c +0 -1
index 1002e18..a4578bf 100644
@@ -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
index d2aa9c4..63b83c0 100644
@@ -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
index 3f67e00..81c4ecd 100644
@@ -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 +8 -5
index 8b4aa05..054b053 100644
@@ -24,10 +24,15 @@ struct mtd_blktrans_dev {
 	int devnum;
 	unsigned long size;
 	int readonly;
-	void *blkcore_priv; /* gendisk in 2.5, devfs_handle in 2.4 */
-};
+	int deleted;
+	int open;
 
-struct blkcore_priv; /* Differs for 2.4 and 2.5 kernels; private */
+	struct gendisk *disk;
+	struct task_struct *thread;
+	struct request_queue *rq;
+	spinlock_t queue_lock;
+	void *priv;
+};
 
 struct mtd_blktrans_ops {
 	char *name;
@@ -60,8 +65,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
#7 lore raw

PATCH 4/9 MTD: make mtdtrans thread freezable.

In reply to Maxim Levitsky
Quoted 1 line

From e8648ebdc31d65556fccb340e4c16edc43017cf1 Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Fri, 8 Jan 2010 15:52:18 +0200
Subject: [PATCH 4/9] MTD: make mtdtrans thread freezable.

This makes the mtd blktrans thread enter the freezer in between accesses to nand device.
This will ensure that we aren't suspending the system in the middle of page read/write and even worse erase, which is a bad idea.

---
 drivers/mtd/mtd_blkdevs.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
drivers/mtd/mtd_blkdevs.c +7 -7
index 04a875f..db996d6 100644
@@ -20,6 +20,7 @@
 #include <linux/init.h>
 #include <linux/mutex.h>
 #include <linux/kthread.h>
+#include <linux/freezer.h>
 #include <asm/uaccess.h>
 
 #include "mtdcore.h"
@@ -79,36 +80,35 @@ static int mtd_blktrans_thread(void *arg)
 	struct request_queue *rq = dev->rq;
 	struct request *req = NULL;
 
-	spin_lock_irq(rq->queue_lock);
+	set_freezable();
 
 	while (!kthread_should_stop()) {
 		int res;
 
+		try_to_freeze();
+
+		spin_lock_irq(rq->queue_lock);
 		if (!req && !(req = blk_fetch_request(rq))) {
 			set_current_state(TASK_INTERRUPTIBLE);
 			spin_unlock_irq(rq->queue_lock);
 			schedule();
-			spin_lock_irq(rq->queue_lock);
 			continue;
 		}
-
 		spin_unlock_irq(rq->queue_lock);
 
+
 		mutex_lock(&dev->lock);
 		res = do_blktrans_request(dev->tr, dev, req);
 		mutex_unlock(&dev->lock);
 
 		spin_lock_irq(rq->queue_lock);
-
 		if (!__blk_end_request_cur(req, res))
 			req = NULL;
+		spin_unlock_irq(rq->queue_lock);
 	}
 
 	if (req)
 		__blk_end_request_all(req, -EIO);
-
-	spin_unlock_irq(rq->queue_lock);
-
 	return 0;
 }
 
Signature · 1 line
1.6.3.3
#8 lore raw

PATCH 5/9 MTD: nand subsystem, export nand_do_read_oob and nand_do_write_oob

In reply to Maxim Levitsky
Quoted 1 line

From 5dbd1e5f7b5a4fe76053e25e744327156f015c6f Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Fri, 8 Jan 2010 15:54:42 +0200
Subject: [PATCH 5/9] MTD: nand subsystem, export nand_do_read_oob and nand_do_write_oob

Drivers might need sane way to read/write oob area, but can't use mtd interface due to locking.

---
 drivers/mtd/nand/nand_base.c |   10 +++++-----
 include/linux/mtd/nand.h     |    5 +++++
 2 files changed, 10 insertions(+), 5 deletions(-)
drivers/mtd/nand/nand_base.c +5 -5
index 8f2958f..8e31245 100644
@@ -99,9 +99,6 @@ static struct nand_ecclayout nand_oob_128 = {
 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
  * compiled away when LED support is disabled.
@@ -1536,7 +1533,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;
@@ -1620,6 +1617,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
@@ -2110,7 +2108,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;
@@ -2181,6 +2179,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
@@ -3082,6 +3081,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 +5 -0
index ccab9df..75575fb 100644
@@ -469,6 +469,11 @@ 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);
 /**
  * struct platform_nand_chip - chip level device structure
  * @nr_chips:		max. number of chips to scan for
Signature · 1 line
1.6.3.3
#9 lore raw

PATCH 6/9 mtd: common module for smartmedia/xD support

In reply to Maxim Levitsky
Quoted 1 line

From 7297f3c08c9cd19b5cca4073afc225e1e4e293fb Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Fri, 8 Jan 2010 16:00:56 +0200
Subject: [PATCH 6/9] mtd: common module for smartmedia/xD support
This small module implements few helpers that are usefull for nand drivers for SmartMedia/xD card readers
and for SmartMedia translation layer.

---
 drivers/mtd/Kconfig     |    9 ++
 drivers/mtd/Makefile    |    1 +
 drivers/mtd/sm_common.c |  227 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/sm_common.h |   50 ++++++++++
 4 files changed, 287 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/sm_common.c
 create mode 100644 drivers/mtd/sm_common.h
drivers/mtd/Kconfig +9 -0
index ecf90f5..ebeabd6 100644
@@ -25,6 +25,15 @@ config MTD_DEBUG_VERBOSE
 	help
 	  Determines the verbosity level of the MTD debugging messages.
 
+config MTD_NAND_SMARTMEDIA
+	boolean
+
+config MTD_SM_COMMON
+	depends on MTD_NAND
+	select MTD_NAND_SMARTMEDIA
+	tristate
+	default n
+
 config MTD_TESTS
 	tristate "MTD tests support"
 	depends on m
drivers/mtd/Makefile +1 -0
index 82d1e4d..02c5b17 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_MTD)		+= mtd.o
 mtd-y				:= mtdcore.o mtdsuper.o mtdbdi.o
 mtd-$(CONFIG_MTD_PARTITIONS)	+= mtdpart.o
 
+obj-$(CONFIG_MTD_SM_COMMON) 	+= sm_common.o
 obj-$(CONFIG_MTD_CONCAT)	+= mtdconcat.o
 obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
 obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o
drivers/mtd/sm_common.c new file +227 -0

227 lines not on this page · raw message

drivers/mtd/sm_common.h new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#10 lore raw

PATCH 7/9 MTD: add few workarounds to nand system for SmartMedia/xD chips.

In reply to Maxim Levitsky
Quoted 1 line

From 4ade18c0eff30b0a5aa7360651448ec4efff761f Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Fri, 8 Jan 2010 16:03:10 +0200
Subject: [PATCH 7/9] MTD: add few workarounds to nand system for SmartMedia/xD chips.

* 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 |   29 +++++++++++++++++++++--------
 drivers/mtd/nand/nand_ids.c  |   38 ++++++++++++++++++++++++++++++++++++++
 drivers/mtd/sm_common.c      |    2 +-
 include/linux/mtd/nand.h     |   11 +++++++++++
 4 files changed, 71 insertions(+), 9 deletions(-)
drivers/mtd/nand/nand_base.c +21 -8
index 8e31245..a4a9284 100644
@@ -398,9 +398,17 @@ 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;
+
 	/* 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;
+
+	/* broken xD cards report WP despite beeing writable */
+	if (chip->options & NAND_BROKEN_XD)
+		return 0;
+
+	return wp;
 }
 
 /**
@@ -2624,14 +2632,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)
@@ -2988,7 +3000,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 +38 -0
index 69ee2c9..7ac7538 100644
@@ -127,6 +127,44 @@ 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},
+
+	/* 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, NAND_BROKEN_XD},
+	{"SmartMedia 256MiB 3,3V ROM",	0x5b, 512, 256, 0x4000, NAND_ROM},
+
+	/* xD only */
+	{"xD 512MiB 3,3V",	0xDC, 512, 512, 0x4000, NAND_BROKEN_XD},
+	{"xD 1GiB 3,3V",	0xD3, 512, 1024, 0x4000, NAND_BROKEN_XD},
+	{"xD 2GiB 3,3V",	0xD5, 512, 2048, 0x4000, NAND_BROKEN_XD},
+	{NULL,}
+};
+EXPORT_SYMBOL(nand_smartmedia_flash_ids);
+#endif
+
 /*
 *	Manufacturer ID list
 */
drivers/mtd/sm_common.c +1 -1
index 45b577f..6234482 100644
@@ -186,7 +186,7 @@ int sm_register_device(struct mtd_info *mtd)
 	struct nand_chip *chip = (struct nand_chip *)mtd->priv;
 	int ret;
 
-	chip->options |= NAND_SKIP_BBTSCAN | NAND_NO_AUTOINCR;
+	chip->options |= NAND_SKIP_BBTSCAN | NAND_SMARTMEDIA | NAND_NO_AUTOINCR;
 
 	/* Scan for card properties */
 	ret = nand_scan_ident(mtd, 1);
include/linux/mtd/nand.h +11 -0
index 75575fb..a3670c1 100644
@@ -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
#11 lore raw

PATCH 8/9 mtd: Add nand driver for ricoh xD/SmartMedia reader

In reply to Maxim Levitsky
Quoted 1 line

From 8ba5765479d06c2b2cd5d54ad62bd4c4406dac85 Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Fri, 8 Jan 2010 16:26:41 +0200
Subject: [PATCH 8/9] mtd: Add nand driver for ricoh xD/SmartMedia reader

This adds a driver for Ricoh xD card reader that has 0x0852 PCI ID

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 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   | 1051 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/nand/r822.h   |  155 +++++++
 5 files changed, 1224 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/r822.c
 create mode 100644 drivers/mtd/nand/r822.h
MAINTAINERS +6 -0
index 8f0109b..81c451b 100644
@@ -4585,6 +4585,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
index 677cd53..59bfabb 100644
@@ -104,6 +104,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
index 1407bd1..986ab9c 100644
@@ -42,5 +42,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 +1051 -0

1,051 lines not on this page · raw message

drivers/mtd/nand/r822.h new file +155 -0

155 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#12 lore raw

PATCH 9/9 mtd: Add new SmartMedia/xD FTL

In reply to Maxim Levitsky
Quoted 1 line

From 743f723b6e7134cf9d99a158f3ac920c180d406a Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Fri, 8 Jan 2010 16:44:07 +0200
Subject: [PATCH 9/9] mtd: Add new SmartMedia/xD FTL

This implements new readwrite SmartMedia/xd FTL.

It depends on nand driver to define proper oob layout that excludes all ecc areas and nothing more.

Support for very old 256 byte/page devices is not yet enabled/complete. For these devices, all ecc handling will be done inside this FTL due to wierd oob layout.

---
 drivers/mtd/Kconfig  |   12 +
 drivers/mtd/Makefile |    1 +
 drivers/mtd/sm_ftl.c | 1043 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/sm_ftl.h |   75 ++++
 4 files changed, 1131 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/sm_ftl.c
 create mode 100644 drivers/mtd/sm_ftl.h
drivers/mtd/Kconfig +12 -0
index ebeabd6..e13bf41 100644
@@ -313,6 +313,18 @@ 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
+	select MTD_SM_COMMON
+	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 MTD_OOPS
 	tristate "Log panic/oops to an MTD buffer"
 	depends on MTD
drivers/mtd/Makefile +1 -0
index 02c5b17..02f6375 100644
@@ -25,6 +25,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 +1043 -0

1,043 lines not on this page · raw message

drivers/mtd/sm_ftl.h new file +75 -0

75 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#13 lore raw

Re: [PATCH 9/9] mtd: Add new SmartMedia/xD FTL

Quoted 10 lines · Maxim Levitsky

This implements new readwrite SmartMedia/xd FTL.

It depends on nand driver to define proper oob layout that excludes all ecc areas and nothing more.

Support for very old 256 byte/page devices is not yet enabled/complete. For these devices, all ecc handling will be done inside this FTL due to wierd oob layout.

Quoted 6 lines
---
 drivers/mtd/Kconfig  |   12 +
 drivers/mtd/Makefile |    1 +
 drivers/mtd/sm_ftl.c | 1043 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/sm_ftl.h |   75 ++++

sm_ftl is certainly nicer than ssfdc.c - at least I can decrypt the acronym. But I am missing a reason why ssfdc is not sufficient and we need yet another implementation of the same ftl.

Or maybe ssfdc is sufficient or barely sufficient and just needs a small patch?

Jörn

Signature · 2 lines
He that composes himself is wiser than he that composes a book.
-- B. Franklin
#14 lore raw

Re: [PATCH 9/9] mtd: Add new SmartMedia/xD FTL

Quoted 18 lines · Jörn Engel
Quoted 10 lines · Maxim Levitsky

This implements new readwrite SmartMedia/xd FTL.

It depends on nand driver to define proper oob layout that excludes all ecc areas and nothing more.

Support for very old 256 byte/page devices is not yet enabled/complete. For these devices, all ecc handling will be done inside this FTL due to wierd oob layout.

Quoted 6 lines
---
 drivers/mtd/Kconfig  |   12 +
 drivers/mtd/Makefile |    1 +
 drivers/mtd/sm_ftl.c | 1043 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/sm_ftl.h |   75 ++++
Quoted 3 lines

sm_ftl is certainly nicer than ssfdc.c - at least I can decrypt the acronym. But I am missing a reason why ssfdc is not sufficient and we need yet another implementation of the same ftl.

ssfdc is readonly, and bulk of the hard work is the write part. Also ssfdc creates one big table by reading oob of whole device and this takes about 1 second here.
I instead defer this by doing it one per zone.

Ideally ssfdc can be deprecated/removed, since my driver is its superset.
However if one needs only R/O support he can use the smaller and safer ssfdc.c

I also though about patching the ssfdc.c, but really there will be nothing old left after doing that.

Best regards,
Maxim Levitsky

#15 lore raw
In reply to Maxim Levitsky
Quoted 3 lines · Maxim Levitsky

* Write speed is of course still very low, but like I said, it might be hardware problem.

Iirc the alauda could do about 400kB/s. Speed didn't change noticeably between 16M and 256M cards. My conclusion back then was to blame the alauda chip. If you get even less, the problem likely isn't in the cards but in the reader and/or your driver.

Quoted 4 lines

* No support for 256 byte SmartMedia in the FTL. I don't have the hardware to test that, and I think for now there is not much need for that.
(It only applies to 1MB and 2MB SmartMedia devices anyway...)

Fair enough. If either of the two people who still use such cards cares... ;)

Jörn

Signature · 4 lines
I've never met a human being who would want to read 17,000 pages of
documentation, and if there was, I'd kill him to get him out of the
gene pool.
-- Joseph Costello
#16 lore raw
Quoted 9 lines · Jörn Engel
Quoted 3 lines · Maxim Levitsky

* Write speed is of course still very low, but like I said, it might be hardware problem.

Iirc the alauda could do about 400kB/s. Speed didn't change noticeably between 16M and 256M cards. My conclusion back then was to blame the alauda chip. If you get even less, the problem likely isn't in the cards but in the reader and/or your driver.

Who knows...
Like I said, I get around 330 Kbytes/s in card reader integrated in printer. It is still much higher that what I get with this driver....

I will figure that out sooner or later.

Btw, your cards aren't Type M, right?
However I use here a Type M card, and its likely to include an FTL inside, thus, it might explain the low speeds I get there partially...

Best regards,
Maxim Levitsky

#17 lore raw
Quoted 4 lines · Maxim Levitsky

Btw, your cards aren't Type M, right?
However I use here a Type M card, and its likely to include an FTL inside, thus, it might explain the low speeds I get there partially...

No, mine were the old ones before marketing invented the two types.

Jörn

Signature · 3 lines
Fancy algorithms are buggier than simple ones, and they're much harder
to implement. Use simple algorithms as well as simple data structures.
-- Rob Pike
#18 lore raw
Quoted 10 lines · Jörn Engel
Quoted 4 lines · Maxim Levitsky

Btw, your cards aren't Type M, right?
However I use here a Type M card, and its likely to include an FTL inside, thus, it might explain the low speeds I get there partially...

No, mine were the old ones before marketing invented the two types.

Jörn

I finally located the source of slowdown.
It appears to be caused by too large caching I did (5 erase blocks). If I cache one block, write speed nears 1 MB/s.
As a bonus that makes the FTL much simplified.

Another small flaw that currently exists in my FTL is that it ignores the underlying badblock support from mtd driver and requeres it to expose the two bad block bytes in the oob layout, I think I can avoid that after all.

Other that that, everything is just perfect.

I post updated patchset soon.

Best regards,
Maxim Levitsky