svn commit: r188413 - head/sys/dev/usb2/serial

Andrew Thompson thompsa at FreeBSD.org
Mon Feb 9 14:05:26 PST 2009


Author: thompsa
Date: Mon Feb  9 22:05:25 2009
New Revision: 188413
URL: http://svn.freebsd.org/changeset/base/188413

Log:
  MFp4 //depot/projects/usb; 157069, 157136, 157143, 157145, 157429
  
   - USB serial drivers cleanup, factor out code
   - Simplify line state programming
   - Integrate uslcom from old USB stack
  
  Submitted by:	Hans Petter Selasky

Added:
  head/sys/dev/usb2/serial/uslcom2.c   (contents, props changed)
Modified:
  head/sys/dev/usb2/serial/u3g2.c
  head/sys/dev/usb2/serial/uark2.c
  head/sys/dev/usb2/serial/ubsa2.c
  head/sys/dev/usb2/serial/ubser2.c
  head/sys/dev/usb2/serial/uchcom2.c
  head/sys/dev/usb2/serial/ucycom2.c
  head/sys/dev/usb2/serial/ufoma2.c
  head/sys/dev/usb2/serial/uftdi2.c
  head/sys/dev/usb2/serial/ugensa2.c
  head/sys/dev/usb2/serial/uipaq2.c
  head/sys/dev/usb2/serial/ulpt2.c
  head/sys/dev/usb2/serial/umct2.c
  head/sys/dev/usb2/serial/umodem2.c
  head/sys/dev/usb2/serial/umoscom2.c
  head/sys/dev/usb2/serial/uplcom2.c
  head/sys/dev/usb2/serial/usb2_serial.c
  head/sys/dev/usb2/serial/usb2_serial.h
  head/sys/dev/usb2/serial/uvisor2.c
  head/sys/dev/usb2/serial/uvscom2.c

Modified: head/sys/dev/usb2/serial/u3g2.c
==============================================================================
--- head/sys/dev/usb2/serial/u3g2.c	Mon Feb  9 22:02:38 2009	(r188412)
+++ head/sys/dev/usb2/serial/u3g2.c	Mon Feb  9 22:05:25 2009	(r188413)
@@ -88,7 +88,7 @@ struct u3g_speeds_s {
 enum {
 	U3G_BULK_WR,
 	U3G_BULK_RD,
-	U3G_N_TRANSFER = 2,
+	U3G_N_TRANSFER,
 };
 
 struct u3g_softc {
@@ -98,11 +98,8 @@ struct u3g_softc {
 	struct usb2_xfer *sc_xfer[U3G_MAXPORTS][U3G_N_TRANSFER];
 	struct usb2_device *sc_udev;
 
-	uint8_t	sc_iface_no;		/* interface number */
-	uint8_t	sc_iface_index;		/* interface index */
 	uint8_t	sc_lsr;			/* local status register */
 	uint8_t	sc_msr;			/* U3G status register */
-	struct u3g_speeds_s sc_speed;
 	uint8_t	sc_numports;
 };
 
@@ -148,6 +145,7 @@ static const struct usb2_com_callback u3
 	.usb2_com_stop_write = &u3g_stop_write,
 };
 
+#if 0
 static const struct u3g_speeds_s u3g_speeds[U3GSP_MAX] = {
 	[U3GSP_GPRS] = {64000, 64000},
 	[U3GSP_EDGE] = {384000, 64000},
@@ -157,6 +155,7 @@ static const struct u3g_speeds_s u3g_spe
 	[U3GSP_HSUPA] = {1200000, 384000},
 	[U3GSP_HSPA] = {7200000, 384000},
 };
+#endif
 
 static device_method_t u3g_methods[] = {
 	DEVMETHOD(device_probe, u3g_probe),
@@ -385,8 +384,12 @@ u3g_attach(device_t dev)
 	struct usb2_config u3g_config_tmp[U3G_N_TRANSFER];
 	struct usb2_attach_arg *uaa = device_get_ivars(dev);
 	struct u3g_softc *sc = device_get_softc(dev);
-	uint8_t n;
+	struct usb2_interface *iface;
+	struct usb2_interface_descriptor *id;
 	uint8_t m;
+	uint8_t n;
+	uint8_t i;
+	uint8_t x;
 	int error;
 
 	DPRINTF("sc=%p\n", sc);
@@ -398,30 +401,56 @@ u3g_attach(device_t dev)
 	device_set_usb2_desc(dev);
 
 	sc->sc_udev = uaa->device;
-	sc->sc_iface_no = uaa->info.bIfaceNum;
-	sc->sc_iface_index = uaa->info.bIfaceIndex;
-	sc->sc_speed = u3g_speeds[U3G_GET_SPEED(uaa)];
 
-	for (m = 0; m != U3G_MAXPORTS; m++) {
+	x = 0;		/* interface index */
+	i = 0;		/* endpoint index */
+	m = 0;		/* number of ports */
+
+	while (m != U3G_MAXPORTS) {
 
 		/* update BULK endpoint index */
 		for (n = 0; n != U3G_N_TRANSFER; n++) 
-			u3g_config_tmp[n].ep_index = m;
+			u3g_config_tmp[n].ep_index = i;
+
+		iface = usb2_get_iface(uaa->device, x);
+		if (iface == NULL) {
+			if (m != 0)
+				break;	/* end of interfaces */
+			DPRINTF("did not find any modem endpoints\n");
+			goto detach;
+		}
+
+		id = usb2_get_interface_descriptor(iface);
+		if ((id == NULL) || 
+		    (id->bInterfaceClass != UICLASS_VENDOR)) {
+			/* next interface */
+			x++;
+			i = 0;
+			continue;
+		}
 
 		/* try to allocate a set of BULK endpoints */
-		error = usb2_transfer_setup(uaa->device, &sc->sc_iface_index,
+		error = usb2_transfer_setup(uaa->device, &x,
 		    sc->sc_xfer[m], u3g_config_tmp, U3G_N_TRANSFER, 
 		    &sc->sc_ucom[m], &Giant);
-
 		if (error) {
-			if (m != 0)
-				break;	/* end of endpoints */
-			DPRINTF("could not allocate all pipes\n");
-			goto detach;
+			/* next interface */
+			x++;
+			i = 0;
+			continue;
 		}
+
+		/* grab other interface, if any */
+                if (x != uaa->info.bIfaceIndex)
+                        usb2_set_parent_iface(uaa->device, x,
+                            uaa->info.bIfaceIndex);
+
 		/* set stall by default */
 		usb2_transfer_set_stall(sc->sc_xfer[m][U3G_BULK_WR]);
 		usb2_transfer_set_stall(sc->sc_xfer[m][U3G_BULK_RD]);
+
+		m++;	/* found one port */
+		i++;	/* next endpoint index */
 	}
 
 	sc->sc_numports = m;

Modified: head/sys/dev/usb2/serial/uark2.c
==============================================================================
--- head/sys/dev/usb2/serial/uark2.c	Mon Feb  9 22:02:38 2009	(r188412)
+++ head/sys/dev/usb2/serial/uark2.c	Mon Feb  9 22:05:25 2009	(r188413)
@@ -64,9 +64,7 @@
 enum {
 	UARK_BULK_DT_WR,
 	UARK_BULK_DT_RD,
-	UARK_BULK_CS_WR,
-	UARK_BULK_CS_RD,
-	UARK_N_TRANSFER = 4,
+	UARK_N_TRANSFER,
 };
 
 struct uark_softc {
@@ -76,9 +74,6 @@ struct uark_softc {
 	struct usb2_xfer *sc_xfer[UARK_N_TRANSFER];
 	struct usb2_device *sc_udev;
 
-	uint8_t	sc_flags;
-#define	UARK_FLAG_BULK_READ_STALL	0x01
-#define	UARK_FLAG_BULK_WRITE_STALL	0x02
 	uint8_t	sc_msr;
 	uint8_t	sc_lsr;
 };
@@ -90,9 +85,7 @@ static device_attach_t uark_attach;
 static device_detach_t uark_detach;
 
 static usb2_callback_t uark_bulk_write_callback;
-static usb2_callback_t uark_bulk_write_clear_stall_callback;
 static usb2_callback_t uark_bulk_read_callback;
-static usb2_callback_t uark_bulk_read_clear_stall_callback;
 
 static void	uark_start_read(struct usb2_com_softc *);
 static void	uark_stop_read(struct usb2_com_softc *);
@@ -125,28 +118,6 @@ static const struct usb2_config
 		.mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
 		.mh.callback = &uark_bulk_read_callback,
 	},
-
-	[UARK_BULK_CS_WR] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.flags = {},
-		.mh.callback = &uark_bulk_write_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
-
-	[UARK_BULK_CS_RD] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.flags = {},
-		.mh.callback = &uark_bulk_read_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
 };
 
 static const struct usb2_com_callback uark_callback = {
@@ -224,8 +195,8 @@ uark_attach(device_t dev)
 		goto detach;
 	}
 	/* clear stall at first run */
-	sc->sc_flags |= (UARK_FLAG_BULK_WRITE_STALL |
-	    UARK_FLAG_BULK_READ_STALL);
+	usb2_transfer_set_stall(sc->sc_xfer[UARK_BULK_DT_WR]);
+	usb2_transfer_set_stall(sc->sc_xfer[UARK_BULK_DT_RD]);
 
 	error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
 	    &uark_callback, &Giant);
@@ -261,10 +232,7 @@ uark_bulk_write_callback(struct usb2_xfe
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_SETUP:
 	case USB_ST_TRANSFERRED:
-		if (sc->sc_flags & UARK_FLAG_BULK_WRITE_STALL) {
-			usb2_transfer_start(sc->sc_xfer[UARK_BULK_CS_WR]);
-			return;
-		}
+tr_setup:
 		if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
 		    UARK_BUF_SIZE, &actlen)) {
 			xfer->frlengths[0] = actlen;
@@ -274,8 +242,9 @@ uark_bulk_write_callback(struct usb2_xfe
 
 	default:			/* Error */
 		if (xfer->error != USB_ERR_CANCELLED) {
-			sc->sc_flags |= UARK_FLAG_BULK_WRITE_STALL;
-			usb2_transfer_start(sc->sc_xfer[UARK_BULK_CS_WR]);
+			/* try to clear stall first */
+			xfer->flags.stall_pipe = 1;
+			goto tr_setup;
 		}
 		return;
 
@@ -283,19 +252,6 @@ uark_bulk_write_callback(struct usb2_xfe
 }
 
 static void
-uark_bulk_write_clear_stall_callback(struct usb2_xfer *xfer)
-{
-	struct uark_softc *sc = xfer->priv_sc;
-	struct usb2_xfer *xfer_other = sc->sc_xfer[UARK_BULK_DT_WR];
-
-	if (usb2_clear_stall_callback(xfer, xfer_other)) {
-		DPRINTF("stall cleared\n");
-		sc->sc_flags &= ~UARK_FLAG_BULK_WRITE_STALL;
-		usb2_transfer_start(xfer_other);
-	}
-}
-
-static void
 uark_bulk_read_callback(struct usb2_xfer *xfer)
 {
 	struct uark_softc *sc = xfer->priv_sc;
@@ -306,34 +262,18 @@ uark_bulk_read_callback(struct usb2_xfer
 		    xfer->actlen);
 
 	case USB_ST_SETUP:
-		if (sc->sc_flags & UARK_FLAG_BULK_READ_STALL) {
-			usb2_transfer_start(sc->sc_xfer[UARK_BULK_CS_RD]);
-		} else {
-			xfer->frlengths[0] = xfer->max_data_length;
-			usb2_start_hardware(xfer);
-		}
+tr_setup:
+		xfer->frlengths[0] = xfer->max_data_length;
+		usb2_start_hardware(xfer);
 		return;
 
 	default:			/* Error */
 		if (xfer->error != USB_ERR_CANCELLED) {
-			sc->sc_flags |= UARK_FLAG_BULK_READ_STALL;
-			usb2_transfer_start(sc->sc_xfer[UARK_BULK_CS_RD]);
+			/* try to clear stall first */
+			xfer->flags.stall_pipe = 1;
+			goto tr_setup;
 		}
 		return;
-
-	}
-}
-
-static void
-uark_bulk_read_clear_stall_callback(struct usb2_xfer *xfer)
-{
-	struct uark_softc *sc = xfer->priv_sc;
-	struct usb2_xfer *xfer_other = sc->sc_xfer[UARK_BULK_DT_RD];
-
-	if (usb2_clear_stall_callback(xfer, xfer_other)) {
-		DPRINTF("stall cleared\n");
-		sc->sc_flags &= ~UARK_FLAG_BULK_READ_STALL;
-		usb2_transfer_start(xfer_other);
 	}
 }
 
@@ -350,7 +290,6 @@ uark_stop_read(struct usb2_com_softc *uc
 {
 	struct uark_softc *sc = ucom->sc_parent;
 
-	usb2_transfer_stop(sc->sc_xfer[UARK_BULK_CS_RD]);
 	usb2_transfer_stop(sc->sc_xfer[UARK_BULK_DT_RD]);
 }
 
@@ -367,7 +306,6 @@ uark_stop_write(struct usb2_com_softc *u
 {
 	struct uark_softc *sc = ucom->sc_parent;
 
-	usb2_transfer_stop(sc->sc_xfer[UARK_BULK_CS_WR]);
 	usb2_transfer_stop(sc->sc_xfer[UARK_BULK_DT_WR]);
 }
 
@@ -454,18 +392,14 @@ uark_cfg_write(struct uark_softc *sc, ui
 	struct usb2_device_request req;
 	usb2_error_t err;
 
-	if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
-		return;
-	}
 	req.bmRequestType = UARK_WRITE;
 	req.bRequest = UARK_REQUEST;
 	USETW(req.wValue, value);
 	USETW(req.wIndex, index);
 	USETW(req.wLength, 0);
 
-	err = usb2_do_request_flags
-	    (sc->sc_udev, &Giant, &req, NULL, 0, NULL, 1000);
-
+	err = usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 
+	    &req, NULL, 0, 1000);
 	if (err) {
 		DPRINTFN(0, "device request failed, err=%s "
 		    "(ignored)\n", usb2_errstr(err));

Modified: head/sys/dev/usb2/serial/ubsa2.c
==============================================================================
--- head/sys/dev/usb2/serial/ubsa2.c	Mon Feb  9 22:02:38 2009	(r188412)
+++ head/sys/dev/usb2/serial/ubsa2.c	Mon Feb  9 22:05:25 2009	(r188413)
@@ -143,11 +143,8 @@ SYSCTL_INT(_hw_usb2_ubsa, OID_AUTO, debu
 enum {
 	UBSA_BULK_DT_WR,
 	UBSA_BULK_DT_RD,
-	UBSA_BULK_CS_WR,
-	UBSA_BULK_CS_RD,
 	UBSA_INTR_DT_RD,
-	UBSA_INTR_CS_RD,
-	UBSA_N_TRANSFER = 6,
+	UBSA_N_TRANSFER,
 };
 
 struct ubsa_softc {
@@ -157,11 +154,6 @@ struct ubsa_softc {
 	struct usb2_xfer *sc_xfer[UBSA_N_TRANSFER];
 	struct usb2_device *sc_udev;
 
-	uint16_t sc_flag;
-#define	UBSA_FLAG_WRITE_STALL   0x0001
-#define	UBSA_FLAG_READ_STALL    0x0002
-#define	UBSA_FLAG_INTR_STALL    0x0004
-
 	uint8_t	sc_iface_no;		/* interface number */
 	uint8_t	sc_iface_index;		/* interface index */
 	uint8_t	sc_lsr;			/* local status register */
@@ -173,11 +165,8 @@ static device_attach_t ubsa_attach;
 static device_detach_t ubsa_detach;
 
 static usb2_callback_t ubsa_write_callback;
-static usb2_callback_t ubsa_write_clear_stall_callback;
 static usb2_callback_t ubsa_read_callback;
-static usb2_callback_t ubsa_read_clear_stall_callback;
 static usb2_callback_t ubsa_intr_callback;
-static usb2_callback_t ubsa_intr_clear_stall_callback;
 
 static void	ubsa_cfg_request(struct ubsa_softc *, uint8_t, uint16_t);
 static void	ubsa_cfg_set_dtr(struct usb2_com_softc *, uint8_t);
@@ -212,26 +201,6 @@ static const struct usb2_config ubsa_con
 		.mh.callback = &ubsa_read_callback,
 	},
 
-	[UBSA_BULK_CS_WR] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.callback = &ubsa_write_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
-
-	[UBSA_BULK_CS_RD] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.callback = &ubsa_read_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
-
 	[UBSA_INTR_DT_RD] = {
 		.type = UE_INTERRUPT,
 		.endpoint = UE_ADDR_ANY,
@@ -240,16 +209,6 @@ static const struct usb2_config ubsa_con
 		.mh.bufsize = 0,	/* use wMaxPacketSize */
 		.mh.callback = &ubsa_intr_callback,
 	},
-
-	[UBSA_INTR_CS_RD] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.callback = &ubsa_intr_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
 };
 
 static const struct usb2_com_callback ubsa_callback = {
@@ -343,8 +302,8 @@ ubsa_attach(device_t dev)
 		goto detach;
 	}
 	/* clear stall at first run */
-	sc->sc_flag |= (UBSA_FLAG_WRITE_STALL |
-	    UBSA_FLAG_READ_STALL);
+	usb2_transfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_WR]);
+	usb2_transfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_RD]);
 
 	error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
 	    &ubsa_callback, &Giant);
@@ -379,9 +338,6 @@ ubsa_cfg_request(struct ubsa_softc *sc, 
 	struct usb2_device_request req;
 	usb2_error_t err;
 
-	if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
-		return;
-	}
 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
 	req.bRequest = index;
 	USETW(req.wValue, value);
@@ -389,9 +345,8 @@ ubsa_cfg_request(struct ubsa_softc *sc, 
 	req.wIndex[1] = 0;
 	USETW(req.wLength, 0);
 
-	err = usb2_do_request_flags
-	    (sc->sc_udev, &Giant, &req, NULL, 0, NULL, 1000);
-
+	err = usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 
+	    &req, NULL, 0, 1000);
 	if (err) {
 		DPRINTFN(0, "device request failed, err=%s "
 		    "(ignored)\n", usb2_errstr(err));
@@ -544,11 +499,9 @@ ubsa_stop_read(struct usb2_com_softc *uc
 	struct ubsa_softc *sc = ucom->sc_parent;
 
 	/* stop interrupt endpoint */
-	usb2_transfer_stop(sc->sc_xfer[UBSA_INTR_CS_RD]);
 	usb2_transfer_stop(sc->sc_xfer[UBSA_INTR_DT_RD]);
 
 	/* stop read endpoint */
-	usb2_transfer_stop(sc->sc_xfer[UBSA_BULK_CS_RD]);
 	usb2_transfer_stop(sc->sc_xfer[UBSA_BULK_DT_RD]);
 }
 
@@ -565,7 +518,6 @@ ubsa_stop_write(struct usb2_com_softc *u
 {
 	struct ubsa_softc *sc = ucom->sc_parent;
 
-	usb2_transfer_stop(sc->sc_xfer[UBSA_BULK_CS_WR]);
 	usb2_transfer_stop(sc->sc_xfer[UBSA_BULK_DT_WR]);
 }
 
@@ -589,10 +541,7 @@ ubsa_write_callback(struct usb2_xfer *xf
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_SETUP:
 	case USB_ST_TRANSFERRED:
-		if (sc->sc_flag & UBSA_FLAG_WRITE_STALL) {
-			usb2_transfer_start(sc->sc_xfer[UBSA_BULK_CS_WR]);
-			return;
-		}
+tr_setup:
 		if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
 		    UBSA_BSIZE, &actlen)) {
 
@@ -603,8 +552,9 @@ ubsa_write_callback(struct usb2_xfer *xf
 
 	default:			/* Error */
 		if (xfer->error != USB_ERR_CANCELLED) {
-			sc->sc_flag |= UBSA_FLAG_WRITE_STALL;
-			usb2_transfer_start(sc->sc_xfer[UBSA_BULK_CS_WR]);
+			/* try to clear stall first */
+			xfer->flags.stall_pipe = 1;
+			goto tr_setup;
 		}
 		return;
 
@@ -612,19 +562,6 @@ ubsa_write_callback(struct usb2_xfer *xf
 }
 
 static void
-ubsa_write_clear_stall_callback(struct usb2_xfer *xfer)
-{
-	struct ubsa_softc *sc = xfer->priv_sc;
-	struct usb2_xfer *xfer_other = sc->sc_xfer[UBSA_BULK_DT_WR];
-
-	if (usb2_clear_stall_callback(xfer, xfer_other)) {
-		DPRINTF("stall cleared\n");
-		sc->sc_flag &= ~UBSA_FLAG_WRITE_STALL;
-		usb2_transfer_start(xfer_other);
-	}
-}
-
-static void
 ubsa_read_callback(struct usb2_xfer *xfer)
 {
 	struct ubsa_softc *sc = xfer->priv_sc;
@@ -634,18 +571,16 @@ ubsa_read_callback(struct usb2_xfer *xfe
 		usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
 
 	case USB_ST_SETUP:
-		if (sc->sc_flag & UBSA_FLAG_READ_STALL) {
-			usb2_transfer_start(sc->sc_xfer[UBSA_BULK_CS_RD]);
-		} else {
-			xfer->frlengths[0] = xfer->max_data_length;
-			usb2_start_hardware(xfer);
-		}
+tr_setup:
+		xfer->frlengths[0] = xfer->max_data_length;
+		usb2_start_hardware(xfer);
 		return;
 
 	default:			/* Error */
 		if (xfer->error != USB_ERR_CANCELLED) {
-			sc->sc_flag |= UBSA_FLAG_READ_STALL;
-			usb2_transfer_start(sc->sc_xfer[UBSA_BULK_CS_RD]);
+			/* try to clear stall first */
+			xfer->flags.stall_pipe = 1;
+			goto tr_setup;
 		}
 		return;
 
@@ -653,19 +588,6 @@ ubsa_read_callback(struct usb2_xfer *xfe
 }
 
 static void
-ubsa_read_clear_stall_callback(struct usb2_xfer *xfer)
-{
-	struct ubsa_softc *sc = xfer->priv_sc;
-	struct usb2_xfer *xfer_other = sc->sc_xfer[UBSA_BULK_DT_RD];
-
-	if (usb2_clear_stall_callback(xfer, xfer_other)) {
-		DPRINTF("stall cleared\n");
-		sc->sc_flag &= ~UBSA_FLAG_READ_STALL;
-		usb2_transfer_start(xfer_other);
-	}
-}
-
-static void
 ubsa_intr_callback(struct usb2_xfer *xfer)
 {
 	struct ubsa_softc *sc = xfer->priv_sc;
@@ -695,33 +617,18 @@ ubsa_intr_callback(struct usb2_xfer *xfe
 		}
 
 	case USB_ST_SETUP:
-		if (sc->sc_flag & UBSA_FLAG_INTR_STALL) {
-			usb2_transfer_start(sc->sc_xfer[UBSA_INTR_CS_RD]);
-		} else {
-			xfer->frlengths[0] = xfer->max_data_length;
-			usb2_start_hardware(xfer);
-		}
+tr_setup:
+		xfer->frlengths[0] = xfer->max_data_length;
+		usb2_start_hardware(xfer);
 		return;
 
 	default:			/* Error */
 		if (xfer->error != USB_ERR_CANCELLED) {
-			sc->sc_flag |= UBSA_FLAG_INTR_STALL;
-			usb2_transfer_start(sc->sc_xfer[UBSA_INTR_CS_RD]);
+			/* try to clear stall first */
+			xfer->flags.stall_pipe = 1;
+			goto tr_setup;
 		}
 		return;
 
 	}
 }
-
-static void
-ubsa_intr_clear_stall_callback(struct usb2_xfer *xfer)
-{
-	struct ubsa_softc *sc = xfer->priv_sc;
-	struct usb2_xfer *xfer_other = sc->sc_xfer[UBSA_INTR_DT_RD];
-
-	if (usb2_clear_stall_callback(xfer, xfer_other)) {
-		DPRINTF("stall cleared\n");
-		sc->sc_flag &= ~UBSA_FLAG_INTR_STALL;
-		usb2_transfer_start(xfer_other);
-	}
-}

Modified: head/sys/dev/usb2/serial/ubser2.c
==============================================================================
--- head/sys/dev/usb2/serial/ubser2.c	Mon Feb  9 22:02:38 2009	(r188412)
+++ head/sys/dev/usb2/serial/ubser2.c	Mon Feb  9 22:05:25 2009	(r188413)
@@ -113,9 +113,7 @@ SYSCTL_INT(_hw_usb2_ubser, OID_AUTO, deb
 enum {
 	UBSER_BULK_DT_WR,
 	UBSER_BULK_DT_RD,
-	UBSER_BULK_CS_WR,
-	UBSER_BULK_CS_RD,
-	UBSER_N_TRANSFER = 4,
+	UBSER_N_TRANSFER,
 };
 
 struct ubser_softc {
@@ -128,10 +126,6 @@ struct ubser_softc {
 	uint16_t sc_tx_size;
 
 	uint8_t	sc_numser;
-	uint8_t	sc_flags;
-#define	UBSER_FLAG_READ_STALL  0x01
-#define	UBSER_FLAG_WRITE_STALL 0x02
-
 	uint8_t	sc_iface_no;
 	uint8_t	sc_iface_index;
 	uint8_t	sc_curr_tx_unit;
@@ -144,9 +138,7 @@ static device_probe_t ubser_probe;
 static device_attach_t ubser_attach;
 static device_detach_t ubser_detach;
 
-static usb2_callback_t ubser_write_clear_stall_callback;
 static usb2_callback_t ubser_write_callback;
-static usb2_callback_t ubser_read_clear_stall_callback;
 static usb2_callback_t ubser_read_callback;
 
 static int	ubser_pre_param(struct usb2_com_softc *, struct termios *);
@@ -177,28 +169,6 @@ static const struct usb2_config ubser_co
 		.mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
 		.mh.callback = &ubser_read_callback,
 	},
-
-	[UBSER_BULK_CS_WR] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.flags = {},
-		.mh.callback = &ubser_write_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
-
-	[UBSER_BULK_CS_RD] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.flags = {},
-		.mh.callback = &ubser_read_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
 };
 
 static const struct usb2_com_callback ubser_callback = {
@@ -311,8 +281,8 @@ ubser_attach(device_t dev)
 	}
 	mtx_lock(&Giant);
 
-	sc->sc_flags |= (UBSER_FLAG_READ_STALL |
-	    UBSER_FLAG_WRITE_STALL);
+	usb2_transfer_set_stall(sc->sc_xfer[UBSER_BULK_DT_WR]);
+	usb2_transfer_set_stall(sc->sc_xfer[UBSER_BULK_DT_RD]);
 
 	usb2_transfer_start(sc->sc_xfer[UBSER_BULK_DT_RD]);
 
@@ -329,22 +299,11 @@ static int
 ubser_detach(device_t dev)
 {
 	struct ubser_softc *sc = device_get_softc(dev);
-	uint8_t n;
 
 	DPRINTF("\n");
 
 	usb2_com_detach(&sc->sc_super_ucom, sc->sc_ucom, sc->sc_numser);
 
-	/*
-	 * need to stop all transfers atomically, hence when clear stall
-	 * completes, it might start other transfers !
-	 */
-	mtx_lock(&Giant);
-	for (n = 0; n < UBSER_N_TRANSFER; n++) {
-		usb2_transfer_stop(sc->sc_xfer[n]);
-	}
-	mtx_unlock(&Giant);
-
 	usb2_transfer_unsetup(sc->sc_xfer, UBSER_N_TRANSFER);
 
 	return (0);
@@ -409,19 +368,6 @@ ubser_inc_tx_unit(struct ubser_softc *sc
 }
 
 static void
-ubser_write_clear_stall_callback(struct usb2_xfer *xfer)
-{
-	struct ubser_softc *sc = xfer->priv_sc;
-	struct usb2_xfer *xfer_other = sc->sc_xfer[UBSER_BULK_DT_WR];
-
-	if (usb2_clear_stall_callback(xfer, xfer_other)) {
-		DPRINTF("stall cleared\n");
-		sc->sc_flags &= ~UBSER_FLAG_WRITE_STALL;
-		usb2_transfer_start(xfer_other);
-	}
-}
-
-static void
 ubser_write_callback(struct usb2_xfer *xfer)
 {
 	struct ubser_softc *sc = xfer->priv_sc;
@@ -432,10 +378,7 @@ ubser_write_callback(struct usb2_xfer *x
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_SETUP:
 	case USB_ST_TRANSFERRED:
-		if (sc->sc_flags & UBSER_FLAG_WRITE_STALL) {
-			usb2_transfer_start(sc->sc_xfer[UBSER_BULK_CS_WR]);
-			return;
-		}
+tr_setup:
 		do {
 			if (usb2_com_get_data(sc->sc_ucom + sc->sc_curr_tx_unit,
 			    xfer->frbuffers, 1, sc->sc_tx_size - 1,
@@ -460,8 +403,9 @@ ubser_write_callback(struct usb2_xfer *x
 
 	default:			/* Error */
 		if (xfer->error != USB_ERR_CANCELLED) {
-			sc->sc_flags |= UBSER_FLAG_WRITE_STALL;
-			usb2_transfer_start(sc->sc_xfer[UBSER_BULK_CS_WR]);
+			/* try to clear stall first */
+			xfer->flags.stall_pipe = 1;
+			goto tr_setup;
 		}
 		return;
 
@@ -469,19 +413,6 @@ ubser_write_callback(struct usb2_xfer *x
 }
 
 static void
-ubser_read_clear_stall_callback(struct usb2_xfer *xfer)
-{
-	struct ubser_softc *sc = xfer->priv_sc;
-	struct usb2_xfer *xfer_other = sc->sc_xfer[UBSER_BULK_DT_RD];
-
-	if (usb2_clear_stall_callback(xfer, xfer_other)) {
-		DPRINTF("stall cleared\n");
-		sc->sc_flags &= ~UBSER_FLAG_READ_STALL;
-		usb2_transfer_start(xfer_other);
-	}
-}
-
-static void
 ubser_read_callback(struct usb2_xfer *xfer)
 {
 	struct ubser_softc *sc = xfer->priv_sc;
@@ -504,18 +435,15 @@ ubser_read_callback(struct usb2_xfer *xf
 
 	case USB_ST_SETUP:
 tr_setup:
-		if (sc->sc_flags & UBSER_FLAG_READ_STALL) {
-			usb2_transfer_start(sc->sc_xfer[UBSER_BULK_CS_RD]);
-		} else {
-			xfer->frlengths[0] = xfer->max_data_length;
-			usb2_start_hardware(xfer);
-		}
+		xfer->frlengths[0] = xfer->max_data_length;
+		usb2_start_hardware(xfer);
 		return;
 
 	default:			/* Error */
 		if (xfer->error != USB_ERR_CANCELLED) {
-			sc->sc_flags |= UBSER_FLAG_READ_STALL;
-			usb2_transfer_start(sc->sc_xfer[UBSER_BULK_CS_RD]);
+			/* try to clear stall first */
+			xfer->flags.stall_pipe = 1;
+			goto tr_setup;
 		}
 		return;
 
@@ -540,9 +468,8 @@ ubser_cfg_set_break(struct usb2_com_soft
 		req.wIndex[1] = 0;
 		USETW(req.wLength, 0);
 
-		err = usb2_do_request_flags
-		    (sc->sc_udev, &Giant, &req, NULL, 0, NULL, 1000);
-
+		err = usb2_com_cfg_do_request(sc->sc_udev, ucom, 
+		    &req, NULL, 0, 1000);
 		if (err) {
 			DPRINTFN(0, "send break failed, error=%s\n",
 			    usb2_errstr(err));
@@ -571,7 +498,6 @@ ubser_stop_read(struct usb2_com_softc *u
 {
 	struct ubser_softc *sc = ucom->sc_parent;
 
-	usb2_transfer_stop(sc->sc_xfer[UBSER_BULK_CS_RD]);
 	usb2_transfer_stop(sc->sc_xfer[UBSER_BULK_DT_RD]);
 }
 
@@ -588,6 +514,5 @@ ubser_stop_write(struct usb2_com_softc *
 {
 	struct ubser_softc *sc = ucom->sc_parent;
 
-	usb2_transfer_stop(sc->sc_xfer[UBSER_BULK_CS_WR]);
 	usb2_transfer_stop(sc->sc_xfer[UBSER_BULK_DT_WR]);
 }

Modified: head/sys/dev/usb2/serial/uchcom2.c
==============================================================================
--- head/sys/dev/usb2/serial/uchcom2.c	Mon Feb  9 22:02:38 2009	(r188412)
+++ head/sys/dev/usb2/serial/uchcom2.c	Mon Feb  9 22:05:25 2009	(r188413)
@@ -148,11 +148,8 @@ SYSCTL_INT(_hw_usb2_uchcom, OID_AUTO, de
 enum {
 	UCHCOM_BULK_DT_WR,
 	UCHCOM_BULK_DT_RD,
-	UCHCOM_BULK_CS_WR,
-	UCHCOM_BULK_CS_RD,
 	UCHCOM_INTR_DT_RD,
-	UCHCOM_INTR_CS_RD,
-	UCHCOM_N_TRANSFER = 6,
+	UCHCOM_N_TRANSFER,
 };
 
 struct uchcom_softc {
@@ -167,10 +164,6 @@ struct uchcom_softc {
 	uint8_t	sc_version;
 	uint8_t	sc_msr;
 	uint8_t	sc_lsr;			/* local status register */
-	uint8_t	sc_flag;
-#define	UCHCOM_FLAG_INTR_STALL  0x01
-#define	UCHCOM_FLAG_READ_STALL  0x02
-#define	UCHCOM_FLAG_WRITE_STALL 0x04
 };
 
 struct uchcom_divider {
@@ -230,11 +223,8 @@ static device_attach_t uchcom_attach;
 static device_detach_t uchcom_detach;
 
 static usb2_callback_t uchcom_intr_callback;
-static usb2_callback_t uchcom_intr_clear_stall_callback;
 static usb2_callback_t uchcom_write_callback;
-static usb2_callback_t uchcom_write_clear_stall_callback;
 static usb2_callback_t uchcom_read_callback;
-static usb2_callback_t uchcom_read_clear_stall_callback;
 
 static const struct usb2_config uchcom_config_data[UCHCOM_N_TRANSFER] = {
 
@@ -256,26 +246,6 @@ static const struct usb2_config uchcom_c
 		.mh.callback = &uchcom_read_callback,
 	},
 
-	[UCHCOM_BULK_CS_WR] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.callback = &uchcom_write_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
-
-	[UCHCOM_BULK_CS_RD] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.callback = &uchcom_read_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
-
 	[UCHCOM_INTR_DT_RD] = {
 		.type = UE_INTERRUPT,
 		.endpoint = UE_ADDR_ANY,
@@ -284,16 +254,6 @@ static const struct usb2_config uchcom_c
 		.mh.bufsize = 0,	/* use wMaxPacketSize */
 		.mh.callback = &uchcom_intr_callback,
 	},
-
-	[UCHCOM_INTR_CS_RD] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.callback = &uchcom_intr_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
 };
 
 struct usb2_com_callback uchcom_callback = {
@@ -378,8 +338,8 @@ uchcom_attach(device_t dev)
 	sc->sc_rts = 1;
 
 	/* clear stall at first run */
-	sc->sc_flag |= (UCHCOM_FLAG_READ_STALL |
-	    UCHCOM_FLAG_WRITE_STALL);
+	usb2_transfer_set_stall(sc->sc_xfer[UCHCOM_BULK_DT_WR]);
+	usb2_transfer_set_stall(sc->sc_xfer[UCHCOM_BULK_DT_RD]);
 
 	error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
 	    &uchcom_callback, &Giant);
@@ -412,35 +372,6 @@ uchcom_detach(device_t dev)
  */
 
 static void
-uchcom_do_request(struct uchcom_softc *sc,
-    struct usb2_device_request *req, void *data)
-{
-	uint16_t length;
-	uint16_t actlen;
-	usb2_error_t err;
-
-	length = UGETW(req->wLength);
-	actlen = 0;
-
-	if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
-		goto done;
-	}
-	err = usb2_do_request_flags(sc->sc_udev, &Giant, req,
-	    data, USB_SHORT_XFER_OK, &actlen, 1000);
-
-	if (err) {
-		DPRINTFN(0, "device request failed, err=%s "
-		    "(ignored)\n", usb2_errstr(err));
-	}
-done:
-	if (length != actlen) {
-		if (req->bmRequestType & UT_READ) {
-			bzero(USB_ADD_BYTES(data, actlen), length - actlen);
-		}
-	}
-}
-
-static void
 uchcom_ctrl_write(struct uchcom_softc *sc, uint8_t reqno,
     uint16_t value, uint16_t index)
 {
@@ -452,7 +383,8 @@ uchcom_ctrl_write(struct uchcom_softc *s
 	USETW(req.wIndex, index);
 	USETW(req.wLength, 0);
 
-	uchcom_do_request(sc, &req, NULL);
+	usb2_com_cfg_do_request(sc->sc_udev,
+	    &sc->sc_ucom, &req, NULL, 0, 1000);
 }
 
 static void
@@ -467,7 +399,8 @@ uchcom_ctrl_read(struct uchcom_softc *sc
 	USETW(req.wIndex, index);
 	USETW(req.wLength, buflen);
 
-	uchcom_do_request(sc, &req, buf);
+	usb2_com_cfg_do_request(sc->sc_udev,
+	    &sc->sc_ucom, &req, buf, USB_SHORT_XFER_OK, 1000);
 }
 
 static void
@@ -812,7 +745,6 @@ uchcom_stop_read(struct usb2_com_softc *
 	usb2_transfer_stop(sc->sc_xfer[UCHCOM_INTR_DT_RD]);
 
 	/* stop read endpoint */
-	usb2_transfer_stop(sc->sc_xfer[UCHCOM_BULK_CS_RD]);
 	usb2_transfer_stop(sc->sc_xfer[UCHCOM_BULK_DT_RD]);
 }
 
@@ -829,7 +761,6 @@ uchcom_stop_write(struct usb2_com_softc 
 {
 	struct uchcom_softc *sc = ucom->sc_parent;
 
-	usb2_transfer_stop(sc->sc_xfer[UCHCOM_BULK_CS_WR]);
 	usb2_transfer_stop(sc->sc_xfer[UCHCOM_BULK_DT_WR]);
 }
 
@@ -859,37 +790,22 @@ uchcom_intr_callback(struct usb2_xfer *x
 			usb2_com_status_change(&sc->sc_ucom);
 		}
 	case USB_ST_SETUP:
-		if (sc->sc_flag & UCHCOM_FLAG_INTR_STALL) {
-			usb2_transfer_start(sc->sc_xfer[UCHCOM_INTR_CS_RD]);
-		} else {
-			xfer->frlengths[0] = xfer->max_data_length;
-			usb2_start_hardware(xfer);
-		}
+tr_setup:
+		xfer->frlengths[0] = xfer->max_data_length;
+		usb2_start_hardware(xfer);
 		break;
 
 	default:			/* Error */
 		if (xfer->error != USB_ERR_CANCELLED) {
-			sc->sc_flag |= UCHCOM_FLAG_INTR_STALL;
-			usb2_transfer_start(sc->sc_xfer[UCHCOM_INTR_CS_RD]);
+			/* try to clear stall first */
+			xfer->flags.stall_pipe = 1;
+			goto tr_setup;
 		}
 		break;
 	}
 }
 
 static void
-uchcom_intr_clear_stall_callback(struct usb2_xfer *xfer)
-{
-	struct uchcom_softc *sc = xfer->priv_sc;
-	struct usb2_xfer *xfer_other = sc->sc_xfer[UCHCOM_INTR_DT_RD];
-
-	if (usb2_clear_stall_callback(xfer, xfer_other)) {
-		DPRINTF("stall cleared\n");
-		sc->sc_flag &= ~UCHCOM_FLAG_INTR_STALL;
-		usb2_transfer_start(xfer_other);
-	}
-}
-
-static void
 uchcom_write_callback(struct usb2_xfer *xfer)

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-head mailing list