From owner-p4-projects@FreeBSD.ORG Wed Dec 26 10:48:47 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2299416A46E; Wed, 26 Dec 2007 10:48:47 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C833E16A46C for ; Wed, 26 Dec 2007 10:48:46 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id C3FF113C4D3 for ; Wed, 26 Dec 2007 10:48:46 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id lBQAmkp8074503 for ; Wed, 26 Dec 2007 10:48:46 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id lBQAmkIc074500 for perforce@freebsd.org; Wed, 26 Dec 2007 10:48:46 GMT (envelope-from hselasky@FreeBSD.org) Date: Wed, 26 Dec 2007 10:48:46 GMT Message-Id: <200712261048.lBQAmkIc074500@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 131676 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Dec 2007 10:48:47 -0000 http://perforce.freebsd.org/chv.cgi?CH=131676 Change 131676 by hselasky@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 */ }