From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] USB: musb_udc: Bugfix musb_peri_rx_ep
Date: Fri, 14 Sep 2012 02:43:28 +0200 [thread overview]
Message-ID: <201209140243.28372.marex@denx.de> (raw)
In-Reply-To: <1347557191-32760-1-git-send-email-trini@ti.com>
Dear Tom Rini,
> From: Pankaj Bharadiya <pankaj.bharadiya@ti.com>
>
> The endpoint rx count register value will be zero if it is read before
> receive packet ready bit (PERI_RXCSR:RXPKTRDY) is set.
>
> Check for the receive packet ready bit (PERI_RXCSR:RXPKTRDY) before
> reading endpoint rx count register. Proceed with rx count read and
> FIFO read only if RXPKTRDY bit is set.
>
> As this makes the function fit less-well within 80 columns, use __func__
> in some debug statements rather than __PRETTY_FUNCTION__ as they are
> identical for C programs.
>
> Signed-off-by: Pankaj Bharadiya <pankaj.bharadiya@ti.com>
> Signed-off-by: Tom Rini <trini@ti.com>
> ---
> drivers/usb/musb/musb_udc.c | 97
> +++++++++++++++++++++++-------------------- 1 file changed, 52
> insertions(+), 45 deletions(-)
>
> diff --git a/drivers/usb/musb/musb_udc.c b/drivers/usb/musb/musb_udc.c
> index 09cdec3..7180de8 100644
> --- a/drivers/usb/musb/musb_udc.c
> +++ b/drivers/usb/musb/musb_udc.c
> @@ -640,58 +640,65 @@ static void musb_peri_ep0(void)
>
> static void musb_peri_rx_ep(unsigned int ep)
> {
> - u16 peri_rxcount = readw(&musbr->ep[ep].epN.rxcount);
> -
> - if (peri_rxcount) {
> - struct usb_endpoint_instance *endpoint;
> - u32 length;
> - u8 *data;
> -
> - endpoint = GET_ENDPOINT(udc_device, ep);
> - if (endpoint && endpoint->rcv_urb) {
> - struct urb *urb = endpoint->rcv_urb;
> - unsigned int remaining_space = urb->buffer_length -
> - urb->actual_length;
> -
> - if (remaining_space) {
> - int urb_bad = 0; /* urb is good */
> -
> - if (peri_rxcount > remaining_space)
> - length = remaining_space;
> - else
> - length = peri_rxcount;
> -
> - data = (u8 *) urb->buffer_data;
> - data += urb->actual_length;
> -
> - /* The common musb fifo reader */
> - read_fifo(ep, length, data);
> -
> - musb_peri_rx_ack(ep);
> -
> - /*
> - * urb's actual_length is updated in
> - * usbd_rcv_complete
> - */
> - usbd_rcv_complete(endpoint, length, urb_bad);
> + u8 peri_rxcsr = readw(&musbr->ep[ep].epN.rxcsr);
> + if ((peri_rxcsr & MUSB_RXCSR_RXPKTRDY)) {
if (!cond)
return;
This will cut down one indent below.
> + u16 peri_rxcount = readw(&musbr->ep[ep].epN.rxcount);
> + if (peri_rxcount) {
> + struct usb_endpoint_instance *endpoint;
> + u32 length;
> + u8 *data;
>
> + endpoint = GET_ENDPOINT(udc_device, ep);
> + if (endpoint && endpoint->rcv_urb) {
> + struct urb *urb = endpoint->rcv_urb;
> + unsigned int remaining_space =
> + urb->buffer_length -
> + urb->actual_length;
> +
> + if (remaining_space) {
> + int urb_bad = 0; /* urb is good */
> +
> + if (peri_rxcount > remaining_space)
> + length = remaining_space;
> + else
> + length = peri_rxcount;
> +
> + data = (u8 *) urb->buffer_data;
> + data += urb->actual_length;
> +
> + /* The common musb fifo reader */
> + read_fifo(ep, length, data);
> +
> + musb_peri_rx_ack(ep);
> +
> + /*
> + * urb's actual_length is updated in
> + * usbd_rcv_complete
> + */
> + usbd_rcv_complete(endpoint, length,
> + urb_bad);
> +
> + } else {
> + if (debug_level > 0)
> + serial_printf("ERROR : %s %d"
> + " no space "
> + "in rcv "
> + "buffer\n",
> + __func__,
> + ep);
So ... if (error) print error and die.
if (!remaining_space && debug_level)
print and die.
{ rest of the function, as above }
One more indent level down.
Apply common sense to the other else {} and it's work out.
> + }
> } else {
> if (debug_level > 0)
> - serial_printf("ERROR : %s %d no space "
> - "in rcv buffer\n",
> - __PRETTY_FUNCTION__, ep);
> + serial_printf("ERROR : %s %d problem "
use printf(), serial_printf is flat out forbidden and this is a NACK /!\
> + "with endpoint\n",
> + __func__, ep);
> +
> }
> } else {
> if (debug_level > 0)
> - serial_printf("ERROR : %s %d problem with "
> - "endpoint\n",
> - __PRETTY_FUNCTION__, ep);
> + serial_printf("ERROR : %s %d with nothing "
> + "to do\n", __func__, ep);
> }
> -
> - } else {
> - if (debug_level > 0)
> - serial_printf("ERROR : %s %d with nothing to do\n",
> - __PRETTY_FUNCTION__, ep);
> }
> }
Best regards,
Marek Vasut
prev parent reply other threads:[~2012-09-14 0:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-13 17:26 [U-Boot] [PATCH] USB: musb_udc: Bugfix musb_peri_rx_ep Tom Rini
2012-09-13 19:01 ` Kim Phillips
2012-09-13 19:31 ` Tom Rini
2012-09-14 0:39 ` Marek Vasut
2012-09-14 0:43 ` Marek Vasut [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201209140243.28372.marex@denx.de \
--to=marex@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox