Source-Changes-HG archive

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

[src/nick-nhusb]: src/sys/dev/usb WIP ucom support for devices with interrupt...



details:   https://anonhg.NetBSD.org/src/rev/68971dba1806
branches:  nick-nhusb
changeset: 804656:68971dba1806
user:      skrll <skrll%NetBSD.org@localhost>
date:      Mon May 30 06:54:17 2016 +0000

description:
WIP ucom support for devices with interrupt endpoints like umct

diffstat:

 sys/dev/usb/ucom.c    |  133 +++++++++++++++++++++++++++++++------------------
 sys/dev/usb/ucomvar.h |    8 ++-
 sys/dev/usb/umct.c    |   49 ++++++++++++++----
 3 files changed, 129 insertions(+), 61 deletions(-)

diffs (truncated from 370 to 300 lines):

diff -r 3380bed3f4f9 -r 68971dba1806 sys/dev/usb/ucom.c
--- a/sys/dev/usb/ucom.c        Mon May 30 06:51:21 2016 +0000
+++ b/sys/dev/usb/ucom.c        Mon May 30 06:54:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ucom.c,v 1.108.2.14 2016/05/29 08:44:31 skrll Exp $    */
+/*     $NetBSD: ucom.c,v 1.108.2.15 2016/05/30 06:54:17 skrll Exp $    */
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.108.2.14 2016/05/29 08:44:31 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.108.2.15 2016/05/30 06:54:17 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -158,6 +158,11 @@
        SIMPLEQ_HEAD(, ucom_buffer) sc_obuff_free;
        SIMPLEQ_HEAD(, ucom_buffer) sc_obuff_full;
 
+       struct usbd_pipe        *sc_ipipe;
+       struct usbd_xfer        *sc_ixfer;
+       struct usbd_pipe        *sc_opipe;
+       struct usbd_xfer        *sc_oxfer;
+
        void                    *sc_si;
 
        const struct ucom_methods *sc_methods;
@@ -224,7 +229,6 @@
 static void    tiocm_to_ucom(struct ucom_softc *, u_long, int);
 static int     ucom_to_tiocm(struct ucom_softc *);
 
-static void    ucomreadcb(struct usbd_xfer *, void *, usbd_status);
 static void    ucom_submit_write(struct ucom_softc *, struct ucom_buffer *);
 static void    ucom_write_status(struct ucom_softc *, struct ucom_buffer *,
                        usbd_status);
@@ -264,6 +268,9 @@
        prop_dictionary_set_int32(device_properties(self), "port",
            ucaa->ucaa_portno);
 
+       KASSERT(ucaa->ucaa_bulkin != -1 || (ucaa->ucaa_ipipe && ucaa->ucaa_ixfer));
+       KASSERT(ucaa->ucaa_bulkout != -1 || (ucaa->ucaa_opipe && ucaa->ucaa_oxfer));
+
        sc->sc_dev = self;
        sc->sc_udev = ucaa->ucaa_device;
        sc->sc_iface = ucaa->ucaa_iface;
@@ -307,41 +314,57 @@
        usbd_status err;
        int error;
 
-       /* Open the bulk pipes */
-       err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkin_no,
-           USBD_EXCLUSIVE_USE, &sc->sc_bulkin_pipe);
-       if (err) {
-               DPRINTF("open bulk in error (addr %d), err=%d",
-                   sc->sc_bulkin_no, err, 0, 0);
-               error = EIO;
-               goto fail_0;
-       }
-       err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkout_no,
-           USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
-       if (err) {
-               DPRINTF("open bulk out error (addr %d), err=%d",
-                   sc->sc_bulkout_no, err, 0, 0);
-               error = EIO;
-               goto fail_1;
+       if (sc->sc_bulkin_no != -1) {
+               /* Open the bulk pipes */
+               err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkin_no,
+                   USBD_EXCLUSIVE_USE, &sc->sc_bulkin_pipe);
+               if (err) {
+                       DPRINTF("open bulk in error (addr %d), err=%d",
+                           sc->sc_bulkin_no, err, 0, 0);
+                       error = EIO;
+                       goto fail_0;
+               }
+               /* Allocate input buffers */
+               for (ub = &sc->sc_ibuff[0]; ub != &sc->sc_ibuff[UCOM_IN_BUFFS];
+                   ub++) {
+                       error = usbd_create_xfer(sc->sc_bulkin_pipe,
+                           sc->sc_ibufsizepad, USBD_SHORT_XFER_OK, 0,
+                           &ub->ub_xfer);
+                       if (error)
+                               goto fail_1;
+                       ub->ub_data = usbd_get_buffer(ub->ub_xfer);
+               }
+
        }
 
-       /* Allocate input buffers */
-       for (ub = &sc->sc_ibuff[0]; ub != &sc->sc_ibuff[UCOM_IN_BUFFS];
-           ub++) {
-               error = usbd_create_xfer(sc->sc_bulkin_pipe, sc->sc_ibufsizepad,
-                   USBD_SHORT_XFER_OK, 0, &ub->ub_xfer);
-               if (error)
-                       goto fail_2;
-               ub->ub_data = usbd_get_buffer(ub->ub_xfer);
+       if (sc->sc_bulkout_no != -1) {
+               err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkout_no,
+                   USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
+               if (err) {
+                       DPRINTF("open bulk out error (addr %d), err=%d",
+                           sc->sc_bulkout_no, err, 0, 0);
+                       error = EIO;
+                       goto fail_1;
+               }
+               for (ub = &sc->sc_obuff[0]; ub != &sc->sc_obuff[UCOM_OUT_BUFFS];
+                   ub++) {
+                       error = usbd_create_xfer(sc->sc_bulkout_pipe,
+                           sc->sc_obufsize, 0, 0, &ub->ub_xfer);
+                       if (error)
+                               goto fail_2;
+                       ub->ub_data = usbd_get_buffer(ub->ub_xfer);
+                       SIMPLEQ_INSERT_TAIL(&sc->sc_obuff_free, ub, ub_link);
+               }
        }
 
-       for (ub = &sc->sc_obuff[0]; ub != &sc->sc_obuff[UCOM_OUT_BUFFS];
-           ub++) {
-               error = usbd_create_xfer(sc->sc_bulkout_pipe, sc->sc_obufsize,
-                   0, 0, &ub->ub_xfer);
-               if (error)
-                       goto fail_2;
-               ub->ub_data = usbd_get_buffer(ub->ub_xfer);
+       if (sc->sc_ipipe && sc->sc_ixfer) {
+               ub = &sc->sc_ibuff[0];
+               ub->ub_data = usbd_get_buffer(sc->sc_ixfer);
+               SIMPLEQ_INSERT_TAIL(&sc->sc_ibuff_empty, ub, ub_link);
+       }
+       if (sc->sc_opipe && sc->sc_oxfer) {
+               ub = &sc->sc_obuff[0];
+               ub->ub_data = usbd_get_buffer(sc->sc_oxfer);
                SIMPLEQ_INSERT_TAIL(&sc->sc_obuff_free, ub, ub_link);
        }
 
@@ -362,18 +385,20 @@
        return;
 
 fail_2:
-       for (ub = &sc->sc_ibuff[0]; ub != &sc->sc_ibuff[UCOM_IN_BUFFS];
-           ub++) {
-               if (ub->ub_xfer)
-                       usbd_destroy_xfer(ub->ub_xfer);
-       }
        for (ub = &sc->sc_obuff[0]; ub != &sc->sc_obuff[UCOM_OUT_BUFFS];
            ub++) {
                if (ub->ub_xfer)
                        usbd_destroy_xfer(ub->ub_xfer);
        }
 
+       usbd_close_pipe(sc->sc_bulkout_pipe);
+
 fail_1:
+       for (ub = &sc->sc_ibuff[0]; ub != &sc->sc_ibuff[UCOM_IN_BUFFS];
+           ub++) {
+               if (ub->ub_xfer)
+                       usbd_destroy_xfer(ub->ub_xfer);
+       }
        usbd_close_pipe(sc->sc_bulkin_pipe);
 
 fail_0:
@@ -620,6 +645,9 @@
                sc->sc_rx_stopped = 0;
                sc->sc_tx_stopped = 0;
 
+               /*
+                * ucomsubmitread handles bulk vs other
+                */
                for (ub = &sc->sc_ibuff[0]; ub != &sc->sc_ibuff[UCOM_IN_BUFFS];
                    ub++) {
                        if (ucomsubmitread(sc, ub) != USBD_NORMAL_COMPLETION) {
@@ -643,8 +671,10 @@
        return 0;
 
 fail_2:
-       usbd_abort_pipe(sc->sc_bulkin_pipe);
-       usbd_abort_pipe(sc->sc_bulkout_pipe);
+       if (sc->sc_bulkin_no != -1)
+               usbd_abort_pipe(sc->sc_bulkin_pipe);
+       if (sc->sc_bulkout_no != -1)
+               usbd_abort_pipe(sc->sc_bulkout_pipe);
 
        mutex_enter(&sc->sc_lock);
        sc->sc_opening = 0;
@@ -1381,13 +1411,15 @@
 {
        usbd_status err;
 
-       usbd_setup_xfer(ub->ub_xfer, sc, ub->ub_data, sc->sc_ibufsize,
-           USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, ucomreadcb);
+       if (sc->sc_bulkin_no != -1) {
+               usbd_setup_xfer(ub->ub_xfer, sc, ub->ub_data, sc->sc_ibufsize,
+                   USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, ucomreadcb);
 
-       if ((err = usbd_transfer(ub->ub_xfer)) != USBD_IN_PROGRESS) {
-               /* XXX: Recover from this, please! */
-               printf("ucomsubmitread: err=%s\n", usbd_errstr(err));
-               return err;
+               if ((err = usbd_transfer(ub->ub_xfer)) != USBD_IN_PROGRESS) {
+                       /* XXX: Recover from this, please! */
+                       printf("%s: err=%s\n", __func__, usbd_errstr(err));
+                       return err;
+               }
        }
 
        SIMPLEQ_INSERT_TAIL(&sc->sc_ibuff_empty, ub, ub_link);
@@ -1395,7 +1427,7 @@
        return USBD_NORMAL_COMPLETION;
 }
 
-static void
+void
 ucomreadcb(struct usbd_xfer *xfer, void *p, usbd_status status)
 {
        struct ucom_softc *sc = (struct ucom_softc *)p;
@@ -1426,7 +1458,10 @@
        SIMPLEQ_REMOVE_HEAD(&sc->sc_ibuff_empty, ub_link);
 
        if (status == USBD_STALLED) {
-               usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
+               if (sc->sc_bulkin_no != -1)
+                       usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
+               if (sc->sc_ipipe)
+                       usbd_clear_endpoint_stall_async(sc->sc_ipipe);
                ucomsubmitread(sc, ub);
                mutex_exit(&sc->sc_lock);
                return;
diff -r 3380bed3f4f9 -r 68971dba1806 sys/dev/usb/ucomvar.h
--- a/sys/dev/usb/ucomvar.h     Mon May 30 06:51:21 2016 +0000
+++ b/sys/dev/usb/ucomvar.h     Mon May 30 06:54:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ucomvar.h,v 1.20.24.4 2016/04/16 13:22:00 skrll Exp $  */
+/*     $NetBSD: ucomvar.h,v 1.20.24.5 2016/05/30 06:54:17 skrll Exp $  */
 
 /*
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -93,6 +93,10 @@
        int ucaa_portno;
        int ucaa_bulkin;
        int ucaa_bulkout;
+       struct usbd_xfer *ucaa_ixfer;
+       struct usbd_pipe *ucaa_ipipe;
+       struct usbd_xfer *ucaa_oxfer;
+       struct usbd_pipe *ucaa_opipe;
        u_int ucaa_ibufsize;
        u_int ucaa_ibufsizepad;
        u_int ucaa_obufsize;
@@ -107,3 +111,5 @@
 int ucomprint(void *, const char *);
 int ucomsubmatch(device_t t, cfdata_t, const int *, void *);
 void ucom_status_change(struct ucom_softc *);
+void ucomreadcb(struct usbd_xfer *, void *, usbd_status);
+
diff -r 3380bed3f4f9 -r 68971dba1806 sys/dev/usb/umct.c
--- a/sys/dev/usb/umct.c        Mon May 30 06:51:21 2016 +0000
+++ b/sys/dev/usb/umct.c        Mon May 30 06:54:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umct.c,v 1.32.24.12 2016/04/16 13:30:35 skrll Exp $    */
+/*     $NetBSD: umct.c,v 1.32.24.13 2016/05/30 06:54:17 skrll Exp $    */
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umct.c,v 1.32.24.12 2016/04/16 13:30:35 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umct.c,v 1.32.24.13 2016/05/30 06:54:17 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -74,13 +74,17 @@
 
 struct umct_softc {
        device_t                sc_dev;         /* base device */
-       struct usbd_device *    sc_udev;        /* USB device */
-       struct usbd_interface * sc_iface;       /* interface */
+       struct usbd_device      *sc_udev;       /* USB device */
+       struct usbd_interface   *sc_iface;      /* interface */
        int                     sc_iface_number;        /* interface number */
        uint16_t                sc_product;
 
+       int                     sc_inendpt;     /* data in endpoint */
+       struct usbd_pipe        *sc_inpipe;     /* data in pipe */
+       u_char                  *sc_inbuf;      /* interrupt buffer */
+
        int                     sc_intr_number; /* interrupt number */
-       struct usbd_pipe *      sc_intr_pipe;   /* interrupt pipe */
+       struct usbd_pipe        *sc_intr_pipe;  /* interrupt pipe */
        u_char                  *sc_intr_buf;   /* interrupt buffer */
        int                     sc_isize;
 
@@ -113,6 +117,8 @@
 Static void umct_set_lcr(struct umct_softc *, u_int);
 Static void umct_intr(struct usbd_xfer *, void *, usbd_status);
 
+Static void umct_rxintr(struct usbd_xfer *, void *, usbd_status);
+



Home | Main Index | Thread Index | Old Index