svn commit: r187751 - user/thompsa/usb/sys/dev/usb2/serial
Andrew Thompson
thompsa at FreeBSD.org
Mon Jan 26 17:23:27 PST 2009
Author: thompsa
Date: Tue Jan 27 01:23:25 2009
New Revision: 187751
URL: http://svn.freebsd.org/changeset/base/187751
Log:
Change over to usb2_proc w/ taskqueues.
Modified:
user/thompsa/usb/sys/dev/usb2/serial/uark2.c
user/thompsa/usb/sys/dev/usb2/serial/ubsa2.c
user/thompsa/usb/sys/dev/usb2/serial/uchcom2.c
user/thompsa/usb/sys/dev/usb2/serial/ucycom2.c
user/thompsa/usb/sys/dev/usb2/serial/ufoma2.c
user/thompsa/usb/sys/dev/usb2/serial/uftdi2.c
user/thompsa/usb/sys/dev/usb2/serial/uipaq2.c
user/thompsa/usb/sys/dev/usb2/serial/umct2.c
user/thompsa/usb/sys/dev/usb2/serial/umodem2.c
user/thompsa/usb/sys/dev/usb2/serial/umoscom2.c
user/thompsa/usb/sys/dev/usb2/serial/uplcom2.c
user/thompsa/usb/sys/dev/usb2/serial/usb2_serial.c
user/thompsa/usb/sys/dev/usb2/serial/usb2_serial.h
user/thompsa/usb/sys/dev/usb2/serial/uvscom2.c
Modified: user/thompsa/usb/sys/dev/usb2/serial/uark2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/uark2.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/uark2.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -457,9 +457,6 @@ 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);
Modified: user/thompsa/usb/sys/dev/usb2/serial/ubsa2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/ubsa2.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/ubsa2.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -382,9 +382,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);
Modified: user/thompsa/usb/sys/dev/usb2/serial/uchcom2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/uchcom2.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/uchcom2.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -425,9 +425,6 @@ uchcom_do_request(struct uchcom_softc *s
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);
@@ -435,7 +432,6 @@ uchcom_do_request(struct uchcom_softc *s
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);
Modified: user/thompsa/usb/sys/dev/usb2/serial/ucycom2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/ucycom2.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/ucycom2.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -2,7 +2,7 @@
__FBSDID("$FreeBSD$");
/*-
- * Copyright (c) 2004 Dag-Erling Coïdan Smørgrav
+ * Copyright (c) 2004 Dag-Erling Co�dan Sm�rgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -441,9 +441,6 @@ ucycom_cfg_write(struct ucycom_softc *sc
sc->sc_temp_cfg[3] = (baud >> 24) & 0xff;
sc->sc_temp_cfg[4] = cfg;
- if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
- return;
- }
err = usb2_do_request_flags
(sc->sc_udev, &Giant, &req, sc->sc_temp_cfg, 0, NULL, 1000);
Modified: user/thompsa/usb/sys/dev/usb2/serial/ufoma2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/ufoma2.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/ufoma2.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -534,9 +534,6 @@ ufoma_cfg_do_request(struct ufoma_softc
uint16_t length;
usb2_error_t err;
- if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
- goto error;
- }
err = usb2_do_request_flags
(sc->sc_udev, &Giant, req, data, 0, NULL, 1000);
@@ -545,7 +542,6 @@ ufoma_cfg_do_request(struct ufoma_softc
DPRINTFN(0, "device request failed, err=%s "
"(ignored)\n", usb2_errstr(err));
-error:
length = UGETW(req->wLength);
if ((req->bmRequestType & UT_READ) && length) {
Modified: user/thompsa/usb/sys/dev/usb2/serial/uftdi2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/uftdi2.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/uftdi2.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -367,9 +367,6 @@ uftdi_cfg_do_request(struct uftdi_softc
uint16_t length;
usb2_error_t err;
- if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
- goto error;
- }
err = usb2_do_request_flags
(sc->sc_udev, &Giant, req, data, 0, NULL, 1000);
@@ -378,7 +375,6 @@ uftdi_cfg_do_request(struct uftdi_softc
DPRINTFN(0, "device request failed, err=%s "
"(ignored)\n", usb2_errstr(err));
-error:
length = UGETW(req->wLength);
if ((req->bmRequestType & UT_READ) && length) {
Modified: user/thompsa/usb/sys/dev/usb2/serial/uipaq2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/uipaq2.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/uipaq2.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -1234,9 +1234,6 @@ uipaq_cfg_do_request(struct uipaq_softc
uint16_t length;
usb2_error_t err;
- if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
- goto error;
- }
err = usb2_do_request(sc->sc_udev, &Giant, req, data);
if (err) {
@@ -1244,7 +1241,6 @@ uipaq_cfg_do_request(struct uipaq_softc
DPRINTFN(0, "device request failed, err=%s "
"(ignored)\n", usb2_errstr(err));
-error:
length = UGETW(req->wLength);
if ((req->bmRequestType & UT_READ) && length) {
Modified: user/thompsa/usb/sys/dev/usb2/serial/umct2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/umct2.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/umct2.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -352,9 +352,6 @@ umct_cfg_do_request(struct umct_softc *s
usb2_error_t err;
uint8_t temp[4];
- if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
- goto done;
- }
if (len > 4) {
len = 4;
}
@@ -373,8 +370,6 @@ umct_cfg_do_request(struct umct_softc *s
DPRINTFN(0, "device request failed, err=%s "
"(ignored)\n", usb2_errstr(err));
}
-done:
- return;
}
static void
Modified: user/thompsa/usb/sys/dev/usb2/serial/umodem2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/umodem2.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/umodem2.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -890,9 +890,6 @@ umodem_cfg_do_request(struct umodem_soft
uint16_t length;
usb2_error_t err;
- if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
- goto error;
- }
err = usb2_do_request_flags(sc->sc_udev, &Giant, req,
data, 0, NULL, 1000);
@@ -901,7 +898,6 @@ umodem_cfg_do_request(struct umodem_soft
DPRINTFN(0, "device request failed, err=%s "
"(ignored)\n", usb2_errstr(err));
-error:
length = UGETW(req->wLength);
if ((req->bmRequestType & UT_READ) && length) {
Modified: user/thompsa/usb/sys/dev/usb2/serial/umoscom2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/umoscom2.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/umoscom2.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -590,16 +590,12 @@ umoscom_cfg_do_request(struct umoscom_so
uint16_t length;
usb2_error_t err;
- if (usb2_com_cfg_is_gone(&sc->sc_ucom))
- goto error;
-
err = usb2_do_request_flags
(sc->sc_udev, &Giant, req, data, 0, NULL, 1000);
if (err) {
DPRINTFN(0, "control request failed: %s\n",
usb2_errstr(err));
-error:
length = UGETW(req->wLength);
if ((req->bmRequestType & UT_READ) && length) {
Modified: user/thompsa/usb/sys/dev/usb2/serial/uplcom2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/uplcom2.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/uplcom2.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -930,9 +930,6 @@ uplcom_cfg_do_request(struct uplcom_soft
uint16_t length;
usb2_error_t err;
- if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
- goto error;
- }
err = usb2_do_request_flags(sc->sc_udev, &Giant, req,
data, 0, NULL, 1000);
@@ -941,7 +938,6 @@ uplcom_cfg_do_request(struct uplcom_soft
DPRINTFN(0, "device request failed, err=%s "
"(ignored)\n", usb2_errstr(err));
-error:
length = UGETW(req->wLength);
if ((req->bmRequestType & UT_READ) && length) {
Modified: user/thompsa/usb/sys/dev/usb2/serial/usb2_serial.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/usb2_serial.c Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/usb2_serial.c Tue Jan 27 01:23:25 2009 (r187751)
@@ -96,26 +96,21 @@ SYSCTL_INT(_hw_usb2_ucom, OID_AUTO, debu
&usb2_com_debug, 0, "ucom debug level");
#endif
-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 usb2_task_fn_t usb2_com_cfg_start_transfers;
+static usb2_task_fn_t usb2_com_cfg_open;
+static usb2_task_fn_t usb2_com_cfg_close;
+static usb2_task_fn_t usb2_com_cfg_break;
+static usb2_task_fn_t usb2_com_cfg_dtr;
+static usb2_task_fn_t usb2_com_cfg_rts;
+static usb2_task_fn_t usb2_com_cfg_status_change;
+static usb2_task_fn_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 *sc,
- uint8_t cmd);
-static void usb2_com_wait_command(struct usb2_com_softc *sc,
- uint8_t cmd);
+static int usb2_com_attach_tty(struct usb2_com_softc *);
+static void usb2_com_detach_tty(struct usb2_com_softc *);
+static void usb2_com_queue_command(struct usb2_com_softc *,
+ struct usb2_task *, int);
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);
@@ -127,14 +122,14 @@ static tsw_close_t usb2_com_close;
static tsw_ioctl_t usb2_com_ioctl;
static tsw_modem_t usb2_com_modem;
static tsw_param_t usb2_com_param;
-static tsw_outwakeup_t usb2_com_start_write;
+static tsw_outwakeup_t usb2_com_outwakeup;
static tsw_free_t usb2_com_free;
static struct ttydevsw usb2_com_class = {
.tsw_flags = TF_INITLOCK | TF_CALLOUT,
.tsw_open = usb2_com_open,
.tsw_close = usb2_com_close,
- .tsw_outwakeup = usb2_com_start_write,
+ .tsw_outwakeup = usb2_com_outwakeup,
.tsw_ioctl = usb2_com_ioctl,
.tsw_param = usb2_com_param,
.tsw_modem = usb2_com_modem,
@@ -221,15 +216,15 @@ usb2_com_units_free(uint32_t root_unit,
* sub-units can be used to differentiate among
* different types of devices.
*
- * The mutex pointed to by "p_mtx" is applied before all
- * callbacks are called back. Also "p_mtx" must be applied
+ * The mutex pointed to by "mtx" is applied before all
+ * callbacks are called back. Also "mtx" must be applied
* before calling into the ucom-layer! Currently only Giant
* is supported.
*/
int
usb2_com_attach(struct usb2_com_super_softc *ssc, struct usb2_com_softc *sc,
uint32_t sub_units, void *parent,
- const struct usb2_com_callback *callback, struct mtx *p_mtx)
+ const struct usb2_com_callback *callback, struct mtx *mtx)
{
uint32_t n;
uint32_t root_unit;
@@ -244,26 +239,39 @@ usb2_com_attach(struct usb2_com_super_so
if (usb2_com_units_alloc(sub_units, &root_unit)) {
return (ENOMEM);
}
- if (usb2_proc_setup(&ssc->sc_config_td, p_mtx, USB_PRI_MED)) {
- usb2_com_units_free(root_unit, sub_units);
- return (ENOMEM);
- }
+
+ error = usb2_proc_create(&ssc->sc_tq, USB_PRI_MED, "ucom");
+ if (error)
+ return (error);
+
for (n = 0; n < sub_units; n++, sc++) {
sc->sc_unit = root_unit + n;
sc->sc_local_unit = n;
sc->sc_super = ssc;
- sc->sc_parent_mtx = p_mtx;
+ sc->sc_mtx = mtx;
sc->sc_parent = parent;
sc->sc_callback = callback;
- error = usb2_com_attach_sub(sc);
+ error = usb2_com_attach_tty(sc);
if (error) {
usb2_com_detach(ssc, sc - n, n);
usb2_com_units_free(root_unit + n, sub_units - n);
- break;
+ goto error;
}
sc->sc_flag |= UCOM_FLAG_ATTACHED;
+
+ USB_TASK_INIT(&sc->sc_start_task, usb2_com_cfg_start_transfers, sc, mtx);
+ USB_TASK_INIT(&sc->sc_open_task, usb2_com_cfg_open, sc, mtx);
+ USB_TASK_INIT(&sc->sc_close_task, usb2_com_cfg_close, sc, mtx);
+ USB_TASK_INIT(&sc->sc_break_task, usb2_com_cfg_break, sc, mtx);
+ USB_TASK_INIT(&sc->sc_dtr_task, usb2_com_cfg_dtr, sc, mtx);
+ USB_TASK_INIT(&sc->sc_rts_task, usb2_com_cfg_rts, sc, mtx);
+ USB_TASK_INIT(&sc->sc_status_task, usb2_com_cfg_status_change, sc, mtx);
+ USB_TASK_INIT(&sc->sc_param_task, usb2_com_cfg_param, sc, mtx);
}
+ return (0);
+error:
+ usb2_proc_free(&ssc->sc_tq);
return (error);
}
@@ -276,12 +284,10 @@ usb2_com_detach(struct usb2_com_super_so
{
uint32_t n;
- usb2_proc_drain(&ssc->sc_config_td);
-
for (n = 0; n < sub_units; n++, sc++) {
if (sc->sc_flag & UCOM_FLAG_ATTACHED) {
- usb2_com_detach_sub(sc);
+ usb2_com_detach_tty(sc);
usb2_com_units_free(sc->sc_unit, 1);
@@ -289,18 +295,17 @@ usb2_com_detach(struct usb2_com_super_so
sc->sc_flag &= ~UCOM_FLAG_ATTACHED;
}
}
- usb2_proc_unsetup(&ssc->sc_config_td);
+ usb2_proc_free(&ssc->sc_tq);
}
static int
-usb2_com_attach_sub(struct usb2_com_softc *sc)
+usb2_com_attach_tty(struct usb2_com_softc *sc)
{
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);
+ tp = tty_alloc(&usb2_com_class, sc, sc->sc_mtx);
if (tp == NULL) {
error = ENOMEM;
goto done;
@@ -327,45 +332,12 @@ 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);
}
static void
-usb2_com_detach_sub(struct usb2_com_softc *sc)
+usb2_com_detach_tty(struct usb2_com_softc *sc)
{
struct tty *tp = sc->sc_tty;
@@ -373,11 +345,11 @@ usb2_com_detach_sub(struct usb2_com_soft
/* the config thread has been stopped when we get here */
- mtx_lock(sc->sc_parent_mtx);
+ mtx_lock(sc->sc_mtx);
sc->sc_flag |= UCOM_FLAG_GONE;
sc->sc_flag &= ~(UCOM_FLAG_HL_READY |
UCOM_FLAG_LL_READY);
- mtx_unlock(sc->sc_parent_mtx);
+ mtx_unlock(sc->sc_mtx);
if (tp) {
tty_lock(tp);
@@ -385,10 +357,10 @@ usb2_com_detach_sub(struct usb2_com_soft
tty_rel_gone(tp);
- mtx_lock(sc->sc_parent_mtx);
+ mtx_lock(sc->sc_mtx);
/* Wait for the callback after the TTY is torn down */
while (sc->sc_ttyfreed == 0)
- usb2_cv_wait(&sc->sc_cv, sc->sc_parent_mtx);
+ usb2_cv_wait(&sc->sc_cv, sc->sc_mtx);
/*
* make sure that read and write transfers are stopped
*/
@@ -398,46 +370,20 @@ usb2_com_detach_sub(struct usb2_com_soft
if (sc->sc_callback->usb2_com_stop_write) {
(sc->sc_callback->usb2_com_stop_write) (sc);
}
- mtx_unlock(sc->sc_parent_mtx);
+ mtx_unlock(sc->sc_mtx);
}
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_queue_command(struct usb2_com_softc *sc, uint8_t cmd)
+usb2_com_queue_command(struct usb2_com_softc *sc, struct usb2_task *task, int arg)
{
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 */
- }
+ mtx_assert(sc->sc_mtx, MA_OWNED);
- 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_wait_command(struct usb2_com_softc *sc, uint8_t cmd)
-{
- 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 */
- }
- usb2_proc_mwait(&ssc->sc_config_td,
- &sc->sc_cmds[2*cmd], &sc->sc_cmds[(2*cmd)+1]);
+ USB_TASK_ARG(task) = arg;
+ usb2_proc_enqueue(&ssc->sc_tq, task);
}
static void
@@ -445,7 +391,7 @@ usb2_com_shutdown(struct usb2_com_softc
{
struct tty *tp = sc->sc_tty;
- mtx_assert(sc->sc_parent_mtx, MA_OWNED);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
DPRINTF("\n");
@@ -457,59 +403,10 @@ usb2_com_shutdown(struct usb2_com_softc
}
}
-/*
- * This function will sleep "timeout" system ticks.
- *
- * Return values:
- * 0: normal delay
- * else: config thread is gone
- */
-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 */
- }
-
- mtx_lock(sc->sc_parent_mtx);
-
- /* refresh gone status */
- is_gone = usb2_proc_is_gone(&ssc->sc_config_td);
-done:
- return (is_gone);
-}
-
-/*
- * Return values:
- * 0: normal
- * else: config thread is gone
- */
-uint8_t
-usb2_com_cfg_is_gone(struct usb2_com_softc *sc)
-{
- struct usb2_com_super_softc *ssc = sc->sc_super;
-
- return (usb2_proc_is_gone(&ssc->sc_config_td));
-}
-
static void
-usb2_com_cfg_start_transfers(struct usb2_proc_msg *_cc)
+usb2_com_cfg_start_transfers(void *context, struct usb2_task *task)
{
- struct usb2_com_command_msg *cc = (void *)_cc;
- struct usb2_com_softc *sc;
-
- sc = cc->cc_softc;
+ struct usb2_com_softc *sc = context;
if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
return;
@@ -545,17 +442,14 @@ 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, USB_COM_CFG_START_TRANSFERS);
+ usb2_com_queue_command(sc, &sc->sc_start_task, 0);
}
}
static void
-usb2_com_cfg_open(struct usb2_proc_msg *_cc)
+usb2_com_cfg_open(void *context, struct usb2_task *task)
{
- struct usb2_com_command_msg *cc = (void *)_cc;
- struct usb2_com_softc *sc;
-
- sc = cc->cc_softc;
+ struct usb2_com_softc *sc = context;
DPRINTF("\n");
@@ -571,7 +465,7 @@ usb2_com_cfg_open(struct usb2_proc_msg *
(sc->sc_callback->usb2_com_cfg_open) (sc);
/* wait a little */
- usb2_com_cfg_sleep(sc, hz / 10);
+ usb2_pause_mtx(sc->sc_mtx, hz / 10);
}
}
}
@@ -582,7 +476,7 @@ usb2_com_open(struct tty *tp)
struct usb2_com_softc *sc = tty_softc(tp);
int error;
- mtx_assert(sc->sc_parent_mtx, MA_OWNED);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
if (sc->sc_flag & UCOM_FLAG_GONE) {
return (ENXIO);
@@ -612,7 +506,7 @@ usb2_com_open(struct tty *tp)
sc->sc_msr = 0;
sc->sc_mcr = 0;
- usb2_com_queue_command(sc, USB_COM_CFG_OPEN);
+ usb2_com_queue_command(sc, &sc->sc_open_task, 0);
usb2_com_start_transfers(sc);
@@ -626,12 +520,9 @@ usb2_com_open(struct tty *tp)
}
static void
-usb2_com_cfg_close(struct usb2_proc_msg *_cc)
+usb2_com_cfg_close(void *context, struct usb2_task *task)
{
- struct usb2_com_command_msg *cc = (void *)_cc;
- struct usb2_com_softc *sc;
-
- sc = cc->cc_softc;
+ struct usb2_com_softc *sc = context;
DPRINTF("\n");
@@ -652,8 +543,8 @@ static void
usb2_com_close(struct tty *tp)
{
struct usb2_com_softc *sc = tty_softc(tp);
-
- mtx_assert(sc->sc_parent_mtx, MA_OWNED);
+
+ mtx_assert(sc->sc_mtx, MA_OWNED);
DPRINTF("tp=%p\n", tp);
@@ -663,9 +554,7 @@ usb2_com_close(struct tty *tp)
}
usb2_com_shutdown(sc);
- /* 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);
+ usb2_com_queue_command(sc, &sc->sc_close_task, 0);
sc->sc_flag &= ~(UCOM_FLAG_HL_READY |
UCOM_FLAG_WR_START |
@@ -685,7 +574,7 @@ usb2_com_ioctl(struct tty *tp, u_long cm
struct usb2_com_softc *sc = tty_softc(tp);
int error;
- mtx_assert(sc->sc_parent_mtx, MA_OWNED);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
return (EIO);
@@ -719,7 +608,7 @@ usb2_com_modem(struct tty *tp, int sigon
struct usb2_com_softc *sc = tty_softc(tp);
uint8_t onoff;
- mtx_assert(sc->sc_parent_mtx, MA_OWNED);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
return (0);
@@ -768,11 +657,10 @@ usb2_com_modem(struct tty *tp, int sigon
}
static void
-usb2_com_cfg_break(struct usb2_com_command_msg *cc, uint8_t onoff)
+usb2_com_cfg_break(void *context, struct usb2_task *task)
{
- struct usb2_com_softc *sc;
-
- sc = cc->cc_softc;
+ struct usb2_com_softc *sc = context;
+ int onoff = USB_TASK_ARG(task);
if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
return;
@@ -785,37 +673,23 @@ usb2_com_cfg_break(struct usb2_com_comma
}
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);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
return;
}
DPRINTF("onoff = %d\n", onoff);
- usb2_com_queue_command(sc, onoff ?
- USB_COM_CFG_BREAK_ON : USB_COM_CFG_BREAK_OFF);
+ usb2_com_queue_command(sc, &sc->sc_break_task, onoff);
}
static void
-usb2_com_cfg_dtr(struct usb2_com_command_msg *cc, uint8_t onoff)
+usb2_com_cfg_dtr(void *context, struct usb2_task *task)
{
- struct usb2_com_softc *sc;
-
- sc = cc->cc_softc;
+ struct usb2_com_softc *sc = context;
+ int onoff = USB_TASK_ARG(task);
if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
return;
@@ -828,37 +702,23 @@ usb2_com_cfg_dtr(struct usb2_com_command
}
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);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
return;
}
DPRINTF("onoff = %d\n", onoff);
- usb2_com_queue_command(sc, onoff ?
- USB_COM_CFG_DTR_ON : USB_COM_CFG_DTR_OFF);
+ usb2_com_queue_command(sc, &sc->sc_dtr_task, onoff);
}
static void
-usb2_com_cfg_rts(struct usb2_com_command_msg *cc, uint8_t onoff)
+usb2_com_cfg_rts(void *context, struct usb2_task *task)
{
- struct usb2_com_softc *sc;
-
- sc = cc->cc_softc;
+ struct usb2_com_softc *sc = context;
+ int onoff = USB_TASK_ARG(task);
DPRINTF("onoff=%d\n", onoff);
@@ -871,46 +731,30 @@ usb2_com_cfg_rts(struct usb2_com_command
}
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);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
return;
}
DPRINTF("onoff = %d\n", onoff);
- usb2_com_queue_command(sc, onoff ?
- USB_COM_CFG_RTS_ON : USB_COM_CFG_RTS_OFF);
+ usb2_com_queue_command(sc, &sc->sc_rts_task, onoff);
}
static void
-usb2_com_cfg_status_change(struct usb2_proc_msg *_cc)
+usb2_com_cfg_status_change(void *context, struct usb2_task *task)
{
- struct usb2_com_command_msg *cc = (void *)_cc;
- struct usb2_com_softc *sc;
+ struct usb2_com_softc *sc = context;
struct tty *tp;
-
uint8_t new_msr;
uint8_t new_lsr;
uint8_t onoff;
- sc = cc->cc_softc;
tp = sc->sc_tty;
- mtx_assert(sc->sc_parent_mtx, MA_OWNED);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
return;
@@ -947,25 +791,22 @@ usb2_com_cfg_status_change(struct usb2_p
void
usb2_com_status_change(struct usb2_com_softc *sc)
{
- mtx_assert(sc->sc_parent_mtx, MA_OWNED);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
return;
}
DPRINTF("\n");
- usb2_com_queue_command(sc, USB_COM_CFG_STATUS_CHANGE);
+ usb2_com_queue_command(sc, &sc->sc_status_task, 0);
}
static void
-usb2_com_cfg_param(struct usb2_proc_msg *_cc)
+usb2_com_cfg_param(void *context, struct usb2_task *task)
{
- struct usb2_com_command_msg *cc = (void *)_cc;
- struct usb2_com_softc *sc;
+ struct usb2_com_softc *sc = context;
struct termios t_copy;
- sc = cc->cc_softc;
-
if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
return;
}
@@ -977,7 +818,7 @@ usb2_com_cfg_param(struct usb2_proc_msg
(sc->sc_callback->usb2_com_cfg_param) (sc, &t_copy);
/* wait a little */
- usb2_com_cfg_sleep(sc, hz / 10);
+ usb2_pause_mtx(sc->sc_mtx, hz / 10);
}
static int
@@ -987,7 +828,7 @@ usb2_com_param(struct tty *tp, struct te
uint8_t opened;
int error;
- mtx_assert(sc->sc_parent_mtx, MA_OWNED);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
opened = 0;
error = 0;
@@ -1032,7 +873,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, USB_COM_CFG_PARAM);
+ usb2_com_queue_command(sc, &sc->sc_param_task, 0);
/* Queue transfer enable command last */
usb2_com_start_transfers(sc);
@@ -1053,11 +894,11 @@ done:
}
static void
-usb2_com_start_write(struct tty *tp)
+usb2_com_outwakeup(struct tty *tp)
{
struct usb2_com_softc *sc = tty_softc(tp);
- mtx_assert(sc->sc_parent_mtx, MA_OWNED);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
DPRINTF("sc = %p\n", sc);
@@ -1086,7 +927,7 @@ usb2_com_get_data(struct usb2_com_softc
uint32_t cnt;
uint32_t offset_orig;
- mtx_assert(sc->sc_parent_mtx, MA_OWNED);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
if ((!(sc->sc_flag & UCOM_FLAG_HL_READY)) ||
(!(sc->sc_flag & UCOM_FLAG_GP_DATA)) ||
@@ -1134,7 +975,7 @@ usb2_com_put_data(struct usb2_com_softc
char *buf;
uint32_t cnt;
- mtx_assert(sc->sc_parent_mtx, MA_OWNED);
+ mtx_assert(sc->sc_mtx, MA_OWNED);
if ((!(sc->sc_flag & UCOM_FLAG_HL_READY)) ||
(!(sc->sc_flag & UCOM_FLAG_GP_DATA))) {
@@ -1188,8 +1029,8 @@ usb2_com_free(void *xsc)
{
struct usb2_com_softc *sc = xsc;
- mtx_lock(sc->sc_parent_mtx);
+ mtx_lock(sc->sc_mtx);
sc->sc_ttyfreed = 1;
usb2_cv_signal(&sc->sc_cv);
- mtx_unlock(sc->sc_parent_mtx);
+ mtx_unlock(sc->sc_mtx);
}
Modified: user/thompsa/usb/sys/dev/usb2/serial/usb2_serial.h
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/serial/usb2_serial.h Tue Jan 27 01:21:11 2009 (r187750)
+++ user/thompsa/usb/sys/dev/usb2/serial/usb2_serial.h Tue Jan 27 01:23:25 2009 (r187751)
@@ -82,10 +82,7 @@
struct usb2_com_softc;
struct thread;
-/* NOTE: Only callbacks with "_cfg_" in its name are called
- * from a config thread, and are allowed to sleep! The other
- * callbacks are _not_ allowed to sleep!
- *
+/*
* NOTE: There is no guarantee that "usb2_com_cfg_close()" will
* be called after "usb2_com_cfg_open()" if the device is detached
* while it is open!
@@ -119,41 +116,17 @@ 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_process sc_config_td;
+ struct usb2_process sc_tq;
};
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;
struct usb2_com_super_softc *sc_super;
struct tty *sc_tty;
- struct mtx *sc_parent_mtx;
+ struct mtx *sc_mtx;
void *sc_parent;
uint32_t sc_unit;
uint32_t sc_local_unit;
@@ -170,7 +143,15 @@ 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];
+
+ struct usb2_task sc_start_task;
+ struct usb2_task sc_open_task;
+ struct usb2_task sc_close_task;
+ struct usb2_task sc_break_task;
+ struct usb2_task sc_dtr_task;
+ struct usb2_task sc_rts_task;
+ struct usb2_task sc_status_task;
+ struct usb2_task sc_param_task;
};
int usb2_com_attach(struct usb2_com_super_softc *ssc,
@@ -184,6 +165,5 @@ uint8_t usb2_com_get_data(struct usb2_co
void usb2_com_put_data(struct usb2_com_softc *sc, struct usb2_page_cache *pc,
uint32_t offset, uint32_t len);
uint8_t usb2_com_cfg_sleep(struct usb2_com_softc *sc, uint32_t timeout);
-uint8_t usb2_com_cfg_is_gone(struct usb2_com_softc *sc);
#endif /* _USB2_SERIAL_H_ */
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-user
mailing list