Skip to contentSkip to conversation

snd-usb-usx2y 0.6.4

PATCH Applied Karsten Wiese 2 participants 7 messages Jun 21, 2004 – Jun 23, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 snd-usb-usx2y 0.6.4

Hi Takashi

This lets midi in work after usb-set-interface() on kernel 2.6.7 and doesn't disturb otherwise.
snd-usb-usx2x calls usb-set-interface() to set the sample format. Please commit, if you agree with the changes to usbmidi.c, with comments:

- resubmit midi in urb after usb-set-interface(), called by snd-usb-usx2x to set the sample format. needed for usb compatibility with kernel 2.6.7.

I think, it is also a good time to move snd-usb-usx2y over to alsa-kernel now.

Best Regards
Karsten

Index: alsa-driver/usb/usbmidi.c
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/usb/usbmidi.c,v retrieving revision 1.12

usb/usbmidi.c +1 -0
diff -u -r1.12 usbmidi.c
@@ -38,4 +38,5 @@
 #endif
 
 EXPORT_SYMBOL(snd_usb_create_midi_interface);
+EXPORT_SYMBOL(snd_usbmidi_in_urb_retry);
 EXPORT_SYMBOL(snd_usbmidi_disconnect);

Index: alsa-driver/usb/usx2y/usbusx2y.c
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/usb/usx2y/usbusx2y.c,v retrieving revision 1.11

usb/usx2y/usbusx2y.c +7 -0
diff -u -r1.11 usbusx2y.c
@@ -1,6 +1,13 @@
 /*
  * usbus428.c - ALSA USB US-428 Driver
  *
+2004-06-19 Karsten Wiese
+	Version 0.6.4:
+	with kernelversion > 2.6.6 (maybe before also)
+	snd-usb-midi cannot resubmit the in_urb when we switch the usb interface.
+	work around that be calling snd_usbmidi_in_urb_retry()
+	after usb_set_interface().
+
 2004-06-12 Karsten Wiese
 	Version 0.6.3:
 	Made it thus the following rule is enforced:

Index: alsa-driver/usb/usx2y/usbusx2yaudio.c
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/usb/usx2y/usbusx2yaudio.c,v retrieving revision 1.11

usb/usx2y/usbusx2yaudio.c +4 -0
diff -u -r1.11 usbusx2yaudio.c
@@ -993,6 +993,7 @@
 
 	if (usX2Y_stream->usX2Y->format != format) {
 		int alternate, unlink_err;
+		struct list_head* p;
 		if (format == SNDRV_PCM_FORMAT_S24_3LE) {
 			alternate = 2;
 			usX2Y_stream->usX2Y->stride = 6;
@@ -1009,6 +1010,9 @@
 			usX2Y_stream->usX2Y->In04urb->dev = usX2Y_stream->usX2Y->chip.dev;
 			err = usb_submit_urb(usX2Y_stream->usX2Y->In04urb, GFP_KERNEL);
 		}
+		list_for_each(p, &usX2Y_stream->usX2Y->chip.midi_list) {
+			snd_usbmidi_in_urb_retry(p);
+		}
 		usX2Y_stream->usX2Y->format = format;
 		usX2Y_stream->usX2Y->rate = 0;
 	}

Index: alsa-kernel/usb/usbaudio.h
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usbaudio.h,v retrieving revision 1.31

usb/usbaudio.h +1 -0
diff -u -r1.31 usbaudio.h
@@ -206,6 +206,7 @@
 
 int snd_usb_create_midi_interface(snd_usb_audio_t *chip, struct usb_interface *iface, const snd_usb_audio_quirk_t *quirk);
 void snd_usbmidi_disconnect(struct list_head *p, struct usb_driver *driver);
+void snd_usbmidi_in_urb_retry(struct list_head* p);
 
 /*
  * retrieve usb_interface descriptor from the host interface

Index: alsa-kernel/usb/usbmidi.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usbmidi.c,v retrieving revision 1.28

usb/usbmidi.c +34 -3
diff -u -r1.28 usbmidi.c
@@ -113,6 +113,7 @@
 struct snd_usb_midi_in_endpoint {
 	snd_usb_midi_t* umidi;
 	struct urb* urb;
+	struct urb* urb_retry;
 	struct usbmidi_in_port {
 		snd_rawmidi_substream_t* substream;
 	} ports[0x10];
@@ -138,8 +139,13 @@
 /*
  * Error handling for URB completion functions.
  */
-static int snd_usbmidi_urb_error(int status)
+static int snd_usbmidi_urb_error(snd_usb_midi_in_endpoint_t* ep, int status)
 {
+	if (status == -ESHUTDOWN)
+		if (ep) {
+			ep->urb_retry = ep->urb;
+			return status;
+		}
 	if (status == -ENOENT)
 		return status; /* killed */
 	if (status == -EILSEQ ||
@@ -185,7 +191,7 @@
 			if (buffer[i] != 0)
 				snd_usbmidi_input_packet(ep, &buffer[i]);
 	} else {
-		if (snd_usbmidi_urb_error(urb->status) < 0)
+		if (snd_usbmidi_urb_error(ep, urb->status) < 0)
 			return;
 	}
 
@@ -232,7 +238,7 @@
 	snd_usb_midi_out_endpoint_t* ep = snd_magic_cast(snd_usb_midi_out_endpoint_t, urb->context, return);
 
 	if (urb->status < 0) {
-		if (snd_usbmidi_urb_error(urb->status) < 0)
+		if (snd_usbmidi_urb_error((snd_usb_midi_in_endpoint_t*)NULL, urb->status) < 0)
 			return;
 	}
 	snd_usbmidi_do_output(ep);
@@ -698,6 +704,31 @@
 	snd_magic_kfree(umidi);
 }
 
+static void snd_usbmidi_in_urb_retry_do(snd_usb_midi_in_endpoint_t* ep)
+{
+	if (ep) {
+		struct urb* urb = ep->urb; 
+		snd_printd("\n");
+		if (urb && urb == ep->urb_retry && usb_pipe_needs_resubmit(urb->pipe)) {
+			snd_printd("\n");
+			urb->dev = ep->umidi->chip->dev;
+			snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
+		}
+	}
+}
+
+void snd_usbmidi_in_urb_retry(struct list_head* p)
+{
+	snd_usb_midi_t* umidi;
+	int i;
+
+	umidi = list_entry(p, snd_usb_midi_t, list);
+	for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
+		snd_usb_midi_endpoint_t* ep = &umidi->endpoints[i];
+		snd_usbmidi_in_urb_retry_do(ep->in);
+	}
+}
+
 /*
  * Unlinks all URBs (must be done before the usb_device is deleted).
  */
#1 lore raw
Quoted 1 line · Karsten Wiese

snd-usb-usx2x calls usb-set-interface() to set the sample format.

.. and the USx2y devices use the same interface for MIDI, it seems.

Quoted 4 lines

This lets midi in work after usb-set-interface() on kernel 2.6.7 and doesn't disturb otherwise.

+ if (urb && urb == ep->urb_retry

It's not obvious why urb_retry is needed. Isn't it always the same as ep->urb?

Quoted 1 line

+ && usb_pipe_needs_resubmit(urb->pipe))

Won't this prevent it from working with interrupt pipes on 2.4?

Quoted 1 line

+ snd_usbmidi_submit_urb(urb, GFP_ATOMIC);

I think we can use GFP_KERNEL here.

I don't like this solution too much, it's just a device-specific kludge. A more general solution would be to have two functions snd_usbmidi_stop/start_input() and calling them before/after changing the sample format. (The start function could be used at the end of snd_usb_create_midi_interface(), too.)

And what should happen to data that is being output when the sample format is changed?

Regards,
Clemens

-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND

#2 lore raw

Am Montag 21 Juni 2004 10:02 schrieb Clemens Ladisch:

Quoted 4 lines
Quoted 1 line · Karsten Wiese

snd-usb-usx2x calls usb-set-interface() to set the sample format.

... and the USx2y devices use the same interface for MIDI, it seems.

Yes.
It is impossible to use different interfaces on one usb_device at the same time. Or not?

Quoted 8 lines
Quoted 5 lines

This lets midi in work after usb-set-interface() on kernel 2.6.7 and doesn't disturb otherwise.

+ if (urb && urb == ep->urb_retry

It's not obvious why urb_retry is needed. Isn't it always the same as ep->urb?

ep->urb_retry is normally NULL and only set to ep->urb, if ep->urb comes back with -ESHUTDOWN.
Thus ep->urb_retry serves as a flag to show that resubmission is needed.

Quoted 7 lines
Quoted 2 lines

+ && usb_pipe_needs_resubmit(urb->pipe))

Won't this prevent it from working with interrupt pipes on 2.4?

Quoted 1 line

+ snd_usbmidi_submit_urb(urb, GFP_ATOMIC);

Quoted 8 lines

I think we can use GFP_KERNEL here.

I don't like this solution too much, it's just a device-specific kludge. A more general solution would be to have two functions snd_usbmidi_stop/start_input() and calling them before/after changing the sample format. (The start function could be used at the end of snd_usb_create_midi_interface(), too.)

Agreed.

Quoted 3 lines

And what should happen to data that is being output when the sample format is changed?

There was no out midi urb missed so far. It looks as if there is no special handling needed.

Regards,
Karsten

-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND

#3 lore raw

Am Montag 21 Juni 2004 10:30 schrieb Karsten Wiese:

Quoted 37 lines

Am Montag 21 Juni 2004 10:02 schrieb Clemens Ladisch:

Quoted 4 lines
Quoted 1 line · Karsten Wiese

snd-usb-usx2x calls usb-set-interface() to set the sample format.

... and the USx2y devices use the same interface for MIDI, it seems.

Yes.
It is impossible to use different interfaces on one usb_device at the same time. Or not?

Quoted 7 lines
Quoted 4 lines

This lets midi in work after usb-set-interface() on kernel 2.6.7 and doesn't disturb otherwise.

+ if (urb && urb == ep->urb_retry

It's not obvious why urb_retry is needed. Isn't it always the same as ep->urb?

ep->urb_retry is normally NULL and only set to ep->urb, if ep->urb comes back with -ESHUTDOWN.
Thus ep->urb_retry serves as a flag to show that resubmission is needed.

Quoted 6 lines
Quoted 1 line

+ && usb_pipe_needs_resubmit(urb->pipe))

Won't this prevent it from working with interrupt pipes on 2.4?

Quoted 1 line

+ snd_usbmidi_submit_urb(urb, GFP_ATOMIC);

Quoted 8 lines

I think we can use GFP_KERNEL here.

I don't like this solution too much, it's just a device-specific kludge. A more general solution would be to have two functions snd_usbmidi_stop/start_input() and calling them before/after changing the sample format. (The start function could be used at the end of snd_usb_create_midi_interface(), too.)

Quoted 8 lines

Agreed.

Quoted 2 lines

And what should happen to data that is being output when the sample format is changed?

There was no out midi urb missed so far. It looks as if there is no special handling needed.

This Patch implements snd_usbmidi_in_stop() and snd_usbmidi_in_start(). Comment for commit would be:
- new functions snd_usbmidi_in_stop() and snd_usbmidi_in_start(). Needed by snd-usb-usx2y to usb-set-interface() in between.

Thanks & Regards,
Karsten

Index: alsa-driver/usb/usbmidi.c
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/usb/usbmidi.c,v retrieving revision 1.12

usb/usbmidi.c +2 -0
diff -u -r1.12 usbmidi.c
@@ -38,4 +38,6 @@
 #endif
 
 EXPORT_SYMBOL(snd_usb_create_midi_interface);
+EXPORT_SYMBOL(snd_usbmidi_in_start);
+EXPORT_SYMBOL(snd_usbmidi_in_stop);
 EXPORT_SYMBOL(snd_usbmidi_disconnect);

Index: alsa-driver/usb/usx2y/usbusx2y.c
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/usb/usx2y/usbusx2y.c,v retrieving revision 1.11

usb/usx2y/usbusx2y.c +5 -0
diff -u -r1.11 usbusx2y.c
@@ -1,6 +1,11 @@
 /*
  * usbus428.c - ALSA USB US-428 Driver
  *
+2004-06-21 Karsten Wiese
+	Version 0.6.4:
+	Temporarely suspend midi in
+	to sanely call usb_set_interface() when setting format.
+
 2004-06-12 Karsten Wiese
 	Version 0.6.3:
 	Made it thus the following rule is enforced:

Index: alsa-driver/usb/usx2y/usbusx2yaudio.c
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/usb/usx2y/usbusx2yaudio.c,v retrieving revision 1.11

usb/usx2y/usbusx2yaudio.c +7 -0
diff -u -r1.11 usbusx2yaudio.c
@@ -993,6 +993,7 @@
 
 	if (usX2Y_stream->usX2Y->format != format) {
 		int alternate, unlink_err;
+		struct list_head* p;
 		if (format == SNDRV_PCM_FORMAT_S24_3LE) {
 			alternate = 2;
 			usX2Y_stream->usX2Y->stride = 6;
@@ -1000,6 +1001,9 @@
 			alternate = 1;
 			usX2Y_stream->usX2Y->stride = 4;
 		}
+		list_for_each(p, &usX2Y_stream->usX2Y->chip.midi_list) {
+			snd_usbmidi_in_stop(p);
+		}
 		unlink_err = usb_unlink_urb(usX2Y_stream->usX2Y->In04urb);
 		if ((err = usb_set_interface(usX2Y_stream->usX2Y->chip.dev, 0, alternate))) {
 			snd_printk("usb_set_interface error \n");
@@ -1009,6 +1013,9 @@
 			usX2Y_stream->usX2Y->In04urb->dev = usX2Y_stream->usX2Y->chip.dev;
 			err = usb_submit_urb(usX2Y_stream->usX2Y->In04urb, GFP_KERNEL);
 		}
+		list_for_each(p, &usX2Y_stream->usX2Y->chip.midi_list) {
+			snd_usbmidi_in_start(p);
+		}
 		usX2Y_stream->usX2Y->format = format;
 		usX2Y_stream->usX2Y->rate = 0;
 	}

Index: alsa-kernel/usb/usbaudio.h
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usbaudio.h,v retrieving revision 1.31

usb/usbaudio.h +2 -0
diff -u -r1.31 usbaudio.h
@@ -206,6 +206,8 @@
 
 int snd_usb_create_midi_interface(snd_usb_audio_t *chip, struct usb_interface *iface, const snd_usb_audio_quirk_t *quirk);
 void snd_usbmidi_disconnect(struct list_head *p, struct usb_driver *driver);
+void snd_usbmidi_in_start(struct list_head* p);
+void snd_usbmidi_in_stop(struct list_head* p);
 
 /*
  * retrieve usb_interface descriptor from the host interface

Index: alsa-kernel/usb/usbmidi.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usbmidi.c,v retrieving revision 1.28

usb/usbmidi.c +38 -3

52 lines not on this page · raw message

#4 lore raw
Quoted 3 lines · Karsten Wiese

Am Montag 21 Juni 2004 10:30 schrieb Karsten Wiese:

Quoted 2 lines

It is impossible to use different interfaces on one usb_device at the same time. Or not?

On other devices, mixer / PCM output / PCM input / MIDI use one interface each, as mandated by the USB Audio specification.

Quoted 6 lines
Quoted 6 lines

Am Montag 21 Juni 2004 10:02 schrieb Clemens Ladisch:

Quoted 2 lines

And what should happen to data that is being output when the sample format is changed?

There was no out midi urb missed so far. It looks as if there is no special handling needed.

The data in the current URB, if there is one, will be silently dropped. Won't happen often, I guess.

usb/usbmidi.c line 1176

Quoted 4 lines
usb/usbmidi.c +4 -0
+void snd_usbmidi_in_start(struct list_head* p)
+void snd_usbmidi_in_stop(struct list_head* p)
+{
+       umidi = list_entry(p, snd_usb_midi_t, list);

Logically, these functions operate on a usb_midi structure/object, not on a list entry. AFAICS current pratice would put the list_entry() call int the list iteration loop (in the caller of these functions).

usb/usbmidi.c line 1259

Quoted 5 lines
        for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
usb/usbmidi.c +1 -3
-               if (umidi->endpoints[i].in)
-                       snd_usbmidi_submit_urb(umidi->endpoints[i].in->urb,
-                                              GFP_KERNEL);
+               snd_usbmidi_in_start_do(umidi->endpoints[i].in);

... and then the entire loop could be replaced by a call to snd_usbmidi_in_start().

Regards,
Clemens

-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND

#5 lore raw

Am Montag 21 Juni 2004 13:21 schrieb Clemens Ladisch:
<snip>

Quoted 11 lines

Logically, these functions operate on a usb_midi structure/object, not on a list entry. AFAICS current pratice would put the list_entry() call int the list iteration loop (in the caller of these functions).

Quoted 6 lines
        for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
(quoted diff) +0 -2
-               if (umidi->endpoints[i].in)
-                      

snd_usbmidi_submit_urb(umidi->endpoints[i].in->urb, -

                         GFP_KERNEL);

+ snd_usbmidi_in_start_do(umidi->endpoints[i].in);

Quoted 2 lines

.... and then the entire loop could be replaced by a call to snd_usbmidi_in_start().

I followed the model given by
snd_usb_audio_disconnect():
and
snd_usbmidi_disconnect()
If you change that, I'll change my patch ;-)
Though I'd vote against doing so, 'cause as things are, struct snd_usb_midi and the corresponding typedef may stay hidden in usbmidi.c.

Regards,
Karsten

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#6 lore raw
Quoted 10 lines · Karsten Wiese

Am Montag 21 Juni 2004 13:21 schrieb Clemens Ladisch:

Quoted 3 lines

Logically, these functions operate on a usb_midi structure/object, not on a list entry. AFAICS current pratice would put the list_entry() call int the list iteration loop (in the caller of these functions).

I followed the model given by
snd_usb_audio_disconnect():
and
snd_usbmidi_disconnect()
If you change that, I'll change my patch ;-)

Well, the USB driver as a whole isn't as modular as I'd like it to be, but just now I'm too lazy to rewrite the entire thing. :-)

Applied, with some minor changes.

Regards,
Clemens

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com