Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2731996rdb; Wed, 4 Oct 2023 09:44:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbv3RM/5gC+AQYjksR0Wnn+BTsKnJrgl0GEvSldMmk1zEHsk2RuSPygH2pA2+EFXU3zoht X-Received: by 2002:a17:903:244f:b0:1c3:19d6:3559 with SMTP id l15-20020a170903244f00b001c319d63559mr251485pls.1.1696437888960; Wed, 04 Oct 2023 09:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696437888; cv=none; d=google.com; s=arc-20160816; b=hQ/esVSiDeu/MPqv1ellOfIhuXFuH7pdkHEH5lgrtBkcMe5ErK0sNJB2T776lAxcgD SLqb1oql8qdt3rPedhK8jlkW9S6rus1DjggivhiCl6BnHBxvrr7atEiuqOW7XyGUFnUF tBM3MeX5if/kL2jxiABFrbtJYyspSriOAbmx1PCL14JZtSWinmRPU3bo/5pX4AEIVdYL yIr2VJcltLcs3jYHx4y2luY8q0gbzs+p+dsUtC8EjUArDEbuPV1F1Ft+3GpmdgTARziQ 5B6T6f/SqOu5i3X3h4H0s21TuDF3B8OMPcMJNoH2fmnsekIfoByvjKXVn27ay9hMtMxA wWfQ== 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=P9XaYn4lnPCdZB+6xNgGrQfZXQTuNNsqAtwrHKyNOHg=; fh=AGN/tYtQjW7mdZ75nxqNDap8wtPE9BlC41CQHrUz6ag=; b=vIHZe43k1xYeq/WXHMCMgTGUa+MM5SUAI3OZE3N9p2EBgO0onQkCBQbsDUjcSGjua2 7tv+8OfprRZmTbVgHzXb1mny2T58E69x1YKoYp4blQJSXB631sk7dOffLdWX5YyjKgsO +4Zw5UcJsYvuB6nu0J+HwVyvUS8Lh1P7CxRVRYpXlppZDAZ9z6TP95A3t8Bchr9WzndD z+gx+6+Eh0Qto9XzRM6E2OpqWMSwk+pZrg5m2nfWQQlnthRwoOjoilbfC2+MtBEG7GBE nM2ihX8ueltvQZiI/4NNYpcsUlSF9kiTfZgoZ8AXyF5Hf9dg+GxXssJoWjcmmKozF/C0 mMWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rsDHKJcL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id q7-20020a170902a3c700b001c3976e22f5si3690628plb.515.2023.10.04.09.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 09:44:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rsDHKJcL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 009558373197; Wed, 4 Oct 2023 09:44:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243467AbjJDQop (ORCPT + 99 others); Wed, 4 Oct 2023 12:44:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243464AbjJDQoo (ORCPT ); Wed, 4 Oct 2023 12:44:44 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CB87D8 for ; Wed, 4 Oct 2023 09:44:40 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-692d2e8c003so909351b3a.1 for ; Wed, 04 Oct 2023 09:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696437880; x=1697042680; 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=P9XaYn4lnPCdZB+6xNgGrQfZXQTuNNsqAtwrHKyNOHg=; b=rsDHKJcLPFehRXqwzgavkAknaxznvjRbIBb8ILgDf4enuqORaEsKVJOJm+k2dIuwMD lYRruGDfBU8mY/UqFcqR3C7iULOS8oA5pG/mJ4LG+giZcNzvAAWIHhYuv+VsnN1+QstW 0SD/4dRGcbjC2Dm/P25pefUHaHdB/vdB2CHStSdKYABznNhLWgFhr2dTWizPZycajXDd 6CzYpeN5lPS41qkN98CQ4r2G7sNeE605/flTCgIKRKaD9mbvluN3BLVSniiwxsnhsFyE uQNgUyqM7ay01IpC07jc0kD5MoMqNiMxnRM5+cPROg2188qd6oFBILmIwX4AkzfdegeW X01g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696437880; x=1697042680; 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=P9XaYn4lnPCdZB+6xNgGrQfZXQTuNNsqAtwrHKyNOHg=; b=JvIkABLB0tyN4HqdTkNaFgOlBBrOOLhIpWU4Z9bOq1yd9J2vPFoZiOfYhSXu7Qxkn+ Q9xxhgdQ4WeygH5dpcGm0r0xGFU08mkLMat/04Odtjr49fV+18570cc7VG5Y8PEOqxOO WHrE+2/QvmpEswoDPmP6wtEJ6E4NFfuD4JEIU2NVUYaohfTDU8YAQydR86iptjXGUnNc KRSeWGt/Dv7jtGJzMt4RSPSs3MC05MoTTcjSHxq2fbS24PwWKbQoPxznrH4L8Zd4m3ZW CVWK6b4fM2SVQ1iF49rAM+Fi6YrzvCtzY43561q+cYVNR1OMsb+Ql8fwp2RzK9yK3x5u MBrA== X-Gm-Message-State: AOJu0Yx6j7g9ycdBbFBBVhrQ2x/ZNzPJSLdxg12SlmGNKqsn2DUsq8Rk BP+9t1qQDsM7L3N7OUG825dW X-Received: by 2002:a05:6a20:8f0b:b0:155:1710:664a with SMTP id b11-20020a056a208f0b00b001551710664amr274538pzk.18.1696437879936; Wed, 04 Oct 2023 09:44:39 -0700 (PDT) Received: from localhost.localdomain ([117.217.185.220]) by smtp.gmail.com with ESMTPSA id k14-20020aa792ce000000b0066a31111cc5sm3434628pfa.152.2023.10.04.09.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 09:44:39 -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 v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed Date: Wed, 4 Oct 2023 22:14:28 +0530 Message-Id: <20231004164430.39662-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Wed, 04 Oct 2023 09:44:48 -0700 (PDT) Instead of hardcoding the link speed in MBps, use 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 v4: * Modified the subject and commit message as per Bjorn's suggestion 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