From patchwork Sat Nov 6 17:54:59 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: 12606423 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 2A7F0C433F5 for ; Sat, 6 Nov 2021 17:55:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 104106023D for ; Sat, 6 Nov 2021 17:55:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233578AbhKFR5v (ORCPT ); Sat, 6 Nov 2021 13:57:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232950AbhKFR5u (ORCPT ); Sat, 6 Nov 2021 13:57:50 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE5F5C061570; Sat, 6 Nov 2021 10:55:08 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id o8so44667318edc.3; Sat, 06 Nov 2021 10:55:08 -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=M/ckoETcz+yDddWrcBDGrX7LHLDThJbVjbuAhn7hXgw=; b=SFtPHmKQmzg2xNySjUeW7uj9FY8djQRU2IHJpRV7StO1e9KqYwy82fMh0vANf8XyHC Smply+kcEW/e8/5pUKaXdPJ1C1E6iEsaPNN2K6MIrC06zZVSJ1DMj/ZumieiyAeiOZ8G dDQP/Pif9btC8RxWLFFe6JMdx/JgrJTPe83BBoq5FrC9w0Z2xe63FN/ZeeA8pO2VKTVY PEebt7T0WoWUKQuiOdZbAuGsBviXkBFrkRLxiNa7xdqsxnAYezadpohEL9hmRUs16Zkk AyhanJ41xMEr1y3c0CexvuKpvKnetnp+GJnOupIoDtNTa42Vb/Na5e89POfM0GD+8gaG +dNQ== 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=f2+ftb6KeK2t3wgEhd6L+foFZXGTdLf+V501GhkeXB2q78hcUIyYV1u04DCbqb5nT6 XhtoyVqfhNLdMVB2YGaQiPhY52Gzgci0qxJtKxXc3W5+Dnda7dQ2n9ATljNaNUdB1+gJ rCXx3orsneCLxN14jwDtegWRVyVVDLfRG8p5kYmIeDceijzFm9yM6ZtuvF6rgBLYymHr ev6ZSOnPtsd6tKekyuAVO53DX1q4pbJKALrpETs6uXeGIgxFWn16zU4OI2I4COFKtgsc 95yhahR5wCDZIjhm42V3Amfy69Anojr2c5SpghpJM1d6tRMYPGpoPIfVivXB3kvOuj0n dxvg== X-Gm-Message-State: AOAM532M8Ixc+wxqVsxwgTL7qokicOPNYCld/aFqkufa707pGjmL88F6 WHVN+IVr1VFodJ+VCHnW06M= X-Google-Smtp-Source: ABdhPJy64kPU3OqrrSSQGHxhbjsgy2XMgPPRzMctH5uVasLD2sxUJIHcPnbnq+KRzoYE9o48nf3vTA== X-Received: by 2002:a05:6402:3488:: with SMTP id v8mr63961116edc.170.1636221307512; Sat, 06 Nov 2021 10:55:07 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id 25sm6542848edw.19.2021.11.06.10.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:55:07 -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 v3 1/5] PCI: Handle NULL value inside pci_upstream_bridge() Date: Sat, 6 Nov 2021 18:54:59 +0100 Message-Id: <20211106175503.27178-2-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175503.27178-1-refactormyself@gmail.com> References: <20211106175503.27178-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 Sat Nov 6 17:55:00 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: 12606425 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 34551C433EF for ; Sat, 6 Nov 2021 17:55:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 171A1610E9 for ; Sat, 6 Nov 2021 17:55:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234117AbhKFR5w (ORCPT ); Sat, 6 Nov 2021 13:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230007AbhKFR5v (ORCPT ); Sat, 6 Nov 2021 13:57:51 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD4ADC061570; Sat, 6 Nov 2021 10:55:09 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id c8so28018867ede.13; Sat, 06 Nov 2021 10:55:09 -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=wTTKVOhs/I799H09rjmZEQmciYfZTgIQlicE2Jx3/dI=; b=fP6LQ6dAJc52TmEgncKsSnHKMLSZeF1qai0kdTkhDU4JCSaaHc7FK1kZiKPlRM2Zcu jW0pL+DthYMtxKvHvfZ3evYvEKo8MGqoRCzFTXaAIrKBTDHwaWKu8BUXrNCdOQX1KI6N eZNUA23cmxWYMDU+U80DgU6PVuBpXJMOq4CnnQj9Uynhs12uSesrwQmmfswEay0N979l sieRwU+LNsm7x3xit6LNhyALz46A1aNsywLhB+M5nQPRTcXd66AgQtvw39zFZ/kbyCbe 2t+6bA47XFjNT//NKw6Vm5WA23NgiiRxQKUNY5ccAnX5LfgNm/0p/zgoJKp5kbmWbtkE 4qHQ== 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=itdR+O9jgnpClgP0rwJo+GR963y+8jxA/PBnMWiUT8OxcbcPD1qLlSnaTzEZBBAsn2 u0qf2lyJwun602xtc7BCpYQch+If+MAOLS/7HU1aDViewZGInFWIYIxhmXgx3wH5WtK9 0y7eDbCNKEiL6zTrXFsHD2R7ptrXW989gM55Rq1B2oAlB1kUtdG5EIr/39P7YDymZHRj VRBf3yUVUAFarVeg/e3biYLZF4tRCk4sFVrNPxStqvhgf1WnGBHkbVm7MWlTWM5uUH14 hMtZKXk+s8uSKFA9FxjM1b0i80DkrcPYVwyxYFE1ooJ1x4CtTPbSVxpsLA1iZn6YX5ZK k+lQ== X-Gm-Message-State: AOAM533p1oZv1KAFHdv02DB3Yo08DoAe/JfY7S4dmgsNZVmcXpl04HTU JHMg+r/IsVkfZN8mlLwkGU1RuM3eKlQ= X-Google-Smtp-Source: ABdhPJxNbluPO1DgW4gCj+wmoSdDbQB5Svm1eVcQdx0xbuUyd++cwBGIpBdC9ZLoLENRkzmIkivuaA== X-Received: by 2002:a17:906:a057:: with SMTP id bg23mr22245742ejb.375.1636221308452; Sat, 06 Nov 2021 10:55:08 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id 25sm6542848edw.19.2021.11.06.10.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:55:08 -0700 (PDT) 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 v3 2/5] PCI/ASPM: Remove struct pcie_link_state.parent Date: Sat, 6 Nov 2021 18:55:00 +0100 Message-Id: <20211106175503.27178-3-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175503.27178-1-refactormyself@gmail.com> References: <20211106175503.27178-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 Sat Nov 6 17:55:01 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: 12606427 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 5A13DC433F5 for ; Sat, 6 Nov 2021 17:55:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46B3E6109F for ; Sat, 6 Nov 2021 17:55:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234057AbhKFR5x (ORCPT ); Sat, 6 Nov 2021 13:57:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234077AbhKFR5w (ORCPT ); Sat, 6 Nov 2021 13:57:52 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD914C061714; Sat, 6 Nov 2021 10:55:10 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id j21so44590923edt.11; Sat, 06 Nov 2021 10:55:10 -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=mdiJ7lzX3Ms7UkaPuy+L6z/d3dXtyRjWewegyVGznlA=; b=U5brS4q+ZV/VyyfCbC/Jj+7up3l0DMIB5wUkEXlLpdcDXuS1zkYTVfj7Es3cblrwfR nU3lGcf6o6eVU2ZxksREOegaCfmMRPlV+H/wsqot3hYPUe3TinQnNGnRtfTHXhhmc2o5 S2wfOZyHhiLpO5rY0Vq7IgfWqk+q6Mv9qgoBRxLDL5FG0UKarvYVYECAOalAldp0a8tX hXxNTo7SQFver3iOqmcSq1lqIK2zx0omDf1f94/LiJv6RVEL79VcE1S4a+oSaGxYe7d+ OKItILjmkDoreJsEYhX1vwPetJSNdb2CzDdIMvtuM80WBUnFYwDpWlfKgVG/FhpvjP6H 777A== 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=PGllBAV+IdQsX+jrnIN3RMKn9ZnmuN//3XtA7gaSKoI3kaAUmYJ2zCa91enrhY43ef 4dzDr37npXsIgVZhZ/DljJoYoQhpPnGBJlt+5TwTzZygkzHbYXXhTwnMmEBEzvEGPWbw VmiMqCT/x0sKPVJXW5BdJkcZHMC6dtp4qWPDhe5v3MI1Oh0sHbP5s/78ofV4gnsCjKvz w2MI779vDeY313iL1jWpBG36+KJ/bGeEj+N6EKncYIFiYiY8JAYMAYt2US3i1yjYMTq0 aqQCdxH8Ypld4GO0P/agjmu57B5f0HmTPgkEWPjfVcFsSZhFbVt18JkhHoefI6cbxjFe 6YAg== X-Gm-Message-State: AOAM532/9hcn4X7HJfLeI/FUSHWInhxqRAAyDuqQ+ukLvq2d4k97Ggg9 tr/9B348K9LlwAN3nMz8EZ7WentrXNE= X-Google-Smtp-Source: ABdhPJzeAczhbQq1/KPY2amb0QUPRmTY6o8zUiacMimDcZHRGUOK8evCnV9roemFO5g5D+6+5eAgpw== X-Received: by 2002:a17:906:8a62:: with SMTP id hy2mr39004642ejc.347.1636221309296; Sat, 06 Nov 2021 10:55:09 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id 25sm6542848edw.19.2021.11.06.10.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:55:08 -0700 (PDT) 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 v3 3/5] PCI/ASPM: Remove struct pcie_link_state.root Date: Sat, 6 Nov 2021 18:55:01 +0100 Message-Id: <20211106175503.27178-4-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175503.27178-1-refactormyself@gmail.com> References: <20211106175503.27178-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 Sat Nov 6 17:55:02 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: 12606429 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 59DDBC433F5 for ; Sat, 6 Nov 2021 17:55:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A7056109F for ; Sat, 6 Nov 2021 17:55:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234738AbhKFR5y (ORCPT ); Sat, 6 Nov 2021 13:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234172AbhKFR5x (ORCPT ); Sat, 6 Nov 2021 13:57:53 -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 8F591C061746; Sat, 6 Nov 2021 10:55:11 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id m14so44030250edd.0; Sat, 06 Nov 2021 10:55:11 -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=poWzBna8Q7V3exJi/2cqueSy7kuer5ibESKko9F1UGU=; b=TxcsTb0hrfxRWgz1/VF8bnHUjl2ULNpjx13h9QUrjMXNn81LcG3YbiFX+TfneOSCOM oFCHAIlTV97d/R0dCwbvdO6kMJKXE64xfHI4b3Nq/2pHIFJovWyRYNSwOcrkymqXcGjm KcyE3t9VXSdINE+clSjyQFRsGmb/iUZWL+X/j+Ra+Bsu6eClfxRlhQKLfY+2l7mCFh5Y dBde0BTHCjUjy14AYBv1RajiRDzTN5oyJdf9feBNraFEdcVw7h9j4HeXuSdg2xhKOhtv BiHJdBmrVsFmYzKeadN5ZTfWVJtt9iuRpSyuBlEUrBmsq/K1vakKmX5s4XBBe4LtahZx EaUA== 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=Bo1+ublbofOG9lf4nSxSWBnGc6rIfrsPjs/hQNajVnOInNP38KzhPaQ5FXFdsTVoPm YteisiByRSQLPoSROhr7XzMIXX4FxSGsMvV5nON/Oa7vAwWpMYxRy57JPDFiXEUadk8T dbtbf3S/OTmatC89XVIQRrvsfCVDFakj3ooNSENHHNaU91px4iQklgN9pjSDxlW0E0gv JQH4FhL7FsxfbP/2h/kX8O70aOF0s7a4esTLNJm1OB1xwkHYbdJpx+nH/p7r6T7JWlRk 7aYL2vH1bTqT75CRPZr6p0+oZgE+JM+aNrVoM+CenYDAsylbN9onG66X/j1YWPjnfPl8 3vuA== X-Gm-Message-State: AOAM533WOnLnoF5Q2iytg+SNN0GOc/VuDYyP9iA8C3EnWMe2vJidubR1 vDIGBJbxsiRh28QIIYC7LQdb5gTpmA4= X-Google-Smtp-Source: ABdhPJxcmnz3lN4m3IBTPNedKEAsozptNqGCJkwjgKauE2s6D2VOeiGH8Jr5Jc3s3ZenL9NFxk0brg== X-Received: by 2002:a17:907:c1d:: with SMTP id ga29mr42619925ejc.180.1636221310148; Sat, 06 Nov 2021 10:55:10 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id 25sm6542848edw.19.2021.11.06.10.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:55:09 -0700 (PDT) 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 v3 4/5] PCI/ASPM: Remove struct pcie_link_state.downstream Date: Sat, 6 Nov 2021 18:55:02 +0100 Message-Id: <20211106175503.27178-5-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175503.27178-1-refactormyself@gmail.com> References: <20211106175503.27178-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 Sat Nov 6 17:55:03 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: 12606431 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 A110BC433FE for ; Sat, 6 Nov 2021 17:55:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A7906109F for ; Sat, 6 Nov 2021 17:55:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234773AbhKFR54 (ORCPT ); Sat, 6 Nov 2021 13:57:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234736AbhKFR5y (ORCPT ); Sat, 6 Nov 2021 13:57:54 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F811C061570; Sat, 6 Nov 2021 10:55:12 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id m14so44030357edd.0; Sat, 06 Nov 2021 10:55:12 -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=zNMcoDy+urPCjbL8WvhZ7GWXlrRboR3b2AarG7TVayM=; b=PDonr5eSpV0B1wWMCsPholmfVIfaH8T2XamfJx/zwpdV6Nl6rferfudFs/Adt/nZic lnJPdyZ0VML73yL1dYvOvH1bV5Lx1vZEZAcewsU/RSObmCLc59T9e65NTWqL09MebmnQ fkK8CdRql5lZoFZ6UWdX91Tz3NQKNRMjbQdPTjeyUC4yqtDmqt3u7Ns3byskgNqzLHqO pN8jogywzHh9O9ojuoWlpBnU/JGpCINf8lKXNzOql2pHC/pq55UbEuzjnZSwn6qBy0qd PqYgzljUrtVXD5g6KwLNtFAA902VFPO3jCPuhIYAuCpPKhZE3jH08XZbfdThSN1fqj/j XDtA== 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=zNMcoDy+urPCjbL8WvhZ7GWXlrRboR3b2AarG7TVayM=; b=pV5KGNZh3iuV4f9WPm2a6FUWon4aH6NbUZp+FuAcjpTldv5aELEjmUDC2XyYoGkFev nE5hzSChBK8A6EARTxKwI0eejchykNsYl+LMoGC3UfS7ktIc8bUMkrg6kobghYKjsKWS 9Oz8LHFpQaPlloF3IFuDGOo4cQR8iZdN45dEdEZR3NKJq3GstenSWrOsUNMKPMbHwO4W m3XX298mf9lKNlOSE6Cijk/3dE2K9TK8nCdoPClKn4MYLYz4EpA0e+DXGEGaGy9p1YfA NVwgsFqlUO5rayn3mQTiJpi8i1GSDrCBHIeYr8L6F5KxzfSnLzMnD83/Z1TeaNzVPkxU VVKQ== X-Gm-Message-State: AOAM530F9NL8axF2NNQdVIuCRXoZzeSsNPYXEIQIZwfcWc7Z4rlmwdHr qUj2ACRVd9c43Ig9frwCDNNohEhCpAI= X-Google-Smtp-Source: ABdhPJy+nNjrpZL5EWmz+2ExevSX0dZ2XgfhvixJqGi4/BbaMn1lgJnLhZX5uyRLXncZQcZ5ZWt/AQ== X-Received: by 2002:a17:906:6149:: with SMTP id p9mr79339640ejl.362.1636221311076; Sat, 06 Nov 2021 10:55:11 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id 25sm6542848edw.19.2021.11.06.10.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:55:10 -0700 (PDT) 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 v3 5/5] PCI/ASPM: Remove unncessary linked list from aspm.c Date: Sat, 6 Nov 2021 18:55:03 +0100 Message-Id: <20211106175503.27178-6-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175503.27178-1-refactormyself@gmail.com> References: <20211106175503.27178-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 | 53 +++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 12623556f750..65da034dc290 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; } @@ -970,24 +965,22 @@ 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) { + if (!dev->link_state) continue; - link->aspm_capable = link->aspm_support; + dev->link_state->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 +1015,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 +1149,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 +1188,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;