From patchwork Fri Nov 16 03:03:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 10685529 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABE0814D6 for ; Fri, 16 Nov 2018 03:03:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E6E920408 for ; Fri, 16 Nov 2018 03:03:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 919692D471; Fri, 16 Nov 2018 03:03:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED8B62D309 for ; Fri, 16 Nov 2018 03:03:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727215AbeKPNN6 (ORCPT ); Fri, 16 Nov 2018 08:13:58 -0500 Received: from us01smtprelay-2.synopsys.com ([198.182.60.111]:36660 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726714AbeKPNN6 (ORCPT ); Fri, 16 Nov 2018 08:13:58 -0500 Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id 00F7B10C10A2; Thu, 15 Nov 2018 19:03:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1542337403; bh=F9KXAieUBb93KRfIJySygbuTGgypp8l4kz6d1wDPt18=; h=Date:From:Subject:To:CC:From; b=FeeFCaHT+U44VDBsNxxWbku15qnKOe3vCCt40wg2EGlXzjR+psD6ah46P6q0uJw9i mxCpkNPqV/AUlbUyJQOU7u3S/W+olW1wjrq/sdxtqe1VbTy8y9Bl4S8E1dQ7GfO2BB XkY/OBYYXZjA3xWu+68HMBaU43Ak9YtHao9+vd+uicw9anTECiwQrSy21qsyNcka0W N8ZmPONhVG/PWFfOo1fIolRhN8yrBnfyxHB514viVT9oJhl4jyb0a9Lkb84lYbv79X H192U6ia6Q2bWlgdTf3zH9CSSf+Lq+JHGL9Yw31K1mAfsh2h20puJUr3LQ0Hhxih8P 1h2+muAlRWZQQ== Received: from US01WEHTC3.internal.synopsys.com (us01wehtc3.internal.synopsys.com [10.15.84.232]) by mailhost.synopsys.com (Postfix) with ESMTP id D47CE36C4; Thu, 15 Nov 2018 19:03:22 -0800 (PST) Received: from US01WEHTC1.internal.synopsys.com (10.12.239.236) by US01WEHTC3.internal.synopsys.com (10.15.84.232) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 15 Nov 2018 19:03:22 -0800 Received: from te-lab16 (10.13.184.20) by us01wehtc1.internal.synopsys.com (10.12.239.236) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 15 Nov 2018 19:03:21 -0800 Received: by te-lab16 (sSMTP sendmail emulation); Thu, 15 Nov 2018 19:03:21 -0800 Date: Thu, 15 Nov 2018 19:03:21 -0800 Message-ID: From: Thinh Nguyen Subject: [PATCH v3 1/2] usb: gadget: Introduce frame_number to usb_request To: Felipe Balbi , Greg Kroah-Hartman , CC: John Youn , Thinh Nguyen MIME-Version: 1.0 X-Originating-IP: [10.13.184.20] Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a field frame_number to the usb_request to report the interval number in (micro)frames in which the isochronous transfer was transmitted or received. The gadget driver can use this knowledge to synchronize with the host. Also, this option is useful for debugging purposes. Signed-off-by: Thinh Nguyen --- Change in v3: - Rename the "start_frame" field to "frame_number" - Redefine the frame_number meaning and purpose Change in v2: - None include/linux/usb/gadget.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index e5cd84a0f84a..7595056b96c1 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -61,6 +61,8 @@ struct usb_ep; * invalidated by the error may first be dequeued. * @context: For use by the completion callback * @list: For use by the gadget driver. + * @frame_number: Reports the interval number in (micro)frame in which the + * isochronous transfer was transmitted or received. * @status: Reports completion code, zero or a negative errno. * Normally, faults block the transfer queue from advancing until * the completion callback returns. @@ -112,6 +114,8 @@ struct usb_request { void *context; struct list_head list; + unsigned frame_number; /* ISO ONLY */ + int status; unsigned actual; }; From patchwork Fri Nov 16 03:03:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 10685531 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 809C31709 for ; Fri, 16 Nov 2018 03:03:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71F0D283A6 for ; Fri, 16 Nov 2018 03:03:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 642942787C; Fri, 16 Nov 2018 03:03:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03F0920408 for ; Fri, 16 Nov 2018 03:03:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727231AbeKPNOF (ORCPT ); Fri, 16 Nov 2018 08:14:05 -0500 Received: from smtprelay4.synopsys.com ([198.182.47.9]:33658 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726714AbeKPNOE (ORCPT ); Fri, 16 Nov 2018 08:14:04 -0500 Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id 5711324E0F88; Thu, 15 Nov 2018 19:03:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1542337409; bh=GV9fklMgPxiB8RmKk+GyOpgryYveRG6SrhADPtNto08=; h=Date:In-Reply-To:References:From:Subject:To:CC:From; b=GZdtq1aGaNOXEX4ARxiszyH2IhAwNcnrCnIYlTMBePoiwK5xPyPVfsJqF9zP5XI/T 9a0BW3Ix5isdNz5Y18A7bK3oXJukzEwkrX95deyHtKmz+se85sZNUUg9UHVZmoZJDH UfMjr7th2UoYnNXHgODSpPFoS1HArZtNGvy1srT/1f3OD7NKBL9ecwBDCS1DL5E50S e/y2KG536bXeQt9YrtHe1DAm3b9TnEHZUrPPXnO3BBt52C7oFLE8HHqYz+IgJfbuJT CSOuF8vGgeMNw6a8OpGQYxQ6kebrHb54CmVPC5GPIVnPLzYbsk/mPpLwhTsu5uUOBl 5em/MtESqm9Rw== Received: from US01WEHTC2.internal.synopsys.com (us01wehtc2-vip.internal.synopsys.com [10.12.239.238]) by mailhost.synopsys.com (Postfix) with ESMTP id 4447F36E0; Thu, 15 Nov 2018 19:03:29 -0800 (PST) Received: from US01WEHTC1.internal.synopsys.com (10.12.239.236) by US01WEHTC2.internal.synopsys.com (10.12.239.237) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 15 Nov 2018 19:03:29 -0800 Received: from te-lab16 (10.13.184.20) by us01wehtc1.internal.synopsys.com (10.12.239.236) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 15 Nov 2018 19:03:27 -0800 Received: by te-lab16 (sSMTP sendmail emulation); Thu, 15 Nov 2018 19:03:27 -0800 Date: Thu, 15 Nov 2018 19:03:27 -0800 Message-ID: <44b1e6169ea672ddc6f6d035ef081bc96b1c1bec.1542336692.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v3 2/2] usb: dwc3: gadget: Report isoc transfer frame number To: Felipe Balbi , Greg Kroah-Hartman , CC: John Youn , Thinh Nguyen MIME-Version: 1.0 X-Originating-IP: [10.13.184.20] Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement the new frame_number API to report the isochronous interval frame number. This patch checks and reports the interval in which the isoc transfer was transmitted or received via the Isoc-First TRB SOF number field. Signed-off-by: Thinh Nguyen --- Change in v3: - Implement the change with the redefined frame_number meaning Change in v2: - Capture frame number at request cleanup drivers/usb/dwc3/core.h | 1 + drivers/usb/dwc3/gadget.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index ed0359d1216d..2c9f7a93147a 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -777,6 +777,7 @@ enum dwc3_link_state { #define DWC3_TRB_CTRL_ISP_IMI BIT(10) #define DWC3_TRB_CTRL_IOC BIT(11) #define DWC3_TRB_CTRL_SID_SOFN(n) (((n) & 0xffff) << 14) +#define DWC3_TRB_CTRL_GET_SID_SOFN(n) (((n) & (0xffff << 14)) >> 14) #define DWC3_TRBCTL_TYPE(n) ((n) & (0x3f << 4)) #define DWC3_TRBCTL_NORMAL DWC3_TRB_CTRL_TRBCTL(1) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 679c12e14522..2de563124fc1 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2254,6 +2254,19 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, if (chain && (trb->ctrl & DWC3_TRB_CTRL_HWO)) trb->ctrl &= ~DWC3_TRB_CTRL_HWO; + /* + * For isochronous transfers, the first TRB in a service interval must + * have the Isoc-First type. Track and report its interval frame number. + */ + if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && + (trb->ctrl & DWC3_TRBCTL_ISOCHRONOUS_FIRST)) { + unsigned int frame_number; + + frame_number = DWC3_TRB_CTRL_GET_SID_SOFN(trb->ctrl); + frame_number &= ~(dep->interval - 1); + req->request.frame_number = frame_number; + } + /* * If we're dealing with unaligned size OUT transfer, we will be left * with one TRB pending in the ring. We need to manually clear HWO bit