Adding PHY MDI(X) support
Subsystems (3)
PATCH v2 1/4 net: phy: add mdix_ctrl to hold the user configuration.
In reply to Raju LakkarajuFrom: Raju Lakkaraju <[email protected]>
Add new parameter mdix_ctrl to hold the user configuration. Existing mdix maintain the current status of MDI(X) crossover performed or not.mdix_ctrl can configure either ETH_TP_MDI or ETH_TP_MDI_X orETH_TP_MDI_AUTO.
--- include/linux/phy.h | 1 + 1 file changed, 1 insertion(+)
include/linux/phy.h +1 -0
@@ -447,6 +447,7 @@ struct phy_device {struct net_device *attached_dev;u8 mdix; +u8 mdix_ctrl;void (*adjust_link)(struct net_device *dev); };
Signature · 1 line
2.7.4
PATCH v2 3/4 net: phy: Add mdi(x) support in Microsemi PHYs driver
In reply to Raju LakkarajuFrom: Raju Lakkaraju <[email protected]>
To connect two ports of the same configuration (MDI to MDI or MDI-X to MDI-X) with a 10/100/1000 Mbit/s connection, an Ethernet crossover cable is needed to cross over the transmit and receive signals in the cable, so that they are matched at the connector level.
When connecting an MDI port to an MDI-X port a straight through cable is used while to connect two MDI ports or two MDI-X ports a crossover cable must be used. Conventionally MDI is used on end devices while MDI-X is used on hubs and switches
Auto MDI-X automatically detects the required cable connection type and configures the connection appropriately, removing the need for crossover cables to interconnect switches or connecting PCs peer-to-peer.
--- drivers/net/phy/mscc.c | 105 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 8 deletions(-)
drivers/net/phy/mscc.c +97 -8
@@ -27,6 +27,11 @@ enum rgmii_rx_clock_delay {/* Microsemi VSC85xx PHY registers */ /* IEEE 802. Std Registers */ +#define MSCC_PHY_BYPASS_CONTROL 18 +#define DISABLE_HP_AUTO_MDIX_MASK 0x0080 +#define DISABLE_PAIR_SWAP_CORR_MASK 0x0020 +#define DISABLE_POLARITY_CORR_MASK 0x0010 +#define MSCC_PHY_EXT_PHY_CNTL_1 23#define MAC_IF_SELECTION_MASK 0x1800#define MAC_IF_SELECTION_GMII 0
@@ -44,12 +49,20 @@ enum rgmii_rx_clock_delay {#define EDGE_RATE_CNTL_POS 5#define EDGE_RATE_CNTL_MASK 0x00E0 +#define MSCC_PHY_DEV_AUX_CNTL 28 +#define HP_AUTO_MDIX_X_OVER_IND_MASK 0x2000 +#define MSCC_EXT_PAGE_ACCESS 31#define MSCC_PHY_PAGE_STANDARD 0x0000/* Standard registers */ #define MSCC_PHY_PAGE_EXTENDED 0x0001/* Extended registers */ #define MSCC_PHY_PAGE_EXTENDED_2 0x0002/* Extended reg - page 2 */ /* Extended Page 1 Registers */ +#define MSCC_PHY_EXT_MODE_CNTL 19 +#define FORCE_MDI_CROSSOVER_MASK 0x000C +#define FORCE_MDI_CROSSOVER_MDIX 0x000C +#define FORCE_MDI_CROSSOVER_MDI 0x0008 +#define MSCC_PHY_ACTIPHY_CNTL 20#define DOWNSHIFT_CNTL_MASK 0x001C#define DOWNSHIFT_EN 0x0010
@@ -110,6 +123,59 @@ static int vsc85xx_phy_page_set(struct phy_device *phydev, u8 page)return rc; } +static int vsc85xx_mdix_get (struct phy_device *phydev,u8 *mdix) +{ +u16 reg_val; + + reg_val =phy_read (phydev,MSCC_PHY_DEV_AUX_CNTL ); +if (reg_val &HP_AUTO_MDIX_X_OVER_IND_MASK ) + *mdix =ETH_TP_MDI_X ; +else + *mdix =ETH_TP_MDI ; + +return 0 ; +} + +static int vsc85xx_mdix_set (struct phy_device *phydev,u8 mdix) +{ +int rc; +u16 reg_val; + + reg_val =phy_read (phydev,MSCC_PHY_BYPASS_CONTROL ); +if ((mdix ==ETH_TP_MDI ) || (mdix ==ETH_TP_MDI_X )) { + reg_val |= (DISABLE_PAIR_SWAP_CORR_MASK | +DISABLE_POLARITY_CORR_MASK | +DISABLE_HP_AUTO_MDIX_MASK ); + }else { + reg_val &= ~(DISABLE_PAIR_SWAP_CORR_MASK | +DISABLE_POLARITY_CORR_MASK | +DISABLE_HP_AUTO_MDIX_MASK ); + } + rc =phy_write (phydev,MSCC_PHY_BYPASS_CONTROL , reg_val); +if (rc !=0 ) +return rc; + + rc =vsc85xx_phy_page_set (phydev,MSCC_PHY_PAGE_EXTENDED ); +if (rc !=0 ) +return rc; + + reg_val =phy_read (phydev,MSCC_PHY_EXT_MODE_CNTL ); + reg_val &= ~(FORCE_MDI_CROSSOVER_MASK ); +if (mdix ==ETH_TP_MDI ) + reg_val |=FORCE_MDI_CROSSOVER_MDI ; +else if (mdix ==ETH_TP_MDI_X ) + reg_val |=FORCE_MDI_CROSSOVER_MDIX ; + rc =phy_write (phydev,MSCC_PHY_EXT_MODE_CNTL , reg_val); +if (rc !=0 ) +return rc; + + rc =vsc85xx_phy_page_set (phydev,MSCC_PHY_PAGE_STANDARD ); +if (rc !=0 ) +return rc; + +return genphy_restart_aneg (phydev); +} +static int vsc85xx_downshift_get (struct phy_device *phydev,u8 *count) {int rc;
@@ -381,6 +447,7 @@ static int vsc85xx_default_config(struct phy_device *phydev)int rc;u16 reg_val; + phydev->mdix_ctrl =ETH_TP_MDI_AUTO ;mutex_lock (&phydev->lock); rc =vsc85xx_phy_page_set (phydev,MSCC_PHY_PAGE_EXTENDED_2 );if (rc !=0 )
@@ -470,6 +537,28 @@ static int vsc85xx_config_intr(struct phy_device *phydev)return rc; } +static int vsc85xx_config_aneg (struct phy_device *phydev) +{ +int rc; + + rc =vsc85xx_mdix_set (phydev, phydev->mdix_ctrl); +if (rc <0 ) +return rc; + +return genphy_config_aneg (phydev); +} + +static int vsc85xx_read_status (struct phy_device *phydev) +{ +int rc; + + rc =vsc85xx_mdix_get (phydev, &phydev->mdix); +if (rc <0 ) +return rc; + +return genphy_read_status (phydev); +} +static int vsc85xx_probe (struct phy_device *phydev) {int rate_magic;
@@ -500,9 +589,9 @@ static struct phy_driver vsc85xx_driver[] = { .flags = PHY_HAS_INTERRUPT, .soft_reset = &genphy_soft_reset, .config_init = &vsc85xx_config_init, - .config_aneg = &genphy_config_aneg, + .config_aneg = &vsc85xx_config_aneg, .aneg_done = &genphy_aneg_done, - .read_status = &genphy_read_status, + .read_status = &vsc85xx_read_status, .ack_interrupt = &vsc85xx_ack_interrupt, .config_intr = &vsc85xx_config_intr, .suspend = &genphy_suspend,
@@ -521,9 +610,9 @@ static struct phy_driver vsc85xx_driver[] = { .flags = PHY_HAS_INTERRUPT, .soft_reset = &genphy_soft_reset, .config_init = &vsc85xx_config_init, - .config_aneg = &genphy_config_aneg, + .config_aneg = &vsc85xx_config_aneg, .aneg_done = &genphy_aneg_done, - .read_status = &genphy_read_status, + .read_status = &vsc85xx_read_status, .ack_interrupt = &vsc85xx_ack_interrupt, .config_intr = &vsc85xx_config_intr, .suspend = &genphy_suspend,
@@ -542,9 +631,9 @@ static struct phy_driver vsc85xx_driver[] = { .flags = PHY_HAS_INTERRUPT, .soft_reset = &genphy_soft_reset, .config_init = &vsc85xx_config_init, - .config_aneg = &genphy_config_aneg, + .config_aneg = &vsc85xx_config_aneg, .aneg_done = &genphy_aneg_done, - .read_status = &genphy_read_status, + .read_status = &vsc85xx_read_status, .ack_interrupt = &vsc85xx_ack_interrupt, .config_intr = &vsc85xx_config_intr, .suspend = &genphy_suspend,
@@ -563,9 +652,9 @@ static struct phy_driver vsc85xx_driver[] = { .flags = PHY_HAS_INTERRUPT, .soft_reset = &genphy_soft_reset, .config_init = &vsc85xx_config_init, - .config_aneg = &genphy_config_aneg, + .config_aneg = &vsc85xx_config_aneg, .aneg_done = &genphy_aneg_done, - .read_status = &genphy_read_status, + .read_status = &vsc85xx_read_status, .ack_interrupt = &vsc85xx_ack_interrupt, .config_intr = &vsc85xx_config_intr, .suspend = &genphy_suspend,
Signature · 1 line
2.7.4
PATCH v2 2/4 net: phy: update the mdix_ctrl with correct value.
In reply to Raju LakkarajuFrom: Raju Lakkaraju <[email protected]>
Update the mdix and mdix_ctrl with corresponding ethtool configuration parameters.
--- drivers/net/phy/phy.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/phy/phy.c +6 -4
@@ -389,7 +389,7 @@ int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd) phydev->duplex = cmd->duplex; - phydev->mdix = cmd->eth_tp_mdix_ctrl; + phydev->mdix_ctrl = cmd->eth_tp_mdix_ctrl;/* Restart the PHY */ phy_start_aneg (phydev);
@@ -443,7 +443,7 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev, phydev->duplex = duplex; - phydev->mdix = cmd->base.eth_tp_mdix_ctrl; + phydev->mdix_ctrl = cmd->base.eth_tp_mdix_ctrl;/* Restart the PHY */ phy_start_aneg (phydev);
@@ -469,7 +469,8 @@ int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd) cmd->transceiver =phy_is_internal (phydev) ?XCVR_INTERNAL :XCVR_EXTERNAL ; cmd->autoneg = phydev->autoneg; - cmd->eth_tp_mdix_ctrl = phydev->mdix; + cmd->eth_tp_mdix_ctrl = phydev->mdix_ctrl; + cmd->eth_tp_mdix = phydev->mdix;return 0 ; }
@@ -496,7 +497,8 @@ int phy_ethtool_ksettings_get(struct phy_device *phydev, cmd->base.phy_address = phydev->mdio.addr; cmd->base.autoneg = phydev->autoneg; - cmd->base.eth_tp_mdix_ctrl = phydev->mdix; + cmd->base.eth_tp_mdix_ctrl = phydev->mdix_ctrl; + cmd->base.eth_tp_mdix = phydev->mdix;return 0 ; }
Signature · 1 line
2.7.4
v2 cover Adding PHY MDI(X) support
Hi All,
I updated all review comments which were given by Andrew and Florian.
This series add support for PHY MDI(X), and implement it for MSCC phys.
Tested on Beaglebone Black with VSC 8531 PHY.
Please review.
Thanks and regards
Raju.
---
Change set:
v1:
- Initial patch submit the WoL and MDI-X in single set of patches
v2:
- Split the mdi(x) as signal set of patches.
- Remove the out_unlock as suggested by Andrew.
- Add mdix_ctrl parameter in "phy_device" to handle the user configure mdi(x). Proposed implementation accepted by Florian.
- phydev->mdix_ctrl initialize with ETH_TP_MDI_AUTO. Ethernet controller never initialize this parameter.
- Fix the mdix changes in marvell and microchip driver.
Raju Lakkaraju (4):
net: phy: add mdix_ctrl to hold the user configuration.
net: phy: update the mdix_ctrl with correct value.
net: phy: Add mdi(x) support in Microsemi PHYs driver
net: phy: Fix the mdix_ctrl changes
drivers/net/phy/marvell.c | 4 +- drivers/net/phy/microchip.c | 2 +- drivers/net/phy/mscc.c | 105 ++++++++++++++++++++++++++++++++++++++++---- drivers/net/phy/phy.c | 10 +++-- include/linux/phy.h | 1 + 5 files changed, 107 insertions(+), 15 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 4/4 net: phy: Fix the mdix_ctrl changes
From: Raju Lakkaraju <[email protected]>
PHY drivers to have an eth_tp_mdix_ctrl to indicate what is the configured MDI setting, and read eth_tp_mdi to indicate what is the current status,
Add new parameter mdix_ctrl in phy_device structure and fix driver.
--- drivers/net/phy/marvell.c | 4 ++-- drivers/net/phy/microchip.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/phy/marvell.c +2 -2
@@ -268,7 +268,7 @@ static int marvell_config_aneg(struct phy_device *phydev)if (err <0 )return err; - err =marvell_set_polarity (phydev, phydev->mdix); + err =marvell_set_polarity (phydev, phydev->mdix_ctrl);if (err <0 )return err;
@@ -311,7 +311,7 @@ static int m88e1111_config_aneg(struct phy_device *phydev)*/ err =phy_write (phydev,MII_BMCR ,BMCR_RESET ); - err =marvell_set_polarity (phydev, phydev->mdix); + err =marvell_set_polarity (phydev, phydev->mdix_ctrl);if (err <0 )return err;
drivers/net/phy/microchip.c +1 -1
@@ -111,7 +111,7 @@ static void lan88xx_set_mdix(struct phy_device *phydev)int buf;int val; -switch (phydev->mdix) { +switch (phydev->mdix_ctrl) {case ETH_TP_MDI : val =LAN88XX_EXT_MODE_CTRL_MDI_ ;break ;
Signature · 1 line
2.7.4
David Miller
maintainerFrom: Raju Lakkaraju <[email protected]>
Date: Tue, 29 Nov 2016 15:16:45 +0530
Quoted 5 lines
I updated all review comments which were given by Andrew and Florian.
This series add support for PHY MDI(X), and implement it for MSCC phys.
Tested on Beaglebone Black with VSC 8531 PHY.
Series applied, thanks.