From patchwork Mon Mar 18 08:18:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guido Kiener X-Patchwork-Id: 10856921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13F2B6C2 for ; Mon, 18 Mar 2019 07:19:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E21FF2921A for ; Mon, 18 Mar 2019 07:19:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D07C82927C; Mon, 18 Mar 2019 07:19:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9F602921A for ; Mon, 18 Mar 2019 07:19:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727173AbfCRHTu (ORCPT ); Mon, 18 Mar 2019 03:19:50 -0400 Received: from mr08.mx01.tldhost.de ([84.19.26.246]:35069 "EHLO mr08.mx01.tldhost.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726135AbfCRHTu (ORCPT ); Mon, 18 Mar 2019 03:19:50 -0400 Received: from mx01.tldhost.de (localhost [127.0.0.1]) by mx01.tldhost.de (Postfix) with ESMTP id 38FDF120CDF for ; Mon, 18 Mar 2019 08:19:47 +0100 (CET) Received: by mx01.tldhost.de (Postfix, from userid 1001) id 2E69B120CD9; Mon, 18 Mar 2019 08:19:47 +0100 (CET) Received: from server12.tldhost.de (server12.tldhost.de [84.19.26.112]) by mx01.tldhost.de (Postfix) with ESMTPS id 6FD9E120C26; Mon, 18 Mar 2019 08:19:46 +0100 (CET) From: Guido Kiener To: Felipe Balbi , linux-usb@vger.kernel.org, guido.kiener@rohde-schwarz.com, Alan Stern Cc: Guido Kiener Subject: [PATCH v2 1/3] usb: gadget: net2280: Fix overrun of OUT messages Date: Mon, 18 Mar 2019 09:18:32 +0100 Message-Id: <20190318081834.4601-1-guido@kiener-muenchen.de> X-PPP-Message-ID: <20190318071946.6812.6913@server12.tldhost.de> X-PPP-Vhost: kiener-muenchen.de X-POWERED-BY: TLDHost.de - AV:CLEAN SPAM:OK Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The OUT endpoint normally blocks (NAK) subsequent packets when a short packet was received and returns an incomplete queue entry to the gadget driver. Thereby the gadget driver can detect a short packet when reading queue entries with a length that is not equal to a multiple of packet size. The start_queue() function enables receiving OUT packets regardless of the content of the OUT FIFO. This results in a problem: When receiving is enabled again, more OUT packets are appended to the last short packet and the gadget driver cannot determine the end of a short packet anymore. Furthermore the remaining data in the OUT FIFO is not delivered to the gadget driver immediately and can produce timeout errors. This fix stops OUT naking only when OUT naking is enabled and when the OUT FIFO is empty. It ensures that all received data is delivered to the gadget driver which can detect a short packet now before new packets overrun the last short packet. Signed-off-by: Guido Kiener --- drivers/usb/gadget/udc/net2280.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index f63f82450bf4..e0b413e9e532 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -866,9 +866,6 @@ static void start_queue(struct net2280_ep *ep, u32 dmactl, u32 td_dma) (void) readl(&ep->dev->pci->pcimstctl); writel(BIT(DMA_START), &dma->dmastat); - - if (!ep->is_in) - stop_out_naking(ep); } static void start_dma(struct net2280_ep *ep, struct net2280_request *req) @@ -907,6 +904,7 @@ static void start_dma(struct net2280_ep *ep, struct net2280_request *req) writel(BIT(DMA_START), &dma->dmastat); return; } + stop_out_naking(ep); } tmp = dmactl_default;