Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3630372rdh; Thu, 28 Sep 2023 19:03:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4QhV3+DkZHGymO3iwy+x/mxznwVgdrZwMCLHytjd4Hwm4FLe7cF72GAjBp8XUVLqaRAqa X-Received: by 2002:a05:6a20:9798:b0:159:f71f:4083 with SMTP id hx24-20020a056a20979800b00159f71f4083mr2773418pzc.6.1695953011521; Thu, 28 Sep 2023 19:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695953011; cv=none; d=google.com; s=arc-20160816; b=l/4zqVSVEbleGCB1WBZXmDVmkFvILLv1UvOa5v0WrWJRa2ci+eC2PAfGMDIk2VwMU9 m3UsLvz/ZiZFn/JHH0EJNKi9EGfNo/J/kkH1yhdU2c8ChtxVTkkUjW1VrR+aqlHCJuHR CRwcgdikRJlD4BAII8v++F3iBwfgYXsqr59Rskq4aM8+w4kPwqWc/+wGiwnDXbzWN9WV H7JkOPM8uAVevfSWLylIZhpTvfsN4SwKIRZaWVeFYLb2R8MYXKJBt/P2JmAVf7IL7Gxl HMHbpuXVK94JMN33ESGsYRP5Ge/gnSxWw8dP50CSCLOCovfG7NbwmcEXq8ZvMnaB3bj5 whnw== 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=kF3xTzsn9HLZQj02Y4JAVq4+cnHK5cK7+MRBOAK1zto=; fh=AGN/tYtQjW7mdZ75nxqNDap8wtPE9BlC41CQHrUz6ag=; b=DIzokEQ4CuPAu08ak6f2n1vNvMLpfdRUd2HrSTR9nVwsHds1PILcZnbZRCQnaDIVMZ LpqeN/kYoBEp8inh5D6ePwTilgABMUy/zcvexMo7uQJq3FwHkIFKgBLap59KLftXKWMs yif+2hxIwxbuQ14g0WkUkXI6xtCFbY322URKd3KKcgbvHnJaySOjm8j6JOPOScX+Bh2f qdK/xRihANznS/f8rNIzguS12j4xxmZKckzDTVTHEj82HpAylAfKMkVH9b0JFyupC8cr p46fTDRTrXusBRj4cI70ildn6MGntC08dLJuH7YS0QFUPS/PAocshuEILr4GsnJZKOy/ RGJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zSHzsHoy; 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 j4-20020a170902da8400b001c5de4a5b4esi6659632plx.597.2023.09.28.19.03.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 19:03:31 -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=zSHzsHoy; 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 939478083A97; Wed, 27 Sep 2023 07:57: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 S232054AbjI0O5p (ORCPT + 99 others); Wed, 27 Sep 2023 10:57:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232067AbjI0O5o (ORCPT ); Wed, 27 Sep 2023 10:57:44 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4378FF5 for ; Wed, 27 Sep 2023 07:57:42 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b9338e4695so188585971fa.2 for ; Wed, 27 Sep 2023 07:57:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695826660; x=1696431460; 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=kF3xTzsn9HLZQj02Y4JAVq4+cnHK5cK7+MRBOAK1zto=; b=zSHzsHoystgSRI8WbSiGKcLfQskrpMxRxAB7ABn3riafYp8WN13+U4YT8L77Mw6W0f HlnWyaGbi6Sy2AFz0T6jr3/fu55o6cvQj3/AiSF56I2EYHpCa6Shb30U/6pYPW80mW1l qOemVXQDrwuXuXOme4SGTK+owFNnvrGjEOq0MPcU17uz01WoZmeKqcgBHdfAaeD8EYy9 jsBYUPRiE+YWntvqQt2BVNqephU2XWl4P5A4zn8g3Q1hwNduz3WgCK8RfvhEwR6WMm2X lyUauhquPV8zo7Np3nWwrw2cxyqRwuaqd9X5L7w5qTW2JbtWLdjKrO7MBtxREuuQZoBq Bf7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695826660; x=1696431460; 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=kF3xTzsn9HLZQj02Y4JAVq4+cnHK5cK7+MRBOAK1zto=; b=puU5UtPVjoXDfiM6aVLGqSwP5pSEZKCC+HBfBlLa5zMREOMZZCtjvbX5dee7G+0cSe qBmB+K/SUzLZ37kC0mopEfaM9xlXU3cYh6HPEfuki5HGVpxg9T5HBHrYoSLaV1dYM2QX Y4Xh8l9fygycjfU6ywB0o0c+1COWllCZyO26/d2zwg9JrgkPK6fy/N8hekGuaJev/SPl ql3hiHWV/s+J7xmBYirHY+o880CpotbMnODuGN5AluZKR6v5E954IqIBI2NdWpS6LUHI XWUxwtiWIPxRsaStAv1r1VhYP+kyiF7VNKeb70xRzwPWNxTdPevJJTMAEvFOQsTc/wT+ hiIA== X-Gm-Message-State: AOJu0YyWtA1D5FsM9hkcLdWL1SeU/1U6YwMxOru3v4XRlWVT4Cq/AdMH EzcEnpfecpOxV1p8O+wQTNkS X-Received: by 2002:a2e:9d55:0:b0:2c0:1cfd:8698 with SMTP id y21-20020a2e9d55000000b002c01cfd8698mr2040919ljj.36.1695826660497; Wed, 27 Sep 2023 07:57:40 -0700 (PDT) Received: from thinkpad.fritz.box ([2a02:2454:9d09:3f00:b024:394e:56d7:d8b4]) by smtp.gmail.com with ESMTPSA id j26-20020a170906831a00b0099bc8bd9066sm9405220ejx.150.2023.09.27.07.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:57: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 v2] PCI: qcom: Make use of QCOM_PCIE_LINK_SPEED_TO_BW() macro for encoding link speed Date: Wed, 27 Sep 2023 16:57:38 +0200 Message-Id: <20230927145738.115843-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 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, 27 Sep 2023 07:57:48 -0700 (PDT) Instead of hardcoding the link speed in MBps, let's make use of the existing QCOM_PCIE_LINK_SPEED_TO_BW() macro that does the encoding of the link speed for us. 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 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 297442c969b6..dce80d6dc88f 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]) / BITS_PER_BYTE) + #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