phylib MMD accessor cleanups
Subsystems (6)
Russell King - ARM Linux
reviewercover phylib MMD accessor cleanups
Hi,
This series cleans up the phylib MMD accessors. We have two accessors at present, phy_(read|write)_mmd() and phy_(read|write)_mmd_indirect()
The _indirect methods access the MMD registers via a clause 22 phy, whereas the non-_indirect methods acess via clause 45 accesses.
Current PHY-independent parts of phylib (such as EEE) access the MMD registers via the _indirect methods, which is no good if you have a clause 45 PHY that doesn't respond to clause 22 accesses.
In order to make these features available, we need to rework these accessors such that they can access the MMD registers using a method dependent on the clause that the PHY conforms with.
This series of patches does exactly that - we merge the functionality of the indirect accesses into the clause 45 accessors, and use these exclusively to access MMD registers. Internally, the new clause independent MMD accessors indirect via the PHY drivers read_mmd/write_mmd methods if present, otherwise fall back to using clause 45 accesses if the PHY is a clause 45 phy, or clause 22 indirect accesses if the PHY is clause 22.
Note: confusingly, phy_read_mmd_indirect() vs phy_read_mmd() switches the order of prtad and devad, which means that converting between the two is not a simple matter of just replacing the function name. Same applies for the write methods.
drivers/net/phy/Makefile | 2 +- drivers/net/phy/bcm-phy-lib.c | 12 ++--- drivers/net/phy/dp83867.c | 25 +++++----- drivers/net/phy/intel-xway.c | 26 +++++----- drivers/net/phy/micrel.c | 13 +++-- drivers/net/phy/microchip.c | 5 +- drivers/net/phy/phy-core.c | 101 ++++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 110 ++++-------------------------------------- drivers/net/phy/phy_device.c | 4 +- drivers/net/usb/lan78xx.c | 10 ++-- include/linux/phy.h | 80 +++++++++--------------------- 11 files changed, 178 insertions(+), 210 deletions(-)
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
RFC PATCH 1/7 net: phy: move phy MMD accessors to phy-core.c
Move the phy_(read|write)__mmd() helpers out of line, they will become our main MMD accessor functions, and so will be a little more complex. This complexity doesn't belong in an inline function. Also move the _indirect variants as well to keep like functionality together.
--- drivers/net/phy/Makefile | 2 +- drivers/net/phy/phy-core.c | 135 +++++++++++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 85 ---------------------------- include/linux/phy.h | 20 +------ 4 files changed, 138 insertions(+), 104 deletions(-) create mode 100644 drivers/net/phy/phy-core.c
drivers/net/phy/Makefile +1 -1
@@ -1,7 +1,7 @@ # Makefile for Linux PHY drivers and MDIO bus drivers libphy-y := phy.o phy_device.o mdio_bus.o mdio_device.o \ - mdio-boardinfo.o + mdio-boardinfo.o phy-core.o libphy-$(CONFIG_SWPHY) += swphy.o libphy-$(CONFIG_LED_TRIGGER_PHY) += phy_led_triggers.o
drivers/net/phy/phy-core.c new file +135 -0
135 lines not on this page · raw message
drivers/net/phy/phy.c +0 -85
91 lines not on this page · raw message
include/linux/phy.h +2 -18
@@ -651,14 +651,7 @@ struct phy_fixup {* * Same rules as for phy_read(); */ -static inline int phy_read_mmd (struct phy_device *phydev,int devad,u32 regnum) -{ -if (!phydev->is_c45) -return -EOPNOTSUPP ; - -return mdiobus_read (phydev->mdio.bus, phydev->mdio.addr, -MII_ADDR_C45 | (devad <<16 ) | (regnum &0xffff )); -} +int phy_read_mmd (struct phy_device *phydev,int devad,u32 regnum);/** * phy_read_mmd_indirect - reads data from the MMD registers
@@ -752,16 +745,7 @@ static inline bool phy_is_pseudo_fixed_link(struct phy_device *phydev)* * Same rules as for phy_write(); */ -static inline int phy_write_mmd (struct phy_device *phydev,int devad, -u32 regnum,u16 val) -{ -if (!phydev->is_c45) -return -EOPNOTSUPP ; - - regnum =MII_ADDR_C45 | ((devad &0x1f ) <<16 ) | (regnum &0xffff ); - -return mdiobus_write (phydev->mdio.bus, phydev->mdio.addr, regnum, val); -} +int phy_write_mmd (struct phy_device *phydev,int devad,u32 regnum,u16 val);/** * phy_write_mmd_indirect - writes data to the MMD registers
Signature · 1 line
2.7.4
RFC PATCH 2/7 net: phy: make phy_(read|write)_mmd() generic MMD accessors
In reply to Russell King - ARM LinuxMake phy_(read|write)_mmd() generic 802.3 clause 45 register accessors for both Clause 22 and Clause 45 PHYs, using either the direct register reading for Clause 45, or the indirect method for Clause 22 PHYs. Allow this behaviour to be overriden by PHY drivers where necessary.
--- drivers/net/phy/phy-core.c | 31 +++++++++++++++++++++++-------- include/linux/phy.h | 24 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 8 deletions(-)
drivers/net/phy/phy-core.c +23 -8
@@ -69,11 +69,18 @@ EXPORT_SYMBOL(phy_read_mmd_indirect);*/ int phy_read_mmd (struct phy_device *phydev,int devad,u32 regnum) { -if (!phydev->is_c45) -return -EOPNOTSUPP ; +if (regnum > (u16 )~0 || devad >32 ) +return -EINVAL ; -return mdiobus_read (phydev->mdio.bus, phydev->mdio.addr, -MII_ADDR_C45 | (devad <<16 ) | (regnum &0xffff )); +if (phydev->drv->read_mmd) +return phydev->drv->read_mmd (phydev, devad, regnum); + +if (phydev->is_c45) { +u32 addr =MII_ADDR_C45 | (devad <<16 ) | (regnum &0xffff ); +return mdiobus_read (phydev->mdio.bus, phydev->mdio.addr, addr); + } + +return phy_read_mmd_indirect (phydev, regnum, devad); }EXPORT_SYMBOL (phy_read_mmd);
@@ -125,11 +132,19 @@ EXPORT_SYMBOL(phy_write_mmd_indirect);*/ int phy_write_mmd (struct phy_device *phydev,int devad,u32 regnum,u16 val) { -if (!phydev->is_c45) -return -EOPNOTSUPP ; +if (regnum > (u16 )~0 || devad >32 ) +return -EINVAL ; - regnum =MII_ADDR_C45 | ((devad &0x1f ) <<16 ) | (regnum &0xffff ); +if (phydev->drv->read_mmd) +return phydev->drv->write_mmd (phydev, devad, regnum, val); + +if (phydev->is_c45) { +u32 addr =MII_ADDR_C45 | (devad <<16 ) | (regnum &0xffff ); + +return mdiobus_write (phydev->mdio.bus, phydev->mdio.addr, + addr, val); + } -return mdiobus_write (phydev->mdio.bus, phydev->mdio.addr, regnum, val); +return phy_write_mmd_indirect (phydev, regnum, devad, val); }EXPORT_SYMBOL (phy_write_mmd);
include/linux/phy.h +24 -0
@@ -587,6 +587,30 @@ struct phy_driver {*/ void (*link_change_notify)(struct phy_device *dev); +/* +* Phy specific driver override for reading a MMD register. +* This function is optional for PHY specific drivers. When +* not provided, the default MMD read function will be used +* by phy_read_mmd(), which will use either a direct read for +* Clause 45 PHYs or an indirect read for Clause 22 PHYs. +* devnum is the MMD device number within the PHY device, +* regnum is the register within the selected MMD device. +*/ +int (*read_mmd)(struct phy_device *dev,int devnum,u16 regnum); + +/* +* Phy specific driver override for writing a MMD register. +* This function is optional for PHY specific drivers. When +* not provided, the default MMD write function will be used +* by phy_write_mmd(), which will use either a direct write for +* Clause 45 PHYs, or an indirect write for Clause 22 PHYs. +* devnum is the MMD device number within the PHY device, +* regnum is the register within the selected MMD device. +* val is the value to be written. +*/ +int (*write_mmd)(struct phy_device *dev,int devnum,u16 regnum, +u16 val); +/* A function provided by a phy specific driver to override the * the PHY driver framework support for reading a MMD register * from the PHY. If not supported, return -1. This function is
Signature · 1 line
2.7.4
RFC PATCH 3/7 net: lan78xx: update for phy_(read|write)_mmd_indirect() removal
In reply to Russell King - ARM Linuxlan78xx appears to use phylib in a rather weird way, accessing the PHY partly through phylib, and partly by makign direct accesses to it, including to the Clause 45 registers. As the indirect MMD accessors are going away, update this driver to use the plain phy_(read|write)_mmd() accessors instead.
--- drivers/net/usb/lan78xx.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/usb/lan78xx.c +5 -5
@@ -1952,10 +1952,10 @@ static int lan8835_fixup(struct phy_device *phydev)struct lan78xx_net *dev =netdev_priv (phydev->attached_dev);/* LED2/PME_N/IRQ_N/RGMII_ID pin to IRQ_N mode */ - buf =phy_read_mmd_indirect (phydev,0x8010 ,3 ); + buf =phy_read_mmd (phydev,MDIO_MMD_PCS ,0x8010 ); buf &= ~0x1800 ; buf |=0x0800 ; -phy_write_mmd_indirect (phydev,0x8010 ,3 , buf); +phy_write_mmd (phydev,MDIO_MMD_PCS ,0x8010 , buf);/* RGMII MAC TXC Delay Enable */ ret = lan78xx_write_reg(dev, MAC_RGMII_ID,
@@ -1975,11 +1975,11 @@ static int ksz9031rnx_fixup(struct phy_device *phydev)/* Micrel9301RNX PHY configuration */ /* RGMII Control Signal Pad Skew */ -phy_write_mmd_indirect (phydev,4 ,2 ,0x0077 ); +phy_write_mmd (phydev,MDIO_MMD_WIS ,4 ,0x0077 );/* RGMII RX Data Pad Skew */ -phy_write_mmd_indirect (phydev,5 ,2 ,0x7777 ); +phy_write_mmd (phydev,MDIO_MMD_WIS ,5 ,0x7777 );/* RGMII RX Clock Pad Skew */ -phy_write_mmd_indirect (phydev,8 ,2 ,0x1FF ); +phy_write_mmd (phydev,MDIO_MMD_WIS ,8 ,0x1FF ); dev->interface =PHY_INTERFACE_MODE_RGMII_RXID ;
Signature · 1 line
2.7.4
A message that is not in the archive (sent off-list or not yet received): E1cpYZZ-0006Uj-8Z-eh5Bv4kxaXIk46pC+1QYvQNdhmdF6hFW@public.gmane.org
Re: [PATCH RFC 3/7] net: lan78xx: update for phy_(read|write)_mmd_indirect() removal
Quoted 2 lines · Russell King
lan78xx appears to use phylib in a rather weird way, accessing the PHY partly through phylib, and partly by makign direct accesses to it,
Hi Russell
s/makign/making
Andrew
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH RFC 3/7] net: lan78xx: update for phy_(read|write)_mmd_indirect() removal
In reply to Russell KingQuoted 7 lines
lan78xx appears to use phylib in a rather weird way, accessing the PHY partly through phylib, and partly by makign direct accesses to it, including to the Clause 45 registers. As the indirect MMD accessors are going away, update this driver to use the plain phy_(read|write)_mmd() accessors instead.
Signed-off-by Russell King <[email protected]>
RFC PATCH 4/7 net: phy: switch remaining users to phy_(read|write)_mmd()
In reply to Russell King - ARM LinuxSwitch everyone over to using phy_read_mmd() and phy_write_mmd() now that they are able to handle both Clause 22 indirect addressing and Clause 45 direct addressing methods to the MMD registers.
--- drivers/net/phy/bcm-phy-lib.c | 12 ++++-------- drivers/net/phy/dp83867.c | 25 +++++++++++-------------- drivers/net/phy/intel-xway.c | 26 +++++++++++++------------- drivers/net/phy/microchip.c | 5 ++--- drivers/net/phy/phy.c | 25 ++++++++++--------------- drivers/net/phy/phy_device.c | 4 ++-- 6 files changed, 42 insertions(+), 55 deletions(-)
drivers/net/phy/bcm-phy-lib.c +4 -8
@@ -201,8 +201,7 @@ int bcm_phy_set_eee(struct phy_device *phydev, bool enable)int val;/* Enable EEE at PHY level */ - val =phy_read_mmd_indirect (phydev,BRCM_CL45VEN_EEE_CONTROL , -MDIO_MMD_AN ); + val =phy_read_mmd (phydev,MDIO_MMD_AN ,BRCM_CL45VEN_EEE_CONTROL );if (val <0 )return val;
@@ -211,12 +210,10 @@ int bcm_phy_set_eee(struct phy_device *phydev, bool enable)else val &= ~(LPI_FEATURE_EN |LPI_FEATURE_EN_DIG1000X ); -phy_write_mmd_indirect (phydev,BRCM_CL45VEN_EEE_CONTROL , -MDIO_MMD_AN , (u32 )val); +phy_write_mmd (phydev,MDIO_MMD_AN ,BRCM_CL45VEN_EEE_CONTROL , (u32 )val);/* Advertise EEE */ - val =phy_read_mmd_indirect (phydev,BCM_CL45VEN_EEE_ADV , -MDIO_MMD_AN ); + val =phy_read_mmd (phydev,MDIO_MMD_AN ,BCM_CL45VEN_EEE_ADV );if (val <0 )return val;
@@ -225,8 +222,7 @@ int bcm_phy_set_eee(struct phy_device *phydev, bool enable)else val &= ~(MDIO_AN_EEE_ADV_100TX |MDIO_AN_EEE_ADV_1000T ); -phy_write_mmd_indirect (phydev,BCM_CL45VEN_EEE_ADV , -MDIO_MMD_AN , (u32 )val); +phy_write_mmd (phydev,MDIO_MMD_AN ,BCM_CL45VEN_EEE_ADV , (u32 )val);return 0 ; }
drivers/net/phy/dp83867.c +11 -14
@@ -133,14 +133,14 @@ static int dp83867_config_port_mirroring(struct phy_device *phydev) (struct dp83867_private *)phydev->priv;u16 val; - val =phy_read_mmd_indirect (phydev,DP83867_CFG4 ,DP83867_DEVADDR ); + val =phy_read_mmd (phydev,DP83867_DEVADDR ,DP83867_CFG4 );if (dp83867->port_mirroring ==DP83867_PORT_MIRROING_EN ) val |=DP83867_CFG4_PORT_MIRROR_EN ;else val &= ~DP83867_CFG4_PORT_MIRROR_EN ; -phy_write_mmd_indirect (phydev,DP83867_CFG4 ,DP83867_DEVADDR , val); +phy_write_mmd (phydev,DP83867_DEVADDR ,DP83867_CFG4 , val);return 0 ; }
@@ -231,8 +231,7 @@ static int dp83867_config_init(struct phy_device *phydev)* register's bit 11 (marked as RESERVED). */ - bs =phy_read_mmd_indirect (phydev,DP83867_STRAP_STS1 , -DP83867_DEVADDR ); + bs =phy_read_mmd (phydev,DP83867_DEVADDR ,DP83867_STRAP_STS1 );if (bs &DP83867_STRAP_STS1_RESERVED ) val &= ~DP83867_PHYCR_RESERVED_MASK ;
@@ -243,8 +242,7 @@ static int dp83867_config_init(struct phy_device *phydev)if ((phydev->interface >=PHY_INTERFACE_MODE_RGMII_ID ) && (phydev->interface <=PHY_INTERFACE_MODE_RGMII_RXID )) { - val =phy_read_mmd_indirect (phydev,DP83867_RGMIICTL , -DP83867_DEVADDR ); + val =phy_read_mmd (phydev,DP83867_DEVADDR ,DP83867_RGMIICTL );if (phydev->interface ==PHY_INTERFACE_MODE_RGMII_ID ) val |= (DP83867_RGMII_TX_CLK_DELAY_EN |DP83867_RGMII_RX_CLK_DELAY_EN );
@@ -255,25 +253,24 @@ static int dp83867_config_init(struct phy_device *phydev)if (phydev->interface ==PHY_INTERFACE_MODE_RGMII_RXID ) val |=DP83867_RGMII_RX_CLK_DELAY_EN ; -phy_write_mmd_indirect (phydev,DP83867_RGMIICTL , -DP83867_DEVADDR , val); +phy_write_mmd (phydev,DP83867_DEVADDR ,DP83867_RGMIICTL , val); delay = (dp83867->rx_id_delay | (dp83867->tx_id_delay <<DP83867_RGMII_TX_CLK_DELAY_SHIFT )); -phy_write_mmd_indirect (phydev,DP83867_RGMIIDCTL , -DP83867_DEVADDR , delay); +phy_write_mmd (phydev,DP83867_DEVADDR ,DP83867_RGMIIDCTL , + delay);if (dp83867->io_impedance >=0 ) { - val =phy_read_mmd_indirect (phydev,DP83867_IO_MUX_CFG , -DP83867_DEVADDR ); + val =phy_read_mmd (phydev,DP83867_DEVADDR , +DP83867_IO_MUX_CFG ); val &= ~DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL ; val |= dp83867->io_impedance &DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL ; -phy_write_mmd_indirect (phydev,DP83867_IO_MUX_CFG , -DP83867_DEVADDR , val); +phy_write_mmd (phydev,DP83867_DEVADDR , +DP83867_IO_MUX_CFG , val); } }
drivers/net/phy/intel-xway.c +13 -13
@@ -166,13 +166,13 @@ static int xway_gphy_config_init(struct phy_device *phydev)/* Clear all pending interrupts */ phy_read (phydev,XWAY_MDIO_ISTAT ); -phy_write_mmd_indirect (phydev,XWAY_MMD_LEDCH ,MDIO_MMD_VEND2 , -XWAY_MMD_LEDCH_NACS_NONE | -XWAY_MMD_LEDCH_SBF_F02HZ | -XWAY_MMD_LEDCH_FBF_F16HZ ); -phy_write_mmd_indirect (phydev,XWAY_MMD_LEDCL ,MDIO_MMD_VEND2 , -XWAY_MMD_LEDCH_CBLINK_NONE | -XWAY_MMD_LEDCH_SCAN_NONE ); +phy_write_mmd (phydev,MDIO_MMD_VEND2 ,XWAY_MMD_LEDCH , +XWAY_MMD_LEDCH_NACS_NONE | +XWAY_MMD_LEDCH_SBF_F02HZ | +XWAY_MMD_LEDCH_FBF_F16HZ ); +phy_write_mmd (phydev,MDIO_MMD_VEND2 ,XWAY_MMD_LEDCL , +XWAY_MMD_LEDCH_CBLINK_NONE | +XWAY_MMD_LEDCH_SCAN_NONE );/** * In most cases only one LED is connected to this phy, so
@@ -183,12 +183,12 @@ static int xway_gphy_config_init(struct phy_device *phydev) ledxh = XWAY_MMD_LEDxH_BLINKF_NONE | XWAY_MMD_LEDxH_CON_LINK10XX; ledxl = XWAY_MMD_LEDxL_PULSE_TXACT | XWAY_MMD_LEDxL_PULSE_RXACT | XWAY_MMD_LEDxL_BLINKS_NONE; -phy_write_mmd_indirect (phydev,XWAY_MMD_LED0H ,MDIO_MMD_VEND2 , ledxh); -phy_write_mmd_indirect (phydev,XWAY_MMD_LED0L ,MDIO_MMD_VEND2 , ledxl); -phy_write_mmd_indirect (phydev,XWAY_MMD_LED1H ,MDIO_MMD_VEND2 , ledxh); -phy_write_mmd_indirect (phydev,XWAY_MMD_LED1L ,MDIO_MMD_VEND2 , ledxl); -phy_write_mmd_indirect (phydev,XWAY_MMD_LED2H ,MDIO_MMD_VEND2 , ledxh); -phy_write_mmd_indirect (phydev,XWAY_MMD_LED2L ,MDIO_MMD_VEND2 , ledxl); +phy_write_mmd (phydev,MDIO_MMD_VEND2 ,XWAY_MMD_LED0H , ledxh); +phy_write_mmd (phydev,MDIO_MMD_VEND2 ,XWAY_MMD_LED0L , ledxl); +phy_write_mmd (phydev,MDIO_MMD_VEND2 ,XWAY_MMD_LED1H , ledxh); +phy_write_mmd (phydev,MDIO_MMD_VEND2 ,XWAY_MMD_LED1L , ledxl); +phy_write_mmd (phydev,MDIO_MMD_VEND2 ,XWAY_MMD_LED2H , ledxh); +phy_write_mmd (phydev,MDIO_MMD_VEND2 ,XWAY_MMD_LED2L , ledxl);return 0 ; }
drivers/net/phy/microchip.c +2 -3
@@ -78,9 +78,8 @@ static int lan88xx_probe(struct phy_device *phydev) priv->wolopts =0 ;/* these values can be used to identify internal PHY */ - priv->chip_id =phy_read_mmd_indirect (phydev,LAN88XX_MMD3_CHIP_ID ,3 ); - priv->chip_rev =phy_read_mmd_indirect (phydev,LAN88XX_MMD3_CHIP_REV , -3 ); + priv->chip_id =phy_read_mmd (phydev,3 ,LAN88XX_MMD3_CHIP_ID ); + priv->chip_rev =phy_read_mmd (phydev,3 ,LAN88XX_MMD3_CHIP_REV ); phydev->priv = priv;
drivers/net/phy/phy.c +10 -15
@@ -1227,8 +1227,7 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)return status;/* First check if the EEE ability is supported */ - eee_cap =phy_read_mmd_indirect (phydev,MDIO_PCS_EEE_ABLE , -MDIO_MMD_PCS ); + eee_cap =phy_read_mmd (phydev,MDIO_MMD_PCS ,MDIO_PCS_EEE_ABLE );if (eee_cap <=0 ) goto eee_exit_err;
@@ -1239,13 +1238,11 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)/* Check which link settings negotiated and verify it in * the EEE advertising registers. */ - eee_lp =phy_read_mmd_indirect (phydev,MDIO_AN_EEE_LPABLE , -MDIO_MMD_AN ); + eee_lp =phy_read_mmd (phydev,MDIO_MMD_AN ,MDIO_AN_EEE_LPABLE );if (eee_lp <=0 ) goto eee_exit_err; - eee_adv =phy_read_mmd_indirect (phydev,MDIO_AN_EEE_ADV , -MDIO_MMD_AN ); + eee_adv =phy_read_mmd (phydev,MDIO_MMD_AN ,MDIO_AN_EEE_ADV );if (eee_adv <=0 ) goto eee_exit_err;
@@ -1258,14 +1255,12 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)/* Configure the PHY to stop receiving xMII * clock while it is signaling LPI. */ -int val =phy_read_mmd_indirect (phydev,MDIO_CTRL1 , -MDIO_MMD_PCS ); +int val =phy_read_mmd (phydev,MDIO_MMD_PCS ,MDIO_CTRL1 );if (val <0 )return val; val |=MDIO_PCS_CTRL1_CLKSTOP_EN ; -phy_write_mmd_indirect (phydev,MDIO_CTRL1 , -MDIO_MMD_PCS , val); +phy_write_mmd (phydev,MDIO_MMD_PCS ,MDIO_CTRL1 , val); }return 0 ;/* EEE supported */
@@ -1287,7 +1282,7 @@ int phy_get_eee_err(struct phy_device *phydev)if (!phydev->drv)return -EIO ; -return phy_read_mmd_indirect (phydev,MDIO_PCS_EEE_WK_ERR ,MDIO_MMD_PCS ); +return phy_read_mmd (phydev,MDIO_MMD_PCS ,MDIO_PCS_EEE_WK_ERR ); }EXPORT_SYMBOL (phy_get_eee_err);
@@ -1307,19 +1302,19 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data)return -EIO ;/* Get Supported EEE */ - val =phy_read_mmd_indirect (phydev,MDIO_PCS_EEE_ABLE ,MDIO_MMD_PCS ); + val =phy_read_mmd (phydev,MDIO_MMD_PCS ,MDIO_PCS_EEE_ABLE );if (val <0 )return val; data->supported =mmd_eee_cap_to_ethtool_sup_t (val);/* Get advertisement EEE */ - val =phy_read_mmd_indirect (phydev,MDIO_AN_EEE_ADV ,MDIO_MMD_AN ); + val =phy_read_mmd (phydev,MDIO_MMD_AN ,MDIO_AN_EEE_ADV );if (val <0 )return val; data->advertised =mmd_eee_adv_to_ethtool_adv_t (val);/* Get LP advertisement EEE */ - val =phy_read_mmd_indirect (phydev,MDIO_AN_EEE_LPABLE ,MDIO_MMD_AN ); + val =phy_read_mmd (phydev,MDIO_MMD_AN ,MDIO_AN_EEE_LPABLE );if (val <0 )return val; data->lp_advertised =mmd_eee_adv_to_ethtool_adv_t (val);
@@ -1345,7 +1340,7 @@ int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data)/* Mask prohibited EEE modes */ val &= ~phydev->eee_broken_modes; -phy_write_mmd_indirect (phydev,MDIO_AN_EEE_ADV ,MDIO_MMD_AN , val); +phy_write_mmd (phydev,MDIO_MMD_AN ,MDIO_AN_EEE_ADV , val);return 0 ; }
drivers/net/phy/phy_device.c +2 -2
@@ -1217,7 +1217,7 @@ static int genphy_config_eee_advert(struct phy_device *phydev)* supported by the phy. If we read 0, EEE is not advertised * In both case, we don't need to continue */ - adv =phy_read_mmd_indirect (phydev,MDIO_AN_EEE_ADV ,MDIO_MMD_AN ); + adv =phy_read_mmd (phydev,MDIO_MMD_AN ,MDIO_AN_EEE_ADV );if (adv <=0 )return 0 ;
@@ -1228,7 +1228,7 @@ static int genphy_config_eee_advert(struct phy_device *phydev)if (old_adv == adv)return 0 ; -phy_write_mmd_indirect (phydev,MDIO_AN_EEE_ADV ,MDIO_MMD_AN , adv); +phy_write_mmd (phydev,MDIO_MMD_AN ,MDIO_AN_EEE_ADV , adv);return 1 ; }
Signature · 1 line
2.7.4
RFC PATCH 5/7 net: phy: convert micrel to new read_mmd/write_mmd driver methods
In reply to Russell King - ARM LinuxConvert micrel to the new read_mmd/write_mmd driver methods. This Clause 22 PHY does not support any MMD access method.
--- drivers/net/phy/micrel.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/phy/micrel.c +6 -7
@@ -637,8 +637,7 @@ static int ksz8873mll_config_aneg(struct phy_device *phydev)* MMD extended PHY registers. */ static int -ksz9021_rd_mmd_phyreg (struct phy_device *phydev,int ptrad,int devnum, -int regnum) +ksz9021_rd_mmd_phyreg (struct phy_device *phydev,int devad,u16 regnum) {return -1 ; }
@@ -646,10 +645,10 @@ ksz9021_rd_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum,/* This routine does nothing since the Micrel ksz9021 does not support * standard IEEE MMD extended PHY registers. */ -static void -ksz9021_wr_mmd_phyreg (struct phy_device *phydev,int ptrad,int devnum, -int regnum,u32 val) +static int +ksz9021_wr_mmd_phyreg (struct phy_device *phydev,int devad,u16 regnum,u16 val) { +return -1 ; }static int kszphy_get_sset_count (struct phy_device *phydev)
@@ -962,8 +961,8 @@ static struct phy_driver ksphy_driver[] = { .get_stats = kszphy_get_stats, .suspend = genphy_suspend, .resume = genphy_resume, - .read_mmd_indirect = ksz9021_rd_mmd_phyreg, - .write_mmd_indirect = ksz9021_wr_mmd_phyreg, + .read_mmd = ksz9021_rd_mmd_phyreg, + .write_mmd = ksz9021_wr_mmd_phyreg, }, { .phy_id = PHY_ID_KSZ9031, .phy_id_mask = MICREL_PHY_ID_MASK,
Signature · 1 line
2.7.4
RFC PATCH 6/7 net: phy: remove the indirect MMD read/write methods
In reply to Russell King - ARM LinuxRemove the indirect MMD read/write methods which are now no longer necessary.
--- drivers/net/phy/phy-core.c | 119 +++++++++++++-------------------------------- include/linux/phy.h | 42 ---------------- 2 files changed, 35 insertions(+), 126 deletions(-)
drivers/net/phy/phy-core.c +35 -84
@@ -23,102 +23,41 @@ static inline void mmd_phy_indirect(struct mii_bus *bus, int prtad, int devad, }/** -* phy_read_mmd_indirect - reads data from the MMD registers -* @phydev: The PHY device bus -* @prtad: MMD Address -* @devad: MMD DEVAD -* -* Description: it reads data from the MMD registers (clause 22 to access to -* clause 45) of the specified phy address. -* To read these register we have: -* 1) Write reg 13 // DEVAD -* 2) Write reg 14 // MMD Address -* 3) Write reg 13 // MMD Data Command for MMD DEVAD -* 3) Read reg 14 // Read MMD data -*/ -int phy_read_mmd_indirect (struct phy_device *phydev,int prtad,int devad) -{ -struct phy_driver *phydrv = phydev->drv; -int addr = phydev->mdio.addr; -int value =-1 ; - -if (!phydrv->read_mmd_indirect) { -struct mii_bus *bus = phydev->mdio.bus; - -mutex_lock (&bus->mdio_lock); -mmd_phy_indirect (bus, prtad, devad, addr); - -/* Read the content of the MMD's selected register */ - value = bus->read (bus, addr,MII_MMD_DATA ); -mutex_unlock (&bus->mdio_lock); - }else { - value = phydrv->read_mmd_indirect (phydev, prtad, devad, addr); - } -return value; -} -EXPORT_SYMBOL (phy_read_mmd_indirect); - -/** * phy_read_mmd - Convenience function for reading a register * from an MMD on a given PHY. * @phydev: The phy_device struct -* @devad: The MMD to read from -* @regnum: The register on the MMD to read +* @devad: The MMD to read from (0..31) +* @regnum: The register on the MMD to read (0..65535) * * Same rules as for phy_read(); */ int phy_read_mmd (struct phy_device *phydev,int devad,u32 regnum) { +int val; +if (regnum > (u16 )~0 || devad >32 )return -EINVAL ; -if (phydev->drv->read_mmd) -return phydev->drv->read_mmd (phydev, devad, regnum); - -if (phydev->is_c45) { +if (phydev->drv->read_mmd) { + val = phydev->drv->read_mmd (phydev, devad, regnum); + }else if (phydev->is_c45) {u32 addr =MII_ADDR_C45 | (devad <<16 ) | (regnum &0xffff ); -return mdiobus_read (phydev->mdio.bus, phydev->mdio.addr, addr); - } - -return phy_read_mmd_indirect (phydev, regnum, devad); -} -EXPORT_SYMBOL (phy_read_mmd); - -/** -* phy_write_mmd_indirect - writes data to the MMD registers -* @phydev: The PHY device -* @prtad: MMD Address -* @devad: MMD DEVAD -* @data: data to write in the MMD register -* -* Description: Write data from the MMD registers of the specified -* phy address. -* To write these register we have: -* 1) Write reg 13 // DEVAD -* 2) Write reg 14 // MMD Address -* 3) Write reg 13 // MMD Data Command for MMD DEVAD -* 3) Write reg 14 // Write MMD data -*/ -void phy_write_mmd_indirect (struct phy_device *phydev,int prtad, -int devad,u32 data) -{ -struct phy_driver *phydrv = phydev->drv; -int addr = phydev->mdio.addr; -if (!phydrv->write_mmd_indirect) { + val =mdiobus_read (phydev->mdio.bus, phydev->mdio.addr, addr); + }else {struct mii_bus *bus = phydev->mdio.bus; +int phy_addr = phydev->mdio.addr;mutex_lock (&bus->mdio_lock); -mmd_phy_indirect (bus, prtad, devad, addr); +mmd_phy_indirect (bus, regnum, devad, phy_addr); -/* Write the data into MMD's selected register */ - bus->write (bus, addr,MII_MMD_DATA , data); +/* Read the content of the MMD's selected register */ + val = bus->read (bus, phy_addr,MII_MMD_DATA );mutex_unlock (&bus->mdio_lock); - }else { - phydrv->write_mmd_indirect (phydev, prtad, devad, addr, data); } +return val; } -EXPORT_SYMBOL (phy_write_mmd_indirect); +EXPORT_SYMBOL (phy_read_mmd);/** * phy_write_mmd - Convenience function for writing a register
@@ -132,19 +71,31 @@ EXPORT_SYMBOL(phy_write_mmd_indirect);*/ int phy_write_mmd (struct phy_device *phydev,int devad,u32 regnum,u16 val) { +int ret; +if (regnum > (u16 )~0 || devad >32 )return -EINVAL ; -if (phydev->drv->read_mmd) -return phydev->drv->write_mmd (phydev, devad, regnum, val); - -if (phydev->is_c45) { +if (phydev->drv->read_mmd) { + ret = phydev->drv->write_mmd (phydev, devad, regnum, val); + }else if (phydev->is_c45) {u32 addr =MII_ADDR_C45 | (devad <<16 ) | (regnum &0xffff ); -return mdiobus_write (phydev->mdio.bus, phydev->mdio.addr, - addr, val); - } + ret =mdiobus_write (phydev->mdio.bus, phydev->mdio.addr, + addr, val); + }else { +struct mii_bus *bus = phydev->mdio.bus; +int phy_addr = phydev->mdio.addr; -return phy_write_mmd_indirect (phydev, regnum, devad, val); +mutex_lock (&bus->mdio_lock); +mmd_phy_indirect (bus, regnum, devad, phy_addr); + +/* Write the data into MMD's selected register */ + bus->write (bus, phy_addr,MII_MMD_DATA , val); +mutex_unlock (&bus->mdio_lock); + + ret =0 ; + } +return ret; }EXPORT_SYMBOL (phy_write_mmd);
include/linux/phy.h +0 -42
60 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH 7/7 net: phy: clean up mmd_phy_indirect()
In reply to Russell King - ARM LinuxMake mmd_phy_indirect() use the same terminology as the rest of the code, making clear what each address is - phy address, devad, and register number.
While here, remove the "inline" from this static function, leaving it to the compiler to decide whether to inline this function, and get rid of unnecessary parens.
--- drivers/net/phy/phy-core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/net/phy/phy-core.c +7 -7
@@ -9,17 +9,17 @@#include <linux/export.h> #include <linux/phy.h> -static inline void mmd_phy_indirect (struct mii_bus *bus,int prtad,int devad, -int addr) +static void mmd_phy_indirect (struct mii_bus *bus,int phy_addr,int devad, +u16 regnum) {/* Write the desired MMD Devad */ - bus->write (bus, addr,MII_MMD_CTRL , devad); + bus->write (bus, phy_addr,MII_MMD_CTRL , devad);/* Write the desired MMD register address */ - bus->write (bus, addr,MII_MMD_DATA , prtad); + bus->write (bus, phy_addr,MII_MMD_DATA , regnum);/* Select the Function : DATA with no post increment */ - bus->write (bus, addr,MII_MMD_CTRL , (devad |MII_MMD_CTRL_NOINCR )); + bus->write (bus, phy_addr,MII_MMD_CTRL , devad |MII_MMD_CTRL_NOINCR ); }/**
@@ -49,7 +49,7 @@ int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)int phy_addr = phydev->mdio.addr;mutex_lock (&bus->mdio_lock); -mmd_phy_indirect (bus, regnum, devad, phy_addr); +mmd_phy_indirect (bus, phy_addr, devad, regnum);/* Read the content of the MMD's selected register */ val = bus->read (bus, phy_addr,MII_MMD_DATA );
@@ -88,7 +88,7 @@ int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)int phy_addr = phydev->mdio.addr;mutex_lock (&bus->mdio_lock); -mmd_phy_indirect (bus, regnum, devad, phy_addr); +mmd_phy_indirect (bus, phy_addr, devad, regnum);/* Write the data into MMD's selected register */ bus->write (bus, phy_addr,MII_MMD_DATA , val);
Signature · 1 line
2.7.4
Quoted 24 lines · Russell King - ARM Linux
Hi,
This series cleans up the phylib MMD accessors. We have two accessors at present, phy_(read|write)_mmd() and phy_(read|write)_mmd_indirect()
The
_indirectmethods access the MMD registers via a clause 22 phy, whereas the non-_indirect methods acess via clause 45 accesses.Current PHY-independent parts of phylib (such as EEE) access the MMD registers via the
_indirectmethods, which is no good if you have a clause 45 PHY that doesn't respond to clause 22 accesses.In order to make these features available, we need to rework these accessors such that they can access the MMD registers using a method dependent on the clause that the PHY conforms with.
This series of patches does exactly that - we merge the functionality of the indirect accesses into the clause 45 accessors, and use these exclusively to access MMD registers. Internally, the new clause independent MMD accessors indirect via the PHY drivers read_mmd/write_mmd methods if present, otherwise fall back to using clause 45 accesses if the PHY is a clause 45 phy, or clause 22 indirect accesses if the PHY is clause 22.
Quoted 4 lines
Note: confusingly,
phy_read_mmd_indirect()vsphy_read_mmd()switches the order of prtad and devad, which means that converting between the two is not a simple matter of just replacing the function name. Same applies for the write methods.
Hi Russell
This all looks good, apart from the one typo i spotted.
Andrew
Quoted 16 lines · Russell King - ARM Linux
Hi,
This series cleans up the phylib MMD accessors. We have two accessors at present, phy_(read|write)_mmd() and phy_(read|write)_mmd_indirect()
The
_indirectmethods access the MMD registers via a clause 22 phy, whereas the non-_indirect methods acess via clause 45 accesses.Current PHY-independent parts of phylib (such as EEE) access the MMD registers via the
_indirectmethods, which is no good if you have a clause 45 PHY that doesn't respond to clause 22 accesses.In order to make these features available, we need to rework these accessors such that they can access the MMD registers using a method dependent on the clause that the PHY conforms with.
Quoted 7 lines
This series of patches does exactly that - we merge the functionality of the indirect accesses into the clause 45 accessors, and use these exclusively to access MMD registers. Internally, the new clause independent MMD accessors indirect via the PHY drivers read_mmd/write_mmd methods if present, otherwise fall back to using clause 45 accesses if the PHY is a clause 45 phy, or clause 22 indirect accesses if the PHY is clause 22.
LGTM:
Quoted 19 lines
Note: confusingly,
phy_read_mmd_indirect()vsphy_read_mmd()switches the order of prtad and devad, which means that converting between the two is not a simple matter of just replacing the function name. Same applies for the write methods.drivers/net/phy/Makefile | 2 +- drivers/net/phy/bcm-phy-lib.c | 12 ++--- drivers/net/phy/dp83867.c | 25 +++++----- drivers/net/phy/intel-xway.c | 26 +++++----- drivers/net/phy/micrel.c | 13 +++-- drivers/net/phy/microchip.c | 5 +- drivers/net/phy/phy-core.c | 101 ++++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 110 ++++-------------------------------------- drivers/net/phy/phy_device.c | 4 +- drivers/net/usb/lan78xx.c | 10 ++-- include/linux/phy.h | 80 +++++++++--------------------- 11 files changed, 178 insertions(+), 210 deletions(-)
Signature · 1 line
Florian
A message that is not in the archive (sent off-list or not yet received): 0b44bbd9-2be9-85cb-1518-4e4ec36927e1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 9 lines · Florian Fainelli
Quoted 7 lines · Russell King - ARM Linux
This series of patches does exactly that - we merge the functionality of the indirect accesses into the clause 45 accessors, and use these exclusively to access MMD registers. Internally, the new clause independent MMD accessors indirect via the PHY drivers read_mmd/write_mmd methods if present, otherwise fall back to using clause 45 accesses if the PHY is a clause 45 phy, or clause 22 indirect accesses if the PHY is clause 22.
Quoted 3 lines
LGTM:
Reviewed-by Florian Fainelli <[email protected]>
Thanks. When I posted this last time around (19th Jan) I mentioned about marking the old _indirect() accessors with __deprecated - is that still something we want to do?
I haven't tested this against net-next yet, so I don't know if there are any new users of the indirect accessors - going down the deprecated route would avoid breakage, but means having to submit a patch later to actually remove them.
How would people want this handled?
Signature · 7 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Andrew Lunn
maintainerQuoted 10 lines
Thanks. When I posted this last time around (19th Jan) I mentioned about marking the old
_indirect()accessors with__deprecated- is that still something we want to do?I haven't tested this against net-next yet, so I don't know if there are any new users of the indirect accessors - going down the deprecated route would avoid breakage, but means having to submit a patch later to actually remove them.
How would people want this handled?
Hi Russell
We can get patches into net-next very quickly. So i suggest you rebase and resubmit and get it in. If something breaks, we add followup patches to fix it.
Andrew