amd-xgbe: add support for AMD Crater
Subsystems (3)
Raju Rangoju
maintainercover 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 pci_{read/write}_* calls instead
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 | 142 +++++++++++++++----- drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 85 +++++++++--- drivers/net/ethernet/amd/xgbe/xgbe.h | 11 ++ 4 files changed, 185 insertions(+), 58 deletions(-)
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH 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.
--- 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 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 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 =get_mmd_address (pdata, mmd_reg); + +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 =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); +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 =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 =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 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 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.
--- drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 79 ++++++++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 6 ++ 2 files changed, 85 insertions(+)
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +79 -0
@@ -11,6 +11,7 @@#include <linux/bitrev.h> #include <linux/crc32.h> #include <linux/crc32poly.h> +#include <linux/pci.h> #include "xgbe.h" #include "xgbe-common.h"
@@ -1066,6 +1067,78 @@ static void 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; +struct pci_dev *rdev; +unsigned long flags; +int mmd_data; + + rdev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (0 ,0 )); +if (!rdev) +return 0 ; + + mmd_address =get_mmd_address (pdata, mmd_reg); + +get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + +spin_lock_irqsave (&pdata->xpcs_lock, flags); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , pdata->xphy_base + offset); +pci_read_config_dword (rdev,0x64 , &mmd_data); + mmd_data = (offset %4 ) ?FIELD_GET (XGBE_GEN_HI_MASK , mmd_data) : +FIELD_GET (XGBE_GEN_LO_MASK , mmd_data); + +pci_dev_put (rdev); +spin_unlock_irqrestore (&pdata->xpcs_lock, flags); + +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 *rdev; +unsigned long flags; + + rdev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (0 ,0 )); +if (!rdev) +return ; + + mmd_address =get_mmd_address (pdata, mmd_reg); + +get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + +spin_lock_irqsave (&pdata->xpcs_lock, flags); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , pdata->xphy_base + offset); +pci_read_config_dword (rdev,0x64 , &pci_mmd_data); + +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; + +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + offset)); +pci_write_config_dword (rdev,0x64 , pci_mmd_data); +pci_dev_put (rdev); + +spin_unlock_irqrestore (&pdata->xpcs_lock, flags); +} +static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad,int mmd_reg) {
@@ -1160,6 +1233,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); } }
@@ -1173,6 +1249,9 @@ static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,case XGBE_XPCS_ACCESS_V2 :default :return xgbe_write_mmd_regs_v2 (pdata, prtad, mmd_reg, mmd_data); + +case XGBE_XPCS_ACCESS_V3 : +return xgbe_write_mmd_regs_v3 (pdata, prtad, mmd_reg, mmd_data); } }
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 xphy_base;/* Version related data */ struct xgbe_version_data *vdata;
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH 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.
--- drivers/net/ethernet/amd/xgbe/xgbe-common.h | 5 ++++ drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 32 +++++++++++++++------ drivers/net/ethernet/amd/xgbe/xgbe.h | 1 + 3 files changed, 30 insertions(+), 8 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 +24 -8
@@ -98,14 +98,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 +181,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 ;
@@ -190,10 +194,22 @@ static int xgbe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) pdata->xpcs_window_def_reg =PCS_V2_WINDOW_DEF ; pdata->xpcs_window_sel_reg =PCS_V2_WINDOW_SELECT ; } -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->xphy_base =PCS_RN_SMN_BASE_ADDR + port_addr_size; + + address = pdata->xphy_base + (pdata->xpcs_window_def_reg); +pci_write_config_dword (rdev,0x60 , address); +pci_read_config_dword (rdev,0x64 , ®); + }else { + reg =XPCS32_IOREAD (pdata, pdata->xpcs_window_def_reg); + } + +pci_dev_put (rdev); 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 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
@@ -387,6 +387,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 ,
@@ -424,6 +440,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
Re: [PATCH net-next 1/5] amd-xgbe: reorganize the code of XPCS access
In reply to Raju RangojuQuoted 4 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.
Overall seems reasonable, but the new functions are missing the xgbe_ prefix, contrary to other in this file.
Quoted 114 lines
Signed-off-by Raju Rangoju <[email protected]>--- 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 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 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 =get_mmd_address (pdata, mmd_reg); + +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 =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); +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 =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 =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
Re: [PATCH net-next 2/5] amd-xgbe: reorganize the xgbe_pci_probe() code path
In reply to Raju RangojuQuoted 4 lines · Raju Rangoju
Reorganize the
xgbe_pci_probe()code path to convert if/else statements to switch case to help add future code. This helps code look cleaner.Signed-off-by Raju Rangoju <[email protected]>
Quoted 70 lines
--- 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
Re: [PATCH net-next 3/5] amd-xgbe: add support for new XPCS routines
In reply to Raju RangojuQuoted 27 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.
Signed-off-by Raju Rangoju <[email protected]>--- drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 79 ++++++++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 6 ++ 2 files changed, 85 insertions(+)drivers/net/ethernet/amd/xgbe/xgbe-dev.c +2
-0@@ -11,6 +11,7 @@#include <linux/bitrev.h> #include <linux/crc32.h> #include <linux/crc32poly.h> +#include <linux/pci.h> #include "xgbe.h" #include "xgbe-common.h" @@ -1066,6 +1067,78 @@ static void 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,
drivers/net/ethernet/amd/xgbe/xgbe-dev.c static void get_pcs_index_and_offset(struct xgbe_prv_data *pdata, · line 1080
Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +10
-0+ int mmd_reg) +{ +unsigned int mmd_address, index, offset; +struct pci_dev *rdev; +unsigned long flags; +int mmd_data; + + rdev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (0 ,0 )); +if (!rdev) +return 0 ;
Why do you operate on the root device's config space? Is this SoC-specific, like in ixgbe_x550em_a_has_mii()? If so, would be nice to have a comment or at least something in the commit message.
Quoted 119 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +67
-0+ + mmd_address =get_mmd_address (pdata, mmd_reg); + +get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + +spin_lock_irqsave (&pdata->xpcs_lock, flags); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , pdata->xphy_base + offset); +pci_read_config_dword (rdev,0x64 , &mmd_data); + mmd_data = (offset %4 ) ?FIELD_GET (XGBE_GEN_HI_MASK , mmd_data) : +FIELD_GET (XGBE_GEN_LO_MASK , mmd_data); + +pci_dev_put (rdev); +spin_unlock_irqrestore (&pdata->xpcs_lock, flags); + +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 *rdev; +unsigned long flags; + + rdev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (0 ,0 )); +if (!rdev) +return ; + + mmd_address =get_mmd_address (pdata, mmd_reg); + +get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + +spin_lock_irqsave (&pdata->xpcs_lock, flags); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , pdata->xphy_base + offset); +pci_read_config_dword (rdev,0x64 , &pci_mmd_data); + +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; + +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + offset)); +pci_write_config_dword (rdev,0x64 , pci_mmd_data); +pci_dev_put (rdev); + +spin_unlock_irqrestore (&pdata->xpcs_lock, flags); +} +static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad,int mmd_reg) {@@ -1160,6 +1233,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); } }@@ -1173,6 +1249,9 @@ static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,case XGBE_XPCS_ACCESS_V2 :default :return xgbe_write_mmd_regs_v2 (pdata, prtad, mmd_reg, mmd_data); + +case XGBE_XPCS_ACCESS_V3 : +return xgbe_write_mmd_regs_v3 (pdata, prtad, mmd_reg, mmd_data); } }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 xphy_base;/* Version related data */ struct xgbe_version_data *vdata;Signature · 1 line
2.34.1
Rangoju, Raju
maintainerRe: [PATCH net-next 3/5] amd-xgbe: add support for new XPCS routines
Quoted 27 lines · Larysa Zaremba
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.
Signed-off-by Raju Rangoju <[email protected]>--- drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 79 ++++++++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 6 ++ 2 files changed, 85 insertions(+)drivers/net/ethernet/amd/xgbe/xgbe-dev.c +1
-0@@ -11,6 +11,7 @@#include <linux/bitrev.h> #include <linux/crc32.h> #include <linux/crc32poly.h> +#include <linux/pci.h> #include "xgbe.h" #include "xgbe-common.h" @@ -1066,6 +1067,78 @@ static void get_pcs_index_and_offset(struct xgbe_prv_data *pdata, *offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); }
Quoted 15 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c static void get_pcs_index_and_offset(struct xgbe_prv_data *pdata, · line 1080
Quoted 11 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +11
-0+static int xgbe_read_mmd_regs_v3 (struct xgbe_prv_data *pdata,int prtad, +int mmd_reg) +{ +unsigned int mmd_address, index, offset; +struct pci_dev *rdev; +unsigned long flags; +int mmd_data; + + rdev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (0 ,0 )); +if (!rdev) +return 0 ;Why do you operate on the root device's config space? Is this SoC-specific, like in
ixgbe_x550em_a_has_mii()? If so, would be nice to have a comment or at least something in the commit message.
Yes. We have additional patches in development that follow this path, and I'll ensure that future patches include relevant comments to clarify this.
Quoted 120 lines
Quoted 120 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +67
-0+ + mmd_address =get_mmd_address (pdata, mmd_reg); + +get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + +spin_lock_irqsave (&pdata->xpcs_lock, flags); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , pdata->xphy_base + offset); +pci_read_config_dword (rdev,0x64 , &mmd_data); + mmd_data = (offset %4 ) ?FIELD_GET (XGBE_GEN_HI_MASK , mmd_data) : +FIELD_GET (XGBE_GEN_LO_MASK , mmd_data); + +pci_dev_put (rdev); +spin_unlock_irqrestore (&pdata->xpcs_lock, flags); + +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 *rdev; +unsigned long flags; + + rdev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (0 ,0 )); +if (!rdev) +return ; + + mmd_address =get_mmd_address (pdata, mmd_reg); + +get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + +spin_lock_irqsave (&pdata->xpcs_lock, flags); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , pdata->xphy_base + offset); +pci_read_config_dword (rdev,0x64 , &pci_mmd_data); + +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; + +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + offset)); +pci_write_config_dword (rdev,0x64 , pci_mmd_data); +pci_dev_put (rdev); + +spin_unlock_irqrestore (&pdata->xpcs_lock, flags); +} +static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad,int mmd_reg) {@@ -1160,6 +1233,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); } }@@ -1173,6 +1249,9 @@ static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,case XGBE_XPCS_ACCESS_V2 :default :return xgbe_write_mmd_regs_v2 (pdata, prtad, mmd_reg, mmd_data); + +case XGBE_XPCS_ACCESS_V3 : +return xgbe_write_mmd_regs_v3 (pdata, prtad, mmd_reg, mmd_data); } }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 xphy_base;/* Version related data */ struct xgbe_version_data *vdata;Signature · 1 line
2.34.1
Rangoju, Raju
maintainerRe: [PATCH net-next 1/5] amd-xgbe: reorganize the code of XPCS access
In reply to Larysa ZarembaQuoted 8 lines · Larysa Zaremba
Quoted 4 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.Overall seems reasonable, but the new functions are missing the
xgbe_prefix, contrary to other in this file.
Thank you for your observation. We have additional patches in development that follow this path, and I'll take care of this in the future patches that follow.
Quoted 115 lines
Quoted 115 lines
Signed-off-by Raju Rangoju <[email protected]>--- 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 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 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 =get_mmd_address (pdata, mmd_reg); + +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 =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); +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 =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 =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
Re: [PATCH net-next 3/5] amd-xgbe: add support for new XPCS routines
In reply to Raju RangojuQuoted 33 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.
Signed-off-by Raju Rangoju <[email protected]>--- drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 79 ++++++++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 6 ++ 2 files changed, 85 insertions(+)drivers/net/ethernet/amd/xgbe/xgbe-dev.c +8
-0@@ -11,6 +11,7 @@#include <linux/bitrev.h> #include <linux/crc32.h> #include <linux/crc32poly.h> +#include <linux/pci.h> #include "xgbe.h" #include "xgbe-common.h" @@ -1066,6 +1067,78 @@ static void 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; +struct pci_dev *rdev; +unsigned long flags; +int mmd_data;
drivers/net/ethernet/amd/xgbe/xgbe-dev.c static void get_pcs_index_and_offset(struct xgbe_prv_data *pdata, · line 1086
Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +10
-0+ + rdev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (0 ,0 )); +if (!rdev) +return 0 ; + + mmd_address =get_mmd_address (pdata, mmd_reg); + +get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + +spin_lock_irqsave (&pdata->xpcs_lock, flags);
These PCI config accesses can race with other drivers performing SMN accesses. You'll need to make use of the AMD SMN API (see arch/x86/kernel/amd_node.c, amd_smn_{read,write}()) to ensure protection.
The AMD SMN API uses a mutex to sync access, if you need to protect these accesses with a spinlock then you are looking at updating the AMD SMN API, too.
Thanks,
Tom
Quoted 109 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +61
-0+pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , pdata->xphy_base + offset); +pci_read_config_dword (rdev,0x64 , &mmd_data); + mmd_data = (offset %4 ) ?FIELD_GET (XGBE_GEN_HI_MASK , mmd_data) : +FIELD_GET (XGBE_GEN_LO_MASK , mmd_data); + +pci_dev_put (rdev); +spin_unlock_irqrestore (&pdata->xpcs_lock, flags); + +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 *rdev; +unsigned long flags; + + rdev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (0 ,0 )); +if (!rdev) +return ; + + mmd_address =get_mmd_address (pdata, mmd_reg); + +get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + +spin_lock_irqsave (&pdata->xpcs_lock, flags); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , pdata->xphy_base + offset); +pci_read_config_dword (rdev,0x64 , &pci_mmd_data); + +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; + +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + offset)); +pci_write_config_dword (rdev,0x64 , pci_mmd_data); +pci_dev_put (rdev); + +spin_unlock_irqrestore (&pdata->xpcs_lock, flags); +} +static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad,int mmd_reg) {@@ -1160,6 +1233,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); } }@@ -1173,6 +1249,9 @@ static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,case XGBE_XPCS_ACCESS_V2 :default :return xgbe_write_mmd_regs_v2 (pdata, prtad, mmd_reg, mmd_data); + +case XGBE_XPCS_ACCESS_V3 : +return xgbe_write_mmd_regs_v3 (pdata, prtad, mmd_reg, mmd_data); } }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 xphy_base;/* Version related data */ struct xgbe_version_data *vdata;
Rangoju, Raju
maintainerRe: [PATCH net-next 3/5] amd-xgbe: add support for new XPCS routines
Quoted 40 lines · Tom Lendacky
Quoted 39 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.
Signed-off-by Raju Rangoju <[email protected]>--- drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 79 ++++++++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 6 ++ 2 files changed, 85 insertions(+)drivers/net/ethernet/amd/xgbe/xgbe-dev.c +14
-0@@ -11,6 +11,7 @@#include <linux/bitrev.h> #include <linux/crc32.h> #include <linux/crc32poly.h> +#include <linux/pci.h> #include "xgbe.h" #include "xgbe-common.h" @@ -1066,6 +1067,78 @@ static void 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; +struct pci_dev *rdev; +unsigned long flags; +int mmd_data; + + rdev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (0 ,0 )); +if (!rdev) +return 0 ; + + mmd_address =get_mmd_address (pdata, mmd_reg);
Quoted 9 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c static void get_pcs_index_and_offset(struct xgbe_prv_data *pdata, · line 1086
Quoted 4 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +4
-0+ +get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + +spin_lock_irqsave (&pdata->xpcs_lock, flags);These PCI config accesses can race with other drivers performing SMN accesses. You'll need to make use of the AMD SMN API (see
arch/x86/kernel/amd_node.c, amd_smn_{read,write}()) to ensure protection.
Thank you for your observations, Tom. Initially the patch series was using AMD SMN APIs. However, there were problems when accessing these routines from atomic context.
Quoted 3 lines
The AMD SMN API uses a mutex to sync access, if you need to protect these accesses with a spinlock then you are looking at updating the AMD SMN API, too.
I'm working on updating the SMN APIs to use the spinlock to allow access to these from atomic context aswell. I'll submit that patch after these patches are landed.
Quoted 113 lines
Thanks,
TomQuoted 109 lines
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +61
-0+pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , pdata->xphy_base + offset); +pci_read_config_dword (rdev,0x64 , &mmd_data); + mmd_data = (offset %4 ) ?FIELD_GET (XGBE_GEN_HI_MASK , mmd_data) : +FIELD_GET (XGBE_GEN_LO_MASK , mmd_data); + +pci_dev_put (rdev); +spin_unlock_irqrestore (&pdata->xpcs_lock, flags); + +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 *rdev; +unsigned long flags; + + rdev =pci_get_domain_bus_and_slot (0 ,0 ,PCI_DEVFN (0 ,0 )); +if (!rdev) +return ; + + mmd_address =get_mmd_address (pdata, mmd_reg); + +get_pcs_index_and_offset (pdata, mmd_address, &index, &offset); + +spin_lock_irqsave (&pdata->xpcs_lock, flags); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , pdata->xphy_base + offset); +pci_read_config_dword (rdev,0x64 , &pci_mmd_data); + +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; + +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + pdata->xpcs_window_sel_reg)); +pci_write_config_dword (rdev,0x64 , index); +pci_write_config_dword (rdev,0x60 , (pdata->xphy_base + offset)); +pci_write_config_dword (rdev,0x64 , pci_mmd_data); +pci_dev_put (rdev); + +spin_unlock_irqrestore (&pdata->xpcs_lock, flags); +} +static int xgbe_read_mmd_regs_v2 (struct xgbe_prv_data *pdata,int prtad,int mmd_reg) {@@ -1160,6 +1233,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); } }@@ -1173,6 +1249,9 @@ static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,case XGBE_XPCS_ACCESS_V2 :default :return xgbe_write_mmd_regs_v2 (pdata, prtad, mmd_reg, mmd_data); + +case XGBE_XPCS_ACCESS_V3 : +return xgbe_write_mmd_regs_v3 (pdata, prtad, mmd_reg, mmd_data); } }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 xphy_base;/* Version related data */ struct xgbe_version_data *vdata;