Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp592396pxx; Wed, 28 Oct 2020 11:55:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5bcPLj2eUcOULp0+paFWHhnTwQGKov6LzuhTAMrIcaIPz+wGilFCfP0cHQhcsET06cOHJ X-Received: by 2002:a05:6402:17e4:: with SMTP id t4mr348400edy.118.1603911326595; Wed, 28 Oct 2020 11:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603911326; cv=none; d=google.com; s=arc-20160816; b=zd4W2ARCo8jjC6o5lIBxbRzqk+g12QiQV3k9o98M5iNVoiu7pxcMYK6MjzIwSrxhqF CbbbSS7DCdlKUuv7KZCKmo6Cpue2bBiHSSy+3ublsHA+n/F5BVR6VZuxck2Kgn5uIua1 C52mBq+OETKpyNS/+tskwLP8gxYb0RL/17GuawQOnUpxF28a7KruefcI+G8879c3jdNJ HOJOR41rfY+IJ+Cwtm4tYvvbRMkPZd3BJ7Lpsj8zsK01cWXXm9mdSTM7U0dqWTeWlYB+ zeWnfJVemAksDCR3go38etGD2D33PIwfl+csF+sKdnztgvihQdhEnMhvB+xsoq2g6Dzk 0f6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0T2gaSRnnYNZJQd+2fBBAWgNpXV3RzCRSD/uh88K/yw=; b=IQT43XMWqrFLbzaDqJ7IIkLAxZ7cJPkh4ig3by/XMJxeZ3vfoFVwMqQflyERv/yIv4 P5x0f1eKc2zXXMJqso3MlvMa8eHm9XtJpXxokwIzP5qRtWyqn7V6uaTOkxidoeX8186r dWxTiC8iedTA6daSQ+kzdaO/ssmwTiVgUk8jlFkbJLMLDTrLp+wOPV/BqhiRsWnHvumZ fwcA9WSXZG53jngPOjECNoNGKWhkKYtIdK7T9A3WG180fDI1VJ7vPTvIj23oeFDSMz5P 8mr7RaraZAtQU4/43fyB8bRBF+pAnv8Q1wTXmV5Mixl7YhTcnRN/ObNI2ldf6/Fzod6E m+Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JEVWYGsM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y1si30775edp.57.2020.10.28.11.55.03; Wed, 28 Oct 2020 11:55:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JEVWYGsM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1826032AbgJ0SPV (ORCPT + 99 others); Tue, 27 Oct 2020 14:15:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:34094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1745903AbgJ0OMt (ORCPT ); Tue, 27 Oct 2020 10:12:49 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 081FB2072D; Tue, 27 Oct 2020 14:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807967; bh=d2vJnqc1igUd41tys1yFYhtr2g3demjzRaBzwvy58dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JEVWYGsMgtGDiQ7Sp5TDJAzVXhg4fls32r6XfQBmDPSl63UIY90yc6F1Ge6GK4PjE yxNzZwLq2COjgKcFTEDYBR3qVkRdQQurQqhGLVTyNueDQBvruYyyZWwvaaVJi2UvdI Pk7VH0uz12ZtVA39Nca1E0tYZGMGtNe8Ml5yIkKg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Maciej=20=C5=BBenczykowski?= , Lorenzo Colitti , Felipe Balbi , Sasha Levin Subject: [PATCH 4.14 076/191] usb: gadget: f_ncm: fix ncm_bitrate for SuperSpeed and above. Date: Tue, 27 Oct 2020 14:48:51 +0100 Message-Id: <20201027134913.365590192@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134909.701581493@linuxfoundation.org> References: <20201027134909.701581493@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lorenzo Colitti [ Upstream commit 986499b1569af980a819817f17238015b27793f6 ] 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") Reviewed-by: Maciej Żenczykowski Signed-off-by: Lorenzo Colitti Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- 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 f62cdf1238d77..fbf15ab700f49 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -92,8 +92,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 -- 2.25.1