summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthompsa <thompsa@FreeBSD.org>2009-02-13 20:57:43 +0000
committerthompsa <thompsa@FreeBSD.org>2009-02-13 20:57:43 +0000
commit4324b99ee64f0e11f62a6398d8c9693c3f90bf16 (patch)
tree13833b56286574b229c8c3edb8ec5babd670c04d
parentf606fe1aa49674b039012a7e003cc903f115e53d (diff)
downloadFreeBSD-src-4324b99ee64f0e11f62a6398d8c9693c3f90bf16.zip
FreeBSD-src-4324b99ee64f0e11f62a6398d8c9693c3f90bf16.tar.gz
MFp4 //depot/projects/usb; 157501, 157608, 157609
- Make usb2_transfer_pending() part of the USB core header file. - Make usb2_transfer_pending() NULL safe. - Make sure that USB process functions return if the process has been drained. - Remove two unused functions. Submitted by: Hans Petter Selasky
-rw-r--r--sys/dev/usb2/core/usb2_core.h1
-rw-r--r--sys/dev/usb2/core/usb2_process.c98
-rw-r--r--sys/dev/usb2/core/usb2_process.h2
-rw-r--r--sys/dev/usb2/core/usb2_transfer.c4
-rw-r--r--sys/dev/usb2/core/usb2_transfer.h1
5 files changed, 29 insertions, 77 deletions
diff --git a/sys/dev/usb2/core/usb2_core.h b/sys/dev/usb2/core/usb2_core.h
index 33b1a27..06f77cb 100644
--- a/sys/dev/usb2/core/usb2_core.h
+++ b/sys/dev/usb2/core/usb2_core.h
@@ -449,6 +449,7 @@ void usb2_start_hardware(struct usb2_xfer *xfer);
void usb2_transfer_clear_stall(struct usb2_xfer *xfer);
void usb2_transfer_drain(struct usb2_xfer *xfer);
void usb2_transfer_set_stall(struct usb2_xfer *xfer);
+uint8_t usb2_transfer_pending(struct usb2_xfer *xfer);
void usb2_transfer_start(struct usb2_xfer *xfer);
void usb2_transfer_stop(struct usb2_xfer *xfer);
void usb2_transfer_unsetup(struct usb2_xfer **pxfer, uint16_t n_setup);
diff --git a/sys/dev/usb2/core/usb2_process.c b/sys/dev/usb2/core/usb2_process.c
index 890d53e..4c50695 100644
--- a/sys/dev/usb2/core/usb2_process.c
+++ b/sys/dev/usb2/core/usb2_process.c
@@ -84,9 +84,9 @@ usb2_process(void *arg)
while (1) {
- if (up->up_gone) {
+ if (up->up_gone)
break;
- }
+
/*
* NOTE to reimplementors: dequeueing a command from the
* "used" queue and executing it must be atomic, with regard
@@ -213,10 +213,10 @@ error:
void
usb2_proc_free(struct usb2_process *up)
{
- if (!(up->up_mtx)) {
- /* not initialised */
+ /* check if not initialised */
+ if (up->up_mtx == NULL)
return;
- }
+
usb2_proc_drain(up);
usb2_cv_destroy(&up->up_cv);
@@ -246,6 +246,10 @@ usb2_proc_msignal(struct usb2_process *up, void *_pm0, void *_pm1)
uint32_t d;
uint8_t t;
+ /* check if gone, return dummy value */
+ if (up->up_gone)
+ return (_pm0);
+
mtx_assert(up->up_mtx, MA_OWNED);
t = 0;
@@ -319,9 +323,11 @@ usb2_proc_msignal(struct usb2_process *up, void *_pm0, void *_pm1)
uint8_t
usb2_proc_is_gone(struct usb2_process *up)
{
- mtx_assert(up->up_mtx, MA_OWNED);
+ if (up->up_gone)
+ return (1);
- return (up->up_gone ? 1 : 0);
+ mtx_assert(up->up_mtx, MA_OWNED);
+ return (0);
}
/*------------------------------------------------------------------------*
@@ -337,6 +343,10 @@ usb2_proc_mwait(struct usb2_process *up, void *_pm0, void *_pm1)
struct usb2_proc_msg *pm0 = _pm0;
struct usb2_proc_msg *pm1 = _pm1;
+ /* check if gone */
+ if (up->up_gone)
+ return;
+
mtx_assert(up->up_mtx, MA_OWNED);
if (up->up_curtd == curthread) {
@@ -372,13 +382,13 @@ usb2_proc_mwait(struct usb2_process *up, void *_pm0, void *_pm1)
void
usb2_proc_drain(struct usb2_process *up)
{
- if (!(up->up_mtx)) {
- /* not initialised */
+ /* check if not initialised */
+ if (up->up_mtx == NULL)
return;
- }
- if (up->up_mtx != &Giant) {
+ /* handle special case with Giant */
+ if (up->up_mtx != &Giant)
mtx_assert(up->up_mtx, MA_NOTOWNED);
- }
+
mtx_lock(up->up_mtx);
/* Set the gone flag */
@@ -398,7 +408,8 @@ usb2_proc_drain(struct usb2_process *up)
if (cold) {
USB_THREAD_SUSPEND(up->up_ptr);
- printf("WARNING: A USB process has been left suspended!\n");
+ printf("WARNING: A USB process has "
+ "been left suspended!\n");
break;
}
usb2_cv_wait(&up->up_cv, up->up_mtx);
@@ -413,64 +424,3 @@ usb2_proc_drain(struct usb2_process *up)
}
mtx_unlock(up->up_mtx);
}
-
-/*------------------------------------------------------------------------*
- * usb2_proc_cwait
- *
- * This function will suspend the current process until
- * "usb2_proc_signal()" or "usb2_proc_drain()" is called. The
- * "timeout" parameter defines the maximum wait time in system
- * ticks. If "timeout" is zero that means no timeout.
- *
- * NOTE: This function can only be called from within an USB process.
- *
- * Return values:
- * USB_PROC_WAIT_TIMEOUT: Timeout
- * USB_PROC_WAIT_NORMAL: Success
- * Else: USB process is tearing down
- *------------------------------------------------------------------------*/
-uint8_t
-usb2_proc_cwait(struct usb2_process *up, int timeout)
-{
- int error;
-
- mtx_assert(up->up_mtx, MA_OWNED);
-
- if (up->up_gone) {
- return (USB_PROC_WAIT_DRAIN);
- }
- up->up_csleep = 1;
-
- if (timeout == 0) {
- usb2_cv_wait(&up->up_cv, up->up_mtx);
- error = 0;
- } else {
- error = usb2_cv_timedwait(&up->up_cv, up->up_mtx, timeout);
- }
-
- up->up_csleep = 0;
-
- if (up->up_gone) {
- return (USB_PROC_WAIT_DRAIN);
- }
- if (error == EWOULDBLOCK) {
- return (USB_PROC_WAIT_TIMEOUT);
- }
- return (0);
-}
-
-/*------------------------------------------------------------------------*
- * usb2_proc_csignal
- *
- * This function will wakeup the given USB process.
- *------------------------------------------------------------------------*/
-void
-usb2_proc_csignal(struct usb2_process *up)
-{
- mtx_assert(up->up_mtx, MA_OWNED);
-
- if (up->up_csleep) {
- up->up_csleep = 0;
- usb2_cv_signal(&up->up_cv);
- }
-}
diff --git a/sys/dev/usb2/core/usb2_process.h b/sys/dev/usb2/core/usb2_process.h
index 78fdb3aa..756b929 100644
--- a/sys/dev/usb2/core/usb2_process.h
+++ b/sys/dev/usb2/core/usb2_process.h
@@ -77,11 +77,9 @@ struct usb2_process {
/* prototypes */
-uint8_t usb2_proc_cwait(struct usb2_process *up, int timeout);
uint8_t usb2_proc_is_gone(struct usb2_process *up);
int usb2_proc_create(struct usb2_process *up, struct mtx *p_mtx,
const char *pmesg, uint8_t prio);
-void usb2_proc_csignal(struct usb2_process *up);
void usb2_proc_drain(struct usb2_process *up);
void usb2_proc_mwait(struct usb2_process *up, void *pm0, void *pm1);
void usb2_proc_free(struct usb2_process *up);
diff --git a/sys/dev/usb2/core/usb2_transfer.c b/sys/dev/usb2/core/usb2_transfer.c
index ef512d3..2572b25 100644
--- a/sys/dev/usb2/core/usb2_transfer.c
+++ b/sys/dev/usb2/core/usb2_transfer.c
@@ -1690,6 +1690,10 @@ usb2_transfer_pending(struct usb2_xfer *xfer)
struct usb2_xfer_root *info;
struct usb2_xfer_queue *pq;
+ if (xfer == NULL) {
+ /* transfer is gone */
+ return (0);
+ }
USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
if (xfer->flags_int.transferring) {
diff --git a/sys/dev/usb2/core/usb2_transfer.h b/sys/dev/usb2/core/usb2_transfer.h
index 4149499..34124c5 100644
--- a/sys/dev/usb2/core/usb2_transfer.h
+++ b/sys/dev/usb2/core/usb2_transfer.h
@@ -102,7 +102,6 @@ struct usb2_setup_params {
/* function prototypes */
-uint8_t usb2_transfer_pending(struct usb2_xfer *xfer);
uint8_t usb2_transfer_setup_sub_malloc(struct usb2_setup_params *parm,
struct usb2_page_cache **ppc, uint32_t size, uint32_t align,
uint32_t count);
OpenPOWER on IntegriCloud