amd-xgbe: add support for AMD Crater
Subsystems (3)
Raju Rangoju
maintainerv2 cover amd-xgbe: add support for AMD Crater
Add support for a new AMD Ethernet device called "Crater". It has a new PCI ID, add this to the current list of supported devices in the amd-xgbe devices. Also, the BAR1 addresses cannot be used to access the PCS registers on Crater platform, use the indirect addressing via SMN instead.
Changes since v1:
- PCI config accesses can race with other drivers performing SMN accesses so, fall back to AMD SMN API to avoid race.
- add the xgbe_ prefix to new functions
Raju Rangoju (5):
amd-xgbe: reorganize the code of XPCS access
amd-xgbe: reorganize the xgbe_pci_probe() code path
amd-xgbe: add support for new XPCS routines
amd-xgbe: Add XGBE_XPCS_ACCESS_V3 support to xgbe_pci_probe()
amd-xgbe: add support for new pci device id 0x1641
drivers/net/ethernet/amd/xgbe/xgbe-common.h | 5 + drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 144 +++++++++++++++----- drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 87 +++++++++--- drivers/net/ethernet/amd/xgbe/xgbe-smn.h | 30 ++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 11 ++ 5 files changed, 220 insertions(+), 57 deletions(-) create mode 100644 drivers/net/ethernet/amd/xgbe/xgbe-smn.h
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH v2 1/5 amd-xgbe: reorganize the code of XPCS access
The xgbe_{read/write}_mmd_regs_v* functions have common code which can be moved to helper functions. Add new helper functions to calculate the mmd_address for v1/v2 of xpcs access.
---
Changes since v1:
- add the xgbe_ prefix to new functions
drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 63 ++++++++++-------------- 1 file changed, 27 insertions(+), 36 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +27 -36
@@ -1041,18 +1041,17 @@ static int xgbe_set_gpio(struct xgbe_prv_data *pdata, unsigned int gpio)return 0 ; } -static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad, -int mmd_reg) +static unsigned int xgbe_get_mmd_address (struct xgbe_prv_data *pdata,int mmd_reg) { -unsigned long flags; -unsigned int mmd_address, index, offset; -int mmd_data; - -if (mmd_reg &XGBE_ADDR_C45 ) - mmd_address = mmd_reg & ~XGBE_ADDR_C45 ; -else - mmd_address = (pdata->mdio_mmd <<16 ) | (mmd_reg &0xffff ); +return (mmd_reg &XGBE_ADDR_C45 ) ? + mmd_reg & ~XGBE_ADDR_C45 : + (pdata->mdio_mmd <<16 ) | (mmd_reg &0xffff ); +} +static void xgbe_get_pcs_index_and_offset (struct xgbe_prv_data *pdata, +unsigned int mmd_address, +unsigned int *index,unsigned int *offset) +{/* The PCS registers are accessed using mmio. The underlying * management interface uses indirect addressing to access the MMD * register sets. This requires accessing of the PCS register in two
@@ -1063,8 +1062,20 @@ static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,* offset 1 bit and reading 16 bits of data. */ mmd_address <<=1 ; - index = mmd_address & ~pdata->xpcs_window_mask; - offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); + *index = mmd_address & ~pdata->xpcs_window_mask; + *offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); +} + +static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad, +int mmd_reg) +{ +unsigned long flags; +unsigned int mmd_address, index, offset; +int mmd_data; + + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg); + +xgbe_get_pcs_index_and_offset (pdata, mmd_address, &index, &offset);spin_lock_irqsave (&pdata->xpcs_lock, flags);XPCS32_IOWRITE (pdata, pdata->xpcs_window_sel_reg, index);
@@ -1080,23 +1091,9 @@ static void xgbe_write_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,unsigned long flags;unsigned int mmd_address, index, offset; -if (mmd_reg &XGBE_ADDR_C45 ) - mmd_address = mmd_reg & ~XGBE_ADDR_C45 ; -else - mmd_address = (pdata->mdio_mmd <<16 ) | (mmd_reg &0xffff ); + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg); -/* The PCS registers are accessed using mmio. The underlying -* management interface uses indirect addressing to access the MMD -* register sets. This requires accessing of the PCS register in two -* phases, an address phase and a data phase. -* -* The mmio interface is based on 16-bit offsets and values. All -* register offsets must therefore be adjusted by left shifting the -* offset 1 bit and writing 16 bits of data. -*/ - mmd_address <<=1 ; - index = mmd_address & ~pdata->xpcs_window_mask; - offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); +xgbe_get_pcs_index_and_offset (pdata, mmd_address, &index, &offset);spin_lock_irqsave (&pdata->xpcs_lock, flags);XPCS32_IOWRITE (pdata, pdata->xpcs_window_sel_reg, index);
@@ -1111,10 +1108,7 @@ static int xgbe_read_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,unsigned int mmd_address;int mmd_data; -if (mmd_reg &XGBE_ADDR_C45 ) - mmd_address = mmd_reg & ~XGBE_ADDR_C45 ; -else - mmd_address = (pdata->mdio_mmd <<16 ) | (mmd_reg &0xffff ); + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg);/* The PCS registers are accessed using mmio. The underlying APB3 * management interface uses indirect addressing to access the MMD
@@ -1139,10 +1133,7 @@ static void xgbe_write_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,unsigned int mmd_address;unsigned long flags; -if (mmd_reg &XGBE_ADDR_C45 ) - mmd_address = mmd_reg & ~XGBE_ADDR_C45 ; -else - mmd_address = (pdata->mdio_mmd <<16 ) | (mmd_reg &0xffff ); + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg);/* The PCS registers are accessed using mmio. The underlying APB3 * management interface uses indirect addressing to access the MMD
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH v2 2/5 amd-xgbe: reorganize the xgbe_pci_probe() code path
In reply to Raju RangojuReorganize the xgbe_pci_probe() code path to convert if/else statements to switch case to help add future code. This helps code look cleaner.
--- drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 35 ++++++++++++++---------- drivers/net/ethernet/amd/xgbe/xgbe.h | 4 +++ 2 files changed, 25 insertions(+), 14 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-pci.c +21 -14
@@ -165,20 +165,27 @@ static int xgbe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)/* Set the PCS indirect addressing definition registers */ rdev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (0 ,0 )); -if (rdev && - (rdev->vendor ==PCI_VENDOR_ID_AMD ) && (rdev->device ==0x15d0 )) { - pdata->xpcs_window_def_reg =PCS_V2_RV_WINDOW_DEF ; - pdata->xpcs_window_sel_reg =PCS_V2_RV_WINDOW_SELECT ; - }else if (rdev && (rdev->vendor ==PCI_VENDOR_ID_AMD ) && - (rdev->device ==0x14b5 )) { - pdata->xpcs_window_def_reg =PCS_V2_YC_WINDOW_DEF ; - pdata->xpcs_window_sel_reg =PCS_V2_YC_WINDOW_SELECT ; - -/* Yellow Carp devices do not need cdr workaround */ - pdata->vdata->an_cdr_workaround =0 ; - -/* Yellow Carp devices do not need rrc */ - pdata->vdata->enable_rrc =0 ; +if (rdev && rdev->vendor ==PCI_VENDOR_ID_AMD ) { +switch (rdev->device) { +case XGBE_RV_PCI_DEVICE_ID : + pdata->xpcs_window_def_reg =PCS_V2_RV_WINDOW_DEF ; + pdata->xpcs_window_sel_reg =PCS_V2_RV_WINDOW_SELECT ; +break ; +case XGBE_YC_PCI_DEVICE_ID : + pdata->xpcs_window_def_reg =PCS_V2_YC_WINDOW_DEF ; + pdata->xpcs_window_sel_reg =PCS_V2_YC_WINDOW_SELECT ; + +/* Yellow Carp devices do not need cdr workaround */ + pdata->vdata->an_cdr_workaround =0 ; + +/* Yellow Carp devices do not need rrc */ + pdata->vdata->enable_rrc =0 ; +break ; +default : + pdata->xpcs_window_def_reg =PCS_V2_WINDOW_DEF ; + pdata->xpcs_window_sel_reg =PCS_V2_WINDOW_SELECT ; +break ; + } }else { pdata->xpcs_window_def_reg =PCS_V2_WINDOW_DEF ; pdata->xpcs_window_sel_reg =PCS_V2_WINDOW_SELECT ;
drivers/net/ethernet/amd/xgbe/xgbe.h +4 -0
@@ -238,6 +238,10 @@ (_src)->link_modes._sname, \ __ETHTOOL_LINK_MODE_MASK_NBITS) +/* XGBE PCI device id */ +#define XGBE_RV_PCI_DEVICE_ID 0x15d0 +#define XGBE_YC_PCI_DEVICE_ID 0x14b5 +struct xgbe_prv_data ;struct xgbe_packet_data {
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH v2 3/5 amd-xgbe: add support for new XPCS routines
In reply to Raju RangojuAdd the necessary support to enable Crater ethernet device. Since the BAR1 address cannot be used to access the XPCS registers on Crater, use the smn functions.
Some of the ethernet add-in-cards have dual PHY but share a single MDIO line (between the ports). In such cases, link inconsistencies are noticed during the heavy traffic and during reboot stress tests. Using smn calls helps avoid such race conditions.
---
- PCI config accesses can race with other drivers performing SMN accesses so, fall back to AMD SMN API to avoid race.
drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 81 ++++++++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe-smn.h | 30 +++++++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 6 ++ 3 files changed, 117 insertions(+) create mode 100644 drivers/net/ethernet/amd/xgbe/xgbe-smn.h
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +81 -0
@@ -14,6 +14,7 @@#include "xgbe.h" #include "xgbe-common.h" +#include "xgbe-smn.h" static inline unsigned int xgbe_get_max_frame (struct xgbe_prv_data *pdata) {
@@ -1066,6 +1067,80 @@ static void xgbe_get_pcs_index_and_offset(struct xgbe_prv_data *pdata, *offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); } +static int xgbe_read_mmd_regs_v3 (struct xgbe_prv_data *pdata,int prtad, +int mmd_reg) +{ +unsigned int mmd_address, index, offset; +int mmd_data; +int ret; + + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg); + +xgbe_get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + + ret =amd_smn_write (0 , (pdata->smn_base + pdata->xpcs_window_sel_reg), index); +if (ret) +return ret; + + ret =amd_smn_read (0 , pdata->smn_base + offset, &mmd_data); +if (ret) +return ret; + + mmd_data = (offset %4 ) ?FIELD_GET (XGBE_GEN_HI_MASK , mmd_data) : +FIELD_GET (XGBE_GEN_LO_MASK , mmd_data); + +return mmd_data; +} + +static void xgbe_write_mmd_regs_v3 (struct xgbe_prv_data *pdata,int prtad, +int mmd_reg,int mmd_data) +{ +unsigned int pci_mmd_data, hi_mask, lo_mask; +unsigned int mmd_address, index, offset; +struct pci_dev *dev; +int ret; + + dev = pdata->pcidev; + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg); + +xgbe_get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + + ret =amd_smn_write (0 , (pdata->smn_base + pdata->xpcs_window_sel_reg), index); +if (ret) { +pci_err (dev,"Failed to write data 0x%x\n" , index); +return ; + } + + ret =amd_smn_read (0 , pdata->smn_base + offset, &pci_mmd_data); +if (ret) { +pci_err (dev,"Failed to read data\n" ); +return ; + } + +if (offset %4 ) { + hi_mask =FIELD_PREP (XGBE_GEN_HI_MASK , mmd_data); + lo_mask =FIELD_GET (XGBE_GEN_LO_MASK , pci_mmd_data); + }else { + hi_mask =FIELD_PREP (XGBE_GEN_HI_MASK , +FIELD_GET (XGBE_GEN_HI_MASK , pci_mmd_data)); + lo_mask =FIELD_GET (XGBE_GEN_LO_MASK , mmd_data); + } + + pci_mmd_data = hi_mask | lo_mask; + + ret =amd_smn_write (0 , (pdata->smn_base + pdata->xpcs_window_sel_reg), index); +if (ret) { +pci_err (dev,"Failed to write data 0x%x\n" , index); +return ; + } + + ret =amd_smn_write (0 , (pdata->smn_base + offset), pci_mmd_data); +if (ret) { +pci_err (dev,"Failed to write data 0x%x\n" , pci_mmd_data); +return ; + } +} +static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad,int mmd_reg) {
@@ -1160,6 +1235,9 @@ static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,case XGBE_XPCS_ACCESS_V2 :default :return xgbe_read_mmd_regs_v2 (pdata, prtad, mmd_reg); + +case XGBE_XPCS_ACCESS_V3 : +return xgbe_read_mmd_regs_v3 (pdata, prtad, mmd_reg); } }
@@ -1170,6 +1248,9 @@ static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,case XGBE_XPCS_ACCESS_V1 :return xgbe_write_mmd_regs_v1 (pdata, prtad, mmd_reg, mmd_data); +case XGBE_XPCS_ACCESS_V3 : +return xgbe_write_mmd_regs_v3 (pdata, prtad, mmd_reg, mmd_data); +case XGBE_XPCS_ACCESS_V2 :default :return xgbe_write_mmd_regs_v2 (pdata, prtad, mmd_reg, mmd_data);
drivers/net/ethernet/amd/xgbe/xgbe-smn.h new file +30 -0
@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-3-Clause) +/* +* Copyright (c) 2014-2025, Advanced Micro Devices, Inc. +* Copyright (c) 2014, Synopsys, Inc. +* All rights reserved +* +* Author: Raju Rangoju <[email protected]> +*/ + +#ifndef __SMN_H__ +#define __SMN_H__ + +#ifdef CONFIG_AMD_NB + +#include <asm/amd_nb.h> + +#else + +static inline int amd_smn_write (u16 node,u32 address,u32 value) +{ +return -ENODEV ; +} + +static inline int amd_smn_read (u16 node,u32 address,u32 *value) +{ +return -ENODEV ; +} + +#endif +#endif
drivers/net/ethernet/amd/xgbe/xgbe.h +6 -0
@@ -242,6 +242,10 @@#define XGBE_RV_PCI_DEVICE_ID 0x15d0#define XGBE_YC_PCI_DEVICE_ID 0x14b5 +/* Generic low and high masks */ +#define XGBE_GEN_HI_MASK GENMASK(31, 16) +#define XGBE_GEN_LO_MASK GENMASK(15, 0) +struct xgbe_prv_data ;struct xgbe_packet_data {
@@ -460,6 +464,7 @@ enum xgbe_speed {enum xgbe_xpcs_access {XGBE_XPCS_ACCESS_V1 =0 ,XGBE_XPCS_ACCESS_V2 , +XGBE_XPCS_ACCESS_V3 , };enum xgbe_an_mode {
@@ -951,6 +956,7 @@ struct xgbe_prv_data {struct device *dev;struct platform_device *phy_platdev;struct device *phy_dev; +unsigned int smn_base;/* Version related data */ struct xgbe_version_data *vdata;
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH v2 4/5 amd-xgbe: Add XGBE_XPCS_ACCESS_V3 support to xgbe_pci_probe()
In reply to Raju RangojuA new version of XPCS access routines have been introduced, add the support to xgbe_pci_probe() to use these routines.
---
- PCI config accesses can race with other drivers performing SMN accesses so, fall back to AMD SMN API to avoid race.
drivers/net/ethernet/amd/xgbe/xgbe-common.h | 5 +++ drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 34 ++++++++++++++++----- drivers/net/ethernet/amd/xgbe/xgbe.h | 1 + 3 files changed, 33 insertions(+), 7 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-common.h +5 -0
@@ -791,6 +791,11 @@#define PCS_V2_RV_WINDOW_SELECT 0x1064#define PCS_V2_YC_WINDOW_DEF 0x18060#define PCS_V2_YC_WINDOW_SELECT 0x18064 +#define PCS_V3_RN_WINDOW_DEF 0xf8078 +#define PCS_V3_RN_WINDOW_SELECT 0xf807c + +#define PCS_RN_SMN_BASE_ADDR 0x11e00000 +#define PCS_RN_PORT_ADDR_SIZE 0x100000/* PCS register entry bit positions and sizes */ #define PCS_V2_WINDOW_DEF_OFFSET_INDEX 6
drivers/net/ethernet/amd/xgbe/xgbe-pci.c +27 -7
@@ -9,6 +9,7 @@#include <linux/device.h> #include <linux/pci.h> #include <linux/log2.h> +#include "xgbe-smn.h" #include "xgbe.h" #include "xgbe-common.h"
@@ -98,14 +99,14 @@ static int xgbe_config_irqs(struct xgbe_prv_data *pdata)static int xgbe_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) { -struct xgbe_prv_data *pdata; -struct device *dev = &pdev->dev;void __iomem *const *iomap_table; -struct pci_dev *rdev; +unsigned int port_addr_size, reg; +struct device *dev = &pdev->dev; +struct xgbe_prv_data *pdata;unsigned int ma_lo, ma_hi; -unsigned int reg; -int bar_mask; -int ret; +struct pci_dev *rdev; +int bar_mask, ret; +u32 address; pdata =xgbe_alloc_pdata (dev);if (IS_ERR (pdata)) {
@@ -181,6 +182,10 @@ static int xgbe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)/* Yellow Carp devices do not need rrc */ pdata->vdata->enable_rrc =0 ;break ; +case XGBE_RN_PCI_DEVICE_ID : + pdata->xpcs_window_def_reg =PCS_V3_RN_WINDOW_DEF ; + pdata->xpcs_window_sel_reg =PCS_V3_RN_WINDOW_SELECT ; +break ;default : pdata->xpcs_window_def_reg =PCS_V2_WINDOW_DEF ; pdata->xpcs_window_sel_reg =PCS_V2_WINDOW_SELECT ;
@@ -193,7 +198,22 @@ static int xgbe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)pci_dev_put (rdev);/* Configure the PCS indirect addressing support */ - reg =XPCS32_IOREAD (pdata, pdata->xpcs_window_def_reg); +if (pdata->vdata->xpcs_access ==XGBE_XPCS_ACCESS_V3 ) { + reg =XP_IOREAD (pdata,XP_PROP_0 ); + port_addr_size =PCS_RN_PORT_ADDR_SIZE * +XP_GET_BITS (reg,XP_PROP_0 ,PORT_ID ); + pdata->smn_base =PCS_RN_SMN_BASE_ADDR + port_addr_size; + + address = pdata->smn_base + (pdata->xpcs_window_def_reg); + ret =amd_smn_read (0 , address, ®); +if (ret) { +pci_err (pdata->pcidev,"Failed to read data\n" ); + goto err_pci_enable; + } + }else { + reg =XPCS32_IOREAD (pdata, pdata->xpcs_window_def_reg); + } + pdata->xpcs_window =XPCS_GET_BITS (reg,PCS_V2_WINDOW_DEF ,OFFSET ); pdata->xpcs_window <<=6 ; pdata->xpcs_window_size =XPCS_GET_BITS (reg,PCS_V2_WINDOW_DEF ,SIZE );
drivers/net/ethernet/amd/xgbe/xgbe.h +1 -0
@@ -241,6 +241,7 @@/* XGBE PCI device id */ #define XGBE_RV_PCI_DEVICE_ID 0x15d0#define XGBE_YC_PCI_DEVICE_ID 0x14b5 +#define XGBE_RN_PCI_DEVICE_ID 0x1630/* Generic low and high masks */ #define XGBE_GEN_HI_MASK GENMASK(31, 16)
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH v2 5/5 amd-xgbe: add support for new pci device id 0x1641
In reply to Raju RangojuAdd support for new pci device id 0x1641 to register Crater device with PCIe.
--- drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/net/ethernet/amd/xgbe/xgbe-pci.c +18 -0
@@ -391,6 +391,22 @@ static int __maybe_unused xgbe_pci_resume(struct device *dev)return ret; } +static struct xgbe_version_data xgbe_v3 = { + .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2, + .xpcs_access =XGBE_XPCS_ACCESS_V3 , + .mmc_64bit =1 , + .tx_max_fifo_size =65536 , + .rx_max_fifo_size =65536 , + .tx_tstamp_workaround =1 , + .ecc_support =1 , + .i2c_support =1 , + .irq_reissue_support =1 , + .tx_desc_prefetch =5 , + .rx_desc_prefetch =5 , + .an_cdr_workaround =0 , + .enable_rrc =0 , +}; +static struct xgbe_version_data xgbe_v2a = { .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2, .xpcs_access =XGBE_XPCS_ACCESS_V2 ,
@@ -428,6 +444,8 @@ static const struct pci_device_id xgbe_pci_table[] = { .driver_data = (kernel_ulong_t)&xgbe_v2a }, { PCI_VDEVICE(AMD, 0x1459), .driver_data = (kernel_ulong_t)&xgbe_v2b }, + { PCI_VDEVICE(AMD, 0x1641), + .driver_data = (kernel_ulong_t)&xgbe_v3 },/* Last entry must be zero */ { 0, } };
Signature · 1 line
2.34.1
Simon Horman
reviewerRe: [PATCH net-next v2 3/5] amd-xgbe: add support for new XPCS routines
In reply to Raju Rangojudrivers/net/ethernet/amd/xgbe/xgbe-dev.c
Quoted 26 lines · Raju Rangoju
Add the necessary support to enable Crater ethernet device. Since the BAR1 address cannot be used to access the XPCS registers on Crater, use the smn functions.
Some of the ethernet add-in-cards have dual PHY but share a single MDIO line (between the ports). In such cases, link inconsistencies are noticed during the heavy traffic and during reboot stress tests. Using smn calls helps avoid such race conditions.
Suggested-by Sudheesh Mavila <[email protected]>Signed-off-by Raju Rangoju <[email protected]>---
- PCI config accesses can race with other drivers performing SMN accesses so, fall back to AMD SMN API to avoid race.drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 81 ++++++++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe-smn.h | 30 +++++++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 6 ++ 3 files changed, 117 insertions(+) create mode 100644 drivers/net/ethernet/amd/xgbe/xgbe-smn.hdrivers/net/ethernet/amd/xgbe/xgbe-dev.c +0
-0@@ -14,6 +14,7 @@
Hi Raju,
I think you need the following about here:
#include <linux/pci.h>
To make sure that pci_err(), which is used elsewhere in this patch, is always defined. Building allmodconfig for arm and arm64 shows that, without this change, pci_err is not defined.
Alternatively, perhaps netdev_err can be used instead of pci_err().
Quoted 13 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +3
-0#include "xgbe.h" #include "xgbe-common.h" +#include "xgbe-smn.h" static inline unsigned int xgbe_get_max_frame (struct xgbe_prv_data *pdata) {@@ -1066,6 +1067,80 @@ static void xgbe_get_pcs_index_and_offset(struct xgbe_prv_data *pdata, *offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); } +static int xgbe_read_mmd_regs_v3 (struct xgbe_prv_data *pdata,int prtad, +int mmd_reg)
drivers/net/ethernet/amd/xgbe/xgbe-dev.c static void xgbe_get_pcs_index_and_offset(struct xgbe_prv_data *pdata, · line 1081
Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +10
-0+{ +unsigned int mmd_address, index, offset; +int mmd_data; +int ret; + + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg); + +xgbe_get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + + ret =amd_smn_write (0 , (pdata->smn_base + pdata->xpcs_window_sel_reg), index);
nit: Please line wrap to 80 columns wide or less, as is still preferred for
Networking code. Likewise elsewhere in this patch.
Flagged by checkpatch.pl --max-line-length=80
Also, the inner parentheses seem to be unnecessary.
Quoted 61 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +61
-0+if (ret) +return ret; + + ret =amd_smn_read (0 , pdata->smn_base + offset, &mmd_data); +if (ret) +return ret; + + mmd_data = (offset %4 ) ?FIELD_GET (XGBE_GEN_HI_MASK , mmd_data) : +FIELD_GET (XGBE_GEN_LO_MASK , mmd_data); + +return mmd_data; +} + +static void xgbe_write_mmd_regs_v3 (struct xgbe_prv_data *pdata,int prtad, +int mmd_reg,int mmd_data) +{ +unsigned int pci_mmd_data, hi_mask, lo_mask; +unsigned int mmd_address, index, offset; +struct pci_dev *dev; +int ret; + + dev = pdata->pcidev; + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg); + +xgbe_get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + + ret =amd_smn_write (0 , (pdata->smn_base + pdata->xpcs_window_sel_reg), index); +if (ret) { +pci_err (dev,"Failed to write data 0x%x\n" , index); +return ; + } + + ret =amd_smn_read (0 , pdata->smn_base + offset, &pci_mmd_data); +if (ret) { +pci_err (dev,"Failed to read data\n" ); +return ; + } + +if (offset %4 ) { + hi_mask =FIELD_PREP (XGBE_GEN_HI_MASK , mmd_data); + lo_mask =FIELD_GET (XGBE_GEN_LO_MASK , pci_mmd_data); + }else { + hi_mask =FIELD_PREP (XGBE_GEN_HI_MASK , +FIELD_GET (XGBE_GEN_HI_MASK , pci_mmd_data)); + lo_mask =FIELD_GET (XGBE_GEN_LO_MASK , mmd_data); + } + + pci_mmd_data = hi_mask | lo_mask; + + ret =amd_smn_write (0 , (pdata->smn_base + pdata->xpcs_window_sel_reg), index); +if (ret) { +pci_err (dev,"Failed to write data 0x%x\n" , index); +return ; + } + + ret =amd_smn_write (0 , (pdata->smn_base + offset), pci_mmd_data); +if (ret) { +pci_err (dev,"Failed to write data 0x%x\n" , pci_mmd_data); +return ; + } +}
...
drivers/net/ethernet/amd/xgbe/xgbe-smn.h line 1
Quoted 7 lines
drivers/net/ethernet/amd/xgbe/xgbe-smn.h new file +1
-0@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-3-Clause)
Checkpatch says this should be:
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-3-Clause) */
Quoted 19 lines
drivers/net/ethernet/amd/xgbe/xgbe-smn.h new file +19
-0+/* +* Copyright (c) 2014-2025, Advanced Micro Devices, Inc. +* Copyright (c) 2014, Synopsys, Inc. +* All rights reserved +* +* Author: Raju Rangoju <[email protected]> +*/ + +#ifndef __SMN_H__ +#define __SMN_H__ + +#ifdef CONFIG_AMD_NB + +#include <asm/amd_nb.h> + +#else + +static inline int amd_smn_write(u16 node, u32 address, u32 value) +{
drivers/net/ethernet/amd/xgbe/xgbe-smn.h line 30
Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe-smn.h new file +10
-0+return -ENODEV ; +} + +static inline int amd_smn_read (u16 node,u32 address,u32 *value) +{ +return -ENODEV ; +} + +#endif +#endif
It feels a little odd to provide these dummy implementation here, rather than where the real implementations are declared. But I do see where you are coming from with this approach. And I guess it is fine so long as this is the only user of this mechanism.
...
Re: [PATCH net-next v2 1/5] amd-xgbe: reorganize the code of XPCS access
In reply to Raju RangojuQuoted 50 lines · Raju Rangoju
The xgbe_{read/write}_mmd_regs_v* functions have common code which can be moved to helper functions. Add new helper functions to calculate the
mmd_addressfor v1/v2 of xpcs access.Signed-off-by Raju Rangoju <[email protected]>---
Changes since v1:
- add thexgbe_prefix to new functionsdrivers/net/ethernet/amd/xgbe/xgbe-dev.c | 63 ++++++++++-------------- 1 file changed, 27 insertions(+), 36 deletions(-)drivers/net/ethernet/amd/xgbe/xgbe-dev.c +9
-12@@ -1041,18 +1041,17 @@ static int xgbe_set_gpio(struct xgbe_prv_data *pdata, unsigned int gpio)return 0 ; } -static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad, -int mmd_reg) +static unsigned int xgbe_get_mmd_address (struct xgbe_prv_data *pdata,int mmd_reg) { -unsigned long flags; -unsigned int mmd_address, index, offset; -int mmd_data; - -if (mmd_reg &XGBE_ADDR_C45 ) - mmd_address = mmd_reg & ~XGBE_ADDR_C45 ; -else - mmd_address = (pdata->mdio_mmd <<16 ) | (mmd_reg &0xffff ); +return (mmd_reg &XGBE_ADDR_C45 ) ? + mmd_reg & ~XGBE_ADDR_C45 : + (pdata->mdio_mmd <<16 ) | (mmd_reg &0xffff ); +} +static void xgbe_get_pcs_index_and_offset (struct xgbe_prv_data *pdata, +unsigned int mmd_address, +unsigned int *index,unsigned int *offset) +{/* The PCS registers are accessed using mmio. The underlying * management interface uses indirect addressing to access the MMD * register sets. This requires accessing of the PCS register in two @@ -1063,8 +1062,20 @@ static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,* offset 1 bit and reading 16 bits of data. */ mmd_address <<=1 ; - index = mmd_address & ~pdata->xpcs_window_mask; - offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask);
drivers/net/ethernet/amd/xgbe/xgbe-dev.c static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, · line 1074
Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +10
-0+ *index = mmd_address & ~pdata->xpcs_window_mask; + *offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); +} + +static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad, +int mmd_reg) +{ +unsigned long flags; +unsigned int mmd_address, index, offset; +int mmd_data;
Please, follow reverse Xmass tree ordering
Quoted 57 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +8
-24+ + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg); + +xgbe_get_pcs_index_and_offset (pdata, mmd_address, &index, &offset);spin_lock_irqsave (&pdata->xpcs_lock, flags);XPCS32_IOWRITE (pdata, pdata->xpcs_window_sel_reg, index);@@ -1080,23 +1091,9 @@ static void xgbe_write_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,unsigned long flags;unsigned int mmd_address, index, offset; -if (mmd_reg &XGBE_ADDR_C45 ) - mmd_address = mmd_reg & ~XGBE_ADDR_C45 ; -else - mmd_address = (pdata->mdio_mmd <<16 ) | (mmd_reg &0xffff ); + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg); -/* The PCS registers are accessed using mmio. The underlying -* management interface uses indirect addressing to access the MMD -* register sets. This requires accessing of the PCS register in two -* phases, an address phase and a data phase. -* -* The mmio interface is based on 16-bit offsets and values. All -* register offsets must therefore be adjusted by left shifting the -* offset 1 bit and writing 16 bits of data. -*/ - mmd_address <<=1 ; - index = mmd_address & ~pdata->xpcs_window_mask; - offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); +xgbe_get_pcs_index_and_offset (pdata, mmd_address, &index, &offset);spin_lock_irqsave (&pdata->xpcs_lock, flags);XPCS32_IOWRITE (pdata, pdata->xpcs_window_sel_reg, index);@@ -1111,10 +1108,7 @@ static int xgbe_read_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,unsigned int mmd_address;int mmd_data; -if (mmd_reg &XGBE_ADDR_C45 ) - mmd_address = mmd_reg & ~XGBE_ADDR_C45 ; -else - mmd_address = (pdata->mdio_mmd <<16 ) | (mmd_reg &0xffff ); + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg);/* The PCS registers are accessed using mmio. The underlying APB3 * management interface uses indirect addressing to access the MMD @@ -1139,10 +1133,7 @@ static void xgbe_write_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,unsigned int mmd_address;unsigned long flags; -if (mmd_reg &XGBE_ADDR_C45 ) - mmd_address = mmd_reg & ~XGBE_ADDR_C45 ; -else - mmd_address = (pdata->mdio_mmd <<16 ) | (mmd_reg &0xffff ); + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg);/* The PCS registers are accessed using mmio. The underlying APB3 * management interface uses indirect addressing to access the MMD
kernel test robot
build botRe: [PATCH net-next v2 3/5] amd-xgbe: add support for new XPCS routines
In reply to Raju Rangojukernel test robot noticed the following build errors:
Hi Raju,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Raju-Rangoju/amd-xgbe-reorganize-the-code-of-XPCS-access/20250428-230635 base: net-next/main patch link: https://lore.kernel.org/r/20250428150235.2938110-4-Raju.Rangoju%40amd.com patch subject: [PATCH net-next v2 3/5] amd-xgbe: add support for new XPCS routines config: i386-buildonly-randconfig-002-20250429 (https://download.01.org/0day-ci/archive/20250507/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-12) 11.3.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250507/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/net/ethernet/amd/xgbe/xgbe-dev.c: In function 'xgbe_write_mmd_regs_v3':
>> drivers/net/ethernet/amd/xgbe/xgbe-dev.c:1110:17: error: implicit declaration of function 'pci_err'; did you mean 'pr_err'? [-Werror=implicit-function-declaration]
1110 | pci_err(dev, "Failed to write data 0x%x\n", index);
| ^~~~~~~
| pr_errcc1: some warnings being treated as errors
vim +1110 drivers/net/ethernet/amd/xgbe/xgbe-dev.c
1094
1095 static void xgbe_write_mmd_regs_v3(struct xgbe_prv_data *pdata, int prtad,
1096 int mmd_reg, int mmd_data)
1097 {
1098 unsigned int pci_mmd_data, hi_mask, lo_mask;
1099 unsigned int mmd_address, index, offset;
1100 struct pci_dev *dev;
1101 int ret;
1102
1103 dev = pdata->pcidev;
1104 mmd_address = xgbe_get_mmd_address(pdata, mmd_reg);
1105
1106 xgbe_get_pcs_index_and_offset(pdata, mmd_address, &index, &offset);
1107
1108 ret = amd_smn_write(0, (pdata->smn_base + pdata->xpcs_window_sel_reg), index);
1109 if (ret) {
> 1110 pci_err(dev, "Failed to write data 0x%x\n", index);
1111 return;
1112 }
1113
1114 ret = amd_smn_read(0, pdata->smn_base + offset, &pci_mmd_data);
1115 if (ret) {
1116 pci_err(dev, "Failed to read data\n");
1117 return;
1118 }
1119
1120 if (offset % 4) {
1121 hi_mask = FIELD_PREP(XGBE_GEN_HI_MASK, mmd_data);
1122 lo_mask = FIELD_GET(XGBE_GEN_LO_MASK, pci_mmd_data);
1123 } else {
1124 hi_mask = FIELD_PREP(XGBE_GEN_HI_MASK,
1125 FIELD_GET(XGBE_GEN_HI_MASK, pci_mmd_data));
1126 lo_mask = FIELD_GET(XGBE_GEN_LO_MASK, mmd_data);
1127 }
1128
1129 pci_mmd_data = hi_mask | lo_mask;
1130
1131 ret = amd_smn_write(0, (pdata->smn_base + pdata->xpcs_window_sel_reg), index);
1132 if (ret) {
1133 pci_err(dev, "Failed to write data 0x%x\n", index);
1134 return;
1135 }
1136
1137 ret = amd_smn_write(0, (pdata->smn_base + offset), pci_mmd_data);
1138 if (ret) {
1139 pci_err(dev, "Failed to write data 0x%x\n", pci_mmd_data);
1140 return;
1141 }
1142 }
1143
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Rangoju, Raju
maintainerRe: [PATCH net-next v2 3/5] amd-xgbe: add support for new XPCS routines
In reply to Simon HormanQuoted 30 lines · Simon Horman
drivers/net/ethernet/amd/xgbe/xgbe-dev.c
Quoted 26 lines · Raju Rangoju
Add the necessary support to enable Crater ethernet device. Since the BAR1 address cannot be used to access the XPCS registers on Crater, use the smn functions.
Some of the ethernet add-in-cards have dual PHY but share a single MDIO line (between the ports). In such cases, link inconsistencies are noticed during the heavy traffic and during reboot stress tests. Using smn calls helps avoid such race conditions.
Suggested-by Sudheesh Mavila <[email protected]>Signed-off-by Raju Rangoju <[email protected]>---
- PCI config accesses can race with other drivers performing SMN accesses so, fall back to AMD SMN API to avoid race.drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 81 ++++++++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe-smn.h | 30 +++++++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 6 ++ 3 files changed, 117 insertions(+)create mode 100644
drivers/net/ethernet/amd/xgbe/xgbe-smn.hdrivers/net/ethernet/amd/xgbe/xgbe-dev.c +0
-0@@ -14,6 +14,7 @@Hi Raju,
Quoted 7 lines
I think you need the following about here:
#include <
linux/pci.h>To make sure that
pci_err(), which is used elsewhere in this patch, is always defined. Building allmodconfig for arm and arm64 shows that, without this change,pci_erris not defined.
Hi Simon,
Thanks for pointing it out. Sure, will address it in v3.
Quoted 30 lines
Alternatively, perhaps
netdev_errcan be used instead ofpci_err().Quoted 13 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +3
-0#include "xgbe.h" #include "xgbe-common.h" +#include "xgbe-smn.h" static inline unsigned int xgbe_get_max_frame (struct xgbe_prv_data *pdata) {@@ -1066,6 +1067,80 @@ static void xgbe_get_pcs_index_and_offset(struct xgbe_prv_data *pdata, *offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); } +static int xgbe_read_mmd_regs_v3 (struct xgbe_prv_data *pdata,int prtad, +int mmd_reg)drivers/net/ethernet/amd/xgbe/xgbe-dev.c static void xgbe_get_pcs_index_and_offset(struct xgbe_prv_data *pdata, · line 1081
Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +10
-0+{ +unsigned int mmd_address, index, offset; +int mmd_data; +int ret; + + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg); + +xgbe_get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + + ret =amd_smn_write (0 , (pdata->smn_base + pdata->xpcs_window_sel_reg), index);nit: Please line wrap to 80 columns wide or less, as is still preferred for
Networking code. Likewise elsewhere in this patch.
Quoted 3 lines
Flagged by checkpatch.pl --max-line-length=80
Also, the inner parentheses seem to be unnecessary.
Sure, will address it in v3.
Quoted 75 lines
Quoted 62 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +61
-0+if (ret) +return ret; + + ret =amd_smn_read (0 , pdata->smn_base + offset, &mmd_data); +if (ret) +return ret; + + mmd_data = (offset %4 ) ?FIELD_GET (XGBE_GEN_HI_MASK , mmd_data) : +FIELD_GET (XGBE_GEN_LO_MASK , mmd_data); + +return mmd_data; +} + +static void xgbe_write_mmd_regs_v3 (struct xgbe_prv_data *pdata,int prtad, +int mmd_reg,int mmd_data) +{ +unsigned int pci_mmd_data, hi_mask, lo_mask; +unsigned int mmd_address, index, offset; +struct pci_dev *dev; +int ret; + + dev = pdata->pcidev; + mmd_address =xgbe_get_mmd_address (pdata, mmd_reg); + +xgbe_get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + + ret =amd_smn_write (0 , (pdata->smn_base + pdata->xpcs_window_sel_reg), index); +if (ret) { +pci_err (dev,"Failed to write data 0x%x\n" , index); +return ; + } + + ret =amd_smn_read (0 , pdata->smn_base + offset, &pci_mmd_data); +if (ret) { +pci_err (dev,"Failed to read data\n" ); +return ; + } + +if (offset %4 ) { + hi_mask =FIELD_PREP (XGBE_GEN_HI_MASK , mmd_data); + lo_mask =FIELD_GET (XGBE_GEN_LO_MASK , pci_mmd_data); + }else { + hi_mask =FIELD_PREP (XGBE_GEN_HI_MASK , +FIELD_GET (XGBE_GEN_HI_MASK , pci_mmd_data)); + lo_mask =FIELD_GET (XGBE_GEN_LO_MASK , mmd_data); + } + + pci_mmd_data = hi_mask | lo_mask; + + ret =amd_smn_write (0 , (pdata->smn_base + pdata->xpcs_window_sel_reg), index); +if (ret) { +pci_err (dev,"Failed to write data 0x%x\n" , index); +return ; + } + + ret =amd_smn_write (0 , (pdata->smn_base + offset), pci_mmd_data); +if (ret) { +pci_err (dev,"Failed to write data 0x%x\n" , pci_mmd_data); +return ; + } +}...
drivers/net/ethernet/amd/xgbe/xgbe-smn.h line 1
Quoted 7 lines
drivers/net/ethernet/amd/xgbe/xgbe-smn.h new file +1
-0@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-3-Clause) Checkpatch says this should be:
Quoted 1 line
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-3-Clause) */
Sure, will address it in v3.
Quoted 28 lines
Quoted 28 lines
drivers/net/ethernet/amd/xgbe/xgbe-smn.h new file +26
-0+/* +* Copyright (c) 2014-2025, Advanced Micro Devices, Inc. +* Copyright (c) 2014, Synopsys, Inc. +* All rights reserved +* +* Author: Raju Rangoju <[email protected]> +*/ + +#ifndef __SMN_H__ +#define __SMN_H__ + +#ifdef CONFIG_AMD_NB + +#include <asm/amd_nb.h> + +#else + +static inline int amd_smn_write (u16 node,u32 address,u32 value) +{ +return -ENODEV ; +} + +static inline int amd_smn_read (u16 node,u32 address,u32 *value) +{ +return -ENODEV ; +}
Quoted 8 lines
drivers/net/ethernet/amd/xgbe/xgbe-smn.h line 30
Quoted 3 lines
drivers/net/ethernet/amd/xgbe/xgbe-smn.h new file +3
-0+ +#endif +#endif It feels a little odd to provide these dummy implementation here, rather than where the real implementations are declared. But I do see where you are coming from with this approach. And I guess it is fine so long as this is the only user of this mechanism.
Sure, thank you.
Quoted 2 lines
...
Rangoju, Raju
maintainerRe: [PATCH net-next v2 1/5] amd-xgbe: reorganize the code of XPCS access
In reply to Vadim FedorenkoQuoted 56 lines · Vadim Fedorenko
Quoted 55 lines · Raju Rangoju
The xgbe_{read/write}_mmd_regs_v* functions have common code which can be moved to helper functions. Add new helper functions to calculate the
mmd_addressfor v1/v2 of xpcs access.Signed-off-by Raju Rangoju <[email protected]>---
Changes since v1:
- add thexgbe_prefix to new functions
drivers/net/ethernet/amd/xgbe/xgbe-dev.c| 63 ++++++++++--------------1 file changed, 27 insertions(+), 36 deletions(-)drivers/net/ethernet/amd/xgbe/xgbe-dev.c +11
-12@@ -1041,18 +1041,17 @@ static int xgbe_set_gpio(struct xgbe_prv_data *pdata, unsigned int gpio) return 0; } -static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad, - int mmd_reg) +static unsigned int xgbe_get_mmd_address (struct xgbe_prv_data *pdata,int mmd_reg) { - unsigned long flags; - unsigned int mmd_address, index, offset; - int mmd_data; - - if (mmd_reg & XGBE_ADDR_C45) - mmd_address = mmd_reg & ~XGBE_ADDR_C45; - else - mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); + return (mmd_reg & XGBE_ADDR_C45) ? + mmd_reg & ~XGBE_ADDR_C45 : + (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); +} +static void xgbe_get_pcs_index_and_offset (struct xgbe_prv_data *pdata, + unsigned int mmd_address, + unsigned int *index, unsigned int *offset) +{ /* The PCS registers are accessed using mmio. The underlying* management interface uses indirect addressing to access the MMD * register sets. This requires accessing of the PCS register in two @@ -1063,8 +1062,20 @@ static int xgbe_read_mmd_regs_v2(structxgbe_prv_data *pdata, int prtad, * offset 1 bit and reading 16 bits of data. */ mmd_address <<= 1; - index = mmd_address & ~pdata->xpcs_window_mask; - offset = pdata->xpcs_window + (mmd_address & pdata- >xpcs_window_mask); + *index = mmd_address & ~pdata->xpcs_window_mask; + *offset = pdata->xpcs_window + (mmd_address & pdata- >xpcs_window_mask);
Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, · line 1074
Quoted 8 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +8
-0+} + +static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad, + int mmd_reg) +{ + unsigned long flags; + unsigned int mmd_address, index, offset; + int mmd_data;Please, follow reverse Xmass tree ordering
Sure, will address it in v3. Thanks.
Quoted 55 lines
Quoted 54 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +4
-0+ + mmd_address = xgbe_get_mmd_address(pdata, mmd_reg); + + xgbe_get_pcs_index_and_offset(pdata, mmd_address, &index, &offset);
spin_lock_irqsave(&pdata->xpcs_lock, flags);XPCS32_IOWRITE(pdata, pdata->xpcs_window_sel_reg, index);drivers/net/ethernet/amd/xgbe/xgbe-dev.c +4
-24@@ -1080,23 +1091,9 @@ static void xgbe_write_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, unsigned long flags; unsigned int mmd_address, index, offset; - if (mmd_reg & XGBE_ADDR_C45) - mmd_address = mmd_reg & ~XGBE_ADDR_C45; - else - mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); + mmd_address = xgbe_get_mmd_address(pdata, mmd_reg); - /* The PCS registers are accessed using mmio. The underlying - * management interface uses indirect addressing to access the MMD - * register sets. This requires accessing of the PCS register in two - * phases, an address phase and a data phase. - * - * The mmio interface is based on 16-bit offsets and values. All - * register offsets must therefore be adjusted by left shifting the - * offset 1 bit and writing 16 bits of data. - */ - mmd_address <<= 1; - index = mmd_address & ~pdata->xpcs_window_mask; - offset = pdata->xpcs_window + (mmd_address & pdata- >xpcs_window_mask); + xgbe_get_pcs_index_and_offset(pdata, mmd_address, &index, &offset); spin_lock_irqsave(&pdata->xpcs_lock, flags); XPCS32_IOWRITE(pdata, pdata->xpcs_window_sel_reg, index);@@ -1111,10 +1108,7 @@ static int xgbe_read_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad, unsigned int mmd_address; int mmd_data; - if (mmd_reg & XGBE_ADDR_C45) - mmd_address = mmd_reg & ~XGBE_ADDR_C45; - else - mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); + mmd_address = xgbe_get_mmd_address(pdata, mmd_reg); /* The PCS registers are accessed using mmio. The underlying APB3* management interface uses indirect addressing to access the MMD @@ -1139,10 +1133,7 @@ static void xgbe_write_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad, unsigned int mmd_address; unsigned long flags; - if (mmd_reg & XGBE_ADDR_C45) - mmd_address = mmd_reg & ~XGBE_ADDR_C45; - else - mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); + mmd_address = xgbe_get_mmd_address(pdata, mmd_reg); /* The PCS registers are accessed using mmio. The underlying APB3* management interface uses indirect addressing to access the MMD