Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2729208rdh; Wed, 27 Sep 2023 10:50:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFX7jcY2oaa7mxiH/h4xjsBaL/1eXiJfd3Z86sVjzaN0Y1vMWjUwP5N1VJr4Y96kHvVQaUP X-Received: by 2002:a05:6a20:3c8c:b0:161:76a4:4f79 with SMTP id b12-20020a056a203c8c00b0016176a44f79mr420678pzj.23.1695837050824; Wed, 27 Sep 2023 10:50:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695837050; cv=none; d=google.com; s=arc-20160816; b=rlGz7TQGCjxwxmmkZCuCuUhk66Po6iEZi2fqEd1fUkSHb74DmYl1XSN/8RWfCXV7tU hSCgykR3huklTp+Em6hqUVOJOX3jsQgIemOSQ4COx/imoa7alLVF2UDZ2aPuxZsJYSNF Ve5DidmC15n/8+XxkkyNRpe5+MbTiGw7xaop+YzHHE4DRXpviHQHYtqU8sUJmOgkHqUF 3RbO+yO5Gc+SuCcgHUqrRzQRDvNzIn6YYejmzAk99uutSKu3RiErn5v566vguBVa8XXJ Bt9gG2EyaUJ4ypGqdulsxSZK0lonenG/KI02aWhE0xGcJ6P8oA9UhF5jgyikaP+srjh/ cqBw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=AnVyIhUQftvj++Ho5Yy6rcq1eYnc1pWWiufohODrEFE=; fh=AGN/tYtQjW7mdZ75nxqNDap8wtPE9BlC41CQHrUz6ag=; b=Jb2mhntE0mpsgO0UlwlPPtN2EHipo3BWCeoWo9VILibDSG18O4WAuV7YtWkWY6Qb7Y BgGIc03GyvE6gOab0EQRIKOewPYVClUNg5d0yY0Lh5nZW3C32qJMEV+dVi3QZ6scqhwT X/ZJgvz0Bffd6MXa7juoE8Sm8uHhRNzh18geYuvLHEnTZucTL63Mz2r43fn9reK7a1+k CDrcuzp9S0+1G+G4X+DPf6hSRaC7EcKdAhX/WJtJOBWvzss7TihU1lgdn9uE5iOyi5m3 mxIyayPMCMCgzhQxYzLPu5ZooU+lYUSSFATlVD/yoEqoFugjOn/3R3VsJATIhxq2r5Jg yT/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yMMij82n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id c21-20020a17090aa61500b002776c8df9b7si6679783pjq.144.2023.09.27.10.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 10:50:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yMMij82n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 0106D8095F72; Wed, 27 Sep 2023 08:46:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232464AbjI0PqK (ORCPT + 99 others); Wed, 27 Sep 2023 11:46:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231849AbjI0PqJ (ORCPT ); Wed, 27 Sep 2023 11:46:09 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E46BF272AC for ; Wed, 27 Sep 2023 08:46:06 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3231df68584so7429559f8f.1 for ; Wed, 27 Sep 2023 08:46:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695829565; x=1696434365; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AnVyIhUQftvj++Ho5Yy6rcq1eYnc1pWWiufohODrEFE=; b=yMMij82nkhn4Th830NPLjXLNPcSSoWWVBozahIduJCUCr97mo97OVUDEnaUSIqHIn8 mB2+bKQFfdICXcxkcifGdTUhUFG0s7cTcx2viflW6pMBn2s01RlHhAGUyz8aYaQMdrXk Dwp3G9SRV+fm2cvq4NPT7yYTJaDodrhOfSBlbG95/og1E4w1Jjd48WhTGKQtgtbJ4lDF IWtElAfog+Wbm6L5MXKfCew5VKxWgJFJjm536l7oYh8Z0psCzMqJNVPCf4kcxmd/g0Q2 w55c+P+jV1i/xJOWuplzClh91O7xjX8qGtI8Fe6ugc5aFbIPicSPFQKdbU8Ja6n8+k9O T86w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695829565; x=1696434365; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AnVyIhUQftvj++Ho5Yy6rcq1eYnc1pWWiufohODrEFE=; b=tRhRl6IslrMgxZIR6MDqzjR7oTzNcqjY+UnwM5GoactHK+ujTfJPJsWQpVoJxjptRb jxjM1lRbtRaVkYwKrxexfa8PVqkhtQ5Netf6XfiihYtzsBFwVNrJG/KyyMGR7tSFlO/T ngtsEZ+rssxLLKbPEV9YNIMag6EvgS6qK7VXESHVVxFlbH7VrJaYJ3uDvDUiZTJucs1c bK6X3dY7Y5bVp2Atd2DM7wHxN3ZVirwV4a5II1/h/yT2Rbuz4r94tAy1+ZchcXQxEvwU aLPuLH24QTOcNASbtw2indabchU+N0tJysyHYj+Uypn8a0FvHICB2CutzfkfBpcjHheM WPqw== X-Gm-Message-State: AOJu0Yz9uldOMr2Uiop0HNfe6fHMxPwgDup+uiZEKxtUyKwOgT2mg6J+ qzZ0QeTun/ydx6evXpNZIkrW X-Received: by 2002:a05:6000:4cd:b0:321:4df5:b85e with SMTP id h13-20020a05600004cd00b003214df5b85emr2167996wri.26.1695829565184; Wed, 27 Sep 2023 08:46:05 -0700 (PDT) Received: from thinkpad.fritz.box ([2a02:2454:9d09:3f00:b024:394e:56d7:d8b4]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm6925852wra.108.2023.09.27.08.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 08:46:04 -0700 (PDT) From: Manivannan Sadhasivam To: lpieralisi@kernel.org, kw@linux.com Cc: andersson@kernel.org, konrad.dybcio@linaro.org, bhelgaas@google.com, linux-arm-msm@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, abel.vesa@linaro.org, Manivannan Sadhasivam Subject: [PATCH v3 1/3] PCI: qcom: Make use of PCIE_SPEED2MBS_ENC() macro for encoding link speed Date: Wed, 27 Sep 2023 17:46:01 +0200 Message-Id: <20230927154603.172049-1-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 27 Sep 2023 08:46:28 -0700 (PDT) Instead of hardcoding the link speed in MBps, let's make use of the existing PCIE_SPEED2MBS_ENC() macro that does the encoding of the link speed for us. Also, let's Wrap it with QCOM_PCIE_LINK_SPEED_TO_BW() macro to do the conversion to ICC speed. This eliminates the need for a switch case in qcom_pcie_icc_update() and also works for future Gen speeds without any code modifications. Suggested-by: Bjorn Helgaas Signed-off-by: Manivannan Sadhasivam --- Changes in v3: - Used Mbps_to_icc() macro and changed the commit message a bit Changes in v2: - Switched to QCOM_PCIE_LINK_SPEED_TO_BW() macro as per Bjorn's suggestion https://lore.kernel.org/linux-pci/20230924160713.217086-1-manivannan.sadhasivam@linaro.org/ drivers/pci/controller/dwc/pcie-qcom.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index e2f29404c84e..367acb419a2b 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -148,6 +148,9 @@ #define QCOM_PCIE_CRC8_POLYNOMIAL (BIT(2) | BIT(1) | BIT(0)) +#define QCOM_PCIE_LINK_SPEED_TO_BW(speed) \ + Mbps_to_icc(PCIE_SPEED2MBS_ENC(pcie_link_speed[speed])) + #define QCOM_PCIE_1_0_0_MAX_CLOCKS 4 struct qcom_pcie_resources_1_0_0 { struct clk_bulk_data clks[QCOM_PCIE_1_0_0_MAX_CLOCKS]; @@ -1347,7 +1350,7 @@ static int qcom_pcie_icc_init(struct qcom_pcie *pcie) * Set an initial peak bandwidth corresponding to single-lane Gen 1 * for the pcie-mem path. */ - ret = icc_set_bw(pcie->icc_mem, 0, MBps_to_icc(250)); + ret = icc_set_bw(pcie->icc_mem, 0, QCOM_PCIE_LINK_SPEED_TO_BW(1)); if (ret) { dev_err(pci->dev, "failed to set interconnect bandwidth: %d\n", ret); @@ -1360,7 +1363,7 @@ static int qcom_pcie_icc_init(struct qcom_pcie *pcie) static void qcom_pcie_icc_update(struct qcom_pcie *pcie) { struct dw_pcie *pci = pcie->pci; - u32 offset, status, bw; + u32 offset, status; int speed, width; int ret; @@ -1377,22 +1380,7 @@ static void qcom_pcie_icc_update(struct qcom_pcie *pcie) speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, status); width = FIELD_GET(PCI_EXP_LNKSTA_NLW, status); - switch (speed) { - case 1: - bw = MBps_to_icc(250); - break; - case 2: - bw = MBps_to_icc(500); - break; - default: - WARN_ON_ONCE(1); - fallthrough; - case 3: - bw = MBps_to_icc(985); - break; - } - - ret = icc_set_bw(pcie->icc_mem, 0, width * bw); + ret = icc_set_bw(pcie->icc_mem, 0, width * QCOM_PCIE_LINK_SPEED_TO_BW(speed)); if (ret) { dev_err(pci->dev, "failed to set interconnect bandwidth: %d\n", ret); -- 2.25.1