From patchwork Mon Jan 27 19:30:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 182984 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp4142191ile; Mon, 27 Jan 2020 11:30:50 -0800 (PST) X-Received: by 2002:a62:ee11:: with SMTP id e17mr214814pfi.48.1580153450514; Mon, 27 Jan 2020 11:30:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580153450; cv=none; d=google.com; s=arc-20160816; b=fe83ffqtITR4C6ikFAk+60+eEayuYZj9Jvc+W0FEK6W9pEU6GhKoWKxp1w0oWTSLs8 PFM4IYLbDZtuqwSL19+vwGOn9wLXzrgInkX9oD0gGI5N4Ud6xJ8YOWJWoVwyDeU8bJlz VPm8Nnw+Su3D59XGK87rQL+uTFvJquLoo+whfHRWLeHNDfrrDrDKQJRhj2PaEkJAZfTW 9wWHXG8BJ22wpIoEM6D1r6bRVef/LWzXZ5Tb+ipWXWWL9YvrcpUJ4uRM6hXKrmysvCGD FkgWG4gKDbG2LrJDP4ixwdRbO13/fISXuJ2dS6fAHMmidmC7GpsDMIX3dWxLMoSp7KsS HR1g== 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=4FpDeS7FVDfifQejKt5Fo3FpOuyI3aVXyTigplJTJKg=; b=uOdrn1DazYUNRwN+SiARU7R3LgniyvqNFAEAito2u3xQQPsDRa9lhGLUCy/gI+J/eq CxrKOJY+CiMu7g16Q8Lp/FvS3n7Pxxg5CSYUsKfSfZWfUJB6L5nsYLcOhUXREj7he7mE b9kn/bctxC7nYbx2TOoxv4uzXRrA6gfs0G/zrBPZEMXawQ3Qzk6WzitoOF1hGsT2cwMf D4jsGB+59eXn0x0Y8RMy69YKXJ/0i95NJCgt1oJF3kCO9Uz709o3v8D/0yIz71ztR/7/ 7Xg43FMhl9W1sXAUoCsgMvk2fcnnpy3NDa3bIGdGk4/Huen59BuUMjvc6t39O+qyvlEZ 288w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=elJrTPL4; 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 bt16sor7155046pjb.7.2020.01.27.11.30.50 for (Google Transport Security); Mon, 27 Jan 2020 11:30:50 -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=elJrTPL4; 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=4FpDeS7FVDfifQejKt5Fo3FpOuyI3aVXyTigplJTJKg=; b=elJrTPL4i5D0s3VuCe3A4IDJCMJuckpknfF6RIj8HfDon93rN/Eqzm8gM7opbJMwtg +olHjcgUyYyCp6ww5p5oyoHP5iI0CRYn81PHwx0DJxXLDgTpxKOJQ9U87JTTzHWG7Q0Q ZU7VDPNvyMmPVgsEaV3yLk0o2tiP1EGvzlAy/THV0fNIp2kl8NcYAicRC8bdPPvYXuiN nftlTxOTXAO2K0Z4hKH7cYPykfFl9cqSVl11uuxm6YXeRxO8g9DdkB8Fw+8Ux5+dO+1k EpKJAVe9HrdQX3VpnlSo8njj5kQdqYeb5f6yjOXsP3e4VhjxFigNXszMJNPAujQRe42Y PQRQ== 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=4FpDeS7FVDfifQejKt5Fo3FpOuyI3aVXyTigplJTJKg=; b=D8QDxtmoCqkFMvJ19f7eRpTEwnRczoXesFAwU09tWLFQ/HgUcYIJ+uEi/M2fT4pY7q gre9nkvMrMPCUeyypuH4fkM9P0noa9FdO6rN94vbr9fbCTRx1hyCeknXPgeKecZq4ZJG BFHqV81dvimP8rfkqEjcA/FMn02ObnmGDbm020s2+ufonAJbpwx/OADQf5GRX/GAR9Aa NCwqRoosZKua6UJj5dFc5juSmtfZvPaiRL9XE2odAXhtE+wh/1q5LHxyyg8bPS8XIJ1X PX9mJM/v6b8eSqi0A7FZVj53AVzVhls2OxeX86vl0I2j8qCOuxwyEtQFfINfjAGgr+W5 ImRQ== X-Gm-Message-State: APjAAAUsge1hYwURPRd2eM2uXjfpyN0ePS+BnStPPJ+hy+/fp3Dohtxt zN2Tr86G/rSKnQ9RnWtAZ9fhS/Hx X-Google-Smtp-Source: APXvYqzh/Vr2MusTZAdq4TOlr4ztx3Wty77tirQdE63vSY4MuktYCgn7bpoGIcSfXi+Hff+43HUCfw== X-Received: by 2002:a17:90a:858a:: with SMTP id m10mr200813pjn.117.1580153450023; Mon, 27 Jan 2020 11:30:50 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id k26sm9349186pfp.47.2020.01.27.11.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 11:30:49 -0800 (PST) From: John Stultz To: lkml Cc: Anurag Kumar Vulisha , 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: Check for IOC/LST bit in TRB->ctrl fields Date: Mon, 27 Jan 2020 19:30:46 +0000 Message-Id: <20200127193046.110258-1-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 From: Anurag Kumar Vulisha The current code in dwc3_gadget_ep_reclaim_completed_trb() will check for IOC/LST bit in the event->status and returns if IOC/LST bit is set. This logic doesn't work if multiple TRBs are queued per request and the IOC/LST bit is set on the last TRB of that request. Consider an example where a queued request has multiple queued TRBs and IOC/LST bit is set only for the last TRB. In this case, the core generates XferComplete/XferInProgress events only for the last TRB (since IOC/LST are set only for the last TRB). As per the logic in dwc3_gadget_ep_reclaim_completed_trb() event->status is checked for IOC/LST bit and returns on the first TRB. This leaves the remaining TRBs left unhandled. Similarly, if the gadget function enqueues an unaligned request with sglist already in it, it should fail the same way, since we will append another TRB to something that already uses more than one TRB. To aviod this, this patch changes the code to check for IOC/LST bits in TRB->ctrl instead. At a practical level, this patch resolves USB transfer stalls seen with adb on dwc3 based HiKey960 after functionfs gadget added scatter-gather support around v4.20. 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 Tested-by: Tejas Joglekar Reviewed-by: Thinh Nguyen Signed-off-by: Anurag Kumar Vulisha [jstultz: forward ported to mainline, reworded commit log, reworked to only check trb->ctrl as suggested by Felipe] Signed-off-by: John Stultz --- v2: * Rework to only check trb->ctrl as suggested by Felipe * Reword the commit message to include more of Felipe's assessment --- drivers/usb/dwc3/gadget.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 154f3f3e8cff..9a085eee1ae3 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2420,7 +2420,8 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, if (event->status & DEPEVT_STATUS_SHORT && !chain) return 1; - if (event->status & DEPEVT_STATUS_IOC) + if ((trb->ctrl & DWC3_TRB_CTRL_IOC) || + (trb->ctrl & DWC3_TRB_CTRL_LST)) return 1; return 0;