Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Feb 2009 20:57:43 +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: r188600 - head/sys/dev/usb2/core
Message-ID:  <200902132057.n1DKvhdl099135@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: thompsa
Date: Fri Feb 13 20:57:43 2009
New Revision: 188600
URL: http://svn.freebsd.org/changeset/base/188600

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

Modified:
  head/sys/dev/usb2/core/usb2_core.h
  head/sys/dev/usb2/core/usb2_process.c
  head/sys/dev/usb2/core/usb2_process.h
  head/sys/dev/usb2/core/usb2_transfer.c
  head/sys/dev/usb2/core/usb2_transfer.h

Modified: head/sys/dev/usb2/core/usb2_core.h
==============================================================================
--- head/sys/dev/usb2/core/usb2_core.h	Fri Feb 13 20:09:11 2009	(r188599)
+++ head/sys/dev/usb2/core/usb2_core.h	Fri Feb 13 20:57:43 2009	(r188600)
@@ -449,6 +449,7 @@ void	usb2_start_hardware(struct usb2_xfe
 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);

Modified: head/sys/dev/usb2/core/usb2_process.c
==============================================================================
--- head/sys/dev/usb2/core/usb2_process.c	Fri Feb 13 20:09:11 2009	(r188599)
+++ head/sys/dev/usb2/core/usb2_process.c	Fri Feb 13 20:57:43 2009	(r188600)
@@ -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 *u
 	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 *u
 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,
 	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
 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);
-	}
-}

Modified: head/sys/dev/usb2/core/usb2_process.h
==============================================================================
--- head/sys/dev/usb2/core/usb2_process.h	Fri Feb 13 20:09:11 2009	(r188599)
+++ head/sys/dev/usb2/core/usb2_process.h	Fri Feb 13 20:57:43 2009	(r188600)
@@ -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);

Modified: head/sys/dev/usb2/core/usb2_transfer.c
==============================================================================
--- head/sys/dev/usb2/core/usb2_transfer.c	Fri Feb 13 20:09:11 2009	(r188599)
+++ head/sys/dev/usb2/core/usb2_transfer.c	Fri Feb 13 20:57:43 2009	(r188600)
@@ -1690,6 +1690,10 @@ usb2_transfer_pending(struct usb2_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) {

Modified: head/sys/dev/usb2/core/usb2_transfer.h
==============================================================================
--- head/sys/dev/usb2/core/usb2_transfer.h	Fri Feb 13 20:09:11 2009	(r188599)
+++ head/sys/dev/usb2/core/usb2_transfer.h	Fri Feb 13 20:57:43 2009	(r188600)
@@ -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);



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