Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb uhmodem(4) uses ubsa(4)'s softc in its own softc...



details:   https://anonhg.NetBSD.org/src/rev/0c8dd615a699
branches:  trunk
changeset: 451047:0c8dd615a699
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sat May 04 23:07:07 2019 +0000

description:
uhmodem(4) uses ubsa(4)'s softc in its own softc as the only member,
and the code relies upon it being the first member (some functions
called with the callback arg are in uhmodem and some in ubsa.)

make it less implicit that this is really supposed to be identical
to ubsa usage, and operate on ubsa_softc directly.

clean up some Static.

diffstat:

 sys/dev/usb/uhmodem.c |  181 ++++++++++++++++++++++++-------------------------
 1 files changed, 89 insertions(+), 92 deletions(-)

diffs (truncated from 440 to 300 lines):

diff -r 9d22873c0889 -r 0c8dd615a699 sys/dev/usb/uhmodem.c
--- a/sys/dev/usb/uhmodem.c     Sat May 04 22:55:32 2019 +0000
+++ b/sys/dev/usb/uhmodem.c     Sat May 04 23:07:07 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhmodem.c,v 1.16 2019/05/04 08:04:13 mrg Exp $ */
+/*     $NetBSD: uhmodem.c,v 1.17 2019/05/04 23:07:07 mrg Exp $ */
 
 /*
  * Copyright (c) 2008 Yojiro UO <yuo%nui.org@localhost>.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhmodem.c,v 1.16 2019/05/04 08:04:13 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhmodem.c,v 1.17 2019/05/04 23:07:07 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -113,7 +113,7 @@
 #define UHMODEMOBUFSIZE        4096
 
 #ifdef UHMODEM_DEBUG
-Static int     uhmodemdebug = 0;
+static int     uhmodemdebug = 0;
 #define DPRINTFN(n, x)  do { \
                                if (uhmodemdebug > (n)) \
                                        printf x; \
@@ -123,21 +123,18 @@
 #endif
 #define DPRINTF(x) DPRINTFN(0, x)
 
-Static int uhmodem_open(void *, int);
-Static  usbd_status e220_modechange_request(struct usbd_device *);
-Static usbd_status uhmodem_endpointhalt(struct ubsa_softc *, int);
-Static usbd_status uhmodem_regwrite(struct usbd_device *, uint8_t *, size_t);
-Static usbd_status uhmodem_regread(struct usbd_device *, uint8_t *, size_t);
-Static  usbd_status a2502_init(struct usbd_device *);
+static int     uhmodem_open(void *, int);
+static usbd_status e220_modechange_request(struct usbd_device *);
+static usbd_status uhmodem_endpointhalt(struct ubsa_softc *, int);
+static usbd_status uhmodem_regwrite(struct usbd_device *, uint8_t *, size_t);
+static usbd_status uhmodem_regread(struct usbd_device *, uint8_t *, size_t);
+static usbd_status a2502_init(struct usbd_device *);
 #if 0
-Static usbd_status uhmodem_regsetup(struct usbd_device *, uint16_t);
-Static  usbd_status e220_init(struct usbd_device *);
+static usbd_status uhmodem_regsetup(struct usbd_device *, uint16_t);
+static usbd_status e220_init(struct usbd_device *);
 #endif
 
-struct uhmodem_softc {
-       struct ubsa_softc       sc_ubsa;
-};
-
+/* this driver uses the ubsa_softc and methods directly as-is. */
 struct ucom_methods uhmodem_methods = {
        .ucom_get_status = ubsa_get_status,
        .ucom_set = ubsa_set,
@@ -156,7 +153,7 @@
                                /* Whether or not it is a device different from E220 is not clear. */
 };
 
-Static const struct uhmodem_type uhmodem_devs[] = {
+static const struct uhmodem_type uhmodem_devs[] = {
        /* HUAWEI E220 / Emobile D0[12]HW */
        {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E220 }, 2,     E220},
        /* ANYDATA / NTT DoCoMo A2502 */
@@ -166,16 +163,16 @@
 };
 #define uhmodem_lookup(v, p) ((const struct uhmodem_type *)usb_lookup(uhmodem_devs, v, p))
 
-int uhmodem_match(device_t, cfdata_t, void *);
-void uhmodem_attach(device_t, device_t, void *);
-void uhmodem_childdet(device_t, device_t);
-int uhmodem_detach(device_t, int);
-int uhmodem_activate(device_t, enum devact);
-extern struct cfdriver uhmodem_cd;
-CFATTACH_DECL2_NEW(uhmodem, sizeof(struct uhmodem_softc), uhmodem_match,
+static int     uhmodem_match(device_t, cfdata_t, void *);
+static void    uhmodem_attach(device_t, device_t, void *);
+static void    uhmodem_childdet(device_t, device_t);
+static int     uhmodem_detach(device_t, int);
+static int     uhmodem_activate(device_t, enum devact);
+
+CFATTACH_DECL2_NEW(uhmodem, sizeof(struct ubsa_softc), uhmodem_match,
     uhmodem_attach, uhmodem_detach, uhmodem_activate, NULL, uhmodem_childdet);
 
-int
+static int
 uhmodem_match(device_t parent, cfdata_t match, void *aux)
 {
        struct usbif_attach_arg *uiaa = aux;
@@ -188,10 +185,10 @@
        return UMATCH_NONE;
 }
 
-void
+static void
 uhmodem_attach(device_t parent, device_t self, void *aux)
 {
-       struct uhmodem_softc *sc = device_private(self);
+       struct ubsa_softc *sc = device_private(self);
        struct usbif_attach_arg *uiaa = aux;
        struct usbd_device *dev = uiaa->uiaa_device;
        usb_config_descriptor_t *cdesc;
@@ -211,10 +208,10 @@
        aprint_normal_dev(self, "%s\n", devinfop);
        usbd_devinfo_free(devinfop);
 
-       sc->sc_ubsa.sc_dev = self;
-       sc->sc_ubsa.sc_udev = dev;
-       sc->sc_ubsa.sc_config_index = UBSA_DEFAULT_CONFIG_INDEX;
-       sc->sc_ubsa.sc_numif = 1; /* defaut device has one interface */
+       sc->sc_dev = self;
+       sc->sc_udev = dev;
+       sc->sc_config_index = UBSA_DEFAULT_CONFIG_INDEX;
+       sc->sc_numif = 1; /* defaut device has one interface */
 
        /* Hauwei E220 need special request to change its mode to modem */
        if ((uiaa->uiaa_ifaceno == 0) && (uiaa->uiaa_class != 255)) {
@@ -222,12 +219,12 @@
                if (err) {
                        aprint_error_dev(self, "failed to change mode: %s\n",
                                usbd_errstr(err));
-                       sc->sc_ubsa.sc_dying = 1;
+                       sc->sc_dying = 1;
                        goto error;
                }
                aprint_error_dev(self,
                    "mass storage only mode, reattach to enable modem\n");
-               sc->sc_ubsa.sc_dying = 1;
+               sc->sc_dying = 1;
                goto error;
        }
 
@@ -235,60 +232,60 @@
         * initialize rts, dtr variables to something
         * different from boolean 0, 1
         */
-       sc->sc_ubsa.sc_dtr = -1;
-       sc->sc_ubsa.sc_rts = -1;
+       sc->sc_dtr = -1;
+       sc->sc_rts = -1;
 
-       sc->sc_ubsa.sc_quadumts = 1;
-       sc->sc_ubsa.sc_config_index = 0;
-       sc->sc_ubsa.sc_numif = uhmodem_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product)->uhmodem_coms;
-       sc->sc_ubsa.sc_devflags = uhmodem_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product)->uhmodem_flags;
+       sc->sc_quadumts = 1;
+       sc->sc_config_index = 0;
+       sc->sc_numif = uhmodem_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product)->uhmodem_coms;
+       sc->sc_devflags = uhmodem_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product)->uhmodem_flags;
 
        DPRINTF(("uhmodem attach: sc = %p\n", sc));
 
        /* Move the device into the configured state. */
-       err = usbd_set_config_index(dev, sc->sc_ubsa.sc_config_index, 1);
+       err = usbd_set_config_index(dev, sc->sc_config_index, 1);
        if (err) {
                aprint_error_dev(self, "failed to set configuration: %s\n",
                    usbd_errstr(err));
-               sc->sc_ubsa.sc_dying = 1;
+               sc->sc_dying = 1;
                goto error;
        }
 
        /* get the config descriptor */
-       cdesc = usbd_get_config_descriptor(sc->sc_ubsa.sc_udev);
+       cdesc = usbd_get_config_descriptor(sc->sc_udev);
        if (cdesc == NULL) {
                aprint_error_dev(self,
                    "failed to get configuration descriptor\n");
-               sc->sc_ubsa.sc_dying = 1;
+               sc->sc_dying = 1;
                goto error;
        }
 
-       sc->sc_ubsa.sc_intr_number = -1;
-       sc->sc_ubsa.sc_intr_pipe = NULL;
+       sc->sc_intr_number = -1;
+       sc->sc_intr_pipe = NULL;
 
        /* get the interfaces */
-       for (i = 0; i < sc->sc_ubsa.sc_numif; i++) {
+       for (i = 0; i < sc->sc_numif; i++) {
                err = usbd_device2interface_handle(dev, UBSA_IFACE_INDEX_OFFSET+i,
-                                &sc->sc_ubsa.sc_iface[i]);
+                                &sc->sc_iface[i]);
                if (err) {
                        if (i == 0){
                                /* can not get main interface */
-                               sc->sc_ubsa.sc_dying = 1;
+                               sc->sc_dying = 1;
                                goto error;
                        } else
                                break;
                }
 
                /* Find the endpoints */
-               id = usbd_get_interface_descriptor(sc->sc_ubsa.sc_iface[i]);
-               sc->sc_ubsa.sc_iface_number[i] = id->bInterfaceNumber;
+               id = usbd_get_interface_descriptor(sc->sc_iface[i]);
+               sc->sc_iface_number[i] = id->bInterfaceNumber;
 
                /* initialize endpoints */
                ucaa.ucaa_bulkin = ucaa.ucaa_bulkout = -1;
 
                for (j = 0; j < id->bNumEndpoints; j++) {
                        ed = usbd_interface2endpoint_descriptor(
-                               sc->sc_ubsa.sc_iface[i], j);
+                               sc->sc_iface[i], j);
                        if (ed == NULL) {
                                aprint_error_dev(self,
                                    "no endpoint descriptor for %d "
@@ -298,8 +295,8 @@
 
                        if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
                            UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
-                               sc->sc_ubsa.sc_intr_number = ed->bEndpointAddress;
-                               sc->sc_ubsa.sc_isize = UGETW(ed->wMaxPacketSize);
+                               sc->sc_intr_number = ed->bEndpointAddress;
+                               sc->sc_isize = UGETW(ed->wMaxPacketSize);
                        } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
                            UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
                                ucaa.ucaa_bulkin = ed->bEndpointAddress;
@@ -309,12 +306,12 @@
                        }
                } /* end of Endpoint loop */
 
-               if (sc->sc_ubsa.sc_intr_number == -1) {
+               if (sc->sc_intr_number == -1) {
                        aprint_error_dev(self, "HUAWEI E220 need to re-attach "
                            "to enable modem function\n");
                        if (i == 0) {
                                /* could not get intr for main tty */
-                               sc->sc_ubsa.sc_dying = 1;
+                               sc->sc_dying = 1;
                                goto error;
                        } else
                                break;
@@ -322,14 +319,14 @@
                if (ucaa.ucaa_bulkin == -1) {
                        aprint_error_dev(self,
                            "Could not find data bulk in\n");
-                       sc->sc_ubsa.sc_dying = 1;
+                       sc->sc_dying = 1;
                        goto error;
                }
 
                if (ucaa.ucaa_bulkout == -1) {
                        aprint_error_dev(self,
                            "Could not find data bulk out\n");
-                       sc->sc_ubsa.sc_dying = 1;
+                       sc->sc_dying = 1;
                        goto error;
                }
 
@@ -355,14 +352,14 @@
                ucaa.ucaa_ibufsizepad = UHMODEMIBUFSIZE;
                ucaa.ucaa_opkthdrlen = 0;
                ucaa.ucaa_device = dev;
-               ucaa.ucaa_iface = sc->sc_ubsa.sc_iface[i];
+               ucaa.ucaa_iface = sc->sc_iface[i];
                ucaa.ucaa_methods = &uhmodem_methods;
                ucaa.ucaa_arg = &sc->sc_ubsa;
                ucaa.ucaa_info = comname;
                DPRINTF(("uhmodem: int#=%d, in = 0x%x, out = 0x%x, intr = 0x%x\n",
                    i, ucaa.ucaa_bulkin, ucaa.ucaa_bulkout,
-                   sc->sc_ubsa.sc_intr_number));
-               sc->sc_ubsa.sc_subdevs[i] = config_found_sm_loc(self, "ucombus", NULL,
+                   sc->sc_intr_number));
+               sc->sc_subdevs[i] = config_found_sm_loc(self, "ucombus", NULL,
                                 &ucaa, ucomprint, ucomsubmatch);
 
                /* issue endpoint halt to each interface */
@@ -370,11 +367,11 @@
                if (err)
                        aprint_error("%s: endpointhalt fail\n", __func__);
                else
-                       usbd_delay_ms(sc->sc_ubsa.sc_udev, 50);
+                       usbd_delay_ms(sc->sc_udev, 50);
        } /* end of Interface loop */
 
-       usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_ubsa.sc_udev,
-                          sc->sc_ubsa.sc_dev);
+       usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
+                          sc->sc_dev);
 
        return;
 
@@ -382,63 +379,63 @@
        return;
 }
 
-void
+static void
 uhmodem_childdet(device_t self, device_t child)
 {
        int i;
-       struct uhmodem_softc *sc = device_private(self);



Home | Main Index | Thread Index | Old Index