* [PATCH v2 01/10] IB/hfi1: Use FIELD_GET() to extract Link Width
2023-09-13 12:27 [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
@ 2023-09-13 12:27 ` Ilpo Järvinen
2023-09-13 13:14 ` Jonathan Cameron
2023-09-13 12:27 ` [PATCH v2 02/10] media: cobalt: " Ilpo Järvinen
` (9 subsequent siblings)
10 siblings, 1 reply; 19+ messages in thread
From: Ilpo Järvinen @ 2023-09-13 12:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-pci, Bjorn Helgaas, Dennis Dalessandro,
Jason Gunthorpe, Leon Romanovsky, linux-rdma, linux-kernel
Cc: Ilpo Järvinen
Use FIELD_GET() to extract PCIe Negotiated Link Width field instead of
custom masking and shifting, and remove extract_width() which only
wraps that FIELD_GET().
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/infiniband/hw/hfi1/pcie.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/drivers/infiniband/hw/hfi1/pcie.c b/drivers/infiniband/hw/hfi1/pcie.c
index 08732e1ac966..c132a9c073bf 100644
--- a/drivers/infiniband/hw/hfi1/pcie.c
+++ b/drivers/infiniband/hw/hfi1/pcie.c
@@ -3,6 +3,7 @@
* Copyright(c) 2015 - 2019 Intel Corporation.
*/
+#include <linux/bitfield.h>
#include <linux/pci.h>
#include <linux/io.h>
#include <linux/delay.h>
@@ -210,12 +211,6 @@ static u32 extract_speed(u16 linkstat)
return speed;
}
-/* return the PCIe link speed from the given link status */
-static u32 extract_width(u16 linkstat)
-{
- return (linkstat & PCI_EXP_LNKSTA_NLW) >> PCI_EXP_LNKSTA_NLW_SHIFT;
-}
-
/* read the link status and set dd->{lbus_width,lbus_speed,lbus_info} */
static void update_lbus_info(struct hfi1_devdata *dd)
{
@@ -228,7 +223,7 @@ static void update_lbus_info(struct hfi1_devdata *dd)
return;
}
- dd->lbus_width = extract_width(linkstat);
+ dd->lbus_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, linkstat);
dd->lbus_speed = extract_speed(linkstat);
snprintf(dd->lbus_info, sizeof(dd->lbus_info),
"PCIe,%uMHz,x%u", dd->lbus_speed, dd->lbus_width);
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v2 01/10] IB/hfi1: Use FIELD_GET() to extract Link Width
2023-09-13 12:27 ` [PATCH v2 01/10] IB/hfi1: Use FIELD_GET() to extract Link Width Ilpo Järvinen
@ 2023-09-13 13:14 ` Jonathan Cameron
0 siblings, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2023-09-13 13:14 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: linux-pci, Bjorn Helgaas, Dennis Dalessandro, Jason Gunthorpe,
Leon Romanovsky, linux-rdma, linux-kernel
On Wed, 13 Sep 2023 15:27:39 +0300
Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> wrote:
> Use FIELD_GET() to extract PCIe Negotiated Link Width field instead of
> custom masking and shifting, and remove extract_width() which only
> wraps that FIELD_GET().
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/infiniband/hw/hfi1/pcie.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/infiniband/hw/hfi1/pcie.c b/drivers/infiniband/hw/hfi1/pcie.c
> index 08732e1ac966..c132a9c073bf 100644
> --- a/drivers/infiniband/hw/hfi1/pcie.c
> +++ b/drivers/infiniband/hw/hfi1/pcie.c
> @@ -3,6 +3,7 @@
> * Copyright(c) 2015 - 2019 Intel Corporation.
> */
>
> +#include <linux/bitfield.h>
> #include <linux/pci.h>
> #include <linux/io.h>
> #include <linux/delay.h>
> @@ -210,12 +211,6 @@ static u32 extract_speed(u16 linkstat)
> return speed;
> }
>
> -/* return the PCIe link speed from the given link status */
> -static u32 extract_width(u16 linkstat)
> -{
> - return (linkstat & PCI_EXP_LNKSTA_NLW) >> PCI_EXP_LNKSTA_NLW_SHIFT;
> -}
> -
> /* read the link status and set dd->{lbus_width,lbus_speed,lbus_info} */
> static void update_lbus_info(struct hfi1_devdata *dd)
> {
> @@ -228,7 +223,7 @@ static void update_lbus_info(struct hfi1_devdata *dd)
> return;
> }
>
> - dd->lbus_width = extract_width(linkstat);
> + dd->lbus_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, linkstat);
> dd->lbus_speed = extract_speed(linkstat);
> snprintf(dd->lbus_info, sizeof(dd->lbus_info),
> "PCIe,%uMHz,x%u", dd->lbus_speed, dd->lbus_width);
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2 02/10] media: cobalt: Use FIELD_GET() to extract Link Width
2023-09-13 12:27 [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
2023-09-13 12:27 ` [PATCH v2 01/10] IB/hfi1: Use FIELD_GET() to extract Link Width Ilpo Järvinen
@ 2023-09-13 12:27 ` Ilpo Järvinen
2023-09-13 12:27 ` [PATCH v2 03/10] igb: " Ilpo Järvinen
` (8 subsequent siblings)
10 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2023-09-13 12:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-pci, Bjorn Helgaas, Hans Verkuil,
Mauro Carvalho Chehab, linux-media, linux-kernel
Cc: Ilpo Järvinen, Jonathan Cameron
Use FIELD_GET() to extract PCIe Negotiated and Maximum Link Width fields
instead of custom masking and shifting.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/media/pci/cobalt/cobalt-driver.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/media/pci/cobalt/cobalt-driver.c b/drivers/media/pci/cobalt/cobalt-driver.c
index 74edcc76d12f..6e1a0614e6d0 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.c
+++ b/drivers/media/pci/cobalt/cobalt-driver.c
@@ -8,6 +8,7 @@
* All rights reserved.
*/
+#include <linux/bitfield.h>
#include <linux/delay.h>
#include <media/i2c/adv7604.h>
#include <media/i2c/adv7842.h>
@@ -210,17 +211,17 @@ void cobalt_pcie_status_show(struct cobalt *cobalt)
pcie_capability_read_word(pci_dev, PCI_EXP_LNKSTA, &stat);
cobalt_info("PCIe link capability 0x%08x: %s per lane and %u lanes\n",
capa, get_link_speed(capa),
- (capa & PCI_EXP_LNKCAP_MLW) >> 4);
+ FIELD_GET(PCI_EXP_LNKCAP_MLW, capa));
cobalt_info("PCIe link control 0x%04x\n", ctrl);
cobalt_info("PCIe link status 0x%04x: %s per lane and %u lanes\n",
stat, get_link_speed(stat),
- (stat & PCI_EXP_LNKSTA_NLW) >> 4);
+ FIELD_GET(PCI_EXP_LNKSTA_NLW, stat));
/* Bus */
pcie_capability_read_dword(pci_bus_dev, PCI_EXP_LNKCAP, &capa);
cobalt_info("PCIe bus link capability 0x%08x: %s per lane and %u lanes\n",
capa, get_link_speed(capa),
- (capa & PCI_EXP_LNKCAP_MLW) >> 4);
+ FIELD_GET(PCI_EXP_LNKCAP_MLW, capa));
/* Slot */
pcie_capability_read_dword(pci_dev, PCI_EXP_SLTCAP, &capa);
@@ -239,7 +240,7 @@ static unsigned pcie_link_get_lanes(struct cobalt *cobalt)
if (!pci_is_pcie(pci_dev))
return 0;
pcie_capability_read_word(pci_dev, PCI_EXP_LNKSTA, &link);
- return (link & PCI_EXP_LNKSTA_NLW) >> 4;
+ return FIELD_GET(PCI_EXP_LNKSTA_NLW, link);
}
static unsigned pcie_bus_link_get_lanes(struct cobalt *cobalt)
@@ -250,7 +251,7 @@ static unsigned pcie_bus_link_get_lanes(struct cobalt *cobalt)
if (!pci_is_pcie(pci_dev))
return 0;
pcie_capability_read_dword(pci_dev, PCI_EXP_LNKCAP, &link);
- return (link & PCI_EXP_LNKCAP_MLW) >> 4;
+ return FIELD_GET(PCI_EXP_LNKCAP_MLW, link);
}
static void msi_config_show(struct cobalt *cobalt, struct pci_dev *pci_dev)
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH v2 03/10] igb: Use FIELD_GET() to extract Link Width
2023-09-13 12:27 [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
2023-09-13 12:27 ` [PATCH v2 01/10] IB/hfi1: Use FIELD_GET() to extract Link Width Ilpo Järvinen
2023-09-13 12:27 ` [PATCH v2 02/10] media: cobalt: " Ilpo Järvinen
@ 2023-09-13 12:27 ` Ilpo Järvinen
2023-09-13 12:27 ` [PATCH v2 04/10] PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields Ilpo Järvinen
` (7 subsequent siblings)
10 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2023-09-13 12:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-pci, Bjorn Helgaas, Jesse Brandeburg,
Tony Nguyen, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, intel-wired-lan, netdev, linux-kernel
Cc: Ilpo Järvinen, Jonathan Cameron
Use FIELD_GET() to extract PCIe Negotiated Link Width field instead of
custom masking and shifting.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/net/ethernet/intel/igb/e1000_mac.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/intel/igb/e1000_mac.c b/drivers/net/ethernet/intel/igb/e1000_mac.c
index caf91c6f52b4..5a23b9cfec6c 100644
--- a/drivers/net/ethernet/intel/igb/e1000_mac.c
+++ b/drivers/net/ethernet/intel/igb/e1000_mac.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2007 - 2018 Intel Corporation. */
+#include <linux/bitfield.h>
#include <linux/if_ether.h>
#include <linux/delay.h>
#include <linux/pci.h>
@@ -50,9 +51,8 @@ s32 igb_get_bus_info_pcie(struct e1000_hw *hw)
break;
}
- bus->width = (enum e1000_bus_width)((pcie_link_status &
- PCI_EXP_LNKSTA_NLW) >>
- PCI_EXP_LNKSTA_NLW_SHIFT);
+ bus->width = (enum e1000_bus_width)FIELD_GET(PCI_EXP_LNKSTA_NLW,
+ pcie_link_status);
}
reg = rd32(E1000_STATUS);
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH v2 04/10] PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields
2023-09-13 12:27 [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
` (2 preceding siblings ...)
2023-09-13 12:27 ` [PATCH v2 03/10] igb: " Ilpo Järvinen
@ 2023-09-13 12:27 ` Ilpo Järvinen
2023-09-13 12:27 ` [PATCH v2 05/10] PCI: mvebu: Use FIELD_PREP() with Link Width Ilpo Järvinen
` (6 subsequent siblings)
10 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2023-09-13 12:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-pci, Bjorn Helgaas, Lorenzo Pieralisi,
Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
Thierry Reding, Jonathan Hunter, linux-tegra, linux-kernel
Cc: Ilpo Järvinen, Jonathan Cameron
Use FIELD_GET() to extract PCIe Negotiated Link Width field instead of
custom masking and shifting.
Similarly, change custom code that misleadingly used
PCI_EXP_LNKSTA_NLW_SHIFT to prepare value for PCI_EXP_LNKCAP write
to use FIELD_PREP() with correct field define (PCI_EXP_LNKCAP_MLW).
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/pci/controller/dwc/pcie-tegra194.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
index 4bba31502ce1..248cd9347e8f 100644
--- a/drivers/pci/controller/dwc/pcie-tegra194.c
+++ b/drivers/pci/controller/dwc/pcie-tegra194.c
@@ -9,6 +9,7 @@
* Author: Vidya Sagar <vidyas@nvidia.com>
*/
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
@@ -346,8 +347,7 @@ static void apply_bad_link_workaround(struct dw_pcie_rp *pp)
*/
val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA);
if (val & PCI_EXP_LNKSTA_LBMS) {
- current_link_width = (val & PCI_EXP_LNKSTA_NLW) >>
- PCI_EXP_LNKSTA_NLW_SHIFT;
+ current_link_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val);
if (pcie->init_link_width > current_link_width) {
dev_warn(pci->dev, "PCIe link is bad, width reduced\n");
val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
@@ -760,8 +760,7 @@ static void tegra_pcie_enable_system_interrupts(struct dw_pcie_rp *pp)
val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base +
PCI_EXP_LNKSTA);
- pcie->init_link_width = (val_w & PCI_EXP_LNKSTA_NLW) >>
- PCI_EXP_LNKSTA_NLW_SHIFT;
+ pcie->init_link_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val_w);
val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base +
PCI_EXP_LNKCTL);
@@ -920,7 +919,7 @@ static int tegra_pcie_dw_host_init(struct dw_pcie_rp *pp)
/* Configure Max lane width from DT */
val = dw_pcie_readl_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKCAP);
val &= ~PCI_EXP_LNKCAP_MLW;
- val |= (pcie->num_lanes << PCI_EXP_LNKSTA_NLW_SHIFT);
+ val |= FIELD_PREP(PCI_EXP_LNKCAP_MLW, pcie->num_lanes);
dw_pcie_writel_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKCAP, val);
/* Clear Slot Clock Configuration bit if SRNS configuration */
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH v2 05/10] PCI: mvebu: Use FIELD_PREP() with Link Width
2023-09-13 12:27 [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
` (3 preceding siblings ...)
2023-09-13 12:27 ` [PATCH v2 04/10] PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields Ilpo Järvinen
@ 2023-09-13 12:27 ` Ilpo Järvinen
2023-09-13 12:27 ` [PATCH v2 06/10] PCI: Use FIELD_GET() to extract " Ilpo Järvinen
` (5 subsequent siblings)
10 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2023-09-13 12:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-pci, Bjorn Helgaas, Thomas Petazzoni,
Pali Rohár, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring, Bjorn Helgaas, linux-arm-kernel, linux-kernel
Cc: Ilpo Järvinen, Jonathan Cameron
mvebu_pcie_setup_hw() setups the Maximum Link Width field in the Link
Capabilities registers using an open-coded variant of FIELD_PREP() with
a literal in shift. Improve readability by using
FIELD_PREP(PCI_EXP_LNKCAP_MLW, ...).
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/pci/controller/pci-mvebu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
index 60810a1fbfb7..29fe09c99e7d 100644
--- a/drivers/pci/controller/pci-mvebu.c
+++ b/drivers/pci/controller/pci-mvebu.c
@@ -264,7 +264,7 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
*/
lnkcap = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_LNKCAP);
lnkcap &= ~PCI_EXP_LNKCAP_MLW;
- lnkcap |= (port->is_x4 ? 4 : 1) << 4;
+ lnkcap |= FIELD_PREP(PCI_EXP_LNKCAP_MLW, port->is_x4 ? 4 : 1);
mvebu_writel(port, lnkcap, PCIE_CAP_PCIEXP + PCI_EXP_LNKCAP);
/* Disable Root Bridge I/O space, memory space and bus mastering. */
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH v2 06/10] PCI: Use FIELD_GET() to extract Link Width
2023-09-13 12:27 [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
` (4 preceding siblings ...)
2023-09-13 12:27 ` [PATCH v2 05/10] PCI: mvebu: Use FIELD_PREP() with Link Width Ilpo Järvinen
@ 2023-09-13 12:27 ` Ilpo Järvinen
2023-09-13 12:27 ` [PATCH v2 07/10] scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields Ilpo Järvinen
` (4 subsequent siblings)
10 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2023-09-13 12:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-pci, Bjorn Helgaas, Bjorn Helgaas,
linux-kernel
Cc: Ilpo Järvinen, Jonathan Cameron
Use FIELD_GET() to extract PCIe Negotiated and Maximum Link Width fields
instead of custom masking and shifting.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/pci/pci-sysfs.c | 5 ++---
drivers/pci/pci.c | 6 +++---
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index d9eede2dbc0e..5a6241044c3c 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -12,7 +12,7 @@
* Modeled after usb's driverfs.c
*/
-
+#include <linux/bitfield.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/pci.h>
@@ -230,8 +230,7 @@ static ssize_t current_link_width_show(struct device *dev,
if (err)
return -EINVAL;
- return sysfs_emit(buf, "%u\n",
- (linkstat & PCI_EXP_LNKSTA_NLW) >> PCI_EXP_LNKSTA_NLW_SHIFT);
+ return sysfs_emit(buf, "%u\n", FIELD_GET(PCI_EXP_LNKSTA_NLW, linkstat));
}
static DEVICE_ATTR_RO(current_link_width);
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 59c01d68c6d5..a8adc34dc86f 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -9,6 +9,7 @@
*/
#include <linux/acpi.h>
+#include <linux/bitfield.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/dmi.h>
@@ -6257,8 +6258,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
next_speed = pcie_link_speed[lnksta & PCI_EXP_LNKSTA_CLS];
- next_width = (lnksta & PCI_EXP_LNKSTA_NLW) >>
- PCI_EXP_LNKSTA_NLW_SHIFT;
+ next_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, lnksta);
next_bw = next_width * PCIE_SPEED2MBS_ENC(next_speed);
@@ -6330,7 +6330,7 @@ enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev)
pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap);
if (lnkcap)
- return (lnkcap & PCI_EXP_LNKCAP_MLW) >> 4;
+ return FIELD_GET(PCI_EXP_LNKCAP_MLW, lnkcap);
return PCIE_LNK_WIDTH_UNKNOWN;
}
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH v2 07/10] scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields
2023-09-13 12:27 [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
` (5 preceding siblings ...)
2023-09-13 12:27 ` [PATCH v2 06/10] PCI: Use FIELD_GET() to extract " Ilpo Järvinen
@ 2023-09-13 12:27 ` Ilpo Järvinen
2023-09-13 13:15 ` Jonathan Cameron
2023-09-14 1:02 ` Martin K. Petersen
2023-09-13 12:27 ` [PATCH v2 08/10] scsi: qla2xxx: " Ilpo Järvinen
` (3 subsequent siblings)
10 siblings, 2 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2023-09-13 12:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-pci, Bjorn Helgaas, Bradley Grove,
James E.J. Bottomley, Martin K. Petersen, linux-scsi,
linux-kernel
Cc: Ilpo Järvinen
Use FIELD_GET() to extract PCIe capability register fields instead of
custom masking and shifting. Also remove the unnecessary cast to u8,
the value in those fields always fits to u8.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/scsi/esas2r/esas2r_ioctl.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c b/drivers/scsi/esas2r/esas2r_ioctl.c
index 055d2e87a2c8..3f7c1d131ec3 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -41,6 +41,8 @@
* USA.
*/
+#include <linux/bitfield.h>
+
#include "esas2r.h"
/*
@@ -792,16 +794,10 @@ static int hba_ioctl_callback(struct esas2r_adapter *a,
pcie_capability_read_dword(a->pcid, PCI_EXP_LNKCAP,
&caps);
- gai->pci.link_speed_curr =
- (u8)(stat & PCI_EXP_LNKSTA_CLS);
- gai->pci.link_speed_max =
- (u8)(caps & PCI_EXP_LNKCAP_SLS);
- gai->pci.link_width_curr =
- (u8)((stat & PCI_EXP_LNKSTA_NLW)
- >> PCI_EXP_LNKSTA_NLW_SHIFT);
- gai->pci.link_width_max =
- (u8)((caps & PCI_EXP_LNKCAP_MLW)
- >> 4);
+ gai->pci.link_speed_curr = FIELD_GET(PCI_EXP_LNKSTA_CLS, stat);
+ gai->pci.link_speed_max = FIELD_GET(PCI_EXP_LNKCAP_SLS, caps);
+ gai->pci.link_width_curr = FIELD_GET(PCI_EXP_LNKSTA_NLW, stat);
+ gai->pci.link_width_max = FIELD_GET(PCI_EXP_LNKCAP_MLW, caps);
}
gai->pci.msi_vector_cnt = 1;
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v2 07/10] scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields
2023-09-13 12:27 ` [PATCH v2 07/10] scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields Ilpo Järvinen
@ 2023-09-13 13:15 ` Jonathan Cameron
2023-09-14 1:02 ` Martin K. Petersen
1 sibling, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2023-09-13 13:15 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: linux-pci, Bjorn Helgaas, Bradley Grove, James E.J. Bottomley,
Martin K. Petersen, linux-scsi, linux-kernel
On Wed, 13 Sep 2023 15:27:45 +0300
Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> wrote:
> Use FIELD_GET() to extract PCIe capability register fields instead of
> custom masking and shifting. Also remove the unnecessary cast to u8,
> the value in those fields always fits to u8.
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/scsi/esas2r/esas2r_ioctl.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c b/drivers/scsi/esas2r/esas2r_ioctl.c
> index 055d2e87a2c8..3f7c1d131ec3 100644
> --- a/drivers/scsi/esas2r/esas2r_ioctl.c
> +++ b/drivers/scsi/esas2r/esas2r_ioctl.c
> @@ -41,6 +41,8 @@
> * USA.
> */
>
> +#include <linux/bitfield.h>
> +
> #include "esas2r.h"
>
> /*
> @@ -792,16 +794,10 @@ static int hba_ioctl_callback(struct esas2r_adapter *a,
> pcie_capability_read_dword(a->pcid, PCI_EXP_LNKCAP,
> &caps);
>
> - gai->pci.link_speed_curr =
> - (u8)(stat & PCI_EXP_LNKSTA_CLS);
> - gai->pci.link_speed_max =
> - (u8)(caps & PCI_EXP_LNKCAP_SLS);
> - gai->pci.link_width_curr =
> - (u8)((stat & PCI_EXP_LNKSTA_NLW)
> - >> PCI_EXP_LNKSTA_NLW_SHIFT);
> - gai->pci.link_width_max =
> - (u8)((caps & PCI_EXP_LNKCAP_MLW)
> - >> 4);
> + gai->pci.link_speed_curr = FIELD_GET(PCI_EXP_LNKSTA_CLS, stat);
> + gai->pci.link_speed_max = FIELD_GET(PCI_EXP_LNKCAP_SLS, caps);
> + gai->pci.link_width_curr = FIELD_GET(PCI_EXP_LNKSTA_NLW, stat);
> + gai->pci.link_width_max = FIELD_GET(PCI_EXP_LNKCAP_MLW, caps);
> }
>
> gai->pci.msi_vector_cnt = 1;
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 07/10] scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields
2023-09-13 12:27 ` [PATCH v2 07/10] scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields Ilpo Järvinen
2023-09-13 13:15 ` Jonathan Cameron
@ 2023-09-14 1:02 ` Martin K. Petersen
1 sibling, 0 replies; 19+ messages in thread
From: Martin K. Petersen @ 2023-09-14 1:02 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Jonathan Cameron, linux-pci, Bjorn Helgaas, Bradley Grove,
James E.J. Bottomley, Martin K. Petersen, linux-scsi,
linux-kernel
Ilpo,
> Use FIELD_GET() to extract PCIe capability register fields instead of
> custom masking and shifting. Also remove the unnecessary cast to u8,
> the value in those fields always fits to u8.
Applied to 6.7/scsi-staging, thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2 08/10] scsi: qla2xxx: Use FIELD_GET() to extract PCIe capability fields
2023-09-13 12:27 [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
` (6 preceding siblings ...)
2023-09-13 12:27 ` [PATCH v2 07/10] scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields Ilpo Järvinen
@ 2023-09-13 12:27 ` Ilpo Järvinen
2023-09-13 13:16 ` Jonathan Cameron
2023-09-14 1:02 ` Martin K. Petersen
2023-09-13 12:27 ` [PATCH v2 09/10] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code Ilpo Järvinen
` (2 subsequent siblings)
10 siblings, 2 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2023-09-13 12:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-pci, Bjorn Helgaas, Nilesh Javali,
GR-QLogic-Storage-Upstream, James E.J. Bottomley,
Martin K. Petersen, linux-scsi, linux-kernel
Cc: Ilpo Järvinen
Use FIELD_GET() to extract PCIe capability registers field instead of
custom masking and shifting.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/scsi/qla2xxx/qla_os.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 50db08265c51..7e103d711825 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -5,6 +5,7 @@
*/
#include "qla_def.h"
+#include <linux/bitfield.h>
#include <linux/moduleparam.h>
#include <linux/vmalloc.h>
#include <linux/delay.h>
@@ -633,8 +634,8 @@ qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
const char *speed_str;
pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
- lspeed = lstat & PCI_EXP_LNKCAP_SLS;
- lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
+ lspeed = FIELD_GET(PCI_EXP_LNKCAP_SLS, lstat);
+ lwidth = FIELD_GET(PCI_EXP_LNKCAP_MLW, lstat);
switch (lspeed) {
case 1:
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v2 08/10] scsi: qla2xxx: Use FIELD_GET() to extract PCIe capability fields
2023-09-13 12:27 ` [PATCH v2 08/10] scsi: qla2xxx: " Ilpo Järvinen
@ 2023-09-13 13:16 ` Jonathan Cameron
2023-09-14 1:02 ` Martin K. Petersen
1 sibling, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2023-09-13 13:16 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: linux-pci, Bjorn Helgaas, Nilesh Javali,
GR-QLogic-Storage-Upstream, James E.J. Bottomley,
Martin K. Petersen, linux-scsi, linux-kernel
On Wed, 13 Sep 2023 15:27:46 +0300
Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> wrote:
> Use FIELD_GET() to extract PCIe capability registers field instead of
> custom masking and shifting.
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/scsi/qla2xxx/qla_os.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
> index 50db08265c51..7e103d711825 100644
> --- a/drivers/scsi/qla2xxx/qla_os.c
> +++ b/drivers/scsi/qla2xxx/qla_os.c
> @@ -5,6 +5,7 @@
> */
> #include "qla_def.h"
>
> +#include <linux/bitfield.h>
> #include <linux/moduleparam.h>
> #include <linux/vmalloc.h>
> #include <linux/delay.h>
> @@ -633,8 +634,8 @@ qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
> const char *speed_str;
>
> pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
> - lspeed = lstat & PCI_EXP_LNKCAP_SLS;
> - lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
> + lspeed = FIELD_GET(PCI_EXP_LNKCAP_SLS, lstat);
> + lwidth = FIELD_GET(PCI_EXP_LNKCAP_MLW, lstat);
>
> switch (lspeed) {
> case 1:
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH v2 08/10] scsi: qla2xxx: Use FIELD_GET() to extract PCIe capability fields
2023-09-13 12:27 ` [PATCH v2 08/10] scsi: qla2xxx: " Ilpo Järvinen
2023-09-13 13:16 ` Jonathan Cameron
@ 2023-09-14 1:02 ` Martin K. Petersen
1 sibling, 0 replies; 19+ messages in thread
From: Martin K. Petersen @ 2023-09-14 1:02 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Jonathan Cameron, linux-pci, Bjorn Helgaas, Nilesh Javali,
GR-QLogic-Storage-Upstream, James E.J. Bottomley,
Martin K. Petersen, linux-scsi, linux-kernel
Ilpo,
> Use FIELD_GET() to extract PCIe capability registers field instead of
> custom masking and shifting.
Applied to 6.7/scsi-staging, thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2 09/10] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code
2023-09-13 12:27 [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
` (7 preceding siblings ...)
2023-09-13 12:27 ` [PATCH v2 08/10] scsi: qla2xxx: " Ilpo Järvinen
@ 2023-09-13 12:27 ` Ilpo Järvinen
2023-09-13 13:17 ` Jonathan Cameron
2023-09-13 12:27 ` [PATCH v2 10/10] e1000e: Use pcie_capability_read_word() for reading LNKSTA Ilpo Järvinen
2023-09-22 1:05 ` (subset) [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Martin K. Petersen
10 siblings, 1 reply; 19+ messages in thread
From: Ilpo Järvinen @ 2023-09-13 12:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-pci, Bjorn Helgaas, Jesse Brandeburg,
Tony Nguyen, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, intel-wired-lan, netdev, linux-kernel
Cc: Ilpo Järvinen, Jonathan Cameron
e1000e has own copy of PCI Negotiated Link Width field defines. Use the
one from include/uapi/linux/pci_regs.h instead of the custom ones and
remove the custom ones. Also convert to use FIELD_GET().
Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/ethernet/intel/e1000e/defines.h | 2 --
drivers/net/ethernet/intel/e1000e/mac.c | 7 ++++---
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/intel/e1000e/defines.h b/drivers/net/ethernet/intel/e1000e/defines.h
index 63c3c79380a1..a4d29c9e03a6 100644
--- a/drivers/net/ethernet/intel/e1000e/defines.h
+++ b/drivers/net/ethernet/intel/e1000e/defines.h
@@ -681,8 +681,6 @@
#define PCIE_LINK_STATUS 0x12
#define PCI_HEADER_TYPE_MULTIFUNC 0x80
-#define PCIE_LINK_WIDTH_MASK 0x3F0
-#define PCIE_LINK_WIDTH_SHIFT 4
#define PHY_REVISION_MASK 0xFFFFFFF0
#define MAX_PHY_REG_ADDRESS 0x1F /* 5 bit address bus (0-0x1F) */
diff --git a/drivers/net/ethernet/intel/e1000e/mac.c b/drivers/net/ethernet/intel/e1000e/mac.c
index 5df7ad93f3d7..5340cf73778d 100644
--- a/drivers/net/ethernet/intel/e1000e/mac.c
+++ b/drivers/net/ethernet/intel/e1000e/mac.c
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 1999 - 2018 Intel Corporation. */
+#include <linux/bitfield.h>
+
#include "e1000.h"
/**
@@ -25,9 +27,8 @@ s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw)
pci_read_config_word(adapter->pdev,
cap_offset + PCIE_LINK_STATUS,
&pcie_link_status);
- bus->width = (enum e1000_bus_width)((pcie_link_status &
- PCIE_LINK_WIDTH_MASK) >>
- PCIE_LINK_WIDTH_SHIFT);
+ bus->width = (enum e1000_bus_width)FIELD_GET(PCI_EXP_LNKSTA_NLW,
+ pcie_link_status);
}
mac->ops.set_lan_id(hw);
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v2 09/10] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code
2023-09-13 12:27 ` [PATCH v2 09/10] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code Ilpo Järvinen
@ 2023-09-13 13:17 ` Jonathan Cameron
0 siblings, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2023-09-13 13:17 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: linux-pci, Bjorn Helgaas, Jesse Brandeburg, Tony Nguyen,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
intel-wired-lan, netdev, linux-kernel
On Wed, 13 Sep 2023 15:27:47 +0300
Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> wrote:
> e1000e has own copy of PCI Negotiated Link Width field defines. Use the
> one from include/uapi/linux/pci_regs.h instead of the custom ones and
> remove the custom ones. Also convert to use FIELD_GET().
>
> Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/net/ethernet/intel/e1000e/defines.h | 2 --
> drivers/net/ethernet/intel/e1000e/mac.c | 7 ++++---
> 2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/e1000e/defines.h b/drivers/net/ethernet/intel/e1000e/defines.h
> index 63c3c79380a1..a4d29c9e03a6 100644
> --- a/drivers/net/ethernet/intel/e1000e/defines.h
> +++ b/drivers/net/ethernet/intel/e1000e/defines.h
> @@ -681,8 +681,6 @@
> #define PCIE_LINK_STATUS 0x12
>
> #define PCI_HEADER_TYPE_MULTIFUNC 0x80
> -#define PCIE_LINK_WIDTH_MASK 0x3F0
> -#define PCIE_LINK_WIDTH_SHIFT 4
>
> #define PHY_REVISION_MASK 0xFFFFFFF0
> #define MAX_PHY_REG_ADDRESS 0x1F /* 5 bit address bus (0-0x1F) */
> diff --git a/drivers/net/ethernet/intel/e1000e/mac.c b/drivers/net/ethernet/intel/e1000e/mac.c
> index 5df7ad93f3d7..5340cf73778d 100644
> --- a/drivers/net/ethernet/intel/e1000e/mac.c
> +++ b/drivers/net/ethernet/intel/e1000e/mac.c
> @@ -1,6 +1,8 @@
> // SPDX-License-Identifier: GPL-2.0
> /* Copyright(c) 1999 - 2018 Intel Corporation. */
>
> +#include <linux/bitfield.h>
> +
> #include "e1000.h"
>
> /**
> @@ -25,9 +27,8 @@ s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw)
> pci_read_config_word(adapter->pdev,
> cap_offset + PCIE_LINK_STATUS,
> &pcie_link_status);
> - bus->width = (enum e1000_bus_width)((pcie_link_status &
> - PCIE_LINK_WIDTH_MASK) >>
> - PCIE_LINK_WIDTH_SHIFT);
> + bus->width = (enum e1000_bus_width)FIELD_GET(PCI_EXP_LNKSTA_NLW,
> + pcie_link_status);
> }
>
> mac->ops.set_lan_id(hw);
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2 10/10] e1000e: Use pcie_capability_read_word() for reading LNKSTA
2023-09-13 12:27 [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
` (8 preceding siblings ...)
2023-09-13 12:27 ` [PATCH v2 09/10] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code Ilpo Järvinen
@ 2023-09-13 12:27 ` Ilpo Järvinen
2023-09-13 13:22 ` Jonathan Cameron
2023-09-22 1:05 ` (subset) [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Martin K. Petersen
10 siblings, 1 reply; 19+ messages in thread
From: Ilpo Järvinen @ 2023-09-13 12:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-pci, Bjorn Helgaas, Jesse Brandeburg,
Tony Nguyen, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, intel-wired-lan, netdev, linux-kernel
Cc: Ilpo Järvinen
Use pcie_capability_read_word() for reading LNKSTA and remove the
custom define that matches to PCI_EXP_LNKSTA.
As only single user for cap_offset remains, remove it too and use
adapter->pdev->pcie_cap directly in the if condition.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/ethernet/intel/e1000e/defines.h | 1 -
drivers/net/ethernet/intel/e1000e/mac.c | 10 ++++------
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/intel/e1000e/defines.h b/drivers/net/ethernet/intel/e1000e/defines.h
index a4d29c9e03a6..23a58cada43a 100644
--- a/drivers/net/ethernet/intel/e1000e/defines.h
+++ b/drivers/net/ethernet/intel/e1000e/defines.h
@@ -678,7 +678,6 @@
/* PCI/PCI-X/PCI-EX Config space */
#define PCI_HEADER_TYPE_REGISTER 0x0E
-#define PCIE_LINK_STATUS 0x12
#define PCI_HEADER_TYPE_MULTIFUNC 0x80
diff --git a/drivers/net/ethernet/intel/e1000e/mac.c b/drivers/net/ethernet/intel/e1000e/mac.c
index 5340cf73778d..e86652a30069 100644
--- a/drivers/net/ethernet/intel/e1000e/mac.c
+++ b/drivers/net/ethernet/intel/e1000e/mac.c
@@ -18,15 +18,13 @@ s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw)
struct e1000_mac_info *mac = &hw->mac;
struct e1000_bus_info *bus = &hw->bus;
struct e1000_adapter *adapter = hw->adapter;
- u16 pcie_link_status, cap_offset;
+ u16 pcie_link_status;
- cap_offset = adapter->pdev->pcie_cap;
- if (!cap_offset) {
+ if (!adapter->pdev->pcie_cap) {
bus->width = e1000_bus_width_unknown;
} else {
- pci_read_config_word(adapter->pdev,
- cap_offset + PCIE_LINK_STATUS,
- &pcie_link_status);
+ pcie_capability_read_word(adapter->pdev, PCI_EXP_LNKSTA,
+ &pcie_link_status);
bus->width = (enum e1000_bus_width)FIELD_GET(PCI_EXP_LNKSTA_NLW,
pcie_link_status);
}
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v2 10/10] e1000e: Use pcie_capability_read_word() for reading LNKSTA
2023-09-13 12:27 ` [PATCH v2 10/10] e1000e: Use pcie_capability_read_word() for reading LNKSTA Ilpo Järvinen
@ 2023-09-13 13:22 ` Jonathan Cameron
0 siblings, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2023-09-13 13:22 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: linux-pci, Bjorn Helgaas, Jesse Brandeburg, Tony Nguyen,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
intel-wired-lan, netdev, linux-kernel
On Wed, 13 Sep 2023 15:27:48 +0300
Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> wrote:
> Use pcie_capability_read_word() for reading LNKSTA and remove the
> custom define that matches to PCI_EXP_LNKSTA.
>
> As only single user for cap_offset remains, remove it too and use
> adapter->pdev->pcie_cap directly in the if condition.
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
> drivers/net/ethernet/intel/e1000e/defines.h | 1 -
> drivers/net/ethernet/intel/e1000e/mac.c | 10 ++++------
> 2 files changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/e1000e/defines.h b/drivers/net/ethernet/intel/e1000e/defines.h
> index a4d29c9e03a6..23a58cada43a 100644
> --- a/drivers/net/ethernet/intel/e1000e/defines.h
> +++ b/drivers/net/ethernet/intel/e1000e/defines.h
> @@ -678,7 +678,6 @@
>
> /* PCI/PCI-X/PCI-EX Config space */
> #define PCI_HEADER_TYPE_REGISTER 0x0E
> -#define PCIE_LINK_STATUS 0x12
>
> #define PCI_HEADER_TYPE_MULTIFUNC 0x80
>
> diff --git a/drivers/net/ethernet/intel/e1000e/mac.c b/drivers/net/ethernet/intel/e1000e/mac.c
> index 5340cf73778d..e86652a30069 100644
> --- a/drivers/net/ethernet/intel/e1000e/mac.c
> +++ b/drivers/net/ethernet/intel/e1000e/mac.c
> @@ -18,15 +18,13 @@ s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw)
> struct e1000_mac_info *mac = &hw->mac;
> struct e1000_bus_info *bus = &hw->bus;
> struct e1000_adapter *adapter = hw->adapter;
> - u16 pcie_link_status, cap_offset;
> + u16 pcie_link_status;
>
> - cap_offset = adapter->pdev->pcie_cap;
> - if (!cap_offset) {
> + if (!adapter->pdev->pcie_cap) {
Could use pci_pcie_cap() though it'll end up longer, so not sure if it is
a good idea.
Given number of accesses to adapter->pdev, perhaps a local variable pdev, would help.
> bus->width = e1000_bus_width_unknown;
> } else {
> - pci_read_config_word(adapter->pdev,
> - cap_offset + PCIE_LINK_STATUS,
> - &pcie_link_status);
> + pcie_capability_read_word(adapter->pdev, PCI_EXP_LNKSTA,
> + &pcie_link_status);
> bus->width = (enum e1000_bus_width)FIELD_GET(PCI_EXP_LNKSTA_NLW,
> pcie_link_status);
> }
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: (subset) [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups
2023-09-13 12:27 [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
` (9 preceding siblings ...)
2023-09-13 12:27 ` [PATCH v2 10/10] e1000e: Use pcie_capability_read_word() for reading LNKSTA Ilpo Järvinen
@ 2023-09-22 1:05 ` Martin K. Petersen
10 siblings, 0 replies; 19+ messages in thread
From: Martin K. Petersen @ 2023-09-22 1:05 UTC (permalink / raw)
To: Jonathan Cameron, linux-pci, Bjorn Helgaas, Ilpo Järvinen
Cc: Martin K . Petersen, linux-kernel
On Wed, 13 Sep 2023 15:27:38 +0300, Ilpo Järvinen wrote:
> Instead of custom code to extract the PCIe capabilities, make the code
> more obvious using FIELD_GET/PREP().
>
> Also cleanup some duplicated defines in e1000e.
>
> I've only put Jonathan's Reviewed-by to patches I didn't modify
> significantly.
>
> [...]
Applied to 6.7/scsi-queue, thanks!
[07/10] scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields
https://git.kernel.org/mkp/scsi/c/5532f2495150
[08/10] scsi: qla2xxx: Use FIELD_GET() to extract PCIe capability fields
https://git.kernel.org/mkp/scsi/c/dc1d7b363301
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 19+ messages in thread