Module Name:    src
Committed By:   mrg
Date:           Sat May  4 23:07:07 UTC 2019

Modified Files:
        src/sys/dev/usb: uhmodem.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/usb/uhmodem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/uhmodem.c
diff -u src/sys/dev/usb/uhmodem.c:1.16 src/sys/dev/usb/uhmodem.c:1.17
--- src/sys/dev/usb/uhmodem.c:1.16	Sat May  4 08:04:13 2019
+++ src/sys/dev/usb/uhmodem.c	Sat May  4 23:07:07 2019
@@ -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 <y...@nui.org>.
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: uhmodem.c,v 
 #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 @@ Static int	uhmodemdebug = 0;
 #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 @@ struct uhmodem_type {
 				/* 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 @@ Static const struct uhmodem_type uhmodem
 };
 #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 @@ uhmodem_match(device_t parent, cfdata_t 
 	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 @@ uhmodem_attach(device_t parent, device_t
 	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 @@ uhmodem_attach(device_t parent, device_t
 		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 @@ uhmodem_attach(device_t parent, device_t
 	 * 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 @@ uhmodem_attach(device_t parent, device_t
 
 			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 @@ uhmodem_attach(device_t parent, device_t
 			}
 		} /* 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 @@ uhmodem_attach(device_t parent, device_t
 		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 @@ uhmodem_attach(device_t parent, device_t
 		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 @@ uhmodem_attach(device_t parent, device_t
 		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 @@ error:
 	return;
 }
 
-void
+static void
 uhmodem_childdet(device_t self, device_t child)
 {
 	int i;
-	struct uhmodem_softc *sc = device_private(self);
+	struct ubsa_softc *sc = device_private(self);
 
-	for (i = 0; i < sc->sc_ubsa.sc_numif; i++) {
-		if (sc->sc_ubsa.sc_subdevs[i] == child)
+	for (i = 0; i < sc->sc_numif; i++) {
+		if (sc->sc_subdevs[i] == child)
 			break;
 	}
-	KASSERT(i < sc->sc_ubsa.sc_numif);
-	sc->sc_ubsa.sc_subdevs[i] = NULL;
+	KASSERT(i < sc->sc_numif);
+	sc->sc_subdevs[i] = NULL;
 }
 
-int
+static int
 uhmodem_detach(device_t self, int flags)
 {
-	struct uhmodem_softc *sc = device_private(self);
+	struct ubsa_softc *sc = device_private(self);
 	int i;
 	int rv = 0;
 
 	DPRINTF(("uhmodem_detach: sc = %p\n", sc));
 
-	if (sc->sc_ubsa.sc_intr_pipe != NULL) {
-		usbd_abort_pipe(sc->sc_ubsa.sc_intr_pipe);
-		usbd_close_pipe(sc->sc_ubsa.sc_intr_pipe);
-		kmem_free(sc->sc_ubsa.sc_intr_buf, sc->sc_ubsa.sc_isize);
-		sc->sc_ubsa.sc_intr_pipe = NULL;
+	if (sc->sc_intr_pipe != NULL) {
+		usbd_abort_pipe(sc->sc_intr_pipe);
+		usbd_close_pipe(sc->sc_intr_pipe);
+		kmem_free(sc->sc_intr_buf, sc->sc_isize);
+		sc->sc_intr_pipe = NULL;
 	}
 
-	sc->sc_ubsa.sc_dying = 1;
-	for (i = 0; i < sc->sc_ubsa.sc_numif; i++) {
-		if (sc->sc_ubsa.sc_subdevs[i] != NULL)
-			rv |= config_detach(sc->sc_ubsa.sc_subdevs[i], flags);
+	sc->sc_dying = 1;
+	for (i = 0; i < sc->sc_numif; i++) {
+		if (sc->sc_subdevs[i] != NULL)
+			rv |= config_detach(sc->sc_subdevs[i], flags);
 	}
 
-	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_ubsa.sc_udev,
-			   sc->sc_ubsa.sc_dev);
+	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
+			   sc->sc_dev);
 
 	return rv;
 }
 
-int
+static int
 uhmodem_activate(device_t self, enum devact act)
 {
-	struct uhmodem_softc *sc = device_private(self);
+	struct ubsa_softc *sc = device_private(self);
 
 	switch (act) {
 	case DVACT_DEACTIVATE:
-		sc->sc_ubsa.sc_dying = 1;
+		sc->sc_dying = 1;
 		return 0;
 	default:
 		return EOPNOTSUPP;
 	}
 }
 
-Static int
+static int
 uhmodem_open(void *addr, int portno)
 {
 	struct ubsa_softc *sc = addr;
@@ -499,7 +496,7 @@ uhmodem_open(void *addr, int portno)
  * Hauwei E220 needs special request to enable modem function.
  * -- DEVICE_REMOTE_WAKEUP ruquest to endpoint 2.
  */
-Static  usbd_status
+static  usbd_status
 e220_modechange_request(struct usbd_device *dev)
 {
 #define E220_MODE_CHANGE_REQUEST 0x2
@@ -523,7 +520,7 @@ e220_modechange_request(struct usbd_devi
 #undef E220_MODE_CHANGE_REQUEST
 }
 
-Static  usbd_status
+static  usbd_status
 uhmodem_endpointhalt(struct ubsa_softc *sc, int iface)
 {
 	usb_device_request_t req;
@@ -560,7 +557,7 @@ uhmodem_endpointhalt(struct ubsa_softc *
 	return 0;
 }
 
-Static usbd_status
+static usbd_status
 uhmodem_regwrite(struct usbd_device *dev, uint8_t *data, size_t len)
 {
 	usb_device_request_t req;
@@ -578,7 +575,7 @@ uhmodem_regwrite(struct usbd_device *dev
 	return 0;
 }
 
-Static usbd_status
+static usbd_status
 uhmodem_regread(struct usbd_device *dev, uint8_t *data, size_t len)
 {
 	usb_device_request_t req;
@@ -598,7 +595,7 @@ uhmodem_regread(struct usbd_device *dev,
 }
 
 #if 0
-Static usbd_status
+static usbd_status
 uhmodem_regsetup(struct usbd_device *dev, uint16_t cmd)
 {
 	usb_device_request_t req;
@@ -618,7 +615,7 @@ uhmodem_regsetup(struct usbd_device *dev
 }
 #endif
 
-Static  usbd_status
+static  usbd_status
 a2502_init(struct usbd_device *dev)
 {
 	uint8_t data[8];
@@ -661,7 +658,7 @@ a2502_init(struct usbd_device *dev)
  * However currently I can't understand what the messege is,
  * disable this code when I get more information about it.
  */
-Static  usbd_status
+static  usbd_status
 e220_init(struct usbd_device *dev)
 {
 	uint8_t data[8];

Reply via email to