From patchwork Thu Feb 20 06:06:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 183663 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp186140ile; Wed, 19 Feb 2020 22:06:22 -0800 (PST) X-Received: by 2002:a63:28a:: with SMTP id 132mr31055697pgc.165.1582178782048; Wed, 19 Feb 2020 22:06:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582178782; cv=none; d=google.com; s=arc-20160816; b=OD6rfL2nGzTO1neE8Y1zLG2RvU7E5iAUbgsXo0/JjO36LBAbMzBG35JFyCikfALcds AkKRe9bI6SKRbjrEa84BD3HaWOtRfLx+J+n+sxAZOL08coae731jk7CdjWGTDd89LMGp XMOhAXYmpKQmy/ngvjl97TCjZF1MNlmlxr0Ch+5X5/PtIXxCEBz3l/x+fJ35y/I3xT41 kyfIEEJB/XwCYO86nKD6A0ZbR3obBpdp5scrctWuPJp7sOpbbE5lwthOfm+oPZaDfZ7i rHSoZ2jCemNv/kKSXFlzf7sFUM5ZTs8XiQEzEBeihskfYzoATHFykLjOdzIaUWeYEneF vhVg== 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=FwVgCncLbVot4SV9ouCUOJjc6U+mADi+9P9iseWgOPI=; b=MMsHWwXS4jvKdY4XqDqFMETJZUblv0ncTleZt562g1laPR4UPpsxe0ykXf1c/FkgKt MQQCcsw+eWqpuVuGrgl6YDRyaOdS5BVnXlsHu92QrGi3H8uTe6q6CVcl0PJG8JZ9+cJ4 eQrTANp6NzyCb9C9a1tu/kSUkz9QGvE8+yIT4H37wunHot37bw7imfDs4RsuMKeBnvjv T1PJPDbLCXLOfNYIR04aWj8cAVP7HauZW7hXSsWdapV0ImVEKIO5hNq/UqY0MrIkDVBy Ai3fsvEUcAp10Xg5i4tyzw6UOIldJNF322+drnyMB33GmnRPc3x2IspapmfgbFXWEWL/ GURw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FIncW3q4; 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 j8sor2353481pll.70.2020.02.19.22.06.21 for (Google Transport Security); Wed, 19 Feb 2020 22:06:21 -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=FIncW3q4; 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=FwVgCncLbVot4SV9ouCUOJjc6U+mADi+9P9iseWgOPI=; b=FIncW3q427jUrJc76Y5wnHtilxkDdRipTd9Z0W6sQzjmc+I7zTxLGoIyw5+dU7OBr6 xrVqqX8ncq4AKJ6CL6Qmo+cGKPU73ueOlos1tpypHNlQ9M/EvpgTzwpB9AaEnQI8ck2v ms4ipHKtI5c1iTbQd9nEPS6BnFc4XgsIZlFyZd02dzlB9ONFilIOqF7K7KyGkZohLd8/ ewQy5rduuyxd99ICYAUd8gFtrG5NWZav4DTMTYEYj5gKuL5jCuiCM2t8XBn8CnbTCSvN niBFIKoC72wYfwWxxcYjLuo+3jO1dQPeLMcexsDoxjb9MfY0Cgz96/d2bqLFVL/D9jPv W/Lg== 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=FwVgCncLbVot4SV9ouCUOJjc6U+mADi+9P9iseWgOPI=; b=ZBXUJhaBfO4A+esAgMJBi1yIlC44pRNVsGzQMa94ggfdwBaDaRBp2TcelgCYcFYxYj 7Cywf4gNOBWiupbtpouOCr6GwQy4Mj/49V8rXZxyqcrfbQPi8SN8swaUZG14N2PO0+Dw 1PbuLgguWCEMPTTXW5thSKoqPA7O7FRIFy/JIENNayFQCUYccdlUZuVfnyiSR7RppYYR efTLiy8TWzxgDv8cTgLkNwbCnqsWO+8gCf4x5HCr4XLOtoeqWpj60YgrFT8O4/QrBCCG zq1UR0/JeDjI1AaZSP1hdPR2rRca6TQUIY73LDbTcHhq4YAwAKbORow+UnWrIWJbhnQd mCfQ== X-Gm-Message-State: APjAAAV9bax9jFpU3JVZglpJtPrNM0PkpspfZgmFPp8jhQbBZ4spWylo WQvoHye2e37kjRKWZs6mulECGJZnPVuDlQ== X-Google-Smtp-Source: APXvYqwnon8ICd/yoj8ge5wkuOIkItWJbqBTJlG7DQJMrVrVL6k/BZq66xnHxJjvkgHYIn2qovfoQA== X-Received: by 2002:a17:902:d20f:: with SMTP id t15mr30941281ply.55.1582178781449; Wed, 19 Feb 2020 22:06:21 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id v5sm1747887pgc.11.2020.02.19.22.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 22:06:20 -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: [PATCH v2] usb: dwc3: gadget: Update chain bit correctly when using sg list Date: Thu, 20 Feb 2020 06:06:16 +0000 Message-Id: <20200220060616.54389-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 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 1b8014ab0b25..721d897fef94 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) {