From patchwork Mon Mar 2 21:44:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 184116 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp2882510ile; Mon, 2 Mar 2020 13:44:48 -0800 (PST) X-Received: by 2002:a17:90b:1254:: with SMTP id gx20mr493522pjb.189.1583185488728; Mon, 02 Mar 2020 13:44:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583185488; cv=none; d=google.com; s=arc-20160816; b=jU101uRyQPqKE6TOhANyNXRztSHeYirFJ5YPDpuDsE7AjnrV9Zlp8ifiO8vzlcLj8D UWpqivjRBcQiUr0IKX/u2qTUBjmsWdw4lZeCLZGoF0yi4A1/By/AtadybOyqPP+7t3Tx /K2z6Ia7AchngRBOW04Va6dLzmlBtO1dWS94diuGiS2gw9Az2Jb/ORmUBsa1Dp4GkSet 1E3cqoFma7xznQi5XrNQa+YB5R4Hc0I4hi58ZMJBOkXq+IRdnuznE/H08K/6TglifF6J IuVX+ApsA1HrYf7v0TCD4A+6IPyXng2Mj0DgmWuWMo9LCfA/nhZFVicpnqyFmS2IUcuZ icWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=4Y3ObTGarg5FSEMw5sy9VH68aTZS5szI2sN7gCsNGVk=; b=b38aGOM6jIh9lCnV+Eq6U6htSmx01ryZAsUOIeK9Z1WHipfhmSLTQ0sJ/zh4pPfjpM uWESaMA28DB9vgbHWjnQdSMeO8iC27sTGXQ3XzMEACXZ2D7kSHcTVdW5bxya002KZ2Za Uwz22s3pv71QwvxpwLQ81mQpgHwQr2GWqxx8q3CMeq0inTZbV1qJCgHrZiDxmv70c5IC GgnxQbS6iaghfxx7WFaAKhCJYgVlm5+3o1V0nAZEEUeFTdKLwCmILYtrAXBLhM1dDydQ 6AjHUH+ex6W+wNB5I/HX5zACPSqeAXiNO5xWIE+ytFju6uob7oINBW++S+LB+NbFvDOH lmyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eQSofJhH; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id c27sor2996723pgn.41.2020.03.02.13.44.48 for (Google Transport Security); Mon, 02 Mar 2020 13:44:48 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eQSofJhH; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=4Y3ObTGarg5FSEMw5sy9VH68aTZS5szI2sN7gCsNGVk=; b=eQSofJhH/+iTx+5JQ5yxGwjEuHa1BvH0/uRrXBVnpM6oVu2o/WCVZlvyy4KVqZCfIU K/BstL1P9irmhKujSgxC21S67oMoQAAwtV2fX9Wksw9rY9XYNcdLjustJ4gHopJczxrx OIQyRJzue5x/ia8NDW/JQgmFIXU7p2Yb9Tmg7Z1vUeSLYXSGVjZ50yIFFS49AogQ5dQs +smFGVxG7GzvElalaj66J0TaavSIZdwBWJP68Fb7GG32dCvyCcOApd1UhA/2+hMNp/zK feyHJFt2SVoCJ8lfKAHgKaw1PxrZdjFChc25V3Y51SFIom5IqvQyG9u23UePVCc0I9Er 4pkQ== 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; bh=4Y3ObTGarg5FSEMw5sy9VH68aTZS5szI2sN7gCsNGVk=; b=kH/joGUDnzDGVhFHEqFm2Sx4SO8X1mv4mrkg1LWNTTjml8SaalvS+YEro9HIyglreZ ZdTmWz2cQtr/9QMnGZqxLrcGyd4V6wwPS0Qwc5OyoshKx1t9EbSNcrg7ixbJnxxi4505 +INPf5xyzAub6Ah87BW6Dr5YYsAZnYQFJrq/G9VJ19snY0mxCWzLenfsifnbcn4WE/E4 xkdXErQ3s05W7a//PeK/bX/zwwQSDuVj43ie1nEFds6RgQuo4QZb38+1rQ2syJ/Y6Iyg s1JzGE48jMbE3UxtYPoUyj1O1lDV79M30dlnuc1dKQ7CIEmqvYNBJs2miYOvYzkZkeIH vocQ== X-Gm-Message-State: ANhLgQ03AgAYjavUnL02Msnd58jX7e4Xq42fWSaierpPnyCcz8jKsrP1 NiTNV+ZzrtULwqHsjokhq2ngOBWY X-Google-Smtp-Source: ADFU+vvwaFfaYzRy+WqqPZG1NBwX75qifdGXa03PdoCWDVY1D1w3m7zNwD2USUnR1U6pC0T3j49MPA== X-Received: by 2002:a63:f354:: with SMTP id t20mr870398pgj.126.1583185488289; Mon, 02 Mar 2020 13:44:48 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id v25sm21573567pfe.147.2020.03.02.13.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2020 13:44:47 -0800 (PST) From: John Stultz To: lkml Cc: Pratham Pratap , Felipe Balbi , Yang Fei , Thinh Nguyen , Tejas Joglekar , Andrzej Pietrasiewicz , Jack Pham , Todd Kjos , Greg KH , Linux USB List , stable , John Stultz Subject: [RESEND][PATCH v2] usb: dwc3: gadget: Update chain bit correctly when using sg list Date: Mon, 2 Mar 2020 21:44:43 +0000 Message-Id: <20200302214443.55783-1-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 From: Pratham Pratap If scatter-gather operation is allowed, a large USB request is split into multiple TRBs. For preparing TRBs for sg list, driver iterates over the list and creates TRB for each sg and mark the chain bit to false for the last sg. The current IOMMU driver is clubbing the list of sgs which shares a page boundary into one and giving it to USB driver. With this the number of sgs mapped it not equal to the the number of sgs passed. Because of this USB driver is not marking the chain bit to false since it couldn't iterate to the last sg. This patch addresses this issue by marking the chain bit to false if it is the last mapped sg. At a practical level, this patch resolves USB transfer stalls seen with adb on dwc3 based db845c, pixel3 and other qcom hardware after functionfs gadget added scatter-gather support around v4.20. Credit also to Anurag Kumar Vulisha who implemented a very similar fix to this issue. Cc: Felipe Balbi Cc: Yang Fei Cc: Thinh Nguyen Cc: Tejas Joglekar Cc: Andrzej Pietrasiewicz Cc: Jack Pham Cc: Todd Kjos Cc: Greg KH Cc: Linux USB List Cc: stable #4.20+ Signed-off-by: Pratham Pratap [jstultz: Slight tweak to remove sg_is_last() usage, reworked commit message, minor comment tweak] Signed-off-by: John Stultz --- v2: * Fix typeos and unnecssary parens as suggested by Jack --- drivers/usb/dwc3/gadget.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 1b7d2f9cb673..1e00bf2d65a2 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1071,7 +1071,14 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, unsigned int rem = length % maxp; unsigned chain = true; - if (sg_is_last(s)) + /* + * IOMMU driver is coalescing the list of sgs which shares a + * page boundary into one and giving it to USB driver. With + * this the number of sgs mapped is not equal to the number of + * sgs passed. So mark the chain bit to false if it isthe last + * mapped sg. + */ + if (i == remaining - 1) chain = false; if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) {