From patchwork Thu Sep 13 17:26:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rini X-Patchwork-Id: 183685 X-Patchwork-Delegate: kim.phillips@freescale.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 6CDC92C0088 for ; Fri, 14 Sep 2012 03:26:42 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 967C7280CB; Thu, 13 Sep 2012 19:26:40 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nMZkOJok+Wv0; Thu, 13 Sep 2012 19:26:40 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 611F9280CC; Thu, 13 Sep 2012 19:26:37 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 87448280CC for ; Thu, 13 Sep 2012 19:26:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OTtQyV9dcd7U for ; Thu, 13 Sep 2012 19:26:33 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pb0-f44.google.com (mail-pb0-f44.google.com [209.85.160.44]) by theia.denx.de (Postfix) with ESMTPS id 93ABD280CB for ; Thu, 13 Sep 2012 19:26:30 +0200 (CEST) Received: by pbbrr4 with SMTP id rr4so4363226pbb.3 for ; Thu, 13 Sep 2012 10:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=FaEPJLJrMvVut83JSMJrylb7pHPNw+6p5gH0Yq+/j+I=; b=J8lNL9SfIhhTQwm6ipJ50aDn6a1ImuSC9BriYrLdcH+dZUChn46ge5jiAZGtqBuEhv XHHqNRtpNqXrxhajqoxTVTZi7MQH2WDnQt4u6reIL4k+ff5WsIioz+DxuAykKPcxCumo imbp6pzxcMzzpwkODzM5ziS7eS4Tu/eYAluFsDqYhO7O3yitUinNqze9YKmbwSg4e6FD uyy7LbXFxiCeFgZPGrPlcpMmfuNg2ebL1AV46ohdDfaVIxdIFvC9FIGaV/6U+0Acsx0R oTjqpZllrqcZuhZUIjg6KMnh67xi8Evn4iiDqZJd/x2DbqB2VdB0HfjtFqkx8GBIF9cL WoEg== Received: by 10.68.212.230 with SMTP id nn6mr422038pbc.103.1347557189095; Thu, 13 Sep 2012 10:26:29 -0700 (PDT) Received: from localhost.localdomain (ip68-230-54-74.ph.ph.cox.net. [68.230.54.74]) by mx.google.com with ESMTPS id mu8sm13384892pbc.49.2012.09.13.10.26.26 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Sep 2012 10:26:27 -0700 (PDT) From: Tom Rini To: u-boot@lists.denx.de Date: Thu, 13 Sep 2012 10:26:31 -0700 Message-Id: <1347557191-32760-1-git-send-email-trini@ti.com> X-Mailer: git-send-email 1.7.9.5 Cc: Pankaj Bharadiya Subject: [U-Boot] [PATCH] USB: musb_udc: Bugfix musb_peri_rx_ep X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Pankaj Bharadiya 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 Signed-off-by: Tom Rini --- 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)) { + 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); + } } 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 " + "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); } }