From patchwork Mon Mar 6 11:36:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 659696 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19F29C6FD1A for ; Mon, 6 Mar 2023 11:37:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230193AbjCFLhC (ORCPT ); Mon, 6 Mar 2023 06:37:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230138AbjCFLhA (ORCPT ); Mon, 6 Mar 2023 06:37:00 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B21505595 for ; Mon, 6 Mar 2023 03:36:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678102618; x=1709638618; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=chlrvLtKWt2yT2etE61aoHQMymbTBF1ZzUMncaZ8CG0=; b=Gqaiw/OkhNeQ2e9kBimsVeuun+DZrddeDaMKc3SKv/1k54Z0zuBhhayF c5YJ8D4ntTHF/Gy3SZlTyGdSyALg9Ph3dDw2OaTainvE6hrZfl+RoJM+u Eq2L6koh8DPdMfcFcsN51uYhV3VpBdskJ6lOIN1Zhq+gjbk6xKykKVQOe n9elxw/bnx0KcMo0euG5Ee9jX5kJk/e2YKOfNevPTgV27KmnFNF88wd7d Y+XqbuBynZZnMOV46Gu8RwPBYLJahCrXY6DDDC8iVqqwe7gPQg2LczNqx wpKJy0A6zaXfM5+UgHwQYeJRc6d9tDzyQPpOy8cCyOanQx+TpnAjIvoNv w==; X-IronPort-AV: E=McAfee;i="6500,9779,10640"; a="363147610" X-IronPort-AV: E=Sophos;i="5.98,236,1673942400"; d="scan'208";a="363147610" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2023 03:35:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10640"; a="745024107" X-IronPort-AV: E=Sophos;i="5.98,236,1673942400"; d="scan'208";a="745024107" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 06 Mar 2023 03:35:25 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 46B63367; Mon, 6 Mar 2023 13:36:06 +0200 (EET) From: Mika Westerberg To: linux-usb@vger.kernel.org Cc: Yehezkel Bernat , Michael Jamet , Lukas Wunner , Andreas Noever , =?utf-8?q?Christian_Schaubschl?= =?utf-8?q?=C3=A4ger?= , Gil Fine , Mika Westerberg Subject: [PATCH 5/5] thunderbolt: Use scale field when allocating USB3 bandwidth Date: Mon, 6 Mar 2023 13:36:05 +0200 Message-Id: <20230306113605.46137-6-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230306113605.46137-1-mika.westerberg@linux.intel.com> References: <20230306113605.46137-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When tunneling aggregated USB3 (20 Gb/s) the bandwidth values that are programmed to the ADP_USB3_CS_2 go higher than 4096 and that does not fit anymmore to the 12-bit field. Fix this by scaling the value using the scale field accordingly. Fixes: 3b1d8d577ca8 ("thunderbolt: Implement USB3 bandwidth negotiation routines") Cc: stable@vger.kernel.org Signed-off-by: Mika Westerberg --- drivers/thunderbolt/usb4.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/thunderbolt/usb4.c b/drivers/thunderbolt/usb4.c index 6e87cf993c68..a0996cb2893c 100644 --- a/drivers/thunderbolt/usb4.c +++ b/drivers/thunderbolt/usb4.c @@ -2094,18 +2094,30 @@ static int usb4_usb3_port_write_allocated_bandwidth(struct tb_port *port, int downstream_bw) { u32 val, ubw, dbw, scale; - int ret; + int ret, max_bw; - /* Read the used scale, hardware default is 0 */ - ret = tb_port_read(port, &scale, TB_CFG_PORT, - port->cap_adap + ADP_USB3_CS_3, 1); + /* Figure out suitable scale */ + scale = 0; + max_bw = max(upstream_bw, downstream_bw); + while (scale < 64) { + if (mbps_to_usb3_bw(max_bw, scale) < 4096) + break; + scale++; + } + + if (WARN_ON(scale >= 64)) + return -EINVAL; + + ret = tb_port_write(port, &scale, TB_CFG_PORT, + port->cap_adap + ADP_USB3_CS_3, 1); if (ret) return ret; - scale &= ADP_USB3_CS_3_SCALE_MASK; ubw = mbps_to_usb3_bw(upstream_bw, scale); dbw = mbps_to_usb3_bw(downstream_bw, scale); + tb_port_dbg(port, "scaled bandwidth %u/%u, scale %u\n", ubw, dbw, scale); + ret = tb_port_read(port, &val, TB_CFG_PORT, port->cap_adap + ADP_USB3_CS_2, 1); if (ret)