Re: [PATCH 3/5] ARM: sun8i: dt: Add DT bindings documentation for Allwinner sun8i-emac

2016-06-06 Thread Corentin LABBE
Le 06/06/2016 16:14, Rob Herring a écrit :
> On Fri, Jun 03, 2016 at 11:56:28AM +0200, LABBE Corentin wrote:
>> This patch adds documentation for Device-Tree bindings for the
>> Allwinner sun8i-emac driver.
>>
>> Signed-off-by: LABBE Corentin 
>> ---
>>  .../bindings/net/allwinner,sun8i-emac.txt  | 64 
>> ++
>>  1 file changed, 64 insertions(+)
>>  create mode 100644 
>> Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt
>>
>> diff --git a/Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt 
>> b/Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt
>> new file mode 100644
>> index 000..cf71a71
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt
>> @@ -0,0 +1,64 @@
>> +* Allwinner sun8i EMAC ethernet controller
>> +
>> +Required properties:
>> +- compatible: "allwinner,sun8i-a83t-emac", "allwinner,sun8i-h3-emac",
>> +or "allwinner,sun50i-a64-emac"
>> +- reg: address and length of the register sets for the device.
>> +- reg-names: should be "emac" and "syscon", matching the register sets
> 
> Is syscon shared with other devices? Your example only has 1 reg 
> address.
> 

The example is bad, emac and syscon are two distinct regspaces.
I will correct the example.

>> +- interrupts: interrupt for the device
>> +- clocks: A phandle to the reference clock for this device
>> +- clock-names: should be "ahb"
>> +- resets: A phandle to the reset control for this device
>> +- reset-names: should be "ahb"
>> +- phy-mode: See ethernet.txt
>> +- phy or phy-handle: See ethernet.txt
>> +- #address-cells: shall be 1
>> +- #size-cells: shall be 0
>> +
>> +"allwinner,sun8i-h3-emac" also requires:
>> +- clocks: an extra phandle to the reference clock for the EPHY
>> +- clock-names: an extra "ephy" entry matching the clocks property
>> +- resets: an extra phandle to the reset control for the EPHY
>> +- resets-names: an extra "ephy" entry matching the resets property
>> +
>> +See ethernet.txt in the same directory for generic bindings for ethernet
>> +controllers.
>> +
>> +The device node referenced by "phy" or "phy-handle" should be a child node
>> +of this node. See phy.txt for the generic PHY bindings.
>> +
>> +Optional properties:
>> +- phy-supply: phandle to a regulator if the PHY needs one
>> +- phy-io-supply: phandle to a regulator if the PHY needs a another one for 
>> I/O.
>> + This is sometimes found with RGMII PHYs, which use a second
>> + regulator for the lower I/O voltage.
> 
> These should go in the phy's node.
> 

In fact, I forgot to remove them, since for the moment, the driver sent do not 
have any regulator support.

Thanks



[PATCH 14/17] net: stmmac: print phy information

2017-01-31 Thread Corentin Labbe
When a PHY is found, printing which one was found (and which type/model) is
a good information to know.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index e53b727..3d52b8c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -885,6 +885,7 @@ static int stmmac_init_phy(struct net_device *dev)
netdev_dbg(priv->dev, "%s: attached to PHY (UID 0x%x) Link = %d\n",
   __func__, phydev->phy_id, phydev->link);
 
+   phy_attached_info(phydev);
return 0;
 }
 
-- 
2.10.2



[PATCH 01/17] net: stmmac: fix the typo on MAC_RNABLE_RX

2017-01-31 Thread Corentin Labbe
the define MAC_RNABLE_RX have a typo, rename it to MAC_ENABLE_RX

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/common.h| 2 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index b13a144..0f90f91 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -340,7 +340,7 @@ struct dma_features {
 /* Common MAC defines */
 #define MAC_CTRL_REG   0x  /* MAC Control */
 #define MAC_ENABLE_TX  0x0008  /* Transmitter Enable */
-#define MAC_RNABLE_RX  0x0004  /* Receiver Enable */
+#define MAC_ENABLE_RX  0x0004  /* Receiver Enable */
 
 /* Default LPI timers */
 #define STMMAC_DEFAULT_LIT_LS  0x3E8
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
index 84e3e84..a414bde 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
@@ -261,9 +261,9 @@ void stmmac_set_mac(void __iomem *ioaddr, bool enable)
u32 value = readl(ioaddr + MAC_CTRL_REG);
 
if (enable)
-   value |= MAC_RNABLE_RX | MAC_ENABLE_TX;
+   value |= MAC_ENABLE_RX | MAC_ENABLE_TX;
else
-   value &= ~(MAC_ENABLE_TX | MAC_RNABLE_RX);
+   value &= ~(MAC_ENABLE_TX | MAC_ENABLE_RX);
 
writel(value, ioaddr + MAC_CTRL_REG);
 }
-- 
2.10.2



[PATCH 00/17] net: stmmac: misc fix

2017-01-31 Thread Corentin Labbe
Hello

I am currently working on dwmac-sun8i glue driver for Allwinner H3/A83T/A64.
This serie is the result of all minor problem found in the stmmac driver.

Regards

Corentin Labbe (17):
  net: stmmac: fix the typo on MAC_RNABLE_RX
  net: stmmac: Remove the bus_setup function pointer
  net: stmmac: fix some typos in comments
  net: stmmac: remove freesoftware address
  net: stmmac: remplace asm/io.h by linux/io.h
  net: stmmac: fix some code style problem
  net: stmmac: replace stmmac_mdio_busy_wait by readl_poll_timeout
  net: stmmac: Use readl_poll_timeout
  net: stmmac: replace ENOSYS by EINVAL
  net: stmmac: Correct the error message about invalid speed
  net: stmmac: Rewrite two test against NULL value
  net: stmmac: rename rx_crc to rx_crc_errors
  net: stmmac: Implement NAPI for TX
  net: stmmac: print phy information
  net: stmmac: remove dead code in stmmac_tx_clean
  net: stmmac: remove unused variable in sysfs_display_ring
  net: stmmac: replace unsigned by u32

 drivers/net/ethernet/stmicro/stmmac/chain_mode.c   |  4 --
 drivers/net/ethernet/stmicro/stmmac/common.h   |  8 +--
 drivers/net/ethernet/stmicro/stmmac/descs.h|  4 --
 drivers/net/ethernet/stmicro/stmmac/descs_com.h|  4 --
 drivers/net/ethernet/stmicro/stmmac/dwmac100.h |  4 --
 drivers/net/ethernet/stmicro/stmmac/dwmac1000.h|  4 --
 .../net/ethernet/stmicro/stmmac/dwmac1000_core.c   |  4 --
 .../net/ethernet/stmicro/stmmac/dwmac1000_dma.c|  4 --
 .../net/ethernet/stmicro/stmmac/dwmac100_core.c|  4 --
 drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c |  4 --
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c |  2 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h|  4 --
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c| 28 --
 drivers/net/ethernet/stmicro/stmmac/enh_desc.c |  6 +--
 drivers/net/ethernet/stmicro/stmmac/mmc.h  |  4 --
 drivers/net/ethernet/stmicro/stmmac/mmc_core.c |  4 --
 drivers/net/ethernet/stmicro/stmmac/norm_desc.c|  6 +--
 drivers/net/ethernet/stmicro/stmmac/ring_mode.c|  4 --
 drivers/net/ethernet/stmicro/stmmac/stmmac.h   |  4 --
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   |  6 +--
 .../net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c  |  4 --
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 63 ++
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c  | 52 +++---
 drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c   |  4 --
 .../net/ethernet/stmicro/stmmac/stmmac_platform.c  |  6 +--
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c   |  4 --
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h   |  4 --
 include/linux/stmmac.h |  1 -
 28 files changed, 65 insertions(+), 185 deletions(-)

-- 
2.10.2



[PATCH 17/17] net: stmmac: replace unsigned by u32

2017-01-31 Thread Corentin Labbe
checkpatch complains about two unsigned without type after.
Since the value return is u32, it is simpler to replace it by u32 instead
of "unsigned int"

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index f0ce780..6260b6f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -187,7 +187,7 @@ static void print_pkt(unsigned char *buf, int len)
 
 static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
 {
-   unsigned avail;
+   u32 avail;
 
if (priv->dirty_tx > priv->cur_tx)
avail = priv->dirty_tx - priv->cur_tx - 1;
@@ -199,7 +199,7 @@ static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
 
 static inline u32 stmmac_rx_dirty(struct stmmac_priv *priv)
 {
-   unsigned dirty;
+   u32 dirty;
 
if (priv->dirty_rx <= priv->cur_rx)
dirty = priv->cur_rx - priv->dirty_rx;
-- 
2.10.2



[PATCH 13/17] net: stmmac: Implement NAPI for TX

2017-01-31 Thread Corentin Labbe
The stmmac driver run TX completion under NAPI but without checking the
work done by the TX completion function.

This patch add work/budget to the TX completion function.

The visible effect is that it keep the driver longer under NAPI and
boost performance.
Under dwmac-sun8i the iperf goes from 140Mbit/s to 500Mbit/s.
Under dwmac-sunxi an iperf run use half less interrupts.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 2df36bd..e53b727 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1299,10 +1299,11 @@ static void stmmac_dma_operation_mode(struct 
stmmac_priv *priv)
  * @priv: driver private structure
  * Description: it reclaims the transmit resources after transmission 
completes.
  */
-static void stmmac_tx_clean(struct stmmac_priv *priv)
+static int stmmac_tx_clean(struct stmmac_priv *priv, int budget)
 {
unsigned int bytes_compl = 0, pkts_compl = 0;
unsigned int entry = priv->dirty_tx;
+   int work = 0;
 
netif_tx_lock(priv->dev);
 
@@ -1369,6 +1370,9 @@ static void stmmac_tx_clean(struct stmmac_priv *priv)
priv->hw->desc->release_tx_desc(p, priv->mode);
 
entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE);
+   work++;
+   if (work >= budget)
+   break;
}
priv->dirty_tx = entry;
 
@@ -1386,6 +1390,11 @@ static void stmmac_tx_clean(struct stmmac_priv *priv)
mod_timer(>eee_ctrl_timer, STMMAC_LPI_T(eee_timer));
}
netif_tx_unlock(priv->dev);
+
+   if (work < budget)
+   work = 0;
+
+   return work;
 }
 
 static inline void stmmac_enable_dma_irq(struct stmmac_priv *priv)
@@ -1617,7 +1626,7 @@ static void stmmac_tx_timer(unsigned long data)
 {
struct stmmac_priv *priv = (struct stmmac_priv *)data;
 
-   stmmac_tx_clean(priv);
+   stmmac_tx_clean(priv, 256);
 }
 
 /**
@@ -2657,9 +2666,10 @@ static int stmmac_poll(struct napi_struct *napi, int 
budget)
int work_done = 0;
 
priv->xstats.napi_poll++;
-   stmmac_tx_clean(priv);
+   work_done += stmmac_tx_clean(priv, budget);
 
-   work_done = stmmac_rx(priv, budget);
+   if (work_done < budget)
+   work_done += stmmac_rx(priv, budget - work_done);
if (work_done < budget) {
napi_complete(napi);
stmmac_enable_dma_irq(priv);
-- 
2.10.2



[PATCH 16/17] net: stmmac: remove unused variable in sysfs_display_ring

2017-01-31 Thread Corentin Labbe
The u64 x variable in sysfs_display_ring is unused.
This patch remove it.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index b494bc2..f0ce780 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2890,9 +2890,7 @@ static void sysfs_display_ring(void *head, int size, int 
extend_desc,
struct dma_desc *p = (struct dma_desc *)head;
 
for (i = 0; i < size; i++) {
-   u64 x;
if (extend_desc) {
-   x = *(u64 *) ep;
seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
   i, (unsigned int)virt_to_phys(ep),
   le32_to_cpu(ep->basic.des0),
@@ -2901,7 +2899,6 @@ static void sysfs_display_ring(void *head, int size, int 
extend_desc,
   le32_to_cpu(ep->basic.des3));
ep++;
} else {
-   x = *(u64 *) p;
seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
   i, (unsigned int)virt_to_phys(ep),
   le32_to_cpu(p->des0), le32_to_cpu(p->des1),
-- 
2.10.2



[PATCH 09/17] net: stmmac: replace ENOSYS by EINVAL

2017-01-31 Thread Corentin Labbe
As said by checkpatch ENOSYS means 'invalid syscall nr' and nothing
else.
This patch replace ENOSYS by the more appropriate value EINVAL.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index eff6282..485b1cd 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -353,7 +353,7 @@ void stmmac_remove_config_dt(struct platform_device *pdev,
 struct plat_stmmacenet_data *
 stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
 {
-   return ERR_PTR(-ENOSYS);
+   return ERR_PTR(-EINVAL);
 }
 
 void stmmac_remove_config_dt(struct platform_device *pdev,
-- 
2.10.2



[PATCH 15/17] net: stmmac: remove dead code in stmmac_tx_clean

2017-01-31 Thread Corentin Labbe
Since commit cf32deec16e4 ("stmmac: add tx_skbuff_dma to save descriptors used 
by PTP"),
the struct dma_desc *p in stmmac_tx_clean was not used at all.

This patch remove this dead code.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 3d52b8c..b494bc2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1124,13 +1124,6 @@ static void dma_free_tx_skbufs(struct stmmac_priv *priv)
int i;
 
for (i = 0; i < DMA_TX_SIZE; i++) {
-   struct dma_desc *p;
-
-   if (priv->extend_desc)
-   p = &((priv->dma_etx + i)->basic);
-   else
-   p = priv->dma_tx + i;
-
if (priv->tx_skbuff_dma[i].buf) {
if (priv->tx_skbuff_dma[i].map_as_page)
dma_unmap_page(priv->device,
-- 
2.10.2



Re: [PATCH 07/17] net: stmmac: replace stmmac_mdio_busy_wait by readl_poll_timeout

2017-01-31 Thread Corentin Labbe
On Tue, Jan 31, 2017 at 11:13:49AM +0100, Giuseppe CAVALLARO wrote:
> On 1/31/2017 10:11 AM, Corentin Labbe wrote:
> > The stmmac_mdio_busy_wait() function do the same job than
> > readl_poll_timeout().
> > So is is better to replace it.
> >
> > Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
> 
> I just wonder if you also tested it, this impacts all the platforms
> where SMA block is used

I have tested all patch in this series on my cubieboard2 (dwmac-sunxi) and my 
opipc/pine64/bpim2+ (dwmac-sun8i)
(Yes I could have said that in cover letter).
So this code was tested on two different stmmac glue driver.

> 
> if yes, pls consider my:
> 
> Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
> 
> > ---
> >  drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 33 
> > ---
> >  1 file changed, 11 insertions(+), 22 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
> > b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> > index c24bef2..d9893cf 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> > @@ -21,6 +21,7 @@
> >  
> > ***/
> >
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -38,22 +39,6 @@
> >  #define MII_GMAC4_WRITE(1 << MII_GMAC4_GOC_SHIFT)
> >  #define MII_GMAC4_READ (3 << MII_GMAC4_GOC_SHIFT)
> >
> > -static int stmmac_mdio_busy_wait(void __iomem *ioaddr, unsigned int 
> > mii_addr)
> > -{
> > -   unsigned long curr;
> > -   unsigned long finish = jiffies + 3 * HZ;
> > -
> > -   do {
> > -   curr = jiffies;
> > -   if (readl(ioaddr + mii_addr) & MII_BUSY)
> > -   cpu_relax();
> > -   else
> > -   return 0;
> > -   } while (!time_after_eq(curr, finish));
> > -
> > -   return -EBUSY;
> > -}
> > -
> >  /**
> >   * stmmac_mdio_read
> >   * @bus: points to the mii_bus structure
> > @@ -70,7 +55,7 @@ static int stmmac_mdio_read(struct mii_bus *bus, int 
> > phyaddr, int phyreg)
> > struct stmmac_priv *priv = netdev_priv(ndev);
> > unsigned int mii_address = priv->hw->mii.addr;
> > unsigned int mii_data = priv->hw->mii.data;
> > -
> > +   u32 v;
> > int data;
> > u32 value = MII_BUSY;
> >
> > @@ -82,12 +67,14 @@ static int stmmac_mdio_read(struct mii_bus *bus, int 
> > phyaddr, int phyreg)
> > if (priv->plat->has_gmac4)
> > value |= MII_GMAC4_READ;
> >
> > -   if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
> > +   if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
> > +  100, 1))
> > return -EBUSY;
> >
> > writel(value, priv->ioaddr + mii_address);
> >
> > -   if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
> > +   if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
> > +  100, 1))
> > return -EBUSY;
> >
> > /* Read the data from the MII data register */
> > @@ -111,7 +98,7 @@ static int stmmac_mdio_write(struct mii_bus *bus, int 
> > phyaddr, int phyreg,
> > struct stmmac_priv *priv = netdev_priv(ndev);
> > unsigned int mii_address = priv->hw->mii.addr;
> > unsigned int mii_data = priv->hw->mii.data;
> > -
> > +   u32 v;
> > u32 value = MII_BUSY;
> >
> > value |= (phyaddr << priv->hw->mii.addr_shift)
> > @@ -126,7 +113,8 @@ static int stmmac_mdio_write(struct mii_bus *bus, int 
> > phyaddr, int phyreg,
> > value |= MII_WRITE;
> >
> > /* Wait until any existing MII operation is complete */
> > -   if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
> > +   if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
> > +  100, 1))
> > return -EBUSY;
> >
> > /* Set the MII address register to write */
> > @@ -134,7 +122,8 @@ static int stmmac_mdio_write(struct mii_bus *bus, int 
> > phyaddr, int phyreg,
> > writel(value, priv->ioaddr + mii_address);
> >
> > /* Wait until any existing MII operation is complete */
> > -   return stmmac_mdio_busy_wait(priv->ioaddr, mii_address);
> > +   return readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & 
> > MII_BUSY),
> > + 100, 1);
> >  }
> >
> >  /**
> >
> 


[PATCH 04/17] net: stmmac: remove freesoftware address

2017-01-31 Thread Corentin Labbe
This patch fix the checkpatch warning about free software address.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/chain_mode.c  | 4 
 drivers/net/ethernet/stmicro/stmmac/common.h  | 4 
 drivers/net/ethernet/stmicro/stmmac/descs.h   | 4 
 drivers/net/ethernet/stmicro/stmmac/descs_com.h   | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac100.h| 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac1000.h   | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c  | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c   | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c   | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c| 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h   | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c   | 4 
 drivers/net/ethernet/stmicro/stmmac/enh_desc.c| 4 
 drivers/net/ethernet/stmicro/stmmac/mmc.h | 4 
 drivers/net/ethernet/stmicro/stmmac/mmc_core.c| 4 
 drivers/net/ethernet/stmicro/stmmac/norm_desc.c   | 4 
 drivers/net/ethernet/stmicro/stmmac/ring_mode.c   | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c  | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c  | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c  | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h  | 4 
 26 files changed, 104 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c 
b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
index 026e8e9..01a8c02 100644
--- a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
@@ -16,10 +16,6 @@
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc.,
-  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
-
   The full GNU General Public License is included in this distribution in
   the file called "COPYING".
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index 0f90f91..9da4877 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -12,10 +12,6 @@
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc.,
-  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
-
   The full GNU General Public License is included in this distribution in
   the file called "COPYING".
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/descs.h 
b/drivers/net/ethernet/stmicro/stmmac/descs.h
index faeeef7..0c2432b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/descs.h
+++ b/drivers/net/ethernet/stmicro/stmmac/descs.h
@@ -11,10 +11,6 @@
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc.,
-  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
-
   The full GNU General Public License is included in this distribution in
   the file called "COPYING".
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/descs_com.h 
b/drivers/net/ethernet/stmicro/stmmac/descs_com.h
index 1d181e2..ca9d7e4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/descs_com.h
+++ b/drivers/net/ethernet/stmicro/stmmac/descs_com.h
@@ -17,10 +17,6 @@
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc.,
-  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
-
   The full GNU General Public License is included in this distribution in
   the file called "COPYING".
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100.h 
b/drivers/net/ethernet/stmicro/stmmac/dwmac100.h
index 1657acf..e149848 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac100.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100.h
@@ -12,10 +12,6 @@
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received 

[PATCH 11/17] net: stmmac: Rewrite two test against NULL value

2017-01-31 Thread Corentin Labbe
This patch rewrite two test against NULL value with correct style.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index b0154d5..2df36bd 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -700,7 +700,7 @@ static void stmmac_adjust_link(struct net_device *dev)
int new_state = 0;
unsigned int fc = priv->flow_ctrl, pause_time = priv->pause;
 
-   if (phydev == NULL)
+   if (!phydev)
return;
 
spin_lock_irqsave(>lock, flags);
@@ -1143,7 +1143,7 @@ static void dma_free_tx_skbufs(struct stmmac_priv *priv)
 DMA_TO_DEVICE);
}
 
-   if (priv->tx_skbuff[i] != NULL) {
+   if (priv->tx_skbuff[i]) {
dev_kfree_skb_any(priv->tx_skbuff[i]);
priv->tx_skbuff[i] = NULL;
priv->tx_skbuff_dma[i].buf = 0;
-- 
2.10.2



[PATCH 10/17] net: stmmac: Correct the error message about invalid speed

2017-01-31 Thread Corentin Labbe
Add 1000 as a valid speed in the error message about invalid speed
in stmmac_adjust_link()

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 98f544e..b0154d5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -749,7 +749,7 @@ static void stmmac_adjust_link(struct net_device *dev)
break;
default:
netif_warn(priv, link, priv->dev,
-  "Speed (%d) not 10/100\n",
+  "Speed (%d) not 10/100/1000\n",
   phydev->speed);
break;
}
-- 
2.10.2



[PATCH 08/17] net: stmmac: Use readl_poll_timeout

2017-01-31 Thread Corentin Labbe
The dwmac_dma_reset function use an open coded of readl_poll_timeout().
Replace the open coded handling with the proper function.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
index e4cda39..e60bfca 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
@@ -17,6 +17,7 @@
 
***/
 
 #include 
+#include 
 #include "common.h"
 #include "dwmac_dma.h"
 
@@ -25,19 +26,16 @@
 int dwmac_dma_reset(void __iomem *ioaddr)
 {
u32 value = readl(ioaddr + DMA_BUS_MODE);
-   int limit;
+   int err;
 
/* DMA SW reset */
value |= DMA_BUS_MODE_SFT_RESET;
writel(value, ioaddr + DMA_BUS_MODE);
-   limit = 10;
-   while (limit--) {
-   if (!(readl(ioaddr + DMA_BUS_MODE) & DMA_BUS_MODE_SFT_RESET))
-   break;
-   mdelay(10);
-   }
 
-   if (limit < 0)
+   err = readl_poll_timeout(ioaddr + DMA_BUS_MODE, value,
+!(value & DMA_BUS_MODE_SFT_RESET),
+10, 1);
+   if (err)
return -EBUSY;
 
return 0;
-- 
2.10.2



[PATCH 12/17] net: stmmac: rename rx_crc to rx_crc_errors

2017-01-31 Thread Corentin Labbe
The ethtool stat counter rx_crc from stmmac is mis-named, the name
seems to speak about the number of RX CRC done, but in fact it is about
errors.

This patch rename it to rx_crc_errors, just like the same ifconfig
counter.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/common.h | 2 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c   | 2 +-
 drivers/net/ethernet/stmicro/stmmac/enh_desc.c   | 2 +-
 drivers/net/ethernet/stmicro/stmmac/norm_desc.c  | 2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index 9da4877..b7ee15a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -67,7 +67,7 @@ struct stmmac_extra_stats {
unsigned long overflow_error;
unsigned long ipc_csum_error;
unsigned long rx_collision;
-   unsigned long rx_crc;
+   unsigned long rx_crc_errors;
unsigned long dribbling_bit;
unsigned long rx_length;
unsigned long rx_mii;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
index 8816515..843ec69 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
@@ -103,7 +103,7 @@ static int dwmac4_wrback_get_rx_status(void *data, struct 
stmmac_extra_stats *x,
x->rx_mii++;
 
if (unlikely(rdes3 & RDES3_CRC_ERROR)) {
-   x->rx_crc++;
+   x->rx_crc_errors++;
stats->rx_crc_errors++;
}
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c 
b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
index 8427643..323b59e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
@@ -221,7 +221,7 @@ static int enh_desc_get_rx_status(void *data, struct 
stmmac_extra_stats *x,
x->rx_mii++;
 
if (unlikely(rdes0 & RDES0_CRC_ERROR)) {
-   x->rx_crc++;
+   x->rx_crc_errors++;
stats->rx_crc_errors++;
}
ret = discard_frame;
diff --git a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c 
b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
index 5a0d4b0..efb818e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
@@ -111,7 +111,7 @@ static int ndesc_get_rx_status(void *data, struct 
stmmac_extra_stats *x,
stats->collisions++;
}
if (unlikely(rdes0 & RDES0_CRC_ERROR)) {
-   x->rx_crc++;
+   x->rx_crc_errors++;
stats->rx_crc_errors++;
}
ret = discard_frame;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index 69db8cb..6ca0a10 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -61,7 +61,7 @@ static const struct stmmac_stats stmmac_gstrings_stats[] = {
STMMAC_STAT(overflow_error),
STMMAC_STAT(ipc_csum_error),
STMMAC_STAT(rx_collision),
-   STMMAC_STAT(rx_crc),
+   STMMAC_STAT(rx_crc_errors),
STMMAC_STAT(dribbling_bit),
STMMAC_STAT(rx_length),
STMMAC_STAT(rx_mii),
-- 
2.10.2



[PATCH 07/17] net: stmmac: replace stmmac_mdio_busy_wait by readl_poll_timeout

2017-01-31 Thread Corentin Labbe
The stmmac_mdio_busy_wait() function do the same job than
readl_poll_timeout().
So is is better to replace it.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 33 ---
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index c24bef2..d9893cf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -21,6 +21,7 @@
 
***/
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -38,22 +39,6 @@
 #define MII_GMAC4_WRITE(1 << MII_GMAC4_GOC_SHIFT)
 #define MII_GMAC4_READ (3 << MII_GMAC4_GOC_SHIFT)
 
-static int stmmac_mdio_busy_wait(void __iomem *ioaddr, unsigned int mii_addr)
-{
-   unsigned long curr;
-   unsigned long finish = jiffies + 3 * HZ;
-
-   do {
-   curr = jiffies;
-   if (readl(ioaddr + mii_addr) & MII_BUSY)
-   cpu_relax();
-   else
-   return 0;
-   } while (!time_after_eq(curr, finish));
-
-   return -EBUSY;
-}
-
 /**
  * stmmac_mdio_read
  * @bus: points to the mii_bus structure
@@ -70,7 +55,7 @@ static int stmmac_mdio_read(struct mii_bus *bus, int phyaddr, 
int phyreg)
struct stmmac_priv *priv = netdev_priv(ndev);
unsigned int mii_address = priv->hw->mii.addr;
unsigned int mii_data = priv->hw->mii.data;
-
+   u32 v;
int data;
u32 value = MII_BUSY;
 
@@ -82,12 +67,14 @@ static int stmmac_mdio_read(struct mii_bus *bus, int 
phyaddr, int phyreg)
if (priv->plat->has_gmac4)
value |= MII_GMAC4_READ;
 
-   if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
+   if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
+  100, 1))
return -EBUSY;
 
writel(value, priv->ioaddr + mii_address);
 
-   if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
+   if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
+  100, 1))
return -EBUSY;
 
/* Read the data from the MII data register */
@@ -111,7 +98,7 @@ static int stmmac_mdio_write(struct mii_bus *bus, int 
phyaddr, int phyreg,
struct stmmac_priv *priv = netdev_priv(ndev);
unsigned int mii_address = priv->hw->mii.addr;
unsigned int mii_data = priv->hw->mii.data;
-
+   u32 v;
u32 value = MII_BUSY;
 
value |= (phyaddr << priv->hw->mii.addr_shift)
@@ -126,7 +113,8 @@ static int stmmac_mdio_write(struct mii_bus *bus, int 
phyaddr, int phyreg,
value |= MII_WRITE;
 
/* Wait until any existing MII operation is complete */
-   if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
+   if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
+  100, 1))
return -EBUSY;
 
/* Set the MII address register to write */
@@ -134,7 +122,8 @@ static int stmmac_mdio_write(struct mii_bus *bus, int 
phyaddr, int phyreg,
writel(value, priv->ioaddr + mii_address);
 
/* Wait until any existing MII operation is complete */
-   return stmmac_mdio_busy_wait(priv->ioaddr, mii_address);
+   return readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & 
MII_BUSY),
+ 100, 1);
 }
 
 /**
-- 
2.10.2



[PATCH 03/17] net: stmmac: fix some typos in comments

2017-01-31 Thread Corentin Labbe
This patch fix some typos in comments.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c   |  6 +++---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 16 
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c |  2 +-
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
index a414bde..3b1570d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
@@ -102,7 +102,7 @@ static void show_tx_process_state(unsigned int status)
pr_debug("- TX (Stopped): Reset or Stop command\n");
break;
case 1:
-   pr_debug("- TX (Running):Fetching the Tx desc\n");
+   pr_debug("- TX (Running): Fetching the Tx desc\n");
break;
case 2:
pr_debug("- TX (Running): Waiting for end of tx\n");
@@ -136,7 +136,7 @@ static void show_rx_process_state(unsigned int status)
pr_debug("- RX (Running): Fetching the Rx desc\n");
break;
case 2:
-   pr_debug("- RX (Running):Checking for end of pkt\n");
+   pr_debug("- RX (Running): Checking for end of pkt\n");
break;
case 3:
pr_debug("- RX (Running): Waiting for Rx pkt\n");
@@ -246,7 +246,7 @@ void stmmac_set_mac_addr(void __iomem *ioaddr, u8 addr[6],
unsigned long data;
 
data = (addr[5] << 8) | addr[4];
-   /* For MAC Addr registers se have to set the Address Enable (AE)
+   /* For MAC Addr registers we have to set the Address Enable (AE)
 * bit that has no effect on the High Reg 0 where the bit 31 (MO)
 * is RO.
 */
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index bf2d8e6..ee71c07 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -216,7 +216,7 @@ static inline u32 stmmac_rx_dirty(struct stmmac_priv *priv)
 /**
  * stmmac_hw_fix_mac_speed - callback for speed selection
  * @priv: driver private structure
- * Description: on some platforms (e.g. ST), some HW system configuraton
+ * Description: on some platforms (e.g. ST), some HW system configuration
  * registers have to be set according to the link speed negotiated.
  */
 static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv *priv)
@@ -415,7 +415,7 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv 
*priv, struct dma_desc *p,
 /**
  *  stmmac_hwtstamp_ioctl - control hardware timestamping.
  *  @dev: device pointer.
- *  @ifr: An IOCTL specefic structure, that can contain a pointer to
+ *  @ifr: An IOCTL specific structure, that can contain a pointer to
  *  a proprietary structure used to pass information to the driver.
  *  Description:
  *  This function configures the MAC to enable/disable both outgoing(TX)
@@ -1014,7 +1014,7 @@ static void stmmac_free_rx_buffers(struct stmmac_priv 
*priv, int i)
  * @dev: net device structure
  * @flags: gfp flag.
  * Description: this function initializes the DMA RX/TX descriptors
- * and allocates the socket buffers. It suppors the chained and ring
+ * and allocates the socket buffers. It supports the chained and ring
  * modes.
  */
 static int init_dma_desc_rings(struct net_device *dev, gfp_t flags)
@@ -2515,7 +2515,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
if (unlikely(status == discard_frame)) {
priv->dev->stats.rx_errors++;
if (priv->hwts_rx_en && !priv->extend_desc) {
-   /* DESC2 & DESC3 will be overwitten by device
+   /* DESC2 & DESC3 will be overwritten by device
 * with timestamp value, hence reinitialize
 * them in stmmac_rx_refill() function so that
 * device can reuse it.
@@ -2538,7 +2538,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
 
frame_len = priv->hw->desc->get_rx_frame_len(p, coe);
 
-   /*  If frame length is greather than skb buffer size
+   /*  If frame length is greater than skb buffer size
 *  (preallocated during init) then the packet is
 *  ignored
 */
@@ -2744,7 +2744,7 @@ static netdev_features_t stmmac_fix_features(struct 
net_device *dev,
/* Some GMAC devices have a bugged Jumbo frame support that
 * needs to have the Tx COE disabled for oversized frames
 * (due to limited buffer sizes).

[PATCH 02/17] net: stmmac: Remove the bus_setup function pointer

2017-01-31 Thread Corentin Labbe
The bus_setup function pointer is not used at all, this patch remove it.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 
 include/linux/stmmac.h| 1 -
 2 files changed, 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index e3f6389..bf2d8e6 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1671,10 +1671,6 @@ static int stmmac_hw_setup(struct net_device *dev, bool 
init_ptp)
/* Copy the MAC addr into the HW  */
priv->hw->mac->set_umac_addr(priv->hw, dev->dev_addr, 0);
 
-   /* If required, perform hw setup of the bus. */
-   if (priv->plat->bus_setup)
-   priv->plat->bus_setup(priv->ioaddr);
-
/* PS and related bits will be programmed according to the speed */
if (priv->hw->pcs) {
int speed = priv->plat->mac_port_sel_speed;
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 266dab9..2d82df9 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -135,7 +135,6 @@ struct plat_stmmacenet_data {
int tx_fifo_size;
int rx_fifo_size;
void (*fix_mac_speed)(void *priv, unsigned int speed);
-   void (*bus_setup)(void __iomem *ioaddr);
int (*init)(struct platform_device *pdev, void *priv);
void (*exit)(struct platform_device *pdev, void *priv);
void *bsp_priv;
-- 
2.10.2



[PATCH 05/17] net: stmmac: remplace asm/io.h by linux/io.h

2017-01-31 Thread Corentin Labbe
This patch fix the checkpatch warning about asm/io.h.
Sorting all includes in the process.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 738d5c7..3fdc6ec 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -20,13 +20,13 @@
   Maintainer: Giuseppe Cavallaro <peppe.cavall...@st.com>
 
***/
 
+#include 
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 
-#include 
+#include 
+#include 
 
 #include "stmmac.h"
 
-- 
2.10.2



[PATCH 06/17] net: stmmac: fix some code style problem

2017-01-31 Thread Corentin Labbe
Checkpatch complains about some code style problem on stmmac_mdio.c.
This patch fix them.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 3fdc6ec..c24bef2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -152,9 +152,9 @@ int stmmac_mdio_reset(struct mii_bus *bus)
 
 #ifdef CONFIG_OF
if (priv->device->of_node) {
-
if (data->reset_gpio < 0) {
struct device_node *np = priv->device->of_node;
+
if (!np)
return 0;
 
@@ -221,7 +221,7 @@ int stmmac_mdio_register(struct net_device *ndev)
return 0;
 
new_bus = mdiobus_alloc();
-   if (new_bus == NULL)
+   if (!new_bus)
return -ENOMEM;
 
if (mdio_bus_data->irqs)
@@ -258,6 +258,7 @@ int stmmac_mdio_register(struct net_device *ndev)
found = 0;
for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
struct phy_device *phydev = mdiobus_get_phy(new_bus, addr);
+
if (phydev) {
int act = 0;
char irq_num[4];
@@ -267,7 +268,7 @@ int stmmac_mdio_register(struct net_device *ndev)
 * If an IRQ was provided to be assigned after
 * the bus probe, do it here.
 */
-   if ((mdio_bus_data->irqs == NULL) &&
+   if ((!mdio_bus_data->irqs) &&
(mdio_bus_data->probed_phy_irq > 0)) {
new_bus->irq[addr] =
mdio_bus_data->probed_phy_irq;
-- 
2.10.2



Re: [PATCH 13/17] net: stmmac: Implement NAPI for TX

2017-01-31 Thread Corentin Labbe
On Tue, Jan 31, 2017 at 11:28:03AM +0100, Giuseppe CAVALLARO wrote:
> On 1/31/2017 10:11 AM, Corentin Labbe wrote:
> > The stmmac driver run TX completion under NAPI but without checking the
> > work done by the TX completion function.
> >
> > This patch add work/budget to the TX completion function.
> >
> > The visible effect is that it keep the driver longer under NAPI and
> > boost performance.
> > Under dwmac-sun8i the iperf goes from 140Mbit/s to 500Mbit/s.
> > Under dwmac-sunxi an iperf run use half less interrupts.
> 
> I think that this patch should be sent separately with more details
> about the implementation you are adopting and results.
> 

This patch is just implementing what NAPI documentation say.
"The budget parameter places a limit on the amount of work the driver may do. 
Each received packet counts as one unit of work. The poll() function may also 
process TX completions, in which case if it processes the entire TX ring then 
it should count that work as the rest of the budget. Otherwise, TX completions 
are not counted."

For the history, I have done the sun8i-emac driver for H3/A64 and get with if 
very good performance.
Some people find that the hardware was in fact a modified version of dwmac and 
so I start working on dwmac-sun8i glue driver.
Testing dwmac-sun8i give very bad performance and the only real difference 
between thoses two driver was the handling of NAPI TX mitigation.

The performance are tested with a simple iperf.
I will redo some test with some numbers

> For example, in the timer callback you force 256 (it seems
> DMA_TX_SIZE/2); do you think this should be tunable or fixed to
> NAPI budget?

I think that the whole "TX mitigation timer" is useless when using TX 
completion within NAPI.
I will do some bench for checking with and without it.

> 
> I'd like to understand if performance you get are for TCP traffic;
> can you tell me what happens on unidirectional traffic?
> 
> Thx a lot for your effort, pls let me know
> 
> Regards
> peppe
> 



Re: [PATCH v2 06/16] net: stmmac: fix some code style problem

2017-02-08 Thread Corentin Labbe
On Wed, Feb 08, 2017 at 02:41:58AM -0800, Joe Perches wrote:
> On Wed, 2017-02-08 at 09:31 +0100, Corentin Labbe wrote:
> > Checkpatch complains about some code style problem on stmmac_mdio.c.
> > This patch fix them.
> []
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
> > b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> []
> > @@ -258,6 +258,7 @@ int stmmac_mdio_register(struct net_device *ndev)
> > found = 0;
> > for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
> > struct phy_device *phydev = mdiobus_get_phy(new_bus, addr);
> > +
> > if (phydev) {
> > int act = 0;
> > char irq_num[4];
> 
> Maybe use
>   if (!phydev)
>   continue;
> to reduce indentation

Thanks I will do it in a subsequent patch

Regards
Corentin Labbe


[PATCH v2 11/16] net: stmmac: Rewrite two test against NULL value

2017-02-08 Thread Corentin Labbe
This patch rewrite two test against NULL value with correct style.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index ed81375..cc88bdb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -689,7 +689,7 @@ static void stmmac_adjust_link(struct net_device *dev)
int new_state = 0;
unsigned int fc = priv->flow_ctrl, pause_time = priv->pause;
 
-   if (phydev == NULL)
+   if (!phydev)
return;
 
spin_lock_irqsave(>lock, flags);
@@ -1131,7 +1131,7 @@ static void dma_free_tx_skbufs(struct stmmac_priv *priv)
 DMA_TO_DEVICE);
}
 
-   if (priv->tx_skbuff[i] != NULL) {
+   if (priv->tx_skbuff[i]) {
dev_kfree_skb_any(priv->tx_skbuff[i]);
priv->tx_skbuff[i] = NULL;
priv->tx_skbuff_dma[i].buf = 0;
-- 
2.10.2



[PATCH v2 09/16] net: stmmac: replace ENOSYS by EINVAL

2017-02-08 Thread Corentin Labbe
As said by checkpatch ENOSYS means 'invalid syscall nr' and nothing
else.
This patch replace ENOSYS by the more appropriate value EINVAL.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 320f46e..433a842 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -411,7 +411,7 @@ void stmmac_remove_config_dt(struct platform_device *pdev,
 struct plat_stmmacenet_data *
 stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
 {
-   return ERR_PTR(-ENOSYS);
+   return ERR_PTR(-EINVAL);
 }
 
 void stmmac_remove_config_dt(struct platform_device *pdev,
-- 
2.10.2



[PATCH v2 12/16] net: stmmac: rename rx_crc to rx_crc_errors

2017-02-08 Thread Corentin Labbe
The ethtool stat counter rx_crc from stmmac is mis-named, the name
seems to speak about the number of RX CRC done, but in fact it is about
errors.

This patch rename it to rx_crc_errors, just like the same ifconfig
counter.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/common.h | 2 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c   | 2 +-
 drivers/net/ethernet/stmicro/stmmac/enh_desc.c   | 2 +-
 drivers/net/ethernet/stmicro/stmmac/norm_desc.c  | 2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index 24929bf..144fe84 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -67,7 +67,7 @@ struct stmmac_extra_stats {
unsigned long overflow_error;
unsigned long ipc_csum_error;
unsigned long rx_collision;
-   unsigned long rx_crc;
+   unsigned long rx_crc_errors;
unsigned long dribbling_bit;
unsigned long rx_length;
unsigned long rx_mii;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
index 8816515..843ec69 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
@@ -103,7 +103,7 @@ static int dwmac4_wrback_get_rx_status(void *data, struct 
stmmac_extra_stats *x,
x->rx_mii++;
 
if (unlikely(rdes3 & RDES3_CRC_ERROR)) {
-   x->rx_crc++;
+   x->rx_crc_errors++;
stats->rx_crc_errors++;
}
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c 
b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
index 8427643..323b59e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
@@ -221,7 +221,7 @@ static int enh_desc_get_rx_status(void *data, struct 
stmmac_extra_stats *x,
x->rx_mii++;
 
if (unlikely(rdes0 & RDES0_CRC_ERROR)) {
-   x->rx_crc++;
+   x->rx_crc_errors++;
stats->rx_crc_errors++;
}
ret = discard_frame;
diff --git a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c 
b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
index 5a0d4b0..efb818e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
@@ -111,7 +111,7 @@ static int ndesc_get_rx_status(void *data, struct 
stmmac_extra_stats *x,
stats->collisions++;
}
if (unlikely(rdes0 & RDES0_CRC_ERROR)) {
-   x->rx_crc++;
+   x->rx_crc_errors++;
stats->rx_crc_errors++;
}
ret = discard_frame;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index 9083d9a..aab895d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -61,7 +61,7 @@ static const struct stmmac_stats stmmac_gstrings_stats[] = {
STMMAC_STAT(overflow_error),
STMMAC_STAT(ipc_csum_error),
STMMAC_STAT(rx_collision),
-   STMMAC_STAT(rx_crc),
+   STMMAC_STAT(rx_crc_errors),
STMMAC_STAT(dribbling_bit),
STMMAC_STAT(rx_length),
STMMAC_STAT(rx_mii),
-- 
2.10.2



[PATCH v2 13/16] net: stmmac: print phy information

2017-02-08 Thread Corentin Labbe
When a PHY is found, printing which one was found (and which type/model) is
a good information to know.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index cc88bdb..9805aa8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -870,9 +870,7 @@ static int stmmac_init_phy(struct net_device *dev)
if (phydev->is_pseudo_fixed_link)
phydev->irq = PHY_POLL;
 
-   netdev_dbg(priv->dev, "%s: attached to PHY (UID 0x%x) Link = %d\n",
-  __func__, phydev->phy_id, phydev->link);
-
+   phy_attached_info(phydev);
return 0;
 }
 
-- 
2.10.2



[PATCH v2 07/16] net: stmmac: replace stmmac_mdio_busy_wait by readl_poll_timeout

2017-02-08 Thread Corentin Labbe
The stmmac_mdio_busy_wait() function do the same job than
readl_poll_timeout().
So is is better to replace it.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 33 ---
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index c24bef2..d9893cf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -21,6 +21,7 @@
 
***/
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -38,22 +39,6 @@
 #define MII_GMAC4_WRITE(1 << MII_GMAC4_GOC_SHIFT)
 #define MII_GMAC4_READ (3 << MII_GMAC4_GOC_SHIFT)
 
-static int stmmac_mdio_busy_wait(void __iomem *ioaddr, unsigned int mii_addr)
-{
-   unsigned long curr;
-   unsigned long finish = jiffies + 3 * HZ;
-
-   do {
-   curr = jiffies;
-   if (readl(ioaddr + mii_addr) & MII_BUSY)
-   cpu_relax();
-   else
-   return 0;
-   } while (!time_after_eq(curr, finish));
-
-   return -EBUSY;
-}
-
 /**
  * stmmac_mdio_read
  * @bus: points to the mii_bus structure
@@ -70,7 +55,7 @@ static int stmmac_mdio_read(struct mii_bus *bus, int phyaddr, 
int phyreg)
struct stmmac_priv *priv = netdev_priv(ndev);
unsigned int mii_address = priv->hw->mii.addr;
unsigned int mii_data = priv->hw->mii.data;
-
+   u32 v;
int data;
u32 value = MII_BUSY;
 
@@ -82,12 +67,14 @@ static int stmmac_mdio_read(struct mii_bus *bus, int 
phyaddr, int phyreg)
if (priv->plat->has_gmac4)
value |= MII_GMAC4_READ;
 
-   if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
+   if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
+  100, 1))
return -EBUSY;
 
writel(value, priv->ioaddr + mii_address);
 
-   if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
+   if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
+  100, 1))
return -EBUSY;
 
/* Read the data from the MII data register */
@@ -111,7 +98,7 @@ static int stmmac_mdio_write(struct mii_bus *bus, int 
phyaddr, int phyreg,
struct stmmac_priv *priv = netdev_priv(ndev);
unsigned int mii_address = priv->hw->mii.addr;
unsigned int mii_data = priv->hw->mii.data;
-
+   u32 v;
u32 value = MII_BUSY;
 
value |= (phyaddr << priv->hw->mii.addr_shift)
@@ -126,7 +113,8 @@ static int stmmac_mdio_write(struct mii_bus *bus, int 
phyaddr, int phyreg,
value |= MII_WRITE;
 
/* Wait until any existing MII operation is complete */
-   if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
+   if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
+  100, 1))
return -EBUSY;
 
/* Set the MII address register to write */
@@ -134,7 +122,8 @@ static int stmmac_mdio_write(struct mii_bus *bus, int 
phyaddr, int phyreg,
writel(value, priv->ioaddr + mii_address);
 
/* Wait until any existing MII operation is complete */
-   return stmmac_mdio_busy_wait(priv->ioaddr, mii_address);
+   return readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & 
MII_BUSY),
+ 100, 1);
 }
 
 /**
-- 
2.10.2



[PATCH v2 15/16] net: stmmac: remove unused variable in sysfs_display_ring

2017-02-08 Thread Corentin Labbe
The u64 x variable in sysfs_display_ring is unused.
This patch remove it.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index c5dc3f9..d1b2e1e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2893,9 +2893,7 @@ static void sysfs_display_ring(void *head, int size, int 
extend_desc,
struct dma_desc *p = (struct dma_desc *)head;
 
for (i = 0; i < size; i++) {
-   u64 x;
if (extend_desc) {
-   x = *(u64 *) ep;
seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
   i, (unsigned int)virt_to_phys(ep),
   le32_to_cpu(ep->basic.des0),
@@ -2904,7 +2902,6 @@ static void sysfs_display_ring(void *head, int size, int 
extend_desc,
   le32_to_cpu(ep->basic.des3));
ep++;
} else {
-   x = *(u64 *) p;
seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
   i, (unsigned int)virt_to_phys(ep),
   le32_to_cpu(p->des0), le32_to_cpu(p->des1),
-- 
2.10.2



[PATCH v2 16/16] net: stmmac: replace unsigned by u32

2017-02-08 Thread Corentin Labbe
checkpatch complains about two unsigned without type after.
Since the value return is u32, it is simpler to replace it by u32 instead
of "unsigned int"

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index d1b2e1e..7251871 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -187,7 +187,7 @@ static void print_pkt(unsigned char *buf, int len)
 
 static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
 {
-   unsigned avail;
+   u32 avail;
 
if (priv->dirty_tx > priv->cur_tx)
avail = priv->dirty_tx - priv->cur_tx - 1;
@@ -199,7 +199,7 @@ static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
 
 static inline u32 stmmac_rx_dirty(struct stmmac_priv *priv)
 {
-   unsigned dirty;
+   u32 dirty;
 
if (priv->dirty_rx <= priv->cur_rx)
dirty = priv->cur_rx - priv->dirty_rx;
-- 
2.10.2



[PATCH v2 14/16] net: stmmac: remove dead code in stmmac_tx_clean

2017-02-08 Thread Corentin Labbe
Since commit cf32deec16e4 ("stmmac: add tx_skbuff_dma to save descriptors used 
by PTP"),
the struct dma_desc *p in stmmac_tx_clean was not used at all.

This patch remove this dead code.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 9805aa8..c5dc3f9 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1109,13 +1109,6 @@ static void dma_free_tx_skbufs(struct stmmac_priv *priv)
int i;
 
for (i = 0; i < DMA_TX_SIZE; i++) {
-   struct dma_desc *p;
-
-   if (priv->extend_desc)
-   p = &((priv->dma_etx + i)->basic);
-   else
-   p = priv->dma_tx + i;
-
if (priv->tx_skbuff_dma[i].buf) {
if (priv->tx_skbuff_dma[i].map_as_page)
dma_unmap_page(priv->device,
-- 
2.10.2



[PATCH v2 03/16] net: stmmac: fix some typos in comments

2017-02-08 Thread Corentin Labbe
This patch fix some typos in comments.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c   |  6 +++---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 16 
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c |  2 +-
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
index a414bde..3b1570d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
@@ -102,7 +102,7 @@ static void show_tx_process_state(unsigned int status)
pr_debug("- TX (Stopped): Reset or Stop command\n");
break;
case 1:
-   pr_debug("- TX (Running):Fetching the Tx desc\n");
+   pr_debug("- TX (Running): Fetching the Tx desc\n");
break;
case 2:
pr_debug("- TX (Running): Waiting for end of tx\n");
@@ -136,7 +136,7 @@ static void show_rx_process_state(unsigned int status)
pr_debug("- RX (Running): Fetching the Rx desc\n");
break;
case 2:
-   pr_debug("- RX (Running):Checking for end of pkt\n");
+   pr_debug("- RX (Running): Checking for end of pkt\n");
break;
case 3:
pr_debug("- RX (Running): Waiting for Rx pkt\n");
@@ -246,7 +246,7 @@ void stmmac_set_mac_addr(void __iomem *ioaddr, u8 addr[6],
unsigned long data;
 
data = (addr[5] << 8) | addr[4];
-   /* For MAC Addr registers se have to set the Address Enable (AE)
+   /* For MAC Addr registers we have to set the Address Enable (AE)
 * bit that has no effect on the High Reg 0 where the bit 31 (MO)
 * is RO.
 */
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 1ef60282..0636858 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -216,7 +216,7 @@ static inline u32 stmmac_rx_dirty(struct stmmac_priv *priv)
 /**
  * stmmac_hw_fix_mac_speed - callback for speed selection
  * @priv: driver private structure
- * Description: on some platforms (e.g. ST), some HW system configuraton
+ * Description: on some platforms (e.g. ST), some HW system configuration
  * registers have to be set according to the link speed negotiated.
  */
 static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv *priv)
@@ -416,7 +416,7 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv 
*priv, struct dma_desc *p,
 /**
  *  stmmac_hwtstamp_ioctl - control hardware timestamping.
  *  @dev: device pointer.
- *  @ifr: An IOCTL specefic structure, that can contain a pointer to
+ *  @ifr: An IOCTL specific structure, that can contain a pointer to
  *  a proprietary structure used to pass information to the driver.
  *  Description:
  *  This function configures the MAC to enable/disable both outgoing(TX)
@@ -1003,7 +1003,7 @@ static void stmmac_free_rx_buffers(struct stmmac_priv 
*priv, int i)
  * @dev: net device structure
  * @flags: gfp flag.
  * Description: this function initializes the DMA RX/TX descriptors
- * and allocates the socket buffers. It suppors the chained and ring
+ * and allocates the socket buffers. It supports the chained and ring
  * modes.
  */
 static int init_dma_desc_rings(struct net_device *dev, gfp_t flags)
@@ -2532,7 +2532,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
if (unlikely(status == discard_frame)) {
priv->dev->stats.rx_errors++;
if (priv->hwts_rx_en && !priv->extend_desc) {
-   /* DESC2 & DESC3 will be overwitten by device
+   /* DESC2 & DESC3 will be overwritten by device
 * with timestamp value, hence reinitialize
 * them in stmmac_rx_refill() function so that
 * device can reuse it.
@@ -2555,7 +2555,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
 
frame_len = priv->hw->desc->get_rx_frame_len(p, coe);
 
-   /*  If frame length is greather than skb buffer size
+   /*  If frame length is greater than skb buffer size
 *  (preallocated during init) then the packet is
 *  ignored
 */
@@ -2761,7 +2761,7 @@ static netdev_features_t stmmac_fix_features(struct 
net_device *dev,
/* Some GMAC devices have a bugged Jumbo frame support that
 * needs to have the Tx COE disa

[PATCH v2 02/16] net: stmmac: Remove the bus_setup function pointer

2017-02-08 Thread Corentin Labbe
The bus_setup function pointer is not used at all, this patch remove it.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 
 include/linux/stmmac.h| 1 -
 2 files changed, 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index bd83bf9..1ef60282 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1682,10 +1682,6 @@ static int stmmac_hw_setup(struct net_device *dev, bool 
init_ptp)
/* Copy the MAC addr into the HW  */
priv->hw->mac->set_umac_addr(priv->hw, dev->dev_addr, 0);
 
-   /* If required, perform hw setup of the bus. */
-   if (priv->plat->bus_setup)
-   priv->plat->bus_setup(priv->ioaddr);
-
/* PS and related bits will be programmed according to the speed */
if (priv->hw->pcs) {
int speed = priv->plat->mac_port_sel_speed;
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index d76033d6..fc273e9 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -134,7 +134,6 @@ struct plat_stmmacenet_data {
int tx_fifo_size;
int rx_fifo_size;
void (*fix_mac_speed)(void *priv, unsigned int speed);
-   void (*bus_setup)(void __iomem *ioaddr);
int (*init)(struct platform_device *pdev, void *priv);
void (*exit)(struct platform_device *pdev, void *priv);
void *bsp_priv;
-- 
2.10.2



[PATCH v2 05/16] net: stmmac: remplace asm/io.h by linux/io.h

2017-02-08 Thread Corentin Labbe
This patch fix the checkpatch warning about asm/io.h.
Sorting all includes in the process.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 738d5c7..3fdc6ec 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -20,13 +20,13 @@
   Maintainer: Giuseppe Cavallaro <peppe.cavall...@st.com>
 
***/
 
+#include 
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 
-#include 
+#include 
+#include 
 
 #include "stmmac.h"
 
-- 
2.10.2



[PATCH v2 10/16] net: stmmac: Correct the error message about invalid speed

2017-02-08 Thread Corentin Labbe
The message about invalid speed does not state 1000 as a valid speed.
It is much simpler to said that the speed is invalid.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a13fcc4..ed81375 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -738,8 +738,7 @@ static void stmmac_adjust_link(struct net_device *dev)
break;
default:
netif_warn(priv, link, priv->dev,
-  "Speed (%d) not 10/100\n",
-  phydev->speed);
+  "broken speed: %d\n", phydev->speed);
break;
}
 
-- 
2.10.2



[PATCH v2 04/16] net: stmmac: remove freesoftware address

2017-02-08 Thread Corentin Labbe
This patch fix the checkpatch warning about free software address.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/chain_mode.c  | 4 
 drivers/net/ethernet/stmicro/stmmac/common.h  | 4 
 drivers/net/ethernet/stmicro/stmmac/descs.h   | 4 
 drivers/net/ethernet/stmicro/stmmac/descs_com.h   | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac100.h| 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac1000.h   | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c  | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c   | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c   | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c| 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h   | 4 
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c   | 4 
 drivers/net/ethernet/stmicro/stmmac/enh_desc.c| 4 
 drivers/net/ethernet/stmicro/stmmac/mmc.h | 4 
 drivers/net/ethernet/stmicro/stmmac/mmc_core.c| 4 
 drivers/net/ethernet/stmicro/stmmac/norm_desc.c   | 4 
 drivers/net/ethernet/stmicro/stmmac/ring_mode.c   | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c  | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c  | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c  | 4 
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h  | 4 
 26 files changed, 104 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c 
b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
index 026e8e9..01a8c02 100644
--- a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
@@ -16,10 +16,6 @@
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc.,
-  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
-
   The full GNU General Public License is included in this distribution in
   the file called "COPYING".
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index 262a1c4..24929bf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -12,10 +12,6 @@
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc.,
-  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
-
   The full GNU General Public License is included in this distribution in
   the file called "COPYING".
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/descs.h 
b/drivers/net/ethernet/stmicro/stmmac/descs.h
index faeeef7..0c2432b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/descs.h
+++ b/drivers/net/ethernet/stmicro/stmmac/descs.h
@@ -11,10 +11,6 @@
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc.,
-  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
-
   The full GNU General Public License is included in this distribution in
   the file called "COPYING".
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/descs_com.h 
b/drivers/net/ethernet/stmicro/stmmac/descs_com.h
index 1d181e2..ca9d7e4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/descs_com.h
+++ b/drivers/net/ethernet/stmicro/stmmac/descs_com.h
@@ -17,10 +17,6 @@
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc.,
-  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
-
   The full GNU General Public License is included in this distribution in
   the file called "COPYING".
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100.h 
b/drivers/net/ethernet/stmicro/stmmac/dwmac100.h
index 1657acf..e149848 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac100.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100.h
@@ -12,10 +12,6 @@
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received 

[PATCH v2 06/16] net: stmmac: fix some code style problem

2017-02-08 Thread Corentin Labbe
Checkpatch complains about some code style problem on stmmac_mdio.c.
This patch fix them.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 3fdc6ec..c24bef2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -152,9 +152,9 @@ int stmmac_mdio_reset(struct mii_bus *bus)
 
 #ifdef CONFIG_OF
if (priv->device->of_node) {
-
if (data->reset_gpio < 0) {
struct device_node *np = priv->device->of_node;
+
if (!np)
return 0;
 
@@ -221,7 +221,7 @@ int stmmac_mdio_register(struct net_device *ndev)
return 0;
 
new_bus = mdiobus_alloc();
-   if (new_bus == NULL)
+   if (!new_bus)
return -ENOMEM;
 
if (mdio_bus_data->irqs)
@@ -258,6 +258,7 @@ int stmmac_mdio_register(struct net_device *ndev)
found = 0;
for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
struct phy_device *phydev = mdiobus_get_phy(new_bus, addr);
+
if (phydev) {
int act = 0;
char irq_num[4];
@@ -267,7 +268,7 @@ int stmmac_mdio_register(struct net_device *ndev)
 * If an IRQ was provided to be assigned after
 * the bus probe, do it here.
 */
-   if ((mdio_bus_data->irqs == NULL) &&
+   if ((!mdio_bus_data->irqs) &&
(mdio_bus_data->probed_phy_irq > 0)) {
new_bus->irq[addr] =
mdio_bus_data->probed_phy_irq;
-- 
2.10.2



[PATCH v2 08/16] net: stmmac: Use readl_poll_timeout

2017-02-08 Thread Corentin Labbe
The dwmac_dma_reset function use an open coded of readl_poll_timeout().
Replace the open coded handling with the proper function.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
index e4cda39..e60bfca 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
@@ -17,6 +17,7 @@
 
***/
 
 #include 
+#include 
 #include "common.h"
 #include "dwmac_dma.h"
 
@@ -25,19 +26,16 @@
 int dwmac_dma_reset(void __iomem *ioaddr)
 {
u32 value = readl(ioaddr + DMA_BUS_MODE);
-   int limit;
+   int err;
 
/* DMA SW reset */
value |= DMA_BUS_MODE_SFT_RESET;
writel(value, ioaddr + DMA_BUS_MODE);
-   limit = 10;
-   while (limit--) {
-   if (!(readl(ioaddr + DMA_BUS_MODE) & DMA_BUS_MODE_SFT_RESET))
-   break;
-   mdelay(10);
-   }
 
-   if (limit < 0)
+   err = readl_poll_timeout(ioaddr + DMA_BUS_MODE, value,
+!(value & DMA_BUS_MODE_SFT_RESET),
+10, 1);
+   if (err)
return -EBUSY;
 
return 0;
-- 
2.10.2



[PATCH v2 00/16] net: stmmac: misc fix

2017-02-08 Thread Corentin Labbe
Hello

I am currently working on dwmac-sun8i glue driver for Allwinner H3/A83T/A64.
This serie is the result of all minor problem found in the stmmac driver.

All patch are tested on cubieboard2 via dwmac-sunxi and on pine64/orangepis via 
dwmac-sun8i.

Regards

Changes since v1:
- Removed netdev_dbg() in "net: stmmac: print phy information"
- Removed patch "net: stmmac: Implement NAPI for TX", it will be reworked
- Changed error message in "Correct the error message about invalid speed"
- Added some acked-by

Corentin Labbe (16):
  net: stmmac: fix the typo on MAC_RNABLE_RX
  net: stmmac: Remove the bus_setup function pointer
  net: stmmac: fix some typos in comments
  net: stmmac: remove freesoftware address
  net: stmmac: remplace asm/io.h by linux/io.h
  net: stmmac: fix some code style problem
  net: stmmac: replace stmmac_mdio_busy_wait by readl_poll_timeout
  net: stmmac: Use readl_poll_timeout
  net: stmmac: replace ENOSYS by EINVAL
  net: stmmac: Correct the error message about invalid speed
  net: stmmac: Rewrite two test against NULL value
  net: stmmac: rename rx_crc to rx_crc_errors
  net: stmmac: print phy information
  net: stmmac: remove dead code in stmmac_tx_clean
  net: stmmac: remove unused variable in sysfs_display_ring
  net: stmmac: replace unsigned by u32

 drivers/net/ethernet/stmicro/stmmac/chain_mode.c   |  4 --
 drivers/net/ethernet/stmicro/stmmac/common.h   |  8 +---
 drivers/net/ethernet/stmicro/stmmac/descs.h|  4 --
 drivers/net/ethernet/stmicro/stmmac/descs_com.h|  4 --
 drivers/net/ethernet/stmicro/stmmac/dwmac100.h |  4 --
 drivers/net/ethernet/stmicro/stmmac/dwmac1000.h|  4 --
 .../net/ethernet/stmicro/stmmac/dwmac1000_core.c   |  4 --
 .../net/ethernet/stmicro/stmmac/dwmac1000_dma.c|  4 --
 .../net/ethernet/stmicro/stmmac/dwmac100_core.c|  4 --
 drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c |  4 --
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c |  2 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h|  4 --
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c| 28 +---
 drivers/net/ethernet/stmicro/stmmac/enh_desc.c |  6 +--
 drivers/net/ethernet/stmicro/stmmac/mmc.h  |  4 --
 drivers/net/ethernet/stmicro/stmmac/mmc_core.c |  4 --
 drivers/net/ethernet/stmicro/stmmac/norm_desc.c|  6 +--
 drivers/net/ethernet/stmicro/stmmac/ring_mode.c|  4 --
 drivers/net/ethernet/stmicro/stmmac/stmmac.h   |  4 --
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   |  6 +--
 .../net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c  |  4 --
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 49 ++--
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c  | 52 --
 drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c   |  4 --
 .../net/ethernet/stmicro/stmmac/stmmac_platform.c  |  6 +--
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c   |  4 --
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h   |  4 --
 include/linux/stmmac.h |  1 -
 28 files changed, 51 insertions(+), 185 deletions(-)

-- 
2.10.2



[PATCH v2 01/16] net: stmmac: fix the typo on MAC_RNABLE_RX

2017-02-08 Thread Corentin Labbe
the define MAC_RNABLE_RX have a typo, rename it to MAC_ENABLE_RX

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/common.h| 2 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index 75e2666..262a1c4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -343,7 +343,7 @@ struct dma_features {
 /* Common MAC defines */
 #define MAC_CTRL_REG   0x  /* MAC Control */
 #define MAC_ENABLE_TX  0x0008  /* Transmitter Enable */
-#define MAC_RNABLE_RX  0x0004  /* Receiver Enable */
+#define MAC_ENABLE_RX  0x0004  /* Receiver Enable */
 
 /* Default LPI timers */
 #define STMMAC_DEFAULT_LIT_LS  0x3E8
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
index 84e3e84..a414bde 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
@@ -261,9 +261,9 @@ void stmmac_set_mac(void __iomem *ioaddr, bool enable)
u32 value = readl(ioaddr + MAC_CTRL_REG);
 
if (enable)
-   value |= MAC_RNABLE_RX | MAC_ENABLE_TX;
+   value |= MAC_ENABLE_RX | MAC_ENABLE_TX;
else
-   value &= ~(MAC_ENABLE_TX | MAC_RNABLE_RX);
+   value &= ~(MAC_ENABLE_TX | MAC_ENABLE_RX);
 
writel(value, ioaddr + MAC_CTRL_REG);
 }
-- 
2.10.2



Re: [PATCH 14/17] net: stmmac: print phy information

2017-02-03 Thread Corentin Labbe
On Tue, Jan 31, 2017 at 11:10:04AM +0100, Giuseppe CAVALLARO wrote:
> On 1/31/2017 10:11 AM, Corentin Labbe wrote:
> > When a PHY is found, printing which one was found (and which type/model) is
> > a good information to know.
> >
> > Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
> > ---
> >  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
> > b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > index e53b727..3d52b8c 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > @@ -885,6 +885,7 @@ static int stmmac_init_phy(struct net_device *dev)
> > netdev_dbg(priv->dev, "%s: attached to PHY (UID 0x%x) Link = %d\n",
> >__func__, phydev->phy_id, phydev->link);
> >
> > +   phy_attached_info(phydev);
> 
> maybe we could remove the netdev_dbg above and just keep
> phy_attached_info(phydev);
> 
> peppe
> 

Ok, I will remove it

Regards
Corentin Labbe


Re: [PATCH 13/17] net: stmmac: Implement NAPI for TX

2017-02-03 Thread Corentin Labbe
On Fri, Feb 03, 2017 at 10:15:30AM -0500, David Miller wrote:
> From: Corentin Labbe <clabbe.montj...@gmail.com>
> Date: Fri, 3 Feb 2017 14:41:45 +0100
> 
> > On Tue, Jan 31, 2017 at 11:12:25PM -0500, David Miller wrote:
> >> From: Corentin Labbe <clabbe.montj...@gmail.com>
> >> Date: Tue, 31 Jan 2017 10:11:48 +0100
> >> 
> >> > The stmmac driver run TX completion under NAPI but without checking
> >> > the work done by the TX completion function.
> >> 
> >> The current behavior is correct and completely intentional.
> >> 
> >> A driver should _never_ account TX work to the NAPI poll budget.
> >> 
> >> This is because TX liberation is orders of magnitude cheaper than
> >> receiving a packet, and such SKB freeing makes more SKBs available
> >> for RX processing.
> >> 
> >> Therefore, TX work should never count against the NAPI budget.
> >> 
> >> Please do not fix something which is not broken.
> > 
> > So at least the documentation I read must be fixed 
> > (https://wiki.linuxfoundation.org/networking/napi)
> 
> We have no control over nor care about what the Linux Foundation writes
> about the Linux networking code.
> 
> Complain to them and please do not bother us about it.
> 
> Thank you.

Sorry, this was not to bother you.

Could you give me your opinion on the other question of the mail ? (just copied 
below)
So perhaps the best way is to do like intel igb/ixgbe, keeping under NAPI until 
the stmmac_tx_clean function said that it finished handling the queue (with a 
distinct TX budget)?

Thanks
Regards


Re: [PATCH 13/17] net: stmmac: Implement NAPI for TX

2017-02-03 Thread Corentin Labbe
On Tue, Jan 31, 2017 at 11:12:25PM -0500, David Miller wrote:
> From: Corentin Labbe <clabbe.montj...@gmail.com>
> Date: Tue, 31 Jan 2017 10:11:48 +0100
> 
> > The stmmac driver run TX completion under NAPI but without checking
> > the work done by the TX completion function.
> 
> The current behavior is correct and completely intentional.
> 
> A driver should _never_ account TX work to the NAPI poll budget.
> 
> This is because TX liberation is orders of magnitude cheaper than
> receiving a packet, and such SKB freeing makes more SKBs available
> for RX processing.
> 
> Therefore, TX work should never count against the NAPI budget.
> 
> Please do not fix something which is not broken.

So at least the documentation I read must be fixed 
(https://wiki.linuxfoundation.org/networking/napi)

So perhaps the best way is to do like intel igb/ixgbe, keeping under NAPI until 
the stmmac_tx_clean function said that it finish handling the queue ?

Regards
Corentin Labbe


Re: [PATCH] Net: ethernet: mediatek - Fix possible NULL derefrence.

2017-01-27 Thread Corentin Labbe
On Fri, Jan 27, 2017 at 04:49:40PM +0530, Shailendra Verma wrote:
> of_match_device could return NULL, and so can cause a NULL
> pointer dereference later.
> 
> Signed-off-by: Shailendra Verma <shailendr...@samsung.com>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c |4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c 
> b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 4a62ffd..4495b7b 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -2369,6 +2369,10 @@ static int mtk_probe(struct platform_device *pdev)
>   int i;
>  
>   match = of_match_device(of_mtk_match, >dev);
> + if (!match) {
> + dev_err(>dev, "Error: No device match found\n");
> + return -ENODEV;
> + }
>   soc = (struct mtk_soc_data *)match->data;
>  
>   eth = devm_kzalloc(>dev, sizeof(*eth), GFP_KERNEL);
> -- 

Hello

You could use of_device_get_match_data() and simplifiy code

Regards
Corentin Labbe


[PATCH RFC] net: stmmac: unify registers dumps methods

2017-02-20 Thread Corentin Labbe
The stmmac driver have two methods for registers dumps: via ethtool and
at init (if NETIF_MSG_HW is enabled).

It is better to keep only one method, ethtool, since the other was ugly.

This patch convert all dump_regs() function from "printing regs" to
"fill the reg_space used by ethtool".

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/common.h   |  4 +-
 .../net/ethernet/stmicro/stmmac/dwmac1000_core.c   | 10 +--
 .../net/ethernet/stmicro/stmmac/dwmac1000_dma.c| 16 ++---
 .../net/ethernet/stmicro/stmmac/dwmac100_core.c| 30 +++--
 drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c | 15 ++---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c  | 12 +---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c   | 78 +++---
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   | 21 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |  5 --
 9 files changed, 71 insertions(+), 120 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index daaafa9..7552775 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -416,7 +416,7 @@ struct stmmac_dma_ops {
/* Configure the AXI Bus Mode Register */
void (*axi)(void __iomem *ioaddr, struct stmmac_axi *axi);
/* Dump DMA registers */
-   void (*dump_regs) (void __iomem *ioaddr);
+   void (*dump_regs)(void __iomem *ioaddr, u32 *reg_space);
/* Set tx/rx threshold in the csr6 register
 * An invalid value enables the store-and-forward mode */
void (*dma_mode)(void __iomem *ioaddr, int txmode, int rxmode,
@@ -456,7 +456,7 @@ struct stmmac_ops {
/* Enable RX Queues */
void (*rx_queue_enable)(struct mac_device_info *hw, u32 queue);
/* Dump MAC registers */
-   void (*dump_regs)(struct mac_device_info *hw);
+   void (*dump_regs)(struct mac_device_info *hw, u32 *reg_space);
/* Handle extra events on specific interrupts hw dependent */
int (*host_irq_status)(struct mac_device_info *hw,
   struct stmmac_extra_stats *x);
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
index 91c8926..19b9b30 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
@@ -92,17 +92,13 @@ static int dwmac1000_rx_ipc_enable(struct mac_device_info 
*hw)
return !!(value & GMAC_CONTROL_IPC);
 }
 
-static void dwmac1000_dump_regs(struct mac_device_info *hw)
+static void dwmac1000_dump_regs(struct mac_device_info *hw, u32 *reg_space)
 {
void __iomem *ioaddr = hw->pcsr;
int i;
-   pr_info("\tDWMAC1000 regs (base addr = 0x%p)\n", ioaddr);
 
-   for (i = 0; i < 55; i++) {
-   int offset = i * 4;
-   pr_info("\tReg No. %d (offset 0x%x): 0x%08x\n", i,
-   offset, readl(ioaddr + offset));
-   }
+   for (i = 0; i < 55; i++)
+   reg_space[i] = readl(ioaddr + i * 4);
 }
 
 static void dwmac1000_set_umac_addr(struct mac_device_info *hw,
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
index fbaec0f..d3654a4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
@@ -201,18 +201,14 @@ static void dwmac1000_dma_operation_mode(void __iomem 
*ioaddr, int txmode,
writel(csr6, ioaddr + DMA_CONTROL);
 }
 
-static void dwmac1000_dump_dma_regs(void __iomem *ioaddr)
+static void dwmac1000_dump_dma_regs(void __iomem *ioaddr, u32 *reg_space)
 {
int i;
-   pr_info(" DMA registers\n");
-   for (i = 0; i < 22; i++) {
-   if ((i < 9) || (i > 17)) {
-   int offset = i * 4;
-   pr_err("\t Reg No. %d (offset 0x%x): 0x%08x\n", i,
-  (DMA_BUS_MODE + offset),
-  readl(ioaddr + DMA_BUS_MODE + offset));
-   }
-   }
+
+   for (i = 0; i < 22; i++)
+   if ((i < 9) || (i > 17))
+   reg_space[DMA_BUS_MODE / 4 + i] =
+   readl(ioaddr + DMA_BUS_MODE + i * 4);
 }
 
 static void dwmac1000_get_hw_feature(void __iomem *ioaddr,
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
index 8ab5189..e370cce 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
@@ -40,28 +40,18 @@ static void dwmac100_core_init(struct mac_device_info *hw, 
int mtu)
 #endif
 }
 
-static void dwmac100_dump_mac_regs(struct mac_device_info *hw

[PATCH RFC] net: stmmac: unify registers dumps methods

2017-02-20 Thread Corentin Labbe
hello

The following patch address the problem that two way of dumping registers are
available in stmmac, via ethtool and directly at init (if NETIF_MSG_HW is 
enabled).
It is better to keep only one method, ethtool, since the other was ugly (logs 
of pr_xxx).

But by working on this issue, I saw two problem:
- "ethtool" for gmac/gmac4 always dump the 55 first registers, while 
dwmac4_dump_regs dump the first 132 registers, so clearly the current 
stmmac_ethtool_gregs miss some registers
- stmmac_ethtool_gregs claim to dump whole address space (len=REG_SPACE_SIZE), 
but in fact concat two distant address space.

The current patch address all by being bijective between reg_space and address 
space, so all DMA registers goes to their "real" address in reg_space.
But this fix break the pretty print of registers name of ethtool. (ethtool -d 
eth0 hex on still works).

What do you think about this issue ?

Corentin Labbe (1):
  net: stmmac: unify registers dumps methods

 drivers/net/ethernet/stmicro/stmmac/common.h   |  4 +-
 .../net/ethernet/stmicro/stmmac/dwmac1000_core.c   | 10 +--
 .../net/ethernet/stmicro/stmmac/dwmac1000_dma.c| 16 ++---
 .../net/ethernet/stmicro/stmmac/dwmac100_core.c| 30 +++--
 drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c | 15 ++---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c  | 12 +---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c   | 78 +++---
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   | 21 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |  5 --
 9 files changed, 71 insertions(+), 120 deletions(-)

-- 
2.10.2



Re: [PATCH 04/21] ARM: sun8i: dt: Add DT bindings documentation for Allwinner dwmac-sun8i

2017-02-20 Thread Corentin Labbe
On Thu, Feb 16, 2017 at 12:58:46PM -0800, Florian Fainelli wrote:
> On 02/16/2017 04:48 AM, Corentin Labbe wrote:
> > +
> > +Optional properties:
> > +- allwinner,tx-delay: TX clock delay chain value. Range value is 0-0x07. 
> > Default is 0)
> > +- allwinner,rx-delay: RX clock delay chain value. Range value is 0-0x1F. 
> > Default is 0)
> 
> Delays should be specified in nanosecond units, and should not be a
> value that maps directly to a HW register value, you need to convert the
> property value into the appropriate register value.
> 

This question already raised multiple times in sun8i-emac development, I do not 
have any information on how to decode thoses values. (and so the comment below 
in documentation)
I will try to contact Allwinner for more details.

> > +Both delay properties does not have units, there are arbitrary value.
> > +The TX/RX clock delay chain settings are board specific and could be found
> > +in vendor FEX files.
> > +
> > +Optional properties for "allwinner,sun8i-h3-emac":
> > +- allwinner,leds-active-low: EPHY LEDs are active low
> 
> Are you sure this is appropriate at the MAC node level and this is not
> something that follows the PHY instead?
> 

As said by MoeIcenowy, an internal PHY is present. At early stage of 
development, wens tried to create a PHY driver for it, but finaly it was too 
much over complicated and with few interest to split in two.

> > +
> > +Required child node of emac:
> > +- mdio bus node: should be named mdio
> > +
> > +Required properties of the mdio node:
> > +- #address-cells: shall be 1
> > +- #size-cells: shall be 0
> > +
> > +The device node referenced by "phy" or "phy-handle" should be a child node
> > +of the mdio node. See phy.txt for the generic PHY bindings.
> > +
> > +Required properties of the phy node with "allwinner,sun8i-h3-emac":
> > +- clocks: an extra phandle to the reference clock for the EPHY
> 
> s/an extra/a phandle/
> 

Thanks, will fix

Regards
Corentin Labbe


[PATCH] net: vxge: fix typo argumnet argument

2017-02-25 Thread Corentin Labbe
This commit fix the typo argumnet/argument

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/neterion/vxge/vxge-ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/neterion/vxge/vxge-ethtool.c 
b/drivers/net/ethernet/neterion/vxge/vxge-ethtool.c
index db55e6d..0452848 100644
--- a/drivers/net/ethernet/neterion/vxge/vxge-ethtool.c
+++ b/drivers/net/ethernet/neterion/vxge/vxge-ethtool.c
@@ -119,7 +119,7 @@ static void vxge_ethtool_gdrvinfo(struct net_device *dev,
  * @dev: device pointer.
  * @regs: pointer to the structure with parameters given by ethtool for
  * dumping the registers.
- * @reg_space: The input argumnet into which all the registers are dumped.
+ * @reg_space: The input argument into which all the registers are dumped.
  *
  * Dumps the vpath register space of Titan NIC into the user given
  * buffer area.
-- 
2.10.2



[PATCH] net: s2io: fix typo argumnet argument

2017-02-25 Thread Corentin Labbe
This commit fix the typo argumnet/argument

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/neterion/s2io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/neterion/s2io.c 
b/drivers/net/ethernet/neterion/s2io.c
index c5c1d0e..118723e 100644
--- a/drivers/net/ethernet/neterion/s2io.c
+++ b/drivers/net/ethernet/neterion/s2io.c
@@ -5397,7 +5397,7 @@ static void s2io_ethtool_gdrvinfo(struct net_device *dev,
  *  s2io_nic structure.
  *  @regs : pointer to the structure with parameters given by ethtool for
  *  dumping the registers.
- *  @reg_space: The input argumnet into which all the registers are dumped.
+ *  @reg_space: The input argument into which all the registers are dumped.
  *  Description:
  *  Dumps the entire register space of xFrame NIC into the user given
  *  buffer area.
-- 
2.10.2



[PATCH] net: stmmac: unify registers dumps methods

2017-02-23 Thread Corentin Labbe
The stmmac driver have two methods for registers dumps: via ethtool and
at init (if NETIF_MSG_HW is enabled).

It is better to keep only one method, ethtool, since the other was ugly.

This patch convert all dump_regs() function from "printing regs" to
"fill the reg_space used by ethtool".

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/common.h   |  4 +-
 .../net/ethernet/stmicro/stmmac/dwmac1000_core.c   | 10 +--
 .../net/ethernet/stmicro/stmmac/dwmac1000_dma.c| 16 ++---
 .../net/ethernet/stmicro/stmmac/dwmac100_core.c| 30 +++--
 drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c | 15 ++---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c  | 12 +---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c   | 78 +++---
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   | 21 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |  5 --
 9 files changed, 71 insertions(+), 120 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index daaafa9..7552775 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -416,7 +416,7 @@ struct stmmac_dma_ops {
/* Configure the AXI Bus Mode Register */
void (*axi)(void __iomem *ioaddr, struct stmmac_axi *axi);
/* Dump DMA registers */
-   void (*dump_regs) (void __iomem *ioaddr);
+   void (*dump_regs)(void __iomem *ioaddr, u32 *reg_space);
/* Set tx/rx threshold in the csr6 register
 * An invalid value enables the store-and-forward mode */
void (*dma_mode)(void __iomem *ioaddr, int txmode, int rxmode,
@@ -456,7 +456,7 @@ struct stmmac_ops {
/* Enable RX Queues */
void (*rx_queue_enable)(struct mac_device_info *hw, u32 queue);
/* Dump MAC registers */
-   void (*dump_regs)(struct mac_device_info *hw);
+   void (*dump_regs)(struct mac_device_info *hw, u32 *reg_space);
/* Handle extra events on specific interrupts hw dependent */
int (*host_irq_status)(struct mac_device_info *hw,
   struct stmmac_extra_stats *x);
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
index 91c8926..19b9b30 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
@@ -92,17 +92,13 @@ static int dwmac1000_rx_ipc_enable(struct mac_device_info 
*hw)
return !!(value & GMAC_CONTROL_IPC);
 }
 
-static void dwmac1000_dump_regs(struct mac_device_info *hw)
+static void dwmac1000_dump_regs(struct mac_device_info *hw, u32 *reg_space)
 {
void __iomem *ioaddr = hw->pcsr;
int i;
-   pr_info("\tDWMAC1000 regs (base addr = 0x%p)\n", ioaddr);
 
-   for (i = 0; i < 55; i++) {
-   int offset = i * 4;
-   pr_info("\tReg No. %d (offset 0x%x): 0x%08x\n", i,
-   offset, readl(ioaddr + offset));
-   }
+   for (i = 0; i < 55; i++)
+   reg_space[i] = readl(ioaddr + i * 4);
 }
 
 static void dwmac1000_set_umac_addr(struct mac_device_info *hw,
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
index fbaec0f..d3654a4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
@@ -201,18 +201,14 @@ static void dwmac1000_dma_operation_mode(void __iomem 
*ioaddr, int txmode,
writel(csr6, ioaddr + DMA_CONTROL);
 }
 
-static void dwmac1000_dump_dma_regs(void __iomem *ioaddr)
+static void dwmac1000_dump_dma_regs(void __iomem *ioaddr, u32 *reg_space)
 {
int i;
-   pr_info(" DMA registers\n");
-   for (i = 0; i < 22; i++) {
-   if ((i < 9) || (i > 17)) {
-   int offset = i * 4;
-   pr_err("\t Reg No. %d (offset 0x%x): 0x%08x\n", i,
-  (DMA_BUS_MODE + offset),
-  readl(ioaddr + DMA_BUS_MODE + offset));
-   }
-   }
+
+   for (i = 0; i < 22; i++)
+   if ((i < 9) || (i > 17))
+   reg_space[DMA_BUS_MODE / 4 + i] =
+   readl(ioaddr + DMA_BUS_MODE + i * 4);
 }
 
 static void dwmac1000_get_hw_feature(void __iomem *ioaddr,
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
index 8ab5189..e370cce 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
@@ -40,28 +40,18 @@ static void dwmac100_core_init(struct mac_device_info *hw, 
int mtu)
 #endif
 

[PATCH v3 7/8] net: stmmac: reduce indentation by adding a continue

2017-02-15 Thread Corentin Labbe
As suggested by Joe Perches, replacing the "if phydev" logic permit to
reduce indentation in the for loop.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
Reviewed-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 82 +++
 1 file changed, 40 insertions(+), 42 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index a695773..db157a4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -247,50 +247,48 @@ int stmmac_mdio_register(struct net_device *ndev)
found = 0;
for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
struct phy_device *phydev = mdiobus_get_phy(new_bus, addr);
+   int act = 0;
+   char irq_num[4];
+   char *irq_str;
+
+   if (!phydev)
+   continue;
+
+   /*
+* If an IRQ was provided to be assigned after
+* the bus probe, do it here.
+*/
+   if (!mdio_bus_data->irqs &&
+   (mdio_bus_data->probed_phy_irq > 0)) {
+   new_bus->irq[addr] = mdio_bus_data->probed_phy_irq;
+   phydev->irq = mdio_bus_data->probed_phy_irq;
+   }
 
-   if (phydev) {
-   int act = 0;
-   char irq_num[4];
-   char *irq_str;
-
-   /*
-* If an IRQ was provided to be assigned after
-* the bus probe, do it here.
-*/
-   if (!mdio_bus_data->irqs &&
-   (mdio_bus_data->probed_phy_irq > 0)) {
-   new_bus->irq[addr] =
-   mdio_bus_data->probed_phy_irq;
-   phydev->irq = mdio_bus_data->probed_phy_irq;
-   }
-
-   /*
-* If we're going to bind the MAC to this PHY bus,
-* and no PHY number was provided to the MAC,
-* use the one probed here.
-*/
-   if (priv->plat->phy_addr == -1)
-   priv->plat->phy_addr = addr;
-
-   act = (priv->plat->phy_addr == addr);
-   switch (phydev->irq) {
-   case PHY_POLL:
-   irq_str = "POLL";
-   break;
-   case PHY_IGNORE_INTERRUPT:
-   irq_str = "IGNORE";
-   break;
-   default:
-   sprintf(irq_num, "%d", phydev->irq);
-   irq_str = irq_num;
-   break;
-   }
-   netdev_info(ndev, "PHY ID %08x at %d IRQ %s (%s)%s\n",
-   phydev->phy_id, addr,
-   irq_str, phydev_name(phydev),
-   act ? " active" : "");
-   found = 1;
+   /*
+* If we're going to bind the MAC to this PHY bus,
+* and no PHY number was provided to the MAC,
+* use the one probed here.
+*/
+   if (priv->plat->phy_addr == -1)
+   priv->plat->phy_addr = addr;
+
+   act = (priv->plat->phy_addr == addr);
+   switch (phydev->irq) {
+   case PHY_POLL:
+   irq_str = "POLL";
+   break;
+   case PHY_IGNORE_INTERRUPT:
+   irq_str = "IGNORE";
+   break;
+   default:
+   sprintf(irq_num, "%d", phydev->irq);
+   irq_str = irq_num;
+   break;
}
+   netdev_info(ndev, "PHY ID %08x at %d IRQ %s (%s)%s\n",
+   phydev->phy_id, addr, irq_str, phydev_name(phydev),
+   act ? " active" : "");
+   found = 1;
}
 
if (!found && !mdio_node) {
-- 
2.10.2



[PATCH v3 8/8] net: stmmac: invert the logic for dumping regs

2017-02-15 Thread Corentin Labbe
It is easier to follow the logic by removing the not operator

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
Reviewed-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index aab895d..5ff6bc4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -442,24 +442,24 @@ static void stmmac_ethtool_gregs(struct net_device *dev,
 
memset(reg_space, 0x0, REG_SPACE_SIZE);
 
-   if (!(priv->plat->has_gmac || priv->plat->has_gmac4)) {
+   if (priv->plat->has_gmac || priv->plat->has_gmac4) {
/* MAC registers */
-   for (i = 0; i < 12; i++)
+   for (i = 0; i < 55; i++)
reg_space[i] = readl(priv->ioaddr + (i * 4));
/* DMA registers */
-   for (i = 0; i < 9; i++)
-   reg_space[i + 12] =
+   for (i = 0; i < 22; i++)
+   reg_space[i + 55] =
readl(priv->ioaddr + (DMA_BUS_MODE + (i * 4)));
-   reg_space[22] = readl(priv->ioaddr + DMA_CUR_TX_BUF_ADDR);
-   reg_space[23] = readl(priv->ioaddr + DMA_CUR_RX_BUF_ADDR);
} else {
/* MAC registers */
-   for (i = 0; i < 55; i++)
+   for (i = 0; i < 12; i++)
reg_space[i] = readl(priv->ioaddr + (i * 4));
/* DMA registers */
-   for (i = 0; i < 22; i++)
-   reg_space[i + 55] =
+   for (i = 0; i < 9; i++)
+   reg_space[i + 12] =
readl(priv->ioaddr + (DMA_BUS_MODE + (i * 4)));
+   reg_space[22] = readl(priv->ioaddr + DMA_CUR_TX_BUF_ADDR);
+   reg_space[23] = readl(priv->ioaddr + DMA_CUR_RX_BUF_ADDR);
}
 }
 
-- 
2.10.2



[PATCH v3 5/8] net: stmmac: run stmmac_hw_fix_mac_speed when speed is valid

2017-02-15 Thread Corentin Labbe
This patch mutualise a bit by running stmmac_hw_fix_mac_speed() after
the switch in case of valid speed.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
Reviewed-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index f7664b9..bebe810 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -719,7 +719,6 @@ static void stmmac_adjust_link(struct net_device *dev)
if (priv->plat->has_gmac ||
priv->plat->has_gmac4)
ctrl &= ~priv->hw->link.port;
-   stmmac_hw_fix_mac_speed(priv);
break;
case 100:
case 10:
@@ -734,7 +733,6 @@ static void stmmac_adjust_link(struct net_device *dev)
} else {
ctrl &= ~priv->hw->link.port;
}
-   stmmac_hw_fix_mac_speed(priv);
break;
default:
netif_warn(priv, link, priv->dev,
@@ -742,7 +740,8 @@ static void stmmac_adjust_link(struct net_device *dev)
phydev->speed = SPEED_UNKNOWN;
break;
}
-
+   if (phydev->speed != SPEED_UNKNOWN)
+   stmmac_hw_fix_mac_speed(priv);
priv->speed = phydev->speed;
}
 
-- 
2.10.2



[PATCH v3 3/8] net: stmmac: use SPEED_UNKNOWN/DUPLEX_UNKNOWN

2017-02-15 Thread Corentin Labbe
It is better to use DUPLEX_UNKNOWN instead of just "-1".
Using 0 for an invalid speed is bad since 0 is a valid value for speed.
So this patch replace 0 by SPEED_UNKNOWN.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
Reviewed-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 511c47c..a87071d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -754,8 +754,8 @@ static void stmmac_adjust_link(struct net_device *dev)
} else if (priv->oldlink) {
new_state = 1;
priv->oldlink = 0;
-   priv->speed = 0;
-   priv->oldduplex = -1;
+   priv->speed = SPEED_UNKNOWN;
+   priv->oldduplex = DUPLEX_UNKNOWN;
}
 
if (new_state && netif_msg_link(priv))
@@ -817,8 +817,8 @@ static int stmmac_init_phy(struct net_device *dev)
int interface = priv->plat->interface;
int max_speed = priv->plat->max_speed;
priv->oldlink = 0;
-   priv->speed = 0;
-   priv->oldduplex = -1;
+   priv->speed = SPEED_UNKNOWN;
+   priv->oldduplex = DUPLEX_UNKNOWN;
 
if (priv->plat->phy_node) {
phydev = of_phy_connect(dev, priv->plat->phy_node,
@@ -3434,8 +3434,8 @@ int stmmac_suspend(struct device *dev)
spin_unlock_irqrestore(>lock, flags);
 
priv->oldlink = 0;
-   priv->speed = 0;
-   priv->oldduplex = -1;
+   priv->speed = SPEED_UNKNOWN;
+   priv->oldduplex = DUPLEX_UNKNOWN;
return 0;
 }
 EXPORT_SYMBOL_GPL(stmmac_suspend);
-- 
2.10.2



[PATCH v3 4/8] net: stmmac: set speed at SPEED_UNKNOWN in case of broken speed

2017-02-15 Thread Corentin Labbe
In case of invalid speed given, stmmac_adjust_link() still record it as
current speed.
This patch modify the default case to set speed as SPEED_UNKNOWN if not
10/100/1000.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
Reviewed-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a87071d..f7664b9 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -739,6 +739,7 @@ static void stmmac_adjust_link(struct net_device *dev)
default:
netif_warn(priv, link, priv->dev,
   "broken speed: %d\n", phydev->speed);
+   phydev->speed = SPEED_UNKNOWN;
break;
}
 
-- 
2.10.2



[PATCH v3 0/8] misc patchs

2017-02-15 Thread Corentin Labbe
Hello

This is a follow up of my previous stmmac serie which address some comment
done in v2.

Corentin Labbe (8):
  net: stmmac: remove useless parenthesis
  net: stmmac: likely is useless in occasional function
  net: stmmac: use SPEED_UNKNOWN/DUPLEX_UNKNOWN
  net: stmmac: set speed at SPEED_UNKNOWN in case of broken speed
  net: stmmac: run stmmac_hw_fix_mac_speed when speed is valid
  net: stmmac: split the stmmac_adjust_link 10/100 case
  net: stmmac: reduce indentation by adding a continue
  net: stmmac: invert the logic for dumping regs

 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   | 18 ++---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 40 ++-
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c  | 82 +++---
 3 files changed, 71 insertions(+), 69 deletions(-)

-- 
2.10.2



[PATCH v3 1/8] net: stmmac: remove useless parenthesis

2017-02-15 Thread Corentin Labbe
This patch remove some useless parenthesis.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
Reviewed-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 7251871..ee1dbf4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -716,15 +716,15 @@ static void stmmac_adjust_link(struct net_device *dev)
new_state = 1;
switch (phydev->speed) {
case 1000:
-   if (likely((priv->plat->has_gmac) ||
-  (priv->plat->has_gmac4)))
+   if (likely(priv->plat->has_gmac ||
+  priv->plat->has_gmac4))
ctrl &= ~priv->hw->link.port;
stmmac_hw_fix_mac_speed(priv);
break;
case 100:
case 10:
-   if (likely((priv->plat->has_gmac) ||
-  (priv->plat->has_gmac4))) {
+   if (likely(priv->plat->has_gmac ||
+  priv->plat->has_gmac4)) {
ctrl |= priv->hw->link.port;
if (phydev->speed == SPEED_100) {
ctrl |= priv->hw->link.speed;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index d9893cf..a695773 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -257,7 +257,7 @@ int stmmac_mdio_register(struct net_device *ndev)
 * If an IRQ was provided to be assigned after
 * the bus probe, do it here.
 */
-   if ((!mdio_bus_data->irqs) &&
+   if (!mdio_bus_data->irqs &&
(mdio_bus_data->probed_phy_irq > 0)) {
new_bus->irq[addr] =
mdio_bus_data->probed_phy_irq;
-- 
2.10.2



[PATCH v3 2/8] net: stmmac: likely is useless in occasional function

2017-02-15 Thread Corentin Labbe
The stmmac_adjust_link() function is called too rarely for having
likely() macros being useful.
Just remove likely annotation in it.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
Reviewed-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index ee1dbf4..511c47c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -716,15 +716,15 @@ static void stmmac_adjust_link(struct net_device *dev)
new_state = 1;
switch (phydev->speed) {
case 1000:
-   if (likely(priv->plat->has_gmac ||
-  priv->plat->has_gmac4))
+   if (priv->plat->has_gmac ||
+   priv->plat->has_gmac4)
ctrl &= ~priv->hw->link.port;
stmmac_hw_fix_mac_speed(priv);
break;
case 100:
case 10:
-   if (likely(priv->plat->has_gmac ||
-  priv->plat->has_gmac4)) {
+   if (priv->plat->has_gmac ||
+   priv->plat->has_gmac4) {
ctrl |= priv->hw->link.port;
if (phydev->speed == SPEED_100) {
ctrl |= priv->hw->link.speed;
-- 
2.10.2



[PATCH v3 6/8] net: stmmac: split the stmmac_adjust_link 10/100 case

2017-02-15 Thread Corentin Labbe
The 10/100 case have too many ifcase.
This patch split it for removing an if.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
Reviewed-by: Giuseppe Cavallaro <peppe.cavall...@st.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index bebe810..3cbe096 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -721,15 +721,19 @@ static void stmmac_adjust_link(struct net_device *dev)
ctrl &= ~priv->hw->link.port;
break;
case 100:
+   if (priv->plat->has_gmac ||
+   priv->plat->has_gmac4) {
+   ctrl |= priv->hw->link.port;
+   ctrl |= priv->hw->link.speed;
+   } else {
+   ctrl &= ~priv->hw->link.port;
+   }
+   break;
case 10:
if (priv->plat->has_gmac ||
priv->plat->has_gmac4) {
ctrl |= priv->hw->link.port;
-   if (phydev->speed == SPEED_100) {
-   ctrl |= priv->hw->link.speed;
-   } else {
-   ctrl &= ~(priv->hw->link.speed);
-   }
+   ctrl &= ~(priv->hw->link.speed);
} else {
ctrl &= ~priv->hw->link.port;
}
-- 
2.10.2



[PATCH 7/8] net: stmmac: reduce indentation by adding a continue

2017-02-14 Thread Corentin Labbe
As suggested by Joe Perches, replacing the "if phydev" logic permit to
reduce indentation in the for loop.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 82 +++
 1 file changed, 40 insertions(+), 42 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index a695773..db157a4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -247,50 +247,48 @@ int stmmac_mdio_register(struct net_device *ndev)
found = 0;
for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
struct phy_device *phydev = mdiobus_get_phy(new_bus, addr);
+   int act = 0;
+   char irq_num[4];
+   char *irq_str;
+
+   if (!phydev)
+   continue;
+
+   /*
+* If an IRQ was provided to be assigned after
+* the bus probe, do it here.
+*/
+   if (!mdio_bus_data->irqs &&
+   (mdio_bus_data->probed_phy_irq > 0)) {
+   new_bus->irq[addr] = mdio_bus_data->probed_phy_irq;
+   phydev->irq = mdio_bus_data->probed_phy_irq;
+   }
 
-   if (phydev) {
-   int act = 0;
-   char irq_num[4];
-   char *irq_str;
-
-   /*
-* If an IRQ was provided to be assigned after
-* the bus probe, do it here.
-*/
-   if (!mdio_bus_data->irqs &&
-   (mdio_bus_data->probed_phy_irq > 0)) {
-   new_bus->irq[addr] =
-   mdio_bus_data->probed_phy_irq;
-   phydev->irq = mdio_bus_data->probed_phy_irq;
-   }
-
-   /*
-* If we're going to bind the MAC to this PHY bus,
-* and no PHY number was provided to the MAC,
-* use the one probed here.
-*/
-   if (priv->plat->phy_addr == -1)
-   priv->plat->phy_addr = addr;
-
-   act = (priv->plat->phy_addr == addr);
-   switch (phydev->irq) {
-   case PHY_POLL:
-   irq_str = "POLL";
-   break;
-   case PHY_IGNORE_INTERRUPT:
-   irq_str = "IGNORE";
-   break;
-   default:
-   sprintf(irq_num, "%d", phydev->irq);
-   irq_str = irq_num;
-   break;
-   }
-   netdev_info(ndev, "PHY ID %08x at %d IRQ %s (%s)%s\n",
-   phydev->phy_id, addr,
-   irq_str, phydev_name(phydev),
-   act ? " active" : "");
-   found = 1;
+   /*
+* If we're going to bind the MAC to this PHY bus,
+* and no PHY number was provided to the MAC,
+* use the one probed here.
+*/
+   if (priv->plat->phy_addr == -1)
+   priv->plat->phy_addr = addr;
+
+   act = (priv->plat->phy_addr == addr);
+   switch (phydev->irq) {
+   case PHY_POLL:
+   irq_str = "POLL";
+   break;
+   case PHY_IGNORE_INTERRUPT:
+   irq_str = "IGNORE";
+   break;
+   default:
+   sprintf(irq_num, "%d", phydev->irq);
+   irq_str = irq_num;
+   break;
}
+   netdev_info(ndev, "PHY ID %08x at %d IRQ %s (%s)%s\n",
+   phydev->phy_id, addr, irq_str, phydev_name(phydev),
+   act ? " active" : "");
+   found = 1;
}
 
if (!found && !mdio_node) {
-- 
2.10.2



[PATCH 8/8] net: stmmac: invert the logic for dumping regs

2017-02-14 Thread Corentin Labbe
It is easier to follow the logic by removing the not operator

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index aab895d..5ff6bc4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -442,24 +442,24 @@ static void stmmac_ethtool_gregs(struct net_device *dev,
 
memset(reg_space, 0x0, REG_SPACE_SIZE);
 
-   if (!(priv->plat->has_gmac || priv->plat->has_gmac4)) {
+   if (priv->plat->has_gmac || priv->plat->has_gmac4) {
/* MAC registers */
-   for (i = 0; i < 12; i++)
+   for (i = 0; i < 55; i++)
reg_space[i] = readl(priv->ioaddr + (i * 4));
/* DMA registers */
-   for (i = 0; i < 9; i++)
-   reg_space[i + 12] =
+   for (i = 0; i < 22; i++)
+   reg_space[i + 55] =
readl(priv->ioaddr + (DMA_BUS_MODE + (i * 4)));
-   reg_space[22] = readl(priv->ioaddr + DMA_CUR_TX_BUF_ADDR);
-   reg_space[23] = readl(priv->ioaddr + DMA_CUR_RX_BUF_ADDR);
} else {
/* MAC registers */
-   for (i = 0; i < 55; i++)
+   for (i = 0; i < 12; i++)
reg_space[i] = readl(priv->ioaddr + (i * 4));
/* DMA registers */
-   for (i = 0; i < 22; i++)
-   reg_space[i + 55] =
+   for (i = 0; i < 9; i++)
+   reg_space[i + 12] =
readl(priv->ioaddr + (DMA_BUS_MODE + (i * 4)));
+   reg_space[22] = readl(priv->ioaddr + DMA_CUR_TX_BUF_ADDR);
+   reg_space[23] = readl(priv->ioaddr + DMA_CUR_RX_BUF_ADDR);
}
 }
 
-- 
2.10.2



[PATCH 4/8] net: stmmac: set speed at SPEED_UNKNOWN in case of broken speed

2017-02-14 Thread Corentin Labbe
In case of invalid speed given, stmmac_adjust_link() still record it as
current speed.
This patch modify the default case to set speed as SPEED_UNKNOWN if not
10/100/1000.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a87071d..f7664b9 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -739,6 +739,7 @@ static void stmmac_adjust_link(struct net_device *dev)
default:
netif_warn(priv, link, priv->dev,
   "broken speed: %d\n", phydev->speed);
+   phydev->speed = SPEED_UNKNOWN;
break;
}
 
-- 
2.10.2



[PATCH 6/8] net: stmmac: split the stmmac_adjust_link 10/100 case

2017-02-14 Thread Corentin Labbe
The 10/100 case have too many ifcase.
This patch split it for removing an if.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index bebe810..3cbe096 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -721,15 +721,19 @@ static void stmmac_adjust_link(struct net_device *dev)
ctrl &= ~priv->hw->link.port;
break;
case 100:
+   if (priv->plat->has_gmac ||
+   priv->plat->has_gmac4) {
+   ctrl |= priv->hw->link.port;
+   ctrl |= priv->hw->link.speed;
+   } else {
+   ctrl &= ~priv->hw->link.port;
+   }
+   break;
case 10:
if (priv->plat->has_gmac ||
priv->plat->has_gmac4) {
ctrl |= priv->hw->link.port;
-   if (phydev->speed == SPEED_100) {
-   ctrl |= priv->hw->link.speed;
-   } else {
-   ctrl &= ~(priv->hw->link.speed);
-   }
+   ctrl &= ~(priv->hw->link.speed);
} else {
ctrl &= ~priv->hw->link.port;
}
-- 
2.10.2



[PATCH 5/8] net: stmmac: run stmmac_hw_fix_mac_speed when speed is valid

2017-02-14 Thread Corentin Labbe
This patch mutualise a bit by running stmmac_hw_fix_mac_speed() after
the switch in case of valid speed.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index f7664b9..bebe810 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -719,7 +719,6 @@ static void stmmac_adjust_link(struct net_device *dev)
if (priv->plat->has_gmac ||
priv->plat->has_gmac4)
ctrl &= ~priv->hw->link.port;
-   stmmac_hw_fix_mac_speed(priv);
break;
case 100:
case 10:
@@ -734,7 +733,6 @@ static void stmmac_adjust_link(struct net_device *dev)
} else {
ctrl &= ~priv->hw->link.port;
}
-   stmmac_hw_fix_mac_speed(priv);
break;
default:
netif_warn(priv, link, priv->dev,
@@ -742,7 +740,8 @@ static void stmmac_adjust_link(struct net_device *dev)
phydev->speed = SPEED_UNKNOWN;
break;
}
-
+   if (phydev->speed != SPEED_UNKNOWN)
+   stmmac_hw_fix_mac_speed(priv);
priv->speed = phydev->speed;
}
 
-- 
2.10.2



[PATCH 1/8] net: stmmac: remove useless parenthesis

2017-02-14 Thread Corentin Labbe
This patch remove some useless parenthesis.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 7251871..ee1dbf4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -716,15 +716,15 @@ static void stmmac_adjust_link(struct net_device *dev)
new_state = 1;
switch (phydev->speed) {
case 1000:
-   if (likely((priv->plat->has_gmac) ||
-  (priv->plat->has_gmac4)))
+   if (likely(priv->plat->has_gmac ||
+  priv->plat->has_gmac4))
ctrl &= ~priv->hw->link.port;
stmmac_hw_fix_mac_speed(priv);
break;
case 100:
case 10:
-   if (likely((priv->plat->has_gmac) ||
-  (priv->plat->has_gmac4))) {
+   if (likely(priv->plat->has_gmac ||
+  priv->plat->has_gmac4)) {
ctrl |= priv->hw->link.port;
if (phydev->speed == SPEED_100) {
ctrl |= priv->hw->link.speed;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index d9893cf..a695773 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -257,7 +257,7 @@ int stmmac_mdio_register(struct net_device *ndev)
 * If an IRQ was provided to be assigned after
 * the bus probe, do it here.
 */
-   if ((!mdio_bus_data->irqs) &&
+   if (!mdio_bus_data->irqs &&
(mdio_bus_data->probed_phy_irq > 0)) {
new_bus->irq[addr] =
mdio_bus_data->probed_phy_irq;
-- 
2.10.2



[PATCH 0/8] net: stmmac: misc patchs

2017-02-14 Thread Corentin Labbe
Hello

This is a follow up of my previous stmmac serie which address some comment
done in v2.

Corentin Labbe (8):
  net: stmmac: remove useless parenthesis
  net: stmmac: likely is useless in occasional function
  net: stmmac: use SPEED_UNKNOWN/DUPLEX_UNKNOWN
  net: stmmac: set speed at SPEED_UNKNOWN in case of broken speed
  net: stmmac: run stmmac_hw_fix_mac_speed when speed is valid
  net: stmmac: split the stmmac_adjust_link 10/100 case
  net: stmmac: reduce indentation by adding a continue
  net: stmmac: invert the logic for dumping regs

 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   | 18 ++---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 40 ++-
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c  | 82 +++---
 3 files changed, 71 insertions(+), 69 deletions(-)

-- 
2.10.2



[PATCH 3/8] net: stmmac: use SPEED_UNKNOWN/DUPLEX_UNKNOWN

2017-02-14 Thread Corentin Labbe
It is better to use DUPLEX_UNKNOWN instead of just "-1".
Using 0 for an invalid speed is bad since 0 is a valid value for speed.
So this patch replace 0 by SPEED_UNKNOWN.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 511c47c..a87071d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -754,8 +754,8 @@ static void stmmac_adjust_link(struct net_device *dev)
} else if (priv->oldlink) {
new_state = 1;
priv->oldlink = 0;
-   priv->speed = 0;
-   priv->oldduplex = -1;
+   priv->speed = SPEED_UNKNOWN;
+   priv->oldduplex = DUPLEX_UNKNOWN;
}
 
if (new_state && netif_msg_link(priv))
@@ -817,8 +817,8 @@ static int stmmac_init_phy(struct net_device *dev)
int interface = priv->plat->interface;
int max_speed = priv->plat->max_speed;
priv->oldlink = 0;
-   priv->speed = 0;
-   priv->oldduplex = -1;
+   priv->speed = SPEED_UNKNOWN;
+   priv->oldduplex = DUPLEX_UNKNOWN;
 
if (priv->plat->phy_node) {
phydev = of_phy_connect(dev, priv->plat->phy_node,
@@ -3434,8 +3434,8 @@ int stmmac_suspend(struct device *dev)
spin_unlock_irqrestore(>lock, flags);
 
priv->oldlink = 0;
-   priv->speed = 0;
-   priv->oldduplex = -1;
+   priv->speed = SPEED_UNKNOWN;
+   priv->oldduplex = DUPLEX_UNKNOWN;
return 0;
 }
 EXPORT_SYMBOL_GPL(stmmac_suspend);
-- 
2.10.2



[PATCH 2/8] net: stmmac: likely is useless in occasional function

2017-02-14 Thread Corentin Labbe
The stmmac_adjust_link() function is called too rarely for having
likely() macros being useful.
Just remove likely annotation in it.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index ee1dbf4..511c47c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -716,15 +716,15 @@ static void stmmac_adjust_link(struct net_device *dev)
new_state = 1;
switch (phydev->speed) {
case 1000:
-   if (likely(priv->plat->has_gmac ||
-  priv->plat->has_gmac4))
+   if (priv->plat->has_gmac ||
+   priv->plat->has_gmac4)
ctrl &= ~priv->hw->link.port;
stmmac_hw_fix_mac_speed(priv);
break;
case 100:
case 10:
-   if (likely(priv->plat->has_gmac ||
-  priv->plat->has_gmac4)) {
+   if (priv->plat->has_gmac ||
+   priv->plat->has_gmac4) {
ctrl |= priv->hw->link.port;
if (phydev->speed == SPEED_100) {
ctrl |= priv->hw->link.speed;
-- 
2.10.2



Re: [PATCH 0/8] net: stmmac: misc patchs

2017-02-14 Thread Corentin Labbe
On Wed, Feb 15, 2017 at 07:34:41AM +0100, Giuseppe CAVALLARO wrote:
> Hello Corentin
> 
> On 2/14/2017 8:54 PM, Corentin Labbe wrote:
> > Hello
> >
> > This is a follow up of my previous stmmac serie which address some comment
> > done in v2.
> 
> I wonder if you can resend all the patches as V3
> please add the Acked-by and Reviewed-by. This will help
> on final review and integration.
> 
> Thx for your support and effort
> 
> Peppe
> 

Hello

Since all patch in v2 already hit linux-next, I just want to be sure, I can add 
"Acked-by and Reviewed-by" to thoses 8 new patchs ?

Regards

> >
> > Corentin Labbe (8):
> >   net: stmmac: remove useless parenthesis
> >   net: stmmac: likely is useless in occasional function
> >   net: stmmac: use SPEED_UNKNOWN/DUPLEX_UNKNOWN
> >   net: stmmac: set speed at SPEED_UNKNOWN in case of broken speed
> >   net: stmmac: run stmmac_hw_fix_mac_speed when speed is valid
> >   net: stmmac: split the stmmac_adjust_link 10/100 case
> >   net: stmmac: reduce indentation by adding a continue
> >   net: stmmac: invert the logic for dumping regs
> >
> >  .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   | 18 ++---
> >  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 40 ++-
> >  drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c  | 82 
> > +++---
> >  3 files changed, 71 insertions(+), 69 deletions(-)
> >
> 


[PATCH 00/21] net-next: stmmac: add dwmac-sun8i ethernet driver

2017-02-16 Thread Corentin Labbe
Hello

This patch series add the driver for dwmac-sun8i which handle the Ethernet MAC
present on Allwinner H3/A83T/A64 SoCs.

This driver is the continuation of the sun8i-emac driver.
During the development, it appeared that in fact the hardware was a modified
version of some dwmac.
So the driver is now written as a glue driver for stmmac.

It supports 10/100/1000 Mbit/s speed with half/full duplex.
It can use an internal PHY (MII 10/100) or an external PHY
via RGMII/RMII.

This patch series enable the driver only for the H3/A64 SoC since A83T
doesn't have the necessary clocks present in mainline.

The driver have been tested on the following boards:
- H3 Orange PI PC, BananaPI-M2+
- A64 Pine64, BananaPi-M64
- A83T BananaPI-M3

The first three patchs are some mandatory changes for letting dwmac-sun8i be 
used.
The following two patchs add the driver and its documentation.
The remaining are DT patch enabling it.

Regards
Corentin Labbe

Corentin Labbe (16):
  net-next: stmmac add optional init_phy function
  net-next: stmmac: export stmmac_set_mac_addr/stmmac_get_mac_addr
  net-next: stmmac: add optional setup function
  ARM: sun8i: dt: Add DT bindings documentation for Allwinner
dwmac-sun8i
  net-next: stmmac: Add dwmac-sun8i
  ARM: dts: sun8i-h3: add dwmac-sun8i rgmii pins
  ARM: dts: sun8i: Enable dwmac-sun8i on the Orange Pi 2
  ARM: dts: sun8i: Enable dwmac-sun8i on the Orange PI One
  ARM: dts: sun8i: Enable dwmac-sun8i on the Orange Pi plus
  ARM: dts: sun8i: orangepi-pc-plus: Set EMAC activity LEDs to active
high
  ARM64: dts: sun50i-a64: Add dt node for the syscon control module
  ARM64: dts: sun50i-a64: add dwmac-sun8i Ethernet driver
  ARM: dts: sun50i-a64: enable dwmac-sun8i on pine64
  ARM: dts: sun50i-a64: enable dwmac-sun8i on pine64 plus
  ARM: dts: sun50i-a64: enable dwmac-sun8i on the BananaPi M64
  ARM: sunxi: Enable dwmac-sun8i driver on multi_v7_defconfig

LABBE Corentin (5):
  ARM: dts: sun8i-h3: Add dt node for the syscon control module
  ARM: dts: sun8i-h3: add dwmac-sun8i ethernet driver
  ARM: dts: sun8i: Enable dwmac-sun8i on the Banana Pi M2+
  ARM: dts: sun8i: Enable dwmac-sun8i on the Orange PI PC
  ARM: sunxi: Enable dwmac-sun8i driver on sunxi_defconfig

 .../devicetree/bindings/net/dwmac-sun8i.txt|  86 ++
 arch/arm/boot/dts/sun8i-h3-bananapi-m2-plus.dts|  38 +
 arch/arm/boot/dts/sun8i-h3-orangepi-2.dts  |   8 +
 arch/arm/boot/dts/sun8i-h3-orangepi-one.dts|   8 +
 arch/arm/boot/dts/sun8i-h3-orangepi-pc-plus.dts|   5 +
 arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts |   8 +
 arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts   |  36 +
 arch/arm/boot/dts/sun8i-h3.dtsi|  42 +
 arch/arm/configs/multi_v7_defconfig|   1 +
 arch/arm/configs/sunxi_defconfig   |   1 +
 .../boot/dts/allwinner/sun50i-a64-bananapi-m64.dts |  14 +
 .../boot/dts/allwinner/sun50i-a64-pine64-plus.dts  |  16 +-
 .../arm64/boot/dts/allwinner/sun50i-a64-pine64.dts |  15 +
 arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi  |  43 +
 drivers/net/ethernet/stmicro/stmmac/Kconfig|  11 +
 drivers/net/ethernet/stmicro/stmmac/Makefile   |   1 +
 drivers/net/ethernet/stmicro/stmmac/common.h   |   3 +
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c  | 892 +
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c|   3 +-
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   |   3 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |  45 +-
 .../net/ethernet/stmicro/stmmac/stmmac_platform.c  |   9 +-
 include/linux/stmmac.h |   4 +
 23 files changed, 1286 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/dwmac-sun8i.txt
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c

-- 
2.10.2



[PATCH 04/21] ARM: sun8i: dt: Add DT bindings documentation for Allwinner dwmac-sun8i

2017-02-16 Thread Corentin Labbe
This patch adds documentation for Device-Tree bindings for the
Allwinner dwmac-sun8i driver.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 .../devicetree/bindings/net/dwmac-sun8i.txt| 86 ++
 1 file changed, 86 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dwmac-sun8i.txt

diff --git a/Documentation/devicetree/bindings/net/dwmac-sun8i.txt 
b/Documentation/devicetree/bindings/net/dwmac-sun8i.txt
new file mode 100644
index 000..ac806c6
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/dwmac-sun8i.txt
@@ -0,0 +1,86 @@
+* Allwinner sun8i GMAC ethernet controller
+
+This device is a platform glue layer for stmmac.
+Please see stmmac.txt for the other unchanged properties.
+
+Required properties:
+- compatible: should be one of the following string:
+   "allwinner,sun8i-a83t-emac"
+   "allwinner,sun8i-h3-emac"
+   "allwinner,sun50i-a64-emac"
+- reg: address and length of the register for the device.
+- interrupts: interrupt for the device
+- interrupt-names: should be "macirq"
+- clocks: A phandle to the reference clock for this device
+- clock-names: should be "stmmaceth"
+- resets: A phandle to the reset control for this device
+- reset-names: should be "stmmaceth"
+- phy-mode: See ethernet.txt
+- phy-handle: See ethernet.txt
+- #address-cells: shall be 1
+- #size-cells: shall be 0
+- syscon: A phandle to the syscon of the SoC with one of the following
+ compatible string:
+  - allwinner,sun8i-h3-system-controller
+  - allwinner,sun8i-a64-system-controller
+  - allwinner,sun8i-a83t-system-controller
+
+Optional properties:
+- allwinner,tx-delay: TX clock delay chain value. Range value is 0-0x07. 
Default is 0)
+- allwinner,rx-delay: RX clock delay chain value. Range value is 0-0x1F. 
Default is 0)
+Both delay properties does not have units, there are arbitrary value.
+The TX/RX clock delay chain settings are board specific and could be found
+in vendor FEX files.
+
+Optional properties for "allwinner,sun8i-h3-emac":
+- allwinner,leds-active-low: EPHY LEDs are active low
+
+Required child node of emac:
+- mdio bus node: should be named mdio
+
+Required properties of the mdio node:
+- #address-cells: shall be 1
+- #size-cells: shall be 0
+
+The device node referenced by "phy" or "phy-handle" should be a child node
+of the mdio node. See phy.txt for the generic PHY bindings.
+
+Required properties of the phy node with "allwinner,sun8i-h3-emac":
+- clocks: an extra phandle to the reference clock for the EPHY
+- resets: an extra phandle to the reset control for the EPHY
+
+Required properties for the system controller:
+- reg: address and length of the register for the device.
+- compatible: should be "syscon" and one of the following string:
+   "allwinner,sun8i-h3-system-controller"
+   "allwinner,sun8i-a64-system-controller"
+   "allwinner,sun8i-a83t-system-controller"
+
+Example:
+
+emac: ethernet@1c0b000 {
+   compatible = "allwinner,sun8i-h3-emac";
+   syscon = <>;
+   reg = <0x01c0b000 0x104>;
+   interrupts = ;
+   interrupt-names = "macirq";
+   resets = < RST_BUS_EMAC>;
+   reset-names = "stmmaceth";
+   clocks = < CLK_BUS_EMAC>;
+   clock-names = "stmmaceth";
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   phy = <_mii_phy>;
+   phy-mode = "mii";
+   allwinner,leds-active-low;
+   mdio: mdio {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   int_mii_phy: ethernet-phy@1 {
+   reg = <1>;
+   clocks = < CLK_BUS_EPHY>;
+   resets = < RST_BUS_EPHY>;
+   };
+   };
+};
-- 
2.10.2



[PATCH 13/21] ARM: dts: sun8i: Enable dwmac-sun8i on the Orange Pi plus

2017-02-16 Thread Corentin Labbe
The dwmac-sun8i hardware is present on the Orange PI plus.
It uses an external PHY rtl8211e via RGMII.

This patch create the needed regulator, emac and phy nodes.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts | 36 
 1 file changed, 36 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts 
b/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts
index 8c40ab7..17b2b92 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts
@@ -58,6 +58,18 @@
enable-active-high;
gpio = < 6 11 GPIO_ACTIVE_HIGH>;
};
+
+   reg_gmac_3v3: gmac-3v3 {
+   compatible = "regulator-fixed";
+   pinctrl-names = "default";
+   pinctrl-0 = <_power_pin_orangepi>;
+   regulator-name = "gmac-3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   startup-delay-us = <10>;
+   enable-active-high;
+   gpio = < 3 6 GPIO_ACTIVE_HIGH>;
+   };
 };
 
  {
@@ -86,8 +98,32 @@
pins = "PG11";
function = "gpio_out";
};
+
+   gmac_power_pin_orangepi: gmac_power_pin@0 {
+   allwinner,pins = "PD6";
+   allwinner,function = "gpio_out";
+   allwinner,drive = ;
+   allwinner,pull = ;
+   };
 };
 
  {
usb3_vbus-supply = <_usb3_vbus>;
 };
+
+ {
+   ext_rgmii_phy: ethernet-phy@1 {
+   reg = <0>;
+   };
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_rgmii_pins>;
+   phy-supply = <_gmac_3v3>;
+   phy-handle = <_rgmii_phy>;
+   phy-mode = "rgmii";
+
+   allwinner,leds-active-low;
+   status = "okay";
+};
-- 
2.10.2



[PATCH 12/21] ARM: dts: sun8i: Enable dwmac-sun8i on the Orange PI One

2017-02-16 Thread Corentin Labbe
The dwmac-sun8i hardware is present on the Orange PI One.
It uses the internal PHY.

This patch create the needed emac node.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/boot/dts/sun8i-h3-orangepi-one.dts | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts 
b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
index 34da853..a053b79 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
@@ -54,6 +54,7 @@
 
aliases {
serial0 = 
+   ethernet0 = 
};
 
chosen {
@@ -94,6 +95,13 @@
status = "okay";
 };
 
+ {
+   phy-handle = <_mii_phy>;
+   phy-mode = "mii";
+   allwinner,leds-active-low;
+   status = "okay";
+};
+
  {
pinctrl-names = "default";
pinctrl-0 = <_pins_a>, <_cd_pin>;
-- 
2.10.2



[PATCH 08/21] ARM: dts: sun8i-h3: add dwmac-sun8i rgmii pins

2017-02-16 Thread Corentin Labbe
This patch add pinctrl node for dwmac-sun8i on H3.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/boot/dts/sun8i-h3.dtsi | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index 61d56d2..59ed40e 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -349,6 +349,17 @@
function = "i2c2";
};
 
+   emac_rgmii_pins: emac0@0 {
+   allwinner,pins = "PD0", "PD1", "PD2", "PD3",
+   "PD4", "PD5", "PD7",
+   "PD8", "PD9", "PD10",
+   "PD12", "PD13", "PD15",
+   "PD16", "PD17";
+   allwinner,function = "emac";
+   allwinner,drive = ;
+   allwinner,pull = ;
+   };
+
mmc0_pins_a: mmc0@0 {
pins = "PF0", "PF1", "PF2", "PF3",
   "PF4", "PF5";
-- 
2.10.2



[PATCH 17/21] ARM: dts: sun50i-a64: enable dwmac-sun8i on pine64

2017-02-16 Thread Corentin Labbe
The dwmac-sun8i hardware is present on the pine64
It uses an external PHY via RMII.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm64/boot/dts/allwinner/sun50i-a64-pine64.dts | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64.dts 
b/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64.dts
index c680ed3..b53994d 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64.dts
@@ -109,3 +109,18 @@
  {
status = "okay";
 };
+
+ {
+   ext_rmii_phy1: ethernet-phy@1 {
+ reg = <1>;
+   };
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   phy-mode = "rmii";
+   phy-handle = <_rmii_phy1>;
+   status = "okay";
+
+};
-- 
2.10.2



[PATCH 01/21] net-next: stmmac add optional init_phy function

2017-02-16 Thread Corentin Labbe
For dwmac-sun8i, some actions must be done for enabling attached PHY.
Thoses actions must be done after stmmac_probe_config_dt() and
at start of stmmac_init_phy().

The best way to handle that is to add an optional init_phy() function.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/common.h  |  3 +++
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index 144fe84..daaafa9 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -483,6 +483,9 @@ struct stmmac_ops {
 bool loopback);
void (*pcs_rane)(void __iomem *ioaddr, bool restart);
void (*pcs_get_adv_lp)(void __iomem *ioaddr, struct rgmii_adv *adv);
+   /* optional function for powering/init PHY */
+   int (*init_phy)(struct net_device *ndev);
+   void (*uninit_phy)(struct net_device *ndev);
 };
 
 /* PTP and HW Timer helpers */
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 3cbe096..942efb7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -820,10 +820,18 @@ static int stmmac_init_phy(struct net_device *dev)
char bus_id[MII_BUS_ID_SIZE];
int interface = priv->plat->interface;
int max_speed = priv->plat->max_speed;
+   int ret;
+
priv->oldlink = 0;
priv->speed = SPEED_UNKNOWN;
priv->oldduplex = DUPLEX_UNKNOWN;
 
+   if (priv->hw->mac->init_phy) {
+   ret = priv->hw->mac->init_phy(dev);
+   if (ret)
+   return ret;
+   }
+
if (priv->plat->phy_node) {
phydev = of_phy_connect(dev, priv->plat->phy_node,
_adjust_link, 0, interface);
@@ -1892,6 +1900,9 @@ static int stmmac_release(struct net_device *dev)
phy_disconnect(dev->phydev);
}
 
+   if (priv->hw->mac->uninit_phy)
+   priv->hw->mac->uninit_phy(dev);
+
netif_stop_queue(dev);
 
napi_disable(>napi);
-- 
2.10.2



[PATCH 02/21] net-next: stmmac: export stmmac_set_mac_addr/stmmac_get_mac_addr

2017-02-16 Thread Corentin Labbe
Thoses symbol will be needed for the dwmac-sun8i ethernet driver.
For letting it to be build as module, they need to be exported.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
index e60bfca..0ab985c8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
@@ -248,6 +248,7 @@ void stmmac_set_mac_addr(void __iomem *ioaddr, u8 addr[6],
data = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0];
writel(data, ioaddr + low);
 }
+EXPORT_SYMBOL_GPL(stmmac_set_mac_addr);
 
 /* Enable disable MAC RX/TX */
 void stmmac_set_mac(void __iomem *ioaddr, bool enable)
@@ -279,4 +280,4 @@ void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned 
char *addr,
addr[4] = hi_addr & 0xff;
addr[5] = (hi_addr >> 8) & 0xff;
 }
-
+EXPORT_SYMBOL_GPL(stmmac_get_mac_addr);
-- 
2.10.2



[PATCH 20/21] ARM: sunxi: Enable dwmac-sun8i driver on sunxi_defconfig

2017-02-16 Thread Corentin Labbe
From: LABBE Corentin <clabbe.montj...@gmail.com>

Enable the dwmac-sun8i driver in the sunxi default configuration

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/configs/sunxi_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/sunxi_defconfig b/arch/arm/configs/sunxi_defconfig
index da92c25..33bde86 100644
--- a/arch/arm/configs/sunxi_defconfig
+++ b/arch/arm/configs/sunxi_defconfig
@@ -40,6 +40,7 @@ CONFIG_ATA=y
 CONFIG_AHCI_SUNXI=y
 CONFIG_NETDEVICES=y
 CONFIG_SUN4I_EMAC=y
+CONFIG_DWMAC_SUN8I=m
 # CONFIG_NET_VENDOR_ARC is not set
 # CONFIG_NET_CADENCE is not set
 # CONFIG_NET_VENDOR_BROADCOM is not set
-- 
2.10.2



[PATCH 14/21] ARM: dts: sun8i: orangepi-pc-plus: Set EMAC activity LEDs to active high

2017-02-16 Thread Corentin Labbe
On the Orange Pi PC Plus, the polarity of the LEDs on the RJ45 Ethernet
port were changed from active low to active high.

Signed-off-by: Chen-Yu Tsai <w...@csie.org>
Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/boot/dts/sun8i-h3-orangepi-pc-plus.dts | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-pc-plus.dts 
b/arch/arm/boot/dts/sun8i-h3-orangepi-pc-plus.dts
index 8b93f5c..0380769 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-pc-plus.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-pc-plus.dts
@@ -86,3 +86,8 @@
/* eMMC is missing pull-ups */
bias-pull-up;
 };
+
+ {
+   /* LEDs changed to active high on the plus */
+   /delete-property/ allwinner,leds-active-low;
+};
-- 
2.10.2



[PATCH 15/21] ARM64: dts: sun50i-a64: Add dt node for the syscon control module

2017-02-16 Thread Corentin Labbe
This patch add the dt node for the syscon register present on the
Allwinner A64.

Only two register are present in this syscon and the only one useful is
the one dedicated to EMAC clock.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi 
b/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
index 1c64ea2..3b09af2 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
@@ -121,6 +121,12 @@
#size-cells = <1>;
ranges;
 
+   syscon: syscon@01c0 {
+   compatible = "syscon",
+   "allwinner,sun8i-h3-system-controller";
+   reg = <0x01c0 0x1000>;
+   };
+
mmc0: mmc@1c0f000 {
compatible = "allwinner,sun50i-a64-mmc";
reg = <0x01c0f000 0x1000>;
-- 
2.10.2



[PATCH 16/21] ARM64: dts: sun50i-a64: add dwmac-sun8i Ethernet driver

2017-02-16 Thread Corentin Labbe
The dwmac-sun8i is an Ethernet MAC that supports 10/100/1000 Mbit
connections. It is very similar to the device found in the Allwinner
H3, but lacks the internal 100 Mbit PHY and its associated control
bits.
This adds the necessary bits to the Allwinner A64 SoC .dtsi, but keeps
it disabled at this level.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi | 37 +++
 1 file changed, 37 insertions(+)

diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi 
b/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
index 3b09af2..57d69e5 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
@@ -277,6 +277,23 @@
bias-pull-up;
};
 
+   rmii_pins: rmii_pins {
+   pins = "PD10", "PD11", "PD13", "PD14",
+   "PD17", "PD18", "PD19", "PD20",
+   "PD22", "PD23";
+   function = "emac";
+   drive-strength = <40>;
+   };
+
+   rgmii_pins: rgmii_pins {
+   pins = "PD8", "PD9", "PD10", "PD11",
+   "PD12", "PD13", "PD15",
+   "PD16", "PD17", "PD18", "PD19",
+   "PD20", "PD21", "PD22", "PD23";
+   function = "emac";
+   drive-strength = <40>;
+   };
+
uart0_pins_a: uart0@0 {
pins = "PB8", "PB9";
function = "uart0";
@@ -381,6 +398,26 @@
#size-cells = <0>;
};
 
+   emac: ethernet@1c3 {
+   compatible = "allwinner,sun50i-a64-emac";
+   syscon = <>;
+   reg = <0x01c3 0x100>;
+   interrupts = ;
+   interrupt-names = "macirq";
+   resets = < RST_BUS_EMAC>;
+   reset-names = "stmmaceth";
+   clocks = < CLK_BUS_EMAC>;
+   clock-names = "stmmaceth";
+   status = "disabled";
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   mdio: mdio {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   };
+   };
+
gic: interrupt-controller@1c81000 {
compatible = "arm,gic-400";
reg = <0x01c81000 0x1000>,
-- 
2.10.2



[PATCH 18/21] ARM: dts: sun50i-a64: enable dwmac-sun8i on pine64 plus

2017-02-16 Thread Corentin Labbe
The dwmac-sun8i hardware is present on the pine64 plus.
It uses an external PHY rtl8211e via RGMII.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm64/boot/dts/allwinner/sun50i-a64-pine64-plus.dts | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64-plus.dts 
b/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64-plus.dts
index 790d14d..8e06aed 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64-plus.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64-plus.dts
@@ -46,5 +46,19 @@
model = "Pine64+";
compatible = "pine64,pine64-plus", "allwinner,sun50i-a64";
 
-   /* TODO: Camera, Ethernet PHY, touchscreen, etc. */
+   /* TODO: Camera, touchscreen, etc. */
+};
+
+ {
+   ext_rgmii_phy: ethernet-phy@1 {
+   reg = <1>;
+   };
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   phy-mode = "rgmii";
+   phy-handle = <_rgmii_phy>;
+   status = "okay";
 };
-- 
2.10.2



[PATCH 21/21] ARM: sunxi: Enable dwmac-sun8i driver on multi_v7_defconfig

2017-02-16 Thread Corentin Labbe
Enable the dwmac-sun8i driver in the multi_v7 default configuration

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/configs/multi_v7_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/multi_v7_defconfig 
b/arch/arm/configs/multi_v7_defconfig
index 3a17555..72f974d 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -257,6 +257,7 @@ CONFIG_SMSC911X=y
 CONFIG_STMMAC_ETH=y
 CONFIG_STMMAC_PLATFORM=y
 CONFIG_DWMAC_DWC_QOS_ETH=y
+CONFIG_DWMAC_SUN8I=m
 CONFIG_TI_CPSW=y
 CONFIG_XILINX_EMACLITE=y
 CONFIG_AT803X_PHY=y
-- 
2.10.2



[PATCH 19/21] ARM: dts: sun50i-a64: enable dwmac-sun8i on the BananaPi M64

2017-02-16 Thread Corentin Labbe
The dwmac-sun8i  hardware is present on the BananaPi M64.
It uses an external PHY rtl8211e via RGMII.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts 
b/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts
index 6872135..347c262 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts
@@ -77,6 +77,20 @@
bias-pull-up;
 };
 
+ {
+   ext_rgmii_phy: ethernet-phy@1 {
+   reg = <1>;
+   };
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   phy-mode = "rgmii";
+   phy-handle = <_rgmii_phy>;
+   status = "okay";
+};
+
  {
pinctrl-names = "default";
pinctrl-0 = <_pins>;
-- 
2.10.2



[PATCH 05/21] net-next: stmmac: Add dwmac-sun8i

2017-02-16 Thread Corentin Labbe
The dwmac-sun8i is a heavy hacked version of stmmac hardware by
allwinner.
In fact the only common part is the descriptor management and the first
register function.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/Kconfig|  11 +
 drivers/net/ethernet/stmicro/stmmac/Makefile   |   1 +
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c  | 892 +
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   |   3 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |  27 +-
 .../net/ethernet/stmicro/stmmac/stmmac_platform.c  |   9 +-
 include/linux/stmmac.h |   1 +
 7 files changed, 941 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c

diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig 
b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index cfbe363..85c0e41 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -145,6 +145,17 @@ config DWMAC_SUNXI
  This selects Allwinner SoC glue layer support for the
  stmmac device driver. This driver is used for A20/A31
  GMAC ethernet controller.
+
+config DWMAC_SUN8I
+   tristate "Allwinner sun8i GMAC support"
+   default ARCH_SUNXI
+   depends on OF && (ARCH_SUNXI || COMPILE_TEST)
+   ---help---
+ Support for Allwinner H3 A83T A64 EMAC ethernet controllers.
+
+ This selects Allwinner SoC glue layer support for the
+ stmmac device driver. This driver is used for H3/A83T/A64
+ EMAC ethernet controller.
 endif
 
 config STMMAC_PCI
diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile 
b/drivers/net/ethernet/stmicro/stmmac/Makefile
index 700c603..fd4937a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Makefile
+++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_DWMAC_SOCFPGA)   += dwmac-altr-socfpga.o
 obj-$(CONFIG_DWMAC_STI)+= dwmac-sti.o
 obj-$(CONFIG_DWMAC_STM32)  += dwmac-stm32.o
 obj-$(CONFIG_DWMAC_SUNXI)  += dwmac-sunxi.o
+obj-$(CONFIG_DWMAC_SUN8I)  += dwmac-sun8i.o
 obj-$(CONFIG_DWMAC_DWC_QOS_ETH)+= dwmac-dwc-qos-eth.o
 obj-$(CONFIG_DWMAC_GENERIC)+= dwmac-generic.o
 stmmac-platform-objs:= stmmac_platform.o
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
new file mode 100644
index 000..0951eb9
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -0,0 +1,892 @@
+/*
+ * dwmac-sun8i.c - Allwinner sun8i DWMAC specific glue layer
+ *
+ * Copyright (C) 2017 Corentin Labbe <clabbe.montj...@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "stmmac.h"
+#include "stmmac_platform.h"
+
+struct emac_variant {
+   u32 default_syscon_value;
+   int internal_phy;
+   bool support_mii;
+   bool support_rmii;
+   bool support_rgmii;
+};
+
+struct sunxi_priv_data {
+   struct clk *tx_clk;
+   struct clk *ephy_clk;
+   struct regulator *regulator;
+   struct reset_control *rst_ephy;
+   const struct emac_variant *variant;
+   bool use_internal_phy;
+   struct regmap *regmap;
+};
+
+static const struct emac_variant emac_variant_h3 = {
+   .default_syscon_value = 0x58000,
+   .internal_phy = PHY_INTERFACE_MODE_MII,
+   .support_mii = true,
+   .support_rmii = true,
+   .support_rgmii = true
+};
+
+static const struct emac_variant emac_variant_a83t = {
+   .default_syscon_value = 0,
+   .internal_phy = 0,
+   .support_mii = true,
+   .support_rgmii = true
+};
+
+static const struct emac_variant emac_variant_a64 = {
+   .default_syscon_value = 0,
+   .internal_phy = 0,
+   .support_mii = true,
+   .support_rmii = true,
+   .support_rgmii = true
+};
+
+#define EMAC_BASIC_CTL0 0x00
+#define EMAC_BASIC_CTL1 0x04
+#define EMAC_INT_STA0x08
+#define EMAC_INT_EN 0x0C
+#define EMAC_TX_CTL00x10
+#define EMAC_TX_CTL10x14
+#define EMAC_TX_FLOW_CTL0x1C
+#define EMAC_TX_DESC_LIST 0x20
+#define EMAC_RX_CTL00x24
+#define EMAC_RX_CTL10x28
+#define EMAC_RX_DESC_LIST 0x34
+#define EMAC_RX_FRM_FLT 0x38
+#define EMAC_MDIO_CMD   0x48
+#define EMAC_MDIO_DATA  0x

[PATCH 07/21] ARM: dts: sun8i-h3: add dwmac-sun8i ethernet driver

2017-02-16 Thread Corentin Labbe
From: LABBE Corentin <clabbe.montj...@gmail.com>

The dwmac-sun8i is an ethernet MAC hardware that support 10/100/1000
speed.

This patch enable the dwmac-sun8i on the Allwinner H3 SoC Device-tree.
The SoC H3 have an internal PHY, so optionals syscon and ephy are set.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/boot/dts/sun8i-h3.dtsi | 25 +
 1 file changed, 25 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index 9f91aaa..61d56d2 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -594,6 +594,31 @@
#size-cells = <0>;
};
 
+   emac: ethernet@1c3 {
+   compatible = "allwinner,sun8i-h3-emac";
+   syscon = <>;
+   reg = <0x01c3 0x104>;
+   interrupts = ;
+   interrupt-names = "macirq";
+   resets = < RST_BUS_EMAC>;
+   reset-names = "stmmaceth";
+   clocks = < CLK_BUS_EMAC>;
+   clock-names = "stmmaceth";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "disabled";
+
+   mdio: mdio {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   int_mii_phy: ethernet-phy@1 {
+   reg = <1>;
+   clocks = < CLK_BUS_EPHY>;
+   resets = < RST_BUS_EPHY>;
+   };
+   };
+   };
+
gic: interrupt-controller@01c81000 {
compatible = "arm,cortex-a7-gic", "arm,cortex-a15-gic";
reg = <0x01c81000 0x1000>,
-- 
2.10.2



[PATCH 10/21] ARM: dts: sun8i: Enable dwmac-sun8i on the Orange PI PC

2017-02-16 Thread Corentin Labbe
From: LABBE Corentin <clabbe.montj...@gmail.com>

The dwmac-sun8i hardware is present on the Orange PI PC.
It uses the internal PHY.

This patch create the needed emac node.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts 
b/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts
index d43978d..13f7267 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts
@@ -54,6 +54,7 @@
 
aliases {
serial0 = 
+   ethernet0 = 
};
 
chosen {
@@ -185,3 +186,10 @@
/* USB VBUS is always on */
status = "okay";
 };
+
+ {
+   phy-handle = <_mii_phy>;
+   phy-mode = "mii";
+   allwinner,leds-active-low;
+   status = "okay";
+};
-- 
2.10.2



[PATCH 06/21] ARM: dts: sun8i-h3: Add dt node for the syscon control module

2017-02-16 Thread Corentin Labbe
From: LABBE Corentin <clabbe.montj...@gmail.com>

This patch add the dt node for the syscon register present on the
Allwinner H3.

Only two register are present in this syscon and the only one useful is
the one dedicated to EMAC clock.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/boot/dts/sun8i-h3.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index 27780b9..9f91aaa 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -140,6 +140,12 @@
#size-cells = <1>;
ranges;
 
+   syscon: syscon@01c0 {
+   compatible = "syscon",
+"allwinner,sun8i-h3-system-controller";
+   reg = <0x01c0 0x1000>;
+   };
+
dma: dma-controller@01c02000 {
compatible = "allwinner,sun8i-h3-dma";
reg = <0x01c02000 0x1000>;
-- 
2.10.2



[PATCH 03/21] net-next: stmmac: add optional setup function

2017-02-16 Thread Corentin Labbe
Instead of ading more ifthen login for adding a new mac_device_info
setup function, it is easier to add a function pointer to the function
needed.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 ++-
 include/linux/stmmac.h| 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 942efb7..319394e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3117,7 +3117,12 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
struct mac_device_info *mac;
 
/* Identify the MAC HW device */
-   if (priv->plat->has_gmac) {
+   if (priv->plat->setup) {
+   mac = priv->plat->setup(priv->ioaddr,
+   priv->plat->multicast_filter_bins,
+   priv->plat->unicast_filter_entries,
+   >synopsys_id);
+   } else if (priv->plat->has_gmac) {
priv->dev->priv_flags |= IFF_UNICAST_FLT;
mac = dwmac1000_setup(priv->ioaddr,
  priv->plat->multicast_filter_bins,
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index fc273e9..95ee4c4 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -136,6 +136,9 @@ struct plat_stmmacenet_data {
void (*fix_mac_speed)(void *priv, unsigned int speed);
int (*init)(struct platform_device *pdev, void *priv);
void (*exit)(struct platform_device *pdev, void *priv);
+   struct mac_device_info *(*setup)(void __iomem *ioaddr, int mcbins,
+int perfect_uc_entries,
+int *synopsys_id);
void *bsp_priv;
struct clk *stmmac_clk;
struct clk *pclk;
-- 
2.10.2



[PATCH 09/21] ARM: dts: sun8i: Enable dwmac-sun8i on the Banana Pi M2+

2017-02-16 Thread Corentin Labbe
From: LABBE Corentin <clabbe.montj...@gmail.com>

The dwmac-sun8i hardware is present on the Banana Pi M2+
It uses an external PHY rtl8211e via RGMII.

This patch create the needed regulator, emac and phy nodes.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/boot/dts/sun8i-h3-bananapi-m2-plus.dts | 38 +
 1 file changed, 38 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3-bananapi-m2-plus.dts 
b/arch/arm/boot/dts/sun8i-h3-bananapi-m2-plus.dts
index c0c49dd..a4f7b99 100644
--- a/arch/arm/boot/dts/sun8i-h3-bananapi-m2-plus.dts
+++ b/arch/arm/boot/dts/sun8i-h3-bananapi-m2-plus.dts
@@ -91,6 +91,18 @@
pinctrl-0 = <_en_bpi_m2p>;
reset-gpios = <_pio 0 7 GPIO_ACTIVE_LOW>; /* PL7 */
};
+
+   reg_gmac_3v3: gmac-3v3 {
+ compatible = "regulator-fixed";
+ pinctrl-names = "default";
+ pinctrl-0 = <_power_pin_orangepi>;
+ regulator-name = "gmac-3v3";
+ regulator-min-microvolt = <330>;
+ regulator-max-microvolt = <330>;
+ startup-delay-us = <10>;
+ enable-active-high;
+ gpio = < 3 6 GPIO_ACTIVE_HIGH>;
+ };
 };
 
  {
@@ -187,3 +199,29 @@
/* USB VBUS is on as long as VCC-IO is on */
status = "okay";
 };
+
+ {
+   gmac_power_pin_orangepi: gmac_power_pin@0 {
+allwinner,pins = "PD6";
+allwinner,function = "gpio_out";
+allwinner,drive = ;
+allwinner,pull = ;
+};
+};
+
+ {
+   ext_rgmii_phy: ethernet-phy@1 {
+   reg = <0>;
+   };
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_rgmii_pins>;
+   phy-supply = <_gmac_3v3>;
+   phy-handle = <_rgmii_phy>;
+   phy-mode = "rgmii";
+
+   allwinner,leds-active-low;
+   status = "okay";
+};
-- 
2.10.2



[PATCH 11/21] ARM: dts: sun8i: Enable dwmac-sun8i on the Orange Pi 2

2017-02-16 Thread Corentin Labbe
The dwmac-sun8i hardware is present on the Orange PI 2.
It uses the internal PHY.

This patch create the needed emac node.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/boot/dts/sun8i-h3-orangepi-2.dts | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-2.dts 
b/arch/arm/boot/dts/sun8i-h3-orangepi-2.dts
index 047e9e1..4b5077c 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-2.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-2.dts
@@ -56,6 +56,7 @@
serial0 = 
/* ethernet0 is the H3 emac, defined in sun8i-h3.dtsi */
ethernet1 = 
+   ethernet0 = 
};
 
chosen {
@@ -204,3 +205,10 @@
usb1_vbus-supply = <_usb1_vbus>;
status = "okay";
 };
+
+ {
+   phy-handle = <_mii_phy>;
+   phy-mode = "mii";
+   allwinner,leds-active-low;
+   status = "okay";
+};
-- 
2.10.2



Re: [linux-sunxi] [PATCH 03/21] net-next: stmmac: add optional setup function

2017-02-17 Thread Corentin Labbe
On Thu, Feb 16, 2017 at 09:38:33PM +0100, Peter Korsgaard wrote:
> >>>>> "Corentin" == Corentin Labbe <clabbe.montj...@gmail.com> writes:
> 
>  > Instead of ading more ifthen login for adding a new mac_device_info
> 
> s/login/logic/
> 
> -- 
> Bye, Peter Korsgaard

Thanks, will fix it.
Regards
Corentin Labbe


Re: [PATCH 20/21] ARM: sunxi: Enable dwmac-sun8i driver on sunxi_defconfig

2017-02-17 Thread Corentin Labbe
On Thu, Feb 16, 2017 at 08:08:27PM +0100, Maxime Ripard wrote:
> Hi,
> 
> On Thu, Feb 16, 2017 at 01:48:58PM +0100, Corentin Labbe wrote:
> > From: LABBE Corentin <clabbe.montj...@gmail.com>
> > 
> > Enable the dwmac-sun8i driver in the sunxi default configuration
> > 
> > Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
> > ---
> >  arch/arm/configs/sunxi_defconfig | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/arch/arm/configs/sunxi_defconfig 
> > b/arch/arm/configs/sunxi_defconfig
> > index da92c25..33bde86 100644
> > --- a/arch/arm/configs/sunxi_defconfig
> > +++ b/arch/arm/configs/sunxi_defconfig
> > @@ -40,6 +40,7 @@ CONFIG_ATA=y
> >  CONFIG_AHCI_SUNXI=y
> >  CONFIG_NETDEVICES=y
> >  CONFIG_SUN4I_EMAC=y
> > +CONFIG_DWMAC_SUN8I=m
> 
> I think I'd prefer to have it compiled statically, just like the other
> net drivers, and drivers in general.
> 
> Thanks!
> Maxime
> 

In previous sun8i-emac, someone request that CONFIG must be set as module 
because kernel went too big.
But I do not care to set it statically.

Regards
Corentin Labbe


Re: [PATCH 08/21] ARM: dts: sun8i-h3: add dwmac-sun8i rgmii pins

2017-02-17 Thread Corentin Labbe
On Thu, Feb 16, 2017 at 08:06:32PM +0100, Maxime Ripard wrote:
> On Thu, Feb 16, 2017 at 01:48:46PM +0100, Corentin Labbe wrote:
> > This patch add pinctrl node for dwmac-sun8i on H3.
> > 
> > Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
> > ---
> >  arch/arm/boot/dts/sun8i-h3.dtsi | 11 +++
> >  1 file changed, 11 insertions(+)
> > 
> > diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi 
> > b/arch/arm/boot/dts/sun8i-h3.dtsi
> > index 61d56d2..59ed40e 100644
> > --- a/arch/arm/boot/dts/sun8i-h3.dtsi
> > +++ b/arch/arm/boot/dts/sun8i-h3.dtsi
> > @@ -349,6 +349,17 @@
> > function = "i2c2";
> > };
> >  
> > +   emac_rgmii_pins: emac0@0 {
> > +   allwinner,pins = "PD0", "PD1", "PD2", "PD3",
> > +   "PD4", "PD5", "PD7",
> > +   "PD8", "PD9", "PD10",
> > +   "PD12", "PD13", "PD15",
> > +   "PD16", "PD17";
> > +   allwinner,function = "emac";
> 
> Please use the generic pin config properties (ie. pins and functions).
> 
> > +   allwinner,drive = ;
> 
> Why do you need to use 40mA?
> 
> > +   allwinner,pull = ;
> 
> This is the default now.
> 

Will fix that in all DT

Thanks
Corentin Labbe


Re: [PATCH 04/21] ARM: sun8i: dt: Add DT bindings documentation for Allwinner dwmac-sun8i

2017-02-17 Thread Corentin Labbe
On Thu, Feb 16, 2017 at 07:48:18PM +0100, Maxime Ripard wrote:
> Hi,
> 
> On Thu, Feb 16, 2017 at 01:48:42PM +0100, Corentin Labbe wrote:
> > This patch adds documentation for Device-Tree bindings for the
> > Allwinner dwmac-sun8i driver.
> > 
> > Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
> > ---
> >  .../devicetree/bindings/net/dwmac-sun8i.txt| 86 
> > ++
> >  1 file changed, 86 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/net/dwmac-sun8i.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/net/dwmac-sun8i.txt 
> > b/Documentation/devicetree/bindings/net/dwmac-sun8i.txt
> > new file mode 100644
> > index 000..ac806c6
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/net/dwmac-sun8i.txt
> > @@ -0,0 +1,86 @@
> > +* Allwinner sun8i GMAC ethernet controller
> > +
> > +This device is a platform glue layer for stmmac.
> > +Please see stmmac.txt for the other unchanged properties.
> > +
> > +Required properties:
> > +- compatible: should be one of the following string:
> > +   "allwinner,sun8i-a83t-emac"
> > +   "allwinner,sun8i-h3-emac"
> > +   "allwinner,sun50i-a64-emac"
> > +- reg: address and length of the register for the device.
> > +- interrupts: interrupt for the device
> > +- interrupt-names: should be "macirq"
> > +- clocks: A phandle to the reference clock for this device
> > +- clock-names: should be "stmmaceth"
> > +- resets: A phandle to the reset control for this device
> > +- reset-names: should be "stmmaceth"
> > +- phy-mode: See ethernet.txt
> > +- phy-handle: See ethernet.txt
> > +- #address-cells: shall be 1
> > +- #size-cells: shall be 0
> > +- syscon: A phandle to the syscon of the SoC with one of the following
> > + compatible string:
> > +  - allwinner,sun8i-h3-system-controller
> > +  - allwinner,sun8i-a64-system-controller
> > +  - allwinner,sun8i-a83t-system-controller
> > +
> > +Optional properties:
> > +- allwinner,tx-delay: TX clock delay chain value. Range value is 0-0x07. 
> > Default is 0)
> > +- allwinner,rx-delay: RX clock delay chain value. Range value is 0-0x1F. 
> > Default is 0)
> > +Both delay properties does not have units, there are arbitrary value.
> > +The TX/RX clock delay chain settings are board specific and could be found
> > +in vendor FEX files.
> > +
> > +Optional properties for "allwinner,sun8i-h3-emac":
> > +- allwinner,leds-active-low: EPHY LEDs are active low
> > +
> > +Required child node of emac:
> > +- mdio bus node: should be named mdio
> > +
> > +Required properties of the mdio node:
> > +- #address-cells: shall be 1
> > +- #size-cells: shall be 0
> > +
> > +The device node referenced by "phy" or "phy-handle" should be a child node
> > +of the mdio node. See phy.txt for the generic PHY bindings.
> > +
> > +Required properties of the phy node with "allwinner,sun8i-h3-emac":
> > +- clocks: an extra phandle to the reference clock for the EPHY
> > +- resets: an extra phandle to the reset control for the EPHY
> > +
> > +Required properties for the system controller:
> > +- reg: address and length of the register for the device.
> > +- compatible: should be "syscon" and one of the following string:
> > +   "allwinner,sun8i-h3-system-controller"
> > +   "allwinner,sun8i-a64-system-controller"
> > +   "allwinner,sun8i-a83t-system-controller"
> 
> This should be in a separate binding document.
> 
> What does it describe / represent?
> 
> Thanks,
> Maxime
> 

I agree, I will split it in two one for syscon, one for emac

Thanks
Corentin Labbe


Re: [PATCH 05/21] net-next: stmmac: Add dwmac-sun8i

2017-02-17 Thread Corentin Labbe
 MDIO 
> > addr\n");
> > +   return ret;
> > +   }
> > +   /* of_mdio_parse_addr returns a valid (0 ~ 31) PHY
> > +* address. No need to mask it again.
> > +*/
> > +   reg |= ret << H3_EPHY_ADDR_SHIFT;
> > +   }
> > +   }
> > +
> > +   if (!of_property_read_u32(node, "allwinner,tx-delay", )) {
> 
> How do you compute it? Can't this be done through auto-training?
> 

The value is the same as used in vendor BSP kernel.
I do not understand what you mean by auto-training.

> > +   dev_info(priv->device, "set tx-delay to %x\n", val);
> 
> change the logging level here too.
> 

I agree

> > +   if (val <= SYSCON_ETXDC_MASK) {
> > +   reg &= ~(SYSCON_ETXDC_MASK << SYSCON_ETXDC_SHIFT);
> > +   reg |= (val << SYSCON_ETXDC_SHIFT);
> > +   } else {
> > +   dev_warn(priv->device, "Invalid TX clock delay: %d\n",
> > +val);
> 
> If it's invalid, why don't you treat it as an error and return?
> 

Ok

[...]
> > +static struct mac_device_info *sun8i_dwmac_setup(void __iomem *ioaddr,
> > +int mcbins,
> > +int perfect_uc_entries,
> > +int *synopsys_id)
> > +{
> > +   struct mac_device_info *mac;
> > +
> > +   mac = kzalloc(sizeof(const struct mac_device_info), GFP_KERNEL);
> > +   if (!mac)
> > +   return NULL;
> 
> Do you ever free that memory?
> 

Good catch, I believed that the "stmmac framework" would free it.
I will send a fix for this memory leak.

[...]
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c 
> > b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
> > index 5ff6bc4..11db658 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
> > @@ -450,6 +450,9 @@ static void stmmac_ethtool_gregs(struct net_device *dev,
> > for (i = 0; i < 22; i++)
> > reg_space[i + 55] =
> > readl(priv->ioaddr + (DMA_BUS_MODE + (i * 4)));
> > +   } else if (priv->plat->has_sun8i) {
> 
> Surely we don't want to add a new flag to the common structure for
> every new platform supported.
> 
> Can't you base that on the compatible instead?

This part will be fixed with the debugfs speaked early in the mail.

But yes I have tried to avoid use of has_sun8i at maximum.

> 
> Thanks a lot for your work,
> Maxime
> 

Thanks for the review

Corentin Labbe


[PATCH v3 0/9] net-next: ethernet: add sun8i-emac driver

2016-09-09 Thread Corentin Labbe
Hello

This patch series add the driver for sun8i-emac which handle the Ethernet MAC
present on Allwinner H3/A83T/A64 SoCs.

It supports 10/100/1000 Mbit/s speed with half/full duplex.
It can use an internal PHY (MII 10/100) or an external PHY
via RGMII/RMII.

This patch series enable the driver only for the H3 SoC since A83T and A64
doesn't have the necessary clocks present in mainline.

This patch series enable the driver only for OrangePiPC and OrangePIOne boards
since other board with H3 use external PHY which need optional regulators
that will be supported later.

The driver have been tested on the following boards:
- H3 Orange PI PC, Orange PI Plus, BananaPI-M2+
- A64 Pine64
- A83T BananaPI-M3

I would like to thanks Chen-Yu Tsai for his help on developing this driver.

Regards

Changes since v2
- Added patch to support Orange PI One
- Added a patch to enable SUN8I_EMAC in sunxi_defconfig
- Added a patch to enable pm_runtime
- The Emac clock is now used standard syscon/regmap
- Added netdev_sent_queue/netdev_completed_queue
- Added lots of documentation on working (locks, memory barrier, etc...)
- Cleaned DT bindings documentation
- Added ethernet0 aliases as suggested by Hans de Goede
- Change prefix of all DEFINE to EMAC_
- The driver is now endian safe
- Reworked the internal PHY mechanism
- Removed dma_set_mask_and_coherent(32) since it is the default for 
of_platform_driver

Changes since v1
- Implement NAPI
- Sorted and reworded all define
- Reworked ethtools stats strings
- Removed all unneeded __packked and __aligned
- Added tuning of RX/TX ring size via ethtool
- Corrected use of sk/skb naming
- Added some wmb when needed
- Moved irq claim/free to emac_open/close
- Lots of code refactoring

Corentin Labbe (8):
  ethernet: sun8i-emac: add pm_runtime support
  ethernet: add sun8i-emac driver
  MAINTAINERS: Add myself as maintainer of sun8i-emac
  ARM: sun8i: dt: Add DT bindings documentation for Allwinner sun8i-emac
  ARM: dts: sun8i-h3: Add dt node for the syscon control module
  ARM: dts: sun8i-h3: add sun8i-emac ethernet driver
  ARM: dts: sun8i: Enable sun8i-emac on the Orange PI PC
  ARM: sunxi: Enable sun8i-emac driver on sunxi_defconfig

Hans de Goede (1):
  ARM: dts: sun8i: Enable sun8i-emac on the Orange PI One

 .../bindings/net/allwinner,sun8i-emac.txt  |   64 +
 MAINTAINERS|6 +
 arch/arm/boot/dts/sun8i-h3-orangepi-one.dts|   10 +
 arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts |   10 +
 arch/arm/boot/dts/sun8i-h3.dtsi|   24 +
 arch/arm/configs/sunxi_defconfig   |1 +
 drivers/net/ethernet/allwinner/Kconfig |   13 +
 drivers/net/ethernet/allwinner/Makefile|1 +
 drivers/net/ethernet/allwinner/sun8i-emac.c| 2313 
 9 files changed, 2442 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt
 create mode 100644 drivers/net/ethernet/allwinner/sun8i-emac.c

-- 
2.7.3



[PATCH v3 3/9] ARM: sun8i: dt: Add DT bindings documentation for Allwinner sun8i-emac

2016-09-09 Thread Corentin Labbe
This patch adds documentation for Device-Tree bindings for the
Allwinner sun8i-emac driver.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 .../bindings/net/allwinner,sun8i-emac.txt  | 64 ++
 1 file changed, 64 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt

diff --git a/Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt 
b/Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt
new file mode 100644
index 000..4968ee3
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt
@@ -0,0 +1,64 @@
+* Allwinner sun8i EMAC ethernet controller
+
+Required properties:
+- compatible: should be one of the following string:
+   "allwinner,sun8i-a83t-emac"
+   "allwinner,sun8i-h3-emac"
+   "allwinner,sun50i-a64-emac"
+- reg: address and length of the register for the device.
+- reg-names: should be "emac"
+- syscon: A phandle to the syscon of the SoC
+- interrupts: interrupt for the device
+- clocks: A phandle to the reference clock for this device
+- clock-names: should be "ahb"
+- resets: A phandle to the reset control for this device
+- reset-names: should be "ahb"
+- phy-mode: See ethernet.txt
+- phy or phy-handle: See ethernet.txt
+- #address-cells: shall be 1
+- #size-cells: shall be 0
+
+"allwinner,sun8i-h3-emac" also requires:
+- clocks: an extra phandle to the reference clock for the EPHY
+- clock-names: an extra "ephy" entry matching the clocks property
+- resets: an extra phandle to the reset control for the EPHY
+- resets-names: an extra "ephy" entry matching the resets property
+
+See ethernet.txt in the same directory for generic bindings for ethernet
+controllers.
+
+The device node referenced by "phy" or "phy-handle" should be a child node
+of this node. See phy.txt for the generic PHY bindings.
+
+Optional properties:
+- allwinner,tx-delay: TX clock delay chain value. Range value is 0-0x07. 
Default is 0)
+- allwinner,rx-delay: RX clock delay chain value. Range value is 0-0x1F. 
Default is 0)
+
+The TX/RX clock delay chain settings are board specific.
+
+Optional properties for "allwinner,sun8i-h3-emac":
+- allwinner,leds-active-low: EPHY LEDs are active low
+
+Example:
+
+emac: ethernet@01c0b000 {
+   compatible = "allwinner,sun8i-h3-emac";
+   syscon = <>;
+   reg = <0x01c0b000 0x104>;
+   reg-names = "emac";
+   interrupts = ;
+   resets = < RST_BUS_EMAC>, << RST_BUS_EPHY>;
+   reset-names = "ahb", "ephy";
+   clocks = < CLK_BUS_EMAC>, < CLK_BUS_EPHY>;
+   clock-names = "ahb", "ephy";
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   phy = <>;
+   phy-mode = "mii";
+   allwinner,leds-active-low;
+
+   phy1: ethernet-phy@1 {
+   reg = <1>;
+   };
+};
-- 
2.7.3



[PATCH v3 5/9] ARM: dts: sun8i-h3: add sun8i-emac ethernet driver

2016-09-09 Thread Corentin Labbe
The sun8i-emac is an ethernet MAC hardware that support 10/100/1000
speed.

This patch enable the sun8i-emac on the Allwinner H3 SoC Device-tree.
The SoC H3 have an internal PHY, so optionals syscon and ephy are set.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/boot/dts/sun8i-h3.dtsi | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index a39da6f..a3ac476 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -50,6 +50,10 @@
 / {
interrupt-parent = <>;
 
+   aliases {
+   ethernet0 = 
+   };
+
cpus {
#address-cells = <1>;
#size-cells = <0>;
@@ -446,6 +450,21 @@
status = "disabled";
};
 
+   emac: ethernet@1c3 {
+   compatible = "allwinner,sun8i-h3-emac";
+   syscon = <>;
+   reg = <0x01c3 0x104>;
+   reg-names = "emac";
+   interrupts = ;
+   resets = < RST_BUS_EMAC>, < RST_BUS_EPHY>;
+   reset-names = "ahb", "ephy";
+   clocks = < CLK_BUS_EMAC>, < CLK_BUS_EPHY>;
+   clock-names = "ahb", "ephy";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "disabled";
+   };
+
gic: interrupt-controller@01c81000 {
compatible = "arm,cortex-a7-gic", "arm,cortex-a15-gic";
reg = <0x01c81000 0x1000>,
-- 
2.7.3



[PATCH v3 6/9] ARM: dts: sun8i: Enable sun8i-emac on the Orange PI PC

2016-09-09 Thread Corentin Labbe
The sun8i-emac hardware is present on the Orange PI PC.
It uses the internal PHY.

This patch create the needed emac and phy nodes.

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts 
b/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts
index daf50b9a6..24f8e97 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts
@@ -165,3 +165,13 @@
/* USB VBUS is always on */
status = "okay";
 };
+
+ {
+   phy = <>;
+   phy-mode = "mii";
+   allwinner,leds-active-low;
+   status = "okay";
+   phy1: ethernet-phy@1 {
+   reg = <1>;
+   };
+};
-- 
2.7.3



[RFC PATCH 9/9] ethernet: sun8i-emac: add pm_runtime support

2016-09-09 Thread Corentin Labbe
This patch add pm_runtime support to sun8i-emac.
For the moment, only basic support is added, (the device is marked as
used when net/open)

Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
---
 drivers/net/ethernet/allwinner/sun8i-emac.c | 62 -
 1 file changed, 60 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/allwinner/sun8i-emac.c 
b/drivers/net/ethernet/allwinner/sun8i-emac.c
index 1c4bc80..cce886e 100644
--- a/drivers/net/ethernet/allwinner/sun8i-emac.c
+++ b/drivers/net/ethernet/allwinner/sun8i-emac.c
@@ -9,7 +9,6 @@
  * - MAC filtering
  * - Jumbo frame
  * - features rx-all (NETIF_F_RXALL_BIT)
- * - PM runtime
  */
 #include 
 #include 
@@ -27,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1301,11 +1301,18 @@ static int sun8i_emac_open(struct net_device *ndev)
int err;
u32 v;
 
+   err = pm_runtime_get_sync(priv->dev);
+   if (err) {
+   pm_runtime_put_noidle(priv->dev);
+   dev_err(priv->dev, "pm_runtime error: %d\n", err);
+   return err;
+   }
+
err = request_irq(priv->irq, sun8i_emac_dma_interrupt, 0,
  dev_name(priv->dev), ndev);
if (err) {
dev_err(priv->dev, "Cannot request IRQ: %d\n", err);
-   return err;
+   goto err_runtime;
}
 
/* Set interface mode (and configure internal PHY on H3) */
@@ -1395,6 +1402,8 @@ err_syscon:
sun8i_emac_unset_syscon(ndev);
 err_irq:
free_irq(priv->irq, ndev);
+err_runtime:
+   pm_runtime_put(priv->dev);
return err;
 }
 
@@ -1483,6 +1492,8 @@ static int sun8i_emac_stop(struct net_device *ndev)
dma_free_coherent(priv->dev, priv->nbdesc_tx * sizeof(struct dma_desc),
  priv->dd_tx, priv->dd_tx_phy);
 
+   pm_runtime_put(priv->dev);
+
return 0;
 }
 
@@ -2210,6 +2221,8 @@ static int sun8i_emac_probe(struct platform_device *pdev)
goto probe_err;
}
 
+   pm_runtime_enable(priv->dev);
+
return 0;
 
 probe_err:
@@ -2221,6 +2234,8 @@ static int sun8i_emac_remove(struct platform_device *pdev)
 {
struct net_device *ndev = platform_get_drvdata(pdev);
 
+   pm_runtime_disable(>dev);
+
unregister_netdev(ndev);
platform_set_drvdata(pdev, NULL);
free_netdev(ndev);
@@ -2228,6 +2243,47 @@ static int sun8i_emac_remove(struct platform_device 
*pdev)
return 0;
 }
 
+static int __maybe_unused sun8i_emac_suspend(struct platform_device *pdev, 
pm_message_t state)
+{
+   struct net_device *ndev = platform_get_drvdata(pdev);
+   struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+   napi_disable(>napi);
+
+   if (netif_running(ndev))
+   netif_device_detach(ndev);
+
+   sun8i_emac_stop_tx(ndev);
+   sun8i_emac_stop_rx(ndev);
+
+   sun8i_emac_rx_clean(ndev);
+   sun8i_emac_tx_clean(ndev);
+
+   phy_stop(ndev->phydev);
+
+   return 0;
+}
+
+static int __maybe_unused sun8i_emac_resume(struct platform_device *pdev)
+{
+   struct net_device *ndev = platform_get_drvdata(pdev);
+   struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+   phy_start(ndev->phydev);
+
+   sun8i_emac_start_tx(ndev);
+   sun8i_emac_start_rx(ndev);
+
+   if (netif_running(ndev))
+   netif_device_attach(ndev);
+
+   netif_start_queue(ndev);
+
+   napi_enable(>napi);
+
+   return 0;
+}
+
 static const struct of_device_id sun8i_emac_of_match_table[] = {
{ .compatible = "allwinner,sun8i-a83t-emac",
  .data = _variant_a83t },
@@ -2246,6 +2302,8 @@ static struct platform_driver sun8i_emac_driver = {
.name   = "sun8i-emac",
.of_match_table = sun8i_emac_of_match_table,
},
+   .suspend= sun8i_emac_suspend,
+   .resume = sun8i_emac_resume,
 };
 
 module_platform_driver(sun8i_emac_driver);
-- 
2.7.3



  1   2   3   4   5   >