Skip to contentSkip to conversation

net: stmmac: add gmac autoneg set for SGMII, TBI, and RTBI

PATCH Giuseppe CAVALLARO 2 participants 8 messages Jan 16, 2013 – Mar 7, 2013 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

Hello Byungho,

Quoted 6 lines · Byungho An

This patch adds gmac autoneg set function for SGMII, TBI, or RTBI interface. In case of PHY's autoneg is set, gmac's autoneg enable bit should set. After checking phy's autoneg if phydev's autoneg is '1' gmac's ANE bit set for those interface.

Sorry I've some doubts about these patches.

Firstly if the MAC is able to manage RGMII/SGMII etc this should be verified by looking at the HW cap register: i.e. PCS bit.

(I have no HW that support this so I cannot do any tests).

In case of this feature is actually supported then the driver could
manage everything bypassing the MDIO.
IMO, we could not need to call the stmmac_phy_init and we should not
use the PHYLIB.
I mean if we have the PCS module we could have a minimal support to get
link status, restart ANE etc w/o using at all the PHYLIB (so w/o touching the PHY regs via the MDIO/MDC).

It could also be useful to complete the support with the RGMII... no extra effort should be needed while adding SGMII if you look at the core registers.
If you add the RGMII on some platforms we could guarantee to manage the fix_mac_speed (see stmmac doc).

Looking at the other your patches, the ethtool support is not completed. I expected to restart ANE, get/set link property etc.

Also pay attention to properly treat EEE. Maybe, as first stage we should disable the feature in this case. We will see it later. The question is that we could not be able to use some extra features that currently need to dialog more with the PHY device. I mean what we actually do by using PHYLIB.

Quoted 27 lines
---
  drivers/net/ethernet/stmicro/stmmac/common.h         |    1 +
  drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c |   11 +++++++++++
  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |    9 +++++++++
  3 files changed, 21 insertions(+)
drivers/net/ethernet/stmicro/stmmac/common.h +1 -0
index 186d148..72ba769 100644
@@ -344,6 +344,7 @@ struct stmmac_ops {
  	void (*reset_eee_mode) (void __iomem *ioaddr);
  	void (*set_eee_timer) (void __iomem *ioaddr, int ls, int tw);
  	void (*set_eee_pls) (void __iomem *ioaddr, int link);
+	void (*set_autoneg) (void __iomem *ioaddr);
  };
 
  struct mac_link {
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +0 -0
index bfe0226..a0737b39 100644

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c static void dwmac1000_set_eee_timer(void __iomem · line 306

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +6 -0
@@ -297,6 +297,16 @@ static void  dwmac1000_set_eee_timer(void __iomem
 *ioaddr, int ls, int tw)
  	writel(value, ioaddr + LPI_TIMER_CTRL);
  }
 
+static void dwmac1000_set_autoneg(void __iomem *ioaddr)
+{
+	u32 value;
+
+	value = readl(ioaddr + GMAC_AN_CTRL);
+	value |= 0x1000;

pls use define instead of raw values ... see below.

Quoted 29 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +4 -0
+	writel(value, ioaddr + GMAC_AN_CTRL);
+}
+
+
  static const struct stmmac_ops dwmac1000_ops = {
  	.core_init = dwmac1000_core_init,

.rx_ipc = dwmac1000_rx_ipc_enable,

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +1 -0
@@ -311,6 +321,7 @@ static const struct stmmac_ops dwmac1000_ops = {
  	.reset_eee_mode =  dwmac1000_reset_eee_mode,
  	.set_eee_timer =  dwmac1000_set_eee_timer,
  	.set_eee_pls =  dwmac1000_set_eee_pls,
+	.set_autoneg =  dwmac1000_set_autoneg,
  };
 
  struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
index f07c061..3e28934 100644
@@ -1007,6 +1007,7 @@ static int stmmac_open(struct net_device *dev)
  {
  	struct stmmac_priv *priv = netdev_priv(dev);
  	int ret;
+	int interface = priv->plat->interface;
 
  	clk_prepare_enable(priv->stmmac_clk);
 

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_open(struct net_device *dev) · line 1051

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -0
@@ -1041,6 +1042,14 @@ static int stmmac_open(struct net_device *dev)
  	/* Initialize the MAC Core */
  	priv->hw->mac->core_init(priv->ioaddr);
 
+	/* If phy autoneg is on, set gmac autoneg for SGMII, TBI and RTBI*/
+	if (interface == PHY_INTERFACE_MODE_SGMII ||
+	    interface == PHY_INTERFACE_MODE_TBI ||
+	    interface == PHY_INTERFACE_MODE_RTBI) {
+		if (priv->phydev->autoneg)
+			priv->hw->mac->set_autoneg(priv->ioaddr);
+	}

we could use the following instead of priv->hw->mac->set_autoneg:

static void dwmac1000_ctrl_ane(void __iomem *ioaddr, bool restart)

{
    int value = GMAC_CTRL_ANE_EN;

    if (restart)
        value |= GMAC_CTRL_ANE_RESTART;

    writel(value, ioaddr +GMAC_AN_CTRL);
}

where we should defines all the missing macros for the registers 48, 49 ...

/* RGMI/SGMII defines */
#define GMAC_CTRL_ANE_SGMII_RAL (1 << 18)
#define GMAC_CTRL_ANE_EN (1 << 12)
#define GMAC_CTRL_ANE_RESTART (1 << 9)

The handler should store the link status that will be used to pass the info to the ethtool for example. We need to manage speed and duplex etc.

What happens if you run "ethtool eth0" command? Or if you run mii-tool?
I expect to get the right speed and duplex at least.

Concerning the stmmac_set_pauseparam I'm also not sure you are doing the right thing. Note that you are not restarting the ANE at all ... (this is what the phy_start_aneg does). If set the bit 12 then you are enabling the ane. To restart it, you need to set the bit 9 in the reg 48.

I can support you on all the points above. Let me know.

BR,
peppe

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
+
  	/* Request the IRQ lines */
  	ret = request_irq(dev->irq, stmmac_interrupt,
  			 IRQF_SHARED, dev->name, dev);
#2 lore raw

Hello Peppe,

On 1/15/2013 11:28 PM, Giuseppe CAVALLARO write:

Quoted 10 lines · Byungho An
Quoted 5 lines

This patch adds gmac autoneg set function for SGMII, TBI, or RTBI interface. In case of PHY's autoneg is set, gmac's autoneg enable bit should set. After checking phy's autoneg if phydev's autoneg is '1' gmac's ANE bit set for those interface.

Sorry I've some doubts about these patches.

Firstly if the MAC is able to manage RGMII/SGMII etc this should be

verified

Quoted 4 lines

by looking at the HW cap register: i.e. PCS bit.

(I have no HW that support this so I cannot do any tests).

I agree with you and actually I tried to use a PCS bit previously. (PCS bit indicates TBI, SGMII, or RTBI PHY interface)
But I was confused which one I should use among PSC, ACTPHYIF or phydev to recognize the interface.
At this time, I want to add auto-negotiation enable because sgmii interface is not working without ANE using PCS bit(in H/W feature register).

Quoted 6 lines

In case of this feature is actually supported then the driver could manage everything bypassing the MDIO.
IMO, we could not need to call the stmmac_phy_init and we should not use the PHYLIB.
I mean if we have the PCS module we could have a minimal support to get link status, restart ANE etc w/o using at all the PHYLIB (so w/o touching

the

Quoted 2 lines

PHY regs via the MDIO/MDC).

Yes. For example SGMII/RGMII/SMII Status Register is useful to know status so we can use this register to manage status of SGMII/RGMII/SMII

Quoted 6 lines

It could also be useful to complete the support with the RGMII... no extra effort should be needed while adding SGMII if you look at the core registers.
If you add the RGMII on some platforms we could guarantee to manage the fix_mac_speed (see stmmac doc).

Unfortunately I have only the SGMII.

Quoted 3 lines

Looking at the other your patches, the ethtool support is not completed. I expected to restart ANE, get/set link property etc.

What is link property? It means link up, speed and duplex mode. Are there anything else?
I think get link property is already working using ethtool. In case of SGMII/RGMII/SMII, I think we can use SGMII/RGMII/SMII Status Register for link status.

I have a question regarding it.
In the mainline code, there is hardcode interrupt mask in dwmac1000_core_init function.
When I try to get interrupt for link change, interrupt is not occurred because of this mask.
Can we modify that?

Quoted 5 lines

Also pay attention to properly treat EEE. Maybe, as first stage we should disable the feature in this case. We will see it later.
The question is that we could not be able to use some extra features that currently need to dialog more with the PHY device. I mean what we actually do by using PHYLIB.

OK. As I understood, using gmac register instead of phydev or phylib... I agree. In my opinion gmac and phy communicate using mdio each other, after that gmac can get updated status.

Quoted 91 lines
Quoted 6 lines
---
  drivers/net/ethernet/stmicro/stmmac/common.h         |    1 +
  drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c |   11

+++++++++++

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c static void dwmac1000_set_eee_timer(void

Quoted 22 lines
  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |    9 +++++++++
  3 files changed, 21 insertions(+)
drivers/net/ethernet/stmicro/stmmac/common.h +1 -0
index 186d148..72ba769 100644
@@ -344,6 +344,7 @@ struct stmmac_ops {
  	void (*reset_eee_mode) (void __iomem *ioaddr);
  	void (*set_eee_timer) (void __iomem *ioaddr, int ls, int tw);
  	void (*set_eee_pls) (void __iomem *ioaddr, int link);
+	void (*set_autoneg) (void __iomem *ioaddr);
  };
 
  struct mac_link {
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +0 -0
index bfe0226..a0737b39 100644
@@ -297,6 +297,16 @@ static void  dwmac1000_set_eee_timer(void

__iomem

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c static void dwmac1000_set_eee_timer(void · line 305

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +5 -0
 *ioaddr, int ls, int tw)
  	writel(value, ioaddr + LPI_TIMER_CTRL);
  }
 
+static void dwmac1000_set_autoneg(void __iomem *ioaddr) {
+	u32 value;
+
+	value = readl(ioaddr + GMAC_AN_CTRL);
+	value |= 0x1000;

pls use define instead of raw values ... see below.

Quoted 28 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +4 -1
+	writel(value, ioaddr + GMAC_AN_CTRL); }
+
+
  static const struct stmmac_ops dwmac1000_ops = {
  	.core_init = dwmac1000_core_init,
  	.rx_ipc = dwmac1000_rx_ipc_enable,
@@ -311,6 +321,7 @@ static const struct stmmac_ops dwmac1000_ops = {
  	.reset_eee_mode =  dwmac1000_reset_eee_mode,
  	.set_eee_timer =  dwmac1000_set_eee_timer,
  	.set_eee_pls =  dwmac1000_set_eee_pls,
+	.set_autoneg =  dwmac1000_set_autoneg,
  };
 
  struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr) diff
--git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index f07c061..3e28934 100644

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
@@ -1007,6 +1007,7 @@ static int stmmac_open(struct net_device *dev)
  {
  	struct stmmac_priv *priv = netdev_priv(dev);
  	int ret;
+	int interface = priv->plat->interface;
 
  	clk_prepare_enable(priv->stmmac_clk);
 

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_open(struct net_device *dev) · line 1051

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -0
@@ -1041,6 +1042,14 @@ static int stmmac_open(struct net_device *dev)
  	/* Initialize the MAC Core */
  	priv->hw->mac->core_init(priv->ioaddr);
 
+	/* If phy autoneg is on, set gmac autoneg for SGMII, TBI and RTBI*/
+	if (interface == PHY_INTERFACE_MODE_SGMII ||
+	    interface == PHY_INTERFACE_MODE_TBI ||
+	    interface == PHY_INTERFACE_MODE_RTBI) {
+		if (priv->phydev->autoneg)
+			priv->hw->mac->set_autoneg(priv->ioaddr);
+	}

we could use the following instead of priv->hw->mac->set_autoneg:

static void dwmac1000_ctrl_ane(void __iomem *ioaddr, bool restart) {
     int value = GMAC_CTRL_ANE_EN;

     if (restart)
         value |= GMAC_CTRL_ANE_RESTART;

     writel(value, ioaddr +GMAC_AN_CTRL); }
Quoted 1 line

where we should defines all the missing macros for the registers 48, 49

...
Actually I tested this code for restart autonegotiation, but even though I changed link (1Gb -> 100Mb) phy's link is not changed.
For more detail, first time 1Gb I changed the link during system working and then check speed using ethtool/mii-tool.
I think phy also should do autonegotiation (I'm not sure this is just for the SGMII). Without phy auto negotiation gmac is not working.

OK, I'll try to check functionality and make macros.
Anyway as a first step, I want to complete to the code regarding ANE (ctrl function, macros, ethtool support for link status etc..)
I'll send new code before making patch soon.

Quoted 7 lines

/* RGMI/SGMII defines */
#define GMAC_CTRL_ANE_SGMII_RAL (1 << 18)
#define GMAC_CTRL_ANE_EN (1 << 12)
#define GMAC_CTRL_ANE_RESTART (1 << 9)

The handler should store the link status that will be used to pass the

info to

Quoted 5 lines

the ethtool for example. We need to manage speed and duplex etc.

What happens if you run "ethtool eth0" command? Or if you run mii-tool?
I expect to get the right speed and duplex at least.

So far, I can get right data speed and duplex and autoneg.

Quoted 3 lines

Concerning the stmmac_set_pauseparam I'm also not sure you are doing the right thing. Note that you are not restarting the ANE at all ... (this is

what the

Quoted 8 lines

phy_start_aneg does). If set the bit 12 then you are enabling the ane. To restart it, you need to set the bit 9 in the reg 48.

I can support you on all the points above. Let me know.

BR,
peppe

OK, thank you and happy new year.
Byungho An

Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
+
  	/* Request the IRQ lines */
  	ret = request_irq(dev->irq, stmmac_interrupt,
  			 IRQF_SHARED, dev->name, dev);
#3 lore raw

Hello Byungho

Quoted 16 lines · Byungho An

Hello Peppe,

On 1/15/2013 11:28 PM, Giuseppe CAVALLARO write:

Quoted 10 lines · Byungho An
Quoted 5 lines

This patch adds gmac autoneg set function for SGMII, TBI, or RTBI interface. In case of PHY's autoneg is set, gmac's autoneg enable bit should set. After checking phy's autoneg if phydev's autoneg is '1' gmac's ANE bit set for those interface.

Sorry I've some doubts about these patches.

Firstly if the MAC is able to manage RGMII/SGMII etc this should be

verified

Quoted 2 lines

by looking at the HW cap register: i.e. PCS bit.

Quoted 9 lines
Quoted 2 lines

(I have no HW that support this so I cannot do any tests).

I agree with you and actually I tried to use a PCS bit previously. (PCS bit indicates TBI, SGMII, or RTBI PHY interface)
But I was confused which one I should use among PSC, ACTPHYIF or phydev to recognize the interface.
At this time, I want to add auto-negotiation enable because sgmii interface is not working without ANE using PCS bit(in H/W feature register).

really strange, from the synopsys databook we should only look at the RO bit in the HW cap reg just to understand if the feature is supported.

Quoted 13 lines
Quoted 6 lines

In case of this feature is actually supported then the driver could manage everything bypassing the MDIO.
IMO, we could not need to call the stmmac_phy_init and we should not use the PHYLIB.
I mean if we have the PCS module we could have a minimal support to get link status, restart ANE etc w/o using at all the PHYLIB (so w/o touching

the

Quoted 2 lines

PHY regs via the MDIO/MDC).

Yes. For example SGMII/RGMII/SMII Status Register is useful to know status so we can use this register to manage status of SGMII/RGMII/SMII

Quoted 7 lines
Quoted 6 lines

It could also be useful to complete the support with the RGMII... no extra effort should be needed while adding SGMII if you look at the core registers.
If you add the RGMII on some platforms we could guarantee to manage the fix_mac_speed (see stmmac doc).

Unfortunately I have only the SGMII.

no problem, I'll complete it by my hand later.

Quoted 10 lines
Quoted 4 lines

Looking at the other your patches, the ethtool support is not completed. I expected to restart ANE, get/set link property etc.

What is link property? It means link up, speed and duplex mode. Are there anything else?
I think get link property is already working using ethtool. In case of SGMII/RGMII/SMII, I think we can use SGMII/RGMII/SMII Status Register for link status.

Quoted 6 lines

I have a question regarding it.
In the mainline code, there is hardcode interrupt mask in dwmac1000_core_init function.
When I try to get interrupt for link change, interrupt is not occurred because of this mask.
Can we modify that?

yes you can. I had wrote an initial patch that started doing something.
I have tested it on my boards and I can send it to the mailing list to be reviewed. Maybe you can build your patch on top of it.

Quoted 8 lines
Quoted 5 lines

Also pay attention to properly treat EEE. Maybe, as first stage we should disable the feature in this case. We will see it later.
The question is that we could not be able to use some extra features that currently need to dialog more with the PHY device. I mean what we actually do by using PHYLIB.

OK. As I understood, using gmac register instead of phydev or phylib... I agree. In my opinion gmac and phy communicate using mdio each other, after that gmac can get updated status.

yep, this is the point :-)

Quoted 100 lines
Quoted 91 lines
Quoted 6 lines
---
   drivers/net/ethernet/stmicro/stmmac/common.h         |    1 +
   drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c |   11

+++++++++++

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c static void dwmac1000_set_eee_timer(void

Quoted 22 lines
   drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |    9 +++++++++
   3 files changed, 21 insertions(+)
drivers/net/ethernet/stmicro/stmmac/common.h +1 -0
index 186d148..72ba769 100644
@@ -344,6 +344,7 @@ struct stmmac_ops {
   	void (*reset_eee_mode) (void __iomem *ioaddr);
   	void (*set_eee_timer) (void __iomem *ioaddr, int ls, int tw);
   	void (*set_eee_pls) (void __iomem *ioaddr, int link);
+	void (*set_autoneg) (void __iomem *ioaddr);
   };
 
   struct mac_link {
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +0 -0
index bfe0226..a0737b39 100644
@@ -297,6 +297,16 @@ static void  dwmac1000_set_eee_timer(void

__iomem

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c static void dwmac1000_set_eee_timer(void · line 305

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +5 -0
 *ioaddr, int ls, int tw)
   	writel(value, ioaddr + LPI_TIMER_CTRL);
   }
 
+static void dwmac1000_set_autoneg(void __iomem *ioaddr) {
+	u32 value;
+
+	value = readl(ioaddr + GMAC_AN_CTRL);
+	value |= 0x1000;

pls use define instead of raw values ... see below.

Quoted 28 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +4 -1
+	writel(value, ioaddr + GMAC_AN_CTRL); }
+
+
   static const struct stmmac_ops dwmac1000_ops = {
   	.core_init = dwmac1000_core_init,
   	.rx_ipc = dwmac1000_rx_ipc_enable,
@@ -311,6 +321,7 @@ static const struct stmmac_ops dwmac1000_ops = {
   	.reset_eee_mode =  dwmac1000_reset_eee_mode,
   	.set_eee_timer =  dwmac1000_set_eee_timer,
   	.set_eee_pls =  dwmac1000_set_eee_pls,
+	.set_autoneg =  dwmac1000_set_autoneg,
   };
 
   struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr) diff
--git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index f07c061..3e28934 100644

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
@@ -1007,6 +1007,7 @@ static int stmmac_open(struct net_device *dev)
   {
   	struct stmmac_priv *priv = netdev_priv(dev);
   	int ret;
+	int interface = priv->plat->interface;
 
   	clk_prepare_enable(priv->stmmac_clk);
 

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_open(struct net_device *dev) · line 1051

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -0
@@ -1041,6 +1042,14 @@ static int stmmac_open(struct net_device *dev)
   	/* Initialize the MAC Core */
   	priv->hw->mac->core_init(priv->ioaddr);
 
+	/* If phy autoneg is on, set gmac autoneg for SGMII, TBI and RTBI*/
+	if (interface == PHY_INTERFACE_MODE_SGMII ||
+	    interface == PHY_INTERFACE_MODE_TBI ||
+	    interface == PHY_INTERFACE_MODE_RTBI) {
+		if (priv->phydev->autoneg)
+			priv->hw->mac->set_autoneg(priv->ioaddr);
+	}

we could use the following instead of priv->hw->mac->set_autoneg:

static void dwmac1000_ctrl_ane(void __iomem *ioaddr, bool restart) {
      int value = GMAC_CTRL_ANE_EN;

      if (restart)
          value |= GMAC_CTRL_ANE_RESTART;

      writel(value, ioaddr +GMAC_AN_CTRL); }
Quoted 1 line

where we should defines all the missing macros for the registers 48, 49

...
Actually I tested this code for restart autonegotiation, but even though I changed link (1Gb -> 100Mb) phy's link is not changed.
For more detail, first time 1Gb I changed the link during system working and then check speed using ethtool/mii-tool.
I think phy also should do autonegotiation (I'm not sure this is just for the SGMII). Without phy auto negotiation gmac is not working.

Quoted 4 lines

OK, I'll try to check functionality and make macros.
Anyway as a first step, I want to complete to the code regarding ANE (ctrl function, macros, ethtool support for link status etc..)
I'll send new code before making patch soon.

thanks you

Quoted 22 lines
Quoted 7 lines

/* RGMI/SGMII defines */
#define GMAC_CTRL_ANE_SGMII_RAL (1 << 18)
#define GMAC_CTRL_ANE_EN (1 << 12)
#define GMAC_CTRL_ANE_RESTART (1 << 9)

The handler should store the link status that will be used to pass the

info to

Quoted 5 lines

the ethtool for example. We need to manage speed and duplex etc.

What happens if you run "ethtool eth0" command? Or if you run mii-tool?
I expect to get the right speed and duplex at least.

So far, I can get right data speed and duplex and autoneg.

Quoted 3 lines

Concerning the stmmac_set_pauseparam I'm also not sure you are doing the right thing. Note that you are not restarting the ANE at all ... (this is

what the

Quoted 3 lines

phy_start_aneg does). If set the bit 12 then you are enabling the ane. To restart it, you need to set the bit 9 in the reg 48.

Quoted 6 lines
Quoted 5 lines

I can support you on all the points above. Let me know.

BR,
peppe

OK, thank you and happy new year.

Also to you :-)

let me know for any progresses etc.

Peppe

Quoted 10 lines

Byungho An

Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
+
   	/* Request the IRQ lines */
   	ret = request_irq(dev->irq, stmmac_interrupt,
   			 IRQF_SHARED, dev->name, dev);
#4 lore raw

On 1/23/2013 1:43 PM, Giuseppe CAVALLARO write:

Quoted 7 lines · Byungho An
Quoted 6 lines

On 1/15/2013 11:28 PM, Giuseppe CAVALLARO write:

Quoted 5 lines · Byungho An
Quoted 4 lines

This patch adds gmac autoneg set function for SGMII, TBI, or RTBI interface. In case of PHY's autoneg is set, gmac's autoneg enable bit should set. After checking phy's autoneg if phydev's autoneg is

'1'

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

gmac's ANE bit set for those interface.

Sorry I've some doubts about these patches.

Firstly if the MAC is able to manage RGMII/SGMII etc this should be

verified

Quoted 2 lines

by looking at the HW cap register: i.e. PCS bit.

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

(I have no HW that support this so I cannot do any tests).

I agree with you and actually I tried to use a PCS bit previously. (PCS bit indicates TBI, SGMII, or RTBI PHY interface) But I was confused which one I should use among PSC, ACTPHYIF or phydev to recognize the interface.
At this time, I want to add auto-negotiation enable because sgmii interface is not working without ANE using PCS bit(in H/W feature

register).

Quoted 3 lines
Quoted 1 line

really strange, from the synopsys databook we should only look at the RO

bit

Quoted 2 lines

in the HW cap reg just to understand if the feature is supported.

I modified this part like below

@@ -1044,12 +1046,8 @@ static int stmmac_open(struct net_device *dev)

        priv->hw->mac->core_init(priv->ioaddr);

        /* Enable auto-negotiation for SGMII, TBI or RTBI */

- if (interface == PHY_INTERFACE_MODE_SGMII ||
- interface == PHY_INTERFACE_MODE_TBI ||
- interface == PHY_INTERFACE_MODE_RTBI) {
- if (priv->phydev->autoneg)
- priv->hw->mac->set_autoneg(priv->ioaddr);
- }
+ if (priv->dma_cap.pcs)
+ priv->hw->mac->ctrl_ane(priv->ioaddr, 0);

        /* Request the IRQ lines */
        ret = request_irq(dev->irq, stmmac_interrupt,

As you may know, auto-negotiation is essential for SGMII, TBI, or RTBI interface.

And ctrl_ane funciont is like that

@@ -311,6 +317,18 @@ static void dwmac1000_set_autoneg(void __iomem *ioaddr)

        writel(value, ioaddr + GMAC_AN_CTRL);

}

+static void dwmac1000_ctrl_ane(void __iomem *ioaddr, bool restart) +{
+ u32 value;
+
+ value = readl(ioaddr + GMAC_AN_CTRL);
+ /* auto negotiation enable and External Loopback enable */
+ value = GMAC_AN_CTRL__ANE | GMAC_AN_CTRL__ELE;
+
+ if (restart)
+ value |= GMAC_AN_CTRL_RAN;
+
+ writel(value, ioaddr + GMAC_AN_CTRL);
+}

 static const struct stmmac_ops dwmac1000_ops = {
        .core_init = dwmac1000_core_init,
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

In case of this feature is actually supported then the driver could manage everything bypassing the MDIO.
IMO, we could not need to call the stmmac_phy_init and we should not use the PHYLIB.
I mean if we have the PCS module we could have a minimal support to get link status, restart ANE etc w/o using at all the PHYLIB (so w/o touching

the

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

PHY regs via the MDIO/MDC).

Yes. For example SGMII/RGMII/SMII Status Register is useful to know status so we can use this register to manage status of SGMII/RGMII/SMII

Quoted 1 line

It could also be useful to complete the support with the RGMII...

no

Quoted 26 lines
Quoted 6 lines
Quoted 5 lines

extra effort should be needed while adding SGMII if you look at the core registers.
If you add the RGMII on some platforms we could guarantee to manage the fix_mac_speed (see stmmac doc).

Unfortunately I have only the SGMII.

no problem, I'll complete it by my hand later.

Quoted 10 lines
Quoted 4 lines

Looking at the other your patches, the ethtool support is not completed. I expected to restart ANE, get/set link property etc.

What is link property? It means link up, speed and duplex mode. Are there anything else?
I think get link property is already working using ethtool. In case of SGMII/RGMII/SMII, I think we can use SGMII/RGMII/SMII Status Register for link status.

Quoted 6 lines

I have a question regarding it.
In the mainline code, there is hardcode interrupt mask in dwmac1000_core_init function.
When I try to get interrupt for link change, interrupt is not occurred because of this mask.
Can we modify that?

Quoted 4 lines

yes you can. I had wrote an initial patch that started doing something. I have tested it on my boards and I can send it to the mailing list to be reviewed. Maybe you can build your patch on top of it.

I've changed restart AN like below.

@@ -610,6 +607,27 @@ static int stmmac_set_coalesce(struct net_device *dev,

        return 0;

}

+static int
+stmmac_nway_reset(struct net_device *netdev)
+{

+       struct stmmac_priv *priv = netdev_priv(netdev);
+       struct phy_device *phy = priv->phydev;
+       int ret = 0;

+
+ spin_lock(&priv->lock);
+
+ if (netif_running(netdev)) {

+               phy_stop(phy);
+               phy_start(phy);
+               ret = phy_start_aneg(phy);
+               if (priv->dma_cap.pcs)

+ priv->hw->mac->ctrl_ane(priv->ioaddr, true);
+ }
+
+ spin_unlock(&priv->lock);
+ return ret;
+}
+
static const struct ethtool_ops stmmac_ethtool_ops = {
.begin = stmmac_check_if_running, .get_drvinfo = stmmac_ethtool_getdrvinfo,

Quoted 22 lines
Quoted 8 lines
Quoted 5 lines

Also pay attention to properly treat EEE. Maybe, as first stage we should disable the feature in this case. We will see it later. The question is that we could not be able to use some extra features that currently need to dialog more with the PHY device. I mean what we actually do by using PHYLIB.

OK. As I understood, using gmac register instead of phydev or phylib... I agree. In my opinion gmac and phy communicate using mdio each other, after that gmac can get updated status.

yep, this is the point :-)

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
---
   drivers/net/ethernet/stmicro/stmmac/common.h         |    1 +
   drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c |   11

+++++++++++

Quoted 1 line
   drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |    9

+++++++++

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
   3 files changed, 21 insertions(+)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/common.h struct stmmac_ops { · line 345

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/common.h +0 -0
index 186d148..72ba769 100644
@@ -344,6 +344,7 @@ struct stmmac_ops {
   	void (*reset_eee_mode) (void __iomem *ioaddr);
   	void (*set_eee_timer) (void __iomem *ioaddr, int ls, int

tw);

Quoted 24 lines
Quoted 24 lines
Quoted 24 lines

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c static void dwmac1000_set_eee_timer(void

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/common.h +1 -0
   	void (*set_eee_pls) (void __iomem *ioaddr, int link);
+	void (*set_autoneg) (void __iomem *ioaddr);
   };
 
   struct mac_link {
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +0 -0
index bfe0226..a0737b39 100644
@@ -297,6 +297,16 @@ static void  dwmac1000_set_eee_timer(void

__iomem

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c static void dwmac1000_set_eee_timer(void · line 305

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +5 -0
 *ioaddr, int ls, int tw)
   	writel(value, ioaddr + LPI_TIMER_CTRL);
   }
 
+static void dwmac1000_set_autoneg(void __iomem *ioaddr) {
+	u32 value;
+
+	value = readl(ioaddr + GMAC_AN_CTRL);
+	value |= 0x1000;

pls use define instead of raw values ... see below.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c static void dwmac1000_set_eee_timer(void

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +3 -0
+	writel(value, ioaddr + GMAC_AN_CTRL); }
+
+
   static const struct stmmac_ops dwmac1000_ops = {
   	.core_init = dwmac1000_core_init,
   	.rx_ipc = dwmac1000_rx_ipc_enable, @@ -311,6 +321,7 @@

static

Quoted 54 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
const struct stmmac_ops dwmac1000_ops = {
   	.reset_eee_mode =  dwmac1000_reset_eee_mode,
   	.set_eee_timer =  dwmac1000_set_eee_timer,
   	.set_eee_pls =  dwmac1000_set_eee_pls,
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +1 -0
+	.set_autoneg =  dwmac1000_set_autoneg,
   };
 
   struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
index f07c061..3e28934 100644
@@ -1007,6 +1007,7 @@ static int stmmac_open(struct net_device *dev)
   {
   	struct stmmac_priv *priv = netdev_priv(dev);
   	int ret;
+	int interface = priv->plat->interface;
 
Quoted 3 lines
Quoted 3 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_open(struct net_device

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
   	clk_prepare_enable(priv->stmmac_clk);
 
@@ -1041,6 +1042,14 @@ static int stmmac_open(struct net_device

*dev)

Quoted 31 lines
Quoted 21 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_open(struct net_device · line 1051

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -0
   	/* Initialize the MAC Core */
   	priv->hw->mac->core_init(priv->ioaddr);
 
+	/* If phy autoneg is on, set gmac autoneg for SGMII, TBI and RTBI*/
+	if (interface == PHY_INTERFACE_MODE_SGMII ||
+	    interface == PHY_INTERFACE_MODE_TBI ||
+	    interface == PHY_INTERFACE_MODE_RTBI) {
+		if (priv->phydev->autoneg)
+			priv->hw->mac->set_autoneg(priv->ioaddr);
+	}

we could use the following instead of priv->hw->mac->set_autoneg:

static void dwmac1000_ctrl_ane(void __iomem *ioaddr, bool restart) {
      int value = GMAC_CTRL_ANE_EN;

      if (restart)
          value |= GMAC_CTRL_ANE_RESTART;

      writel(value, ioaddr +GMAC_AN_CTRL); }
Quoted 2 lines

where we should defines all the missing macros for the registers 48, 49

...
Actually I tested this code for restart autonegotiation, but even though I changed link (1Gb -> 100Mb) phy's link is not changed. For more detail, first time 1Gb I changed the link during system working and then check speed using ethtool/mii-tool.
I think phy also should do autonegotiation (I'm not sure this is just for the SGMII). Without phy auto negotiation gmac is not working.

Quoted 7 lines
Quoted 4 lines

OK, I'll try to check functionality and make macros. Anyway as a first step, I want to complete to the code regarding ANE (ctrl function, macros, ethtool support for link status etc..) I'll send new code before making patch soon.

thanks you

I think whenever link is changed, phy->state is changed and call stmmac_adjust_link. It would update gmac's link.
I can get autonegotiation complete and link change irqs if we need something we can add code in the handler but I'm not sure which one is need yet. As of now I just added phy_state = PHY_CHANGELINK as a test code in the link change irq handler.

@@ -1624,8 +1629,43 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id)

                                priv->xstats.mmc_rx_csum_offload_irq_n++;
                        if (status & core_irq_receive_pmt_irq)
                                priv->xstats.irq_receive_pmt_irq_n++;

+ if (status & core_irq_pcs_autoneg_complete)
+ priv->core_pcs_an = true;
+ if (status & core_irq_pcs_link_status_change) {
+ priv->core_pcs_link_change = true;
+ status = readl(priv->ioaddr +
GMAC_AN_STATUS);
+ if (status & GMAC_AN_STATUS_LS)
+ if ((priv->speed != phy->speed) ||
(priv->oldduplex != phy->duplex))
+ phy->state = PHY_CHANGELINK; /* for
test */
+ }

                        /* For LPI we need to save the tx status */
                        if (status & core_irq_tx_path_in_lpi_mode) {

I have a question, how to hand over phy's irq number, as I analyzed phydev->irq is irqlist and irqlist is like below but I can not find a way to set phy's irq number.
How to register or set priv->mii_irq or mdio_bus_data->irqs.

        if (mdio_bus_data->irqs)
                irqlist = mdio_bus_data->irqs;
        else
                irqlist = priv->mii_irq; 

I added some defines for AN like below
@@ -97,6 +97,20 @@ enum power_event {
#define GMAC_TBI 0x000000d4 /* TBI extend status */
#define GMAC_GMII_STATUS 0x000000d8 /* S/R-GMII status */

+/* AN Configuration defines */
+#define GMAC_AN_CTRL_RAN 0x00000200 /* Restart Auto-Negotiation
*/
+#define GMAC_AN_CTRL_ANE 0x00001000 /* Auto-Negotiation Enable
*/
+#define GMAC_AN_CTRL_ELE 0x00004000 /* External Loopback Enable
*/

+#define GMAC_AN_CTRL_ECD       0x00010000      /* Enable Comma Detect */
+#define GMAC_AN_CTRL_LR        0x00020000      /* Lock to Reference */
+#define GMAC_AN_CTRL_SGMRAL    0x00040000      /* SGMII RAL Control */

+
+/* AN Status defines */
+#define GMAC_AN_STATUS_LS 0x00000004 /* Link Status 0:down 1:up
*/
+#define GMAC_AN_STATUS_ANA 0x00000008 /* Auto-Negotiation Ability
*/
+#define GMAC_AN_STATUS_ANC 0x00000020 /* Auto-Negotiation Complete
*/
+#define GMAC_AN_STATUS_ES 0x00000100 /* Extended Status */
+
/* GMAC Configuration defines */
#define GMAC_CONTROL_TC 0x01000000 /* Transmit Conf. in
RGMII/SGMII */
#define GMAC_CONTROL_WD 0x00800000 /* Disable Watchdog on
receive */

Quoted 29 lines
Quoted 29 lines
Quoted 8 lines

/* RGMI/SGMII defines */
#define GMAC_CTRL_ANE_SGMII_RAL (1 << 18)
#define GMAC_CTRL_ANE_EN (1 << 12)
#define GMAC_CTRL_ANE_RESTART (1 << 9)

The handler should store the link status that will be used to pass the

info to

Quoted 5 lines

the ethtool for example. We need to manage speed and duplex etc.

What happens if you run "ethtool eth0" command? Or if you run mii-tool?
I expect to get the right speed and duplex at least.

So far, I can get right data speed and duplex and autoneg.

Quoted 4 lines

Concerning the stmmac_set_pauseparam I'm also not sure you are doing the right thing. Note that you are not restarting the ANE at all ... (this is

what the

Quoted 8 lines

phy_start_aneg does). If set the bit 12 then you are enabling the ane. To restart it, you need to set the bit 9 in the reg 48.

I can support you on all the points above. Let me know.

BR,
peppe

Quoted 7 lines
Quoted 1 line

OK, thank you and happy new year.

Also to you :-)

let me know for any progresses etc.

Peppe

BR,
Byungho An

Quoted 11 lines
Quoted 11 lines

Byungho An

Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
+
   	/* Request the IRQ lines */
   	ret = request_irq(dev->irq, stmmac_interrupt,
   			 IRQF_SHARED, dev->name, dev);
#5 lore raw

Hello Byungho

sorry for my late reply. I'm attaching two patches built for net-next as we had clarified. I had written the first patch long time ago and on top of it I have added some part of your code below with some fixes (see also the comments inline below).

This work is not yet completed but I do hope these two patches will help you to complete all. Unfortunately, I cannot do any tests because I have no HW that supports PCS. :-(

In the second patch, take a look at the comment that reports the missing parts. For example, ethtool, SGMII etc.

I wonder if you could review/test the two patches on your side. Also I hope you can improve all adding the missing features (that is what you were already doing).

If you agree, you could also re-send *all* to the mailing list to be finally reviewed.

Quoted 2 lines · Byungho An

On 1/23/2013 1:43 PM, Giuseppe CAVALLARO write:

[snip]

Quoted 19 lines
Quoted 1 line

I modified this part like below

(quoted diff) +2 -6
@@ -1044,12 +1046,8 @@ static int stmmac_open(struct net_device *dev)
         priv->hw->mac->core_init(priv->ioaddr);
 
         /* Enable auto-negotiation for SGMII, TBI or RTBI */
-       if (interface == PHY_INTERFACE_MODE_SGMII ||
-           interface == PHY_INTERFACE_MODE_TBI ||
-           interface == PHY_INTERFACE_MODE_RTBI) {
-               if (priv->phydev->autoneg)
-                       priv->hw->mac->set_autoneg(priv->ioaddr);
-       }
+       if (priv->dma_cap.pcs)
+               priv->hw->mac->ctrl_ane(priv->ioaddr, 0);
 
         /* Request the IRQ lines */
         ret = request_irq(dev->irq, stmmac_interrupt,
Quoted 3 lines

As you may know, auto-negotiation is essential for SGMII, TBI, or RTBI interface.

good, add it on top of the second patch.

Quoted 12 lines

And ctrl_ane funciont is like that

(quoted diff) +6 -0
@@ -311,6 +317,18 @@ static void dwmac1000_set_autoneg(void __iomem *ioaddr)
         writel(value, ioaddr + GMAC_AN_CTRL);
  }
 
+static void dwmac1000_ctrl_ane(void __iomem *ioaddr, bool restart)
+{
+       u32 value;
+
+       value = readl(ioaddr + GMAC_AN_CTRL);
+     /* auto negotiation enable and External Loopback enable */

Review static void dwmac1000_set_autoneg(void __iomem *ioaddr)

Quoted 10 lines
(quoted diff) +7 -0
+       value = GMAC_AN_CTRL__ANE | GMAC_AN_CTRL__ELE;
+
+       if (restart)
+               value |= GMAC_AN_CTRL_RAN;
+
+       writel(value, ioaddr + GMAC_AN_CTRL);
+}
 
  static const struct stmmac_ops dwmac1000_ops = {
         .core_init = dwmac1000_core_init,

well done and added in the second patch.

[snip]

Quoted 22 lines

I've changed restart AN like below.

(quoted diff) +14 -0
@@ -610,6 +607,27 @@ static int stmmac_set_coalesce(struct net_device *dev,
         return 0;
  }
 
+static int
+stmmac_nway_reset(struct net_device *netdev)
+{
+       struct stmmac_priv *priv = netdev_priv(netdev);
+       struct phy_device *phy = priv->phydev;
+       int ret = 0;
+
+       spin_lock(&priv->lock);
+
+       if (netif_running(netdev)) {
+               phy_stop(phy);
+               phy_start(phy);
+               ret = phy_start_aneg(phy);
+               if (priv->dma_cap.pcs)

Review static int stmmac_set_coalesce(struct net_device *dev, · line 633

Quoted 10 lines
(quoted diff) +7 -0
+                       priv->hw->mac->ctrl_ane(priv->ioaddr, true);
+       }
+
+       spin_unlock(&priv->lock);
+       return ret;
+}
+
  static const struct ethtool_ops stmmac_ethtool_ops = {
         .begin = stmmac_check_if_running,
         .get_drvinfo = stmmac_ethtool_getdrvinfo,

we have to review this. I expect to have a new patch that includes the ethtool support but, at first glance, the stmmac_nway_reset should only call the ctrl_ane.

pay attention that also some other ethtool functions have to be fixed for this support.

[snip]

Quoted 33 lines

I think whenever link is changed, phy->state is changed and call stmmac_adjust_link. It would update gmac's link.
I can get autonegotiation complete and link change irqs if we need something we can add code in the handler but I'm not sure which one is need yet. As of now I just added phy_state = PHY_CHANGELINK as a test code in the link change irq handler.

(quoted diff) +8 -0
@@ -1624,8 +1629,43 @@ static irqreturn_t stmmac_interrupt(int irq, void
 *dev_id)
                                 priv->xstats.mmc_rx_csum_offload_irq_n++;
                         if (status & core_irq_receive_pmt_irq)
                                 priv->xstats.irq_receive_pmt_irq_n++;
+                       if (status & core_irq_pcs_autoneg_complete)
+                                priv->core_pcs_an = true;
+                       if (status & core_irq_pcs_link_status_change) {
+                               priv->core_pcs_link_change = true;
+                               status = readl(priv->ioaddr +
 GMAC_AN_STATUS);
+                               if (status & GMAC_AN_STATUS_LS)
+                                       if ((priv->speed != phy->speed) ||
 (priv->oldduplex != phy->duplex))
+                                       phy->state = PHY_CHANGELINK;  /* for

test */
+ }

                         /* For LPI we need to save the tx status */
                         if (status & core_irq_tx_path_in_lpi_mode) {

I have a question, how to hand over phy's irq number, as I analyzed phydev->irq is irqlist and irqlist is like below but I can not find a way to set phy's irq number.
How to register or set priv->mii_irq or mdio_bus_data->irqs.

Quoted 4 lines
         if (mdio_bus_data->irqs)
                 irqlist = mdio_bus_data->irqs;
         else
                 irqlist = priv->mii_irq;

I had added something in my first patch that should be ok.

Quoted 27 lines

I added some defines for AN like below

(quoted diff) +10 -0
@@ -97,6 +97,20 @@ enum power_event {
  #define GMAC_TBI       0x000000d4      /* TBI extend status */
  #define GMAC_GMII_STATUS 0x000000d8    /* S/R-GMII status */
 
+/* AN Configuration defines */
+#define GMAC_AN_CTRL_RAN       0x00000200      /* Restart Auto-Negotiation
 */
+#define GMAC_AN_CTRL_ANE       0x00001000      /* Auto-Negotiation Enable
 */
+#define GMAC_AN_CTRL_ELE       0x00004000      /* External Loopback Enable
 */
+#define GMAC_AN_CTRL_ECD       0x00010000      /* Enable Comma Detect */
+#define GMAC_AN_CTRL_LR        0x00020000      /* Lock to Reference */
+#define GMAC_AN_CTRL_SGMRAL    0x00040000      /* SGMII RAL Control */
+
+/* AN Status defines */
+#define GMAC_AN_STATUS_LS      0x00000004      /* Link Status 0:down 1:up

*/
+#define GMAC_AN_STATUS_ANA 0x00000008 /* Auto-Negotiation Ability
*/
+#define GMAC_AN_STATUS_ANC 0x00000020 /* Auto-Negotiation Complete
*/

(quoted diff) +2 -0
+#define GMAC_AN_STATUS_ES      0x00000100      /* Extended Status */
+
  /* GMAC Configuration defines */
  #define GMAC_CONTROL_TC        0x01000000      /* Transmit Conf. in
Quoted 3 lines

RGMII/SGMII */
#define GMAC_CONTROL_WD 0x00800000 /* Disable Watchdog on
receive */

ok, these are in the second patch

Quoted 1 line

From 13a4be74f7a4a7d180cae25f4528dc0a78bf5d7c Mon Sep 17 00:00:00 2001

From: Giuseppe CAVALLARO <[email protected]>
Date: Mon, 17 Dec 2012 07:22:18 +0100
Subject: [net-next.git 1/2] stmmac: start adding pcs and rgmii core irq

This patch starts adding in the main ISR the management of the PCS and RGMII/SGMII core interrupts. This is to help further development on this area. Currently the core irq handler only clears the PCS and S-R_MII interrupts and reports the event in the ethtool stats.

---
 drivers/net/ethernet/stmicro/stmmac/common.h       |   25 ++++++-----
 drivers/net/ethernet/stmicro/stmmac/dwmac1000.h    |    5 +-
 .../net/ethernet/stmicro/stmmac/dwmac1000_core.c   |   44 ++++++++++++-------
 .../net/ethernet/stmicro/stmmac/dwmac100_core.c    |    3 +-
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   |    3 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |   24 ++---------
 6 files changed, 54 insertions(+), 50 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +14 -11
index 186d148..1db761c 100644
@@ -117,6 +117,10 @@ struct stmmac_extra_stats {
 	unsigned long irq_rx_path_in_lpi_mode_n;
 	unsigned long irq_rx_path_exit_lpi_mode_n;
 	unsigned long phy_eee_wakeup_error_n;
+	/* PCS */
+	unsigned long irq_pcs_ane_n;
+	unsigned long irq_pcs_link_n;
+	unsigned long irq_rgmii_n;
 };
 
 /* CSR Frequency Access Defines*/
@@ -194,16 +198,14 @@ enum dma_irq_status {
 	handle_tx = 0x8,
 };
 
-enum core_specific_irq_mask {
-	core_mmc_tx_irq = 1,
-	core_mmc_rx_irq = 2,
-	core_mmc_rx_csum_offload_irq = 4,
-	core_irq_receive_pmt_irq = 8,
-	core_irq_tx_path_in_lpi_mode = 16,
-	core_irq_tx_path_exit_lpi_mode = 32,
-	core_irq_rx_path_in_lpi_mode = 64,
-	core_irq_rx_path_exit_lpi_mode = 128,
-};
+#define	CORE_IRQ_TX_PATH_IN_LPI_MODE	(1 << 1)
+#define	CORE_IRQ_TX_PATH_EXIT_LPI_MODE	(1 << 2)
+#define	CORE_IRQ_RX_PATH_IN_LPI_MODE	(1 << 3)
+#define	CORE_IRQ_RX_PATH_EXIT_LPI_MODE	(1 << 4)
+
+#define	CORE_PCS_ANE_COMPLETE		(1 << 5)
+#define	CORE_PCS_LINK_STATUS		(1 << 6)
+#define	CORE_RGMII_IRQ			(1 << 7)
 
 /* DMA HW capabilities */
 struct dma_features {
@@ -327,7 +329,8 @@ struct stmmac_ops {
 	/* Dump MAC registers */
 	void (*dump_regs) (void __iomem *ioaddr);
 	/* Handle extra events on specific interrupts hw dependent */
-	int (*host_irq_status) (void __iomem *ioaddr);
+	int (*host_irq_status) (void __iomem *ioaddr,
+				struct stmmac_extra_stats *x);
 	/* Multicast filter setting */
 	void (*set_filter) (struct net_device *dev, int id);
 	/* Flow control setting */
drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +3 -2
index 7ad56af..8a8c39f 100644
@@ -89,13 +89,14 @@ enum power_event {
 				(reg * 8))
 #define GMAC_MAX_PERFECT_ADDRESSES	32
 
+/* PCS registers (AN/TBI/SGMII/RGMII) offset */
 #define GMAC_AN_CTRL	0x000000c0	/* AN control */
 #define GMAC_AN_STATUS	0x000000c4	/* AN status */
 #define GMAC_ANE_ADV	0x000000c8	/* Auto-Neg. Advertisement */
-#define GMAC_ANE_LINK	0x000000cc	/* Auto-Neg. link partener ability */
+#define GMAC_ANE_LPA	0x000000cc	/* Auto-Neg. link partener ability */
 #define GMAC_ANE_EXP	0x000000d0	/* ANE expansion */
 #define GMAC_TBI	0x000000d4	/* TBI extend status */
-#define GMAC_GMII_STATUS 0x000000d8	/* S/R-GMII status */
+#define GMAC_S_R_GMII	0x000000d8	/* SGMII RGMII status */
 
 /* GMAC Configuration defines */
 #define GMAC_CONTROL_TC	0x01000000	/* Transmit Conf. in RGMII/SGMII */
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +28 -16

86 lines not on this page · raw message

drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c +2 -1
index f83210e..cb86a58 100644
@@ -72,7 +72,8 @@ static int dwmac100_rx_ipc_enable(void __iomem *ioaddr)
 	return 0;
 }
 
-static int dwmac100_irq_status(void __iomem *ioaddr)
+static int dwmac100_irq_status(void __iomem *ioaddr,
+			       struct stmmac_extra_stats *x)
 {
 	return 0;
 }
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +3 -0
index d1ac39c..e15004f 100644
@@ -108,6 +108,9 @@ static const struct stmmac_stats stmmac_gstrings_stats[] = {
 	STMMAC_STAT(irq_rx_path_in_lpi_mode_n),
 	STMMAC_STAT(irq_rx_path_exit_lpi_mode_n),
 	STMMAC_STAT(phy_eee_wakeup_error_n),
+	/* PCS */
+	STMMAC_STAT(irq_pcs_ane_n),
+	STMMAC_STAT(irq_rgmii_n),
 };
 #define STMMAC_STATS_LEN ARRAY_SIZE(stmmac_gstrings_stats)
 
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -20
index 39c6c55..1f2f349 100644
@@ -1604,30 +1604,14 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
 	/* To handle GMAC own interrupts */
 	if (priv->plat->has_gmac) {
 		int status = priv->hw->mac->host_irq_status((void __iomem *)
-							    dev->base_addr);
+							    dev->base_addr,
+							    &priv->xstats);
 		if (unlikely(status)) {
-			if (status & core_mmc_tx_irq)
-				priv->xstats.mmc_tx_irq_n++;
-			if (status & core_mmc_rx_irq)
-				priv->xstats.mmc_rx_irq_n++;
-			if (status & core_mmc_rx_csum_offload_irq)
-				priv->xstats.mmc_rx_csum_offload_irq_n++;
-			if (status & core_irq_receive_pmt_irq)
-				priv->xstats.irq_receive_pmt_irq_n++;
-
 			/* For LPI we need to save the tx status */
-			if (status & core_irq_tx_path_in_lpi_mode) {
-				priv->xstats.irq_tx_path_in_lpi_mode_n++;
+			if (status & CORE_IRQ_TX_PATH_IN_LPI_MODE)
 				priv->tx_path_in_lpi_mode = true;
-			}
-			if (status & core_irq_tx_path_exit_lpi_mode) {
-				priv->xstats.irq_tx_path_exit_lpi_mode_n++;
+			if (status & CORE_IRQ_TX_PATH_EXIT_LPI_MODE)
 				priv->tx_path_in_lpi_mode = false;
-			}
-			if (status & core_irq_rx_path_in_lpi_mode)
-				priv->xstats.irq_rx_path_in_lpi_mode_n++;
-			if (status & core_irq_rx_path_exit_lpi_mode)
-				priv->xstats.irq_rx_path_exit_lpi_mode_n++;
 		}
 	}
 
Signature · 1 line
1.7.4.4
Quoted 1 line

From 952f89212446f3f346d2ade62aada1d7c06842b0 Mon Sep 17 00:00:00 2001

From: Giuseppe Cavallaro <[email protected]>
Date: Fri, 22 Feb 2013 12:24:00 +0100
Subject: [net-next.git 2/2] stmmac: start managing pcs RGMII modes and
restart ANE

This patch adds the minimal support to manage the PCS modes (RGMII) and restart the ANE when the interface is opened.

Currently the following main things are missing:

o SGMII/TBI support
o manage the advertisement register (e.g. reg 50)
o manage pause via ADV.
o manage the Auto-Nogotiation Ability Register (51)
o improve the ethtool.

Thanks to Byungho that wrote some part of this code.

---
 drivers/net/ethernet/stmicro/stmmac/common.h       |    7 +++
 drivers/net/ethernet/stmicro/stmmac/dwmac1000.h    |   20 +++++++
 .../net/ethernet/stmicro/stmmac/dwmac1000_core.c   |   15 +++++
 drivers/net/ethernet/stmicro/stmmac/stmmac.h       |    1 +
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   |   13 +++++
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |   55 +++++++++++++++----
 6 files changed, 99 insertions(+), 12 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +7 -0
index 1db761c..04134ad 100644
@@ -142,6 +142,12 @@ struct stmmac_extra_stats {
 #define FLOW_TX		2
 #define FLOW_AUTO	(FLOW_TX | FLOW_RX)
 
+/* PCS defines */
+#define STMMAC_PCS_RGMII	(1<<0)
+#define STMMAC_PCS_SGMII	(1<<1)
+#define STMMAC_PCS_TBI		(1<<2)
+#define STMMAC_PCS_RTBI		(1<<1)
+
 #define SF_DMA_MODE 1 /* DMA STORE-AND-FORWARD Operation Mode */
 
 /* DAM HW feature register fields */
@@ -347,6 +353,7 @@ struct stmmac_ops {
 	void (*reset_eee_mode) (void __iomem *ioaddr);
 	void (*set_eee_timer) (void __iomem *ioaddr, int ls, int tw);
 	void (*set_eee_pls) (void __iomem *ioaddr, int link);
+	void (*ctrl_ane) (void __iomem *ioaddr, bool restart);
 };
 
 struct mac_link {
drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +20 -0
index 8a8c39f..5cfd4d2 100644
@@ -98,6 +98,24 @@ enum power_event {
 #define GMAC_TBI	0x000000d4	/* TBI extend status */
 #define GMAC_S_R_GMII	0x000000d8	/* SGMII RGMII status */
 
+/* AN Configuration defines */
+#define GMAC_AN_CTRL_RAN	0x00000200 /* Restart Auto-Negotiation */
+#define GMAC_AN_CTRL_ANE	0x00001000 /* Auto-Negotiation Enable */
+#define GMAC_AN_CTRL_ELE	0x00004000 /* External Loopback Enable */
+#define GMAC_AN_CTRL_ECD	0x00010000 /* Enable Comma Detect */
+#define GMAC_AN_CTRL_LR		0x00020000 /* Lock to Reference */
+#define GMAC_AN_CTRL_SGMRAL	0x00040000 /* SGMII RAL Control */
+
+/* AN Status defines */
+#define GMAC_AN_STATUS_LS	0x00000004 /* Link Status 0:down 1:up */
+#define GMAC_AN_STATUS_ANA	0x00000008 /* Auto-Negotiation Ability */
+#define GMAC_AN_STATUS_ANC	0x00000020 /* Auto-Negotiation Complete */
+#define GMAC_AN_STATUS_ES	0x00000100 /* Extended Status */
+
+ /* GMAC Configuration defines */
+#define GMAC_CONTROL_TC	0x01000000 /* Transmit Conf. in RGMII/SGMII */
+#define GMAC_CONTROL_WD	0x00800000 /* Disable Watchdog on receive */
+
 /* GMAC Configuration defines */
 #define GMAC_CONTROL_TC	0x01000000	/* Transmit Conf. in RGMII/SGMII */
 #define GMAC_CONTROL_WD	0x00800000	/* Disable Watchdog on receive */
@@ -231,5 +249,7 @@ enum rtc_control {
 #define GMAC_MMC_TX_INTR   0x108
 #define GMAC_MMC_RX_CSUM_OFFLOAD   0x208
 
+
+
 extern const struct stmmac_dma_ops dwmac1000_dma_ops;
 #endif /* __DWMAC1000_H__ */
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +15 -0
index ff4c79e..f59366d 100644
@@ -309,6 +309,20 @@ static void  dwmac1000_set_eee_timer(void __iomem *ioaddr, int ls, int tw)
 	writel(value, ioaddr + LPI_TIMER_CTRL);
 }
 
+static void dwmac1000_ctrl_ane(void __iomem *ioaddr, bool restart)
+{
+	u32 value;
+
+	value = readl(ioaddr + GMAC_AN_CTRL);
+	/* auto negotiation enable and External Loopback enable */
+	value = GMAC_AN_CTRL_ANE | GMAC_AN_CTRL_ELE;
+
+	if (restart)
+		value |= GMAC_AN_CTRL_RAN;
+
+	writel(value, ioaddr + GMAC_AN_CTRL);
+}
+
 static const struct stmmac_ops dwmac1000_ops = {
 	.core_init = dwmac1000_core_init,
 	.rx_ipc = dwmac1000_rx_ipc_enable,
@@ -323,6 +337,7 @@ static const struct stmmac_ops dwmac1000_ops = {
 	.reset_eee_mode =  dwmac1000_reset_eee_mode,
 	.set_eee_timer =  dwmac1000_set_eee_timer,
 	.set_eee_pls =  dwmac1000_set_eee_pls,
+	.ctrl_ane = dwmac1000_ctrl_ane,
 };
 
 struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +1 -0
index b05df89..197497c 100644
@@ -93,6 +93,7 @@ struct stmmac_priv {
 	u32 tx_coal_timer;
 	int use_riwt;
 	u32 rx_riwt;
+	int pcs;
 };
 
 extern int phyaddr;
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +13 -0
index e15004f..71b58ea 100644
@@ -222,6 +222,10 @@ static int stmmac_ethtool_getsettings(struct net_device *dev,
 	struct stmmac_priv *priv = netdev_priv(dev);
 	struct phy_device *phy = priv->phydev;
 	int rc;
+
+	if (priv->pcs) /* FIXME */
+		return -EOPNOTSUPP;
+
 	if (phy == NULL) {
 		pr_err("%s: %s: PHY is not registered\n",
 		       __func__, dev->name);
@@ -246,6 +250,9 @@ static int stmmac_ethtool_setsettings(struct net_device *dev,
 	struct phy_device *phy = priv->phydev;
 	int rc;
 
+	if (priv->pcs) /* FIXME */
+		return -EOPNOTSUPP;
+
 	spin_lock(&priv->lock);
 	rc = phy_ethtool_sset(phy, cmd);
 	spin_unlock(&priv->lock);
@@ -317,6 +324,9 @@ stmmac_get_pauseparam(struct net_device *netdev,
 
 	spin_lock(&priv->lock);
 
+	if (priv->pcs)
+		return -EOPNOTSUPP;
+
 	pause->rx_pause = 0;
 	pause->tx_pause = 0;
 	pause->autoneg = priv->phydev->autoneg;
@@ -338,6 +348,9 @@ stmmac_set_pauseparam(struct net_device *netdev,
 	int new_pause = FLOW_OFF;
 	int ret = 0;
 
+	if (priv->pcs)
+		return -EOPNOTSUPP;
+
 	spin_lock(&priv->lock);
 
 	if (pause->rx_pause)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +43 -12

91 lines not on this page · raw message

Signature · 1 line
1.7.4.4
#6 lore raw

Hi Peppe,

I'll check patches and test on my side soon.
After that share with you.

Thank you.

Quoted 123 lines

Hello Byungho

sorry for my late reply. I'm attaching two patches built for net-next as we had clarified. I had written the first patch long time ago and on top of it I have added some part of your code below with some fixes (see also the comments inline below).

This work is not yet completed but I do hope these two patches will help you to complete all. Unfortunately, I cannot do any tests because I have no HW that supports PCS. :-(

In the second patch, take a look at the comment that reports the missing parts. For example, ethtool, SGMII etc.

I wonder if you could review/test the two patches on your side. Also I hope you can improve all adding the missing features (that is what you were already doing).

If you agree, you could also re-send *all* to the mailing list to be finally reviewed.

Quoted 2 lines · Byungho An

On 1/23/2013 1:43 PM, Giuseppe CAVALLARO write:

[snip]

Quoted 19 lines
Quoted 1 line

I modified this part like below

(quoted diff) +2 -6
@@ -1044,12 +1046,8 @@ static int stmmac_open(struct net_device *dev)
         priv->hw->mac->core_init(priv->ioaddr);
 
         /* Enable auto-negotiation for SGMII, TBI or RTBI */
-       if (interface == PHY_INTERFACE_MODE_SGMII ||
-           interface == PHY_INTERFACE_MODE_TBI ||
-           interface == PHY_INTERFACE_MODE_RTBI) {
-               if (priv->phydev->autoneg)
-                       priv->hw->mac->set_autoneg(priv->ioaddr);
-       }
+       if (priv->dma_cap.pcs)
+               priv->hw->mac->ctrl_ane(priv->ioaddr, 0);
 
         /* Request the IRQ lines */
         ret = request_irq(dev->irq, stmmac_interrupt,
Quoted 3 lines

As you may know, auto-negotiation is essential for SGMII, TBI, or RTBI interface.

good, add it on top of the second patch.

Review static void dwmac1000_set_autoneg(void __iomem

Quoted 3 lines

And ctrl_ane funciont is like that

(quoted diff) +0 -0
@@ -311,6 +317,18 @@ static void dwmac1000_set_autoneg(void __iomem

*ioaddr)

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +4 -0
         writel(value, ioaddr + GMAC_AN_CTRL);
  }
 
+static void dwmac1000_ctrl_ane(void __iomem *ioaddr, bool restart) {
+       u32 value;
+
+       value = readl(ioaddr + GMAC_AN_CTRL);

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c static void dwmac1000_set_eee_timer(void __iomem *ioaddr, int ls, int tw) · line 327

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +7 -0
+     /* auto negotiation enable and External Loopback enable */
+       value = GMAC_AN_CTRL__ANE | GMAC_AN_CTRL__ELE;
+
+       if (restart)
+               value |= GMAC_AN_CTRL_RAN;
+
+       writel(value, ioaddr + GMAC_AN_CTRL); }
 
  static const struct stmmac_ops dwmac1000_ops = {
         .core_init = dwmac1000_core_init,

well done and added in the second patch.

[snip]

Review static int stmmac_set_coalesce(struct net_device

Quoted 3 lines

I've changed restart AN like below.

(quoted diff) +0 -0
@@ -610,6 +607,27 @@ static int stmmac_set_coalesce(struct net_device

*dev,

Quoted 18 lines
(quoted diff) +13 -0
         return 0;
  }
 
+static int
+stmmac_nway_reset(struct net_device *netdev) {
+       struct stmmac_priv *priv = netdev_priv(netdev);
+       struct phy_device *phy = priv->phydev;
+       int ret = 0;
+
+       spin_lock(&priv->lock);
+
+       if (netif_running(netdev)) {
+               phy_stop(phy);
+               phy_start(phy);
+               ret = phy_start_aneg(phy);
+               if (priv->dma_cap.pcs)

Review static int stmmac_set_coalesce(struct net_device · line 632

Quoted 10 lines
(quoted diff) +7 -0
+                       priv->hw->mac->ctrl_ane(priv->ioaddr, true);
+       }
+
+       spin_unlock(&priv->lock);
+       return ret;
+}
+
  static const struct ethtool_ops stmmac_ethtool_ops = {
         .begin = stmmac_check_if_running,
         .get_drvinfo = stmmac_ethtool_getdrvinfo,

we have to review this. I expect to have a new patch that includes the ethtool support but, at first glance, the stmmac_nway_reset should only call the ctrl_ane.

pay attention that also some other ethtool functions have to be fixed for this support.

[snip]

Quoted 4 lines

I think whenever link is changed, phy->state is changed and call stmmac_adjust_link. It would update gmac's link.
I can get autonegotiation complete and link change irqs if we need something we can add code in the handler but I'm not sure which one is

Quoted 8 lines

need yet.

Quoted 7 lines

As of now I just added phy_state = PHY_CHANGELINK as a test code in the link change irq handler.

(quoted diff) +0 -0
@@ -1624,8 +1629,43 @@ static irqreturn_t stmmac_interrupt(int irq,

void
*dev_id)

priv->xstats.mmc_rx_csum_offload_irq_n++;

Quoted 33 lines
Quoted 26 lines

if (status & core_irq_receive_pmt_irq)
priv->xstats.irq_receive_pmt_irq_n++;

(quoted diff) +5 -0
+                       if (status & core_irq_pcs_autoneg_complete)
+                                priv->core_pcs_an = true;
+                       if (status & core_irq_pcs_link_status_change) {
+                               priv->core_pcs_link_change = true;
+                               status = readl(priv->ioaddr +

GMAC_AN_STATUS);

(quoted diff) +3 -0
+                               if (status & GMAC_AN_STATUS_LS)
+                                       if ((priv->speed !=
+ phy->speed) ||

(priv->oldduplex != phy->duplex))
+ phy->state = PHY_CHANGELINK;
+ /* for
test */
+ }

                         /* For LPI we need to save the tx status */
                         if (status & core_irq_tx_path_in_lpi_mode) {

I have a question, how to hand over phy's irq number, as I analyzed phydev->irq is irqlist and irqlist is like below but I can not find a phydev->way to
set phy's irq number.
How to register or set priv->mii_irq or mdio_bus_data->irqs.

Quoted 4 lines
         if (mdio_bus_data->irqs)
                 irqlist = mdio_bus_data->irqs;
         else
                 irqlist = priv->mii_irq;

I had added something in my first patch that should be ok.

Quoted 7 lines

Review

Quoted 7 lines

I added some defines for AN like below @@ -97,6 +97,20 @@ enum power_event {
#define GMAC_TBI 0x000000d4 /* TBI extend status */
#define GMAC_GMII_STATUS 0x000000d8 /* S/R-GMII status */

(quoted diff) +2 -0
+/* AN Configuration defines */
+#define GMAC_AN_CTRL_RAN       0x00000200      /* Restart

Auto-Negotiation

Quoted 2 lines
Quoted 2 lines

*/
+#define GMAC_AN_CTRL_ANE 0x00001000 /* Auto-Negotiation

Enable

Quoted 2 lines
Quoted 2 lines

*/
+#define GMAC_AN_CTRL_ELE 0x00004000 /* External Loopback

Enable

Quoted 2 lines
Quoted 2 lines

*/
+#define GMAC_AN_CTRL_ECD 0x00010000 /* Enable Comma Detect

*/

Quoted 5 lines

drivers/net/ethernet/stmicro/stmmac/dwmac1000.h enum power_event {

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +5 -0
+#define GMAC_AN_CTRL_LR        0x00020000      /* Lock to Reference */
+#define GMAC_AN_CTRL_SGMRAL    0x00040000      /* SGMII RAL Control */
+
+/* AN Status defines */
+#define GMAC_AN_STATUS_LS      0x00000004      /* Link Status 0:down

1:up

Quoted 16 lines
Quoted 2 lines

*/
+#define GMAC_AN_STATUS_ANA 0x00000008 /* Auto-Negotiation

Ability

Quoted 2 lines

*/
+#define GMAC_AN_STATUS_ANC 0x00000020 /* Auto-Negotiation

Complete

Quoted 8 lines

*/

drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +2 -0
+#define GMAC_AN_STATUS_ES      0x00000100      /* Extended Status */
+
  /* GMAC Configuration defines */
  #define GMAC_CONTROL_TC        0x01000000      /* Transmit Conf. in

RGMII/SGMII */
#define GMAC_CONTROL_WD 0x00800000 /* Disable Watchdog on
receive */

ok, these are in the second patch

#7 lore raw
In reply to Giuseppe CAVALLARO

Hello Peppe,

Quoted 7 lines

Hello Byungho

sorry for my late reply. I'm attaching two patches built for net-next as we had clarified. I had written the first patch long time ago and on top of it I have added some part of your code below with some fixes (see also the comments inline below).

Quoted 8 lines

This work is not yet completed but I do hope these two patches will help you to complete all. Unfortunately, I cannot do any tests because I have no HW that supports PCS. :-(

In the second patch, take a look at the comment that reports the missing parts. For example, ethtool, SGMII etc.

I wonder if you could review/test the two patches on your side.

Looks good to me and it works fine on my hardware platform. Just note, I tested them with some additional stuff which is in stmmac_init_phy() and stmmac_mdio_register() for SGMII.

Quoted 6 lines

Also I hope you can improve all adding the missing features (that is what you were already doing).

If you agree, you could also re-send *all* to the mailing list to be finally reviewed.

Anyway, in my opinion, you can take them in your tree for now with my tested-by if you want. Of course, I'll implement additional patches as you requested on top of them for remained stuff such as SGMII, TBI, ethtool and so on.
I think those should be separated for each purpose and we can add and modify after those two patches.

Quoted 22 lines · Giuseppe CAVALLARO
Quoted 2 lines · Byungho An

On 1/23/2013 1:43 PM, Giuseppe CAVALLARO write:

[snip]

Quoted 16 lines
Quoted 1 line

I modified this part like below

(quoted diff) +2 -6
@@ -1044,12 +1046,8 @@ static int stmmac_open(struct net_device *dev)
         priv->hw->mac->core_init(priv->ioaddr);
 
         /* Enable auto-negotiation for SGMII, TBI or RTBI */
-       if (interface == PHY_INTERFACE_MODE_SGMII ||
-           interface == PHY_INTERFACE_MODE_TBI ||
-           interface == PHY_INTERFACE_MODE_RTBI) {
-               if (priv->phydev->autoneg)
-                       priv->hw->mac->set_autoneg(priv->ioaddr);
-       }
+       if (priv->dma_cap.pcs)
+               priv->hw->mac->ctrl_ane(priv->ioaddr, 0);
 
Quoted 8 lines
Quoted 6 lines
(quoted diff) +0 -0
         /* Request the IRQ lines */
         ret = request_irq(dev->irq, stmmac_interrupt,

As you may know, auto-negotiation is essential for SGMII, TBI, or RTBI interface.

good, add it on top of the second patch.

this part is already in the second patch. I think restart flag should be 0 because auto-negotiation does not restarted in the stmmac_open function.

Quoted 66 lines

Review static void dwmac1000_set_autoneg(void __iomem

Quoted 4 lines

And ctrl_ane funciont is like that

(quoted diff) +0 -0
@@ -311,6 +317,18 @@ static void dwmac1000_set_autoneg(void __iomem

*ioaddr)

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +6 -0
         writel(value, ioaddr + GMAC_AN_CTRL);
  }
 
+static void dwmac1000_ctrl_ane(void __iomem *ioaddr, bool restart)
+{
+       u32 value;
+
+       value = readl(ioaddr + GMAC_AN_CTRL);
+     /* auto negotiation enable and External Loopback enable */

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c static void dwmac1000_set_eee_timer(void __iomem *ioaddr, int ls, int tw) · line 327

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +7 -0
+       value = GMAC_AN_CTRL__ANE | GMAC_AN_CTRL__ELE;
+
+       if (restart)
+               value |= GMAC_AN_CTRL_RAN;
+
+       writel(value, ioaddr + GMAC_AN_CTRL);
+}
 
  static const struct stmmac_ops dwmac1000_ops = {
         .core_init = dwmac1000_core_init,

well done and added in the second patch.

[snip]

Review static int stmmac_set_coalesce(struct net_device

Quoted 3 lines

I've changed restart AN like below.

(quoted diff) +0 -0
@@ -610,6 +607,27 @@ static int stmmac_set_coalesce(struct net_device

*dev,

Quoted 19 lines
(quoted diff) +14 -0
         return 0;
  }
 
+static int
+stmmac_nway_reset(struct net_device *netdev)
+{
+       struct stmmac_priv *priv = netdev_priv(netdev);
+       struct phy_device *phy = priv->phydev;
+       int ret = 0;
+
+       spin_lock(&priv->lock);
+
+       if (netif_running(netdev)) {
+               phy_stop(phy);
+               phy_start(phy);
+               ret = phy_start_aneg(phy);
+               if (priv->dma_cap.pcs)

Review static int stmmac_set_coalesce(struct net_device · line 633

Quoted 10 lines
(quoted diff) +7 -0
+                       priv->hw->mac->ctrl_ane(priv->ioaddr, true);
+       }
+
+       spin_unlock(&priv->lock);
+       return ret;
+}
+
  static const struct ethtool_ops stmmac_ethtool_ops = {
         .begin = stmmac_check_if_running,
         .get_drvinfo = stmmac_ethtool_getdrvinfo,

we have to review this. I expect to have a new patch that includes the ethtool support but, at first glance, the stmmac_nway_reset should only call the ctrl_ane.

Quoted 3 lines

pay attention that also some other ethtool functions have to be fixed for this support.

I agree with you, I need more time to test ethtool support including advertisement support.

Quoted 6 lines

[snip]

Quoted 3 lines

I think whenever link is changed, phy->state is changed and call stmmac_adjust_link. It would update gmac's link.
I can get autonegotiation complete and link change irqs if we need

something

Quoted 8 lines
Quoted 2 lines

we can add code in the handler but I'm not sure which one is need yet. As of now I just added phy_state = PHY_CHANGELINK as a test code in the

link

Review static irqreturn_t stmmac_interrupt(int irq, void · line 1630

Quoted 5 lines

change irq handler.

(quoted diff) +0 -0
@@ -1624,8 +1629,43 @@ static irqreturn_t stmmac_interrupt(int irq, void
 *dev_id)
 

priv->xstats.mmc_rx_csum_offload_irq_n++;

Quoted 10 lines

Review static irqreturn_t stmmac_interrupt(int irq, void · line 1640

Quoted 10 lines
(quoted diff) +7 -0
                         if (status & core_irq_receive_pmt_irq)
                                 priv->xstats.irq_receive_pmt_irq_n++;
+                       if (status & core_irq_pcs_autoneg_complete)
+                                priv->core_pcs_an = true;
+                       if (status & core_irq_pcs_link_status_change) {
+                               priv->core_pcs_link_change = true;
+                               status = readl(priv->ioaddr +
 GMAC_AN_STATUS);
+                               if (status & GMAC_AN_STATUS_LS)
+                                       if ((priv->speed != phy->speed)

||

Quoted 2 lines

Review static irqreturn_t stmmac_interrupt(int irq, void · line 1642

Quoted 2 lines
(quoted diff) +1 -0
 (priv->oldduplex != phy->duplex))
+                                       phy->state = PHY_CHANGELINK;  /*

for

Quoted 19 lines
Quoted 8 lines

test */
+ }

                         /* For LPI we need to save the tx status */
                         if (status & core_irq_tx_path_in_lpi_mode) {

I have a question, how to hand over phy's irq number, as I analyzed phydev->irq is irqlist and irqlist is like below but I can not find a

way to

Quoted 7 lines

set phy's irq number.
How to register or set priv->mii_irq or mdio_bus_data->irqs.

         if (mdio_bus_data->irqs)
                 irqlist = mdio_bus_data->irqs;
         else
                 irqlist = priv->mii_irq;

I had added something in my first patch that should be ok.

Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac1000.h enum power_event { · line 101

Quoted 7 lines

I added some defines for AN like below

drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +2 -0
@@ -97,6 +97,20 @@ enum power_event {
  #define GMAC_TBI       0x000000d4      /* TBI extend status */
  #define GMAC_GMII_STATUS 0x000000d8    /* S/R-GMII status */
 
+/* AN Configuration defines */
+#define GMAC_AN_CTRL_RAN       0x00000200      /* Restart

Auto-Negotiation

Quoted 2 lines

Review enum power_event { · line 103

Quoted 2 lines
(quoted diff) +1 -0
 */
+#define GMAC_AN_CTRL_ANE       0x00001000      /* Auto-Negotiation

Enable

Quoted 2 lines

Review enum power_event { · line 105

Quoted 2 lines
(quoted diff) +1 -0
 */
+#define GMAC_AN_CTRL_ELE       0x00004000      /* External Loopback

Enable

Quoted 2 lines

Review enum power_event { · line 107

Quoted 2 lines
(quoted diff) +1 -0
 */
+#define GMAC_AN_CTRL_ECD       0x00010000      /* Enable Comma Detect

*/

Quoted 5 lines

drivers/net/ethernet/stmicro/stmmac/dwmac1000.h enum power_event {

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +5 -0
+#define GMAC_AN_CTRL_LR        0x00020000      /* Lock to Reference */
+#define GMAC_AN_CTRL_SGMRAL    0x00040000      /* SGMII RAL Control */
+
+/* AN Status defines */
+#define GMAC_AN_STATUS_LS      0x00000004      /* Link Status 0:down

1:up

Quoted 16 lines
Quoted 2 lines

*/
+#define GMAC_AN_STATUS_ANA 0x00000008 /* Auto-Negotiation

Ability

Quoted 2 lines

*/
+#define GMAC_AN_STATUS_ANC 0x00000020 /* Auto-Negotiation

Complete

Quoted 8 lines

*/

drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +2 -0
+#define GMAC_AN_STATUS_ES      0x00000100      /* Extended Status */
+
  /* GMAC Configuration defines */
  #define GMAC_CONTROL_TC        0x01000000      /* Transmit Conf. in

RGMII/SGMII */
#define GMAC_CONTROL_WD 0x00800000 /* Disable Watchdog on
receive */

ok, these are in the second patch

#8 lore raw
Quoted 11 lines · Byungho An

Hello Peppe,

Quoted 3 lines

If you agree, you could also re-send *all* to the mailing list to be finally reviewed.

Anyway, in my opinion, you can take them in your tree for now with my tested-by if you want. Of course, I'll implement additional patches as you requested on top of them for remained stuff such as SGMII, TBI, ethtool and so on.
I think those should be separated for each purpose and we can add and modify after those two patches.

Ok Byungho, I'm preparing a new update for the stmmac that will also include the initial support for SGMII and RGMII. Thx to have tested it!

Obviously on top of these patches, feel free to add further code. TBI and RTBI are not supported yet.

P.S. in this update I've also added the ethtool missing stuff ;-)

Peppe