From: Lukas Wunner <lukas@wunner.de>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: linux-pci@vger.kernel.org, Bjorn Helgaas <helgaas@kernel.org>,
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Wilczy??ski <kw@linux.com>,
Alexandru Gagniuc <mr.nuke.me@gmail.com>,
Krishna chaitanya chundru <quic_krichai@quicinc.com>,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
"Rafael J . Wysocki" <rafael@kernel.org>,
linux-pm@vger.kernel.org, Bjorn Helgaas <bhelgaas@google.com>,
linux-kernel@vger.kernel.org,
Alex Deucher <alexdeucher@gmail.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Amit Kucheria <amitk@kernel.org>, Zhang Rui <rui.zhang@intel.com>
Subject: Re: [PATCH v3 08/10] PCI/bwctrl: Add "controller" part into PCIe bwctrl
Date: Sat, 30 Dec 2023 19:49:05 +0100 [thread overview]
Message-ID: <20231230184905.GA6104@wunner.de> (raw)
In-Reply-To: <20230929115723.7864-9-ilpo.jarvinen@linux.intel.com>
On Fri, Sep 29, 2023 at 02:57:21PM +0300, Ilpo Järvinen wrote:
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -16569,6 +16569,13 @@ F: include/linux/pci*
> F: include/uapi/linux/pci*
> F: lib/pci*
>
> +PCIE BANDWIDTH CONTROLLER
> +M: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> +L: linux-pci@vger.kernel.org
> +S: Supported
> +F: drivers/pci/pcie/bwctrl.c
> +F: include/linux/pci-bwctrl.h
> +
Maybe add this already in the preceding patch.
> --- a/drivers/pci/pcie/Kconfig
> +++ b/drivers/pci/pcie/Kconfig
> @@ -138,12 +138,13 @@ config PCIE_PTM
> is safe to enable even if you don't.
>
> config PCIE_BW
> - bool "PCI Express Bandwidth Change Notification"
> + bool "PCI Express Bandwidth Controller"
I'd fold this change into the preceding patch.
Deleting a line introduced by the preceding patch isn't great.
Never mind that the patch isn't a clean revert that way.
Your approach of making changes to the original version
of the bandwith monitoring driver and calling out those
changes in the commit message seems fine to me.
> depends on PCIEPORTBUS
> help
> - This enables PCI Express Bandwidth Change Notification. If
> - you know link width or rate changes occur to correct unreliable
> - links, you may answer Y.
> + This enables PCI Express Bandwidth Controller. The Bandwidth
> + Controller allows controlling PCIe link speed and listens for link
> + peed Change Notifications. If you know link width or rate changes
> + occur to correct unreliable links, you may answer Y.
It would be neater if you could avoid deleting lines introduced by
the preceding patch. Ideally you'd add a new paragraph, thus only
add new lines but not delete any existing ones.
> --- a/drivers/pci/pcie/bwctrl.c
> +++ b/drivers/pci/pcie/bwctrl.c
> @@ -1,14 +1,16 @@
> // SPDX-License-Identifier: GPL-2.0+
> /*
> - * PCI Express Link Bandwidth Notification services driver
> + * PCIe bandwidth controller
> + *
Again, fold this change into the preceding patch please.
> * Author: Alexandru Gagniuc <mr.nuke.me@gmail.com>
> *
> * Copyright (C) 2019, Dell Inc
> + * Copyright (C) 2023 Intel Corporation.
For extra neatness, drop the comma in the preceding patch and
the period in this patch.
> - * The PCIe Link Bandwidth Notification provides a way to notify the
> - * operating system when the link width or data rate changes. This
> - * capability is required for all root ports and downstream ports
> - * supporting links wider than x1 and/or multiple link speeds.
> + * The PCIe Bandwidth Controller provides a way to alter PCIe link speeds
> + * and notify the operating system when the link width or data rate changes.
> + * The notification capability is required for all Root Ports and Downstream
> + * Ports supporting links wider than x1 and/or multiple link speeds.
Again, adding a new paragraph and not deleting lines introduced by
the preceding patch would be much nicer.
> +#include <linux/bitops.h>
> +#include <linux/errno.h>
> +#include <linux/mutex.h>
> +#include <linux/pci.h>
> +#include <linux/pci-bwctrl.h>
> +#include <linux/types.h>
> +
> +#include <asm/rwonce.h>
> +
Which of these are necessary for functionality introduced by this
patch and which are necessary anyway and should be moved to the
preceding patch?
> +/**
> + * struct bwctrl_service_data - PCIe Port Bandwidth Controller
Code comment at the top of this file says "PCIe bandwidth controller",
use here as well for neatness.
> +static u16 speed2lnkctl2(enum pci_bus_speed speed)
> +{
> + static const u16 speed_conv[] = {
> + [PCIE_SPEED_2_5GT] = PCI_EXP_LNKCTL2_TLS_2_5GT,
> + [PCIE_SPEED_5_0GT] = PCI_EXP_LNKCTL2_TLS_5_0GT,
> + [PCIE_SPEED_8_0GT] = PCI_EXP_LNKCTL2_TLS_8_0GT,
> + [PCIE_SPEED_16_0GT] = PCI_EXP_LNKCTL2_TLS_16_0GT,
> + [PCIE_SPEED_32_0GT] = PCI_EXP_LNKCTL2_TLS_32_0GT,
> + [PCIE_SPEED_64_0GT] = PCI_EXP_LNKCTL2_TLS_64_0GT,
> + };
Looks like this could be a u8 array to save a little bit of memory.
Also, this seems to duplicate pcie_link_speed[] defined in probe.c.
> +static int bwctrl_select_speed(struct pcie_device *srv, enum pci_bus_speed *speed)
> +{
> + struct pci_bus *bus = srv->port->subordinate;
> + u8 speeds, dev_speeds;
> + int i;
> +
> + if (*speed > PCIE_LNKCAP2_SLS2SPEED(bus->pcie_bus_speeds))
> + return -EINVAL;
> +
> + dev_speeds = READ_ONCE(bus->pcie_dev_speeds);
Hm, why is the compiler barrier needed?
> + /* Only the lowest speed can be set when there are no devices */
> + if (!dev_speeds)
> + dev_speeds = PCI_EXP_LNKCAP2_SLS_2_5GB;
Maybe move this to patch [06/10], i.e. set dev->bus->pcie_dev_speeds to
PCI_EXP_LNKCAP2_SLS_2_5GB on removal (instead of 0).
> + speeds = bus->pcie_bus_speeds & dev_speeds;
> + i = BIT(fls(speeds));
> + while (i >= PCI_EXP_LNKCAP2_SLS_2_5GB) {
> + enum pci_bus_speed candidate;
> +
> + if (speeds & i) {
> + candidate = PCIE_LNKCAP2_SLS2SPEED(i);
> + if (candidate <= *speed) {
> + *speed = candidate;
> + return 0;
> + }
> + }
> + i >>= 1;
> + }
Can't we just do something like
supported_speeds = bus->pcie_bus_speeds & dev_speeds;
desired_speeds = GEN_MASK(pcie_link_speed[*speed], 1);
*speed = BIT(fls(supported_speeds & desired_speeds));
and thus avoid the loop altogether?
> +/**
> + * bwctrl_set_current_speed - Set downstream link speed for PCIe port
> + * @srv: PCIe port
> + * @speed: PCIe bus speed to set
> + *
> + * Attempts to set PCIe port link speed to @speed. As long as @speed is less
> + * than the maximum of what is supported by @srv, the speed is adjusted
> + * downwards to the best speed supported by both the port and device
> + * underneath it.
> + *
> + * Return:
> + * * 0 - on success
> + * * -EINVAL - @speed is higher than the maximum @srv supports
> + * * -ETIMEDOUT - changing link speed took too long
> + * * -EAGAIN - link speed was changed but @speed was not achieved
> + */
So passing a higher speed than what's supported by the Endpoint is fine
but passing a higher speed than what's supported by the Downstream Port
is not? Why the distinction? Maybe it would be more logical to just
pick the maximum of what either supports and use that in lieu of a
too-high speed?
> +int bwctrl_set_current_speed(struct pcie_device *srv, enum pci_bus_speed speed)
> +{
> + struct bwctrl_service_data *data = get_service_data(srv);
> + struct pci_dev *port = srv->port;
> + u16 link_status;
> + int ret;
> +
> + if (WARN_ON_ONCE(!bwctrl_valid_pcie_speed(speed)))
> + return -EINVAL;
> +
> + ret = bwctrl_select_speed(srv, &speed);
> + if (ret < 0)
> + return ret;
How about checking here if the selected speed is equivalent to what's
being used right now and bailing out if so? No need to retrain if
we're already at the desired speed.
> @@ -91,16 +242,32 @@ static int pcie_bandwidth_notification_probe(struct pcie_device *srv)
> if (ret)
> return ret;
>
> + data = kzalloc(sizeof(*data), GFP_KERNEL);
> + if (!data) {
> + ret = -ENOMEM;
> + goto free_irq;
> + }
> + mutex_init(&data->set_speed_mutex);
> + set_service_data(srv, data);
> +
I think you should move that further up so that you allocate and populate
the data struct before requesting the IRQ. Otherwise if BIOS has already
enabled link bandwith notification for some reason, the IRQ handler might
be invoked without the data struct being allocated.
> --- /dev/null
> +++ b/include/linux/pci-bwctrl.h
> @@ -0,0 +1,17 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * PCIe bandwidth controller
> + *
> + * Copyright (C) 2023 Intel Corporation.
Another trailing period I'd remove.
Thanks,
Lukas
next prev parent reply other threads:[~2023-12-30 18:49 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-29 11:57 [PATCH v3 00/10] Add PCIe Bandwidth Controller Ilpo Järvinen
2023-09-29 11:57 ` [PATCH v3 01/10] PCI: Protect Link Control 2 Register with RMW locking Ilpo Järvinen
2023-12-30 10:33 ` Lukas Wunner
2023-09-29 11:57 ` [PATCH v3 02/10] drm/radeon: Use RMW accessors for changing LNKCTL2 Ilpo Järvinen
2023-09-29 11:57 ` [PATCH v3 03/10] drm/amdgpu: " Ilpo Järvinen
2023-09-29 11:57 ` [PATCH v3 04/10] RDMA/hfi1: " Ilpo Järvinen
2023-09-29 13:03 ` Dean Luick
2023-09-29 11:57 ` [PATCH v3 05/10] PCI: Store all PCIe Supported Link Speeds Ilpo Järvinen
2023-12-30 11:45 ` Lukas Wunner
2023-12-30 19:30 ` Lukas Wunner
2024-01-01 16:26 ` Ilpo Järvinen
2024-01-01 16:40 ` Lukas Wunner
2024-01-01 16:53 ` Ilpo Järvinen
2023-09-29 11:57 ` [PATCH v3 06/10] PCI: Cache PCIe device's Supported Speed Vector Ilpo Järvinen
2023-12-30 15:19 ` Lukas Wunner
2024-01-01 18:31 ` Ilpo Järvinen
2024-01-03 16:51 ` Lukas Wunner
2023-09-29 11:57 ` [PATCH v3 07/10] PCI/LINK: Re-add BW notification portdrv as PCIe BW controller Ilpo Järvinen
2023-12-30 15:58 ` Lukas Wunner
2024-01-01 17:37 ` Ilpo Järvinen
2024-01-01 18:11 ` Lukas Wunner
2023-09-29 11:57 ` [PATCH v3 08/10] PCI/bwctrl: Add "controller" part into PCIe bwctrl Ilpo Järvinen
2023-12-30 18:49 ` Lukas Wunner [this message]
2024-01-01 18:12 ` Ilpo Järvinen
2024-01-03 16:40 ` Lukas Wunner
2023-09-29 11:57 ` [PATCH v3 09/10] thermal: Add PCIe cooling driver Ilpo Järvinen
2023-12-30 19:08 ` Lukas Wunner
2024-01-01 16:39 ` Ilpo Järvinen
2023-09-29 11:57 ` [PATCH v3 10/10] selftests/pcie_bwctrl: Create selftests Ilpo Järvinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231230184905.GA6104@wunner.de \
--to=lukas@wunner.de \
--cc=alexdeucher@gmail.com \
--cc=amitk@kernel.org \
--cc=bhelgaas@google.com \
--cc=daniel.lezcano@linaro.org \
--cc=helgaas@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=kw@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=mr.nuke.me@gmail.com \
--cc=quic_krichai@quicinc.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=rui.zhang@intel.com \
--cc=srinivas.pandruvada@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox