PERFORCE change 131676 for review
Hans Petter Selasky
hselasky at FreeBSD.org
Wed Dec 26 02:48:47 PST 2007
http://perforce.freebsd.org/chv.cgi?CH=131676
Change 131676 by hselasky at hselasky_laptop001 on 2007/12/26 10:47:53
Introduce two new functions: "usbd_transfer_set_stall()" and
"usbd_transfer_clear_stall()".
Update documentation.
See README for more information.
Affected files ...
.. //depot/projects/usb/src/sys/dev/usb/README#32 edit
.. //depot/projects/usb/src/sys/dev/usb/if_cdce.c#38 edit
.. //depot/projects/usb/src/sys/dev/usb/usb_subr.h#87 edit
.. //depot/projects/usb/src/sys/dev/usb/usb_transfer.c#91 edit
Differences ...
==== //depot/projects/usb/src/sys/dev/usb/README#32 (text+ko) ====
@@ -381,8 +381,10 @@
a clear-stall command on the STALL'ed endpoint. This flag can
be changed during operation. This flag does only have effect
in USB device side mode except for control endpoints. This
- flag is cleared before the callback is called in case the USB
- transfer state is "USBD_ST_TRANSFERRED".
+ flag is cleared when the stall command has been executed. This
+ flag can only be changed outside the callback function by
+ using the functions "usbd_transfer_set_stall()" and
+ "usbd_transfer_clear_stall()" !
- The "bufsize" field sets the total buffer size in bytes. If
this field is zero, "wMaxPacketSize" will be used, multiplied by the
==== //depot/projects/usb/src/sys/dev/usb/if_cdce.c#38 (text+ko) ====
@@ -727,12 +727,9 @@
CDCE_FLAG_LL_READY |
CDCE_FLAG_HL_READY);
- if (sc->sc_xfer[0]) {
- sc->sc_xfer[0]->flags.stall_pipe = 1;
- }
- if (sc->sc_xfer[1]) {
- sc->sc_xfer[1]->flags.stall_pipe = 1;
- }
+ usbd_transfer_set_stall(sc->sc_xfer[0]);
+ usbd_transfer_set_stall(sc->sc_xfer[1]);
+
cdce_start_transfers(sc);
mtx_unlock(&(sc->sc_mtx));
==== //depot/projects/usb/src/sys/dev/usb/usb_subr.h#87 (text+ko) ====
@@ -934,6 +934,8 @@
void usbd_set_frame_data(struct usbd_xfer *xfer, void *ptr, uint32_t frindex);
void usbd_set_frame_offset(struct usbd_xfer *xfer, uint32_t offset, uint32_t frindex);
void usbd_callback_wrapper(struct usbd_xfer *xfer, void *ctd, uint8_t context);
+void usbd_transfer_clear_stall(struct usbd_xfer *xfer);
+void usbd_transfer_set_stall(struct usbd_xfer *xfer);
void usbd_transfer_intr_enqueue(struct usbd_xfer *xfer);
void usbd_transfer_enqueue(struct usbd_xfer *xfer);
void usbd_transfer_dequeue(struct usbd_xfer *xfer, usbd_status_t error);
==== //depot/projects/usb/src/sys/dev/usb/usb_transfer.c#91 (text+ko) ====
@@ -2388,8 +2388,6 @@
(!xfer->flags_int.bdma_no_post_sync)) {
usbd_bdma_post_sync(xfer);
}
- /* clear any previous stall command */
- xfer->flags.stall_pipe = 0;
callback:
/* call processing routine */
(xfer->callback) (xfer);
@@ -2482,6 +2480,58 @@
}
/*------------------------------------------------------------------------*
+ * usbd_transfer_set_stall
+ *
+ * This function is used to set the stall flag outside the
+ * callback. This function is NULL safe.
+ *------------------------------------------------------------------------*/
+void
+usbd_transfer_set_stall(struct usbd_xfer *xfer)
+{
+ if (xfer == NULL) {
+ /* tearing down */
+ return;
+ }
+
+ mtx_assert(xfer->priv_mtx, MA_OWNED);
+
+ /* avoid any races by locking the USB mutex */
+ mtx_lock(xfer->usb_mtx);
+
+ xfer->flags.stall_pipe = 1;
+
+ mtx_unlock(xfer->usb_mtx);
+
+ return;
+}
+
+/*------------------------------------------------------------------------*
+ * usbd_transfer_clear_stall
+ *
+ * This function is used to clear the stall flag outside the
+ * callback. This function is NULL safe.
+ *------------------------------------------------------------------------*/
+void
+usbd_transfer_clear_stall(struct usbd_xfer *xfer)
+{
+ if (xfer == NULL) {
+ /* tearing down */
+ return;
+ }
+
+ mtx_assert(xfer->priv_mtx, MA_OWNED);
+
+ /* avoid any races by locking the USB mutex */
+ mtx_lock(xfer->usb_mtx);
+
+ xfer->flags.stall_pipe = 0;
+
+ mtx_unlock(xfer->usb_mtx);
+
+ return;
+}
+
+/*------------------------------------------------------------------------*
* usbd_transfer_intr_enqueue
*
* This function is used to add an USB transfer to the interrupt
@@ -2526,8 +2576,11 @@
/*
* Check if we are supposed to stall the pipe:
*/
- if (xfer->flags.stall_pipe &&
- (xfer->flags_int.usb_mode == USB_MODE_DEVICE)) {
+ if (xfer->flags.stall_pipe) {
+ /* clear stall command */
+ xfer->flags.stall_pipe = 0;
+
+ if (xfer->flags_int.usb_mode == USB_MODE_DEVICE) {
/*
* Only stall BULK and INTERRUPT endpoints.
*/
@@ -2539,6 +2592,7 @@
xfer->udev, NULL, xfer->pipe);
goto done;
}
+ }
}
/*
* Handled cases:
@@ -2835,7 +2889,8 @@
* send STALL tokens.
*------------------------------------------------------------------------*/
static usbd_status_t
-usbd_handle_set_stall_sub(struct usbd_device *udev, uint8_t ea_val, uint8_t do_stall)
+usbd_handle_set_stall_sub(struct usbd_device *udev, uint8_t ea_val,
+uint8_t do_stall)
{
struct usbd_pipe *pipe;
struct usbd_xfer *xfer;
@@ -2844,6 +2899,7 @@
pipe = usbd_get_pipe_by_addr(udev, ea_val);
if (pipe == NULL) {
/* nothing to do */
+ PRINTFN(0, ("Cannot find endpoint\n"));
return (USBD_INVAL);
}
et = (pipe->edesc->bmAttributes & UE_XFERTYPE);
@@ -2854,6 +2910,7 @@
* Should not stall control
* nor isochronous endpoints.
*/
+ PRINTFN(0, ("Invalid endpoint\n"));
return (0);
}
mtx_lock(&(udev->bus->mtx));
@@ -2861,6 +2918,7 @@
if (pipe->is_stalled == do_stall) {
/* if the pipe is already stalled do nothing */
mtx_unlock(&(udev->bus->mtx));
+ PRINTFN(0, ("No change\n"));
return (0);
}
/* update stalled state */
@@ -3765,7 +3823,7 @@
break;
}
- xfer2->flags.stall_pipe = 0; /* stop stalling the pipe */
+ usbd_transfer_clear_stall(xfer2);
return (1); /* Clear Stall Finished */
}
More information about the p4-projects
mailing list