Skip to contentSkip to conversation

snd-usb-us122l v0.2 for US-122L

PATCH In review Karsten Wiese 2 participants 20 messages Mar 16, 2008 – May 20, 2008

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

PATCH 1/1 snd-usb-us122l v0.2 for US-122L

Hi,

attached is a fresh US-122L linux(test-)driver.

If everything is installed on top a kernel 2.6.25-rc5 and alsa-lib 1.0.16, everything works, erm at least here.

Without the ehci patch, it still works when connected to the uhci-hcd. (Maybe the ehci-patch makes it into .26)

alsa-lib < 1.0.16 lets the plugin misbehave.

PCM access needs an ~/.asoundrc containing whats in .asoundrc. Its established by patching/compiling/installing alsa-plugins. You need to adjust the path to the kernel's sound/usb/usx2y/usb_stream.h Only S24_3LE, 2 channels interleaved, 2 periods is supported.

The userspace pcm devicename then is forexample "usb_stream:1" (To let alsa convert to other formats, use forexample "plug:usb_stream:1")

Tested with aplay, arecord, amidi & jackd using alsa driver.

Propably doesn't do 32bit PCM access on x86_64, tested on x86_64 only.

Karsten

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#1 lore raw

At Sun, 16 Mar 2008 19:56:41 +0100,

Quoted 4 lines · Karsten Wiese

Hi,

attached is a fresh US-122L linux(test-)driver.

Karsten, is this supposed to be merged to ALSA (and upstream) tree?

If it's highly experimental and you are still unsure to push to the linux kernel tree, we can keep it in alsa-driver tree. If it's in a form that can be in the kernel tree but still you feel unsafe, you can add the dependnecy to CONFIG_EXPERIMENTAL, too.

Takashi

#2 lore raw

Am Montag, 17. März 2008 schrieb Takashi Iwai:

Quoted 8 lines

At Sun, 16 Mar 2008 19:56:41 +0100,

Quoted 4 lines · Karsten Wiese

Hi,

attached is a fresh US-122L linux(test-)driver.

Karsten, is this supposed to be merged to ALSA (and upstream) tree?

Yes.

Quoted 5 lines

If it's highly experimental and you are still unsure to push to the linux kernel tree, we can keep it in alsa-driver tree. If it's in a form that can be in the kernel tree but still you feel unsafe, you can add the dependnecy to CONFIG_EXPERIMENTAL, too.

Hm, as I wrote it needs a patch for ehci-hcd or it will only work when connected to uhci-hcd. (ohci-hcd should be ok too, but I have no such.) The needed ehci patch is in David Brownell's review queue, he wrote. I hope he'll review it in time to go into 2.6.26 kernel.

I'd prefer inclusion into alsa-kernel with dependency to CONFIG_EXPERIMENTAL, as long as the ehci-patch isn't accepted.

We can also wait a little for David's review of the ehci-patch and decide later.

Karsten

#4 lore raw

Re: [PATCH] snd-usb-us122l v0.3 for US-122L

Hi Takashi,

will post v0.4 soon, no need to submit v0.3 now.

Thanks,
Karsten

#5 lore raw

Re: [PATCH] snd-usb-us122l v0.3 for US-122L

At Mon, 14 Apr 2008 15:12:13 +0200,

Quoted 4 lines · Karsten Wiese

Hi Takashi,

will post v0.4 soon, no need to submit v0.3 now.

Thanks, good to know. I'm just right now unpacking your patch :)

Takashi

#6 lore raw

PATCH 1/1 snd-usb-us122l v0.4 for US-122L

In reply to Karsten Wiese

Hi,

there are 2 fixes since v0.3 here:
- compiles & works for x86 32bit again.
- hardware configuration is done via ioctl() instead of write(). Fixing a bug that led to jackd not starting again after a stop.

The tar.bz2 only contains Module & alsa-plugin patches. The asoundrc, ehci-patch and notes in mail

	"[PATCH] snd-usb-us122l v0.2 for US-122L"

still apply.

Regards,
Karsten

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#7 lore raw

Re: [PATCH] snd-usb-us122l v0.4 for US-122L

At Mon, 14 Apr 2008 21:29:54 +0200,

Quoted 7 lines · Karsten Wiese

Hi,

there are 2 fixes since v0.3 here:
- compiles & works for x86 32bit again.
- hardware configuration is done via ioctl() instead of write(). Fixing a bug that led to jackd not starting again after a stop.

sound/usb/usbmidi.c +0 -0
index 6676a17..3c55dea 100644

(snip)
+static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep) (snip)
+ while (count < 9)
+ ((char *)ep->urb->transfer_buffer)[count++] = 0xFD;

Use memset().

sound/usb/usx2y/Makefile +2 -0
index 9ac22bc..7489330 100644
@@ -1,3 +1,5 @@
 snd-usb-usx2y-objs := usbusx2y.o usX2Yhwdep.o usx2yhwdeppcm.o
+snd-usb-us122l-objs := us122l.o
 
 obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-usx2y.o
+obj-$(CONFIG_SND_USB_US122L) += snd-usb-us122l.o

Missing dependency to snd-usb-audio?
Maybe we need to split a helper module...

+static void pt_version(struct usb_device *dev)
+{
+ int ret;
+ u8 *buf = kmalloc(200, GFP_KERNEL);
+ if (!buf)
+ return;
+
+ ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),

+			      'V',
+			      USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+			      0, 0, buf, 200, 1000);

+ if (ret < 0) {
+ P_DBG("%i", ret);
+ goto out;
+ }
+ P_VDBG("%u %u %u", buf[0], buf[1], buf[2]);
+ buf[ret] = 0;
+ P_VDBG(".%s.", buf + 3);
+
+out:
+ kfree(buf);
+}

This function is only for debugging, no?

+static int pt_info(struct usb_device *dev)
+{
+ int ret;
+ u8 *buf = kmalloc(200, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),

+			      'I',
+			      USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+			      0, 0, buf, 200, 1000);

+ if (ret < 0) {
+ P_DBG("%i", ret);
+ goto out;
+ }
+ P_VDBG("0x%X", buf[0]);
+ ret = buf[0];
+
+out:
+ kfree(buf);
+ return ret;
+}

Ditto.

+static void pt_info_set(struct usb_device *dev, u8 v) +{
+ int ret;
+
+ ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),

+			      'I',
+			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+			      v, 0, NULL, 0, 1000);

+ P_VDBG("%i", ret);
+}

Ditto.

--- /dev/null
+++ b/sound/usb/usx2y/usb_stream.h
(snip)
+
+#define INTERFACE_VERSION 1
+#define KERNEL_64 0x80000000

Should be more unique name as this seems imported by user-space apps...

+#define USB_STREAM_INTERFACE_VERSION \
+ ((BITS_PER_LONG == 64 ? KERNEL_64 : 0) | INTERFACE_VERSION)
+
+#define SNDRV_USB_STREAM_IOCTL_SET_PARAMS \
+ _IOW('H', 0x90, struct usb_stream_config)
+
+#if !__KERNEL__

Usually #ifndef __KERNEL__

+struct usb_iso_packet_descriptor {
+ unsigned int offset;
+ unsigned int length; /* expected length */
+ unsigned int actual_length;
+ int status;
+};

Why this is needed for !__KERNEL__ ?
I see only struct usb_stream_config is required.

+
+#endif
+
+#define USB_STREAM_NURBS 4
+struct usb_stream_config {
+ unsigned version;
+ unsigned sample_rate;
+ unsigned period_frames;
+ unsigned frame_size;
+};

The codes below here should be hidden to user-space.
If it's exported, then prepare more explicit struct. For example, pointers may have different sizes on user-space.

+#define P_WARN(fmt, ...) \
+ printk(KERN_WARNING"%s %s:%i "fmt"\n", \
+ MODNAME, __func__, __LINE__, ## __VA_ARGS__);
+
+#define P_DBG(fmt, ...) \
+ printk(KERN_DEBUG"%s %s:%i "fmt"\n", \
+ MODNAME, __func__, __LINE__, ## __VA_ARGS__);
+
+#define P_VDBG(fmt, ...)

Try to avoid own-printk macros as much as possible...

thanks,

Takashi

#8 lore raw

Re: [PATCH] snd-usb-us122l v0.4 for US-122L

Am Dienstag, 15. April 2008 schrieb Takashi Iwai:

Quoted 20 lines

At Mon, 14 Apr 2008 21:29:54 +0200,

Quoted 7 lines · Karsten Wiese

Hi,

there are 2 fixes since v0.3 here:
- compiles & works for x86 32bit again.
- hardware configuration is done via ioctl() instead of write(). Fixing a bug that led to jackd not starting again after a stop.

sound/usb/usbmidi.c +3 -0
index 6676a17..3c55dea 100644
(snip)
+static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep)
(snip)
+	while (count < 9)
+		((char *)ep->urb->transfer_buffer)[count++] = 0xFD;
Quoted 1 line

Use memset().

will do.

Quoted 12 lines
sound/usb/usx2y/Makefile +2 -0
index 9ac22bc..7489330 100644
@@ -1,3 +1,5 @@
 snd-usb-usx2y-objs := usbusx2y.o usX2Yhwdep.o usx2yhwdeppcm.o
+snd-usb-us122l-objs := us122l.o
 
 obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-usx2y.o
+obj-$(CONFIG_SND_USB_US122L) += snd-usb-us122l.o
Quoted 2 lines

Missing dependency to snd-usb-audio?
Maybe we need to split a helper module...

don't understand. please explain.

Quoted 24 lines
sound/usb/usx2y/Makefile +22 -0
+static void pt_version(struct usb_device *dev)
+{
+	int ret;
+	u8 *buf = kmalloc(200, GFP_KERNEL);
+	if (!buf)
+		return;
+
+	ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
+			      'V',
+			      USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+			      0, 0, buf, 200, 1000);
+	if (ret < 0) {
+		P_DBG("%i", ret);
+		goto out;
+	}
+	P_VDBG("%u %u %u", buf[0], buf[1], buf[2]);
+	buf[ret] = 0;
+	P_VDBG(".%s.", buf + 3);
+
+out:
+	kfree(buf);
+}
Quoted 1 line

This function is only for debugging, no?

At least 1 of these is needed to make the thing work. Will check.

Quoted 46 lines
sound/usb/usx2y/Makefile +22 -0
+static int pt_info(struct usb_device *dev)
+{
+	int ret;
+	u8 *buf = kmalloc(200, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
+			      'I',
+			      USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+			      0, 0, buf, 200, 1000);
+	if (ret < 0) {
+		P_DBG("%i", ret);
+		goto out;
+	}
+	P_VDBG("0x%X", buf[0]);
+	ret = buf[0];
+
+out:
+	kfree(buf);
+	return ret;
+}

Ditto.

sound/usb/usx2y/Makefile +10 -0
+static void pt_info_set(struct usb_device *dev, u8 v)
+{
+	int ret;
+
+	ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
+			      'I',
+			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+			      v, 0, NULL, 0, 1000);
+	P_VDBG("%i", ret);
+}

Ditto.

sound/usb/usx2y/usb_stream.h new file +3 -0
(snip)
+
+#define INTERFACE_VERSION 1
+#define KERNEL_64 0x80000000
Quoted 2 lines

Should be more unique name as this seems imported by user-space apps...

Ok.

Quoted 10 lines
sound/usb/usx2y/usb_stream.h new file +7 -0
+#define USB_STREAM_INTERFACE_VERSION \
+	((BITS_PER_LONG == 64 ? KERNEL_64 : 0) | INTERFACE_VERSION)
+
+#define SNDRV_USB_STREAM_IOCTL_SET_PARAMS \
+	_IOW('H', 0x90, struct usb_stream_config)
+
+#if !__KERNEL__

Usually #ifndef __KERNEL__

will change.

Quoted 10 lines
sound/usb/usx2y/usb_stream.h new file +6 -0
+struct usb_iso_packet_descriptor {
+	unsigned int offset;
+	unsigned int length;		/* expected length */
+	unsigned int actual_length;
+	int status;
+};

Why this is needed for !__KERNEL__ ?
I see only struct usb_stream_config is required.

see the plugin. Userspace directly reads urbs.

Quoted 12 lines
sound/usb/usx2y/usb_stream.h new file +10 -0
+
+#endif
+
+#define USB_STREAM_NURBS 4
+struct usb_stream_config {
+	unsigned version;
+	unsigned sample_rate;
+	unsigned period_frames;
+	unsigned frame_size;
+};
Quoted 3 lines

The codes below here should be hidden to user-space.
If it's exported, then prepare more explicit struct. For example, pointers may have different sizes on user-space.

Needed in user-space. Currently only 64Bit userspace works on 64Bit kernel. Also 32bit user-space on 32bit kernel.
32bit user-space on 64bit kernel returns an error to the caller, please see the plugin.
IMO 32bit user-space working on 64bit kernel can wait for "INTERFACE_VERSION 2"

Quoted 12 lines
sound/usb/usx2y/usb_stream.h new file +9 -0
+#define P_WARN(fmt, ...) \
+	printk(KERN_WARNING"%s %s:%i "fmt"\n", \
+	       MODNAME, __func__, __LINE__, ## __VA_ARGS__);
+
+#define P_DBG(fmt, ...) \
+	printk(KERN_DEBUG"%s %s:%i "fmt"\n", \
+	       MODNAME, __func__, __LINE__, ## __VA_ARGS__);
+
+#define P_VDBG(fmt, ...)
Quoted 1 line

Try to avoid own-printk macros as much as possible...

will fix.

thanks,
Karsten

#9 lore raw

Re: [PATCH] snd-usb-us122l v0.4 for US-122L

At Tue, 15 Apr 2008 16:48:34 +0200,

Quoted 9 lines · Karsten Wiese
Quoted 9 lines
sound/usb/usx2y/Makefile +1 -0
index 9ac22bc..7489330 100644
@@ -1,3 +1,5 @@
 snd-usb-usx2y-objs := usbusx2y.o usX2Yhwdep.o usx2yhwdeppcm.o
+snd-usb-us122l-objs := us122l.o
 
Quoted 7 lines
Quoted 5 lines
sound/usb/usx2y/Makefile +1 -0
 obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-usx2y.o
+obj-$(CONFIG_SND_USB_US122L) += snd-usb-us122l.o

Missing dependency to snd-usb-audio?
Maybe we need to split a helper module...

don't understand. please explain.

snd-usb-us122l module calls functions that are present in snd-usb-audio module. This dependency should be written either in Kconfig or Makefile properly.

Quoted 11 lines
Quoted 9 lines
sound/usb/usx2y/Makefile +6 -0
+struct usb_iso_packet_descriptor {
+	unsigned int offset;
+	unsigned int length;		/* expected length */
+	unsigned int actual_length;
+	int status;
+};

Why this is needed for !__KERNEL__ ?
I see only struct usb_stream_config is required.

see the plugin. Userspace directly reads urbs.

Hmm, but this is basically defined in usb stack?
Not a big business to redefine here, though...

Quoted 10 lines
Quoted 10 lines
sound/usb/usx2y/Makefile +9 -0
+#endif
+
+#define USB_STREAM_NURBS 4
+struct usb_stream_config {
+	unsigned version;
+	unsigned sample_rate;
+	unsigned period_frames;
+	unsigned frame_size;
+};
Quoted 9 lines
Quoted 3 lines

The codes below here should be hidden to user-space.
If it's exported, then prepare more explicit struct. For example, pointers may have different sizes on user-space.

Needed in user-space. Currently only 64Bit userspace works on 64Bit kernel. Also 32bit user-space on 32bit kernel.
32bit user-space on 64bit kernel returns an error to the caller, please see the plugin.
IMO 32bit user-space working on 64bit kernel can wait for "INTERFACE_VERSION 2"

Exporting this kind of particular internal struct to the user-space is very dangerous. This shouldn't be done. If a part of the data struct is needed to be accessible via mmap etc, define explicitly the data struct instead.

Takashi

#10 lore raw

Re: [PATCH] snd-usb-us122l v0.4 for US-122L

Am Dienstag, 15. April 2008 schrieb Takashi Iwai:

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
(quoted diff) +9 -0
+#endif
+
+#define USB_STREAM_NURBS 4
+struct usb_stream_config {
+	unsigned version;
+	unsigned sample_rate;
+	unsigned period_frames;
+	unsigned frame_size;
+};
Quoted 9 lines
Quoted 3 lines

The codes below here should be hidden to user-space.
If it's exported, then prepare more explicit struct. For example, pointers may have different sizes on user-space.

Needed in user-space. Currently only 64Bit userspace works on 64Bit kernel. Also 32bit user-space on 32bit kernel.
32bit user-space on 64bit kernel returns an error to the caller, please see the plugin.
IMO 32bit user-space working on 64bit kernel can wait for "INTERFACE_VERSION 2"

Quoted 2 lines

Exporting this kind of particular internal struct to the user-space is very dangerous.

Everything exported by that struct can only be mmap()ed "read only". Please explain why you think its very dangerous.

Quoted 4 lines

This shouldn't be done.
If a part of the data struct
is needed to be accessible via mmap etc, define explicitly the data struct instead.

Nearly all of the data struct is used by the user-space plugin.

thanks,
Karsten

#11 lore raw

Re: [PATCH] snd-usb-us122l v0.4 for US-122L

At Tue, 15 Apr 2008 18:40:48 +0200,

Quoted 21 lines · Karsten Wiese

Am Dienstag, 15. April 2008 schrieb Takashi Iwai:

Quoted 19 lines
Quoted 19 lines
Quoted 10 lines
(quoted diff) +9 -0
+#endif
+
+#define USB_STREAM_NURBS 4
+struct usb_stream_config {
+	unsigned version;
+	unsigned sample_rate;
+	unsigned period_frames;
+	unsigned frame_size;
+};
Quoted 3 lines

The codes below here should be hidden to user-space.
If it's exported, then prepare more explicit struct. For example, pointers may have different sizes on user-space.

Needed in user-space. Currently only 64Bit userspace works on 64Bit kernel. Also 32bit user-space on 32bit kernel.
32bit user-space on 64bit kernel returns an error to the caller, please see the plugin.
IMO 32bit user-space working on 64bit kernel can wait for "INTERFACE_VERSION 2"

Quoted 5 lines
Quoted 2 lines

Exporting this kind of particular internal struct to the user-space is very dangerous.

Everything exported by that struct can only be mmap()ed "read only". Please explain why you think its very dangerous.

It's pretty fragile against ABI breakage, for example. Imagine that if the kernel changes wait_queue_head_t implementation. Even if you don't change your code, the struct size may change, too.

But, what I feel uneasy is that this ABI exposes kernel pointers excessively. Passing pointers should be avoided if you think of portability and maintenance in future.
We don't have to be a naked king. Let's wear something for the thing that we don't want to show.

And, if you avoid pointers (and long offsets / addresses) in the shared parameters, it'd be even bi-arch compliant. One less worry gratis.

Takashi

#12 lore raw

PATCH 1/1 snd-usb-us122l v0.5 for US-122L

Am Freitag, 18. April 2008 schrieb Takashi Iwai:

Quoted 4 lines

And, if you avoid pointers (and long offsets / addresses) in the shared parameters, it'd be even bi-arch compliant. One less worry gratis.

Hi Takashi,

I addressed above and the other issues. Please have a look again.

The tar.bz2 only contains Module & alsa-plugin patches. The asoundrc, ehci-patch and notes in mail

        "[PATCH] snd-usb-us122l v0.2 for US-122L"

still apply.
Except v0.5 maybe (untested) runs 32bit userspace on a 64bit kernel.

Thanks,
Karsten

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#13 lore raw

Re: [PATCH] snd-usb-us122l v0.5 for US-122L

At Mon, 19 May 2008 12:58:30 +0200,

Quoted 8 lines · Karsten Wiese

Am Freitag, 18. April 2008 schrieb Takashi Iwai:

Quoted 4 lines

And, if you avoid pointers (and long offsets / addresses) in the shared parameters, it'd be even bi-arch compliant. One less worry gratis.

Quoted 4 lines

Hi Takashi,

I addressed above and the other issues. Please have a look again.

Thanks, at a quick glance, this looks much better. A good work!

Quoted 4 lines

The tar.bz2 only contains Module & alsa-plugin patches. The asoundrc, ehci-patch and notes in mail

        "[PATCH] snd-usb-us122l v0.2 for US-122L"

still apply.

Could you send both patches separately again? Did USB guys already review your ehci patch?

thanks,

Takashi

#14 lore raw

Re: [PATCH] snd-usb-us122l v0.5 for US-122L

Am Montag, 19. Mai 2008 schrieb Takashi Iwai:

Quoted 2 lines

Could you send both patches separately again?

Yes, following this e-mail.

Quoted 2 lines

Did USB guys already
review your ehci patch?

No. Maybe iff the module is committed, they can be convinced to do so easier ;-)

thanks,
Karsten

#15 lore raw

Re: [PATCH] snd-usb-us122l v0.5 for US-122L

At Tue, 20 May 2008 11:29:39 +0200,

Quoted 6 lines · Karsten Wiese

Am Montag, 19. Mai 2008 schrieb Takashi Iwai:

Quoted 2 lines

Could you send both patches separately again?

Yes, following this e-mail.

Well, I meant the missing patches, usb-ehci etc :)

Anyway, it's better to have one patch per mail. Thanks.

Takashi

#16 lore raw

Re: [PATCH] snd-usb-us122l v0.5 for US-122L

Am Dienstag, 20. Mai 2008 schrieb Takashi Iwai:

Quoted 3 lines

Well, I meant the missing patches, usb-ehci etc :)

I run below patch on top of 2.6.25.x. It also contains some patches not actually needed to let the us122l connected to ehci work.

The needed .asoundrc section is contained in the description part of the plugin patch I've just sent.

Will post the ehci patch I posted to linux-usb after this e-mail.

Thanks,
Karsten

---

drivers/usb/host/ehci-hcd.c +41 -25
index 46ee7f4..aebd534 100644
@@ -174,6 +174,16 @@ static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
 	return -ETIMEDOUT;
 }
 
+static int handshake_on_error_set_halt(struct ehci_hcd *ehci, void __iomem *ptr,
+				       u32 mask, u32 done, int usec)
+{
+	int error = handshake(ehci, ptr, mask, done, usec);
+	if (error)
+		ehci_to_hcd(ehci)->state = HC_STATE_HALT;
+
+	return error;
+}
+
 /* force HC to halt state from unknown (EHCI spec section 2.3) */
 static int ehci_halt (struct ehci_hcd *ehci)
 {
@@ -246,11 +256,9 @@ static void ehci_quiesce (struct ehci_hcd *ehci)
 	/* wait for any schedule enables/disables to take effect */
 	temp = ehci_readl(ehci, &ehci->regs->command) << 10;
 	temp &= STS_ASS | STS_PSS;
-	if (handshake (ehci, &ehci->regs->status, STS_ASS | STS_PSS,
-				temp, 16 * 125) != 0) {
-		ehci_to_hcd(ehci)->state = HC_STATE_HALT;
+	if (handshake_on_error_set_halt(ehci, &ehci->regs->status,
+					STS_ASS | STS_PSS, temp, 16 * 125))
 		return;
-	}
 
 	/* then disable anything that's still active */
 	temp = ehci_readl(ehci, &ehci->regs->command);
@@ -258,11 +266,8 @@ static void ehci_quiesce (struct ehci_hcd *ehci)
 	ehci_writel(ehci, temp, &ehci->regs->command);
 
 	/* hardware can take 16 microframes to turn off ... */
-	if (handshake (ehci, &ehci->regs->status, STS_ASS | STS_PSS,
-				0, 16 * 125) != 0) {
-		ehci_to_hcd(ehci)->state = HC_STATE_HALT;
-		return;
-	}
+	handshake_on_error_set_halt(ehci, &ehci->regs->status,
+				    STS_ASS | STS_PSS, 0, 16 * 125);
 }
 
 /*-------------------------------------------------------------------------*/
@@ -355,17 +360,13 @@ static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
 				&ehci->regs->port_status[port]);
 }
 
-/* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
- * This forcibly disables dma and IRQs, helping kexec and other cases
- * where the next system software may expect clean state.
+/*
+ * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
+ * Should be called with ehci->lock held.
  */
-static void
-ehci_shutdown (struct usb_hcd *hcd)
+static void ehci_silence_controller(struct ehci_hcd *ehci)
 {
-	struct ehci_hcd	*ehci;
-
-	ehci = hcd_to_ehci (hcd);
-	(void) ehci_halt (ehci);
+	ehci_halt(ehci);
 	ehci_turn_off_all_ports(ehci);
 
 	/* make BIOS/etc use companion controller during reboot */
@@ -375,6 +376,22 @@ ehci_shutdown (struct usb_hcd *hcd)
 	ehci_readl(ehci, &ehci->regs->configured_flag);
 }
 
+/* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
+ * This forcibly disables dma and IRQs, helping kexec and other cases
+ * where the next system software may expect clean state.
+ */
+static void ehci_shutdown(struct usb_hcd *hcd)
+{
+	struct ehci_hcd	*ehci = hcd_to_ehci(hcd);
+
+	del_timer_sync(&ehci->watchdog);
+	del_timer_sync(&ehci->iaa_watchdog);
+
+	spin_lock_irq(&ehci->lock);
+	ehci_silence_controller(ehci);
+	spin_unlock_irq(&ehci->lock);
+}
+
 static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
 {
 	unsigned port;
@@ -425,15 +442,15 @@ static void ehci_work (struct ehci_hcd *ehci)
 		timer_action (ehci, TIMER_IO_WATCHDOG);
 }
 
+/*
+ * Called when the ehci_hcd module is removed.
+ */
 static void ehci_stop (struct usb_hcd *hcd)
 {
 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
 
 	ehci_dbg (ehci, "stop\n");
 
-	/* Turn off port power on all root hub ports. */
-	ehci_port_power (ehci, 0);
-
 	/* no more interrupts ... */
 	del_timer_sync (&ehci->watchdog);
 	del_timer_sync(&ehci->iaa_watchdog);
@@ -442,13 +459,10 @@ static void ehci_stop (struct usb_hcd *hcd)
 	if (HC_IS_RUNNING (hcd->state))
 		ehci_quiesce (ehci);
 
+	ehci_silence_controller(ehci);
 	ehci_reset (ehci);
-	ehci_writel(ehci, 0, &ehci->regs->intr_enable);
 	spin_unlock_irq(&ehci->lock);
 
-	/* let companion controllers work when we aren't */
-	ehci_writel(ehci, 0, &ehci->regs->configured_flag);
-
 	remove_companion_file(ehci);
 	remove_debug_files (ehci);
 
@@ -494,6 +508,7 @@ static int ehci_init(struct usb_hcd *hcd)
 	 * periodic_size can shrink by USBCMD update if hcc_params allows.
 	 */
 	ehci->periodic_size = DEFAULT_I_TDPS;
+	INIT_LIST_HEAD(&ehci->cached_itd_list);
 	if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
 		return retval;
 
@@ -506,6 +521,7 @@ static int ehci_init(struct usb_hcd *hcd)
 
 	ehci->reclaim = NULL;
 	ehci->next_uframe = -1;
+	ehci->hw_frame = -1;
 
 	/*
 	 * dedicate a qh for the async ring head, since we couldn't unlink
drivers/usb/host/ehci-mem.c +1 -0
index 0431397..10d5291 100644
@@ -128,6 +128,7 @@ static inline void qh_put (struct ehci_qh *qh)
 
 static void ehci_mem_cleanup (struct ehci_hcd *ehci)
 {
+	free_cached_itd_list(ehci);
 	if (ehci->async)
 		qh_put (ehci->async);
 	ehci->async = NULL;
drivers/usb/host/ehci-sched.c +66 -35

177 lines not on this page · raw message

drivers/usb/host/ehci.h +5 -0
index bf92d20..c61dcb6 100644
@@ -86,6 +86,9 @@ struct ehci_hcd {			/* one per controller */
 	union ehci_shadow	*pshadow;	/* mirror hw periodic table */
 	int			next_uframe;	/* scan periodic, start here */
 	unsigned		periodic_sched;	/* periodic activity count */
+	struct list_head	cached_itd_list; /* list of itds completed
+			while frame hadn't yet elapsed */
+	unsigned		hw_frame;
 
 	/* per root hub port */
 	unsigned long		reset_done [EHCI_MAX_ROOT_PORTS];
@@ -203,6 +206,8 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
 	}
 }
 
+static void free_cached_itd_list(struct ehci_hcd *ehci);
+
 /*-------------------------------------------------------------------------*/
 
 /* EHCI register interface, corresponds to EHCI Revision 0.95 specification */
#17 lore raw

Re: [PATCH] snd-usb-us122l v0.5 for US-122L

This is the ehci patch against 2.6.25.x needed to let the us122l work with my driver if the device is connected to an ehci-hcd.

I've sent it to linux-usb in february. It hasn't been reviewed yet.

Thanks,
Karsten

-----------------------------------------------------------------------------

From: Karsten Wiese <[email protected]>
Date: Wed, 13 Feb 2008 22:22:09 +0100
Subject: [PATCH] USB: Prevent EHCI ITDs reusage while frame is active

ITDs can be detached from urbs, before the frame elapses. Now those ITDs are immediately recycled.
If the ITD is reused then, transaction based on its new usage can already happen while the frame is still active, too early.
Patch takes care of those ITDs by moving them into a new ehci member list cached_itd_list. ITDs resting in cached_itd_list are moved back into their stream's free_list once scan_periodic() detects that the active frame has elapsed.

---
 drivers/usb/host/ehci-hcd.c   |    2 +
 drivers/usb/host/ehci-mem.c   |    1 +
 drivers/usb/host/ehci-sched.c |   57 ++++++++++++++++++++++++++++++++++------
 drivers/usb/host/ehci.h       |    5 +++
 4 files changed, 56 insertions(+), 9 deletions(-)
drivers/usb/host/ehci-hcd.c +2 -0
index 4caa6a8..b75db12 100644
@@ -473,6 +473,7 @@ static int ehci_init(struct usb_hcd *hcd)
 	 * periodic_size can shrink by USBCMD update if hcc_params allows.
 	 */
 	ehci->periodic_size = DEFAULT_I_TDPS;
+	INIT_LIST_HEAD(&ehci->cached_itd_list);
 	if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
 		return retval;
 
@@ -485,6 +486,7 @@ static int ehci_init(struct usb_hcd *hcd)
 
 	ehci->reclaim = NULL;
 	ehci->next_uframe = -1;
+	ehci->hw_frame = -1;
 
 	/*
 	 * dedicate a qh for the async ring head, since we couldn't unlink
drivers/usb/host/ehci-mem.c +1 -0
index 0431397..10d5291 100644
@@ -128,6 +128,7 @@ static inline void qh_put (struct ehci_qh *qh)
 
 static void ehci_mem_cleanup (struct ehci_hcd *ehci)
 {
+	free_cached_itd_list(ehci);
 	if (ehci->async)
 		qh_put (ehci->async);
 	ehci->async = NULL;
drivers/usb/host/ehci-sched.c +48 -9

95 lines not on this page · raw message

drivers/usb/host/ehci.h +5 -0
index bf92d20..c61dcb6 100644
@@ -86,6 +86,9 @@ struct ehci_hcd {			/* one per controller */
 	union ehci_shadow	*pshadow;	/* mirror hw periodic table */
 	int			next_uframe;	/* scan periodic, start here */
 	unsigned		periodic_sched;	/* periodic activity count */
+	struct list_head	cached_itd_list; /* list of itds completed
+			while frame hadn't yet elapsed */
+	unsigned		hw_frame;
 
 	/* per root hub port */
 	unsigned long		reset_done [EHCI_MAX_ROOT_PORTS];
@@ -203,6 +206,8 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
 	}
 }
 
+static void free_cached_itd_list(struct ehci_hcd *ehci);
+
 /*-------------------------------------------------------------------------*/
 
 /* EHCI register interface, corresponds to EHCI Revision 0.95 specification */
Signature · 1 line
1.5.3.8
#18 lore raw

PATCH 1/1 TASCAM US-122L Module

In reply to Karsten Wiese

Establishes standard raw midi and custom pcm i/o.
Pcm is transmitted using mmaped memory, userspace accesses urb dma-memory. ALSA pcm in userspace can be done using the usb_stream alsa-plugin.
Ehci-hcd note: Module doesn't care for iso number of packets being a multiple
of 8 so at least for vanilla kernels <= 2.6.26 it only works when the device is attached to an USB1.1 port.

---

sound/usb/Kconfig +11 -0
index 9351b8a..9426f42 100644
@@ -63,5 +63,16 @@ config SND_USB_CAIAQ_INPUT
 	   * Native Instruments Kore Controller 2
 	   * Native Instruments Audio Kontrol 1
 
+config SND_USB_US122L
+	tristate "Tascam US-122L USB driver"
+	depends on SND && USB && X86 && EXPERIMENTAL
+	select SND_RAWMIDI
+	help
+	  Say Y here to include support for Tascam US-122L USB Audio/MIDI
+	  interfaces.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called snd-usb-us122l.
+
 endmenu
 
sound/usb/Makefile +1 -0
index aa252ef..abb288b 100644
@@ -8,5 +8,6 @@ snd-usb-lib-objs := usbmidi.o
 # Toplevel Module Dependency
 obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-audio.o snd-usb-lib.o
 obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-lib.o
+obj-$(CONFIG_SND_USB_US122L) += snd-usb-lib.o
 
 obj-$(CONFIG_SND) += usx2y/ caiaq/
sound/usb/usbaudio.h +1 -0
index 7cf18c3..140ba36 100644
@@ -156,6 +156,7 @@ enum quirk_type {
 	QUIRK_MIDI_RAW,
 	QUIRK_MIDI_EMAGIC,
 	QUIRK_MIDI_CME,
+	QUIRK_MIDI_US122L,
 	QUIRK_AUDIO_STANDARD_INTERFACE,
 	QUIRK_AUDIO_FIXED_ENDPOINT,
 	QUIRK_AUDIO_EDIROL_UA700_UA25,
sound/usb/usbmidi.c +39 -0
index 6676a17..c0c7770 100644
@@ -669,6 +669,42 @@ static struct usb_protocol_ops snd_usbmidi_raw_ops = {
 	.output = snd_usbmidi_raw_output,
 };
 
+static void snd_usbmidi_us122l_input(struct snd_usb_midi_in_endpoint *ep,
+				     uint8_t *buffer, int buffer_length)
+{
+	if (buffer_length != 9)
+		return;
+	buffer_length = 8;
+	while (buffer_length && buffer[buffer_length - 1] == 0xFD)
+		buffer_length--;
+	if (buffer_length)
+		snd_usbmidi_input_data(ep, 0, buffer, buffer_length);
+}
+
+static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep)
+{
+	int count;
+
+	if (!ep->ports[0].active)
+		return;
+	count = ep->urb->dev->speed == USB_SPEED_HIGH ? 1 : 2;
+	count = snd_rawmidi_transmit(ep->ports[0].substream,
+				     ep->urb->transfer_buffer,
+				     count);
+	if (count < 1) {
+		ep->ports[0].active = 0;
+		return;
+	}
+
+	memset(ep->urb->transfer_buffer + count, 0xFD, 9 - count);
+	ep->urb->transfer_buffer_length = count;
+}
+
+static struct usb_protocol_ops snd_usbmidi_122l_ops = {
+	.input = snd_usbmidi_us122l_input,
+	.output = snd_usbmidi_us122l_output,
+};
+
 /*
  * Emagic USB MIDI protocol: raw MIDI with "F5 xx" port switching.
  */
@@ -1714,6 +1750,9 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
 			umidi->usb_protocol_ops =
 				&snd_usbmidi_maudio_broken_running_status_ops;
 		break;
+	case QUIRK_MIDI_US122L:
+		umidi->usb_protocol_ops = &snd_usbmidi_122l_ops;
+		/* fall through */
 	case QUIRK_MIDI_FIXED_ENDPOINT:
 		memcpy(&endpoints[0], quirk->data,
 		       sizeof(struct snd_usb_midi_endpoint_info));
sound/usb/usx2y/Makefile +2 -0
index 9ac22bc..7489330 100644
@@ -1,3 +1,5 @@
 snd-usb-usx2y-objs := usbusx2y.o usX2Yhwdep.o usx2yhwdeppcm.o
+snd-usb-us122l-objs := us122l.o
 
 obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-usx2y.o
+obj-$(CONFIG_SND_USB_US122L) += snd-usb-us122l.o
sound/usb/usx2y/us122l.c new file +692 -0

692 lines not on this page · raw message

sound/usb/usx2y/us122l.h new file +27 -0
new file mode 100644
index 0000000..3d10c4b
@@ -0,0 +1,27 @@
+#ifndef US122L_H
+#define US122L_H
+
+
+struct us122l {
+	struct snd_usb_audio 	chip;
+	int			stride;
+	struct usb_stream_kernel sk;
+
+	struct mutex		mutex;
+	struct file		*first;
+	unsigned		second_periods_polled;
+	struct file		*master;
+	struct file		*slave;
+
+	atomic_t		mmap_count;
+};
+
+
+#define US122L(c) ((struct us122l *)(c)->private_data)
+
+#define NAME_ALLCAPS "US-122L"
+
+#define USB_ID_US122L 0x800E
+#define USB_ID_US144 0x800F
+
+#endif
sound/usb/usx2y/usb_stream.c new file +699 -0

699 lines not on this page · raw message

sound/usb/usx2y/usb_stream.h new file +112 -0

112 lines not on this page · raw message

include/sound/asound.h +2 -1
index 3eaf155..ca2f358 100644
@@ -93,9 +93,10 @@ enum {
 	SNDRV_HWDEP_IFACE_PCXHR,	/* Digigram PCXHR */
 	SNDRV_HWDEP_IFACE_SB_RC,	/* SB Extigy/Audigy2NX remote control */
 	SNDRV_HWDEP_IFACE_HDA,		/* HD-audio */
+	SNDRV_HWDEP_IFACE_USB_STREAM,	/* direct access to usb stream */
 
 	/* Don't forget to change the following: */
-	SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_HDA
+	SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_USB_STREAM
 };
 
 struct snd_hwdep_info {
#19 lore raw

PATCH 1/1 usb_stream alsa-plugin

In reply to Karsten Wiese

Establishes pcm i/o for the snd_usb_us122l module.

Needs below section to be a part of ~/.asoundrc:
# The usb_stream plugin configuration

pcm.!usb_stream {
	@args [ CARD ]
	@args.CARD {
		type string
		default "0"
	}

	type usb_stream

	card $CARD
}

Example loop command:

$ ARGS="-MDusb_stream:2 -fS24_3LE -r44100 -c2 --period-size=640" ; arecord $ARGS | aplay $ARGS

---

configure.in +1 -0
diff -NpurX /home/ka/diff_exc alsa-plugins-1.0.15/configure.in alsa-plugins-1.0.15+usb_stream/configure.in
@@ -111,6 +111,7 @@ AC_OUTPUT([
 	rate-lavc/Makefile
 	maemo/Makefile
 	doc/Makefile
+	usb_stream/Makefile
 ])
 
 dnl Show the build conditions
Makefile.am +1 -1
diff -NpurX /home/ka/diff_exc alsa-plugins-1.0.15/Makefile.am alsa-plugins-1.0.15+usb_stream/Makefile.am
@@ -18,7 +18,7 @@ if HAVE_PPH
 PPHDIR = pph
 endif
 
-SUBDIRS = oss mix $(PPHDIR) $(JACKDIR) $(PULSEDIR) $(SAMPLERATEDIR) $(A52DIR) $(LAVCRATEDIR) $(MAEMODIR) doc
+SUBDIRS = oss mix $(PPHDIR) $(JACKDIR) $(PULSEDIR) $(SAMPLERATEDIR) $(A52DIR) $(LAVCRATEDIR) $(MAEMODIR) usb_stream doc
 EXTRA_DIST = hgcompile version COPYING.GPL
 AUTOMAKE_OPTIONS = foreign
 
usb_stream/Makefile.am +9 -0
diff -NpurX /home/ka/diff_exc alsa-plugins-1.0.15/usb_stream/Makefile.am alsa-plugins-1.0.15+usb_stream/usb_stream/Makefile.am
@@ -0,0 +1,9 @@
+asound_module_pcm_usb_stream_LTLIBRARIES = libasound_module_pcm_usb_stream.la
+
+asound_module_pcm_usb_streamdir = @ALSA_PLUGIN_DIR@
+
+AM_CFLAGS = -Wall -g @ALSA_CFLAGS@
+AM_LDFLAGS = -module -avoid-version -export-dynamic
+
+libasound_module_pcm_usb_stream_la_SOURCES = pcm_usb_stream.c
+libasound_module_pcm_usb_stream_la_LIBADD = @ALSA_LIBS@
usb_stream/pcm_usb_stream.c +485 -0

485 lines not on this page · raw message