Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Jan 2009 19:03:48 +0000 (UTC)
From:      Andrew Thompson <thompsa@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r187176 - head/sys/dev/usb2/serial
Message-ID:  <200901131903.n0DJ3mP4012621@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: thompsa
Date: Tue Jan 13 19:03:47 2009
New Revision: 187176
URL: http://svn.freebsd.org/changeset/base/187176

Log:
  MFp4: //depot/projects/usb@155917
  
  	Remove dependancy towards the USB config thread in
  	the USB serial core. Use USB process msignalling
  	instead. Saves a little memory and hopefully makes
  	the code more understandable.
  
  Submitted by: Hans Petter Selasky

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	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/u3g2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -44,7 +44,6 @@
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/uark2.c
==============================================================================
--- head/sys/dev/usb2/serial/uark2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/uark2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -34,7 +34,6 @@
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/ubsa2.c
==============================================================================
--- head/sys/dev/usb2/serial/ubsa2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/ubsa2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -73,7 +73,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/ubser2.c
==============================================================================
--- head/sys/dev/usb2/serial/ubser2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/ubser2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -87,7 +87,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/uchcom2.c
==============================================================================
--- head/sys/dev/usb2/serial/uchcom2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/uchcom2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -81,7 +81,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/ucycom2.c
==============================================================================
--- head/sys/dev/usb2/serial/ucycom2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/ucycom2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/ufoma2.c
==============================================================================
--- head/sys/dev/usb2/serial/ufoma2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/ufoma2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -93,7 +93,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/uftdi2.c
==============================================================================
--- head/sys/dev/usb2/serial/uftdi2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/uftdi2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -59,7 +59,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/ugensa2.c
==============================================================================
--- head/sys/dev/usb2/serial/ugensa2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/ugensa2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -54,7 +54,6 @@
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/uipaq2.c
==============================================================================
--- head/sys/dev/usb2/serial/uipaq2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/uipaq2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -62,7 +62,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/ulpt2.c
==============================================================================
--- head/sys/dev/usb2/serial/ulpt2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/ulpt2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -55,7 +55,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/umct2.c
==============================================================================
--- head/sys/dev/usb2/serial/umct2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/umct2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -56,7 +56,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/umodem2.c
==============================================================================
--- head/sys/dev/usb2/serial/umodem2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/umodem2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -92,7 +92,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/umoscom2.c
==============================================================================
--- head/sys/dev/usb2/serial/umoscom2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/umoscom2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -28,7 +28,6 @@
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/uplcom2.c
==============================================================================
--- head/sys/dev/usb2/serial/uplcom2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/uplcom2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -95,7 +95,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/usb2_serial.c
==============================================================================
--- head/sys/dev/usb2/serial/usb2_serial.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/usb2_serial.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -78,13 +78,10 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/include/usb2_cdc.h>
 
 #define	USB_DEBUG_VAR usb2_com_debug
-#define	usb2_config_td_cc usb2_com_config_copy
-#define	usb2_config_td_softc usb2_com_softc
 
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_busdma.h>
 #include <dev/usb2/core/usb2_util.h>
@@ -99,30 +96,26 @@ SYSCTL_INT(_hw_usb2_ucom, OID_AUTO, debu
     &usb2_com_debug, 0, "ucom debug level");
 #endif
 
-struct usb2_com_config_copy {
-	struct usb2_com_softc *cc_softc;
-	uint8_t	cc_flag0;
-	uint8_t	cc_flag1;
-	uint8_t	cc_flag2;
-	uint8_t	cc_flag3;
-};
-
-static usb2_config_td_command_t usb2_com_config_copy;
-static usb2_config_td_command_t usb2_com_cfg_start_transfers;
-static usb2_config_td_command_t usb2_com_cfg_open;
-static usb2_config_td_command_t usb2_com_cfg_close;
-static usb2_config_td_command_t usb2_com_cfg_break;
-static usb2_config_td_command_t usb2_com_cfg_dtr;
-static usb2_config_td_command_t usb2_com_cfg_rts;
-static usb2_config_td_command_t usb2_com_cfg_status_change;
-static usb2_config_td_command_t usb2_com_cfg_param;
+static usb2_proc_callback_t usb2_com_cfg_start_transfers;
+static usb2_proc_callback_t usb2_com_cfg_open;
+static usb2_proc_callback_t usb2_com_cfg_close;
+static usb2_proc_callback_t usb2_com_cfg_break_on;
+static usb2_proc_callback_t usb2_com_cfg_break_off;
+static usb2_proc_callback_t usb2_com_cfg_dtr_on;
+static usb2_proc_callback_t usb2_com_cfg_dtr_off;
+static usb2_proc_callback_t usb2_com_cfg_rts_on;
+static usb2_proc_callback_t usb2_com_cfg_rts_off;
+static usb2_proc_callback_t usb2_com_cfg_status_change;
+static usb2_proc_callback_t usb2_com_cfg_param;
 
 static uint8_t	usb2_com_units_alloc(uint32_t, uint32_t *);
 static void	usb2_com_units_free(uint32_t, uint32_t);
 static int	usb2_com_attach_sub(struct usb2_com_softc *);
 static void	usb2_com_detach_sub(struct usb2_com_softc *);
-static void	usb2_com_queue_command(struct usb2_com_softc *,
-		    usb2_config_td_command_t *, int);
+static void	usb2_com_queue_command(struct usb2_com_softc *sc,
+		    uint8_t cmd);
+static void	usb2_com_wait_command(struct usb2_com_softc *sc,
+		    uint8_t cmd);
 static void	usb2_com_shutdown(struct usb2_com_softc *);
 static void	usb2_com_start_transfers(struct usb2_com_softc *);
 static void	usb2_com_break(struct usb2_com_softc *, uint8_t);
@@ -251,9 +244,7 @@ usb2_com_attach(struct usb2_com_super_so
 	if (usb2_com_units_alloc(sub_units, &root_unit)) {
 		return (ENOMEM);
 	}
-	if (usb2_config_td_setup
-	    (&ssc->sc_config_td, sc, p_mtx, NULL,
-	    sizeof(struct usb2_com_config_copy), 24 * sub_units)) {
+	if (usb2_proc_setup(&ssc->sc_config_td, p_mtx, USB_PRI_MED)) {
 		usb2_com_units_free(root_unit, sub_units);
 		return (ENOMEM);
 	}
@@ -285,7 +276,7 @@ usb2_com_detach(struct usb2_com_super_so
 {
 	uint32_t n;
 
-	usb2_config_td_drain(&ssc->sc_config_td);
+	usb2_proc_drain(&ssc->sc_config_td);
 
 	for (n = 0; n < sub_units; n++, sc++) {
 		if (sc->sc_flag & UCOM_FLAG_ATTACHED) {
@@ -298,8 +289,7 @@ usb2_com_detach(struct usb2_com_super_so
 			sc->sc_flag &= ~UCOM_FLAG_ATTACHED;
 		}
 	}
-
-	usb2_config_td_unsetup(&ssc->sc_config_td);
+	usb2_proc_unsetup(&ssc->sc_config_td);
 }
 
 static int
@@ -307,6 +297,7 @@ usb2_com_attach_sub(struct usb2_com_soft
 {
 	struct tty *tp;
 	int error = 0;
+	uint8_t n;
 	char buf[32];			/* temporary TTY device name buffer */
 
 	tp = tty_alloc(&usb2_com_class, sc, sc->sc_parent_mtx);
@@ -336,6 +327,39 @@ usb2_com_attach_sub(struct usb2_com_soft
 	DPRINTF("ttycreate: %s\n", buf);
 	usb2_cv_init(&sc->sc_cv, "usb2_com");
 
+	/* 
+	 * Set all function callback pointers for deferred COM
+	 * operations:
+	 */
+	for (n = 0; n != 2; n++) {
+		sc->sc_cmds[(2*USB_COM_CFG_START_TRANSFERS) + n].hdr.pm_callback = 
+		    &usb2_com_cfg_start_transfers;
+		sc->sc_cmds[(2*USB_COM_CFG_OPEN) + n].hdr.pm_callback = 
+		    &usb2_com_cfg_open;
+		sc->sc_cmds[(2*USB_COM_CFG_CLOSE) + n].hdr.pm_callback = 
+		    &usb2_com_cfg_close;
+		sc->sc_cmds[(2*USB_COM_CFG_BREAK_ON) + n].hdr.pm_callback = 
+		    &usb2_com_cfg_break_on;
+		sc->sc_cmds[(2*USB_COM_CFG_BREAK_OFF) + n].hdr.pm_callback = 
+		    &usb2_com_cfg_break_off;
+		sc->sc_cmds[(2*USB_COM_CFG_DTR_ON) + n].hdr.pm_callback = 
+		    &usb2_com_cfg_dtr_on;
+		sc->sc_cmds[(2*USB_COM_CFG_DTR_OFF) + n].hdr.pm_callback = 
+		    &usb2_com_cfg_dtr_off;
+		sc->sc_cmds[(2*USB_COM_CFG_RTS_ON) + n].hdr.pm_callback = 
+		    &usb2_com_cfg_rts_on;
+		sc->sc_cmds[(2*USB_COM_CFG_RTS_OFF) + n].hdr.pm_callback = 
+		    &usb2_com_cfg_rts_off;
+		sc->sc_cmds[(2*USB_COM_CFG_STATUS_CHANGE) + n].hdr.pm_callback = 
+		    &usb2_com_cfg_status_change;
+		sc->sc_cmds[(2*USB_COM_CFG_PARAM) + n].hdr.pm_callback = 
+		    &usb2_com_cfg_param;
+	}
+
+	/* initialise all callback pointer arguments */
+	for (n = 0; n != (2*USB_COM_CFG_MAX); n++) {
+		sc->sc_cmds[n].cc_softc = sc;
+	}
 done:
 	return (error);
 }
@@ -379,27 +403,41 @@ usb2_com_detach_sub(struct usb2_com_soft
 	usb2_cv_destroy(&sc->sc_cv);
 }
 
+/*
+ * The following function queues a command for deferred execution.
+ * The following function must be called locked.
+ */
 static void
-usb2_com_config_copy(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc,
-    uint16_t refcount)
+usb2_com_queue_command(struct usb2_com_softc *sc, uint8_t cmd)
 {
-	cc->cc_softc = sc + (refcount % UCOM_SUB_UNIT_MAX);
-	cc->cc_flag0 = (refcount / (1 * UCOM_SUB_UNIT_MAX)) % 2;
-	cc->cc_flag1 = (refcount / (2 * UCOM_SUB_UNIT_MAX)) % 2;
-	cc->cc_flag2 = (refcount / (4 * UCOM_SUB_UNIT_MAX)) % 2;
-	cc->cc_flag3 = (refcount / (8 * UCOM_SUB_UNIT_MAX)) % 2;
+	struct usb2_com_super_softc *ssc = sc->sc_super;
+
+	if (usb2_proc_is_gone(&ssc->sc_config_td)) {
+		DPRINTF("proc is gone\n");
+		return;		/* nothing to do */
+	}
+
+	if (usb2_proc_msignal(&ssc->sc_config_td, 
+	    &sc->sc_cmds[2*cmd], &sc->sc_cmds[(2*cmd)+1])) {
+		/* ignore */
+	}
 }
 
+/*
+ * The following function waits until a command has been executed.
+ * The following function must be called locked.
+ */
 static void
-usb2_com_queue_command(struct usb2_com_softc *sc, usb2_config_td_command_t *cmd, int flag)
+usb2_com_wait_command(struct usb2_com_softc *sc, uint8_t cmd)
 {
 	struct usb2_com_super_softc *ssc = sc->sc_super;
 
-	usb2_config_td_queue_command
-	    (&ssc->sc_config_td, &usb2_com_config_copy,
-	    cmd, (cmd == &usb2_com_cfg_status_change) ? 1 : 0,
-	    ((sc->sc_local_unit % UCOM_SUB_UNIT_MAX) +
-	    (flag ? UCOM_SUB_UNIT_MAX : 0)));
+	if (usb2_proc_is_gone(&ssc->sc_config_td)) {
+		DPRINTF("proc is gone\n");
+		return;		/* nothing to do */
+	}
+	usb2_proc_mwait(&ssc->sc_config_td, 
+	    &sc->sc_cmds[2*cmd], &sc->sc_cmds[(2*cmd)+1]);
 }
 
 static void
@@ -420,6 +458,8 @@ usb2_com_shutdown(struct usb2_com_softc 
 }
 
 /*
+ * This function will sleep "timeout" system ticks.
+ *
  * Return values:
  *    0: normal delay
  * else: config thread is gone
@@ -428,8 +468,26 @@ uint8_t
 usb2_com_cfg_sleep(struct usb2_com_softc *sc, uint32_t timeout)
 {
 	struct usb2_com_super_softc *ssc = sc->sc_super;
+	uint8_t is_gone;
+
+	is_gone = usb2_proc_is_gone(&ssc->sc_config_td);
+	if (is_gone)
+		goto done;	/* we are detaching */
+	if (timeout == 0)
+		timeout = 1;	/* one tick is the least timeout */
+
+	mtx_unlock(sc->sc_parent_mtx);
+
+	if (pause("UCOMWAIT", timeout)) {
+		/* ignore */
+	}
 
-	return (usb2_config_td_sleep(&ssc->sc_config_td, timeout));
+	mtx_lock(sc->sc_parent_mtx);
+
+	/* refresh gone status */
+	is_gone = usb2_proc_is_gone(&ssc->sc_config_td);
+done:
+	return (is_gone);
 }
 
 /*
@@ -442,13 +500,15 @@ usb2_com_cfg_is_gone(struct usb2_com_sof
 {
 	struct usb2_com_super_softc *ssc = sc->sc_super;
 
-	return (usb2_config_td_is_gone(&ssc->sc_config_td));
+	return (usb2_proc_is_gone(&ssc->sc_config_td));
 }
 
 static void
-usb2_com_cfg_start_transfers(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc,
-    uint16_t refcount)
+usb2_com_cfg_start_transfers(struct usb2_proc_msg *_cc)
 {
+	struct usb2_com_command_msg *cc = (void *)_cc;
+	struct usb2_com_softc *sc;
+
 	sc = cc->cc_softc;
 
 	if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
@@ -485,14 +545,16 @@ usb2_com_start_transfers(struct usb2_com
 		(sc->sc_callback->usb2_com_start_write) (sc);
 	}
 	if (!(sc->sc_flag & UCOM_FLAG_GP_DATA)) {
-		usb2_com_queue_command(sc, &usb2_com_cfg_start_transfers, 0);
+		usb2_com_queue_command(sc, USB_COM_CFG_START_TRANSFERS);
 	}
 }
 
 static void
-usb2_com_cfg_open(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc,
-    uint16_t refcount)
+usb2_com_cfg_open(struct usb2_proc_msg *_cc)
 {
+	struct usb2_com_command_msg *cc = (void *)_cc;
+	struct usb2_com_softc *sc;
+
 	sc = cc->cc_softc;
 
 	DPRINTF("\n");
@@ -550,7 +612,7 @@ usb2_com_open(struct tty *tp)
 	sc->sc_msr = 0;
 	sc->sc_mcr = 0;
 
-	usb2_com_queue_command(sc, &usb2_com_cfg_open, 0);
+	usb2_com_queue_command(sc, USB_COM_CFG_OPEN);
 
 	usb2_com_start_transfers(sc);
 
@@ -564,9 +626,11 @@ usb2_com_open(struct tty *tp)
 }
 
 static void
-usb2_com_cfg_close(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc,
-    uint16_t refcount)
+usb2_com_cfg_close(struct usb2_proc_msg *_cc)
 {
+	struct usb2_com_command_msg *cc = (void *)_cc;
+	struct usb2_com_softc *sc;
+
 	sc = cc->cc_softc;
 
 	DPRINTF("\n");
@@ -588,7 +652,6 @@ static void
 usb2_com_close(struct tty *tp)
 {
 	struct usb2_com_softc *sc = tty_softc(tp);
-	struct usb2_com_super_softc *ssc = sc->sc_super;
 	
 	mtx_assert(sc->sc_parent_mtx, MA_OWNED);
 
@@ -600,8 +663,9 @@ usb2_com_close(struct tty *tp)
 	}
 	usb2_com_shutdown(sc);
 
-	usb2_com_queue_command(sc, &usb2_com_cfg_close, 0);
-	usb2_config_td_sync(&ssc->sc_config_td);
+	/* Queue and wait for close command to complete */
+	usb2_com_queue_command(sc, USB_COM_CFG_CLOSE);
+	usb2_com_wait_command(sc, USB_COM_CFG_CLOSE);
 
 	sc->sc_flag &= ~(UCOM_FLAG_HL_READY |
 	    UCOM_FLAG_WR_START |
@@ -704,22 +768,35 @@ usb2_com_modem(struct tty *tp, int sigon
 }
 
 static void
-usb2_com_cfg_break(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc,
-    uint16_t refcount)
+usb2_com_cfg_break(struct usb2_com_command_msg *cc, uint8_t onoff)
 {
+	struct usb2_com_softc *sc;
+
 	sc = cc->cc_softc;
 
 	if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
 		return;
 	}
-	DPRINTF("onoff=%d\n", cc->cc_flag0);
+	DPRINTF("onoff=%d\n", onoff);
 
 	if (sc->sc_callback->usb2_com_cfg_set_break) {
-		(sc->sc_callback->usb2_com_cfg_set_break) (sc, cc->cc_flag0);
+		(sc->sc_callback->usb2_com_cfg_set_break) (sc, onoff);
 	}
 }
 
 static void
+usb2_com_cfg_break_on(struct usb2_proc_msg *_cc)
+{
+	usb2_com_cfg_break((void *)_cc, 1);
+}
+
+static void
+usb2_com_cfg_break_off(struct usb2_proc_msg *_cc)
+{
+	usb2_com_cfg_break((void *)_cc, 0);
+}
+
+static void
 usb2_com_break(struct usb2_com_softc *sc, uint8_t onoff)
 {
 	mtx_assert(sc->sc_parent_mtx, MA_OWNED);
@@ -729,26 +806,40 @@ usb2_com_break(struct usb2_com_softc *sc
 	}
 	DPRINTF("onoff = %d\n", onoff);
 
-	usb2_com_queue_command(sc, &usb2_com_cfg_break, onoff);
+	usb2_com_queue_command(sc, onoff ? 
+	    USB_COM_CFG_BREAK_ON : USB_COM_CFG_BREAK_OFF);
 }
 
 static void
-usb2_com_cfg_dtr(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc,
-    uint16_t refcount)
+usb2_com_cfg_dtr(struct usb2_com_command_msg *cc, uint8_t onoff)
 {
+	struct usb2_com_softc *sc;
+
 	sc = cc->cc_softc;
 
 	if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
 		return;
 	}
-	DPRINTF("onoff=%d\n", cc->cc_flag0);
+	DPRINTF("onoff=%d\n", onoff);
 
 	if (sc->sc_callback->usb2_com_cfg_set_dtr) {
-		(sc->sc_callback->usb2_com_cfg_set_dtr) (sc, cc->cc_flag0);
+		(sc->sc_callback->usb2_com_cfg_set_dtr) (sc, onoff);
 	}
 }
 
 static void
+usb2_com_cfg_dtr_on(struct usb2_proc_msg *_cc)
+{
+	usb2_com_cfg_dtr((void *)_cc, 1);
+}
+
+static void
+usb2_com_cfg_dtr_off(struct usb2_proc_msg *_cc)
+{
+	usb2_com_cfg_dtr((void *)_cc, 0);
+}
+
+static void
 usb2_com_dtr(struct usb2_com_softc *sc, uint8_t onoff)
 {
 	mtx_assert(sc->sc_parent_mtx, MA_OWNED);
@@ -758,26 +849,40 @@ usb2_com_dtr(struct usb2_com_softc *sc, 
 	}
 	DPRINTF("onoff = %d\n", onoff);
 
-	usb2_com_queue_command(sc, &usb2_com_cfg_dtr, onoff);
+	usb2_com_queue_command(sc, onoff ? 
+	    USB_COM_CFG_DTR_ON : USB_COM_CFG_DTR_OFF);
 }
 
 static void
-usb2_com_cfg_rts(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc,
-    uint16_t refcount)
+usb2_com_cfg_rts(struct usb2_com_command_msg *cc, uint8_t onoff)
 {
+	struct usb2_com_softc *sc;
+
 	sc = cc->cc_softc;
 
-	DPRINTF("onoff=%d\n", cc->cc_flag0);
+	DPRINTF("onoff=%d\n", onoff);
 
 	if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
 		return;
 	}
 	if (sc->sc_callback->usb2_com_cfg_set_rts) {
-		(sc->sc_callback->usb2_com_cfg_set_rts) (sc, cc->cc_flag0);
+		(sc->sc_callback->usb2_com_cfg_set_rts) (sc, onoff);
 	}
 }
 
 static void
+usb2_com_cfg_rts_on(struct usb2_proc_msg *_cc)
+{
+	usb2_com_cfg_rts((void *)_cc, 1);
+}
+
+static void
+usb2_com_cfg_rts_off(struct usb2_proc_msg *_cc)
+{
+	usb2_com_cfg_rts((void *)_cc, 0);
+}
+
+static void
 usb2_com_rts(struct usb2_com_softc *sc, uint8_t onoff)
 {
 	mtx_assert(sc->sc_parent_mtx, MA_OWNED);
@@ -787,13 +892,15 @@ usb2_com_rts(struct usb2_com_softc *sc, 
 	}
 	DPRINTF("onoff = %d\n", onoff);
 
-	usb2_com_queue_command(sc, &usb2_com_cfg_rts, onoff);
+	usb2_com_queue_command(sc, onoff ? 
+	    USB_COM_CFG_RTS_ON : USB_COM_CFG_RTS_OFF);
 }
 
 static void
-usb2_com_cfg_status_change(struct usb2_com_softc *sc,
-    struct usb2_com_config_copy *cc, uint16_t refcount)
+usb2_com_cfg_status_change(struct usb2_proc_msg *_cc)
 {
+	struct usb2_com_command_msg *cc = (void *)_cc;
+	struct usb2_com_softc *sc;
 	struct tty *tp;
 
 	uint8_t new_msr;
@@ -847,13 +954,14 @@ usb2_com_status_change(struct usb2_com_s
 	}
 	DPRINTF("\n");
 
-	usb2_com_queue_command(sc, &usb2_com_cfg_status_change, 0);
+	usb2_com_queue_command(sc, USB_COM_CFG_STATUS_CHANGE);
 }
 
 static void
-usb2_com_cfg_param(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc,
-    uint16_t refcount)
+usb2_com_cfg_param(struct usb2_proc_msg *_cc)
 {
+	struct usb2_com_command_msg *cc = (void *)_cc;
+	struct usb2_com_softc *sc;
 	struct termios t_copy;
 
 	sc = cc->cc_softc;
@@ -924,7 +1032,7 @@ usb2_com_param(struct tty *tp, struct te
 	sc->sc_flag &= ~UCOM_FLAG_GP_DATA;
 
 	/* Queue baud rate programming command first */
-	usb2_com_queue_command(sc, &usb2_com_cfg_param, 0);
+	usb2_com_queue_command(sc, USB_COM_CFG_PARAM);
 
 	/* Queue transfer enable command last */
 	usb2_com_start_transfers(sc);

Modified: head/sys/dev/usb2/serial/usb2_serial.h
==============================================================================
--- head/sys/dev/usb2/serial/usb2_serial.h	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/usb2_serial.h	Tue Jan 13 19:03:47 2009	(r187176)
@@ -119,11 +119,35 @@ struct usb2_com_callback {
 #define	ULSR_RXRDY	0x01		/* Byte ready in Receive Buffer */
 #define	ULSR_RCV_MASK	0x1f		/* Mask for incoming data or error */
 
+/*
+ * List of serial adapter commands or deferred function calls:
+ */
+enum {
+	USB_COM_CFG_START_TRANSFERS,
+	USB_COM_CFG_OPEN,
+	USB_COM_CFG_CLOSE,
+	USB_COM_CFG_BREAK_ON,
+	USB_COM_CFG_BREAK_OFF,
+	USB_COM_CFG_DTR_ON,
+	USB_COM_CFG_DTR_OFF,
+	USB_COM_CFG_RTS_ON,
+	USB_COM_CFG_RTS_OFF,
+	USB_COM_CFG_STATUS_CHANGE,
+	USB_COM_CFG_PARAM,
+	USB_COM_CFG_MAX,
+};
+
+struct usb2_com_command_msg {
+	struct usb2_proc_msg hdr;	/* must be first */
+	struct usb2_com_softc *cc_softc;
+};
+
 struct usb2_com_super_softc {
-	struct usb2_config_td sc_config_td;
+	struct usb2_process sc_config_td;
 };
 
 struct usb2_com_softc {
+	struct usb2_com_command_msg sc_cmds[2*USB_COM_CFG_MAX];
 	struct termios sc_termios_copy;
 	struct cv sc_cv;
 	const struct usb2_com_callback *sc_callback;
@@ -146,6 +170,7 @@ struct usb2_com_softc {
 	uint8_t	sc_msr;
 	uint8_t	sc_mcr;
 	uint8_t	sc_ttyfreed;		/* set when TTY has been freed */
+	uint8_t sc_last_cmd_flag[USB_COM_CFG_MAX];
 };
 
 int	usb2_com_attach(struct usb2_com_super_softc *ssc,

Modified: head/sys/dev/usb2/serial/uvisor2.c
==============================================================================
--- head/sys/dev/usb2/serial/uvisor2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/uvisor2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -66,7 +66,6 @@
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>

Modified: head/sys/dev/usb2/serial/uvscom2.c
==============================================================================
--- head/sys/dev/usb2/serial/uvscom2.c	Tue Jan 13 19:03:33 2009	(r187175)
+++ head/sys/dev/usb2/serial/uvscom2.c	Tue Jan 13 19:03:47 2009	(r187176)
@@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_debug.h>
 #include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
 #include <dev/usb2/core/usb2_request.h>
 #include <dev/usb2/core/usb2_lookup.h>
 #include <dev/usb2/core/usb2_util.h>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200901131903.n0DJ3mP4012621>