Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb change how to allocate xfer; alloc xfer when att...



details:   https://anonhg.NetBSD.org/src/rev/67938c278fca
branches:  trunk
changeset: 503241:67938c278fca
user:      tshiozak <tshiozak%NetBSD.org@localhost>
date:      Sat Feb 03 16:49:06 2001 +0000

description:
change how to allocate xfer; alloc xfer when attach and free xfer when detach.

diffstat:

 sys/dev/usb/umidi.c    |  252 +++++++++++++++++++++++++++++-------------------
 sys/dev/usb/umidivar.h |   21 +--
 2 files changed, 160 insertions(+), 113 deletions(-)

diffs (truncated from 567 to 300 lines):

diff -r 85a8d524d448 -r 67938c278fca sys/dev/usb/umidi.c
--- a/sys/dev/usb/umidi.c       Sat Feb 03 16:26:45 2001 +0000
+++ b/sys/dev/usb/umidi.c       Sat Feb 03 16:49:06 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umidi.c,v 1.2 2001/01/31 16:02:38 tshiozak Exp $       */
+/*     $NetBSD: umidi.c,v 1.3 2001/02/03 16:49:06 tshiozak Exp $       */
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -77,8 +77,8 @@
 static int umidi_output(void *, int);
 static void umidi_getinfo(void *, struct midi_info *);
 
-static usbd_status enable_an_endpoint(struct umidi_endpoint *);
-static void disable_an_endpoint(struct umidi_endpoint *, int);
+static usbd_status alloc_pipe(struct umidi_endpoint *);
+static void free_pipe(struct umidi_endpoint *);
 
 static usbd_status alloc_all_endpoints(struct umidi_softc *);
 static void free_all_endpoints(struct umidi_softc *);
@@ -143,16 +143,16 @@
        if (uaa->iface == NULL)
                return UMATCH_NONE;
 
-        if (umidi_search_quirk(uaa->vendor, uaa->product, uaa->ifaceno))
-                return UMATCH_IFACECLASS_IFACESUBCLASS;
+       if (umidi_search_quirk(uaa->vendor, uaa->product, uaa->ifaceno))
+               return UMATCH_IFACECLASS_IFACESUBCLASS;
 
        id = usbd_get_interface_descriptor(uaa->iface);
        if (id!=NULL && 
            id->bInterfaceClass==UICLASS_AUDIO &&
-            id->bInterfaceSubClass==UISUBCLASS_MIDISTREAM)
-                return UMATCH_IFACECLASS_IFACESUBCLASS;
+           id->bInterfaceSubClass==UISUBCLASS_MIDISTREAM)
+               return UMATCH_IFACECLASS_IFACESUBCLASS;
 
-        return UMATCH_NONE;
+       return UMATCH_NONE;
 }
 
 USB_ATTACH(umidi)
@@ -226,7 +226,7 @@
 int
 umidi_activate(device_ptr_t self, enum devact act)
 {
-        struct umidi_softc *sc = (struct umidi_softc *)self;
+       struct umidi_softc *sc = (struct umidi_softc *)self;
 
        switch (act) {
        case DVACT_ACTIVATE:
@@ -245,7 +245,7 @@
 
 USB_DETACH(umidi)
 {
-        USB_DETACH_START(umidi, sc);
+       USB_DETACH_START(umidi, sc);
 
        DPRINTFN(1,("umidi_detach\n"));
 
@@ -256,8 +256,8 @@
        free_all_jacks(sc);
        free_all_endpoints(sc);
 
-        usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
-                           USBDEV(sc->sc_dev));
+       usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
+                          USBDEV(sc->sc_dev));
 
        return 0;
 }
@@ -270,8 +270,8 @@
           void (*ointr)__P((void *)),
           void *arg)
 {
-        struct umidi_mididev *mididev = addr;
-        struct umidi_softc *sc = mididev->sc;
+       struct umidi_mididev *mididev = addr;
+       struct umidi_softc *sc = mididev->sc;
 
        DPRINTF(("umidi_open: sc=%p\n", sc));
 
@@ -289,8 +289,9 @@
        mididev->ointr = ointr;
        if ((mididev->flags & FWRITE) && mididev->out_jack)
                open_jack(mididev->out_jack);
-       if ((mididev->flags & FREAD) && mididev->in_jack)
+       if ((mididev->flags & FREAD) && mididev->in_jack) {
                open_jack(mididev->in_jack);
+       }
 
        return 0;
 }
@@ -299,7 +300,7 @@
 umidi_close(void *addr)
 {
        int s;
-        struct umidi_mididev *mididev = addr;
+       struct umidi_mididev *mididev = addr;
 
        s = splusb();
        if ((mididev->flags & FWRITE) && mididev->out_jack)
@@ -330,8 +331,8 @@
 int
 umidi_output(void *addr, int d)
 {
-        struct umidi_mididev *mididev = addr;
-        struct umidi_softc *sc = mididev->sc;
+       struct umidi_mididev *mididev = addr;
+       struct umidi_softc *sc = mididev->sc;
        struct umidi_jack *out_jack = mididev->out_jack;
        struct umidi_endpoint *ep;
        int error;
@@ -349,14 +350,19 @@
                case PS_END:
                        DPR_PACKET(out, sc, &out_jack->packet);
                        s = splusb();
-                       if (SIMPLEQ_EMPTY(&ep->queue)) {
+                       if (LIST_EMPTY(&ep->queue)) {
                                memcpy(ep->buffer,
                                       out_jack->packet.buffer,
                                       UMIDI_PACKET_SIZE);
                                start_output_transfer(ep);
                        }
-                       SIMPLEQ_INSERT_TAIL(&ep->queue,
-                                           out_jack, queue);
+                       if (LIST_EMPTY(&ep->queue))
+                               LIST_INSERT_HEAD(&ep->queue,
+                                                out_jack, queue);
+                       else
+                               LIST_INSERT_AFTER(ep->queue_tail,
+                                                 out_jack, queue);
+                       ep->queue_tail = out_jack;
                        splx(s);
                        break;
                default:
@@ -371,11 +377,11 @@
 void
 umidi_getinfo(void *addr, struct midi_info *mi)
 {
-        struct umidi_mididev *mididev = addr;
-//        struct umidi_softc *sc = mididev->sc;
+       struct umidi_mididev *mididev = addr;
+/*     struct umidi_softc *sc = mididev->sc; */
 
-        mi->name = "USB MIDI I/F";
-        mi->props = MIDI_PROP_OUT_INTR;
+       mi->name = "USB MIDI I/F"; /* XXX: model name */
+       mi->props = MIDI_PROP_OUT_INTR;
        if (mididev->in_jack)
                mi->props |= MIDI_PROP_CAN_INPUT;
 }
@@ -383,50 +389,40 @@
 
 /* --- */
 
-/* enable/disable to transfer */
+/* alloc/free pipe */
 static usbd_status
-enable_an_endpoint(struct umidi_endpoint *ep)
+alloc_pipe(struct umidi_endpoint *ep)
 {
        struct umidi_softc *sc = ep->sc;
        usbd_status err;
 
-       if (!ep->num_open++) {
-               DPRINTF(("%s: enable_an_endpoint %p\n",
-                        USBDEVNAME(sc->sc_dev), ep));
-               SIMPLEQ_INIT(&ep->queue);
-               ep->xfer = usbd_alloc_xfer(sc->sc_udev);
-               if (!ep->xfer) {
-                       err = USBD_NOMEM;
-                       goto quit;
-               }
-               ep->buffer = usbd_alloc_buffer(ep->xfer, UMIDI_PACKET_SIZE);
-               if (!ep->buffer) {
-                       usbd_free_xfer(ep->xfer);
-                       err = USBD_NOMEM;
-                       goto quit;
-               }
-               err = usbd_open_pipe(sc->sc_iface, ep->addr, 0, &ep->pipe);
-               if (err) {
-                       usbd_free_xfer(ep->xfer);
-                       goto quit;
-               }
+       DPRINTF(("%s: alloc_pipe %p\n", USBDEVNAME(sc->sc_dev), ep));
+       LIST_INIT(&ep->queue);
+       ep->xfer = usbd_alloc_xfer(sc->sc_udev);
+       if (!ep->xfer) {
+           err = USBD_NOMEM;
+           goto quit;
        }
+       ep->buffer = usbd_alloc_buffer(ep->xfer, UMIDI_PACKET_SIZE);
+       if (!ep->buffer) {
+           usbd_free_xfer(ep->xfer);
+           err = USBD_NOMEM;
+           goto quit;
+       }
+       err = usbd_open_pipe(sc->sc_iface, ep->addr, 0, &ep->pipe);
+       if (err)
+           usbd_free_xfer(ep->xfer);
 quit:
        return err;
 }
 
 static void
-disable_an_endpoint(struct umidi_endpoint *ep, int force)
+free_pipe(struct umidi_endpoint *ep)
 {
-       if (force || (ep->num_open>0 && !--ep->num_open)) {
-               ep->num_open = 0;
-               usbd_abort_pipe(ep->pipe);
-               usbd_clear_endpoint_stall(ep->pipe);
-               usbd_close_pipe(ep->pipe);
-               usbd_free_xfer(ep->xfer);
-               DPRINTF(("%s: disable_an_endpoint %p\n",
-                        USBDEVNAME(ep->sc->sc_dev), ep));
-       }
+       DPRINTF(("%s: free_pipe %p\n", USBDEVNAME(ep->sc->sc_dev), ep));
+       usbd_abort_pipe(ep->pipe);
+       usbd_close_pipe(ep->pipe);
+       usbd_free_xfer(ep->xfer);
 }
 
 
@@ -439,19 +435,39 @@
 static usbd_status
 alloc_all_endpoints(struct umidi_softc *sc)
 {
-        if (UMQ_ISTYPE(sc, UMQ_TYPE_FIXED_EP)) {
-               return alloc_all_endpoints_fixed_ep(sc);
-        } else if (UMQ_ISTYPE(sc, UMQ_TYPE_YAMAHA)) {
-               return alloc_all_endpoints_yamaha(sc);
+       usbd_status err;
+       struct umidi_endpoint *ep;
+       int i;
+       if (UMQ_ISTYPE(sc, UMQ_TYPE_FIXED_EP)) {
+               err = alloc_all_endpoints_fixed_ep(sc);
+       } else if (UMQ_ISTYPE(sc, UMQ_TYPE_YAMAHA)) {
+               err = alloc_all_endpoints_yamaha(sc);
        } else {
-               return alloc_all_endpoints_genuine(sc);
+               err = alloc_all_endpoints_genuine(sc);
        }
+       if (err!=USBD_NORMAL_COMPLETION)
+               return err;
+
+       ep = sc->sc_endpoints;
+       for (i=sc->sc_out_num_jacks+sc->sc_in_num_jacks; i>0; i--) {
+               err = alloc_pipe(ep++);
+               if (err!=USBD_NORMAL_COMPLETION) {
+                       for (; ep!=sc->sc_endpoints; ep--)
+                               free_pipe(ep-1);
+                       free(sc->sc_endpoints, M_USBDEV);
+                       sc->sc_endpoints = sc->sc_out_ep = sc->sc_in_ep = NULL;
+                       break;
+               }
+       }
+       return err;
 }
 
 static void
 free_all_endpoints(struct umidi_softc *sc)
 {
-       /* assumes that all endpoints are disabled. */
+       int i;
+       for (i=0; i<sc->sc_in_num_jacks+sc->sc_out_num_jacks; i++)
+           free_pipe(&sc->sc_endpoints[i]);
        free(sc->sc_endpoints, M_USBDEV);
        sc->sc_endpoints = sc->sc_out_ep = sc->sc_in_ep = NULL;
 }
@@ -459,7 +475,9 @@
 static usbd_status
 alloc_all_endpoints_fixed_ep(struct umidi_softc *sc)
 {
+       usbd_status err;
        struct umq_fixed_ep_desc *fp;
+       struct umidi_endpoint *ep;
        usb_endpoint_descriptor_t *epd;
        int i;
 
@@ -480,6 +498,8 @@
        sc->sc_in_ep =
            sc->sc_in_num_endpoints ?
                sc->sc_endpoints+sc->sc_out_num_endpoints : NULL;
+
+       ep = &sc->sc_out_ep[0];
        for (i=0; i<sc->sc_out_num_endpoints; i++) {
                epd = usbd_interface2endpoint_descriptor(
                        sc->sc_iface,
@@ -487,22 +507,26 @@
                if (!epd) {
                        printf("%s: cannot get endpoint descriptor(out:%d)\n",
                               USBDEVNAME(sc->sc_dev), fp->out_ep[i].ep);
+                       err = USBD_INVAL;
                        goto error;
                }
                if (UE_GET_XFERTYPE(epd->bmAttributes)!=UE_BULK ||
                    UE_GET_DIR(epd->bEndpointAddress)!=UE_DIR_OUT) {
                        printf("%s: illegal endpoint(out:%d)\n",



Home | Main Index | Thread Index | Old Index