linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups
@ 2023-09-19 12:56 Ilpo Järvinen
  2023-09-19 12:56 ` [PATCH v3 1/8] RDMA/hfi1: Use FIELD_GET() to extract Link Width Ilpo Järvinen
                   ` (10 more replies)
  0 siblings, 11 replies; 14+ messages in thread
From: Ilpo Järvinen @ 2023-09-19 12:56 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Jonathan Cameron
  Cc: linux-kernel, Ilpo Järvinen

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.

This is just a step into the right direction, there's plenty of places
still to cleanup which will have to wait for another patch series.

v3:
- Remove applied patches (scsi)
- Use pci_pcie_cap() and tweak local variable (e1000e)
- Use the correct prefix for RDMA/hfi1

v2:
- Remove extract_width() and use FIELD_GET() directly (IB/hfi1)
- Convert other fields beside Link Width ones
- Remove useless u8 casts (scsi: esas2r)
- e1000e:
        - Remove defines that duplicate pci_regs.h ones
        - Convert to pcie_capability_read_word()


Ilpo Järvinen (8):
  RDMA/hfi1: Use FIELD_GET() to extract Link Width
  media: cobalt: Use FIELD_GET() to extract Link Width
  igb: Use FIELD_GET() to extract Link Width
  PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields
  PCI: mvebu: Use FIELD_PREP() with Link Width
  PCI: Use FIELD_GET() to extract Link Width
  e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom
    defines/code
  e1000e: Use pcie_capability_read_word() for reading LNKSTA

 drivers/infiniband/hw/hfi1/pcie.c           |  9 ++-------
 drivers/media/pci/cobalt/cobalt-driver.c    | 11 ++++++-----
 drivers/net/ethernet/intel/e1000e/defines.h |  3 ---
 drivers/net/ethernet/intel/e1000e/mac.c     | 18 ++++++++----------
 drivers/net/ethernet/intel/igb/e1000_mac.c  |  6 +++---
 drivers/pci/controller/dwc/pcie-tegra194.c  |  9 ++++-----
 drivers/pci/controller/pci-mvebu.c          |  2 +-
 drivers/pci/pci-sysfs.c                     |  5 ++---
 drivers/pci/pci.c                           |  6 +++---
 9 files changed, 29 insertions(+), 40 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3 1/8] RDMA/hfi1: Use FIELD_GET() to extract Link Width
  2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
@ 2023-09-19 12:56 ` Ilpo Järvinen
  2023-09-19 13:11   ` Dean Luick
  2023-09-19 12:56 ` [PATCH v3 2/8] media: cobalt: " Ilpo Järvinen
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 14+ messages in thread
From: Ilpo Järvinen @ 2023-09-19 12:56 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Jonathan Cameron, 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>
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);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 2/8] media: cobalt: Use FIELD_GET() to extract Link Width
  2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
  2023-09-19 12:56 ` [PATCH v3 1/8] RDMA/hfi1: Use FIELD_GET() to extract Link Width Ilpo Järvinen
@ 2023-09-19 12:56 ` Ilpo Järvinen
  2023-09-19 12:56 ` [PATCH v3 3/8] igb: " Ilpo Järvinen
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Ilpo Järvinen @ 2023-09-19 12:56 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Jonathan Cameron, Hans Verkuil,
	Mauro Carvalho Chehab, linux-media, linux-kernel
  Cc: Ilpo Järvinen

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] 14+ messages in thread

* [PATCH v3 3/8] igb: Use FIELD_GET() to extract Link Width
  2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
  2023-09-19 12:56 ` [PATCH v3 1/8] RDMA/hfi1: Use FIELD_GET() to extract Link Width Ilpo Järvinen
  2023-09-19 12:56 ` [PATCH v3 2/8] media: cobalt: " Ilpo Järvinen
@ 2023-09-19 12:56 ` Ilpo Järvinen
  2023-09-19 12:56 ` [PATCH v3 4/8] PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields Ilpo Järvinen
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Ilpo Järvinen @ 2023-09-19 12:56 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Jonathan Cameron, Jesse Brandeburg,
	Tony Nguyen, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, intel-wired-lan, netdev, linux-kernel
  Cc: Ilpo Järvinen

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] 14+ messages in thread

* [PATCH v3 4/8] PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields
  2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
                   ` (2 preceding siblings ...)
  2023-09-19 12:56 ` [PATCH v3 3/8] igb: " Ilpo Järvinen
@ 2023-09-19 12:56 ` Ilpo Järvinen
  2023-09-19 12:56 ` [PATCH v3 5/8] PCI: mvebu: Use FIELD_PREP() with Link Width Ilpo Järvinen
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Ilpo Järvinen @ 2023-09-19 12:56 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Jonathan Cameron, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Thierry Reding,
	Jonathan Hunter, linux-tegra, linux-kernel
  Cc: Ilpo Järvinen

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] 14+ messages in thread

* [PATCH v3 5/8] PCI: mvebu: Use FIELD_PREP() with Link Width
  2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
                   ` (3 preceding siblings ...)
  2023-09-19 12:56 ` [PATCH v3 4/8] PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields Ilpo Järvinen
@ 2023-09-19 12:56 ` Ilpo Järvinen
  2023-09-19 12:56 ` [PATCH v3 6/8] PCI: Use FIELD_GET() to extract " Ilpo Järvinen
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Ilpo Järvinen @ 2023-09-19 12:56 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Jonathan Cameron, Thomas Petazzoni,
	Pali Rohár, Lorenzo Pieralisi, Krzysztof Wilczyński,
	Rob Herring, linux-arm-kernel, linux-kernel
  Cc: Ilpo Järvinen

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] 14+ messages in thread

* [PATCH v3 6/8] PCI: Use FIELD_GET() to extract Link Width
  2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
                   ` (4 preceding siblings ...)
  2023-09-19 12:56 ` [PATCH v3 5/8] PCI: mvebu: Use FIELD_PREP() with Link Width Ilpo Järvinen
@ 2023-09-19 12:56 ` Ilpo Järvinen
  2023-09-19 12:56 ` [PATCH v3 7/8] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code Ilpo Järvinen
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Ilpo Järvinen @ 2023-09-19 12:56 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Jonathan Cameron, linux-kernel
  Cc: Ilpo Järvinen

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] 14+ messages in thread

* [PATCH v3 7/8] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code
  2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
                   ` (5 preceding siblings ...)
  2023-09-19 12:56 ` [PATCH v3 6/8] PCI: Use FIELD_GET() to extract " Ilpo Järvinen
@ 2023-09-19 12:56 ` Ilpo Järvinen
  2023-09-19 12:56 ` [PATCH v3 8/8] e1000e: Use pcie_capability_read_word() for reading LNKSTA Ilpo Järvinen
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Ilpo Järvinen @ 2023-09-19 12:56 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Jonathan Cameron, Jesse Brandeburg,
	Tony Nguyen, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, intel-wired-lan, netdev, linux-kernel
  Cc: Ilpo Järvinen

e1000e has own copy of PCI Negotiated Link Width field defines. Use the
ones from include/uapi/linux/pci_regs.h instead of the custom ones and
remove the custom ones and convert to 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);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 8/8] e1000e: Use pcie_capability_read_word() for reading LNKSTA
  2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
                   ` (6 preceding siblings ...)
  2023-09-19 12:56 ` [PATCH v3 7/8] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code Ilpo Järvinen
@ 2023-09-19 12:56 ` Ilpo Järvinen
  2023-09-19 13:27   ` Jonathan Cameron
  2023-09-20  7:31 ` (subset) [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Leon Romanovsky
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 14+ messages in thread
From: Ilpo Järvinen @ 2023-09-19 12:56 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Jonathan Cameron, 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, replace it with a call to
pci_pcie_cap(). Instead of e1000_adapter, make local variable out of
pci_dev because both users are interested in it.

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     | 11 ++++-------
 2 files changed, 4 insertions(+), 8 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..694a779e718d 100644
--- a/drivers/net/ethernet/intel/e1000e/mac.c
+++ b/drivers/net/ethernet/intel/e1000e/mac.c
@@ -17,16 +17,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;
+	struct pci_dev *pdev = hw->adapter->pdev;
+	u16 pcie_link_status;
 
-	cap_offset = adapter->pdev->pcie_cap;
-	if (!cap_offset) {
+	if (!pci_pcie_cap(pdev)) {
 		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(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] 14+ messages in thread

* Re: [PATCH v3 1/8] RDMA/hfi1: Use FIELD_GET() to extract Link Width
  2023-09-19 12:56 ` [PATCH v3 1/8] RDMA/hfi1: Use FIELD_GET() to extract Link Width Ilpo Järvinen
@ 2023-09-19 13:11   ` Dean Luick
  0 siblings, 0 replies; 14+ messages in thread
From: Dean Luick @ 2023-09-19 13:11 UTC (permalink / raw)
  To: Ilpo Järvinen, Bjorn Helgaas, linux-pci, Jonathan Cameron,
	Dennis Dalessandro, Jason Gunthorpe, Leon Romanovsky, linux-rdma,
	linux-kernel

On 9/19/2023 7:56 AM, Ilpo Järvinen 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 ++-------

Reviewed-by: Dean Luick <dean.luick@cornelisnetworks.com>


External recipient

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 8/8] e1000e: Use pcie_capability_read_word() for reading LNKSTA
  2023-09-19 12:56 ` [PATCH v3 8/8] e1000e: Use pcie_capability_read_word() for reading LNKSTA Ilpo Järvinen
@ 2023-09-19 13:27   ` Jonathan Cameron
  0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2023-09-19 13:27 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Bjorn Helgaas, linux-pci, Jesse Brandeburg, Tony Nguyen,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	intel-wired-lan, netdev, linux-kernel

On Tue, 19 Sep 2023 15:56: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, replace it with a call to
> pci_pcie_cap(). Instead of e1000_adapter, make local variable out of
> pci_dev because both users are interested in it.
> 
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
LGTM
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/net/ethernet/intel/e1000e/defines.h |  1 -
>  drivers/net/ethernet/intel/e1000e/mac.c     | 11 ++++-------
>  2 files changed, 4 insertions(+), 8 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..694a779e718d 100644
> --- a/drivers/net/ethernet/intel/e1000e/mac.c
> +++ b/drivers/net/ethernet/intel/e1000e/mac.c
> @@ -17,16 +17,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;
> +	struct pci_dev *pdev = hw->adapter->pdev;
> +	u16 pcie_link_status;
>  
> -	cap_offset = adapter->pdev->pcie_cap;
> -	if (!cap_offset) {
> +	if (!pci_pcie_cap(pdev)) {
>  		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(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] 14+ messages in thread

* Re: (subset) [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups
  2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
                   ` (7 preceding siblings ...)
  2023-09-19 12:56 ` [PATCH v3 8/8] e1000e: Use pcie_capability_read_word() for reading LNKSTA Ilpo Järvinen
@ 2023-09-20  7:31 ` Leon Romanovsky
  2023-09-20  7:32 ` Leon Romanovsky
  2023-10-10 20:38 ` Bjorn Helgaas
  10 siblings, 0 replies; 14+ messages in thread
From: Leon Romanovsky @ 2023-09-20  7:31 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Jonathan Cameron, Ilpo Järvinen
  Cc: linux-kernel


On Tue, 19 Sep 2023 15:56:40 +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.
> 
> This is just a step into the right direction, there's plenty of places
> still to cleanup which will have to wait for another patch series.
> 
> [...]

Applied, thanks!

[1/8] RDMA/hfi1: Use FIELD_GET() to extract Link Width
      https://git.kernel.org/rdma/rdma/c/8bf7187d978610

Best regards,
-- 
Leon Romanovsky <leon@kernel.org>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups
  2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
                   ` (8 preceding siblings ...)
  2023-09-20  7:31 ` (subset) [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Leon Romanovsky
@ 2023-09-20  7:32 ` Leon Romanovsky
  2023-10-10 20:38 ` Bjorn Helgaas
  10 siblings, 0 replies; 14+ messages in thread
From: Leon Romanovsky @ 2023-09-20  7:32 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Bjorn Helgaas, linux-pci, Jonathan Cameron, linux-kernel

On Tue, Sep 19, 2023 at 03:56:40PM +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.
> 
> This is just a step into the right direction, there's plenty of places
> still to cleanup which will have to wait for another patch series.
> 
> v3:
> - Remove applied patches (scsi)
> - Use pci_pcie_cap() and tweak local variable (e1000e)
> - Use the correct prefix for RDMA/hfi1
> 
> v2:
> - Remove extract_width() and use FIELD_GET() directly (IB/hfi1)
> - Convert other fields beside Link Width ones
> - Remove useless u8 casts (scsi: esas2r)
> - e1000e:
>         - Remove defines that duplicate pci_regs.h ones
>         - Convert to pcie_capability_read_word()
> 
> 
> Ilpo Järvinen (8):
>   RDMA/hfi1: Use FIELD_GET() to extract Link Width

Applied this patch to RDMA tree.

Thanks

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups
  2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
                   ` (9 preceding siblings ...)
  2023-09-20  7:32 ` Leon Romanovsky
@ 2023-10-10 20:38 ` Bjorn Helgaas
  10 siblings, 0 replies; 14+ messages in thread
From: Bjorn Helgaas @ 2023-10-10 20:38 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Bjorn Helgaas, linux-pci, Jonathan Cameron, linux-kernel

On Tue, Sep 19, 2023 at 03:56:40PM +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.
> 
> This is just a step into the right direction, there's plenty of places
> still to cleanup which will have to wait for another patch series.
> 
> v3:
> - Remove applied patches (scsi)
> - Use pci_pcie_cap() and tweak local variable (e1000e)
> - Use the correct prefix for RDMA/hfi1
> 
> v2:
> - Remove extract_width() and use FIELD_GET() directly (IB/hfi1)
> - Convert other fields beside Link Width ones
> - Remove useless u8 casts (scsi: esas2r)
> - e1000e:
>         - Remove defines that duplicate pci_regs.h ones
>         - Convert to pcie_capability_read_word()
> 
> 
> Ilpo Järvinen (8):
>   RDMA/hfi1: Use FIELD_GET() to extract Link Width
>   media: cobalt: Use FIELD_GET() to extract Link Width
>   igb: Use FIELD_GET() to extract Link Width

>   PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields
>   PCI: mvebu: Use FIELD_PREP() with Link Width
>   PCI: Use FIELD_GET() to extract Link Width

Applied these three drivers/pci patches to pci/field-get for v6.7,
thanks!

>   e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom
>     defines/code
>   e1000e: Use pcie_capability_read_word() for reading LNKSTA
> 
>  drivers/infiniband/hw/hfi1/pcie.c           |  9 ++-------
>  drivers/media/pci/cobalt/cobalt-driver.c    | 11 ++++++-----
>  drivers/net/ethernet/intel/e1000e/defines.h |  3 ---
>  drivers/net/ethernet/intel/e1000e/mac.c     | 18 ++++++++----------
>  drivers/net/ethernet/intel/igb/e1000_mac.c  |  6 +++---
>  drivers/pci/controller/dwc/pcie-tegra194.c  |  9 ++++-----
>  drivers/pci/controller/pci-mvebu.c          |  2 +-
>  drivers/pci/pci-sysfs.c                     |  5 ++---
>  drivers/pci/pci.c                           |  6 +++---
>  9 files changed, 29 insertions(+), 40 deletions(-)
> 
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-10-10 20:38 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-19 12:56 [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Ilpo Järvinen
2023-09-19 12:56 ` [PATCH v3 1/8] RDMA/hfi1: Use FIELD_GET() to extract Link Width Ilpo Järvinen
2023-09-19 13:11   ` Dean Luick
2023-09-19 12:56 ` [PATCH v3 2/8] media: cobalt: " Ilpo Järvinen
2023-09-19 12:56 ` [PATCH v3 3/8] igb: " Ilpo Järvinen
2023-09-19 12:56 ` [PATCH v3 4/8] PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields Ilpo Järvinen
2023-09-19 12:56 ` [PATCH v3 5/8] PCI: mvebu: Use FIELD_PREP() with Link Width Ilpo Järvinen
2023-09-19 12:56 ` [PATCH v3 6/8] PCI: Use FIELD_GET() to extract " Ilpo Järvinen
2023-09-19 12:56 ` [PATCH v3 7/8] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code Ilpo Järvinen
2023-09-19 12:56 ` [PATCH v3 8/8] e1000e: Use pcie_capability_read_word() for reading LNKSTA Ilpo Järvinen
2023-09-19 13:27   ` Jonathan Cameron
2023-09-20  7:31 ` (subset) [PATCH v3 0/8] PCI/treewide: PCIe capability access cleanups Leon Romanovsky
2023-09-20  7:32 ` Leon Romanovsky
2023-10-10 20:38 ` Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).