From patchwork Sat Nov 6 17:53: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: 12606399 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 CA215C4332F for ; Sat, 6 Nov 2021 17:53:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AAD5F61244 for ; Sat, 6 Nov 2021 17:53:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231783AbhKFRz5 (ORCPT ); Sat, 6 Nov 2021 13:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234707AbhKFRz4 (ORCPT ); Sat, 6 Nov 2021 13:55:56 -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 34436C061570; Sat, 6 Nov 2021 10:53:15 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id j21so44579446edt.11; Sat, 06 Nov 2021 10:53:15 -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=nbOjDct3Mi8YpAbJdZDOqR4PzB05X2wNYYMTuBfzE7k=; b=NTbJrxWojFdf4mOBjeTBJg1DMSxlxr/rm5WnHju3Au9ytT279EAsWXOieTl44bBEeA JbaoZ7W/N9klqP0rz7BtURrPN1p2RznOYKKXn6xnxQ3NTte4AL9N6Cugh0cZeEBfckQu UUGoK1UcxVayjWIZP9XgZS5pqfsH6xJgdwX9R+MkQC4MGW5mvk48Dcg8GU02lcLX1htV So22ojHNdi49TxrpXxQ6mnJsV6yzaE5gCKESAz+AXJTLElhjZIk2hs+Xd9c7/N0XKBWS i3fCsIfFbb13DWihAyS592yycd8LCm86nVFQ42iINmvWEWrNj1KHB2dyAIAjdjhQrH5F dNeg== 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=nbOjDct3Mi8YpAbJdZDOqR4PzB05X2wNYYMTuBfzE7k=; b=RLN6/y8rgprsKbuLch9mZaUFLUCZXV07OyjIz5XbCtIq7SC+8FCgoKt45UIqeLcWIi tDsmcIRf7QN9M/2YM73LNDhqCyjylvs8XW0BfcsYQccAvTbronbWpcnIdXZ5n0J5dWg8 Qmm7oPaRI5ib7MFuYGHrQHkAUx80eojDPIsk4yansMmHv6FmTt0Xd41BqwaN6pbdfnnJ twmJXpItqqojh/upgCWryXr9XYAdp1ovwERT0F8WYQJ+0XhXZ6FtBWVMlgqbXCbQKqEL a0UCsdw7RkcZqRxL/HrylPvXOxLiRWUQvie6hMjZYaAXmE6r8EaxhpNNRs0QtKfLCSqc ROew== X-Gm-Message-State: AOAM5337Pc7lb0h1hVSajaW3pm/PxxJ8bf9ECTizxK+7fLWvkpk77GbW JzChZHsqZDzJb8yPmKIlnbqW1XuGGjQ= X-Google-Smtp-Source: ABdhPJz08L5d979C2bchJhsyJbjSGUlwTCY3LU+PcUrS4SSOeSY0oE5ELpiz2BR9qGo/1LAp1MyOJw== X-Received: by 2002:a50:9d8e:: with SMTP id w14mr90190311ede.74.1636221193598; Sat, 06 Nov 2021 10:53:13 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id g10sm6364857edr.56.2021.11.06.10.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:53:13 -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 v4 1/4] PCI/ASPM: Move pci_function_0() upward Date: Sat, 6 Nov 2021 18:53:02 +0100 Message-Id: <20211106175305.25565-2-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175305.25565-1-refactormyself@gmail.com> References: <20211106175305.25565-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: "Bolarinwa O. Saheed" To call pci_function_0() directly from other functions, move its definition upward to a more accessible location. Signed-off-by: Bolarinwa O. Saheed Reviewed-by: Christoph Hellwig --- drivers/pci/pcie/aspm.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 013a47f587ce..a6d89c2c5b60 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -105,6 +105,20 @@ static const char *policy_str[] = { #define LINK_RETRAIN_TIMEOUT HZ +/* + * The L1 PM substate capability is only implemented in function 0 in a + * multi function device. + */ +static struct pci_dev *pci_function_0(struct pci_bus *linkbus) +{ + struct pci_dev *child; + + list_for_each_entry(child, &linkbus->devices, bus_list) + if (PCI_FUNC(child->devfn) == 0) + return child; + return NULL; +} + static int policy_to_aspm_state(struct pcie_link_state *link) { switch (aspm_policy) { @@ -423,20 +437,6 @@ static void pcie_aspm_check_latency(struct pci_dev *endpoint) } } -/* - * The L1 PM substate capability is only implemented in function 0 in a - * multi function device. - */ -static struct pci_dev *pci_function_0(struct pci_bus *linkbus) -{ - struct pci_dev *child; - - list_for_each_entry(child, &linkbus->devices, bus_list) - if (PCI_FUNC(child->devfn) == 0) - return child; - return NULL; -} - static void pci_clear_and_set_dword(struct pci_dev *pdev, int pos, u32 clear, u32 set) { From patchwork Sat Nov 6 17:53: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: 12606401 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 BFEF4C433EF for ; Sat, 6 Nov 2021 17:53:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A06E4610E9 for ; Sat, 6 Nov 2021 17:53:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234719AbhKFRz6 (ORCPT ); Sat, 6 Nov 2021 13:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234714AbhKFRz6 (ORCPT ); Sat, 6 Nov 2021 13:55:58 -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 7FEF8C061570; Sat, 6 Nov 2021 10:53:16 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id ee33so44968757edb.8; Sat, 06 Nov 2021 10:53:16 -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=epBvfuJRJhoeaojCSsux12nzywNe4SCEfxE39DKnyw4=; b=OJNiSuoyuoUidRHOQZMYZXambmieMz/7N9aL8QVwCQKORvHcqwqb8eXIgze6AXC5vo 6srnYlKfnyo7+nVqMkkl7kNnwgnd+097+T5BPeKciANXtMfqHMp5mGtYKb7ynuj4b9/4 AfSRE3T53BlXqfn/W7hD0HMDzbAd6p1VDCH27oTXCCLZj+nPGzQ9AQWNSmixlpfh7hC5 0LDeioT6i5OA802JgU6GO+mbQbyBIs6FIXzHeZ+hGK9P7ifWqb+Fz5EOLuZLJIEA3Jpz UMuCyLj657fEv+cSvfYykCKlZ7tzxIT9abQfp9ywlny4LINZT4npLmD7hQezQJzxvnbs AVlA== 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=epBvfuJRJhoeaojCSsux12nzywNe4SCEfxE39DKnyw4=; b=Vd5A9elHTy19oekM3eYvmV8bXicCLPOF2g1SWuVroXn15HnGEp5KzSACy0YXZ+x5PZ 25gqWxLMhOEL13uY/sCGVPhPxckG02J6eCSeaaeak+GCwWeukYr25j6If6lMht/45t28 SU5YZI93Qt1wAV95iJygF7wHQHwqRv6wySig13/ZXBR0gC8KUdv267tiqdWVF1SkdETe awTQCKjoaEuREPy83+qtB6LLt+t1VzvX0Dky/VPtNyH2sreMBEH/7jozHXwbfBcb2G/t Ld33zw4Xv3jvSGi0UEzvv9DrTAvw5pkNmJub2BkBpwAZNkEH0MtxQSl2xjFx4kUmZ4ZS X4nA== X-Gm-Message-State: AOAM533WA6rIFZX5xE0RJbso5b/NrJt0IbH1boEWqNZFu+oSRKTvxA5g qCHrKNWk4yVfb5j//9SIXm68+QpNrtM= X-Google-Smtp-Source: ABdhPJzHpDHygLa3rd75XeOu0tyX9GrGSGn3fft8/9KEzpaXdzE1FoPU0y1JrlPbVA69Vvx/jbcNig== X-Received: by 2002:a17:906:a08c:: with SMTP id q12mr81899590ejy.443.1636221194400; Sat, 06 Nov 2021 10:53:14 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id g10sm6364857edr.56.2021.11.06.10.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:53:14 -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 v4 2/4] PCI/ASPM: Do not cache link latencies Date: Sat, 6 Nov 2021 18:53:03 +0100 Message-Id: <20211106175305.25565-3-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175305.25565-1-refactormyself@gmail.com> References: <20211106175305.25565-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The latencies of the upstream and downstream are calculated within pcie_aspm_cap_init() and cached in struct pcie_link_state.latency_* These values are only used in pcie_aspm_check_latency() where they are compared with the acceptable latencies on the link. - remove `latency_*` entries from struct pcie_link_state. - calculate the latencies directly where they are needed. Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/pcie/aspm.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index a6d89c2c5b60..9e74df7b9dc0 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -66,9 +66,6 @@ struct pcie_link_state { u32 clkpm_default:1; /* Default Clock PM state by BIOS */ u32 clkpm_disable:1; /* Clock PM disabled */ - /* Exit latencies */ - struct aspm_latency latency_up; /* Upstream direction exit latency */ - struct aspm_latency latency_dw; /* Downstream direction exit latency */ /* * Endpoint acceptable latencies. A pcie downstream port only * has one slot under it, so at most there are 8 functions. @@ -392,7 +389,8 @@ 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; + u32 latency, lnkcap_up, lnkcap_dw, l1_switch_latency = 0; + struct aspm_latency latency_up, latency_dw; struct aspm_latency *acceptable; struct pcie_link_state *link; @@ -405,14 +403,23 @@ static void pcie_aspm_check_latency(struct pci_dev *endpoint) acceptable = &link->acceptable[PCI_FUNC(endpoint->devfn)]; while (link) { + /* Read direction exit latencies */ + pcie_capability_read_dword(link->pdev, PCI_EXP_LNKCAP, &lnkcap_up); + pcie_capability_read_dword(pci_function_0(link->pdev->subordinate), + PCI_EXP_LNKCAP, &lnkcap_dw); + latency_up.l0s = calc_l0s_latency(lnkcap_up); + latency_up.l1 = calc_l1_latency(lnkcap_up); + latency_dw.l0s = calc_l0s_latency(lnkcap_dw); + latency_dw.l1 = calc_l1_latency(lnkcap_dw); + /* Check upstream direction L0s latency */ if ((link->aspm_capable & ASPM_STATE_L0S_UP) && - (link->latency_up.l0s > acceptable->l0s)) + (latency_up.l0s > acceptable->l0s)) link->aspm_capable &= ~ASPM_STATE_L0S_UP; /* Check downstream direction L0s latency */ if ((link->aspm_capable & ASPM_STATE_L0S_DW) && - (link->latency_dw.l0s > acceptable->l0s)) + (latency_dw.l0s > acceptable->l0s)) link->aspm_capable &= ~ASPM_STATE_L0S_DW; /* * Check L1 latency. @@ -427,7 +434,7 @@ static void pcie_aspm_check_latency(struct pci_dev *endpoint) * L1 exit latencies advertised by a device include L1 * substate latencies (and hence do not do any check). */ - latency = max_t(u32, link->latency_up.l1, link->latency_dw.l1); + latency = max_t(u32, latency_up.l1, latency_dw.l1); if ((link->aspm_capable & ASPM_STATE_L1) && (latency + l1_switch_latency > acceptable->l1)) link->aspm_capable &= ~ASPM_STATE_L1; @@ -593,8 +600,6 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) link->aspm_enabled |= ASPM_STATE_L0S_UP; if (parent_lnkctl & PCI_EXP_LNKCTL_ASPM_L0S) link->aspm_enabled |= ASPM_STATE_L0S_DW; - link->latency_up.l0s = calc_l0s_latency(parent_lnkcap); - link->latency_dw.l0s = calc_l0s_latency(child_lnkcap); /* Setup L1 state */ if (parent_lnkcap & child_lnkcap & PCI_EXP_LNKCAP_ASPM_L1) @@ -602,8 +607,6 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) if (parent_lnkctl & child_lnkctl & PCI_EXP_LNKCTL_ASPM_L1) link->aspm_enabled |= ASPM_STATE_L1; - link->latency_up.l1 = calc_l1_latency(parent_lnkcap); - link->latency_dw.l1 = calc_l1_latency(child_lnkcap); /* Setup L1 substate */ pci_read_config_dword(parent, parent->l1ss + PCI_L1SS_CAP, From patchwork Sat Nov 6 17:53:04 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: 12606403 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 970A5C4332F for ; Sat, 6 Nov 2021 17:53:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84123610E9 for ; Sat, 6 Nov 2021 17:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234724AbhKFRz7 (ORCPT ); Sat, 6 Nov 2021 13:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234716AbhKFRz6 (ORCPT ); Sat, 6 Nov 2021 13:55:58 -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 C11A8C061714; Sat, 6 Nov 2021 10:53:16 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id f8so44912128edy.4; Sat, 06 Nov 2021 10:53:16 -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=6exyrB9eI4Ukr7viowD1F2sVcUX7M9z1Yw2CZoS4oow=; b=BCWceeMyYA42nBlr9VPVnXxupqwV8ppJ5aEzz8Cv+ZMwvP6tXIYJgRB/rdOuLRe8Jw trQyZaqKXwS1oyYZ2dWJqVzOMzX5tUslCQHZqbWW/WRMhGO3BnL4MKgBROgmG4Vv6yUL nM4lO3+vAiyTgQRabf+25BVyjDVQk4ez0o1w0mXrdIrl+EbeIiHhb6V9azvun+oHzfhE 1VlO48RVsBrk+Tr9o2Tzm6tS+FtcussABU27ThrOl9tLP6obnPPdopFPP3ZNpMaIOaVK AhrzFJB2c7mJofbFg1d67Lp/aX3DAhE5A8pcx8SwO9psB+bersFMCt5RUFh+WAShmvbw LjWw== 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=6exyrB9eI4Ukr7viowD1F2sVcUX7M9z1Yw2CZoS4oow=; b=fm7LbXAHDVU4CUzQmpdBa3MpQZVde0g2ceAxfXtrtmsmkmio/78YBz2IQfxZW8TSeV fRxFztC7eob70Y6zgFDvqKRBKFI/bxT9lZ1ieYlJd7qRz0NFsiqYqEGNfbBp+C2WpB6B w5n39mhxN0Q2GMsuggMpQyiiQGA37/H9IbNmJ3/tUVhSPowyp+bAocDW9XLr+6USaEiH V4ymXgLGKxv02dOdzEo6j6CCVJ5qRi3vX9i2uGIiMG7a+zf8Q17xukQ5nGY3DP1+t6dH pgiQ+J70RpqgRLPgbFfHQx64KARCKhkURXX65r+SKuCP47nsiMpeWXq/+OSi+b9FhZCr 8KcA== X-Gm-Message-State: AOAM5310vSdRmIWyVJCHhZ+9QtaJ9BS19icH21DrtH7ljKYt4zuJaZuH mnzHlMiqHLk7YV6g5n+wIgU= X-Google-Smtp-Source: ABdhPJyQj8bHzy5SOKI4lotIOvBoTAiWOxLCVdpoStd1VPhI3lCpA/4BaoYWU96kaoA11X5KzJTkGA== X-Received: by 2002:a17:907:86a6:: with SMTP id qa38mr7286788ejc.286.1636221195202; Sat, 06 Nov 2021 10:53:15 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id g10sm6364857edr.56.2021.11.06.10.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:53:14 -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 v4 3/4] PCI/ASPM: Remove struct pcie_link_state.acceptable Date: Sat, 6 Nov 2021 18:53:04 +0100 Message-Id: <20211106175305.25565-4-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175305.25565-1-refactormyself@gmail.com> References: <20211106175305.25565-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The acceptable latencies for each device on the bus are calculated within pcie_aspm_cap_init() and cached in struct pcie_link_state.acceptable. They are only used within pcie_aspm_check_latency() to validate actual latencies. Thus, it is possible to avoid caching these values. - remove `acceptable` from struct pcie_link_state - calculate the acceptable latency for individual device directly - remove the calculations done within pcie_aspm_cap_init() Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/pcie/aspm.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 9e74df7b9dc0..6afbb86d07b8 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -65,12 +65,6 @@ struct pcie_link_state { u32 clkpm_enabled:1; /* Current Clock PM state */ u32 clkpm_default:1; /* Default Clock PM state by BIOS */ u32 clkpm_disable:1; /* Clock PM disabled */ - - /* - * Endpoint acceptable latencies. A pcie downstream port only - * has one slot under it, so at most there are 8 functions. - */ - struct aspm_latency acceptable[8]; }; static int aspm_disabled, aspm_force; @@ -389,7 +383,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, lnkcap_up, lnkcap_dw, l1_switch_latency = 0; + u32 reg32, latency, encoding, lnkcap_up, lnkcap_dw, l1_switch_latency = 0; struct aspm_latency latency_up, latency_dw; struct aspm_latency *acceptable; struct pcie_link_state *link; @@ -400,7 +394,13 @@ static void pcie_aspm_check_latency(struct pci_dev *endpoint) return; link = endpoint->bus->self->link_state; - acceptable = &link->acceptable[PCI_FUNC(endpoint->devfn)]; + pcie_capability_read_dword(endpoint, PCI_EXP_DEVCAP, ®32); + /* Calculate endpoint L0s acceptable latency */ + encoding = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6; + acceptable->l0s = calc_l0s_acceptable(encoding); + /* Calculate endpoint L1 acceptable latency */ + encoding = (reg32 & PCI_EXP_DEVCAP_L1) >> 9; + acceptable->l1 = calc_l1_acceptable(encoding); while (link) { /* Read direction exit latencies */ @@ -663,22 +663,11 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) /* Get and check endpoint acceptable latencies */ list_for_each_entry(child, &linkbus->devices, bus_list) { - u32 reg32, encoding; - struct aspm_latency *acceptable = - &link->acceptable[PCI_FUNC(child->devfn)]; if (pci_pcie_type(child) != PCI_EXP_TYPE_ENDPOINT && pci_pcie_type(child) != PCI_EXP_TYPE_LEG_END) continue; - pcie_capability_read_dword(child, PCI_EXP_DEVCAP, ®32); - /* Calculate endpoint L0s acceptable latency */ - encoding = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6; - acceptable->l0s = calc_l0s_acceptable(encoding); - /* Calculate endpoint L1 acceptable latency */ - encoding = (reg32 & PCI_EXP_DEVCAP_L1) >> 9; - acceptable->l1 = calc_l1_acceptable(encoding); - pcie_aspm_check_latency(child); } } From patchwork Sat Nov 6 17:53:05 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: 12606405 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 1EE51C43217 for ; Sat, 6 Nov 2021 17:53:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 083E56023D for ; Sat, 6 Nov 2021 17:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234728AbhKFR4A (ORCPT ); Sat, 6 Nov 2021 13:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234722AbhKFRz7 (ORCPT ); Sat, 6 Nov 2021 13:55:59 -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 85790C061570; Sat, 6 Nov 2021 10:53:17 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id m14so44018813edd.0; Sat, 06 Nov 2021 10:53:17 -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=+vbyct0ysNWFRh8lOEYGpZrf0n1PUQPKvtjJYv0U1Fg=; b=nop9XaODHozccoOylhdhI8CPJjPKM17ieNUWJrCtPumlVrHLbPl5sLg7lsMWd9IMJn ZwdePy1h1FDTqlt8HUo/ZQzK4tTjj2BfJHdIz9cgPTGecum6C1tA0yIv3qBlVNplilEW lXchoC8ZKChc+/e4Hw5nYd1TdJgHhRDFskQxKJrnE1Ebg66XcYgMGTNlskDRjvvP2kZg ROdHVD1n8K8F7gtd+7R2kNXFJFHk44W/RA2vZUggB1Wi1tpJWD5cXOv+bwWy8BZbef/1 XJj7NMrqJChP89WOSTW/KAR3qz6X+zxCPM/Y8WyLmwmhiFHLBTImeukCgtGadgXnz6vx k3SA== 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=+vbyct0ysNWFRh8lOEYGpZrf0n1PUQPKvtjJYv0U1Fg=; b=hoxjAjZQqqIkKNIc91glro9D7fpgw0zyZJeLw5r35YcNhGvSt2vh/yhGUR69Hc6hfe vGf3IcL7oNiX838sSK67mtdVW5eEC9MHu7ZgTOQ3ZxPYGvjCCnIVN5mqDSslO0/60kSH v3z28dvRAXeCpRr41/SkcQgJ9Nx8jpUemenzGqSxKCyTjprrLigdp62/gtXCS57gg8k8 3jPdGtChFuOfE50i6TBRMJL3qgZYgOplVW7e0hWAmYqioa0UYzpEiqUfVhW8FsJYTzOJ 8hCaGF8Aa8rqfM9LeId7jJBbHqrwkhU/LDY2lcM6AyJZC+HjI2BDwh5K3wJMrz0+QT8m FUnA== X-Gm-Message-State: AOAM530+hAjzQzOo7St1e/8Yh+Z3oBLe4AXgV19EoO5/iuGPoGMCXt4h MD+7RZHiDVBZHfZQODpI/0U= X-Google-Smtp-Source: ABdhPJy40KmcRNVX01xMskLSiiWn2/IuuETjl2zBfZfQPI/LjM5hA1eMKF40N/I4XaTLe5lK6DCApw== X-Received: by 2002:a17:906:6a0f:: with SMTP id qw15mr40649279ejc.463.1636221195944; Sat, 06 Nov 2021 10:53:15 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id g10sm6364857edr.56.2021.11.06.10.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:53:15 -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 v4 4/4] PCI/ASPM: Remove struct aspm_latency Date: Sat, 6 Nov 2021 18:53:05 +0100 Message-Id: <20211106175305.25565-5-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175305.25565-1-refactormyself@gmail.com> References: <20211106175305.25565-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The struct aspm_latency is now used only inside pcie_aspm_check_latency(). - replace struct aspm_latency variables with u32 variables - remove struct aspm_latency Signed-off-by: Saheed O. Bolarinwa Reviewed-by: Christoph Hellwig --- drivers/pci/pcie/aspm.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 6afbb86d07b8..19459cb0af34 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -41,11 +41,6 @@ #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1 | \ ASPM_STATE_L1SS) -struct aspm_latency { - u32 l0s; /* L0s latency (nsec) */ - u32 l1; /* L1 latency (nsec) */ -}; - struct pcie_link_state { struct pci_dev *pdev; /* Upstream component of the Link */ struct pci_dev *downstream; /* Downstream component, function 0 */ @@ -384,8 +379,8 @@ static void encode_l12_threshold(u32 threshold_us, u32 *scale, u32 *value) static void pcie_aspm_check_latency(struct pci_dev *endpoint) { u32 reg32, latency, encoding, lnkcap_up, lnkcap_dw, l1_switch_latency = 0; - struct aspm_latency latency_up, latency_dw; - struct aspm_latency *acceptable; + u32 latency_up_l0s, latency_up_l1, latency_dw_l0s, latency_dw_l1; + u32 acceptable_l0s, acceptable_l1; struct pcie_link_state *link; /* Device not in D0 doesn't need latency check */ @@ -397,29 +392,29 @@ static void pcie_aspm_check_latency(struct pci_dev *endpoint) pcie_capability_read_dword(endpoint, PCI_EXP_DEVCAP, ®32); /* Calculate endpoint L0s acceptable latency */ encoding = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6; - acceptable->l0s = calc_l0s_acceptable(encoding); + acceptable_l0s = calc_l0s_acceptable(encoding); /* Calculate endpoint L1 acceptable latency */ encoding = (reg32 & PCI_EXP_DEVCAP_L1) >> 9; - acceptable->l1 = calc_l1_acceptable(encoding); + acceptable_l1 = calc_l1_acceptable(encoding); while (link) { /* Read direction exit latencies */ pcie_capability_read_dword(link->pdev, PCI_EXP_LNKCAP, &lnkcap_up); pcie_capability_read_dword(pci_function_0(link->pdev->subordinate), PCI_EXP_LNKCAP, &lnkcap_dw); - latency_up.l0s = calc_l0s_latency(lnkcap_up); - latency_up.l1 = calc_l1_latency(lnkcap_up); - latency_dw.l0s = calc_l0s_latency(lnkcap_dw); - latency_dw.l1 = calc_l1_latency(lnkcap_dw); + latency_up_l0s = calc_l0s_latency(lnkcap_up); + latency_up_l1 = calc_l1_latency(lnkcap_up); + latency_dw_l0s = calc_l0s_latency(lnkcap_dw); + latency_dw_l1 = calc_l1_latency(lnkcap_dw); /* Check upstream direction L0s latency */ if ((link->aspm_capable & ASPM_STATE_L0S_UP) && - (latency_up.l0s > acceptable->l0s)) + (latency_up_l0s > acceptable_l0s)) link->aspm_capable &= ~ASPM_STATE_L0S_UP; /* Check downstream direction L0s latency */ if ((link->aspm_capable & ASPM_STATE_L0S_DW) && - (latency_dw.l0s > acceptable->l0s)) + (latency_dw_l0s > acceptable_l0s)) link->aspm_capable &= ~ASPM_STATE_L0S_DW; /* * Check L1 latency. @@ -434,9 +429,9 @@ static void pcie_aspm_check_latency(struct pci_dev *endpoint) * L1 exit latencies advertised by a device include L1 * substate latencies (and hence do not do any check). */ - latency = max_t(u32, latency_up.l1, latency_dw.l1); + latency = max_t(u32, latency_up_l1, latency_dw_l1); if ((link->aspm_capable & ASPM_STATE_L1) && - (latency + l1_switch_latency > acceptable->l1)) + (latency + l1_switch_latency > acceptable_l1)) link->aspm_capable &= ~ASPM_STATE_L1; l1_switch_latency += 1000; @@ -663,7 +658,6 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) /* Get and check endpoint acceptable latencies */ 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) continue;