From patchwork Thu Nov 8 06:57:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 10673595 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 F3AC113AD for ; Thu, 8 Nov 2018 06:57:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2CFA2BFA5 for ; Thu, 8 Nov 2018 06:57:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6A962CA60; Thu, 8 Nov 2018 06:57:47 +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=-7.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SUBJ_OBFU_PUNCT_FEW 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 4E6D02BFA5 for ; Thu, 8 Nov 2018 06:57:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726323AbeKHQbs (ORCPT ); Thu, 8 Nov 2018 11:31:48 -0500 Received: from mga17.intel.com ([192.55.52.151]:56448 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726027AbeKHQbs (ORCPT ); Thu, 8 Nov 2018 11:31:48 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Nov 2018 22:57:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,478,1534834800"; d="scan'208";a="84239119" Received: from pipin.fi.intel.com (HELO localhost) ([10.237.72.128]) by fmsmga007.fm.intel.com with ESMTP; 07 Nov 2018 22:57:45 -0800 From: Felipe Balbi To: Linux USB Cc: Felipe Balbi Subject: [PATCH 1/4] usb: dwc3: gadget: return errors from __dwc3_gadget_start_isoc() Date: Thu, 8 Nov 2018 08:57:40 +0200 Message-Id: <20181108065743.20863-1-felipe.balbi@linux.intel.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 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 Sometimes, errors happen when kicking transfers from __dwc3_gadget_start_isoc(). In those cases, we need to pass along the error so gadget driver can make informed decisions. Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/gadget.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 64481da433ae..18c63137348d 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1266,17 +1266,17 @@ static int __dwc3_gadget_get_frame(struct dwc3 *dwc) return DWC3_DSTS_SOFFN(reg); } -static void __dwc3_gadget_start_isoc(struct dwc3_ep *dep) +static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep) { if (list_empty(&dep->pending_list)) { dev_info(dep->dwc->dev, "%s: ran out of requests\n", dep->name); dep->flags |= DWC3_EP_PENDING_REQUEST; - return; + return -EAGAIN; } dep->frame_number = DWC3_ALIGN_FRAME(dep); - __dwc3_gadget_kick_transfer(dep); + return __dwc3_gadget_kick_transfer(dep); } static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) @@ -1317,8 +1317,7 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) if ((dep->flags & DWC3_EP_PENDING_REQUEST)) { if (!(dep->flags & DWC3_EP_TRANSFER_STARTED)) { - __dwc3_gadget_start_isoc(dep); - return 0; + return __dwc3_gadget_start_isoc(dep); } } } @@ -2381,7 +2380,7 @@ static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3_ep *dep, const struct dwc3_event_depevt *event) { dwc3_gadget_endpoint_frame_from_event(dep, event); - __dwc3_gadget_start_isoc(dep); + (void) __dwc3_gadget_start_isoc(dep); } static void dwc3_endpoint_interrupt(struct dwc3 *dwc, From patchwork Thu Nov 8 06:57:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 10673597 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 0688013AD for ; Thu, 8 Nov 2018 06:57:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC1622BFA5 for ; Thu, 8 Nov 2018 06:57:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E05822CA60; Thu, 8 Nov 2018 06:57:49 +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=-7.9 required=2.0 tests=BAYES_00,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 9ADE22BFA5 for ; Thu, 8 Nov 2018 06:57:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726363AbeKHQbu (ORCPT ); Thu, 8 Nov 2018 11:31:50 -0500 Received: from mga11.intel.com ([192.55.52.93]:18569 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726027AbeKHQbu (ORCPT ); Thu, 8 Nov 2018 11:31:50 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Nov 2018 22:57:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,478,1534834800"; d="scan'208";a="89495842" Received: from pipin.fi.intel.com (HELO localhost) ([10.237.72.128]) by orsmga006.jf.intel.com with ESMTP; 07 Nov 2018 22:57:47 -0800 From: Felipe Balbi To: Linux USB Cc: Felipe Balbi Subject: [PATCH 2/4] usb: dwc3: trace: log ep commands in hex Date: Thu, 8 Nov 2018 08:57:41 +0200 Message-Id: <20181108065743.20863-2-felipe.balbi@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108065743.20863-1-felipe.balbi@linux.intel.com> References: <20181108065743.20863-1-felipe.balbi@linux.intel.com> MIME-Version: 1.0 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 They are much more useful in hexadecimal than in decimal. Moreover, generic commands are already logged in hex. Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/trace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h index f22714cce070..50fb6f2d92dd 100644 --- a/drivers/usb/dwc3/trace.h +++ b/drivers/usb/dwc3/trace.h @@ -199,7 +199,7 @@ DECLARE_EVENT_CLASS(dwc3_log_gadget_ep_cmd, __entry->param2 = params->param2; __entry->cmd_status = cmd_status; ), - TP_printk("%s: cmd '%s' [%d] params %08x %08x %08x --> status: %s", + TP_printk("%s: cmd '%s' [%x] params %08x %08x %08x --> status: %s", __get_str(name), dwc3_gadget_ep_cmd_string(__entry->cmd), __entry->cmd, __entry->param0, __entry->param1, __entry->param2, From patchwork Thu Nov 8 06:57:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 10673599 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 2C6C61751 for ; Thu, 8 Nov 2018 06:57:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E3162BFA5 for ; Thu, 8 Nov 2018 06:57:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12C9E2CA60; Thu, 8 Nov 2018 06:57:52 +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=-7.9 required=2.0 tests=BAYES_00,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 B842F2BFA5 for ; Thu, 8 Nov 2018 06:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726421AbeKHQbw (ORCPT ); Thu, 8 Nov 2018 11:31:52 -0500 Received: from mga02.intel.com ([134.134.136.20]:44705 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726027AbeKHQbw (ORCPT ); Thu, 8 Nov 2018 11:31:52 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Nov 2018 22:57:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,478,1534834800"; d="scan'208";a="106873523" Received: from pipin.fi.intel.com (HELO localhost) ([10.237.72.128]) by orsmga002.jf.intel.com with ESMTP; 07 Nov 2018 22:57:49 -0800 From: Felipe Balbi To: Linux USB Cc: Felipe Balbi Subject: [PATCH 3/4] usb: dwc3: gadget: remove unnecessary dev_info() Date: Thu, 8 Nov 2018 08:57:42 +0200 Message-Id: <20181108065743.20863-3-felipe.balbi@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108065743.20863-1-felipe.balbi@linux.intel.com> References: <20181108065743.20863-1-felipe.balbi@linux.intel.com> MIME-Version: 1.0 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 Running out of requests on isochronous endpoints is part of normal operation. We don't really need to know about it every time it happens. Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/gadget.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 18c63137348d..d8c7ad0c22e8 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1269,8 +1269,6 @@ static int __dwc3_gadget_get_frame(struct dwc3 *dwc) static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep) { if (list_empty(&dep->pending_list)) { - dev_info(dep->dwc->dev, "%s: ran out of requests\n", - dep->name); dep->flags |= DWC3_EP_PENDING_REQUEST; return -EAGAIN; } From patchwork Thu Nov 8 06:57:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 10673601 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 75FD71751 for ; Thu, 8 Nov 2018 06:57:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63D532BB79 for ; Thu, 8 Nov 2018 06:57:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 570B62C61C; Thu, 8 Nov 2018 06:57:54 +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=-7.9 required=2.0 tests=BAYES_00,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 F1D862BB79 for ; Thu, 8 Nov 2018 06:57:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726517AbeKHQbz (ORCPT ); Thu, 8 Nov 2018 11:31:55 -0500 Received: from mga06.intel.com ([134.134.136.31]:17719 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726480AbeKHQby (ORCPT ); Thu, 8 Nov 2018 11:31:54 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Nov 2018 22:57:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,478,1534834800"; d="scan'208";a="90382472" Received: from pipin.fi.intel.com (HELO localhost) ([10.237.72.128]) by orsmga008.jf.intel.com with ESMTP; 07 Nov 2018 22:57:51 -0800 From: Felipe Balbi To: Linux USB Cc: Felipe Balbi Subject: [PATCH 4/4] usb: dwc3: gadget: check if dep->frame_number is still valid Date: Thu, 8 Nov 2018 08:57:43 +0200 Message-Id: <20181108065743.20863-4-felipe.balbi@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108065743.20863-1-felipe.balbi@linux.intel.com> References: <20181108065743.20863-1-felipe.balbi@linux.intel.com> MIME-Version: 1.0 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 Gadget driver may take an unbounded amount of time to queue requests after XferNotReady. This is important for isochronous endpoints which need to be started for a specific (micro-)frame. Before kicking the transfer, let's check how much time has elapsed since dep->frame_number was updated and make sure we start the request to the next valid interval. Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/core.h | 5 +++++ drivers/usb/dwc3/gadget.c | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 131028501752..306a2dd75ed5 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -651,6 +651,7 @@ struct dwc3_event_buffer { * @number: endpoint number (1 - 15) * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK * @resource_index: Resource transfer index + * @frame_timestamp: timestamp of most recent frame number * @frame_number: set to the frame number we want this transfer to start (ISOC) * @interval: the interval on which the ISOC transfer is started * @name: a human readable name e.g. ep1out-bulk @@ -697,7 +698,11 @@ struct dwc3_ep { u8 number; u8 type; u8 resource_index; + + u64 frame_timestamp; u32 frame_number; +#define DWC3_EP_FRAME_NUMBER_MASK 0x3fff + u32 interval; char name[20]; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index d8c7ad0c22e8..00fe01a01977 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1268,12 +1268,22 @@ static int __dwc3_gadget_get_frame(struct dwc3 *dwc) static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep) { + u64 current_timestamp; + u64 diff_timestamp; + u32 elapsed_frames; + if (list_empty(&dep->pending_list)) { dep->flags |= DWC3_EP_PENDING_REQUEST; return -EAGAIN; } + current_timestamp = ktime_get_ns(); + diff_timestamp = current_timestamp - dep->frame_timestamp; + elapsed_frames = DIV_ROUND_UP_ULL(diff_timestamp, 125000); + + dep->frame_number += elapsed_frames; dep->frame_number = DWC3_ALIGN_FRAME(dep); + return __dwc3_gadget_kick_transfer(dep); } @@ -2320,6 +2330,7 @@ static void dwc3_gadget_endpoint_frame_from_event(struct dwc3_ep *dep, const struct dwc3_event_depevt *event) { dep->frame_number = event->parameters; + dep->frame_timestamp = ktime_get_ns(); } static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep,