net: macb: Add gmii2rgmii converter support
Subsystems (3)
RFC PATCH 1/1 net: macb: Add gmii2rgmii converter support
This patch adds support for gmii2rgmii converter
in the macb driver.
The GMII to RGMII IP core provides the
Reduced Gigabit Media Independent Interface
(RGMII) between Ethernet physical media devices
And the Gigabit Ethernet controller.
This core can switch dynamically between the
Three different speed modes of operation (10/100/1000 Mb/s). MDIO interface is used to set operating speed of Ethernet MAC.
---
--> Tried to include this Coverter support in the
PHY layer but it won't fit into the PHY framework as the coverter won't have vaild vendor/Device id registers.
--> The Converter has only one register (16) that need's
to be programmed with the external phy negotiated speed.
--> The converter won't follow the Standard MII(ieee 802.3 clause 22). --> Will appreciate if someone can help on adding this coverter support
drivers/net/ethernet/cadence/macb.c | 37 ++++++++++++++++++++++++++++++++-- drivers/net/ethernet/cadence/macb.h | 7 ++++++ 2 files changed, 41 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/macb.c +34 -3
@@ -305,8 +305,10 @@ static void macb_handle_link_change(struct net_device *dev) {struct macb *bp =netdev_priv (dev);struct phy_device *phydev = bp->phy_dev; +struct phy_device *gmii2rgmii_phydev = bp->gmii2rgmii_phy_dev;unsigned long flags;int status_change =0 ; +u16 gmii2rgmii_reg =0 ;spin_lock_irqsave (&bp->lock, flags);
@@ -320,15 +322,26 @@ static void macb_handle_link_change(struct net_device *dev)if (macb_is_gem (bp)) reg &= ~GEM_BIT (GBE ); -if (phydev->duplex) +if (phydev->duplex) { reg |=MACB_BIT (FD ); -if (phydev->speed ==SPEED_100 ) + gmii2rgmii_reg |=MACB_GMII2RGMII_FULLDPLX ; + } +if (phydev->speed ==SPEED_100 ) { reg |=MACB_BIT (SPD ); + gmii2rgmii_reg |=MACB_GMII2RGMII_SPEED100 ; + }if (phydev->speed ==SPEED_1000 && - bp->caps &MACB_CAPS_GIGABIT_MODE_AVAILABLE ) + bp->caps &MACB_CAPS_GIGABIT_MODE_AVAILABLE ) { reg |=GEM_BIT (GBE ); + gmii2rgmii_reg |=MACB_GMII2RGMII_SPEED1000 ; + }macb_or_gem_writel (bp,NCFGR , reg); +if (!gmii2rgmii_phydev) { +phy_write (gmii2rgmii_phydev, +MACB_GMII2RGMII_REG_NUM , + gmii2rgmii_reg); + } bp->speed = phydev->speed; bp->duplex = phydev->duplex;
@@ -376,6 +389,20 @@ static int macb_mii_probe(struct net_device *dev)int phy_irq;int ret; +if (bp->gmii2rgmii_phy_node) { + phydev =of_phy_attach (bp->dev, + bp->gmii2rgmii_phy_node, +0 ,0 ); +if (!phydev) { +dev_err (&bp->pdev->dev,"%s: no gmii_to_rgmii found\n" , + dev->name); +return -1 ; + } + bp->gmii2rgmii_phy_dev = phydev; + }else { + bp->gmii2rgmii_phy_dev =NULL ; + } + phydev =phy_find_first (bp->mii_bus);if (!phydev) {netdev_err (dev,"no PHY found\n" );
@@ -3001,6 +3028,8 @@ static int macb_probe(struct platform_device *pdev) bp->phy_interface = err; } + bp->gmii2rgmii_phy_node =of_parse_phandle (bp->pdev->dev.of_node, +"gmii2rgmii-phy-handle" ,0 );/* IP specific init */ err =init (pdev);if (err)
@@ -3059,6 +3088,8 @@ static int macb_remove(struct platform_device *pdev) bp =netdev_priv (dev);if (bp->phy_dev)phy_disconnect (bp->phy_dev); +if (bp->gmii2rgmii_phy_dev) +phy_disconnect (bp->gmii2rgmii_phy_dev);mdiobus_unregister (bp->mii_bus);mdiobus_free (bp->mii_bus);
drivers/net/ethernet/cadence/macb.h +7 -0
@@ -559,6 +559,11 @@ struct macb_dma_desc {/* limit RX checksum offload to TCP and UDP packets */ #define GEM_RX_CSUM_CHECKED_MASK 2 +#define MACB_GMII2RGMII_FULLDPLX BMCR_FULLDPLX +#define MACB_GMII2RGMII_SPEED1000 BMCR_SPEED1000 +#define MACB_GMII2RGMII_SPEED100 BMCR_SPEED100 +#define MACB_GMII2RGMII_REG_NUM 0x10 +/* struct macb_tx_skb - data about an skb which is being transmitted * @skb: skb currently being transmitted, only set for the last buffer * of the frame
@@ -846,6 +851,8 @@ struct macb {unsigned int jumbo_max_len;u32 wol; +struct device_node *gmii2rgmii_phy_node; +struct phy_device *gmii2rgmii_phy_dev; };static inline bool macb_is_gem (struct macb *bp)
Signature · 1 line
1.7.1
Quoted 12 lines · Kedareswara rao Appana
This patch adds support for gmii2rgmii converter
in the macb driver.The GMII to RGMII IP core provides the
Reduced Gigabit Media Independent Interface
(RGMII) between Ethernet physical media devices
And the Gigabit Ethernet controller.
This core can switch dynamically between the
Three different speed modes of operation (10/100/1000 Mb/s). MDIO interface is used to set operating speed of Ethernet MAC.Signed-off-by Kedareswara rao Appana <[email protected]>
Quoted 8 lines
---
--> Tried to include this Coverter support in the
PHY layer but it won't fit into the PHY framework as the coverter won't have vaild vendor/Device id registers.
--> The Converter has only one register (16) that need's
to be programmed with the external phy negotiated speed.
--> The converter won't follow the Standard MII(ieee 802.3 clause 22). --> Will appreciate if someone can help on adding this coverter support
With the fixed PHY emulated PHY and registering a link_update callback (see drivers/net/dsa/bcm_sf2.c for an example), you could read specific registers which indicates link parameters and update the PHY device with these.
How exactly is this converter working?
Signature · 1 line
Florian
Quoted 2 lines · Kedareswara rao Appana
This patch adds support for gmii2rgmii converter
in the macb driver.
[]
drivers/net/ethernet/cadence/macb.c
Quoted 1 line
drivers/net/ethernet/cadence/macb.c +0
-0
[]
drivers/net/ethernet/cadence/macb.c static int macb_mii_probe(struct net_device *dev) · line 398
Quoted 11 lines
drivers/net/ethernet/cadence/macb.c +0
-0@@ -376,6 +389,20 @@ static int macb_mii_probe(struct net_device *dev) int phy_irq; int ret;drivers/net/ethernet/cadence/macb.c +7
-0+if (bp->gmii2rgmii_phy_node) { + phydev =of_phy_attach (bp->dev, + bp->gmii2rgmii_phy_node, + 0, 0); +if (!phydev) { +dev_err (&bp->pdev->dev,"%s: no gmii_to_rgmii found\n" , + dev->name);
why use dev_err(&bp->pdev->dev, ...) and not netdev_err(dev, ...) ?
Hi Florian,
Thanks for the quick response...
Quoted 23 lines
Quoted 11 lines · Kedareswara rao Appana
This patch adds support for gmii2rgmii converter in the macb driver.
The GMII to RGMII IP core provides the
Reduced Gigabit Media Independent Interface
(RGMII) between Ethernet physical media devices And the Gigabit Ethernet controller.
This core can switch dynamically between the Three different speed modes of operation (10/100/1000 Mb/s).
MDIO interface is used to set operating speed of Ethernet MAC.Signed-off-by Kedareswara rao Appana <[email protected]>Quoted 8 lines
---
--> Tried to include this Coverter support in the
PHY layer but it won't fit into the PHY framework as the coverter won't have vaild vendor/Device id registers.
--> The Converter has only one register (16) that need's
to be programmed with the external phy negotiated speed.
--> The converter won't follow the Standard MII(ieee 802.3 clause 22). --> Will appreciate if someone can help on adding this coverter support
Quoted 3 lines
With the fixed PHY emulated PHY and registering a
link_updatecallback (seedrivers/net/dsa/bcm_sf2.cfor an example), you could read specific registers which indicates link parameters and update the PHY device with these.
Thanks will check and get back...
Quoted 2 lines
How exactly is this converter working?
This converter does GMII to RGMII conversion.
It provides only one register for programing the desired speed and MDIO is Interface to program this register. It sits between the mac and external phy. So, once the phy negotiation completes and link is up, The negotiated speed should be programmed in the converter.
Converter data sheet:
http://www.xilinx.com/support/documentation/ip_documentation/gmii_to_rgmii/v3_0/pg160-gmii-to-rgmii.pdf
Regards,
Kedar.
Quoted 3 lines
--
Florian