From patchwork Tue Feb 18 23:51:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 183622 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp6688939ile; Tue, 18 Feb 2020 15:51:12 -0800 (PST) X-Received: by 2002:a63:b143:: with SMTP id g3mr24317411pgp.205.1582069871994; Tue, 18 Feb 2020 15:51:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582069871; cv=none; d=google.com; s=arc-20160816; b=TGkinYJ+gY8AgsXSd7P2roCjRwG1vlH2+joUQXJO4MrtYccIFNTDM7sOa4gzOl8XSB yyk7ETK7VyZ5521bmBPsnWM9IrbhAtehbb9nc11x2fSMpAvTZENSO/G+/TDoLLyhbKux atKz9aO0YuoHdLzRGW4sytubqGetPD8GPFnc1jK9xqPrI8Uc6ygi6STZryL8iw7g5i1W YGFYehT7tCsSItxLi8gCrWJ7JGscgFUm1fxFEh0sGr4dpmzCGl7FKQUAeygmMlunFRF9 RUlFcOrLv5tdRvyHXIZJ4iq5aY4T0Zs718EjNp4UtyV3csH/88O3NkbpRxVNkxDjk/Yt 5pwA== 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=H9Vy91VcgS2dfjojUgyTLRgs44OJ1u3F7tZb9F/g2s4=; b=msqAZ4cbOShmawDPciw1K/SqvLvSN/w2tdm0x4MkfoHo5pypGHU13f38hZGG71eiyI stLKW6dkmLKemWgvBSSQ2MXsPvaV/sGIyQSUhLZBqi0T4EBtFeOcEZSzNI+RoVCcCWHq /1+FpQw/62hOGq0dxaQnuVVmfqW4q0GjM1cAamNPhVRWAADmBO+Ru3ltbRp3UdfHqdTh 4HSZmpj6k8h64xmTN85r+sOTl+5CXQTQ6xuOxYh6GfPlBY0tU3W7MD+pFILkvWpPDoPl iG7vLrL2cb4vYaoCyi47UJzJJX3st8YOvgLyhmaoU/wWKkIf5p4JICClq2bbdCGTqqQA LynQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XtjY32mo; 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 e11sor4831560pjj.22.2020.02.18.15.51.11 for (Google Transport Security); Tue, 18 Feb 2020 15:51:11 -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=XtjY32mo; 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=H9Vy91VcgS2dfjojUgyTLRgs44OJ1u3F7tZb9F/g2s4=; b=XtjY32moCVDQQioAXHxahEf5oYVhgz+Ms4AFWGGTaFP4778HtoUNBVCZbW/C2qLolT kDIi0JZqXC7NMPPKTviR9qMq/uEd/2YzpTjSe9IaITXu8Pl4JEDP9qbdg7sIIRVZ//1i KtiroPgJmXpywPRGIY+tRmnl8PQ6+OMwaraP1VH0SOJ5WbBohMTNLRPRezZYc2qxq/sa 2W6kvsh9Fs6Fpve+mm0yDRQIeZ7choax1gRTSiFCOkog4mfLEzJV9OH+KkcYvUUFNjHX S+Hc+3xvGjLdqBzUhHT2TzNGdEjWroRfLHHYpwd/TbZj2sO/pVmhcBrNVgTGZQBeSp5j XUIA== 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=H9Vy91VcgS2dfjojUgyTLRgs44OJ1u3F7tZb9F/g2s4=; b=txSlT+SmmVNgpCLBY0UhKC7CJ6MLoHTkJXvC0i5syb2aoH+Hf6BTvngBwTUzFtdcLy cRBkY8fMjvRQStHqmUTwWtkFB4U3IoLGyncR48FO4f1PV9Fdf6upZkItNVQsEay4JZwB R+Pwn0g0upUsG20SMNk8TFL8ambnYNAWTbrGtLG+o9WXJBB4+GbV64fdcmcZfpsYfpoO 72Sq8SeGvC0Ix3aJG6m5ScuOeqgqWPJL0+t1UyZVjZDCi4110IiDJnKnCc5U7eXjNksh DOyfjDZgwmU/QfeNudEt4ixYVET9CojDLTDPQzl71hglkQi7l9YRv94Ah1SlpKWsawKN LdWQ== X-Gm-Message-State: APjAAAXh4jx9MWQyGpaX+3pVLswnrD4IEjo7McaKsNWVZewLtQZWp67r yMS0UyKc6i/oe1MAG5MKwjZEgw+F X-Google-Smtp-Source: APXvYqxZ65WQ76i7D3Y4yE+ieYshnEw5upVN5/4FZ5xFsoWgY9MsPSPIm9vhiPRL+clNxV3M8q/PVw== X-Received: by 2002:a17:90b:1256:: with SMTP id gx22mr5711887pjb.94.1582069871497; Tue, 18 Feb 2020 15:51:11 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id b1sm88455pgs.27.2020.02.18.15.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 15:51:10 -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] usb: dwc3: gadget: Update chain bit correctly when using sg list Date: Tue, 18 Feb 2020 23:51:04 +0000 Message-Id: <20200218235104.112323-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 --- 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..10aa511051e8 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 it not equal to the the number + * of sgs passed. Mark the chain bit to false if it is the last + * mapped sg. + */ + if ((i == remaining - 1)) chain = false; if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) {