PCI/treewide: PCIe capability access cleanups
Subsystems (14)
v2 cover PCI/treewide: PCIe capability access cleanups
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.
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.
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 (10):
IB/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
scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields
scsi: qla2xxx: Use FIELD_GET() to extract PCIe capability fields
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 | 17 ++++++++--------- 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 +++--- drivers/scsi/esas2r/esas2r_ioctl.c | 16 ++++++---------- drivers/scsi/qla2xxx/qla_os.c | 5 +++-- 11 files changed, 38 insertions(+), 51 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/10 IB/hfi1: Use FIELD_GET() to extract Link Width
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().
--- drivers/infiniband/hw/hfi1/pcie.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/infiniband/hw/hfi1/pcie.c +2 -7
@@ -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);
Signature · 1 line
2.30.2
Re: [PATCH v2 01/10] IB/hfi1: Use FIELD_GET() to extract Link Width
Quoted 5 lines · On Wed, 13 Sep 2023 15:27:39 +0300 Ilpo Järvinen…
Use
FIELD_GET()to extract PCIe Negotiated Link Width field instead of custom masking and shifting, and removeextract_width()which only wraps thatFIELD_GET().Signed-off-by Ilpo Järvinen <[email protected]>
Quoted 38 lines
--- drivers/infiniband/hw/hfi1/pcie.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)drivers/infiniband/hw/hfi1/pcie.c +2
-7@@ -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);
PATCH v2 2/10 media: cobalt: Use FIELD_GET() to extract Link Width
In reply to Ilpo JärvinenUse FIELD_GET() to extract PCIe Negotiated and Maximum Link Width fields instead of custom masking and shifting.
--- drivers/media/pci/cobalt/cobalt-driver.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/media/pci/cobalt/cobalt-driver.c +6 -5
@@ -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)
Signature · 1 line
2.30.2
PATCH v2 3/10 igb: Use FIELD_GET() to extract Link Width
In reply to Ilpo JärvinenUse 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
@@ -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
PATCH v2 4/10 PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields
In reply to Ilpo JärvinenUse 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).
--- drivers/pci/controller/dwc/pcie-tegra194.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/pci/controller/dwc/pcie-tegra194.c +4 -5
@@ -9,6 +9,7 @@* Author: Vidya Sagar <[email protected]> */ +#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 */
Signature · 1 line
2.30.2
PATCH v2 5/10 PCI: mvebu: Use FIELD_PREP() with Link Width
In reply to Ilpo Järvinenmvebu_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, ...).
--- drivers/pci/controller/pci-mvebu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pci-mvebu.c +1 -1
@@ -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. */
Signature · 1 line
2.30.2
PATCH v2 6/10 PCI: Use FIELD_GET() to extract Link Width
In reply to Ilpo JärvinenUse FIELD_GET() to extract PCIe Negotiated and Maximum Link Width fields instead of custom masking and shifting.
--- drivers/pci/pci-sysfs.c | 5 ++--- drivers/pci/pci.c | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/pci/pci-sysfs.c +2 -3
@@ -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);
drivers/pci/pci.c +3 -3
@@ -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 ; }
Signature · 1 line
2.30.2
PATCH v2 7/10 scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields
In reply to Ilpo JärvinenUse 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.
--- drivers/scsi/esas2r/esas2r_ioctl.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/scsi/esas2r/esas2r_ioctl.c +6 -10
@@ -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 ;
Signature · 1 line
2.30.2
Re: [PATCH v2 07/10] scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields
Quoted 5 lines · On Wed, 13 Sep 2023 15:27:45 +0300 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 <[email protected]>
Quoted 38 lines
--- drivers/scsi/esas2r/esas2r_ioctl.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)drivers/scsi/esas2r/esas2r_ioctl.c +6
-10@@ -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 ;
Martin K. Petersen
AppliedRe: [PATCH v2 07/10] scsi: esas2r: Use FIELD_GET() to extract PCIe capability fields
In reply to Ilpo JärvinenIlpo,
Quoted 3 lines
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!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
PATCH v2 8/10 scsi: qla2xxx: Use FIELD_GET() to extract PCIe capability fields
In reply to Ilpo JärvinenUse FIELD_GET() to extract PCIe capability registers field instead of custom masking and shifting.
--- drivers/scsi/qla2xxx/qla_os.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/qla2xxx/qla_os.c +3 -2
@@ -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 :
Signature · 1 line
2.30.2
Re: [PATCH v2 08/10] scsi: qla2xxx: Use FIELD_GET() to extract PCIe capability fields
Quoted 4 lines · On Wed, 13 Sep 2023 15:27:46 +0300 Ilpo Järvinen…
Use
FIELD_GET()to extract PCIe capability registers field instead of custom masking and shifting.Signed-off-by Ilpo Järvinen <[email protected]>
Quoted 27 lines
--- drivers/scsi/qla2xxx/qla_os.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/scsi/qla2xxx/qla_os.c +3
-2@@ -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 :
Martin K. Petersen
AppliedRe: [PATCH v2 08/10] scsi: qla2xxx: Use FIELD_GET() to extract PCIe capability fields
In reply to Ilpo JärvinenIlpo,
Quoted 2 lines
Use
FIELD_GET()to extract PCIe capability registers field instead of custom masking and shifting.
Applied to 6.7/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
PATCH v2 9/10 e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code
In reply to Ilpo Järvinene1000e 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().
--- 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
@@ -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
@@ -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
Re: [PATCH v2 09/10] e1000e: Use PCI_EXP_LNKSTA_NLW & FIELD_GET() instead of custom defines/code
Quoted 6 lines · On Wed, 13 Sep 2023 15:27:47 +0300 Ilpo Järvinen…
e1000e has own copy of PCI Negotiated Link Width field defines. Use the one from
include/uapi/linux/pci_regs.hinstead of the custom ones and remove the custom ones. Also convert to useFIELD_GET().Suggested-by Jonathan Cameron <[email protected]>Signed-off-by Ilpo Järvinen <[email protected]>
Quoted 43 lines
--- 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@@ -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@@ -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);
PATCH v2 10/10 e1000e: Use pcie_capability_read_word() for reading LNKSTA
In reply to Ilpo JärvinenUse 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.
--- drivers/net/ethernet/intel/e1000e/defines.h | 1 - drivers/net/ethernet/intel/e1000e/mac.c | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/e1000e/defines.h +0 -1
@@ -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 -6
@@ -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); }
Signature · 1 line
2.30.2
Re: [PATCH v2 10/10] e1000e: Use pcie_capability_read_word() for reading LNKSTA
Quoted 29 lines · On Wed, 13 Sep 2023 15:27:48 +0300 Ilpo Järvinen…
Use
pcie_capability_read_word()for reading LNKSTA and remove the custom define that matches toPCI_EXP_LNKSTA.As only single user for
cap_offsetremains, remove it too and useadapter->pdev->pcie_capdirectly in the if condition.Signed-off-by Ilpo Järvinen <[email protected]>--- drivers/net/ethernet/intel/e1000e/defines.h | 1 - drivers/net/ethernet/intel/e1000e/mac.c | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-)drivers/net/ethernet/intel/e1000e/defines.h +0
-1@@ -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 0x80drivers/net/ethernet/intel/e1000e/mac.c +0
-0
drivers/net/ethernet/intel/e1000e/mac.c s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw) · line 23
Quoted 9 lines
drivers/net/ethernet/intel/e1000e/mac.c +2
-3@@ -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.
Quoted 10 lines
drivers/net/ethernet/intel/e1000e/mac.c +2
-3bus->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); }
Martin K. Petersen
AppliedRe: (subset) [PATCH v2 00/10] PCI/treewide: PCIe capability access cleanups
In reply to Ilpo JärvinenQuoted 9 lines · 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.
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
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering