On Sat, Mar 23, 2024 at 09:50:20AM +0100, vazub wrote:
> On Sat, 23 Mar 2024, at 07:45, Alexandre Ratchov wrote:
> > which is missing for this device. Maybe another driver has claimed the
> > audio interface?
> >
> > There is one uhidev(4) interface before uaudio, but I see no calls to
> > usbd_claim_iface() in the uhidev(4) driver.
> 
> The other uaudio device connected at the same time was a webcam. Here is an 
> excerpt of the dmesg output, with the webcam detached, so there is only RODE 
> interface present for the uaudio to setup.
> 

Thank you for all the information. There's confusion between the
interface number and the interface index. For most devices, they are
the same, but not for yours.

Could you try this diff please?
(with UAUDIO_DEBUG enabled)

Index: uaudio.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/uaudio.c,v
diff -u -p -r1.174 uaudio.c
--- uaudio.c    10 Dec 2023 06:32:14 -0000      1.174
+++ uaudio.c    23 Mar 2024 09:30:33 -0000
@@ -2702,6 +2702,22 @@ uaudio_fixup_params(struct uaudio_softc 
        }
 }
 
+int
+uaudio_iface_index(struct uaudio_softc *sc, int ifnum)
+{
+       int i, nifaces;
+
+       nifaces = sc->udev->cdesc->bNumInterfaces;
+
+       for (i = 0; i < nifaces; i++) {
+               if (sc->udev->ifaces[i].idesc->bInterfaceNumber == ifnum)
+                       return i;
+       }
+
+       printf("%s: %d: invalid interface number\n", __func__, ifnum);
+       return -1;
+}
+
 /*
  * Parse all descriptors and build configuration of the device.
  */
@@ -2711,6 +2727,7 @@ uaudio_process_conf(struct uaudio_softc 
        struct uaudio_blob dp;
        struct uaudio_alt *a;
        unsigned int type, ifnum, altnum, nep, class, subclass;
+       int i;
 
        while (p->rptr != p->wptr) {
                if (!uaudio_getdesc(p, &dp))
@@ -2736,7 +2753,8 @@ uaudio_process_conf(struct uaudio_softc 
 
                switch (subclass) {
                case UISUBCLASS_AUDIOCONTROL:
-                       if (usbd_iface_claimed(sc->udev, ifnum)) {
+                       i = uaudio_iface_index(sc, ifnum);
+                       if (i != -1 && usbd_iface_claimed(sc->udev, i)) {
                                DPRINTF("%s: %d: AC already claimed\n", 
__func__, ifnum);
                                break;
                        }
@@ -2748,7 +2766,8 @@ uaudio_process_conf(struct uaudio_softc 
                                return 0;
                        break;
                case UISUBCLASS_AUDIOSTREAM:
-                       if (usbd_iface_claimed(sc->udev, ifnum)) {
+                       i = uaudio_iface_index(sc, ifnum);
+                       if (i != -1 && usbd_iface_claimed(sc->udev, i)) {
                                DPRINTF("%s: %d: AS already claimed\n", 
__func__, ifnum);
                                break;
                        }
@@ -2768,10 +2787,19 @@ done:
         * Claim all interfaces we use. This prevents other uaudio(4)
         * devices from trying to use them.
         */
-       for (a = sc->alts; a != NULL; a = a->next)
-               usbd_claim_iface(sc->udev, a->ifnum);
+       for (a = sc->alts; a != NULL; a = a->next) {
+               i = uaudio_iface_index(sc, a->ifnum);
+               if (i != -1) {
+                       DPRINTF("%s: claim: %d at %d\n", __func__, a->ifnum, i);
+                       usbd_claim_iface(sc->udev, i);
+               }
+       }
 
-       usbd_claim_iface(sc->udev, sc->ctl_ifnum);
+       i = uaudio_iface_index(sc, sc->ctl_ifnum);
+       if (i != -1) {
+               DPRINTF("%s: claim: ac %d at %d\n", __func__, sc->ctl_ifnum, i);
+               usbd_claim_iface(sc->udev, i);
+       }
 
        return 1;
 }

Reply via email to