From patchwork Sun Nov 7 16:29:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 12606843 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50E7EC433EF for ; Sun, 7 Nov 2021 16:29:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 31C2661359 for ; Sun, 7 Nov 2021 16:29:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235779AbhKGQcj (ORCPT ); Sun, 7 Nov 2021 11:32:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234861AbhKGQci (ORCPT ); Sun, 7 Nov 2021 11:32:38 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEBC3C061714; Sun, 7 Nov 2021 08:29:55 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id r12so52788189edt.6; Sun, 07 Nov 2021 08:29:55 -0800 (PST) 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=M/ckoETcz+yDddWrcBDGrX7LHLDThJbVjbuAhn7hXgw=; b=lRBeGE/xg0a+xoaD5hh8v/nFUW1deAUpUGukxE2AVv8bQ7P2HCTuweeZlopfRUuT6m OlppMVp+40Fz3X68LLZvhEQJaxnqtK0mUbikvp/a8jHKCOZkDkFV91qiG0gKoCanraH/ WcshdJL0pmUyLOK+rQP6XLT1UejHswpAipYDpt0A52gltqXygrERO+AvijtnKqjKRlfg CmewquMkGF5oGTMK7wrLZyhoXUPO2OG0P8qzWBlaQoTvq0/4IT5N1DuPb5gnPEOtBr6C pIGrCf1J13Swkpeh4edwXiMdQyKrwbGR9bwcTy3kWxLc+lM+/eihVslPYsG5iv9kor3d rh8A== 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=M/ckoETcz+yDddWrcBDGrX7LHLDThJbVjbuAhn7hXgw=; b=kGheVYFDwU5FT26faaPiWG55MzOSRILctAi3ahQQnksNsj5S2jd1VaTvkB6Xe3Z91D pcu83apAh9d6LR0102G9vVDcuRE8KceXRngGHpc+/OrdOraKpKVvOWg+fk0zajboTb95 sV1Qcli4pQg1JFyGQ+ITwAGoKFpK6vZDvCe/zrVDYFLDYyMeJ2flFiTulK7vUgbiMqh+ U/L8Fo1g/ItgC1SQ6svMEsFa/av+30GAnS9Jui1WQI/gtAn9FauMpvqHREZXJvRjyzXi hLnv6AwV75oL5EznQddVHdJXAvYS2fPRMZ9jeRAWSSf7FfYIeX32rv8oee+B5cFn3GQx KsKg== X-Gm-Message-State: AOAM533dy9/L7pVBRCeJwLHZzgYTw0ifDnk/8t5WfkCJKWL9tsljWMG2 NHJq1qpQy2zqBHin7BMfYYOxb5A53kg= X-Google-Smtp-Source: ABdhPJx4PuvDotJ08CW+xFbSbngb6rx7IRub/ESTPR7bXTqFVALcrYeyiWAHmqOQZ+4MJJGb8nBs1g== X-Received: by 2002:a17:907:3f83:: with SMTP id hr3mr90720331ejc.555.1636302594559; Sun, 07 Nov 2021 08:29:54 -0800 (PST) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id hq37sm7195270ejc.116.2021.11.07.08.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 08:29:54 -0800 (PST) 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 v4 1/5] PCI: Handle NULL value inside pci_upstream_bridge() Date: Sun, 7 Nov 2021 17:29:37 +0100 Message-Id: <20211107162941.1196-2-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211107162941.1196-1-refactormyself@gmail.com> References: <20211107162941.1196-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Return NULL if a NULL pointer is passed into pci_upstream_bridge(). Signed-off-by: Saheed O. Bolarinwa --- include/linux/pci.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/pci.h b/include/linux/pci.h index cd8aa6fce204..b087e0b9814e 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -695,6 +695,9 @@ static inline bool pci_is_bridge(struct pci_dev *dev) static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev) { + if (!dev) + return NULL; + dev = pci_physfn(dev); if (pci_is_root_bus(dev->bus)) return NULL; From patchwork Sun Nov 7 16:29:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 12606845 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BA80C433F5 for ; Sun, 7 Nov 2021 16:30:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 643AF61359 for ; Sun, 7 Nov 2021 16:30:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235788AbhKGQcl (ORCPT ); Sun, 7 Nov 2021 11:32:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235784AbhKGQck (ORCPT ); Sun, 7 Nov 2021 11:32:40 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E408C061570; Sun, 7 Nov 2021 08:29:57 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id z21so7368153edb.5; Sun, 07 Nov 2021 08:29:57 -0800 (PST) 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=wTTKVOhs/I799H09rjmZEQmciYfZTgIQlicE2Jx3/dI=; b=OGrQJr9vPzS8s20yYhTQgkvBOGJ9+Qgal9QlQmZBKVnbi8gppt3Tv+q5zN4QteGLTV fDqFdWGBKvIx9ijqXUcv4xFF+/NB9eNZ5aHKFk2CYOckndRTRmf1rsJ25oUv6BFYqGOk s1ZbmMDn7sc1yhaYT0LXzBgvxMwycn/O+QXpMXdBCBaMxqV9zHEiJKuNqJ+JUD2THiiV lhdxYPAXMhnHdQSyvTU49SIVt5jsjC7uKbSU8AeKAXwX2vJHX1+RpovkYMbj0MRrH34L ls2Hj0R/88gzh95AEOAyRjV6AUo753puYXXcW6bnZ4ME80Iza+DKXfCObeJRZANPL9X6 1g/g== 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=wTTKVOhs/I799H09rjmZEQmciYfZTgIQlicE2Jx3/dI=; b=oMvZ8TGwhOrJ3MyS8R9cJNlV2yi6LK+ilaGW+zQ/wBat2ATJ8G4qiXzj+WvH32bhiU OWchs8Ma3RsK2I5pVksk5DqcaK/BtgYQyvL91h4lv3UHDah7DKkddqDmRb80tlIX1eWn vkXM5M2v4zKZrZAHD5ISXeirtlQQKtW1rMBXimyXnMg1NShZ9BqAOeMIbTteii1vV9sh NYP+AH85rvfbOEvbCcaXh+Ru+nO0PHrYIyu9fgTCLemEKYqN/mi1OmPuyKDqXxtc74If vlKmgZCBDFN8Dfbi2qSrTpAvzPrZHjvZE8wtEvfIEtb0NJVgCKdb2xhXJIefWTzYPwO6 mkYQ== X-Gm-Message-State: AOAM533rU1yPN3wZSIihaVr5HSeKS9XiQ2gNNCgRJ0PWTST71RQ5vFvt N8yWf63CVUMSCXoVSuhvfJU= X-Google-Smtp-Source: ABdhPJwvaqxkdw38G9cM22zthlgieTVet8j4doDWTL1ZAgDhWfCqdtX+ZKvHKVra0PGjSWNZpuqdow== X-Received: by 2002:a17:906:26da:: with SMTP id u26mr90755877ejc.315.1636302596147; Sun, 07 Nov 2021 08:29:56 -0800 (PST) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id hq37sm7195270ejc.116.2021.11.07.08.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 08:29:55 -0800 (PST) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Bolarinwa O. Saheed" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v4 2/5] PCI/ASPM: Remove struct pcie_link_state.parent Date: Sun, 7 Nov 2021 17:29:38 +0100 Message-Id: <20211107162941.1196-3-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211107162941.1196-1-refactormyself@gmail.com> References: <20211107162941.1196-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: "Bolarinwa O. Saheed" Information cached in struct pcie_link_state.parent is accessible via struct pci_dev. - remove *parent* from the struct pcie_link_state - creates pcie_upstream_link() to obtain this value directly - replaces references to pcie_link_state.parent with a call to pcie_upstream_link() - remove BUG_ON(root->parent), instead obtain the root of the device returned by pcie_upstream_link NOTE/CLARIFICATION: The logic of pcie_upstream_link() especially as expressed in its use within alloc_pcie_link_state() assumes that: pdev->bus->parent->self == pdev->bus->self->bus->self Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/pcie/aspm.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 013a47f587ce..75618302fb87 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -50,7 +50,6 @@ struct pcie_link_state { struct pci_dev *pdev; /* Upstream component of the Link */ struct pci_dev *downstream; /* Downstream component, function 0 */ struct pcie_link_state *root; /* pointer to the root port link */ - struct pcie_link_state *parent; /* pointer to the parent Link state */ struct list_head sibling; /* node in link_list */ /* ASPM state */ @@ -139,6 +138,18 @@ static int policy_to_clkpm_state(struct pcie_link_state *link) return 0; } +static struct pcie_link_state *pcie_upstream_link(struct pci_dev *dev) +{ + struct pci_dev *bridge; + + bridge = pci_upstream_bridge(dev); + if (!bridge) + return NULL; + + bridge = pci_upstream_bridge(bridge); + return bridge ? bridge->link_state : NULL; +} + static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable) { struct pci_dev *child; @@ -419,7 +430,7 @@ static void pcie_aspm_check_latency(struct pci_dev *endpoint) link->aspm_capable &= ~ASPM_STATE_L1; l1_switch_latency += 1000; - link = link->parent; + link = pcie_upstream_link(link->pdev); } } @@ -795,7 +806,7 @@ static void pcie_config_aspm_path(struct pcie_link_state *link) { while (link) { pcie_config_aspm_link(link, policy_to_aspm_state(link)); - link = link->parent; + link = pcie_upstream_link(link->pdev); } } @@ -864,16 +875,15 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev) !pdev->bus->parent->self) { link->root = link; } else { - struct pcie_link_state *parent; + struct pcie_link_state *uplink_bridge; - parent = pdev->bus->parent->self->link_state; - if (!parent) { + uplink_bridge = pcie_upstream_link(pdev); + if (!uplink_bridge) { kfree(link); return NULL; } - link->parent = parent; - link->root = link->parent->root; + link->root = ulink_bridge->root; } list_add(&link->sibling, &link_list); @@ -962,7 +972,10 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev) static void pcie_update_aspm_capable(struct pcie_link_state *root) { struct pcie_link_state *link; - BUG_ON(root->parent); + struct pcie_link_state *uplink = pcie_upstream_link(root->pdev); + + root = uplink ? uplink->root : root; + list_for_each_entry(link, &link_list, sibling) { if (link->root != root) continue; @@ -986,7 +999,7 @@ static void pcie_update_aspm_capable(struct pcie_link_state *root) void pcie_aspm_exit_link_state(struct pci_dev *pdev) { struct pci_dev *parent = pdev->bus->self; - struct pcie_link_state *link, *root, *parent_link; + struct pcie_link_state *link, *root, *uplink_bridge; if (!parent || !parent->link_state) return; @@ -1002,7 +1015,7 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev) link = parent->link_state; root = link->root; - parent_link = link->parent; + uplink_bridge = pcie_upstream_link(link->pdev); /* All functions are removed, so just disable ASPM for the link */ pcie_config_aspm_link(link, 0); @@ -1011,9 +1024,9 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev) free_link_state(link); /* Recheck latencies and configure upstream links */ - if (parent_link) { + if (uplink_bridge) { pcie_update_aspm_capable(root); - pcie_config_aspm_path(parent_link); + pcie_config_aspm_path(uplink_bridge); } out: mutex_unlock(&aspm_lock); From patchwork Sun Nov 7 16:29:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 12606847 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7634FC433EF for ; Sun, 7 Nov 2021 16:30:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5AC5D6008E for ; Sun, 7 Nov 2021 16:30:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235796AbhKGQcn (ORCPT ); Sun, 7 Nov 2021 11:32:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235787AbhKGQcl (ORCPT ); Sun, 7 Nov 2021 11:32:41 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89411C061714; Sun, 7 Nov 2021 08:29:58 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id v11so50205644edc.9; Sun, 07 Nov 2021 08:29:58 -0800 (PST) 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=mdiJ7lzX3Ms7UkaPuy+L6z/d3dXtyRjWewegyVGznlA=; b=I5rEqpyCm3FkQBtSl4whncXDqjF4h4SOtN8F7XPh51lTJOp+2uoMfXXZVNf67owu1i elg6SyGq9MySmTCnA0ndGZ3RCZecGuGTn3noBhDgPFVSgRvnU9rcT8SJQlQ8FIqOMncl btBgWxhI4DC9odwwgYacSVvQkpsusB1Vp6tpqJ9RCuzPytxpzFPzplCT/dZaSDs+hhuy 9RoXheSibld/cnPUC2yxvzu5jz1zOz/GraM0C9Y8IMY96wLYy8hxBcWy0H6KH4HynkKk sElH7JNAHI+sKkpLLEJuFnDnDWlW1xMlMFNbxAG/xsjEbdUxTRA5eVkwlvH+anRUzShV JccA== 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=mdiJ7lzX3Ms7UkaPuy+L6z/d3dXtyRjWewegyVGznlA=; b=7OOto1lgT+orzLTby5/8QEFXx/kLYqpDl8om/Lh0ZnJEclgze7RD7BPEr5wd/j0YkV T0YLGPByerOFNsdfgen6QOv4sTTqqruNmzWXlu5Xov1QqzY9gKEjIhPx6P2FOg5BCYNk BHXZKIu2ShXT+g3FVishnkQqpY60ivrL9Kz7tjAWYv9lYT4vcZJQIWnStyR0+cSQWeld QiJrqFvvG0FM6GvpcqWPDu3aFV54TfHjyGACFWWTC55XyRKa16jNbwAKqwulKlfVW9+Z B3QlI2JwbFYCaLAc3gFvtDEoialGDJXa9fU8/tIdD2DY6I7wPyv7gQsgh5wSIeTbl9KF 7FWg== X-Gm-Message-State: AOAM532pJYgnNs9Fusq4d3eYXGc19gm5mOdLe4Ti9UhQ3/XkcELQxTXU xaE3pv+Qt7Aoq5NSTGNW0WU= X-Google-Smtp-Source: ABdhPJysDRtCZ1K520GPRXrESIeAxSOLHWwDJPUV3YWakVOE36W4aCfuJC/XJhcbpco1Z0NwoR/Cnw== X-Received: by 2002:a17:907:168f:: with SMTP id hc15mr4100256ejc.115.1636302597058; Sun, 07 Nov 2021 08:29:57 -0800 (PST) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id hq37sm7195270ejc.116.2021.11.07.08.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 08:29:56 -0800 (PST) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Bolarinwa O. Saheed" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v4 3/5] PCI/ASPM: Remove struct pcie_link_state.root Date: Sun, 7 Nov 2021 17:29:39 +0100 Message-Id: <20211107162941.1196-4-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211107162941.1196-1-refactormyself@gmail.com> References: <20211107162941.1196-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: "Bolarinwa O. Saheed" Information on the root device is calculated within alloc_pcie_link_state() and stored in struct pcie_link_state.root. If this calculation is extracted out, it make it possible to avoid storing the value - extract the calculations of pcie_link_state->root into pcie_get_root(). - remove *root* from the struct pcie_link_state. - replace references to struct pcie_link_state.root with a call to pcie_get_root(). Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/pcie/aspm.c | 68 +++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 75618302fb87..90c7a0b379f4 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -49,7 +49,6 @@ struct aspm_latency { struct pcie_link_state { struct pci_dev *pdev; /* Upstream component of the Link */ struct pci_dev *downstream; /* Downstream component, function 0 */ - struct pcie_link_state *root; /* pointer to the root port link */ struct list_head sibling; /* node in link_list */ /* ASPM state */ @@ -851,6 +850,25 @@ static int pcie_aspm_sanity_check(struct pci_dev *pdev) return 0; } +/* + * Root Ports and PCI/PCI-X to PCIe Bridges are roots of PCIe + * hierarchies. Note that some PCIe host implementations omit + * the root ports entirely, in which case a downstream port on + * a switch may become the root of the link state chain for all + * its subordinate endpoints. + */ +static struct pci_dev *pcie_get_root(struct pci_dev *pdev) +{ + struct pcie_link_state *uplink_bridge = pcie_upstream_link(pdev); + + if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT || + pci_pcie_type(pdev) == PCI_EXP_TYPE_PCIE_BRIDGE || !uplink_bridge) { + return pdev; + } else { + return pcie_get_root(uplink_bridge->pdev); + } +} + static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev) { struct pcie_link_state *link; @@ -863,29 +881,6 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev) link->pdev = pdev; link->downstream = pci_function_0(pdev->subordinate); - /* - * Root Ports and PCI/PCI-X to PCIe Bridges are roots of PCIe - * hierarchies. Note that some PCIe host implementations omit - * the root ports entirely, in which case a downstream port on - * a switch may become the root of the link state chain for all - * its subordinate endpoints. - */ - if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT || - pci_pcie_type(pdev) == PCI_EXP_TYPE_PCIE_BRIDGE || - !pdev->bus->parent->self) { - link->root = link; - } else { - struct pcie_link_state *uplink_bridge; - - uplink_bridge = pcie_upstream_link(pdev); - if (!uplink_bridge) { - kfree(link); - return NULL; - } - - link->root = ulink_bridge->root; - } - list_add(&link->sibling, &link_list); pdev->link_state = link; return link; @@ -972,20 +967,26 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev) static void pcie_update_aspm_capable(struct pcie_link_state *root) { struct pcie_link_state *link; - struct pcie_link_state *uplink = pcie_upstream_link(root->pdev); + struct pci_dev *dev, *root_dev; - root = uplink ? uplink->root : root; + /* Ensure it is the root device */ + root_dev = pcie_get_root(root->pdev); + root = root_dev ? root_dev->link_state : root; list_for_each_entry(link, &link_list, sibling) { - if (link->root != root) + dev = pcie_get_root(link->pdev); + if (dev->link_state != root) continue; + link->aspm_capable = link->aspm_support; } list_for_each_entry(link, &link_list, sibling) { struct pci_dev *child; struct pci_bus *linkbus = link->pdev->subordinate; - if (link->root != root) + dev = pcie_get_root(link->pdev); + if (dev->link_state != root) continue; + list_for_each_entry(child, &linkbus->devices, bus_list) { if ((pci_pcie_type(child) != PCI_EXP_TYPE_ENDPOINT) && (pci_pcie_type(child) != PCI_EXP_TYPE_LEG_END)) @@ -998,8 +999,8 @@ static void pcie_update_aspm_capable(struct pcie_link_state *root) /* @pdev: the endpoint device */ void pcie_aspm_exit_link_state(struct pci_dev *pdev) { - struct pci_dev *parent = pdev->bus->self; - struct pcie_link_state *link, *root, *uplink_bridge; + struct pci_dev *root_dev, *parent = pdev->bus->self; + struct pcie_link_state *link, *uplink_bridge; if (!parent || !parent->link_state) return; @@ -1014,7 +1015,7 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev) goto out; link = parent->link_state; - root = link->root; + root_dev = pcie_get_root(link->pdev); uplink_bridge = pcie_upstream_link(link->pdev); /* All functions are removed, so just disable ASPM for the link */ @@ -1025,7 +1026,7 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev) /* Recheck latencies and configure upstream links */ if (uplink_bridge) { - pcie_update_aspm_capable(root); + pcie_update_aspm_capable(root_dev->link_state); pcie_config_aspm_path(uplink_bridge); } out: @@ -1037,6 +1038,7 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev) void pcie_aspm_pm_state_change(struct pci_dev *pdev) { struct pcie_link_state *link = pdev->link_state; + struct pci_dev *root = pcie_get_root(pdev); if (aspm_disabled || !link) return; @@ -1046,7 +1048,7 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev) */ down_read(&pci_bus_sem); mutex_lock(&aspm_lock); - pcie_update_aspm_capable(link->root); + pcie_update_aspm_capable(root->link_state); pcie_config_aspm_path(link); mutex_unlock(&aspm_lock); up_read(&pci_bus_sem); From patchwork Sun Nov 7 16:29:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 12606849 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C487C433F5 for ; Sun, 7 Nov 2021 16:30:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16C9661359 for ; Sun, 7 Nov 2021 16:30:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235799AbhKGQcn (ORCPT ); Sun, 7 Nov 2021 11:32:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235791AbhKGQcm (ORCPT ); Sun, 7 Nov 2021 11:32:42 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51D67C061570; Sun, 7 Nov 2021 08:29:59 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id m14so52081717edd.0; Sun, 07 Nov 2021 08:29:59 -0800 (PST) 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=poWzBna8Q7V3exJi/2cqueSy7kuer5ibESKko9F1UGU=; b=HOjupI9r75bO2EzvidRff/ggfTph1/BGa6gkGDgs1zef4PXXVYVXy2Hpl/MM40NLzW U6ZojXBWMYOVxUWOwmJfbzHuQvFcwS5KpL8/9bezOBXbSBIKirKGAcuGtQFDYhTNbHX/ is1MToBp5DOchkhzK+f7OurXlV9H9O61ilc4/tiHgOOKn2/tm0xGnf7+IbtNBZgCfePl bRri+qmJIqgQjGNWkXdx0DCwsW/uzT1WI9TRrfdrcFYD8wS/gsFvZ3JUoWRIl5YYOepS NsSVbLs4QHoqz/YtANR8+ynezt80AUDkDoUSFGQQ/eS+7T2kdkzPgLI8qEY9B1OypTba VkNQ== 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=poWzBna8Q7V3exJi/2cqueSy7kuer5ibESKko9F1UGU=; b=TYQ/itYWYCuA1OVIRnZIxwKTrbvtGDOcT/I1zqYIVefTNVS4IewXAO1naJ6s+Zilsd imwBqWf3FGxdR8EhDXDfKTblLn5YMyK+4TUOdMUuSDxzlqViCwPgB5RMg7AvUV/pI2pz QvaB1JelswbuFFr18IuEsB6npBgYBkDLAqs2fLWvq5ArkIlQta9wGbTE+VPUgc6TXjmJ 5kbei6RYSuei24QM8Q/hAr/p/02DIE6owSlNYsTvIE16LWkAcV7iK/iBPHJSMcluYBha KS63x1ojplmeGHhRCBLQl2InA4BBHmHflwPm+bmX6SxjWGFZNMgMtLfCDZ9traQ1B5S2 gtpA== X-Gm-Message-State: AOAM532azrk/Pe9QdZeuIT4K6xe66i1NdEFYRNjtvbiNIdhAGA8Qn1HU 01mAitlNvSoc/xy+i371FyL8TuXlLCs= X-Google-Smtp-Source: ABdhPJz1bAn9D1wowPdDJfPD4eySIm/xgTonrRdAdpzAsCqsKd5p8V6oW5SctHSsKIZVpHmYuZL5Fw== X-Received: by 2002:a17:907:3e0a:: with SMTP id hp10mr59581317ejc.318.1636302597962; Sun, 07 Nov 2021 08:29:57 -0800 (PST) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id hq37sm7195270ejc.116.2021.11.07.08.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 08:29:57 -0800 (PST) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Bolarinwa O. Saheed" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v4 4/5] PCI/ASPM: Remove struct pcie_link_state.downstream Date: Sun, 7 Nov 2021 17:29:40 +0100 Message-Id: <20211107162941.1196-5-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211107162941.1196-1-refactormyself@gmail.com> References: <20211107162941.1196-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: "Bolarinwa O. Saheed" Information on the downstream component is cached in struct pcie_link_state.downstream it obtained within alloc_pcie_link_state() by calling pci_function_0() - remove *downstream* from the struct pcie_link_state. - replaces references to pcie_link_state.downstream with a call to pci_function_0(pdev->subordinate). Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/pcie/aspm.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 90c7a0b379f4..12623556f750 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -48,7 +48,6 @@ struct aspm_latency { struct pcie_link_state { struct pci_dev *pdev; /* Upstream component of the Link */ - struct pci_dev *downstream; /* Downstream component, function 0 */ struct list_head sibling; /* node in link_list */ /* ASPM state */ @@ -462,7 +461,8 @@ static void pci_clear_and_set_dword(struct pci_dev *pdev, int pos, static void aspm_calc_l1ss_info(struct pcie_link_state *link, u32 parent_l1ss_cap, u32 child_l1ss_cap) { - struct pci_dev *child = link->downstream, *parent = link->pdev; + struct pci_dev *parent = link->pdev; + struct pci_dev *child = pci_function_0(link->pdev->subordinate); u32 val1, val2, scale1, scale2; u32 t_common_mode, t_power_on, l1_2_threshold, scale, value; u32 ctl1 = 0, ctl2 = 0; @@ -552,7 +552,8 @@ static void aspm_calc_l1ss_info(struct pcie_link_state *link, static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) { - struct pci_dev *child = link->downstream, *parent = link->pdev; + struct pci_dev *parent = link->pdev; + struct pci_dev *child = pci_function_0(link->pdev->subordinate); u32 parent_lnkcap, child_lnkcap; u16 parent_lnkctl, child_lnkctl; u32 parent_l1ss_cap, child_l1ss_cap; @@ -694,7 +695,8 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) static void pcie_config_aspm_l1ss(struct pcie_link_state *link, u32 state) { u32 val, enable_req; - struct pci_dev *child = link->downstream, *parent = link->pdev; + struct pci_dev *parent = link->pdev; + struct pci_dev *child = pci_function_0(link->pdev->subordinate); enable_req = (link->aspm_enabled ^ state) & state; @@ -753,7 +755,8 @@ static void pcie_config_aspm_dev(struct pci_dev *pdev, u32 val) static void pcie_config_aspm_link(struct pcie_link_state *link, u32 state) { u32 upstream = 0, dwstream = 0; - struct pci_dev *child = link->downstream, *parent = link->pdev; + struct pci_dev *parent = link->pdev; + struct pci_dev *child = pci_function_0(link->pdev->subordinate); struct pci_bus *linkbus = parent->subordinate; /* Enable only the states that were not explicitly disabled */ @@ -879,7 +882,6 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev) INIT_LIST_HEAD(&link->sibling); link->pdev = pdev; - link->downstream = pci_function_0(pdev->subordinate); list_add(&link->sibling, &link_list); pdev->link_state = link; From patchwork Sun Nov 7 16:29:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 12606851 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03C46C43217 for ; Sun, 7 Nov 2021 16:30:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA14261361 for ; Sun, 7 Nov 2021 16:30:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235804AbhKGQco (ORCPT ); Sun, 7 Nov 2021 11:32:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234861AbhKGQcn (ORCPT ); Sun, 7 Nov 2021 11:32:43 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73A74C061570; Sun, 7 Nov 2021 08:30:00 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id x15so21541747edv.1; Sun, 07 Nov 2021 08:30:00 -0800 (PST) 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=Mnh2Je31kXke/FQYVUvveakBauZ5U23X82U3Kp0Tx3M=; b=pPJ8t2F2hYPuA0XqqwyPMokwhNggc2Zh2Gh9kergnf6M0TqiTK/EgVJJAvY5j8Ug7b JXQgwKeJ8bBhZ7Ze+3q29Wz7J04pgoha83RG6IrxXA03UaP0lxA0jT71Cw9gJVwKCh7B 58b/vXkqK+E5iowZQYlPfJKgPq1Uec0MMXcj62XdXBLOX35CrjE1DJJCCRo15WgrsvC4 1g0UUmglXhmEyUlYk+5FmroOl+kbYXf4MFVQTg2cB0uHnEdtMDiAFXT1lC71MAYV66Hn P4MbJObTNFq8ukRYIpPJfVhh9XKdR5WQh/ke6vN5an6VfD8juG7NhZMiQZOLQTh1H9sb 83FA== 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=Mnh2Je31kXke/FQYVUvveakBauZ5U23X82U3Kp0Tx3M=; b=3f1bYllywKB7vuaR49RHTynokz9QJ4Nh9UVSIbSTHCNSZop+u0vInTWui6MjEbsoJC wiY07aJXpZnWFO339Cnpb1iZGKOsVgZHBw5Cuq2cYEsHL0mZsQATxbSnlYzK/N10TpH2 5uuups3Dfu/Xgnwrec4+He9zLm3D8DPNqVkCpKXt03c64kKRkxNmMIm2Jn3VHGWOn0p+ wN2926Zi2QmIo8LJ7j36j6T3K0U+lJGpnMKoXBeBWrNME/p2lVkvvTxtG/sz4t0fZOtn zHEXNQoZWpwVBQIrxnQpjqBTxDbI5CJC02sXKVmvQDNDEC1agUtr41/rDh6Ewmk8eBFV Y/FQ== X-Gm-Message-State: AOAM532VC8hRGUkjCbsv+/bGod4edOT3aHxC/q5hEHYPXdNs9JNkapzg lEQ/SJG8Ou5UWc1/9Jl1gWIcL7MIuZs= X-Google-Smtp-Source: ABdhPJz9tHCyYeaQqHalsAEWI0OM70CjMfJ0PGSoZyL3d9SlVSykW4/2hTfsKlOzK9sHwKYhcZXwyA== X-Received: by 2002:a17:906:7951:: with SMTP id l17mr17698654ejo.284.1636302599087; Sun, 07 Nov 2021 08:29:59 -0800 (PST) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id hq37sm7195270ejc.116.2021.11.07.08.29.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 08:29:58 -0800 (PST) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Bolarinwa O. Saheed" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v4 5/5] PCI/ASPM: Remove unncessary linked list from aspm.c Date: Sun, 7 Nov 2021 17:29:41 +0100 Message-Id: <20211107162941.1196-6-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211107162941.1196-1-refactormyself@gmail.com> References: <20211107162941.1196-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: "Bolarinwa O. Saheed" aspm.c defines a linked list - `link_list` and stores each of its node in struct pcie_link_state.sibling. This linked list tracks devices for which the struct pcie_link_state object was successfully created. It is used to loop through the list for instance to set ASPM policy or update changes. However, it is possible to access these devices via existing lists defined inside pci.h - removes link_list and struct pcie_link_state.sibling - accesses child devices via struct pci_dev.bust_list - create pcie_config_bus_devices() which walk across the device heirarchies linked to the bus - accesses all PCI buses via pci_root_buses on struct pci_bus.node Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/pcie/aspm.c | 54 ++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 12623556f750..f9e52c785f91 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -48,7 +48,6 @@ struct aspm_latency { struct pcie_link_state { struct pci_dev *pdev; /* Upstream component of the Link */ - struct list_head sibling; /* node in link_list */ /* ASPM state */ u32 aspm_support:7; /* Supported ASPM state */ @@ -76,7 +75,6 @@ struct pcie_link_state { static int aspm_disabled, aspm_force; static bool aspm_support_enabled = true; static DEFINE_MUTEX(aspm_lock); -static LIST_HEAD(link_list); #define POLICY_DEFAULT 0 /* BIOS default setting */ #define POLICY_PERFORMANCE 1 /* high performance */ @@ -880,10 +878,7 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev) if (!link) return NULL; - INIT_LIST_HEAD(&link->sibling); link->pdev = pdev; - - list_add(&link->sibling, &link_list); pdev->link_state = link; return link; } @@ -968,26 +963,25 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev) /* Recheck latencies and update aspm_capable for links under the root */ static void pcie_update_aspm_capable(struct pcie_link_state *root) { - struct pcie_link_state *link; struct pci_dev *dev, *root_dev; + struct pci_bus *rootbus = root->pdev->bus; /* Ensure it is the root device */ root_dev = pcie_get_root(root->pdev); root = root_dev ? root_dev->link_state : root; - list_for_each_entry(link, &link_list, sibling) { - dev = pcie_get_root(link->pdev); - if (dev->link_state != root) + list_for_each_entry(dev, &rootbus->devices, bus_list) { + struct pcie_link_state *link = dev->link_state; + + if (!link) continue; link->aspm_capable = link->aspm_support; } - list_for_each_entry(link, &link_list, sibling) { + + list_for_each_entry(dev, &rootbus->devices, bus_list) { struct pci_dev *child; - struct pci_bus *linkbus = link->pdev->subordinate; - dev = pcie_get_root(link->pdev); - if (dev->link_state != root) - continue; + struct pci_bus *linkbus = dev->subordinate; list_for_each_entry(child, &linkbus->devices, bus_list) { if ((pci_pcie_type(child) != PCI_EXP_TYPE_ENDPOINT) && @@ -1022,7 +1016,6 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev) /* All functions are removed, so just disable ASPM for the link */ pcie_config_aspm_link(link, 0); - list_del(&link->sibling); /* Clock PM is for endpoint device */ free_link_state(link); @@ -1157,11 +1150,33 @@ int pci_disable_link_state(struct pci_dev *pdev, int state) } EXPORT_SYMBOL(pci_disable_link_state); +static void pcie_config_bus_devices(struct pci_bus *bus) +{ + struct pci_dev *pdev; + struct pcie_link_state *link; + + list_for_each_entry(pdev, &bus->devices, bus_list) { + if (!pci_is_pcie(pdev)) + break; + + link = pdev->link_state; + if (!link) + continue; + + pcie_config_aspm_link(link, policy_to_aspm_state(link)); + pcie_set_clkpm(link, policy_to_clkpm_state(link)); + + /* if this is a bridge, cross it */ + if (pdev->subordinate && pdev->subordinate != bus) + pcie_config_bus_devices(pdev->subordinate); + } +} + static int pcie_aspm_set_policy(const char *val, const struct kernel_param *kp) { int i; - struct pcie_link_state *link; + struct pci_bus *bus; if (aspm_disabled) return -EPERM; @@ -1174,10 +1189,9 @@ static int pcie_aspm_set_policy(const char *val, down_read(&pci_bus_sem); mutex_lock(&aspm_lock); aspm_policy = i; - list_for_each_entry(link, &link_list, sibling) { - pcie_config_aspm_link(link, policy_to_aspm_state(link)); - pcie_set_clkpm(link, policy_to_clkpm_state(link)); - } + list_for_each_entry(bus, &pci_root_buses, node) + pcie_config_bus_devices(bus); + mutex_unlock(&aspm_lock); up_read(&pci_bus_sem); return 0;