Source-Changes-HG archive

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

[src/netbsd-2]: src/sys/dev/usb Pull up revisions 1.47-1.52 (requested by ito...



details:   https://anonhg.NetBSD.org/src/rev/8f6ce383bcf6
branches:  netbsd-2
changeset: 563813:8f6ce383bcf6
user:      riz <riz%NetBSD.org@localhost>
date:      Thu Jul 21 19:26:39 2005 +0000

description:
Pull up revisions 1.47-1.52 (requested by itohy in ticket #1430):
1.47:
use bounded string ops (snprintf, strl*)

1.48:
a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"

1.49:
Use new functions for getting descriptors.

1.50:
Allow multiple modem interfaces per configuration.

1.51:
Split common modem part of umodem.c to umodem_common.c and umodemvar.h,
to be shared with other umodem-like drivers.

1.52:
If CM descriptor is found, use the data interface in it;
if CM descriptor is NOT found but UNION descriotor is found,
use the data interface in it.
Do not require CM or ACM descriptors as long as
the data interface is found.
Should fix NetBSD PR #29754 by rivo nurges.

diffstat:

 sys/dev/usb/umodem.c |  626 +-------------------------------------------------
 1 files changed, 15 insertions(+), 611 deletions(-)

diffs (truncated from 686 to 300 lines):

diff -r 3b7b9581bbea -r 8f6ce383bcf6 sys/dev/usb/umodem.c
--- a/sys/dev/usb/umodem.c      Thu Jul 21 19:26:37 2005 +0000
+++ b/sys/dev/usb/umodem.c      Thu Jul 21 19:26:39 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umodem.c,v 1.46 2003/11/07 17:03:25 wiz Exp $  */
+/*     $NetBSD: umodem.c,v 1.46.4.1 2005/07/21 19:26:39 riz Exp $      */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -51,7 +51,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umodem.c,v 1.46 2003/11/07 17:03:25 wiz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umodem.c,v 1.46.4.1 2005/07/21 19:26:39 riz Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -76,6 +76,7 @@
 
 #include <dev/usb/usbdevs.h>
 #include <dev/usb/ucomvar.h>
+#include <dev/usb/umodemvar.h>
 
 #ifdef UMODEM_DEBUG
 #define DPRINTFN(n, x) if (umodemdebug > (n)) logprintf x
@@ -85,65 +86,6 @@
 #endif
 #define DPRINTF(x) DPRINTFN(0, x)
 
-/*
- * These are the maximum number of bytes transferred per frame.
- * If some really high speed devices should use this driver they
- * may need to be increased, but this is good enough for normal modems.
- */
-#define UMODEMIBUFSIZE 64
-#define UMODEMOBUFSIZE 256
-
-struct umodem_softc {
-       USBBASEDEVICE           sc_dev;         /* base device */
-
-       usbd_device_handle      sc_udev;        /* USB device */
-
-       int                     sc_ctl_iface_no;
-       usbd_interface_handle   sc_ctl_iface;   /* control interface */
-       int                     sc_data_iface_no;
-       usbd_interface_handle   sc_data_iface;  /* data interface */
-
-       int                     sc_cm_cap;      /* CM capabilities */
-       int                     sc_acm_cap;     /* ACM capabilities */
-
-       int                     sc_cm_over_data;
-
-       usb_cdc_line_state_t    sc_line_state;  /* current line state */
-       u_char                  sc_dtr;         /* current DTR state */
-       u_char                  sc_rts;         /* current RTS state */
-
-       device_ptr_t            sc_subdev;      /* ucom device */
-
-       u_char                  sc_opening;     /* lock during open */
-       u_char                  sc_dying;       /* disconnecting */
-
-       int                     sc_ctl_notify;  /* Notification endpoint */
-       usbd_pipe_handle        sc_notify_pipe; /* Notification pipe */
-       usb_cdc_notification_t  sc_notify_buf;  /* Notification structure */
-       u_char                  sc_lsr;         /* Local status register */
-       u_char                  sc_msr;         /* Modem status register */
-};
-
-Static void    *umodem_get_desc(usbd_device_handle dev, int type, int subtype);
-Static usbd_status umodem_set_comm_feature(struct umodem_softc *sc,
-                                          int feature, int state);
-Static usbd_status umodem_set_line_coding(struct umodem_softc *sc,
-                                         usb_cdc_line_state_t *state);
-
-Static void    umodem_get_caps(usbd_device_handle, int *, int *);
-
-Static void    umodem_get_status(void *, int portno, u_char *lsr, u_char *msr);
-Static void    umodem_set(void *, int, int, int);
-Static void    umodem_dtr(struct umodem_softc *, int);
-Static void    umodem_rts(struct umodem_softc *, int);
-Static void    umodem_break(struct umodem_softc *, int);
-Static void    umodem_set_line_state(struct umodem_softc *);
-Static int     umodem_param(void *, int, struct termios *);
-Static int     umodem_ioctl(void *, int, u_long, caddr_t, int, usb_proc_ptr );
-Static int     umodem_open(void *, int portno);
-Static void    umodem_close(void *, int portno);
-Static void    umodem_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
-
 Static struct ucom_methods umodem_methods = {
        umodem_get_status,
        umodem_set,
@@ -173,10 +115,7 @@
            id->bInterfaceProtocol != UIPROTO_CDC_AT)
                return (UMATCH_NONE);
 
-       umodem_get_caps(uaa->device, &cm, &acm);
-       if (!(cm & USB_CDC_CM_DOES_CM) ||
-           !(cm & USB_CDC_CM_OVER_DATA) ||
-           !(acm & USB_CDC_ACM_HAS_LINE))
+       if (umodem_get_caps(uaa->device, &cm, &acm, id) == -1)
                return (UMATCH_NONE);
 
        return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
@@ -185,570 +124,35 @@
 USB_ATTACH(umodem)
 {
        USB_ATTACH_START(umodem, sc, uaa);
-       usbd_device_handle dev = uaa->device;
-       usb_interface_descriptor_t *id;
-       usb_endpoint_descriptor_t *ed;
-       usb_cdc_cm_descriptor_t *cmd;
-       char devinfo[1024];
-       usbd_status err;
-       int data_ifcno;
-       int i;
        struct ucom_attach_args uca;
 
-       usbd_devinfo(uaa->device, 0, devinfo);
-       USB_ATTACH_SETUP;
-
-       sc->sc_udev = dev;
-       sc->sc_ctl_iface = uaa->iface;
-
-       id = usbd_get_interface_descriptor(sc->sc_ctl_iface);
-       printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
-              devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
-       sc->sc_ctl_iface_no = id->bInterfaceNumber;
-
-       umodem_get_caps(dev, &sc->sc_cm_cap, &sc->sc_acm_cap);
-
-       /* Get the data interface no. */
-       cmd = umodem_get_desc(dev, UDESC_CS_INTERFACE, UDESCSUB_CDC_CM);
-       if (cmd == NULL) {
-               printf("%s: no CM descriptor\n", USBDEVNAME(sc->sc_dev));
-               goto bad;
-       }
-       sc->sc_data_iface_no = data_ifcno = cmd->bDataInterface;
-
-       printf("%s: data interface %d, has %sCM over data, has %sbreak\n",
-              USBDEVNAME(sc->sc_dev), data_ifcno,
-              sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ",
-              sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no ");
-
-       /* Get the data interface too. */
-       for (i = 0; i < uaa->nifaces; i++) {
-               if (uaa->ifaces[i] != NULL) {
-                       id = usbd_get_interface_descriptor(uaa->ifaces[i]);
-                       if (id != NULL && id->bInterfaceNumber == data_ifcno) {
-                               sc->sc_data_iface = uaa->ifaces[i];
-                               uaa->ifaces[i] = NULL;
-                       }
-               }
-       }
-       if (sc->sc_data_iface == NULL) {
-               printf("%s: no data interface\n", USBDEVNAME(sc->sc_dev));
-               goto bad;
-       }
-
-       /*
-        * Find the bulk endpoints.
-        * Iterate over all endpoints in the data interface and take note.
-        */
-       uca.bulkin = uca.bulkout = -1;
-
-       id = usbd_get_interface_descriptor(sc->sc_data_iface);
-       for (i = 0; i < id->bNumEndpoints; i++) {
-               ed = usbd_interface2endpoint_descriptor(sc->sc_data_iface, i);
-               if (ed == NULL) {
-                       printf("%s: no endpoint descriptor for %d\n",
-                               USBDEVNAME(sc->sc_dev), i);
-                       goto bad;
-               }
-               if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
-                   (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
-                        uca.bulkin = ed->bEndpointAddress;
-                } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
-                          (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
-                        uca.bulkout = ed->bEndpointAddress;
-                }
-        }
-
-       if (uca.bulkin == -1) {
-               printf("%s: Could not find data bulk in\n",
-                      USBDEVNAME(sc->sc_dev));
-               goto bad;
-       }
-       if (uca.bulkout == -1) {
-               printf("%s: Could not find data bulk out\n",
-                       USBDEVNAME(sc->sc_dev));
-               goto bad;
-       }
-
-       if (usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_ASSUME_CM_OVER_DATA) {
-               sc->sc_cm_over_data = 1;
-       } else {
-               if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) {
-                       if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE)
-                               err = umodem_set_comm_feature(sc,
-                                   UCDC_ABSTRACT_STATE, UCDC_DATA_MULTIPLEXED);
-                       else
-                               err = 0;
-                       if (err) {
-                               printf("%s: could not set data multiplex mode\n",
-                                      USBDEVNAME(sc->sc_dev));
-                               goto bad;
-                       }
-                       sc->sc_cm_over_data = 1;
-               }
-       }
-
-       /*
-        * The standard allows for notification messages (to indicate things
-        * like a modem hangup) to come in via an interrupt endpoint
-        * off of the control interface.  Iterate over the endpoints on
-        * the control interface and see if there are any interrupt
-        * endpoints; if there are, then register it.
-        */
-
-       sc->sc_ctl_notify = -1;
-       sc->sc_notify_pipe = NULL;
-
-       for (i = 0; i < id->bNumEndpoints; i++) {
-               ed = usbd_interface2endpoint_descriptor(sc->sc_ctl_iface, i);
-               if (ed == NULL)
-                       continue;
-
-               if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
-                   (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
-                       printf("%s: status change notification available\n",
-                              USBDEVNAME(sc->sc_dev));
-                       sc->sc_ctl_notify = ed->bEndpointAddress;
-               }
-       }
-
-       sc->sc_dtr = -1;
-
        uca.portno = UCOM_UNK_PORTNO;
-       /* bulkin, bulkout set above */
-       uca.ibufsize = UMODEMIBUFSIZE;
-       uca.obufsize = UMODEMOBUFSIZE;
-       uca.ibufsizepad = UMODEMIBUFSIZE;
-       uca.opkthdrlen = 0;
-       uca.device = sc->sc_udev;
-       uca.iface = sc->sc_data_iface;
        uca.methods = &umodem_methods;
-       uca.arg = sc;
        uca.info = NULL;
 
-       usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
-                          USBDEV(sc->sc_dev));
-
-       DPRINTF(("umodem_attach: sc=%p\n", sc));
-       sc->sc_subdev = config_found_sm(self, &uca, ucomprint, ucomsubmatch);
-
+       if (umodem_common_attach(self, sc, uaa, &uca))
+               USB_ATTACH_ERROR_RETURN;
        USB_ATTACH_SUCCESS_RETURN;
-
- bad:
-       sc->sc_dying = 1;
-       USB_ATTACH_ERROR_RETURN;
-}
-
-Static int
-umodem_open(void *addr, int portno)
-{
-       struct umodem_softc *sc = addr;
-       int err;
-
-       DPRINTF(("umodem_open: sc=%p\n", sc));
-
-       if (sc->sc_ctl_notify != -1 && sc->sc_notify_pipe == NULL) {
-               err = usbd_open_pipe_intr(sc->sc_ctl_iface, sc->sc_ctl_notify,
-                   USBD_SHORT_XFER_OK, &sc->sc_notify_pipe, sc,
-                   &sc->sc_notify_buf, sizeof(sc->sc_notify_buf),
-                   umodem_intr, USBD_DEFAULT_INTERVAL);
-
-               if (err) {
-                       DPRINTF(("Failed to establish notify pipe: %s\n",
-                               usbd_errstr(err)));
-                       return EIO;
-               }
-       }
-
-       return 0;
-}
-
-Static void
-umodem_close(void *addr, int portno)
-{
-       struct umodem_softc *sc = addr;
-       int err;
-
-       DPRINTF(("umodem_close: sc=%p\n", sc));
-
-       if (sc->sc_notify_pipe != NULL) {
-               err = usbd_abort_pipe(sc->sc_notify_pipe);
-               if (err)
-                       printf("%s: abort notify pipe failed: %s\n",



Home | Main Index | Thread Index | Old Index