From patchwork Tue Aug 25 05:55:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lorenzo Colitti X-Patchwork-Id: 11734969 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 85287138A for ; Tue, 25 Aug 2020 05:55:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 679962071E for ; Tue, 25 Aug 2020 05:55:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="FJAMJOfu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728958AbgHYFzc (ORCPT ); Tue, 25 Aug 2020 01:55:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726090AbgHYFzb (ORCPT ); Tue, 25 Aug 2020 01:55:31 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2554BC061574 for ; Mon, 24 Aug 2020 22:55:31 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id u128so8491228ybg.17 for ; Mon, 24 Aug 2020 22:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=GLqgHIx28cw7lshxvBTzb4LB5PmwBFMWJoYCImcYWRM=; b=FJAMJOfuEjq2t3r+vtRrSBP2uPxrM9iEGSb+y4l3VrnlROxigA0mNPtZCchZDAoNHH jdHIe8+WNpj4xAo3TIXcDGgSP1gAwfpw4mH0Bbhpd+CECqB6OY+quw+4glDGrq7qIr6k O4LrJnDhg9c3IaiZnIsaVY4BwdBsFAmPgymrb+nky6JrAdBHhbC6dj3uFHuTjke/bE76 swsdkasWhZ+KjaNuq56VUekJO6qguA1FcurMs/0sXTwO6c4AV5/vfeZzFrepfyiCClUc jpBm3mE6on8EzjVjdIFOEbozQwOreWDuPS+/wZB+k8JFmsWPzFfOQMDK0gjGS51b3ziS vT/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=GLqgHIx28cw7lshxvBTzb4LB5PmwBFMWJoYCImcYWRM=; b=UqZzhjwTwprxD10oZsMqCsTmmtiM81DBiy8gB7hnGk9i8+dTwv841K3dM4Mz8EpZbq DT6Qw8sAGaVydUCRlqixHCKwtnEMyGuosizfvCMFPxRaJM7lkyHQsOUg23jaXIb+lIea HcUhnvpor5nFvpGhaH2Xgao6v9V2nD6Qrkqi77YccBC9pzCiREA+HBDehCG2ujdFR/G/ QQw11gEP79h5fevP5KQvDUTpBl2GRgnZiK0KSegsqLurKYuR+k65bn6HuNlKW2iZ3/Gd 1u9cziKH3aFCUZxQJBPZ0paAyKFkCYA6SI/hNwDIKtubuMwYL5xyEjplj7UcItbunzXj wZdA== X-Gm-Message-State: AOAM533yiA3E+7JOiNlKcyZ0LAHLAUFmL5uG3DXClzfdUPlfrAAZgrKV EJJAvTiNwu1yxaDeZGWc+mdCL/Odt6o60U9mLCvopE8XYg2xLcRhWVfWjrigDQmG6Y+8+CtoMFE muTZsd6cTjR7XaTaIQdK00y64aU3z9tVr9o6JC3bNk9J3dTbFFTOyFeoxzl3J4bOrQLHA X-Google-Smtp-Source: ABdhPJz6xaz19X8bactEf0+/QPH+PK/CEQeGHVXsZOVCAse0HoQRODgGmYbYVo5faFA4B85fRb/gmzLCGmH/ X-Received: from lorenzo.tok.corp.google.com ([2401:fa00:8f:2:eeb1:d7ff:fe57:b7d5]) (user=lorenzo job=sendgmr) by 2002:a25:8812:: with SMTP id c18mr12950357ybl.330.1598334930286; Mon, 24 Aug 2020 22:55:30 -0700 (PDT) Date: Tue, 25 Aug 2020 14:55:03 +0900 In-Reply-To: <20200825055505.765782-1-lorenzo@google.com> Message-Id: <20200825055505.765782-2-lorenzo@google.com> Mime-Version: 1.0 References: <20200825055505.765782-1-lorenzo@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v3 1/3] usb: gadget: f_ncm: fix ncm_bitrate for SuperSpeed and above. From: Lorenzo Colitti To: linux-usb@vger.kernel.org Cc: balbi@kernel.org, gregkh@linuxfoundation.org, zenczykowski@gmail.com, Lorenzo Colitti Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Currently, SuperSpeed NCM gadgets report a speed of 851 Mbps in USB_CDC_NOTIFY_SPEED_CHANGE. But the calculation appears to assume 16 packets per microframe, and USB 3 and above no longer use microframes. Maximum speed is actually much higher. On a direct connection, theoretical throughput is at most 3.86 Gbps for gen1x1 and 9.36 Gbps for gen2x1, and I have seen gadget->host iperf throughput of >2 Gbps for gen1x1 and >4 Gbps for gen2x1. Unfortunately the ConnectionSpeedChange defined in the CDC spec only uses 32-bit values, so we can't report accurate numbers for 10Gbps and above. So, report 3.75Gbps for SuperSpeed (which is roughly maximum theoretical performance) and 4.25Gbps for SuperSpeed Plus (which is close to the maximum that we can report in a 32-bit unsigned integer). This results in: [50879.191272] cdc_ncm 2-2:1.0 enx228b127e050c: renamed from usb0 [50879.234778] cdc_ncm 2-2:1.0 enx228b127e050c: 3750 mbit/s downlink 3750 mbit/s uplink on SuperSpeed and: [50798.434527] cdc_ncm 8-2:1.0 enx228b127e050c: renamed from usb0 [50798.524278] cdc_ncm 8-2:1.0 enx228b127e050c: 4250 mbit/s downlink 4250 mbit/s uplink on SuperSpeed Plus. Fixes: 1650113888fe ("usb: gadget: f_ncm: add SuperSpeed descriptors for CDC NCM") Signed-off-by: Lorenzo Colitti Reviewed-by: Maciej Żenczykowski --- drivers/usb/gadget/function/f_ncm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index 1d900081b1..5b9266a87f 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -85,8 +85,10 @@ static inline struct f_ncm *func_to_ncm(struct usb_function *f) /* peak (theoretical) bulk transfer rate in bits-per-second */ static inline unsigned ncm_bitrate(struct usb_gadget *g) { - if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) - return 13 * 1024 * 8 * 1000 * 8; + if (gadget_is_superspeed(g) && g->speed >= USB_SPEED_SUPER_PLUS) + return 4250000000U; + else if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) + return 3750000000U; else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) return 13 * 512 * 8 * 1000 * 8; else From patchwork Tue Aug 25 05:55:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Colitti X-Patchwork-Id: 11734971 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EB7C13A4 for ; Tue, 25 Aug 2020 05:55:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4632320737 for ; Tue, 25 Aug 2020 05:55:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="fYzaqyTv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728960AbgHYFzh (ORCPT ); Tue, 25 Aug 2020 01:55:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726090AbgHYFzh (ORCPT ); Tue, 25 Aug 2020 01:55:37 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDA38C061574 for ; Mon, 24 Aug 2020 22:55:36 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id x10so13462251ybj.19 for ; Mon, 24 Aug 2020 22:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=wFRIBdJ1ItfhUjGduGxiL3+cKx0oCq2t7HhAcJi23o4=; b=fYzaqyTvsZkLHxpVOCE2/6GZqDQAH+u+hiAo4Qv7nIPAjwVA/NuEl3j17N3T6Wf1Fz bTSM771prVJEHqvYNz4XrFD8E3NSUgtrfFVukrPLTXBo8+4NlqZOggVHwBB8hLzp6s1n oPRM8JK2o3rwdEurh2o/tUKXwt5+xYxIh+frxiRAAx27ZqRM4NGmFv+6EBBPz8QFbVQX Mp1pWbowraHWPWU3wn4T9DKiAdVqyxCrlmAAUFxfT+CRR/mi2BC3EiDt6NkmDhUCRjwi 5nzLlB8pLHp1x3GIhxIJi+FzCkuSJl7NbpmIVwq1j5E2nelQgZL6KTxRmNVldKhSay8K mmQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=wFRIBdJ1ItfhUjGduGxiL3+cKx0oCq2t7HhAcJi23o4=; b=nAcmH9JdyUFFyfh+c2hfahb0S9QJsXcfkB9H4+7TUlMX7fMUZy6aZBS5s6VI3meFxC c2fie8FkdTkbHGy+7yfY3bwLjEHnmptTvtibPSVaCInpAOtBZAbWF/5WLF43Ur72P7Aa V+JU2mz72fwFHusGiwV9VaXzGixXrQWu5LYrN3lL5XTMad5+Zd4RO4Uf4p63vez6v3oh mJj0K7UygGlQN+dGDdKkHKNL6M/lDPuDVA+foKQpR8K2744DmL0D3z8qF+g29LQ1dGOa f+OsZA9Z1C8ofNBm9psmKta46FAi4RJSx5orMO3eyx33je6llRCDjrbC1T5yzhcuJAAx f46Q== X-Gm-Message-State: AOAM531TEBNjoSjUqX+RdWW9P8n2wYNUEMEzDMZtmYkd504pHwFv5t6b Vs+tQptCN/dtoKB/k3hy3Y4VfHuzJCXA820Dg8IfY2ruHzM2W7GHr7z8GjHLSfXrmqdxhdeqGCA /KhEyCvQ5naeJB3YW9565FfrWZEgrhTdmOmy6etEMOHSI3hKY8kLbRo6DJ4xLMui2pSQr X-Google-Smtp-Source: ABdhPJzvW8O/MZQvwDC3SVr4nTk+EMyMSOv9jzCNfKhDOtqHN6QRf10sbtnrG3LtrRBbd43zgUrVXUlyiejQ X-Received: from lorenzo.tok.corp.google.com ([2401:fa00:8f:2:eeb1:d7ff:fe57:b7d5]) (user=lorenzo job=sendgmr) by 2002:a25:ca50:: with SMTP id a77mr12576319ybg.286.1598334935919; Mon, 24 Aug 2020 22:55:35 -0700 (PDT) Date: Tue, 25 Aug 2020 14:55:04 +0900 In-Reply-To: <20200825055505.765782-1-lorenzo@google.com> Message-Id: <20200825055505.765782-3-lorenzo@google.com> Mime-Version: 1.0 References: <20200825055505.765782-1-lorenzo@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v3 2/3] usb: gadget: f_ncm: set SuperSpeed bulk descriptor bMaxBurst to 15 From: Lorenzo Colitti To: linux-usb@vger.kernel.org Cc: balbi@kernel.org, gregkh@linuxfoundation.org, zenczykowski@gmail.com, Lorenzo Colitti Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This improves performance on fast connections. When directly connecting to a Linux laptop running 5.6, single-stream iperf3 goes from ~1.7Gbps to ~2.3Gbps out, and from ~620Mbps to ~720Mbps in. Signed-off-by: Lorenzo Colitti --- drivers/usb/gadget/function/f_ncm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index 5b9266a87f..cad3c9dd61 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -378,7 +378,7 @@ static struct usb_ss_ep_comp_descriptor ss_ncm_bulk_comp_desc = { .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, /* the following 2 values can be tweaked if necessary */ - /* .bMaxBurst = 0, */ + .bMaxBurst = 15, /* .bmAttributes = 0, */ }; From patchwork Tue Aug 25 05:55:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lorenzo Colitti X-Patchwork-Id: 11734973 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C3FF138A for ; Tue, 25 Aug 2020 05:55:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8A8A20738 for ; Tue, 25 Aug 2020 05:55:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="lmEWcWpn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728962AbgHYFzp (ORCPT ); Tue, 25 Aug 2020 01:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726090AbgHYFzo (ORCPT ); Tue, 25 Aug 2020 01:55:44 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9D66C061574 for ; Mon, 24 Aug 2020 22:55:42 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id x6so13609776ybp.10 for ; Mon, 24 Aug 2020 22:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=/BQ21twV62wm0lZCEx/wKH14rKu7noBUW7yQqP/JfhU=; b=lmEWcWpnlFoqZ2r3egJI/eCTh8HJeoidQqPC4IDXzbIPUonPCTCog/KZsG7iWNs9l6 +9u5qiqfNsnXqNyNRq/WhTS3aODErN8aytXabqqVEYrJT51KRq0YLBoezu9wV/mi6im/ ZHovk//hkliJiWqs7184C6+/fBWjZ2JCAJVXLZsNInkgMTFUeatr1Yw2vg8jIi628i+W xIFnNmFMnVcKBNNrh2KwTlldYWPuO7GICsFrG5r32P3OuUpAJxo1kYSjBsClDta1nnej FkfVCQSsQ9JulF0JNwvE9wScNJOk+J2UCa3y0qPisxQFSB1G+MS8t7zmtJZUu2az0Emm zfvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=/BQ21twV62wm0lZCEx/wKH14rKu7noBUW7yQqP/JfhU=; b=OiEuyxPT0ZkJXbWSj+BaESdCQ6MiwjEz7HHGCVHjDZHoj7X7JxHFXFE++IXRXCaMhk i0RhIwR/ooDvDyTxpiiw6DJEi7G++xEXp8Bq76lkkHJyf61ssh6IU5luYgUx9xEBdjob CANIr2eboFcX64BAwJlKg7t/eHNz/+/DF1Olk0qe0H0n975csqVJINiiOYKDgooc4SuM mC1odyS2ZzmjzrpFq3b+pZiCc/KL/Mo82nUGBP3egobFMcxU5ltndigwdj0XzMjdMPUn z5RK/19TBhRXOt2ifQMOyVKotdIlPDFM82gB33Loa7VXYQZTBE9bMCxs6wb4fG/kBw0c /W7w== X-Gm-Message-State: AOAM530F0As9wy86cWYhgUoZnmmXFaOkmdBcQ+z725itv0mgceprjxi0 Ia6gbbGOYz0pKIKuE+oGSsqriJ1oJRhUbwD94xJ0OBM7LI5Hg6n3jlNOi9oOUAuc51gyUBJiaM3 WEtdc2iZtwHipNLYTWtADHGCboqiNGV4sCT+XZh3ZQQ//GdpN+14MiXTLB5K75OqI7uBH X-Google-Smtp-Source: ABdhPJzadoyLYQdE6j5NlFGhrC7eALNHGQ8wWGZBnYhwqbrWUNSA1uK3hbCvj2mRrSkrLBD146fiLIM/O19A X-Received: from lorenzo.tok.corp.google.com ([2401:fa00:8f:2:eeb1:d7ff:fe57:b7d5]) (user=lorenzo job=sendgmr) by 2002:a25:c791:: with SMTP id w139mr12018913ybe.345.1598334942114; Mon, 24 Aug 2020 22:55:42 -0700 (PDT) Date: Tue, 25 Aug 2020 14:55:05 +0900 In-Reply-To: <20200825055505.765782-1-lorenzo@google.com> Message-Id: <20200825055505.765782-4-lorenzo@google.com> Mime-Version: 1.0 References: <20200825055505.765782-1-lorenzo@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v3 3/3] usb: gadget: f_ncm: allow using NCM in SuperSpeed Plus gadgets. From: Lorenzo Colitti To: linux-usb@vger.kernel.org Cc: balbi@kernel.org, gregkh@linuxfoundation.org, zenczykowski@gmail.com, Lorenzo Colitti Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Currently, enabling f_ncm at SuperSpeed Plus speeds results in an oops in config_ep_by_speed because ncm_set_alt passes in NULL ssp_descriptors. Fix this by re-using the SuperSpeed descriptors. This is safe because usb_assign_descriptors calls usb_copy_descriptors. Tested: enabled f_ncm on a dwc3 gadget and 10Gbps link, ran iperf Signed-off-by: Lorenzo Colitti Reviewed-by: Maciej Żenczykowski --- drivers/usb/gadget/function/f_ncm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index cad3c9dd61..87f548bd97 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -1505,7 +1505,7 @@ static int ncm_bind(struct usb_configuration *c, struct usb_function *f) fs_ncm_notify_desc.bEndpointAddress; status = usb_assign_descriptors(f, ncm_fs_function, ncm_hs_function, - ncm_ss_function, NULL); + ncm_ss_function, ncm_ss_function); if (status) goto fail;