Skip to contentSkip to conversation

net/ethernet/intel: PCI cleanups

PATCH In review Ilpo Järvinen 4 participants 10 messages Nov 21, 2023 – Dec 10, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover net/ethernet/intel: PCI cleanups

Resending these PCI related cleanups for Intel Ethernet drivers. No other changes except removing the accepted patches in v4.

These can go through the usual driver tree as there are no PCI tree related dependencies.

v4:
- Removed accepted patches

Ilpo Järvinen (3):
igb: 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/net/ethernet/intel/e1000e/defines.h |  3 ---
 drivers/net/ethernet/intel/e1000e/mac.c     | 18 ++++++++----------
 drivers/net/ethernet/intel/igb/e1000_mac.c  |  6 +++---
 3 files changed, 11 insertions(+), 16 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v4 1/3 igb: Use FIELD_GET() to extract Link Width

Use FIELD_GET() to extract PCIe Negotiated Link Width field instead of custom masking and shifting.

---
 drivers/net/ethernet/intel/igb/e1000_mac.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/igb/e1000_mac.c +3 -3
index caf91c6f52b4..5a23b9cfec6c 100644
@@ -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);
Signature · 1 line
2.30.2
Tested-by on v4 1/3
#3 lore raw

RE: [Intel-wired-lan] [PATCH v4 1/3] igb: Use FIELD_GET() to extract Link Width

In reply to Ilpo Järvinen
Quoted 7 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Ilpo Järvinen
Sent: Tuesday, November 21, 2023 6:04 PM
To: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; [email protected]; Jakub Kicinski <[email protected]>; Brandeburg, Jesse <[email protected]>; Jonathan Cameron <[email protected]>; [email protected]; Paolo Abeni <[email protected]>; Nguyen, Anthony L <[email protected]>; [email protected]
Cc: Ilpo Järvinen <[email protected]>
Subject: [Intel-wired-lan] [PATCH v4 1/3] igb: Use FIELD_GET() to extract Link Width

Quoted 9 lines

Use FIELD_GET() to extract PCIe Negotiated Link Width field instead of custom masking and shifting.

---
 drivers/net/ethernet/intel/igb/e1000_mac.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
#4 lore raw

PATCH v4 2/3 e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code

In reply to 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().

---
 drivers/net/ethernet/intel/e1000e/defines.h | 2 --
 drivers/net/ethernet/intel/e1000e/mac.c     | 7 ++++---
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/e1000e/defines.h +0 -2
index 63c3c79380a1..a4d29c9e03a6 100644
@@ -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) */
drivers/net/ethernet/intel/e1000e/mac.c +4 -3
index 5df7ad93f3d7..5340cf73778d 100644
@@ -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);
Signature · 1 line
2.30.2
reviewer Reviewed-by on v4 2/3
#5 lore raw

Re: [PATCH v4 2/3] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code

Quoted 7 lines · 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().

Tested-by on v4 2/3
#6 lore raw

Re: [Intel-wired-lan] [PATCH v4 2/3] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code

In reply to Ilpo Järvinen
Quoted 11 lines · 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().

---
  drivers/net/ethernet/intel/e1000e/defines.h | 2 --
  drivers/net/ethernet/intel/e1000e/mac.c     | 7 ++++---
  2 files changed, 4 insertions(+), 5 deletions(-)
#7 lore raw

PATCH v4 3/3 e1000e: Use pcie_capability_read_word() for reading LNKSTA

In reply to 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.

---
 drivers/net/ethernet/intel/e1000e/defines.h |  1 -
 drivers/net/ethernet/intel/e1000e/mac.c     | 11 ++++-------
 2 files changed, 4 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/e1000e/defines.h +0 -1
index a4d29c9e03a6..23a58cada43a 100644
@@ -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
 
drivers/net/ethernet/intel/e1000e/mac.c +4 -7
index 5340cf73778d..694a779e718d 100644
@@ -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);
 	}
Signature · 1 line
2.30.2
reviewer Reviewed-by on v4 3/3
#8 lore raw

Re: [PATCH v4 3/3] e1000e: Use pcie_capability_read_word() for reading LNKSTA

Quoted 9 lines · 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.

Tested-by on v4 3/3
#9 lore raw

Re: [Intel-wired-lan] [PATCH v4 3/3] e1000e: Use pcie_capability_read_word() for reading LNKSTA

In reply to Ilpo Järvinen
Quoted 7 lines · 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.

Quoted 6 lines
---
  drivers/net/ethernet/intel/e1000e/defines.h |  1 -
  drivers/net/ethernet/intel/e1000e/mac.c     | 11 ++++-------
  2 files changed, 4 insertions(+), 8 deletions(-)