Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2732025rdb; Wed, 4 Oct 2023 09:44:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqZk6w8ZR7M9qd5LE9crw+whvXRY8ZlRh1pPfxM2n55Q3HObcxJToGuaHKPa9sjIowKHPl X-Received: by 2002:a17:90a:b00a:b0:268:3b8b:140d with SMTP id x10-20020a17090ab00a00b002683b8b140dmr2372275pjq.35.1696437892488; Wed, 04 Oct 2023 09:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696437892; cv=none; d=google.com; s=arc-20160816; b=TmnW4/ufFGeEbmMZKYXxxXxqDWOaAcMp03A5BJFZy6MwWYnAqXH2VUfW3lfkUcFlaL EexiWceULnr+KYIVqk+9EGXo7ZetQ08WrCleIJh4splQvWNVDJsazAcrGaPDFjMaQ34+ 8b0986Npbou4XD0pU2Qifdd++DnnpplYCgL2Lo/ewaEHakPGavAE5BRgPrs+nNx8EdRZ pFuBw7gI8zSJj7ZWDKAtgC9wc3D2QZVVfioHybTEDRbxCbXNuXJtFFu8EM12cr406qTM wZwcwIXFDpYfwbK/uyDUjQY+I8TsWasLRgME68TuNxSMG1l5CXU8fR5wB93vjuHgkTlK q5Bg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u4IEC6XCK24n1wITjZREwVBDCFLCyw9ygvF6/hCtGR0=; fh=AGN/tYtQjW7mdZ75nxqNDap8wtPE9BlC41CQHrUz6ag=; b=rJXes7DiUApBjZsUG+5qRz4mayHbaIu3vT4GE+UxYCWvZ9OlTeMkIN2t8rJn7I7QWV I+kUuN9XHZ3b3kKIS+gSv5Xr4TF/4ba1IwyFWBPSDYYSr/il+TiS8F6wUV0vmdJuGLnI Cqd9DvOasIdphVZ5IDZRDeyXkEiLoQyU/X9ZoofZDZlN+qTDoJ/RuVRmzRwpeHs9iehH gsnZynG4JHyBr3aFuA5c6dyz/qoXaN/99Ee1u8BeFyLdm/e+v4HVfjI9bVPxY84LGLy3 W1IJTFmYcx+9nVmWC+9kM5zk+0MR2IKeVyW2kJnonVr34/vkNe2i81uLJeJYvleXK6lF ISEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mu5T4V90; 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 s8-20020a17090aad8800b00277751629e4si1707456pjq.121.2023.10.04.09.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 09:44:52 -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=mu5T4V90; 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 20EF3837319D; Wed, 4 Oct 2023 09:44:51 -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 S243471AbjJDQot (ORCPT + 99 others); Wed, 4 Oct 2023 12:44:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243472AbjJDQor (ORCPT ); Wed, 4 Oct 2023 12:44:47 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5306C9 for ; Wed, 4 Oct 2023 09:44:43 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-690bccb0d8aso1860510b3a.0 for ; Wed, 04 Oct 2023 09:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696437883; x=1697042683; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u4IEC6XCK24n1wITjZREwVBDCFLCyw9ygvF6/hCtGR0=; b=mu5T4V90A9l/3nQeyFk/x/I8Fi9Yng739I3ldXZr6scKwLI1JGnpMeZxOQ8Kif+uA1 DgsHlQ8oUtzoSZ/nl33ZpEHbnPwyenrmvZQyvARj4aCf3B8C7ap6SP518JUfJ2MBUN5g us2zLf8tIMUuL5xP/TTwXwGK+zsjEMZzrmT19CZ3u6BbsAdfF02Zs4OuaFWxM1lJSJjs J8nzLerQhCNSIP9mGv65m+Bh1v6Vs4WP78rnHI1+DrmHRGe8YwT8aasd+7shqrriKboB 1l5aVycV4cxe6xRKO4/fTjk4lt7E1Pob83oc+2EuOf6/or8pJN0iky5i9FbLF2YTjQAI P/WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696437883; x=1697042683; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u4IEC6XCK24n1wITjZREwVBDCFLCyw9ygvF6/hCtGR0=; b=mvvbHwkjicQ8ylYHUuiDpGs98hIZ2k7Vri1VcPKCJJKvfhey8cJcXBInxcx+bz+qvN xRSU5rjbwnTYtpH+XYAHm0OESznWx718K8d1c5OcZFPOBFxVmiDak6VP7dhw0aFh89Rm JglRhKaijjNskZ+ZED2NR4EqS2lTcj3CTHbPfVdfNmp8IPbK3SSRQ18Fm7TzcBVF7e4N dlRZGqwudz6vrb6Lzkmb3bDwkgH4hnu1euw7yVkMJ04o14Z5Xz5UhyE2FVNg49zae4q1 cZy1wx+e8/QW/c4y4p1Prnfa7J7jNMoZEVRoDVpNsqFJN3ls3IG6Cf1YiAZXU6J7OSoG 4sfQ== X-Gm-Message-State: AOJu0YwLxkieKChvgnex5Hl/7VhL2pDvENGLuTe1oTbnq+FFLHOglQ3r c+HyPP5Yx7cKznP/KBIWAQKN X-Received: by 2002:a05:6a21:329c:b0:15c:b7b9:fc21 with SMTP id yt28-20020a056a21329c00b0015cb7b9fc21mr3263421pzb.14.1696437883311; Wed, 04 Oct 2023 09:44:43 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 09:44:43 -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 2/3] PCI: qcom-ep: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed Date: Wed, 4 Oct 2023 22:14:29 +0530 Message-Id: <20231004164430.39662-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231004164430.39662-1-manivannan.sadhasivam@linaro.org> References: <20231004164430.39662-1-manivannan.sadhasivam@linaro.org> 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:51 -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: - New patch drivers/pci/controller/dwc/pcie-qcom-ep.c | 31 +++++------------------ 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c index 8bd8107690a6..32c8d9e37876 100644 --- a/drivers/pci/controller/dwc/pcie-qcom-ep.c +++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c @@ -23,6 +23,7 @@ #include #include +#include "../../pci.h" #include "pcie-designware.h" /* PARF registers */ @@ -135,10 +136,8 @@ #define CORE_RESET_TIME_US_MAX 1005 #define WAKE_DELAY_US 2000 /* 2 ms */ -#define PCIE_GEN1_BW_MBPS 250 -#define PCIE_GEN2_BW_MBPS 500 -#define PCIE_GEN3_BW_MBPS 985 -#define PCIE_GEN4_BW_MBPS 1969 +#define QCOM_PCIE_LINK_SPEED_TO_BW(speed) \ + Mbps_to_icc(PCIE_SPEED2MBS_ENC(pcie_link_speed[speed])) #define to_pcie_ep(x) dev_get_drvdata((x)->dev) @@ -266,7 +265,7 @@ static void qcom_pcie_dw_stop_link(struct dw_pcie *pci) static void qcom_pcie_ep_icc_update(struct qcom_pcie_ep *pcie_ep) { struct dw_pcie *pci = &pcie_ep->pci; - u32 offset, status, bw; + u32 offset, status; int speed, width; int ret; @@ -279,25 +278,7 @@ static void qcom_pcie_ep_icc_update(struct qcom_pcie_ep *pcie_ep) speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, status); width = FIELD_GET(PCI_EXP_LNKSTA_NLW, status); - switch (speed) { - case 1: - bw = MBps_to_icc(PCIE_GEN1_BW_MBPS); - break; - case 2: - bw = MBps_to_icc(PCIE_GEN2_BW_MBPS); - break; - case 3: - bw = MBps_to_icc(PCIE_GEN3_BW_MBPS); - break; - default: - dev_warn(pci->dev, "using default GEN4 bandwidth\n"); - fallthrough; - case 4: - bw = MBps_to_icc(PCIE_GEN4_BW_MBPS); - break; - } - - ret = icc_set_bw(pcie_ep->icc_mem, 0, width * bw); + ret = icc_set_bw(pcie_ep->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); @@ -335,7 +316,7 @@ static int qcom_pcie_enable_resources(struct qcom_pcie_ep *pcie_ep) * Set an initial peak bandwidth corresponding to single-lane Gen 1 * for the pcie-mem path. */ - ret = icc_set_bw(pcie_ep->icc_mem, 0, MBps_to_icc(PCIE_GEN1_BW_MBPS)); + ret = icc_set_bw(pcie_ep->icc_mem, 0, QCOM_PCIE_LINK_SPEED_TO_BW(1)); if (ret) { dev_err(pci->dev, "failed to set interconnect bandwidth: %d\n", ret); -- 2.25.1