Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4464294pxb; Sat, 6 Nov 2021 14:36:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxl1Wr8R61kXY6EH2LODAvwlMD2S0Lxm1dTyI9hngnuMf1k42pbW2VTChze2cXYCAA0MzO1 X-Received: by 2002:a05:6402:1289:: with SMTP id w9mr87898855edv.268.1636234605742; Sat, 06 Nov 2021 14:36:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636234605; cv=none; d=google.com; s=arc-20160816; b=kuZNaYYSMeP8aSZL0bwFMMfTR4d8HbwgnTq52TlKWhr6RktjkT5Rd06fM8/fg0D/oc pwpfy7E+O7oyiSwFU/Sbt5cKoaeSZDoztfkxDuRDABnGXfzxwofkQTXCbpJ42lKViIkR JPqELU8xJ6tLpjkXXoVnK8t1BcpMDNnKNFKbYBehF9U04wD83tKafsGK8UeABjwUTYjS 0IVTPH1iJ5fsSFw/P6YfV4mP6AUVHHQzsoHZFFLsy7UExGQFeJk5rVf7JYR/aeYGeOqh 0755d6w0Gqu+cNcrfy26LShAe54ym6BDq6y7vJ80I8G0x1shlpRjHTc5EUh5Eb8gYFHA 6Gxg== 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=6D5HkkzZ/+jWBfSY9gLjOQ9sfmUeP65T8bu+SScNXxY=; b=x4FRf3bzevoY4J1hzosxzltuzatJQgV7NmGRogGINVgAfG/VcFfnY1t+p1nE5Mxv91 fqfCgciuIVcGlXwX+GAa+OB7PP0086P5GcWowx4rGFtbq1wVG59JS9oCEocOYm9oAKYM wJtvDVy2G5AlXG2v22bi77Ps29/bb1AxJdrzU+/grkxnrhLsdhZkIcSCXc474/AZOKK+ KnSThugV2YRwKEcgYmfeAAB/2p63C2XlHOTJWUK2yQL87UUkxdr4IFI+uidX5B5YqoTF IKzlfQ5k85vGNXeBWarOoIFuV5IciVvj5fH4i9LGET/0Yw3xPjkvieHP6EHcOYqYMiQD uqYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mqT8opC1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o7si27272365ejy.78.2021.11.06.14.36.22; Sat, 06 Nov 2021 14:36:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mqT8opC1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234745AbhKFR4m (ORCPT + 99 others); Sat, 6 Nov 2021 13:56:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233233AbhKFR4k (ORCPT ); Sat, 6 Nov 2021 13:56:40 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A307C061570; Sat, 6 Nov 2021 10:53:59 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id j21so44583739edt.11; Sat, 06 Nov 2021 10:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6D5HkkzZ/+jWBfSY9gLjOQ9sfmUeP65T8bu+SScNXxY=; b=mqT8opC1vtsJeLwFdLCmo9jx/z0UjbZ4IiGMX906qH/reDbnTKfShqHe9qwUnb1qJ9 rr8JaLowSYpJ94OAwZRgJ47gbTHlRw1oFB5h38s/7bYID61Oj/bya8WzlNcqi0VPDDeQ M+S3kQeZ+n1dXprEY0luKrX3Eu33pSiAx0VH0LAfxdUq1TnZ/5roBtzHnigP/0AqJt4T FzPnWIdPddx+Lm83s0vsOt0/AATsAe65w2cGMWSHyWWCFz9Pk+LpqxDVcJHfuy4aAAsJ t40S43yqP3L3gvaHkxhzuLsbLRL6FG3E+mpSMtFQAt1Aa/MM8A5nsSm4HplX6a8BlSKq 6K1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6D5HkkzZ/+jWBfSY9gLjOQ9sfmUeP65T8bu+SScNXxY=; b=cNJZDuMSn6VMEYvjqpizwpFO1LVNZWqAU80giO2yUKal2sUk6AX2SNOXyPyRyWDgFF UaNu96N27BfYnONHr36EFcJ/cWkFyfHLrixf8mTUkGZkQocPAXGMfF5ffbac0HdJFQcP AqixuvR/8Liltok8tjPyUXUy6ssWqe7wFd9JeK0XOHehNdgbBhus0rtj8Q0rWyrREFab DagCClbM9Id1S4KcHfX1wur6pL+eCpWNrI1oVzXJpCbXV8dZviGJV1Xc+ex2+Pwq9wBL Xo8oR2tXeDrZ9lgL6a+uK9cC2Mf7Fzo6cd+lB1oODgzHaBahLCov2/pxPWOv39bp2FKg NVLw== X-Gm-Message-State: AOAM5330xQ55Q3ZxU8aAqsRWbUDL9xjPN/li/R7CJPApGau2f6JZaV+M zfkyLcqsV+NlBFPhZUKcRwg+sRmDhCY= X-Received: by 2002:a17:906:309b:: with SMTP id 27mr18284487ejv.129.1636221237719; Sat, 06 Nov 2021 10:53:57 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id m12sm5753494ejj.63.2021.11.06.10.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:53:57 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Saheed O. Bolarinwa" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 1/6] PCI/ASPM: Extract out L1SS_CAP calculations Date: Sat, 6 Nov 2021 18:53:48 +0100 Message-Id: <20211106175353.26248-2-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175353.26248-1-refactormyself@gmail.com> References: <20211106175353.26248-1-refactormyself@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Inside pcie_aspm_cap_init() the L1SS_CAP of both ends of the link is calculated. The values are used to calculate link->aspm_support and link->aspm_enabled. Isolating this calcution with simplify pcie_aspm_cap_init(). Extract the calculations of L1SS_CAP on both ends into aspm_calc_both_l1ss_caps(). Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/pcie/aspm.c | 42 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 013a47f587ce..057c6768fb7b 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -540,6 +540,30 @@ static void aspm_calc_l1ss_info(struct pcie_link_state *link, } } +static void aspm_calc_both_l1ss_caps(struct pcie_link_state *link, + u32 *up_l1ss_cap, u32 *dwn_l1ss_cap) +{ + struct pci_dev *child = link->downstream, *parent = link->pdev; + + pci_read_config_dword(parent, parent->l1ss + PCI_L1SS_CAP, + up_l1ss_cap); + pci_read_config_dword(child, child->l1ss + PCI_L1SS_CAP, + dwn_l1ss_cap); + + if (!(*up_l1ss_cap & PCI_L1SS_CAP_L1_PM_SS)) + *up_l1ss_cap = 0; + if (!(*dwn_l1ss_cap & PCI_L1SS_CAP_L1_PM_SS)) + *dwn_l1ss_cap = 0; + + /* + * If we don't have LTR for the entire path from the Root Complex + * to this device, we can't use ASPM L1.2 because it relies on the + * LTR_L1.2_THRESHOLD. See PCIe r4.0, secs 5.5.4, 6.18. + */ + if (!child->ltr_path) + *dwn_l1ss_cap &= ~PCI_L1SS_CAP_ASPM_L1_2; +} + static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) { struct pci_dev *child = link->downstream, *parent = link->pdev; @@ -606,23 +630,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) link->latency_dw.l1 = calc_l1_latency(child_lnkcap); /* Setup L1 substate */ - pci_read_config_dword(parent, parent->l1ss + PCI_L1SS_CAP, - &parent_l1ss_cap); - pci_read_config_dword(child, child->l1ss + PCI_L1SS_CAP, - &child_l1ss_cap); - - if (!(parent_l1ss_cap & PCI_L1SS_CAP_L1_PM_SS)) - parent_l1ss_cap = 0; - if (!(child_l1ss_cap & PCI_L1SS_CAP_L1_PM_SS)) - child_l1ss_cap = 0; - - /* - * If we don't have LTR for the entire path from the Root Complex - * to this device, we can't use ASPM L1.2 because it relies on the - * LTR_L1.2_THRESHOLD. See PCIe r4.0, secs 5.5.4, 6.18. - */ - if (!child->ltr_path) - child_l1ss_cap &= ~PCI_L1SS_CAP_ASPM_L1_2; + aspm_calc_both_l1ss_caps(link, &parent_l1ss_cap, &child_l1ss_cap); if (parent_l1ss_cap & child_l1ss_cap & PCI_L1SS_CAP_ASPM_L1_1) link->aspm_support |= ASPM_STATE_L1_1; -- 2.20.1