Skip to contentSkip to conversation

[PATCH v3 memstick: support for legacy sony memsticks

PATCH In review Maxim Levitsky 4 participants 15 messages Sep 26, 2012 – Oct 11, 2012

Subsystems (3)
lore
Share & tools
lore

Maxim Levitsky

author maintainer
#0 lore raw

Hi,
I am sending an updated version of the driver, this time addressing comments by Tejun Heo

Changes since V2:

* Removed the mutex kludge - ordered worqueue indeed works well
* Removed manul major/minor handling
* Gave more specific names to two sg helpers.

Changes from V1:

* Replaced explicit state numbers with enum items. I agree that code is cleaner this way.

* Swithced to using a workqueue.
Unfortunelly, I still see that workqueue items are executed in parallel I suspect that this happens if one work item sleeps. In this case I don't want other work items to run too. I fixed this with a mutex, and anyway it nice to have it to guaranteee this.

* moved sg_nents into scatterlist.c/h and put that in separate patch as requested

* Made functions static, fixed most whitespace issues (I hope all), and I hope addressed all other comments by Andrew Morton.

author maintainer
#8 lore raw

PATCH 2/2 memstick: add support for legacy memorysticks

Based partially on MS standard spec quotes from Alex Dubov.

As any code that works with user data this driver isn't recommended to use to write cards that contain valuable data.

It tries its best though to avoid data corruption
and possible damage to the card.

Tested on MS DUO 64 MB card on Ricoh R592 card reader.

---
 MAINTAINERS                      |    5 +
 drivers/memstick/core/Kconfig    |   12 +
 drivers/memstick/core/Makefile   |    2 +-
 drivers/memstick/core/ms_block.c | 2395 ++++++++++++++++++++++++++++++++++++++
 drivers/memstick/core/ms_block.h |  293 +++++
 5 files changed, 2706 insertions(+), 1 deletion(-)
 create mode 100644 drivers/memstick/core/ms_block.c
 create mode 100644 drivers/memstick/core/ms_block.h
MAINTAINERS +5 -0
index fdc0119..8fb6bf0 100644
@@ -6393,6 +6393,11 @@ W:	http://tifmxx.berlios.de/
 S:	Maintained
 F:	drivers/memstick/host/tifm_ms.c
 
+SONY MEMORYSTICK STANDARD SUPPORT
+M:	Maxim Levitsky <[email protected]>
+S:	Maintained
+F:	drivers/memstick/core/ms_block.*
+
 SOUND
 M:	Jaroslav Kysela <[email protected]>
 M:	Takashi Iwai <[email protected]>
drivers/memstick/core/Kconfig +12 -0
index 95f1814..f79f2a8 100644
@@ -24,3 +24,15 @@ config MSPRO_BLOCK
 	  support. This provides a block device driver, which you can use
 	  to mount the filesystem. Almost everyone wishing MemoryStick
 	  support should say Y or M here.
+
+config MS_BLOCK
+	tristate "MemoryStick Standard device driver"
+	depends on BLOCK && EXPERIMENTAL
+	help
+	  Say Y here to enable the MemoryStick Standard device driver
+	  support. This provides a block device driver, which you can use
+	  to mount the filesystem.
+	  This driver works with old (bulky) MemoryStick and MemoryStick Duo
+	  but not PRO. Say Y if you have such card.
+	  Driver is new and not yet well tested, thus it can damage your card
+	  (even permanently)
drivers/memstick/core/Makefile +1 -1
index ecd0299..0d7f90c 100644
@@ -3,5 +3,5 @@
 #
 
 obj-$(CONFIG_MEMSTICK)		+= memstick.o
-
+obj-$(CONFIG_MS_BLOCK)		+= ms_block.o
 obj-$(CONFIG_MSPRO_BLOCK)	+= mspro_block.o
drivers/memstick/core/ms_block.c new file +2395 -0

2,395 lines not on this page · raw message

drivers/memstick/core/ms_block.h new file +293 -0

293 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author maintainer
#1 lore raw

PATCH 1/2 scatterlist: add sg_nents

In reply to Maxim Levitsky

Useful helper to know the number of entries in scatterlist.

---
 include/linux/scatterlist.h |    1 +
 lib/scatterlist.c           |   22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)
include/linux/scatterlist.h +1 -0
index 7b600da..4bd6c06 100644
@@ -201,6 +201,7 @@ static inline void *sg_virt(struct scatterlist *sg)
 	return page_address(sg_page(sg)) + sg->offset;
 }
 
+int sg_nents(struct scatterlist *sg);
 struct scatterlist *sg_next(struct scatterlist *);
 struct scatterlist *sg_last(struct scatterlist *s, unsigned int);
 void sg_init_table(struct scatterlist *, unsigned int);
lib/scatterlist.c +22 -0
index e76d85c..5cd9cdc 100644
@@ -39,6 +39,28 @@ struct scatterlist *sg_next(struct scatterlist *sg)
 EXPORT_SYMBOL(sg_next);
 
 /**
+ * sg_nents - return total count of entries in scatterlist
+ * @sg:		The scatterlist
+ *
+ * Description:
+ * Allows to know how many entries are in sg, taking into acount
+ * chaining as well
+ *
+ **/
+int sg_nents(struct scatterlist *sg)
+{
+	int nents = 0;
+	while (sg) {
+		nents++;
+		sg = sg_next(sg);
+	}
+
+	return nents;
+}
+EXPORT_SYMBOL(sg_nents);
+
+
+/**
  * sg_last - return the last scatterlist entry in a list
  * @sgl:	First entry in the scatterlist
  * @nents:	Number of entries in the scatterlist
Signature · 1 line
1.7.9.5
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] scatterlist: add sg_nents

(cc'ing Jens)

Quoted 37 lines · Maxim Levitsky

Useful helper to know the number of entries in scatterlist.

---
 include/linux/scatterlist.h |    1 +
 lib/scatterlist.c           |   22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)
include/linux/scatterlist.h +1 -0
index 7b600da..4bd6c06 100644
@@ -201,6 +201,7 @@ static inline void *sg_virt(struct scatterlist *sg)
 	return page_address(sg_page(sg)) + sg->offset;
 }
 
+int sg_nents(struct scatterlist *sg);
 struct scatterlist *sg_next(struct scatterlist *);
 struct scatterlist *sg_last(struct scatterlist *s, unsigned int);
 void sg_init_table(struct scatterlist *, unsigned int);
lib/scatterlist.c +9 -0
index e76d85c..5cd9cdc 100644
@@ -39,6 +39,28 @@ struct scatterlist *sg_next(struct scatterlist *sg)
 EXPORT_SYMBOL(sg_next);
 
 /**
+ * sg_nents - return total count of entries in scatterlist
+ * @sg:		The scatterlist
+ *
+ * Description:
+ * Allows to know how many entries are in sg, taking into acount
+ * chaining as well
+ *
+ **/
+int sg_nents(struct scatterlist *sg)

lib/scatterlist.c struct scatterlist *sg_next(struct scatterlist *sg) · line 60

Quoted 10 lines
lib/scatterlist.c +10 -0
+{
+	int nents = 0;
+	while (sg) {
+		nents++;
+		sg = sg_next(sg);
+	}
+
+	return nents;
+}
+EXPORT_SYMBOL(sg_nents);

How about the following instead?

	for (nents = 0; sg; sg = sg_next(sg))
		nents++;
	return nents;

Other than that,

Thanks.

Signature · 1 line
tejun
#9 lore raw

Re: [PATCH 2/2] memstick: add support for legacy memorysticks

In reply to Maxim Levitsky
Quoted 11 lines · Maxim Levitsky

Based partially on MS standard spec quotes from Alex Dubov.

As any code that works with user data this driver isn't recommended to use to write cards that contain valuable data.

It tries its best though to avoid data corruption
and possible damage to the card.

Tested on MS DUO 64 MB card on Ricoh R592 card reader.

Workqueue related part looks good to me. Don't have much clue about other stuff.

Thanks.

Signature · 1 line
tejun
#3 lore raw

Re: [PATCH 1/2] scatterlist: add sg_nents

In reply to Tejun Heo
Quoted 53 lines · Tejun Heo

(cc'ing Jens)

Quoted 37 lines · Maxim Levitsky

Useful helper to know the number of entries in scatterlist.

---
 include/linux/scatterlist.h |    1 +
 lib/scatterlist.c           |   22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)
include/linux/scatterlist.h +1 -0
index 7b600da..4bd6c06 100644
@@ -201,6 +201,7 @@ static inline void *sg_virt(struct scatterlist *sg)
 	return page_address(sg_page(sg)) + sg->offset;
 }
 
+int sg_nents(struct scatterlist *sg);
 struct scatterlist *sg_next(struct scatterlist *);
 struct scatterlist *sg_last(struct scatterlist *s, unsigned int);
 void sg_init_table(struct scatterlist *, unsigned int);
lib/scatterlist.c +9 -0
index e76d85c..5cd9cdc 100644
@@ -39,6 +39,28 @@ struct scatterlist *sg_next(struct scatterlist *sg)
 EXPORT_SYMBOL(sg_next);
 
 /**
+ * sg_nents - return total count of entries in scatterlist
+ * @sg:		The scatterlist
+ *
+ * Description:
+ * Allows to know how many entries are in sg, taking into acount
+ * chaining as well
+ *
+ **/
+int sg_nents(struct scatterlist *sg)

lib/scatterlist.c struct scatterlist *sg_next(struct scatterlist *sg) · line 60

Quoted 10 lines
lib/scatterlist.c +10 -0
+{
+	int nents = 0;
+	while (sg) {
+		nents++;
+		sg = sg_next(sg);
+	}
+
+	return nents;
+}
+EXPORT_SYMBOL(sg_nents);

How about the following instead?

Quoted 7 lines
	for (nents = 0; sg; sg = sg_next(sg))
		nents++;
	return nents;

Other than that,

Agree, that'd be cleaner. I've just applied it as-is. Maxim, feel free to send an update to it. I pulled the driver bit into the for-3.7/drivers branch as well.

Signature · 1 line
Jens Axboe
author maintainer
#4 lore raw

PATCH 1/1 scatterlist: refactor the sg_nents

Replace 'while' with 'for' as suggested by Tejun Heo

---
 lib/scatterlist.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/scatterlist.c +2 -5
index 5cd9cdc..3675452b 100644
@@ -49,12 +49,9 @@ EXPORT_SYMBOL(sg_next);
  **/
 int sg_nents(struct scatterlist *sg)
 {
-	int nents = 0;
-	while (sg) {
+	int nents;
+	for (nents = 0; sg; sg = sg_next(sg))
 		nents++;
-		sg = sg_next(sg);
-	}
-
 	return nents;
 }
 EXPORT_SYMBOL(sg_nents);
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [PATCH] scatterlist: refactor the sg_nents

Quoted 1 line · Maxim Levitsky

Replace 'while' with 'for' as suggested by Tejun Heo

Thanks, purtier :-)

Signature · 1 line
Jens Axboe
#10 lore raw

Re: [PATCH 2/2] memstick: add support for legacy memorysticks

In reply to Maxim Levitsky
Quoted 9 lines · Maxim Levitsky
drivers/memstick/core/ms_block.c new file +6 -0
 
+#define pr_fmt(fmt) DRIVER_NAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/blkdev.h>
+#include <linux/memstick.h>
+#include <linux/idr.h>

drivers/memstick/core/ms_block.c line 30

Quoted 10 lines
drivers/memstick/core/ms_block.c new file +10 -0
+#include <linux/hdreg.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/random.h>
+#include <linux/bitmap.h>
+#include <linux/scatterlist.h>
+#include <linux/jiffies.h>
+#include <linux/workqueue.h>
+#include <linux/mutex.h>
+#include "ms_block.h"

http://kisskb.ellerman.id.au/kisskb/buildresult/7280352/
arch/m68k/include/asm/hardirq.h:23:20: error: expected ')' before 'DRIVER_NAME' make[4]: *** [drivers/memstick/core/ms_block.o] Error 1

The reason for this is that pr_fmt() references DRIVER_NAME and is defined before the first include, while DRIVER_NAME is only defined in ms_block.h, which is the last included file. If any subsequent include file uses pr_fmt() (e.g. the call to pr_crit() in arch/m68k/include/asm/hardirq.h), this causes a build
failure.

I suggest moving the DRIVER_NAME define to ms_block.c.
Cfr. memstick.c and mspro_block.c, who already have their own definition.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#11 lore raw

Re: [PATCH 2/2] memstick: add support for legacy memorysticks

Quoted 38 lines · Geert Uytterhoeven
Quoted 9 lines · Maxim Levitsky
drivers/memstick/core/ms_block.c new file +6 -0
 
+#define pr_fmt(fmt) DRIVER_NAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/blkdev.h>
+#include <linux/memstick.h>
+#include <linux/idr.h>

drivers/memstick/core/ms_block.c line 30

Quoted 10 lines
drivers/memstick/core/ms_block.c new file +10 -0
+#include <linux/hdreg.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/random.h>
+#include <linux/bitmap.h>
+#include <linux/scatterlist.h>
+#include <linux/jiffies.h>
+#include <linux/workqueue.h>
+#include <linux/mutex.h>
+#include "ms_block.h"

http://kisskb.ellerman.id.au/kisskb/buildresult/7280352/
arch/m68k/include/asm/hardirq.h:23:20: error: expected ')' before 'DRIVER_NAME' make[4]: *** [drivers/memstick/core/ms_block.o] Error 1

The reason for this is that pr_fmt() references DRIVER_NAME and is defined before the first include, while DRIVER_NAME is only defined in ms_block.h, which is the last included file. If any subsequent include file uses pr_fmt() (e.g. the call to pr_crit() in arch/m68k/include/asm/hardirq.h), this causes a build
failure.

I suggest moving the DRIVER_NAME define to ms_block.c.
Cfr. memstick.c and mspro_block.c, who already have their own definition.

Gr{oetje,eeting}s,

Quoted 8 lines

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Completely agree!
I was somewhat busy lately, so I didn't address this yet. I'll send a patch tomorrow.

Best regards,
Maxim Levitsky

author maintainer
#13 lore raw

PATCH 1/2 memstick: remove unused field from state struct.

In reply to Maxim Levitsky

Oops, I forgot that I have thet field there already. Just save memory by not allocating it.

---
 drivers/memstick/core/ms_block.h |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/memstick/core/ms_block.h +1 -2
index 6b5b83e..a2b2765 100644
@@ -162,7 +162,6 @@ struct msb_data {
 	struct workqueue_struct		*io_queue;
 	bool				io_queue_stopped;
 	struct work_struct		io_work;
-	struct scatterlist		prealloc_sg[MS_BLOCK_MAX_SEGS+1];
 	bool				card_dead;
 
 	/* Media properties */
@@ -194,7 +193,7 @@ struct msb_data {
 
 	/* Preallocated buffers */
 	unsigned char			*block_buffer;
-	struct scatterlist		sg[MS_BLOCK_MAX_SEGS+1];
+	struct scatterlist		prealloc_sg[MS_BLOCK_MAX_SEGS+1];
 
 
 	/* handler's local data */
Signature · 1 line
1.7.9.5
author maintainer
#14 lore raw

PATCH 2/2 memstick: ms_block: fix complile issue.

In reply to Maxim Levitsky

As suggested by Geert Uytterhoeven

http://kisskb.ellerman.id.au/kisskb/buildresult/7280352/
arch/m68k/include/asm/hardirq.h:23:20: error: expected ')' before 'DRIVER_NAME' make[4]: *** [drivers/memstick/core/ms_block.o] Error 1

The reason for this is that pr_fmt() references DRIVER_NAME and is defined before the first include, while DRIVER_NAME is only defined in ms_block.h, which is the last included file. If any subsequent include file uses pr_fmt() (e.g. the call to pr_crit() in arch/m68k/include/asm/hardirq.h), this causes a build
failure.

I suggest moving the DRIVER_NAME define to ms_block.c.
Cfr. memstick.c and mspro_block.c, who already have their own definition.

CC Geert Uytterhoeven <[email protected]>
---
 drivers/memstick/core/ms_block.c |    2 +-
 drivers/memstick/core/ms_block.h |    2 --
 2 files changed, 1 insertion(+), 3 deletions(-)
drivers/memstick/core/ms_block.c +1 -1
index c815fe5..71e5937 100644
@@ -11,7 +11,7 @@
  * Copyright (C) 2007 Alex Dubov <[email protected]>
  *
  */
-
+#define DRIVER_NAME "ms_block"
 #define pr_fmt(fmt) DRIVER_NAME ": " fmt
 
 #include <linux/module.h>
drivers/memstick/core/ms_block.h +0 -2
index a2b2765..546b55e 100644
@@ -277,8 +277,6 @@ static int msb_reset(struct msb_data *msb, bool full);
 static int h_msb_default_bad(struct memstick_dev *card,
 						struct memstick_request **mrq);
 
-#define DRIVER_NAME "ms_block"
-
 #define __dbg(level, format, ...) \
 	do { \
 		if (debug >= level) \
Signature · 1 line
1.7.9.5
author maintainer
#12 lore raw

Fixes for ms_block

In reply to Geert Uytterhoeven

Hi,

I finally found time to send the fix for the compile issue on m68k Among with small cosmetic fix to remove unused field that slipped thorough.

Do you know if my driver will be merged in 3.7 or later?
I hope that the compile issue which I should have handled earlier is not to blame.

#6 lore raw

Re: [PATCH 1/2] scatterlist: add sg_nents

In reply to Maxim Levitsky
Quoted 1 line · Maxim Levitsky

+int sg_nents(struct scatterlist *sg)

unsigned int?

lib/scatterlist.c struct scatterlist *sg_next(struct scatterlist *sg) · line 59

Quoted 9 lines
lib/scatterlist.c +9 -0
+{
+       int nents = 0;
+       while (sg) {
+               nents++;
+               sg = sg_next(sg);
+       }
+
+       return nents;
+}

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#7 lore raw

Re: [PATCH 1/2] scatterlist: add sg_nents

Quoted 5 lines · Geert Uytterhoeven
Quoted 1 line · Maxim Levitsky

+int sg_nents(struct scatterlist *sg)

unsigned int?

and "const struct scatterlist *sg"? Ah no, that won't work as sg_next() treats non-const pointers :-(

Quoted 9 lines

lib/scatterlist.c struct scatterlist *sg_next(struct scatterlist *sg) · line 59

Quoted 9 lines
lib/scatterlist.c +9 -0
+{
+       int nents = 0;
+       while (sg) {
+               nents++;
+               sg = sg_next(sg);
+       }
+
+       return nents;
+}

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds