From patchwork Thu May 6 11:22:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Elwell X-Patchwork-Id: 12242023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB628C433B4 for ; Thu, 6 May 2021 11:22:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 793F161157 for ; Thu, 6 May 2021 11:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234662AbhEFLXJ (ORCPT ); Thu, 6 May 2021 07:23:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234618AbhEFLXJ (ORCPT ); Thu, 6 May 2021 07:23:09 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DB3BC061574 for ; Thu, 6 May 2021 04:22:10 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id j3-20020a05600c4843b02901484662c4ebso5135015wmo.0 for ; Thu, 06 May 2021 04:22:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xX8oNQuVw461EY8weBD4WdkQqtE66BqEug4vL4X/XJU=; b=m2+OSgbtJPu4fE6EdgDgf7oYLJxeo7fJ09HtncB20niKLA4zhAGqWHprJNMpf3vo7g UQg3XmHwbTIXX+uvE/KqZmR0FwVBmrs8JjUAggGd4CID5o2Ycje5Hvf7coSKFVhVcV8x wsJIjPB2TqUk37DtYEnt1aS6DjxZpG0VaxPWH9eT/9py5NNwT3sCgXKWworXlO5sshpA 9oJk77pIp8crA6hBy/KfjgI1R3y9G5PE8vTv3nzAr6EJ1VyuUyCUjevnO/brDR/VLMco 6lfgqlItB5LOIafn61ss6y8pHKVePnHWHknltQlih1bbJ4Uk+7r7pgG8S7YvJ4rfhEqE xEcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xX8oNQuVw461EY8weBD4WdkQqtE66BqEug4vL4X/XJU=; b=CGJzPkRf7kli+97eZHBY7KWZGnjjd3RQp4VnEjbHWIHifCcGZZ6Gen+gAb9n8/IEHM a2LpfhzlKdz3WjtMVWT+V5FF63unnKjG8ywsFY5erYKBwk53SLKvgO7KmnA7nsG42dhf JNfvQtdnMTBkjBw4weP3WLsUyJc2Rcj19YATzOe5b2dav2hjbt35YYgODXxL2kU4be77 U/96LwsqLwHtGMVIOW0HYCBMn8OHxIT1GGzk0VsgBXniiEQIdAWcA1AcC8I4/bqxC1jt DBirxqARgm02MGXTGjFbaTGQgb8URJHFJdz0fbGmcMwEVOss5Qp9hNgEYlPz31Aw5mED /KGA== X-Gm-Message-State: AOAM532x8dVzgnBaLpg940KNbhkQuW23hsjXGFGcHTs/3bGf0ihvv8PA /0/PEGqdP7ZTWSceOwJMCMeqjA== X-Google-Smtp-Source: ABdhPJxW2GKLE/2T1+QdXBtHaqHeRjF8OABMkPC3ciG3cNZCUDuKkTMJuBNHDD8A0ySnNr55idpAng== X-Received: by 2002:a7b:c217:: with SMTP id x23mr14249512wmi.26.1620300128776; Thu, 06 May 2021 04:22:08 -0700 (PDT) Received: from buildbot.pitowers.org ([2a00:1098:3142:14:ae1f:6bff:fedd:de54]) by smtp.gmail.com with ESMTPSA id f22sm2979216wmj.42.2021.05.06.04.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 04:22:08 -0700 (PDT) From: Phil Elwell To: Minas Harutyunyan , Greg Kroah-Hartman , Mian Yousaf Kaukab , Felipe Balbi , Paul Zimmerman , Nicolas Saenz Julienne , linux-usb@vger.kernel.org, linux-rpi-kernel@lists.infradead.org Cc: Phil Elwell Subject: [PATCH] usb: dwc2: Fix gadget DMA unmap direction Date: Thu, 6 May 2021 12:22:00 +0100 Message-Id: <20210506112200.2893922-1-phil@raspberrypi.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The dwc2 gadget support maps and unmaps DMA buffers as necessary. When mapping and unmapping it uses the direction of the endpoint to select the direction of the DMA transfer, but this fails for Control OUT transfers because the unmap occurs after the endpoint direction has been reversed for the status phase. A possible solution would be to unmap the buffer before the direction is changed, but a safer, less invasive fix is to remember the buffer direction independently of the endpoint direction. Fixes: fe0b94abcdf6 ("usb: dwc2: gadget: manage ep0 state in software") Signed-off-by: Phil Elwell Acked-by: Minas Harutyunyan --- drivers/usb/dwc2/core.h | 2 ++ drivers/usb/dwc2/gadget.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index da5ac4a4595b..ab6b815e0089 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -113,6 +113,7 @@ struct dwc2_hsotg_req; * @debugfs: File entry for debugfs file for this endpoint. * @dir_in: Set to true if this endpoint is of the IN direction, which * means that it is sending data to the Host. + * @map_dir: Set to the value of dir_in when the DMA buffer is mapped. * @index: The index for the endpoint registers. * @mc: Multi Count - number of transactions per microframe * @interval: Interval for periodic endpoints, in frames or microframes. @@ -162,6 +163,7 @@ struct dwc2_hsotg_ep { unsigned short fifo_index; unsigned char dir_in; + unsigned char map_dir; unsigned char index; unsigned char mc; u16 interval; diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index e6bb1bdb2760..184964174dc0 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -422,7 +422,7 @@ static void dwc2_hsotg_unmap_dma(struct dwc2_hsotg *hsotg, { struct usb_request *req = &hs_req->req; - usb_gadget_unmap_request(&hsotg->gadget, req, hs_ep->dir_in); + usb_gadget_unmap_request(&hsotg->gadget, req, hs_ep->map_dir); } /* @@ -1242,6 +1242,7 @@ static int dwc2_hsotg_map_dma(struct dwc2_hsotg *hsotg, { int ret; + hs_ep->map_dir = hs_ep->dir_in; ret = usb_gadget_map_request(&hsotg->gadget, req, hs_ep->dir_in); if (ret) goto dma_error;