Skip to contentSkip to conversation

MEMSTICK: Add my 2 drivers

PATCH In review Maxim Levitsky 4 participants 13 messages Dec 9, 2010 – Dec 10, 2010

Subsystems (2)
lore
Share & tools
lore

Maxim Levitsky

author maintainer
#0 lore raw

Hi,

This is standalone version of two drivers that I wrote for memstick subsystem.

Due to attitude of Alex, I decided to avoid contributing to memstick subsystem anymore unless I run into another unsupported chip, or something like that, or any bugs in my code will be found. Of course I will do my best to fix such bugs as fast as possible. And I really care to have as little as possible bugs in my code.

Anderew Morton, older version of these drivers were in your tree for 2 cycles now, could you please set them for 2.6.38 inclusion?

Since I don't touch (and don't want anymore to) any code written by Alex, and I even added workarounds for bugs in his jmicron driver to the generic ms_block.c code (it tested and works on my both card readers), maybe even add these to 2.6.37?

And as a last comment about flamewar with Alex, which I don't want to repeat, I think he ought to add himself as a maintainer of memstick code he wrote, because it seems absurd that he refuses my contributions and yet nether maintains it (code has few bugs that are result of bitrot, I even have a merged commit for biggest one) nor he even appears in MAINTAINERS for mspro_blk.c and memstick.c.

Sorry for my attitude, but its frustrating to see a month's work aimed to make the code readable to be lost.

Best regards,
Maxim Levitsky

author maintainer
#1 lore raw

PATCH 1/2 memstick: add support for legacy memorysticks

Based partialy on spec quotes from Alex Dubov.

As any code that works with user data this driver isn't recommened to use with valuable data.

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

Tested with MS DUO 64 MB card on Ricoh and Jmicron reader.

---
 MAINTAINERS                      |    5 +
 drivers/memstick/core/Kconfig    |   12 +
 drivers/memstick/core/Makefile   |    2 +-
 drivers/memstick/core/ms_block.c | 2385 ++++++++++++++++++++++++++++++++++++++
 drivers/memstick/core/ms_block.h |  245 ++++
 5 files changed, 2648 insertions(+), 1 deletions(-)
 create mode 100644 drivers/memstick/core/ms_block.c
 create mode 100644 drivers/memstick/core/ms_block.h
MAINTAINERS +5 -0
index b3be8b3..a441ce4 100644
@@ -5545,6 +5545,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 8b2b529..19d960b 100644
@@ -7,5 +7,5 @@ ifeq ($(CONFIG_MEMSTICK_DEBUG),y)
 endif
 
 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 +2385 -0

2,385 lines not on this page · raw message

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

245 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

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

At Thu, 9 Dec 2010 04:42:25 +0200,

Quoted 6 lines · Maxim Levitsky

Based partialy on spec quotes from Alex Dubov.

As any code that works with user data this driver isn't recommened to use with valuable data.

Quoted 6 lines

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

Tested with MS DUO 64 MB card on Ricoh and Jmicron reader.

Oh, this is interesting. Just now I looked for a solution for the old MS with new JMicron controllers. (I should have checked mm tree beforehand...)

I'll give it a try and report back later.

thanks,

Takashi

#3 lore raw

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

At Thu, 09 Dec 2010 08:19:47 +0100,

Quoted 14 lines · Takashi Iwai

At Thu, 9 Dec 2010 04:42:25 +0200,

Quoted 11 lines · Maxim Levitsky

Based partialy on spec quotes from Alex Dubov.

As any code that works with user data this driver isn't recommened to use with valuable data.

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

Tested with MS DUO 64 MB card on Ricoh and Jmicron reader.

Quoted 7 lines
Quoted 1 line

Oh, this is interesting. Just now I looked for a solution for the old MS with new JMicron controllers. (I should have checked mm tree beforehand...)

I'll give it a try and report back later.

I tried your patch now.
But got a WARNING and errors without working properly:

[   86.894497] WARNING: at drivers/memstick/core/ms_block.c:255 msb_run_state_machine+0x90/0xb0 [ms_block]()
[   86.894502] Hardware name:  
[   86.894504] Modules linked in: ms_block(+) nls_iso8859_1 nls_cp437 vfat fat mmc_block netconsole configfs nfs lockd nfs_acl auth_rpcgss sunrpc af_packet i915 drm_kms_helper drm i2c_algo_bit snd_pcm_oss cpufreq_conservative snd_mixer_oss cpufreq_userspace snd_seq cpufreq_powersave acpi_cpufreq mperf binfmt_misc snd_seq_device edd ipv6 fuse loop dm_mod acpiphp pci_hotplug snd_hda_codec_hdmi snd_hda_codec_idt processor rtc_cmos snd_hda_intel snd_hda_codec snd_hwdep snd_pcm snd_timer uvcvideo video thermal thermal_sys snd rtc_core sr_mod soundcore snd_page_alloc sdhci_pci hwmon videodev cdrom r8169 rtc_lib v4l1_compat tpm_tis tpm intel_agp tpm_bios pcspkr hp_accel intel_gtt iTCO_wdt jmb38x_ms memstick sdhci mmc_core mii iTCO_vendor_support sg joydev lis3lv02d serio_raw i2c_core input_polldev output wmi container button battery ac ata_piix sd_mod crc_t10dif ehci_hcd ahci libahci libata usbcore scsi_mod ext3 jbd mbcache
[   86.895023] Pid: 4606, comm: modprobe Not tainted 2.6.37-rc5-test #2
[   86.895037] Call Trace:
[   86.895048]  [<f84fa460>] ? msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895062]  [<f84fa460>] ? msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895080]  [<c0241d6c>] warn_slowpath_common+0x6c/0xa0
[   86.895092]  [<f84fa460>] ? msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895105]  [<f84fc280>] ? h_msb_reset+0x0/0x90 [ms_block]
[   86.895118]  [<c0241dbd>] warn_slowpath_null+0x1d/0x20
[   86.895132]  [<f84fa460>] msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895151]  [<f84fa52c>] msb_reset+0xac/0x130 [ms_block]
[   86.895169]  [<f84fc9db>] msb_probe+0x6b/0xcc8 [ms_block]
[   86.895175]  [<c0337345>] ? sysfs_addrm_finish+0x15/0xc0
[   86.895187]  [<c0337d75>] ? sysfs_do_create_link+0xb5/0x1b0
[   86.895191]  [<c0337345>] ? sysfs_addrm_finish+0x15/0xc0
[   86.895212]  [<f92ba344>] memstick_device_probe+0x34/0x50 [memstick]
[   86.895228]  [<c042cbf5>] driver_probe_device+0x95/0x280
[   86.895233]  [<c038be9a>] ? kobject_add_internal+0xca/0x210
[   86.895249]  [<c0395543>] ? kvasprintf+0x43/0x60
[   86.895252]  [<c042ce59>] __driver_attach+0x79/0x80
[   86.895256]  [<c042c3d3>] bus_for_each_dev+0x53/0x80
[   86.895274]  [<f92ba2b0>] ? memstick_device_remove+0x0/0x50 [memstick]
[   86.895278]  [<c042c9f9>] driver_attach+0x19/0x20
[   86.895290]  [<c042cde0>] ? __driver_attach+0x0/0x80
[   86.895292]  [<c042bcc7>] bus_add_driver+0x197/0x280
[   86.895297]  [<f92ba2b0>] ? memstick_device_remove+0x0/0x50 [memstick]
[   86.895308]  [<c042d0f5>] driver_register+0x75/0x160
[   86.895313]  [<c0381f18>] ? register_blkdev+0xf8/0x130
[   86.895326]  [<f8234000>] ? msb_init+0x0/0x6d [ms_block]
[   86.895332]  [<f92ba422>] memstick_register_driver+0x12/0x20 [memstick]
[   86.895337]  [<f8234035>] msb_init+0x35/0x6d [ms_block]
[   86.895351]  [<c020112b>] do_one_initcall+0x2b/0x160
[   86.895365]  [<c0273943>] sys_init_module+0x93/0x1d0
[   86.895377]  [<c0202d98>] sysenter_do_call+0x12/0x28
[   86.895381] ---[ end trace 0f1b7248462dd657 ]---
[   86.895593] ms_block: Switch to parallel failed
[   86.908121] ms_block: Switch to parallel failed

And "switch to parallel failed" continues endlessly until you unplug. Also, at another time, the machine got frozen with plugging.

After unplugging:

[   91.398455] ms_block: read of pba 0, page 0 failed with error -62
[   91.414437] ms_block: read of pba 1, page 0 failed with error -62
[   91.430412] ms_block: read of pba 2, page 0 failed with error -62
[   91.446389] ms_block: read of pba 3, page 0 failed with error -62
[   91.462370] ms_block: read of pba 4, page 0 failed with error -62
[   91.478242] ms_block: read of pba 5, page 0 failed with error -62
[   91.494224] ms_block: read of pba 6, page 0 failed with error -62
[   91.510205] ms_block: read of pba 7, page 0 failed with error -62
[   91.526187] ms_block: read of pba 8, page 0 failed with error -62
[   91.542163] ms_block: read of pba 9, page 0 failed with error -62
[   91.558145] ms_block: read of pba 10, page 0 failed with error -62
[   91.574127] ms_block: read of pba 11, page 0 failed with error -62
[   91.574153] ms_block: media doesn't contain master page, aborting
[   91.574176] ms_block: probe of memstick0 failed with error -5

thanks,

Takashi

#4 lore raw

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

At Thu, 09 Dec 2010 12:56:44 +0100,

Quoted 57 lines · Takashi Iwai

At Thu, 09 Dec 2010 08:19:47 +0100,

Quoted 14 lines · Takashi Iwai

At Thu, 9 Dec 2010 04:42:25 +0200,

Quoted 11 lines · Maxim Levitsky

Based partialy on spec quotes from Alex Dubov.

As any code that works with user data this driver isn't recommened to use with valuable data.

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

Tested with MS DUO 64 MB card on Ricoh and Jmicron reader.

Quoted 7 lines
Quoted 1 line

Oh, this is interesting. Just now I looked for a solution for the old MS with new JMicron controllers. (I should have checked mm tree beforehand...)

I'll give it a try and report back later.

I tried your patch now.
But got a WARNING and errors without working properly:

[   86.894497] WARNING: at drivers/memstick/core/ms_block.c:255 msb_run_state_machine+0x90/0xb0 [ms_block]()
[   86.894502] Hardware name:  
[   86.894504] Modules linked in: ms_block(+) nls_iso8859_1 nls_cp437 vfat fat mmc_block netconsole configfs nfs lockd nfs_acl auth_rpcgss sunrpc af_packet i915 drm_kms_helper drm i2c_algo_bit snd_pcm_oss cpufreq_conservative snd_mixer_oss cpufreq_userspace snd_seq cpufreq_powersave acpi_cpufreq mperf binfmt_misc snd_seq_device edd ipv6 fuse loop dm_mod acpiphp pci_hotplug snd_hda_codec_hdmi snd_hda_codec_idt processor rtc_cmos snd_hda_intel snd_hda_codec snd_hwdep snd_pcm snd_timer uvcvideo video thermal thermal_sys snd rtc_core sr_mod soundcore snd_page_alloc sdhci_pci hwmon videodev cdrom r8169 rtc_lib v4l1_compat tpm_tis tpm intel_agp tpm_bios pcspkr hp_accel intel_gtt iTCO_wdt jmb38x_ms memstick sdhci mmc_core mii iTCO_vendor_support sg joydev lis3lv02d serio_raw i2c_core input_polldev output wmi container button battery ac ata_piix sd_mod crc_t10dif ehci_hcd ahci libahci libata usbcore scsi_mod ext3 jbd mbcache
[   86.895023] Pid: 4606, comm: modprobe Not tainted 2.6.37-rc5-test #2
[   86.895037] Call Trace:
[   86.895048]  [<f84fa460>] ? msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895062]  [<f84fa460>] ? msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895080]  [<c0241d6c>] warn_slowpath_common+0x6c/0xa0
[   86.895092]  [<f84fa460>] ? msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895105]  [<f84fc280>] ? h_msb_reset+0x0/0x90 [ms_block]
[   86.895118]  [<c0241dbd>] warn_slowpath_null+0x1d/0x20
[   86.895132]  [<f84fa460>] msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895151]  [<f84fa52c>] msb_reset+0xac/0x130 [ms_block]
[   86.895169]  [<f84fc9db>] msb_probe+0x6b/0xcc8 [ms_block]
[   86.895175]  [<c0337345>] ? sysfs_addrm_finish+0x15/0xc0
[   86.895187]  [<c0337d75>] ? sysfs_do_create_link+0xb5/0x1b0
[   86.895191]  [<c0337345>] ? sysfs_addrm_finish+0x15/0xc0
[   86.895212]  [<f92ba344>] memstick_device_probe+0x34/0x50 [memstick]
[   86.895228]  [<c042cbf5>] driver_probe_device+0x95/0x280
[   86.895233]  [<c038be9a>] ? kobject_add_internal+0xca/0x210
[   86.895249]  [<c0395543>] ? kvasprintf+0x43/0x60
[   86.895252]  [<c042ce59>] __driver_attach+0x79/0x80
[   86.895256]  [<c042c3d3>] bus_for_each_dev+0x53/0x80
[   86.895274]  [<f92ba2b0>] ? memstick_device_remove+0x0/0x50 [memstick]
[   86.895278]  [<c042c9f9>] driver_attach+0x19/0x20
[   86.895290]  [<c042cde0>] ? __driver_attach+0x0/0x80
[   86.895292]  [<c042bcc7>] bus_add_driver+0x197/0x280
[   86.895297]  [<f92ba2b0>] ? memstick_device_remove+0x0/0x50 [memstick]
[   86.895308]  [<c042d0f5>] driver_register+0x75/0x160
Quoted 8 lines
[   86.895313]  [<c0381f18>] ? register_blkdev+0xf8/0x130
[   86.895326]  [<f8234000>] ? msb_init+0x0/0x6d [ms_block]
[   86.895332]  [<f92ba422>] memstick_register_driver+0x12/0x20 [memstick]
[   86.895337]  [<f8234035>] msb_init+0x35/0x6d [ms_block]
[   86.895351]  [<c020112b>] do_one_initcall+0x2b/0x160
[   86.895365]  [<c0273943>] sys_init_module+0x93/0x1d0
[   86.895377]  [<c0202d98>] sysenter_do_call+0x12/0x28
[   86.895381] ---[ end trace 0f1b7248462dd657 ]---

This turned to be an uninitialized state field. Trivial to fix.

Quoted 5 lines
[   86.895593] ms_block: Switch to parallel failed
[   86.908121] ms_block: Switch to parallel failed

And "switch to parallel failed" continues endlessly until you unplug. Also, at another time, the machine got frozen with plugging.

This was because I'm using the new JMicron chip which doesn't like the parallel mode. Reverting your commented-out code for checking CAP_PAR4 bit makes it working. I attach the patch below.

Maybe it's safer to "parallel-mode-as-default" only for the old JMicron chip using some quirk bits, etc.

thanks,

Takashi

---
 drivers/memstick/core/ms_block.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/memstick/core/ms_block.c +6 -5
@@ -726,7 +726,7 @@
 static int msb_reset(struct msb_data *msb, bool full)
 {
 
-	/*bool was_parallel = msb->regs.param.system & MEMSTICK_SYS_PAM; */
+	bool was_parallel = msb->regs.param.system & MEMSTICK_SYS_PAM;
 	struct memstick_dev *card = msb->card;
 	struct memstick_host *host = card->host;
 	int error;
@@ -762,8 +762,8 @@
 	}
 
 	/* Set parallel mode */
-	/* if (was_parallel) */
-	msb_switch_to_parallel(msb);
+	if (was_parallel)
+		msb_switch_to_parallel(msb);
 	return 0;
 }
 
@@ -1673,7 +1673,7 @@
 static int msb_init_card(struct memstick_dev *card)
 {
 	struct msb_data *msb = memstick_get_drvdata(card);
-	/*struct memstick_host *host = card->host;*/
+	struct memstick_host *host = card->host;
 	struct ms_boot_page *boot_block;
 	int error = 0, i, raw_size_in_megs;
 
@@ -1740,7 +1740,7 @@
 
 	/* Due to a bug in Jmicron driver, its serial mode barely works
 		so we switch to parallel mode right away */
-#if 0
+#if 1
 	/* Now we can switch the interface */
 	if (host->caps & msb->caps & MEMSTICK_CAP_PAR4)
 		msb_switch_to_parallel(msb);
@@ -2184,6 +2184,7 @@
 	msb = kzalloc(sizeof(struct msb_data), GFP_KERNEL);
 	if (!msb)
 		return -ENOMEM;
+	msb->state = -1;
 	memstick_set_drvdata(card, msb);
 	msb->card = card;
 	spin_lock_init(&msb->q_lock);
author maintainer
#5 lore raw

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

Quoted 73 lines · Takashi Iwai

At Thu, 09 Dec 2010 12:56:44 +0100,

Quoted 57 lines · Takashi Iwai

At Thu, 09 Dec 2010 08:19:47 +0100,

Quoted 14 lines · Takashi Iwai

At Thu, 9 Dec 2010 04:42:25 +0200,

Quoted 11 lines · Maxim Levitsky

Based partialy on spec quotes from Alex Dubov.

As any code that works with user data this driver isn't recommened to use with valuable data.

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

Tested with MS DUO 64 MB card on Ricoh and Jmicron reader.

Quoted 7 lines
Quoted 1 line

Oh, this is interesting. Just now I looked for a solution for the old MS with new JMicron controllers. (I should have checked mm tree beforehand...)

I'll give it a try and report back later.

I tried your patch now.
But got a WARNING and errors without working properly:

[   86.894497] WARNING: at drivers/memstick/core/ms_block.c:255 msb_run_state_machine+0x90/0xb0 [ms_block]()
[   86.894502] Hardware name:  
[   86.894504] Modules linked in: ms_block(+) nls_iso8859_1 nls_cp437 vfat fat mmc_block netconsole configfs nfs lockd nfs_acl auth_rpcgss sunrpc af_packet i915 drm_kms_helper drm i2c_algo_bit snd_pcm_oss cpufreq_conservative snd_mixer_oss cpufreq_userspace snd_seq cpufreq_powersave acpi_cpufreq mperf binfmt_misc snd_seq_device edd ipv6 fuse loop dm_mod acpiphp pci_hotplug snd_hda_codec_hdmi snd_hda_codec_idt processor rtc_cmos snd_hda_intel snd_hda_codec snd_hwdep snd_pcm snd_timer uvcvideo video thermal thermal_sys snd rtc_core sr_mod soundcore snd_page_alloc sdhci_pci hwmon videodev cdrom r8169 rtc_lib v4l1_compat tpm_tis tpm intel_agp tpm_bios pcspkr hp_accel intel_gtt iTCO_wdt jmb38x_ms memstick sdhci mmc_core mii iTCO_vendor_support sg joydev lis3lv02d serio_raw i2c_core input_polldev output wmi container button battery ac ata_piix sd_mod crc_t10dif ehci_hcd ahci libahci libata usbcore scsi_mod ext3 jbd mbcache
[   86.895023] Pid: 4606, comm: modprobe Not tainted 2.6.37-rc5-test #2
[   86.895037] Call Trace:
[   86.895048]  [<f84fa460>] ? msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895062]  [<f84fa460>] ? msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895080]  [<c0241d6c>] warn_slowpath_common+0x6c/0xa0
[   86.895092]  [<f84fa460>] ? msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895105]  [<f84fc280>] ? h_msb_reset+0x0/0x90 [ms_block]
[   86.895118]  [<c0241dbd>] warn_slowpath_null+0x1d/0x20
[   86.895132]  [<f84fa460>] msb_run_state_machine+0x90/0xb0 [ms_block]
[   86.895151]  [<f84fa52c>] msb_reset+0xac/0x130 [ms_block]
[   86.895169]  [<f84fc9db>] msb_probe+0x6b/0xcc8 [ms_block]
[   86.895175]  [<c0337345>] ? sysfs_addrm_finish+0x15/0xc0
[   86.895187]  [<c0337d75>] ? sysfs_do_create_link+0xb5/0x1b0
[   86.895191]  [<c0337345>] ? sysfs_addrm_finish+0x15/0xc0
[   86.895212]  [<f92ba344>] memstick_device_probe+0x34/0x50 [memstick]
[   86.895228]  [<c042cbf5>] driver_probe_device+0x95/0x280
[   86.895233]  [<c038be9a>] ? kobject_add_internal+0xca/0x210
[   86.895249]  [<c0395543>] ? kvasprintf+0x43/0x60
[   86.895252]  [<c042ce59>] __driver_attach+0x79/0x80
[   86.895256]  [<c042c3d3>] bus_for_each_dev+0x53/0x80
[   86.895274]  [<f92ba2b0>] ? memstick_device_remove+0x0/0x50 [memstick]
[   86.895278]  [<c042c9f9>] driver_attach+0x19/0x20
[   86.895290]  [<c042cde0>] ? __driver_attach+0x0/0x80
[   86.895292]  [<c042bcc7>] bus_add_driver+0x197/0x280
[   86.895297]  [<f92ba2b0>] ? memstick_device_remove+0x0/0x50 [memstick]
[   86.895308]  [<c042d0f5>] driver_register+0x75/0x160
Quoted 8 lines
[   86.895313]  [<c0381f18>] ? register_blkdev+0xf8/0x130
[   86.895326]  [<f8234000>] ? msb_init+0x0/0x6d [ms_block]
[   86.895332]  [<f92ba422>] memstick_register_driver+0x12/0x20 [memstick]
[   86.895337]  [<f8234035>] msb_init+0x35/0x6d [ms_block]
[   86.895351]  [<c020112b>] do_one_initcall+0x2b/0x160
[   86.895365]  [<c0273943>] sys_init_module+0x93/0x1d0
[   86.895377]  [<c0202d98>] sysenter_do_call+0x12/0x28
[   86.895381] ---[ end trace 0f1b7248462dd657 ]---

This turned to be an uninitialized state field. Trivial to fix.

Quoted 3 lines
[   86.895593] ms_block: Switch to parallel failed
[   86.908121] ms_block: Switch to parallel failed
Quoted 6 lines
Quoted 2 lines

And "switch to parallel failed" continues endlessly until you unplug. Also, at another time, the machine got frozen with plugging.

This was because I'm using the new JMicron chip which doesn't like the parallel mode. Reverting your commented-out code for checking CAP_PAR4 bit makes it working. I attach the patch below.

It is commented out because on my Jmicron, it doesn't work in serial mode.
I fixed this in my patch series, but like I said, due to alex attitude, I don't want to fix that code.
Probably by commenting out the code, I introduced run away recursion in the code if switch fails.

Takashi, you are welcome to look at my version of code, the one that Alex mostly refuses to merge.
It is located at http://gitorious.org/ricoh-kernel/ricoh-kernel
(This contains everything I did for ricoh and jmicron) Try this code and see if MS standard works for you in parallel mode.

If it doesn't, every module contains built-in debugging, activated by debug=1 or 2 module parameter, yet another thing Alex refused to consider.

Best regards,
Maxim Levitsky

Quoted 61 lines

Maybe it's safer to "parallel-mode-as-default" only for the old JMicron chip using some quirk bits, etc.

thanks,

Takashi

---
 drivers/memstick/core/ms_block.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/memstick/core/ms_block.c +6 -5
@@ -726,7 +726,7 @@
 static int msb_reset(struct msb_data *msb, bool full)
 {
 
-	/*bool was_parallel = msb->regs.param.system & MEMSTICK_SYS_PAM; */
+	bool was_parallel = msb->regs.param.system & MEMSTICK_SYS_PAM;
 	struct memstick_dev *card = msb->card;
 	struct memstick_host *host = card->host;
 	int error;
@@ -762,8 +762,8 @@
 	}
 
 	/* Set parallel mode */
-	/* if (was_parallel) */
-	msb_switch_to_parallel(msb);
+	if (was_parallel)
+		msb_switch_to_parallel(msb);
 	return 0;
 }
 
@@ -1673,7 +1673,7 @@
 static int msb_init_card(struct memstick_dev *card)
 {
 	struct msb_data *msb = memstick_get_drvdata(card);
-	/*struct memstick_host *host = card->host;*/
+	struct memstick_host *host = card->host;
 	struct ms_boot_page *boot_block;
 	int error = 0, i, raw_size_in_megs;
 
@@ -1740,7 +1740,7 @@
 
 	/* Due to a bug in Jmicron driver, its serial mode barely works
 		so we switch to parallel mode right away */
-#if 0
+#if 1
 	/* Now we can switch the interface */
 	if (host->caps & msb->caps & MEMSTICK_CAP_PAR4)
 		msb_switch_to_parallel(msb);
@@ -2184,6 +2184,7 @@
 	msb = kzalloc(sizeof(struct msb_data), GFP_KERNEL);
 	if (!msb)
 		return -ENOMEM;
+	msb->state = -1;
 	memstick_set_drvdata(card, msb);
 	msb->card = card;
 	spin_lock_init(&msb->q_lock);
#6 lore raw

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

In reply to Maxim Levitsky
Quoted 34 lines · On Thu, 9 Dec 2010 04:42:25 +0200 Maxim Levitsky <[email protected]>…
drivers/memstick/core/ms_block.c new file +34 -0
+/*
+ * Advance scatterlist by 'consumed' bytes
+ * Returns new scatterlist, or NULL if can't advance that much
+ */
+static struct scatterlist *sg_advance(struct scatterlist *sg, int consumed)
+{
+	while (consumed >= sg->length) {
+		consumed -= sg->length;
+
+		sg = sg_next(sg);
+		if (!sg)
+			break;
+	}
+
+	WARN_ON(!sg && consumed);
+
+	if (!sg)
+		return NULL;
+
+	sg->offset += consumed;
+	sg->length -= consumed;
+
+	if (sg->offset >= PAGE_SIZE) {
+		struct page *page =
+			nth_page(sg_page(sg), sg->offset / PAGE_SIZE);
+		sg_set_page(sg, page, sg->length, sg->offset % PAGE_SIZE);
+	}
+
+	return sg;
+}
+
+/* Calculate number of sg entries in sg list */
+static int sg_nents(struct scatterlist *sg)
+{

drivers/memstick/core/ms_block.c line 79

Quoted 10 lines
drivers/memstick/core/ms_block.c new file +10 -0
+	int nents = 0;
+	while (sg) {
+		nents++;
+		sg = sg_next(sg);
+	}
+
+	return nents;
+}
+
+/* Calculate total lenght of scatterlist */

(typo)

Quoted 30 lines
drivers/memstick/core/ms_block.c new file +30 -0
+static int sg_total_len(struct scatterlist *sg)
+{
+	int len = 0;
+	while (sg) {
+		len += sg->length;
+		sg = sg_next(sg);
+	}
+	return len;
+}
+
+/* Compare contents of an sg to a buffer */
+static bool sg_compare_to_buffer(struct scatterlist *sg, u8 *buffer, size_t len)
+{
+	unsigned long flags;
+	int retval = 0;
+	struct sg_mapping_iter miter;
+
+	if (sg_total_len(sg) < len)
+		return 1;
+
+	local_irq_save(flags);
+	sg_miter_start(&miter, sg, sg_nents(sg),
+				SG_MITER_ATOMIC | SG_MITER_FROM_SG);
+
+	while (sg_miter_next(&miter) && len > 0) {
+
+		int cmplen = min(miter.length, len);
+		if (memcmp(miter.addr, buffer, cmplen)) {
+			retval = 1;
+			break;

drivers/memstick/core/ms_block.c line 119

Quoted 10 lines
drivers/memstick/core/ms_block.c new file +10 -0
+		}
+
+		buffer += cmplen;
+		len -= cmplen;
+	}
+
+	sg_miter_stop(&miter);
+	local_irq_restore(flags);
+	return retval;
+}

I think I mentioned this before, but ... it's really bad that the above functions appear in a particular device driver. They are, to varying degrees, independent of that driver and should be provided by the sglist core code.

Also, the local_irq_save/restore in sg_compare_to_buffer() is quite mysterious and should have a comment explaining why it is there. Once that's done, I might understand why it isn't a bug on SMP machines ;)

author maintainer
#7 lore raw

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

Quoted 87 lines · Andrew Morton
Quoted 34 lines · On Thu, 9 Dec 2010 04:42:25 +0200 Maxim Levitsky <[email protected]>…
drivers/memstick/core/ms_block.c new file +34 -0
+/*
+ * Advance scatterlist by 'consumed' bytes
+ * Returns new scatterlist, or NULL if can't advance that much
+ */
+static struct scatterlist *sg_advance(struct scatterlist *sg, int consumed)
+{
+	while (consumed >= sg->length) {
+		consumed -= sg->length;
+
+		sg = sg_next(sg);
+		if (!sg)
+			break;
+	}
+
+	WARN_ON(!sg && consumed);
+
+	if (!sg)
+		return NULL;
+
+	sg->offset += consumed;
+	sg->length -= consumed;
+
+	if (sg->offset >= PAGE_SIZE) {
+		struct page *page =
+			nth_page(sg_page(sg), sg->offset / PAGE_SIZE);
+		sg_set_page(sg, page, sg->length, sg->offset % PAGE_SIZE);
+	}
+
+	return sg;
+}
+
+/* Calculate number of sg entries in sg list */
+static int sg_nents(struct scatterlist *sg)
+{

drivers/memstick/core/ms_block.c line 79

Quoted 10 lines
drivers/memstick/core/ms_block.c new file +10 -0
+	int nents = 0;
+	while (sg) {
+		nents++;
+		sg = sg_next(sg);
+	}
+
+	return nents;
+}
+
+/* Calculate total lenght of scatterlist */

(typo)

Quoted 37 lines
drivers/memstick/core/ms_block.c new file +37 -0
+static int sg_total_len(struct scatterlist *sg)
+{
+	int len = 0;
+	while (sg) {
+		len += sg->length;
+		sg = sg_next(sg);
+	}
+	return len;
+}
+
+/* Compare contents of an sg to a buffer */
+static bool sg_compare_to_buffer(struct scatterlist *sg, u8 *buffer, size_t len)
+{
+	unsigned long flags;
+	int retval = 0;
+	struct sg_mapping_iter miter;
+
+	if (sg_total_len(sg) < len)
+		return 1;
+
+	local_irq_save(flags);
+	sg_miter_start(&miter, sg, sg_nents(sg),
+				SG_MITER_ATOMIC | SG_MITER_FROM_SG);
+
+	while (sg_miter_next(&miter) && len > 0) {
+
+		int cmplen = min(miter.length, len);
+		if (memcmp(miter.addr, buffer, cmplen)) {
+			retval = 1;
+			break;
+		}
+
+		buffer += cmplen;
+		len -= cmplen;
+	}
+
+	sg_miter_stop(&miter);
Quoted 8 lines

drivers/memstick/core/ms_block.c line 119

Quoted 3 lines
drivers/memstick/core/ms_block.c new file +3 -0
+	local_irq_restore(flags);
+	return retval;
+}

I think I mentioned this before, but ... it's really bad that the above functions appear in a particular device driver. They are, to varying degrees, independent of that driver and should be provided by the sglist core code.

I agree with you.
However, note that Alex's mspro_blk.c, also contains the above logic, it is just not separated from the code.
I don't mind adding these to scatterlist code.

Quoted 4 lines

Also, the local_irq_save/restore in sg_compare_to_buffer() is quite mysterious and should have a comment explaining why it is there. Once that's done, I might understand why it isn't a bug on SMP machines ;)

Its is done to be able to use kmap_atomic.
I think I can use sg_mitter there, I will try to.

Best regards,
Maxim Levitsky.

author maintainer
#8 lore raw

PATCH 2/2 memstick: Add driver for Ricoh R5C592 card reader.

In reply to Maxim Levitsky
---
 MAINTAINERS                    |    5 +
 drivers/memstick/host/Kconfig  |   12 +
 drivers/memstick/host/Makefile |    1 +
 drivers/memstick/host/r592.c   |  908 ++++++++++++++++++++++++++++++++++++++++
 drivers/memstick/host/r592.h   |  175 ++++++++
 5 files changed, 1101 insertions(+), 0 deletions(-)
 create mode 100644 drivers/memstick/host/r592.c
 create mode 100644 drivers/memstick/host/r592.h
MAINTAINERS +5 -0
index a441ce4..9960e0c 100644
@@ -5011,6 +5011,11 @@ S:	Maintained
 F:	drivers/mtd/nand/r852.c
 F:	drivers/mtd/nand/r852.h
 
+RICOH R5C592 MEMORYSTICK DRIVER
+M:	Maxim Levitsky <[email protected]>
+S:	Maintained
+F:	drivers/memstick/host/r592.*
+
 RISCOM8 DRIVER
 S:	Orphan
 F:	Documentation/serial/riscom8.txt
drivers/memstick/host/Kconfig +12 -0
index 4ce5c8d..cc0997a 100644
@@ -30,3 +30,15 @@ config MEMSTICK_JMICRON_38X
 
           To compile this driver as a module, choose M here: the
 	  module will be called jmb38x_ms.
+
+config MEMSTICK_R592
+	tristate "Ricoh R5C592 MemoryStick interface support (EXPERIMENTAL)"
+	depends on EXPERIMENTAL && PCI
+
+	help
+	  Say Y here if you want to be able to access MemoryStick cards with
+	  the Ricoh R5C592 MemoryStick card reader (which is part of 5 in one
+		multifunction reader)
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called r592.
drivers/memstick/host/Makefile +1 -0
index 12530e4..ad63c16 100644
@@ -8,3 +8,4 @@ endif
 
 obj-$(CONFIG_MEMSTICK_TIFM_MS)		+= tifm_ms.o
 obj-$(CONFIG_MEMSTICK_JMICRON_38X)	+= jmb38x_ms.o
+obj-$(CONFIG_MEMSTICK_R592)		+= r592.o
drivers/memstick/host/r592.c new file +908 -0

908 lines not on this page · raw message

drivers/memstick/host/r592.h new file +175 -0

175 lines not on this page · raw message

Signature · 1 line
1.7.1
maintainer
#9 lore raw
In reply to Maxim Levitsky
Quoted 8 lines

Since I don't touch (and don't want anymore to) any code written by
Alex, and I even added workarounds for bugs in his jmicron driver to the
generic ms_block.c code (it tested and works on my both card readers),
maybe even add these to 2.6.37?

This are worked around by the recent patches, are not they?

author maintainer
#10 lore raw
Quoted 10 lines · Alex Dubov
Quoted 8 lines

Since I don't touch (and don't want anymore to) any code written by
Alex, and I even added workarounds for bugs in his jmicron driver to the
generic ms_block.c code (it tested and works on my both card readers),
maybe even add these to 2.6.37?

This are worked around by the recent patches, are not they?

I don't care, really.
This is your code, I don't want another frustration and flamewar. I will eventually test your patches (I did see them before I send that mail), if they don't work, I just ask for a revert.

Best regards,
Maxim Levitsky

#11 lore raw
In reply to Alex Dubov

At Wed, 8 Dec 2010 18:44:04 -0800 (PST),

Quoted 11 lines · Alex Dubov
Quoted 9 lines

Since I don't touch (and don't want anymore to) any code written by
Alex, and I even added workarounds for bugs in his jmicron driver to the
generic ms_block.c code (it tested and works on my both card readers),
maybe even add these to 2.6.37?

This are worked around by the recent patches, are not they?

Do you mean that the support for old memstick media was added / worked around in the recent patches? That would be great. It's what I was looking for right now. If so, could you point your patches?

thanks,

Takashi

author maintainer
#12 lore raw
Quoted 12 lines · Takashi Iwai

At Wed, 8 Dec 2010 18:44:04 -0800 (PST),

Quoted 10 lines · Alex Dubov
Quoted 9 lines

Since I don't touch (and don't want anymore to) any code written by
Alex, and I even added workarounds for bugs in his jmicron driver to the
generic ms_block.c code (it tested and works on my both card readers),
maybe even add these to 2.6.37?

Quoted 5 lines
Quoted 1 line

This are worked around by the recent patches, are not they?

Do you mean that the support for old memstick media was added / worked around in the recent patches? That would be great. It's what I was looking for right now. If so, could you point your patches?

No, Alex is talking about your patches.

Best regards,
Maxim Levitsky