From patchwork Wed Sep 29 00:43:12 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: 1534167 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=JZIWoZPE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HJyKc0cQTz9svs for ; Wed, 29 Sep 2021 10:43:32 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243381AbhI2ApK (ORCPT ); Tue, 28 Sep 2021 20:45:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243429AbhI2ApJ (ORCPT ); Tue, 28 Sep 2021 20:45:09 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B210C06161C; Tue, 28 Sep 2021 17:43:29 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id b26so2134266edt.0; Tue, 28 Sep 2021 17:43:29 -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=L+uzfIlDc0/BI6+RnBLdVYHOCavYJo90T/u3FgP+yR4=; b=JZIWoZPEH/vCzQi1YHcVWh9bW1DLT9s0gtt6auVL4c/AXCjmag22i1FBcbxGOZ3Xyd WH3NQVj5c/e4Vg6PibJPhzMG25yhwzgZaRLqkLM6ZiHgNGDxfLFIanlHYC+lPizpLZXr ItRuP3PA4yvrmi8nly2NEw5jBs5EVxDrOTdmfXcv2xRWsgHjJG8Yqd6p3lVgSyOjY2s3 oXjQi2m+hgu5NfjDYmNww55a9YgoXhH8bJCRLgx0SJI/f94e+zLWQwwm35j3P2SI9SDL r4Oq7HdoWoFJrVX3+ny2ynSkl5LyO+py4gdbjj4tin4AqdTF1/T2Lvl4QW+YwsdHEkkL S82A== 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=L+uzfIlDc0/BI6+RnBLdVYHOCavYJo90T/u3FgP+yR4=; b=e9lJOygqRC85OyVGoGOVQ/6KIhCTMnovgJNwZJmH/acbD4Hz7akjJhF/dRuW0THJAZ sG4z4s94DqbRd1ema0cA08pvdmq448AXokF82nTtUxU9IdARvdp9sykSo1oYvo3CkleF xj3/w+wRfTRhhhyV0h3IiRT+f6ioUqESO8RmWxIsDl4UqiMYrLxh1JE4xq8CmRiw5ZPD pqUjnkruBWpNSwTfsDRUJ5LvPkzZ+RaeM0M+0qY306n84iMqZ+QmaJkqXOHcmgNOnrMQ Y8iDz5Aj7U7sz9/fLCADzo3gbaJ4B3EiVALpH5kKDKxDXiEekAMlMv4T5MyQghhr/dqH HwKQ== X-Gm-Message-State: AOAM53385ezOZHbZx2j+EUzJV1Gn8QOKW8oSm+Vk5DTbVOxOpdMkx/qi q3cs6SG3AjVCQPxlQMxBZXk= X-Google-Smtp-Source: ABdhPJwFD6mqM5OMmarBKhSmWpJiFrxP/O2BzFQ5JFC6vtaGrLPHU7T9NQM12l4XtYoV0kDlBXD6lA== X-Received: by 2002:a17:906:b052:: with SMTP id bj18mr10308003ejb.55.1632876207844; Tue, 28 Sep 2021 17:43:27 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:10f:c9f0:35c7:3af0:a197:61d0]) by smtp.googlemail.com with ESMTPSA id u16sm358489ejy.14.2021.09.28.17.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 17:43:27 -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 v2 1/4] PCI/ASPM: Remove struct pcie_link_state.parent Date: Wed, 29 Sep 2021 02:43:12 +0200 Message-Id: <20210929004315.22558-2-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210929004315.22558-1-refactormyself@gmail.com> References: <20210929004315.22558-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. This patch: - removes *parent* from the *struct pcie_link_state* - creates pci_get_parent() which returns the parent of a pci_dev - replaces references to pcie_link_state.parent with a call to pci_get_parent() - removes BUG_ON(root->parent), instead uses the parent's root Signed-off-by: Bolarinwa O. Saheed --- drivers/pci/pcie/aspm.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 013a47f587ce..414c04ffe962 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,14 @@ static int policy_to_clkpm_state(struct pcie_link_state *link) return 0; } +static struct pci_dev *pci_get_parent(struct pci_dev *pdev) +{ + if (!pdev || !pdev->bus->parent || !pdev->bus->parent->self) + return NULL; + + return pdev->bus->parent->self; +} + static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable) { struct pci_dev *child; @@ -379,6 +386,7 @@ static void encode_l12_threshold(u32 threshold_us, u32 *scale, u32 *value) static void pcie_aspm_check_latency(struct pci_dev *endpoint) { u32 latency, l1_switch_latency = 0; + struct pci_dev *parent; struct aspm_latency *acceptable; struct pcie_link_state *link; @@ -419,7 +427,8 @@ static void pcie_aspm_check_latency(struct pci_dev *endpoint) link->aspm_capable &= ~ASPM_STATE_L1; l1_switch_latency += 1000; - link = link->parent; + parent = pci_get_parent(link->pdev); + link = parent ? parent->link_state : NULL; } } @@ -793,9 +802,11 @@ static void pcie_config_aspm_link(struct pcie_link_state *link, u32 state) static void pcie_config_aspm_path(struct pcie_link_state *link) { + struct pci_dev *parent; while (link) { pcie_config_aspm_link(link, policy_to_aspm_state(link)); - link = link->parent; + parent = pci_get_parent(link->pdev); + link = parent ? parent->link_state : NULL; } } @@ -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 pci_dev *parent; - parent = pdev->bus->parent->self->link_state; - if (!parent) { + parent = pci_get_parent(pdev); + if (!parent->link_state) { kfree(link); return NULL; } - link->parent = parent; - link->root = link->parent->root; + link->root = parent->link_state->root; } list_add(&link->sibling, &link_list); @@ -962,7 +972,11 @@ 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 pci_dev *parent = pci_get_parent(root->pdev); + + if (parent && parent->link_state) + root = parent->link_state->root; + list_for_each_entry(link, &link_list, sibling) { if (link->root != root) continue; @@ -985,6 +999,7 @@ 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_dev; struct pci_dev *parent = pdev->bus->self; struct pcie_link_state *link, *root, *parent_link; @@ -1002,7 +1017,8 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev) link = parent->link_state; root = link->root; - parent_link = link->parent; + parent_dev = pci_get_parent(link->pdev); + parent_link = parent_dev ? parent_dev->link_state : NULL; /* All functions are removed, so just disable ASPM for the link */ pcie_config_aspm_link(link, 0); From patchwork Wed Sep 29 00:43:13 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: 1534168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=MfgLaif9; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HJyKd71z4z9sR4 for ; Wed, 29 Sep 2021 10:43:33 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243429AbhI2ApL (ORCPT ); Tue, 28 Sep 2021 20:45:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243445AbhI2ApK (ORCPT ); Tue, 28 Sep 2021 20:45:10 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E650C06161C; Tue, 28 Sep 2021 17:43:30 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id b26so2134354edt.0; Tue, 28 Sep 2021 17:43:30 -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=DSFOLGj+ldMLpWwvrw+YF05JUnP09SptyU46Tu5pKP8=; b=MfgLaif9MxDFglnFowBdbImagCB3aKbME40C2VMsZFfRaqtkg8zx2a3ZGNP226ftdB NG5O94glOA6iIkWd8srW3nuwD7q4Q12VRASf94jT9kfjtmcW0APWrGgrKiUwcubnYgRz TgOi+6w45j2yx53yqWXNwAOXoistDSjfVD8uQsW0FhBBEp52zfEM/y/kkZFQ4VrvJSDN zqaGvA9LQfu1KcDatEqBQMa1kxMWWy/CJ79BqOcyWXwPnUmYR9lWeTM/NEOMDjuf4r1p 3DrGPPdyFzUi+yccCAghI5BnR/0PeqO17RnrjFXXJFIjvW1cM3MQhIUad3yBijStIExX tXgA== 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=DSFOLGj+ldMLpWwvrw+YF05JUnP09SptyU46Tu5pKP8=; b=rHTZvLdwCmkcpB9209DV3qaxxDkSkIMU30YsjOPdGDSzwuOSQw8xLnsNDPTekHiwL0 cmExVfs+wVn75GFgyyyInY5mrXFtuI0gbJBLFp52q2kB42nQTd45pQE8kHXIz1xL63gq IojhtVeKyUuHc+beaWKr1mL7vlV1+L0S1Q0SurFUcKVvq4H6g0adfwxEPin0v93cflq6 icEI2I22D/Q6JJ7BEBFjfMWEDB9QJR5aj4dbar3Db8iJ0Y8nF6RmAQjnNzLTnTsXnqbt eacNOI33Bm9a/1BLW9+OLiIV6dvKzcjKLuhohJAJuUSW9+GYrMsCd+AXgXXT/tJaIRf9 6TsQ== X-Gm-Message-State: AOAM5308nQ/2R0L8DfKpEU+drHNrjqWia36fBDSm+dB+3Hy/PCKC0p+/ 7TTq6tiOs+QAk5XQADbp+WUpt+ef6rs= X-Google-Smtp-Source: ABdhPJxorhRNcrxYpwWl+HWgSIvah92yltiH8ybFhvmNOkaRT0MzFhc05p8M/dDnwnjVbfnUvOb+MQ== X-Received: by 2002:a05:6402:1b8d:: with SMTP id cc13mr11359421edb.235.1632876208678; Tue, 28 Sep 2021 17:43:28 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:10f:c9f0:35c7:3af0:a197:61d0]) by smtp.googlemail.com with ESMTPSA id u16sm358489ejy.14.2021.09.28.17.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 17:43:28 -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 v2 2/4] PCI/ASPM: Remove struct pcie_link_state.root Date: Wed, 29 Sep 2021 02:43:13 +0200 Message-Id: <20210929004315.22558-3-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210929004315.22558-1-refactormyself@gmail.com> References: <20210929004315.22558-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 cached in struct pcie_link_state.root it obtained within alloc_pcie_link_state(). This patch: - creates *pcie_get_root()* which return the root pci_dev of a pci_dev. - removes *root* from the *struct pcie_link_state*. - replaces references to struct pcie_link_state.root with a call to pcie_get_root(). Signed-off-by: Bolarinwa O. Saheed --- drivers/pci/pcie/aspm.c | 69 +++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 414c04ffe962..ad78aaeea444 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 pci_dev *parent = pci_get_parent(pdev); + + if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT || + pci_pcie_type(pdev) == PCI_EXP_TYPE_PCIE_BRIDGE || !parent) { + return pdev; + } else { + return pcie_get_root(parent); + } +} + 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 pci_dev *parent; - - parent = pci_get_parent(pdev); - if (!parent->link_state) { - kfree(link); - return NULL; - } - - link->root = parent->link_state->root; - } - list_add(&link->sibling, &link_list); pdev->link_state = link; return link; @@ -972,21 +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 pci_dev *parent = pci_get_parent(root->pdev); + struct pci_dev *dev, *root_dev; - if (parent && parent->link_state) - root = parent->link_state->root; + /* Ensure it is the root device */ + root_dev = pcie_get_root(root->pdev); + root = root_dev ? root_dev->link_state : NULL; 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)) @@ -999,9 +999,9 @@ 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_dev; + struct pci_dev *parent_dev, *root_dev; struct pci_dev *parent = pdev->bus->self; - struct pcie_link_state *link, *root, *parent_link; + struct pcie_link_state *link, *parent_link; if (!parent || !parent->link_state) return; @@ -1016,7 +1016,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); parent_dev = pci_get_parent(link->pdev); parent_link = parent_dev ? parent_dev->link_state : NULL; @@ -1028,7 +1028,7 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev) /* Recheck latencies and configure upstream links */ if (parent_link) { - pcie_update_aspm_capable(root); + pcie_update_aspm_capable(root_dev->link_state); pcie_config_aspm_path(parent_link); } out: @@ -1040,6 +1040,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; @@ -1049,7 +1050,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 Wed Sep 29 00:43:14 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: 1534170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=NrgCUBmt; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HJyKj2FJcz9svs for ; Wed, 29 Sep 2021 10:43:37 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243523AbhI2ApO (ORCPT ); Tue, 28 Sep 2021 20:45:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243474AbhI2ApL (ORCPT ); Tue, 28 Sep 2021 20:45:11 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 044E7C06161C; Tue, 28 Sep 2021 17:43:31 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id dj4so1954870edb.5; Tue, 28 Sep 2021 17:43:30 -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=QaYBospqkyo2zoksyaVVuoRPJ/AmIkrCvWCzRt0IhxI=; b=NrgCUBmtDbxItfr92PjOrh9SvkpI4uBP8JeDq8mUeUi5g4jmIdZEl9wB5N4ujUeF7Z ChWlryubPWETX2yW+LFnDNrvg9emu+yYGlGoiw1dSNV5upu3Kf6gtTB+mYGmDk+f1iLa QdqkSJkavjmbs1NkLlLZc2ucjbcft+YvlBOC7RSmbsT0JTTGq/82sZLBfx/1k5Y6W3PV uYrsgByv2XZ1FBzrjmXwZvNcUZzBLf83qDbtx8C+7DVh2FDh9Vwb8f1iOwUul6qVf+TW efrl1sr/G5Wfa9JqF5GF3QmfpO7VT7EX28XquM8cjneHwUaXI/KJboTo1l4X+Yw7y6wH iLlw== 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=QaYBospqkyo2zoksyaVVuoRPJ/AmIkrCvWCzRt0IhxI=; b=HK2CcczWuRimWl9ZUiKW9UvU6sLpa0V1RgLUF1fUEd9IltzzNwRKb7vniz6Vhs249V wT2QT+R+IY+754aWVcrWC5F3M2+d4zXZm6HIc3IUx2l5GXAQCalZYUKol1mhsOVbiPbY LTLvq/1Elu11T0bIy1/DuFPZUsfjrxEOFQSz0ARcEy2mwVFYGb5xF4m4BxcxTygJb3ev AFQ0/Eor0GNpk/ZE6JS/H9IPW2HHnjlIxmLYTcdCcXXj7nSOfg5pMFVLW9q4EaKVDs5D oMeUDDmeY6XsooH8c2mYgP4blbNHiwS0jGG8WIrhkfFl8Rg94G85QmebFZB6YayVdRAq eYOQ== X-Gm-Message-State: AOAM530SGceaLF4c1EH4V0MRy8C9YsA8uhbBEBDivHQkvj4/gnRVLLbl f7yX3WdUr7uo++8RZbFwLB8= X-Google-Smtp-Source: ABdhPJyfIjT01g+qOs6toDr9np44G3SJFNMui1dFBA9izMfN76KUhMtWsTIaZS7PfFxtOH/Y5b1X6w== X-Received: by 2002:a17:906:1ec9:: with SMTP id m9mr10304099ejj.115.1632876209661; Tue, 28 Sep 2021 17:43:29 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:10f:c9f0:35c7:3af0:a197:61d0]) by smtp.googlemail.com with ESMTPSA id u16sm358489ejy.14.2021.09.28.17.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 17:43:29 -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 v2 3/4] PCI/ASPM: Remove struct pcie_link_state.downstream Date: Wed, 29 Sep 2021 02:43:14 +0200 Message-Id: <20210929004315.22558-4-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210929004315.22558-1-refactormyself@gmail.com> References: <20210929004315.22558-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() This patch: - removes *downstream* from *struct pcie_link_state*. - replaces references to pcie_link_state.downstream with a call to pci_function_0(pdev->subordinate). Signed-off-by: Bolarinwa O. Saheed --- 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 ad78aaeea444..56d4fe7d50b5 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 */ @@ -460,7 +459,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; @@ -550,7 +550,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; @@ -692,7 +693,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; @@ -751,7 +753,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 Wed Sep 29 00:43:15 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: 1534169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Al7CIYd6; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HJyKf5t62z9sR4 for ; Wed, 29 Sep 2021 10:43:34 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243493AbhI2ApN (ORCPT ); Tue, 28 Sep 2021 20:45:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243496AbhI2ApM (ORCPT ); Tue, 28 Sep 2021 20:45:12 -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 CCE28C06161C; Tue, 28 Sep 2021 17:43:31 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id b26so2134540edt.0; Tue, 28 Sep 2021 17:43:31 -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=hVi+b42a7oKTH3rSNcSPzpFbX0inHCO5G8w5h2JTx2A=; b=Al7CIYd6CTuRMp0Rodfg3uW+5NZzASZkDXJDPQg8ixM8l4JeFDzGNQLlY6L4cpz7j1 6sK8lSS/MAlg0V56eROlfLgKfhGaZmyfuE5nCz8k+f3n41vVTt2iEKLhLLxuhkaKUHd+ /9472KNg4yZypwF7wJIiBy7zxRLix4hjXR6pCWctB2Meo4rGBPEpm9X5mEO4aL7JL/2u Dn3dGKEqcDdKOpUE8mWjsdtMadGAlFuYJ2NKpoS2rVsl8S8pnr81/ieNplPmrLD4ejY0 kenHNQAA7m9sKuo1cYhtOfqgLX9khkF/b2V0ufY+icFNQZnpuANRD+lVUV3or0w/iuCl nMWg== 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=hVi+b42a7oKTH3rSNcSPzpFbX0inHCO5G8w5h2JTx2A=; b=6uVzBenovspgW/YSvh92X2IT1LxGPgjY8CtTYCFr27XgqvFt6Z+2VTFoJf5AYT3RIU JXoev3FTkjCf+Sb8vDCQALPyFVTGgj4qybFRWLANeer5LtAe0v4D6VMp9oHIjR+UFcZ4 b0udXPunMi9hR6RazZWVZVxi8m0+qiiukYqihVbRl+3pUdRAME3fOZG92QwWhIccx6T6 B48rLCNh8k3u+iBlmBpYAFH9pk+af1hmHTC67/G4ldGyXS6RdX7WLTf+YhsZyJEHP45j aJKqsdwSmpRi3PMJkMYgYbulDOHPG3Mv0ZjWV5pAs0Qj4PZnXoQIFjuJbtkpyIuty9/q k5Dw== X-Gm-Message-State: AOAM532lCM9T0MdK1r6OCZmGE05sgsfr/vwW5IFsz2fkogp/CoxnEc/b xKk8sP3YDRPsjPjiUWz1C/0pdS7gJzs= X-Google-Smtp-Source: ABdhPJxnGXRncGlPxJ5fuzR8LvLkKmpGHBFWFAwNcPfWAG2ozbWYBOnHNXED2VkuTA0MZfsQlHnMZA== X-Received: by 2002:a50:cfc1:: with SMTP id i1mr11283520edk.251.1632876210469; Tue, 28 Sep 2021 17:43:30 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:10f:c9f0:35c7:3af0:a197:61d0]) by smtp.googlemail.com with ESMTPSA id u16sm358489ejy.14.2021.09.28.17.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 17:43:30 -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 v2 4/4] PCI/ASPM: Remove unncessary linked list from aspm.c Date: Wed, 29 Sep 2021 02:43:15 +0200 Message-Id: <20210929004315.22558-5-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210929004315.22558-1-refactormyself@gmail.com> References: <20210929004315.22558-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 This patch: - removes link_list and struct pcie_link_state.sibling - accesses child devices via struct pci_dev.bust_list - accesses all PCI buses via pci_root_buses on struct pci_bus.node Signed-off-by: Bolarinwa O. Saheed --- drivers/pci/pcie/aspm.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 56d4fe7d50b5..4bef652dc63c 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 : NULL; - 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) && @@ -1024,7 +1017,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); @@ -1164,6 +1156,8 @@ static int pcie_aspm_set_policy(const char *val, { int i; struct pcie_link_state *link; + struct pci_bus *bus; + struct pci_dev *pdev; if (aspm_disabled) return -EPERM; @@ -1176,9 +1170,18 @@ 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) { + 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)); + } } mutex_unlock(&aspm_lock); up_read(&pci_bus_sem);