RE: linux-next: Tree for Oct 15 (drivers/net/pcs/pcs-xpcs.o)

2020-10-15 Thread Jose Abreu
From: Randy Dunlap 
Date: Oct/15/2020, 15:45:57 (UTC+00:00)

> On 10/15/20 12:28 AM, Stephen Rothwell wrote:
> > Hi all,
> > 
> > Since the merge window is open, please do not add any v5.11 material to
> > your linux-next included branches until after v5.10-rc1 has been released.
> > 
> > News: there will be no linux-next releases next Monday or Tuesday.
> > 
> > Changes since 20201013:
> > 
> 
> on i386:
> 
> ld: drivers/net/pcs/pcs-xpcs.o: in function `xpcs_read':
> pcs-xpcs.c:(.text+0x29): undefined reference to `mdiobus_read'
> ld: drivers/net/pcs/pcs-xpcs.o: in function `xpcs_soft_reset.constprop.7':
> pcs-xpcs.c:(.text+0x80): undefined reference to `mdiobus_write'
> ld: drivers/net/pcs/pcs-xpcs.o: in function `xpcs_config_aneg':
> pcs-xpcs.c:(.text+0x318): undefined reference to `mdiobus_write'
> ld: pcs-xpcs.c:(.text+0x38e): undefined reference to `mdiobus_write'
> ld: pcs-xpcs.c:(.text+0x3eb): undefined reference to `mdiobus_write'
> ld: pcs-xpcs.c:(.text+0x437): undefined reference to `mdiobus_write'
> ld: drivers/net/pcs/pcs-xpcs.o:pcs-xpcs.c:(.text+0xb1e): more undefined 
> references to `mdiobus_write' follow
> 
> 
> Full randconfig file is attached.
> 
> -- 
> ~Randy
> Reported-by: Randy Dunlap 

++ Andrew Lunn

---
Thanks,
Jose Miguel Abreu


RE: [EXT] [PATCH v2 1/5] scsi: ufs: Allow UFS 3.0 as a valid version

2020-06-12 Thread Jose Abreu
From: Alim Akhtar 
Date: Jun/10/2020, 04:39:48 (UTC+00:00)

> Are you still on this?

Yes, apologies but I was caught on some other things. I'll try to 
re-submit once possible.

---
Thanks,
Jose Miguel Abreu


RE: [PATCH net-next 7/8] net: phy: Add Synopsys DesignWare XPCS MDIO module

2020-06-09 Thread Jose Abreu
From: Russell King - ARM Linux admin 
Date: Jun/05/2020, 18:10:34 (UTC+00:00)

> This is incorrect - you should not mask the link partner's advertisement
> with our advertisement like this; consider the table in 802.3 for
> resolving the pause modes, where simply doing a bitwise-and operation
> between the two advertisements would severely restrict the resulting
> resolution to either symmetric pause or nothing at all.
> 
> You want to do this when you resolve the speed, but only _temporarily_
> in order to resolve the speed - you do not want to write back the
> result to state->lp_advertising.

Thanks for bringing this up. Indeed I believe I did this in order to 
resolve the speed, as you said.
 
> You may wish to fix that.

Added to the list of my pending fixes. Thanks!

---
Thanks,
Jose Miguel Abreu


RE: [PATCH] net: stmmac: Fix RX Coalesce IOC always true issue

2020-06-09 Thread Jose Abreu
From: Biao Huang 
Date: Jun/09/2020, 10:41:33 (UTC+00:00)

> - rx_q->rx_count_frames += priv->rx_coal_frames;
> - if (rx_q->rx_count_frames > priv->rx_coal_frames)
> + if (rx_q->rx_count_frames >= priv->rx_coal_frames)

This is no right. If you want to RX IC bit to not always be set you need 
to change coalesce parameters using ethtool.

---
Thanks,
Jose Miguel Abreu


RE: [EXT] [PATCH v2 1/5] scsi: ufs: Allow UFS 3.0 as a valid version

2020-04-30 Thread Jose Abreu
From: Bean Huo (beanhuo) 
Date: Apr/29/2020, 13:59:08 (UTC+00:00)

> > > > @@ -8441,7 +8441,8 @@ int ufshcd_init(struct ufs_hba *hba, void
> > > > __iomem *mmio_base, unsigned int irq)
> > > > if ((hba->ufs_version != UFSHCI_VERSION_10) &&
> > > > (hba->ufs_version != UFSHCI_VERSION_11) &&
> > > > (hba->ufs_version != UFSHCI_VERSION_20) &&
> > > > -   (hba->ufs_version != UFSHCI_VERSION_21))
> > > > +   (hba->ufs_version != UFSHCI_VERSION_21) &&
> > > > +   (hba->ufs_version != UFSHCI_VERSION_30))
> > >
> > > I don't think these checkups of UFSHCI version is necessary,  does the 
> > > UFSHCI
> > have other version number except these?
> > > Is there somebody still v1.0 and v1.1?
> > 
> > Probably. I think we can leave them or change the dev_err to a dev_warn.
> > This way we have logs in case someone is using a non-supported version.
> > 
> > What do you think ?
> > 
> Hi, Jose
> Seems after your patch, all of current released UFS control versions will be 
> supported except the
> version suffix is non-zero. Right?

I think we cover all versions with this patch.

---
Thanks,
Jose Miguel Abreu


RE: [EXT] [PATCH v2 1/5] scsi: ufs: Allow UFS 3.0 as a valid version

2020-04-29 Thread Jose Abreu
From: Bean Huo (beanhuo) 
Date: Apr/24/2020, 16:57:07 (UTC+00:00)

> Hi, Jose
> 
> > @@ -8441,7 +8441,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem
> > *mmio_base, unsigned int irq)
> > if ((hba->ufs_version != UFSHCI_VERSION_10) &&
> > (hba->ufs_version != UFSHCI_VERSION_11) &&
> > (hba->ufs_version != UFSHCI_VERSION_20) &&
> > -   (hba->ufs_version != UFSHCI_VERSION_21))
> > +   (hba->ufs_version != UFSHCI_VERSION_21) &&
> > +   (hba->ufs_version != UFSHCI_VERSION_30))
> 
> I don't think these checkups of UFSHCI version is necessary,  does the UFSHCI 
> have other version number except these?
> Is there somebody still v1.0 and v1.1?

Probably. I think we can leave them or change the dev_err to a dev_warn. 
This way we have logs in case someone is using a non-supported version.

What do you think ?

---
Thanks,
Jose Miguel Abreu


RE: [PATCH] ARC: guard dsp early init against non ARCv2

2020-04-29 Thread Jose Abreu
From: Eugeniy Paltsev 
Date: Apr/28/2020, 19:50:24 (UTC+00:00)

> As of today we guard early DSP init code with
> ARC_AUX_DSP_BUILD (0x7A) BCR check to verify that we have
> CPU with DSP configured. However that's not enough as in
> ARCv1 CPU the same BCR (0x7A) is used for checking MUL/MAC
> instructions presence.
> 
> So, let's guard DSP early init against non ARCv2.
> 
> Signed-off-by: Eugeniy Paltsev 

Reported-by: Angelo Ribeiro 


---
Thanks,
Jose Miguel Abreu


RE: [PATCH net-next 2/2] net: phy: Add ability to debug RGMII connections

2019-10-16 Thread Jose Abreu
From: Florian Fainelli 
Date: Oct/15/2019, 23:49:53 (UTC+00:00)

> The function phy_rgmii_debug_probe() could also be used by an Ethernet
> controller during its selftests routines instead of open-coding that
> part.

I can add it to stmmac selftests then :)

> +int phy_rgmii_debug_probe(struct phy_device *phydev)
> +{
> + struct net_device *ndev = phydev->attached_dev;
> + unsigned char operstate = ndev->operstate;
> + phy_interface_t rgmii_modes[4] = {

This can be static.

> + PHY_INTERFACE_MODE_RGMII,
> + PHY_INTERFACE_MODE_RGMII_ID,
> + PHY_INTERFACE_MODE_RGMII_RXID,
> + PHY_INTERFACE_MODE_RGMII_TXID
> + };
> + struct phy_rgmii_debug_priv *priv;
> + unsigned int i, count;
> + int ret;
> +
> + ret = phy_rgmii_can_debug(phydev);
> + if (ret <= 0)
> + return ret;
> +
> + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + if (phy_rgmii_probes_type.af_packet_priv)
> + return -EBUSY;

You are leaking "priv" here.

> +
> + phy_rgmii_probes_type.af_packet_priv = priv;
> + priv->phydev = phydev;
> + INIT_WORK(>work, phy_rgmii_probe_xmit_work);
> + init_completion(>compl);
> +
> + /* We are now testing this network device */
> + ndev->operstate = IF_OPER_TESTING;
> +
> + dev_add_pack(_rgmii_probes_type);
> +
> + /* Determine where to start */
> + for (i = 0; i < ARRAY_SIZE(rgmii_modes); i++) {
> + if (phydev->interface == rgmii_modes[i])
> + break;
> + }
> +
> + /* Now probe all modes */
> + for (count = 0; count < ARRAY_SIZE(rgmii_modes); count++) {
> + ret = phy_rgmii_probe_interface(priv, rgmii_modes[i]);
> + if (ret == 0) {
> + netdev_info(ndev, "Determined \"%s\" to be correct\n",
> + phy_modes(rgmii_modes[i]));
> + break;
> + }
> + i = (i + 1) % ARRAY_SIZE(rgmii_modes);
> + }
> +
> + dev_remove_pack(_rgmii_probes_type);
> + kfree(priv);
> + phy_rgmii_probes_type.af_packet_priv = NULL;

I think you should set af_packet_priv to NULL before freeing "priv" 
because of the "if ([...].af_packet_priv)" test, otherwise you can get 
use-after-free.

---
Thanks,
Jose Miguel Abreu


[RFT] stmmac Selftests

2019-10-07 Thread Jose Abreu
Hi stmmac users,

Since 091810dbded9 ("net: stmmac: Introduce selftests support"), the 
stmmac driver supports ethtool selftests that can help diagnose HW 
mis-configurations and SW programming issues.

I would like to request all stmmac users to try running these tests and 
send the output to this thread so that we can try fix more issues and 
make it more stable.

Appreciate all the info you can gather :)

---
Thanks,
Jose Miguel Abreu


RE: [PATCH net-next] net: stmmac: Fix sparse warning

2019-10-07 Thread Jose Abreu
From: David Miller 
Date: Oct/07/2019, 15:14:26 (UTC+00:00)

> From: Jose Abreu 
> Date: Mon,  7 Oct 2019 15:16:08 +0200
> 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
> > b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > index 8b76745a7ec4..40b0756f3a14 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > @@ -4207,6 +4207,7 @@ static u32 stmmac_vid_crc32_le(__le16 vid_le)
> >  static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double)
> >  {
> > u32 crc, hash = 0;
> > +   __le16 pmatch = 0;
> > int count = 0;
> > u16 vid = 0;
> >  
> > @@ -4221,11 +4222,11 @@ static int stmmac_vlan_update(struct stmmac_priv 
> > *priv, bool is_double)
> > if (count > 2) /* VID = 0 always passes filter */
> > return -EOPNOTSUPP;
> >  
> > -   vid = cpu_to_le16(vid);
> > +   pmatch = cpu_to_le16(vid);
> > hash = 0;
> > }
> >  
> > -   return stmmac_update_vlan_hash(priv, priv->hw, hash, vid, is_double);
> > +   return stmmac_update_vlan_hash(priv, priv->hw, hash, pmatch, is_double);
> >  }
> 
> I dunno about this.
> 
> The original code would use the last "vid" iterated over in the
> for_each_set_bit() loop if the priv->dma_cap.vlhash test does not
> pass.
> 
> Now, it will use zero in that case.
> 
> This does not look like an equivalent transformation.

It is intended behavior. HW specific callbacks: 
dwmac4_update_vlan_hash() / dwxgmac2_update_vlan_hash(), will either use 
Hash method or Perfect method so if priv->dma_cap.vlhash is not 
available then pmatch will be last vid. Otherwise, it will be zero and 
hash will be populated.

---
Thanks,
Jose Miguel Abreu


[PATCH net-next] net: stmmac: Fix sparse warning

2019-10-07 Thread Jose Abreu
The VID is converted to le16 so the variable must be __le16 type.

Reported-by: kbuild test robot 
Fixes: c7ab0b8088d7 ("net: stmmac: Fallback to VLAN Perfect filtering if HASH 
is not available")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c   | 2 +-
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 2 +-
 drivers/net/ethernet/stmicro/stmmac/hwif.h  | 2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c   | 5 +++--
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index df11376ee735..090ebceb288a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -733,7 +733,7 @@ static void dwmac4_set_mac_loopback(void __iomem *ioaddr, 
bool enable)
 }
 
 static void dwmac4_update_vlan_hash(struct mac_device_info *hw, u32 hash,
-   u16 perfect_match, bool is_double)
+   __le16 perfect_match, bool is_double)
 {
void __iomem *ioaddr = hw->pcsr;
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 5cda360d5d07..e24382d00e62 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -555,7 +555,7 @@ static int dwxgmac2_rss_configure(struct mac_device_info 
*hw,
 }
 
 static void dwxgmac2_update_vlan_hash(struct mac_device_info *hw, u32 hash,
- u16 perfect_match, bool is_double)
+ __le16 perfect_match, bool is_double)
 {
void __iomem *ioaddr = hw->pcsr;
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h 
b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index 1303d1e9a18f..509daeefdb79 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -357,7 +357,7 @@ struct stmmac_ops {
 struct stmmac_rss *cfg, u32 num_rxq);
/* VLAN */
void (*update_vlan_hash)(struct mac_device_info *hw, u32 hash,
-u16 perfect_match, bool is_double);
+__le16 perfect_match, bool is_double);
void (*enable_vlan)(struct mac_device_info *hw, u32 type);
/* TX Timestamp */
int (*get_mac_tx_timestamp)(struct mac_device_info *hw, u64 *ts);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 8b76745a7ec4..40b0756f3a14 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4207,6 +4207,7 @@ static u32 stmmac_vid_crc32_le(__le16 vid_le)
 static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double)
 {
u32 crc, hash = 0;
+   __le16 pmatch = 0;
int count = 0;
u16 vid = 0;
 
@@ -4221,11 +4222,11 @@ static int stmmac_vlan_update(struct stmmac_priv *priv, 
bool is_double)
if (count > 2) /* VID = 0 always passes filter */
return -EOPNOTSUPP;
 
-   vid = cpu_to_le16(vid);
+   pmatch = cpu_to_le16(vid);
hash = 0;
}
 
-   return stmmac_update_vlan_hash(priv, priv->hw, hash, vid, is_double);
+   return stmmac_update_vlan_hash(priv, priv->hw, hash, pmatch, is_double);
 }
 
 static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 
vid)
-- 
2.7.4



[PATCH net-next 2/3] net: stmmac: selftests: Add tests for VLAN Perfect Filtering

2019-10-06 Thread Jose Abreu
From: Jose Abreu 

Add two new tests for VLAN Perfect Filtering. While at it, increase a
little bit the tests strings lenght so that we can have more descriptive
test names.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 114 ++---
 1 file changed, 77 insertions(+), 37 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index e4ac3c401432..0b5db52149bc 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -823,16 +823,13 @@ static int stmmac_test_vlan_validate(struct sk_buff *skb,
return 0;
 }
 
-static int stmmac_test_vlanfilt(struct stmmac_priv *priv)
+static int __stmmac_test_vlanfilt(struct stmmac_priv *priv)
 {
struct stmmac_packet_attrs attr = { };
struct stmmac_test_priv *tpriv;
struct sk_buff *skb = NULL;
int ret = 0, i;
 
-   if (!priv->dma_cap.vlhash)
-   return -EOPNOTSUPP;
-
tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
if (!tpriv)
return -ENOMEM;
@@ -898,16 +895,32 @@ static int stmmac_test_vlanfilt(struct stmmac_priv *priv)
return ret;
 }
 
-static int stmmac_test_dvlanfilt(struct stmmac_priv *priv)
+static int stmmac_test_vlanfilt(struct stmmac_priv *priv)
+{
+   if (!priv->dma_cap.vlhash)
+   return -EOPNOTSUPP;
+
+   return __stmmac_test_vlanfilt(priv);
+}
+
+static int stmmac_test_vlanfilt_perfect(struct stmmac_priv *priv)
+{
+   int ret, prev_cap = priv->dma_cap.vlhash;
+
+   priv->dma_cap.vlhash = 0;
+   ret = __stmmac_test_vlanfilt(priv);
+   priv->dma_cap.vlhash = prev_cap;
+
+   return ret;
+}
+
+static int __stmmac_test_dvlanfilt(struct stmmac_priv *priv)
 {
struct stmmac_packet_attrs attr = { };
struct stmmac_test_priv *tpriv;
struct sk_buff *skb = NULL;
int ret = 0, i;
 
-   if (!priv->dma_cap.vlhash)
-   return -EOPNOTSUPP;
-
tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
if (!tpriv)
return -ENOMEM;
@@ -974,6 +987,25 @@ static int stmmac_test_dvlanfilt(struct stmmac_priv *priv)
return ret;
 }
 
+static int stmmac_test_dvlanfilt(struct stmmac_priv *priv)
+{
+   if (!priv->dma_cap.vlhash)
+   return -EOPNOTSUPP;
+
+   return __stmmac_test_dvlanfilt(priv);
+}
+
+static int stmmac_test_dvlanfilt_perfect(struct stmmac_priv *priv)
+{
+   int ret, prev_cap = priv->dma_cap.vlhash;
+
+   priv->dma_cap.vlhash = 0;
+   ret = __stmmac_test_dvlanfilt(priv);
+   priv->dma_cap.vlhash = prev_cap;
+
+   return ret;
+}
+
 #ifdef CONFIG_NET_CLS_ACT
 static int stmmac_test_rxp(struct stmmac_priv *priv)
 {
@@ -1648,119 +1680,127 @@ static const struct stmmac_test {
int (*fn)(struct stmmac_priv *priv);
 } stmmac_selftests[] = {
{
-   .name = "MAC Loopback ",
+   .name = "MAC Loopback   ",
.lb = STMMAC_LOOPBACK_MAC,
.fn = stmmac_test_mac_loopback,
}, {
-   .name = "PHY Loopback ",
+   .name = "PHY Loopback   ",
.lb = STMMAC_LOOPBACK_NONE, /* Test will handle it */
.fn = stmmac_test_phy_loopback,
}, {
-   .name = "MMC Counters ",
+   .name = "MMC Counters   ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_mmc,
}, {
-   .name = "EEE  ",
+   .name = "EEE",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_eee,
}, {
-   .name = "Hash Filter MC   ",
+   .name = "Hash Filter MC ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_hfilt,
}, {
-   .name = "Perfect Filter UC",
+   .name = "Perfect Filter UC  ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_pfilt,
}, {
-   .name = "MC Filter",
+   .name = "MC Filter  ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_mcfilt,
}, {
-   .name = "UC Filter",
+   .name = "UC Filter  

[PATCH net-next 1/3] net: stmmac: Fallback to VLAN Perfect filtering if HASH is not available

2019-10-06 Thread Jose Abreu
From: Jose Abreu 

If VLAN Hash Filtering is not available we can fallback to perfect
filtering instead. Let's implement this in XGMAC and GMAC cores and let
the user use this filter.

VLAN VID=0 always passes filter so we check if more than 2 VLANs are
created and return proper error code if so because perfect filtering
only supports 1 VID at a time.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c   | 12 +++-
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 17 -
 drivers/net/ethernet/stmicro/stmmac/hwif.h  |  2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c   | 18 --
 4 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 5a7b0aca1d31..1a04815d1d65 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -733,7 +733,7 @@ static void dwmac4_set_mac_loopback(void __iomem *ioaddr, 
bool enable)
 }
 
 static void dwmac4_update_vlan_hash(struct mac_device_info *hw, u32 hash,
-   bool is_double)
+   u16 perfect_match, bool is_double)
 {
void __iomem *ioaddr = hw->pcsr;
 
@@ -748,6 +748,16 @@ static void dwmac4_update_vlan_hash(struct mac_device_info 
*hw, u32 hash,
}
 
writel(value, ioaddr + GMAC_VLAN_TAG);
+   } else if (perfect_match) {
+   u32 value = GMAC_VLAN_ETV;
+
+   if (is_double) {
+   value |= GMAC_VLAN_EDVLP;
+   value |= GMAC_VLAN_ESVL;
+   value |= GMAC_VLAN_DOVLTC;
+   }
+
+   writel(value | perfect_match, ioaddr + GMAC_VLAN_TAG);
} else {
u32 value = readl(ioaddr + GMAC_VLAN_TAG);
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 5031398e612c..5cda360d5d07 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -555,7 +555,7 @@ static int dwxgmac2_rss_configure(struct mac_device_info 
*hw,
 }
 
 static void dwxgmac2_update_vlan_hash(struct mac_device_info *hw, u32 hash,
- bool is_double)
+ u16 perfect_match, bool is_double)
 {
void __iomem *ioaddr = hw->pcsr;
 
@@ -576,6 +576,21 @@ static void dwxgmac2_update_vlan_hash(struct 
mac_device_info *hw, u32 hash,
}
 
writel(value, ioaddr + XGMAC_VLAN_TAG);
+   } else if (perfect_match) {
+   u32 value = readl(ioaddr + XGMAC_PACKET_FILTER);
+
+   value |= XGMAC_FILTER_VTFE;
+
+   writel(value, ioaddr + XGMAC_PACKET_FILTER);
+
+   value = XGMAC_VLAN_ETV;
+   if (is_double) {
+   value |= XGMAC_VLAN_EDVLP;
+   value |= XGMAC_VLAN_ESVL;
+   value |= XGMAC_VLAN_DOVLTC;
+   }
+
+   writel(value | perfect_match, ioaddr + XGMAC_VLAN_TAG);
} else {
u32 value = readl(ioaddr + XGMAC_PACKET_FILTER);
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h 
b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index ddb851d99618..1303d1e9a18f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -357,7 +357,7 @@ struct stmmac_ops {
 struct stmmac_rss *cfg, u32 num_rxq);
/* VLAN */
void (*update_vlan_hash)(struct mac_device_info *hw, u32 hash,
-bool is_double);
+u16 perfect_match, bool is_double);
void (*enable_vlan)(struct mac_device_info *hw, u32 type);
/* TX Timestamp */
int (*get_mac_tx_timestamp)(struct mac_device_info *hw, u64 *ts);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index b8ac1744950e..8b76745a7ec4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4207,15 +4207,25 @@ static u32 stmmac_vid_crc32_le(__le16 vid_le)
 static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double)
 {
u32 crc, hash = 0;
-   u16 vid;
+   int count = 0;
+   u16 vid = 0;
 
for_each_set_bit(vid, priv->active_vlans, VLAN_N_VID) {
__le16 vid_le = cpu_to_le16(vid);
crc = bitrev32(~stmmac_

[PATCH net-next 3/3] net: stmmac: Implement L3/L4 Filters in GMAC4+

2019-10-06 Thread Jose Abreu
From: Jose Abreu 

GMAC4+ cores support Layer 3 and Layer 4 filtering. Add the
corresponding callbacks in these cores.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h  |  21 +
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 106 ++
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c  |   1 +
 3 files changed, 128 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index 2fe45fa3c482..07e97f45755d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -43,6 +43,10 @@
 #define GMAC_ARP_ADDR  0x0210
 #define GMAC_ADDR_HIGH(reg)(0x300 + reg * 8)
 #define GMAC_ADDR_LOW(reg) (0x304 + reg * 8)
+#define GMAC_L3L4_CTRL(reg)(0x900 + (reg) * 0x30)
+#define GMAC_L4_ADDR(reg)  (0x904 + (reg) * 0x30)
+#define GMAC_L3_ADDR0(reg) (0x910 + (reg) * 0x30)
+#define GMAC_L3_ADDR1(reg) (0x914 + (reg) * 0x30)
 
 /* RX Queues Routing */
 #define GMAC_RXQCTRL_AVCPQ_MASKGENMASK(2, 0)
@@ -67,6 +71,7 @@
 #define GMAC_PACKET_FILTER_PCF BIT(7)
 #define GMAC_PACKET_FILTER_HPF BIT(10)
 #define GMAC_PACKET_FILTER_VTFEBIT(16)
+#define GMAC_PACKET_FILTER_IPFEBIT(20)
 
 #define GMAC_MAX_PERFECT_ADDRESSES 128
 
@@ -202,6 +207,7 @@ enum power_event {
 #define GMAC_HW_FEAT_MIISELBIT(0)
 
 /* MAC HW features1 bitmap */
+#define GMAC_HW_FEAT_L3L4FNUM  GENMASK(30, 27)
 #define GMAC_HW_HASH_TB_SZ GENMASK(25, 24)
 #define GMAC_HW_FEAT_AVSEL BIT(20)
 #define GMAC_HW_TSOEN  BIT(18)
@@ -228,6 +234,21 @@ enum power_event {
 #define GMAC_HI_DCS_SHIFT  16
 #define GMAC_HI_REG_AE BIT(31)
 
+/* L3/L4 Filters regs */
+#define GMAC_L4DPIM0   BIT(21)
+#define GMAC_L4DPM0BIT(20)
+#define GMAC_L4SPIM0   BIT(19)
+#define GMAC_L4SPM0BIT(18)
+#define GMAC_L4PEN0BIT(16)
+#define GMAC_L3DAIM0   BIT(5)
+#define GMAC_L3DAM0BIT(4)
+#define GMAC_L3SAIM0   BIT(3)
+#define GMAC_L3SAM0BIT(2)
+#define GMAC_L3PEN0BIT(0)
+#define GMAC_L4DP0 GENMASK(31, 16)
+#define GMAC_L4DP0_SHIFT   16
+#define GMAC_L4SP0 GENMASK(15, 0)
+
 /*  MTL registers */
 #define MTL_OPERATION_MODE 0x0c00
 #define MTL_FRPE   BIT(15)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 1a04815d1d65..dda3e5b50f4d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -809,6 +809,106 @@ static void dwmac4_set_arp_offload(struct mac_device_info 
*hw, bool en,
writel(value, ioaddr + GMAC_CONFIG);
 }
 
+static int dwmac4_config_l3_filter(struct mac_device_info *hw, u32 filter_no,
+  bool en, bool ipv6, bool sa, bool inv,
+  u32 match)
+{
+   void __iomem *ioaddr = hw->pcsr;
+   u32 value;
+
+   value = readl(ioaddr + GMAC_PACKET_FILTER);
+   value |= GMAC_PACKET_FILTER_IPFE;
+   writel(value, ioaddr + GMAC_PACKET_FILTER);
+
+   value = readl(ioaddr + GMAC_L3L4_CTRL(filter_no));
+
+   /* For IPv6 not both SA/DA filters can be active */
+   if (ipv6) {
+   value |= GMAC_L3PEN0;
+   value &= ~(GMAC_L3SAM0 | GMAC_L3SAIM0);
+   value &= ~(GMAC_L3DAM0 | GMAC_L3DAIM0);
+   if (sa) {
+   value |= GMAC_L3SAM0;
+   if (inv)
+   value |= GMAC_L3SAIM0;
+   } else {
+   value |= GMAC_L3DAM0;
+   if (inv)
+   value |= GMAC_L3DAIM0;
+   }
+   } else {
+   value &= ~GMAC_L3PEN0;
+   if (sa) {
+   value |= GMAC_L3SAM0;
+   if (inv)
+   value |= GMAC_L3SAIM0;
+   } else {
+   value |= GMAC_L3DAM0;
+   if (inv)
+   value |= GMAC_L3DAIM0;
+   }
+   }
+
+   writel(value, ioaddr + GMAC_L3L4_CTRL(filter_no));
+
+   if (sa) {
+   writel(match, ioaddr + GMAC_L3_ADDR0(filter_no));
+   } else {
+  

[PATCH net-next 0/3] net: stmmac: Improvements for -next

2019-10-06 Thread Jose Abreu
Improvements for -next. More info in commit logs.

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---

Jose Abreu (3):
  net: stmmac: Fallback to VLAN Perfect filtering if HASH is not
available
  net: stmmac: selftests: Add tests for VLAN Perfect Filtering
  net: stmmac: Implement L3/L4 Filters in GMAC4+

 drivers/net/ethernet/stmicro/stmmac/dwmac4.h   |  21 
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c  | 118 -
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c   |   1 +
 .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c|  17 ++-
 drivers/net/ethernet/stmicro/stmmac/hwif.h |   2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |  18 ++--
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 114 +---
 7 files changed, 245 insertions(+), 46 deletions(-)

-- 
2.7.4



[PATCH net 2/3] net: stmmac: gmac4+: Not all Unicast addresses may be available

2019-10-06 Thread Jose Abreu
Some setups may not have all Unicast addresses filters available. Check
the number of available filters before trying to setup it.

Fixes: 477286b53f55 ("stmmac: add GMAC4 core support")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 2cb9c53f93b8..5a7b0aca1d31 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -448,7 +448,7 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
value |= GMAC_PACKET_FILTER_HPF;
 
/* Handle multiple unicast addresses */
-   if (netdev_uc_count(dev) > GMAC_MAX_PERFECT_ADDRESSES) {
+   if (netdev_uc_count(dev) > hw->unicast_filter_entries) {
/* Switch to promiscuous mode if more than 128 addrs
 * are required
 */
-- 
2.7.4



[PATCH net 1/3] net: stmmac: selftests: Check if filtering is available before running

2019-10-06 Thread Jose Abreu
We need to check if the number of available Hash Filters is enough to
run the test, otherwise we will get false failures.

Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index cc76a42c7466..ed3926d4471d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -496,6 +496,9 @@ static int stmmac_test_hfilt(struct stmmac_priv *priv)
if (ret)
return ret;
 
+   if (netdev_mc_count(priv->dev) >= priv->hw->multicast_filter_bins)
+   return -EOPNOTSUPP;
+
ret = dev_mc_add(priv->dev, gd_addr);
if (ret)
return ret;
@@ -573,6 +576,8 @@ static int stmmac_test_mcfilt(struct stmmac_priv *priv)
 
if (stmmac_filter_check(priv))
return -EOPNOTSUPP;
+   if (!priv->hw->multicast_filter_bins)
+   return -EOPNOTSUPP;
 
/* Remove all MC addresses */
__dev_mc_unsync(priv->dev, NULL);
@@ -611,6 +616,8 @@ static int stmmac_test_ucfilt(struct stmmac_priv *priv)
 
if (stmmac_filter_check(priv))
return -EOPNOTSUPP;
+   if (!priv->hw->multicast_filter_bins)
+   return -EOPNOTSUPP;
 
/* Remove all UC addresses */
__dev_uc_unsync(priv->dev, NULL);
-- 
2.7.4



[PATCH net 3/3] net: stmmac: selftests: Fix L2 Hash Filter test

2019-10-06 Thread Jose Abreu
With the current MAC addresses hard-coded in the test we can get some
false positives as we use the Hash Filtering method. Let's change the
MAC addresses in the tests to be unique when hashed.

Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index ed3926d4471d..e4ac3c401432 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -487,8 +487,8 @@ static int stmmac_filter_check(struct stmmac_priv *priv)
 
 static int stmmac_test_hfilt(struct stmmac_priv *priv)
 {
-   unsigned char gd_addr[ETH_ALEN] = {0x01, 0x00, 0xcc, 0xcc, 0xdd, 0xdd};
-   unsigned char bd_addr[ETH_ALEN] = {0x09, 0x00, 0xaa, 0xaa, 0xbb, 0xbb};
+   unsigned char gd_addr[ETH_ALEN] = {0x01, 0xee, 0xdd, 0xcc, 0xbb, 0xaa};
+   unsigned char bd_addr[ETH_ALEN] = {0x01, 0x01, 0x02, 0x03, 0x04, 0x05};
struct stmmac_packet_attrs attr = { };
int ret;
 
-- 
2.7.4



[PATCH net 0/3] net: stmmac: Fixes for -net

2019-10-06 Thread Jose Abreu
Fixes for -net. More info in commit logs.

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---

Jose Abreu (3):
  net: stmmac: selftests: Check if filtering is available before running
  net: stmmac: gmac4+: Not all Unicast addresses may be available
  net: stmmac: selftests: Fix L2 Hash Filter test

 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c  |  2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 11 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

-- 
2.7.4



RE: [PATCH] net: stmmac: Read user ID muliple times if needed.

2019-10-02 Thread Jose Abreu
From: Hans Andersson 
Date: Oct/02/2019, 09:02:02 (UTC+00:00)

> We assert / de-assert the reset line, but the CPU is too fast and the IP is 
> still 
> in reset when we later try to read user ID / Synopsys ID. Another option would
> be to add a delay after we reset.

Then I think you should fix the reset driver to only return when the 
reset is fully done.

---
Thanks,
Jose Miguel Abreu


RE: [PATCH] net: stmmac: Read user ID muliple times if needed.

2019-10-02 Thread Jose Abreu
From: Hans Andersson 
Date: Oct/02/2019, 08:07:21 (UTC+00:00)

> When we read user ID / Synopsys ID we might still be in reset,
> so read muliple times if needed.

We shouldn't even try to read it if IP is in reset ... 

---
Thanks,
Jose Miguel Abreu


[PATCH v2 net 5/9] net: stmmac: Correctly take timestamp for PTPv2

2019-09-30 Thread Jose Abreu
The case for PTPV2_EVENT requires event packets to be captured so add
this setting to the list of enabled captures.

Fixes: 891434b18ec0 ("stmmac: add IEEE PTPv1 and PTPv2 support.")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 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 d3232738fb25..31a237ec73bc 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -629,6 +629,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, 
struct ifreq *ifr)
config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
ptp_v2 = PTP_TCR_TSVER2ENA;
snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
+   ts_event_en = PTP_TCR_TSEVNTENA;
ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
ptp_over_ethernet = PTP_TCR_TSIPENA;
-- 
2.7.4



[PATCH v2 net 7/9] net: stmmac: xgmac: Disable the Timestamp interrupt by default

2019-09-30 Thread Jose Abreu
We don't use it anyway as XGMAC only supports polling for timestamp (in
current SW implementation). This greatly reduces the system load by
reducing the number of interrupts.

Fixes: 2142754f8b9c ("net: stmmac: Add MAC related callbacks for XGMAC2")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index f7eb06f8fb37..99037386080a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -84,7 +84,7 @@
 #define XGMAC_TSIE BIT(12)
 #define XGMAC_LPIIEBIT(5)
 #define XGMAC_PMTIEBIT(4)
-#define XGMAC_INT_DEFAULT_EN   (XGMAC_LPIIE | XGMAC_PMTIE | XGMAC_TSIE)
+#define XGMAC_INT_DEFAULT_EN   (XGMAC_LPIIE | XGMAC_PMTIE)
 #define XGMAC_Qx_TX_FLOW_CTRL(x)   (0x0070 + (x) * 4)
 #define XGMAC_PT   GENMASK(31, 16)
 #define XGMAC_PT_SHIFT 16
-- 
2.7.4



[PATCH v2 net 6/9] net: stmmac: Do not stop PHY if WoL is enabled

2019-09-30 Thread Jose Abreu
If WoL is enabled we can't really stop the PHY, otherwise we will not
receive the WoL packet. Fix this by telling phylink that only the MAC is
down and only stop the PHY if WoL is not enabled.

Fixes: 74371272f97f ("net: stmmac: Convert to phylink and remove phylib logic")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 31a237ec73bc..843d53e084b7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4718,9 +4718,7 @@ int stmmac_suspend(struct device *dev)
 
mutex_lock(>lock);
 
-   rtnl_lock();
-   phylink_stop(priv->phylink);
-   rtnl_unlock();
+   phylink_mac_change(priv->phylink, false);
 
netif_device_detach(ndev);
stmmac_stop_all_queues(priv);
@@ -4735,6 +4733,10 @@ int stmmac_suspend(struct device *dev)
stmmac_pmt(priv, priv->hw, priv->wolopts);
priv->irq_wake = 1;
} else {
+   rtnl_lock();
+   phylink_stop(priv->phylink);
+   rtnl_unlock();
+
stmmac_mac_set(priv, priv->ioaddr, false);
pinctrl_pm_select_sleep_state(priv->device);
/* Disable clock in case of PWM is off */
@@ -4825,9 +4827,13 @@ int stmmac_resume(struct device *dev)
 
stmmac_start_all_queues(priv);
 
-   rtnl_lock();
-   phylink_start(priv->phylink);
-   rtnl_unlock();
+   if (!device_may_wakeup(priv->device)) {
+   rtnl_lock();
+   phylink_start(priv->phylink);
+   rtnl_unlock();
+   }
+
+   phylink_mac_change(priv->phylink, true);
 
mutex_unlock(>lock);
 
-- 
2.7.4



[PATCH v2 net 1/9] net: stmmac: xgmac: Not all Unicast addresses may be available

2019-09-30 Thread Jose Abreu
Some setups may not have all Unicast addresses filters available. Let's
check this before trying to setup filters.

Fixes: 0efedbf11f07 ("net: stmmac: xgmac: Fix XGMAC selftests")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 2b277b2c586b..6d8ac2ef4fc2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -472,7 +472,7 @@ static void dwxgmac2_set_filter(struct mac_device_info *hw,
dwxgmac2_set_mchash(ioaddr, mc_filter, mcbitslog2);
 
/* Handle multiple unicast addresses */
-   if (netdev_uc_count(dev) > XGMAC_ADDR_MAX) {
+   if (netdev_uc_count(dev) > hw->unicast_filter_entries) {
value |= XGMAC_FILTER_PR;
} else {
struct netdev_hw_addr *ha;
-- 
2.7.4



[PATCH v2 net 9/9] net: stmmac: xgmac: Fix RSS writing wrong keys

2019-09-30 Thread Jose Abreu
Commit b6b6cc9acd7b, changed the call to dwxgmac2_rss_write_reg()
passing it the variable cfg->key[i].

As key is an u8 but we write 32 bits at a time we need to cast it into
an u32 so that the correct key values are written. Notice that the for
loop already takes this into account so we don't try to write past the
keys size.

Fixes: b6b6cc9acd7b ("net: stmmac: selftest: avoid large stack usage")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: Arnd Bergmann 
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 4a1f52474dbc..5031398e612c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -523,8 +523,8 @@ static int dwxgmac2_rss_configure(struct mac_device_info 
*hw,
  struct stmmac_rss *cfg, u32 num_rxq)
 {
void __iomem *ioaddr = hw->pcsr;
+   u32 value, *key;
int i, ret;
-   u32 value;
 
value = readl(ioaddr + XGMAC_RSS_CTRL);
if (!cfg || !cfg->enable) {
@@ -533,8 +533,9 @@ static int dwxgmac2_rss_configure(struct mac_device_info 
*hw,
return 0;
}
 
+   key = (u32 *)cfg->key;
for (i = 0; i < (ARRAY_SIZE(cfg->key) / sizeof(u32)); i++) {
-   ret = dwxgmac2_rss_write_reg(ioaddr, true, i, cfg->key[i]);
+   ret = dwxgmac2_rss_write_reg(ioaddr, true, i, key[i]);
if (ret)
return ret;
}
-- 
2.7.4



[PATCH v2 net 0/9] net: stmmac: Fixes for -net

2019-09-30 Thread Jose Abreu
Misc fixes for -net tree. More info in commit logs.

v2 is just a rebase of v1 against -net and we added a new patch (09/09) to
fix RSS feature.

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---

Jose Abreu (9):
  net: stmmac: xgmac: Not all Unicast addresses may be available
  net: stmmac: xgmac: Detect Hash Table size dinamically
  net: stmmac: selftests: Always use max DMA size in Jumbo Test
  net: stmmac: dwmac4: Always update the MAC Hash Filter
  net: stmmac: Correctly take timestamp for PTPv2
  net: stmmac: Do not stop PHY if WoL is enabled
  net: stmmac: xgmac: Disable the Timestamp interrupt by default
  net: stmmac: xgmac: Fix RSS not writing all Keys to HW
  net: stmmac: xgmac: Fix RSS writing wrong keys

 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 13 +++--
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h|  3 ++-
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c   |  9 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c|  1 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 19 +--
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c|  4 
 6 files changed, 28 insertions(+), 21 deletions(-)

-- 
2.7.4



[PATCH v2 net 2/9] net: stmmac: xgmac: Detect Hash Table size dinamically

2019-09-30 Thread Jose Abreu
Since commit b8ef7020d6e5 ("net: stmmac: add support for hash table size
128/256 in dwmac4"), we can detect the Hash Table dinamically.

Let's implement this feature in XGMAC cores and fix possible setups that
don't support the maximum size for Hash Table.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h | 1 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index 5923ca62d793..f7eb06f8fb37 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -122,6 +122,7 @@
 #define XGMAC_HWFEAT_GMIISEL   BIT(1)
 #define XGMAC_HW_FEATURE1  0x0120
 #define XGMAC_HWFEAT_L3L4FNUM  GENMASK(30, 27)
+#define XGMAC_HWFEAT_HASHTBLSZ GENMASK(25, 24)
 #define XGMAC_HWFEAT_RSSEN BIT(20)
 #define XGMAC_HWFEAT_TSOEN BIT(18)
 #define XGMAC_HWFEAT_SPHEN BIT(17)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
index 53c4a40d8386..965cbe3e6f51 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
@@ -380,6 +380,7 @@ static void dwxgmac2_get_hw_feature(void __iomem *ioaddr,
/* MAC HW feature 1 */
hw_cap = readl(ioaddr + XGMAC_HW_FEATURE1);
dma_cap->l3l4fnum = (hw_cap & XGMAC_HWFEAT_L3L4FNUM) >> 27;
+   dma_cap->hash_tb_sz = (hw_cap & XGMAC_HWFEAT_HASHTBLSZ) >> 24;
dma_cap->rssen = (hw_cap & XGMAC_HWFEAT_RSSEN) >> 20;
dma_cap->tsoen = (hw_cap & XGMAC_HWFEAT_TSOEN) >> 18;
dma_cap->sphen = (hw_cap & XGMAC_HWFEAT_SPHEN) >> 17;
-- 
2.7.4



[PATCH v2 net 3/9] net: stmmac: selftests: Always use max DMA size in Jumbo Test

2019-09-30 Thread Jose Abreu
Although some XGMAC setups support frames larger than DMA size, some of
them may not. As we can't know before-hand which ones support let's use
the maximum DMA buffer size in the Jumbo Tests.

User can always reconfigure the MTU to achieve larger frames.

Fixes: 427849e8c37f ("net: stmmac: selftests: Add Jumbo Frame tests")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 5f66f6161629..cc76a42c7466 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -1564,10 +1564,6 @@ static int __stmmac_test_jumbo(struct stmmac_priv *priv, 
u16 queue)
struct stmmac_packet_attrs attr = { };
int size = priv->dma_buf_sz;
 
-   /* Only XGMAC has SW support for multiple RX descs in same packet */
-   if (priv->plat->has_xgmac)
-   size = priv->dev->max_mtu;
-
attr.dst = priv->dev->dev_addr;
attr.max_size = size - ETH_FCS_LEN;
attr.queue_mapping = queue;
-- 
2.7.4



[PATCH v2 net 4/9] net: stmmac: dwmac4: Always update the MAC Hash Filter

2019-09-30 Thread Jose Abreu
We need to always update the MAC Hash Filter so that previous entries
are invalidated.

Found out while running stmmac selftests.

Fixes: b8ef7020d6e5 ("net: stmmac: add support for hash table size 128/256 in 
dwmac4")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 9b4b5f69fc02..2cb9c53f93b8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -401,8 +401,11 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
int numhashregs = (hw->multicast_filter_bins >> 5);
int mcbitslog2 = hw->mcast_bits_log2;
unsigned int value;
+   u32 mc_filter[8];
int i;
 
+   memset(mc_filter, 0, sizeof(mc_filter));
+
value = readl(ioaddr + GMAC_PACKET_FILTER);
value &= ~GMAC_PACKET_FILTER_HMC;
value &= ~GMAC_PACKET_FILTER_HPF;
@@ -416,16 +419,13 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
/* Pass all multi */
value |= GMAC_PACKET_FILTER_PM;
/* Set all the bits of the HASH tab */
-   for (i = 0; i < numhashregs; i++)
-   writel(0x, ioaddr + GMAC_HASH_TAB(i));
+   memset(mc_filter, 0xff, sizeof(mc_filter));
} else if (!netdev_mc_empty(dev)) {
struct netdev_hw_addr *ha;
-   u32 mc_filter[8];
 
/* Hash filter for multicast */
value |= GMAC_PACKET_FILTER_HMC;
 
-   memset(mc_filter, 0, sizeof(mc_filter));
netdev_for_each_mc_addr(ha, dev) {
/* The upper n bits of the calculated CRC are used to
 * index the contents of the hash table. The number of
@@ -440,10 +440,11 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
 */
mc_filter[bit_nr >> 5] |= (1 << (bit_nr & 0x1f));
}
-   for (i = 0; i < numhashregs; i++)
-   writel(mc_filter[i], ioaddr + GMAC_HASH_TAB(i));
}
 
+   for (i = 0; i < numhashregs; i++)
+   writel(mc_filter[i], ioaddr + GMAC_HASH_TAB(i));
+
value |= GMAC_PACKET_FILTER_HPF;
 
/* Handle multiple unicast addresses */
-- 
2.7.4



[PATCH v2 net 8/9] net: stmmac: xgmac: Fix RSS not writing all Keys to HW

2019-09-30 Thread Jose Abreu
The sizeof(cfg->key) is != ARRAY_SIZE(cfg->key). Fix it. This warning is
triggered when running with cc flag -Wsizeof-array-div.

Reported-by: kbuild test robot 
Reported-by: Nick Desaulniers 
Reported-by: Nathan Chancellor 
Fixes: 76067459c686 ("net: stmmac: Implement RSS and enable it in XGMAC core")
Reviewed-by: Nick Desaulniers 
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: Nick Desaulniers 
Cc: Nathan Chancellor 
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 6d8ac2ef4fc2..4a1f52474dbc 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -533,7 +533,7 @@ static int dwxgmac2_rss_configure(struct mac_device_info 
*hw,
return 0;
}
 
-   for (i = 0; i < (sizeof(cfg->key) / sizeof(u32)); i++) {
+   for (i = 0; i < (ARRAY_SIZE(cfg->key) / sizeof(u32)); i++) {
ret = dwxgmac2_rss_write_reg(ioaddr, true, i, cfg->key[i]);
if (ret)
return ret;
-- 
2.7.4



RE: [PATCH net 0/8] net: stmmac: Fixes for -net

2019-09-28 Thread Jose Abreu
From: Jose Abreu 
Date: Sep/27/2019, 08:48:48 (UTC+00:00)

> Misc fixes for -net tree. More info in commit logs.

David, please do not apply these. I forgot to rebase my tree against 
-net and this was based on -next. I'll resend. Sorry for the mess :(

---
Thanks,
Jose Miguel Abreu


[PATCH net 6/8] net: stmmac: Do not stop PHY if WoL is enabled

2019-09-27 Thread Jose Abreu
If WoL is enabled we can't really stop the PHY, otherwise we will not
receive the WoL packet. Fix this by telling phylink that only the MAC is
down and only stop the PHY if WoL is not enabled.

Fixes: 74371272f97f ("net: stmmac: Convert to phylink and remove phylib logic")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 31a237ec73bc..843d53e084b7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4718,9 +4718,7 @@ int stmmac_suspend(struct device *dev)
 
mutex_lock(>lock);
 
-   rtnl_lock();
-   phylink_stop(priv->phylink);
-   rtnl_unlock();
+   phylink_mac_change(priv->phylink, false);
 
netif_device_detach(ndev);
stmmac_stop_all_queues(priv);
@@ -4735,6 +4733,10 @@ int stmmac_suspend(struct device *dev)
stmmac_pmt(priv, priv->hw, priv->wolopts);
priv->irq_wake = 1;
} else {
+   rtnl_lock();
+   phylink_stop(priv->phylink);
+   rtnl_unlock();
+
stmmac_mac_set(priv, priv->ioaddr, false);
pinctrl_pm_select_sleep_state(priv->device);
/* Disable clock in case of PWM is off */
@@ -4825,9 +4827,13 @@ int stmmac_resume(struct device *dev)
 
stmmac_start_all_queues(priv);
 
-   rtnl_lock();
-   phylink_start(priv->phylink);
-   rtnl_unlock();
+   if (!device_may_wakeup(priv->device)) {
+   rtnl_lock();
+   phylink_start(priv->phylink);
+   rtnl_unlock();
+   }
+
+   phylink_mac_change(priv->phylink, true);
 
mutex_unlock(>lock);
 
-- 
2.7.4



[PATCH net 7/8] net: stmmac: xgmac: Disable the Timestamp interrupt by default

2019-09-27 Thread Jose Abreu
We don't use it anyway as XGMAC only supports polling for timestamp (in
current SW implementation). This greatly reduces the system load by
reducing the number of interrupts.

Fixes: 2142754f8b9c ("net: stmmac: Add MAC related callbacks for XGMAC2")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index f7eb06f8fb37..99037386080a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -84,7 +84,7 @@
 #define XGMAC_TSIE BIT(12)
 #define XGMAC_LPIIEBIT(5)
 #define XGMAC_PMTIEBIT(4)
-#define XGMAC_INT_DEFAULT_EN   (XGMAC_LPIIE | XGMAC_PMTIE | XGMAC_TSIE)
+#define XGMAC_INT_DEFAULT_EN   (XGMAC_LPIIE | XGMAC_PMTIE)
 #define XGMAC_Qx_TX_FLOW_CTRL(x)   (0x0070 + (x) * 4)
 #define XGMAC_PT   GENMASK(31, 16)
 #define XGMAC_PT_SHIFT 16
-- 
2.7.4



[PATCH net 0/8] net: stmmac: Fixes for -net

2019-09-27 Thread Jose Abreu
Misc fixes for -net tree. More info in commit logs.

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---

Jose Abreu (8):
  net: stmmac: xgmac: Not all Unicast addresses may be available
  net: stmmac: xgmac: Detect Hash Table size dinamically
  net: stmmac: selftests: Always use max DMA size in Jumbo Test
  net: stmmac: dwmac4: Always update the MAC Hash Filter
  net: stmmac: Correctly take timestamp for PTPv2
  net: stmmac: Do not stop PHY if WoL is enabled
  net: stmmac: xgmac: Disable the Timestamp interrupt by default
  net: stmmac: xgmac: Fix RSS not writing all Keys to HW

 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 13 +++--
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h|  3 ++-
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c   |  4 ++--
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c|  1 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 19 +--
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c|  4 
 6 files changed, 25 insertions(+), 19 deletions(-)

-- 
2.7.4



[PATCH net 4/8] net: stmmac: dwmac4: Always update the MAC Hash Filter

2019-09-27 Thread Jose Abreu
We need to always update the MAC Hash Filter so that previous entries
are invalidated.

Found out while running stmmac selftests.

Fixes: b8ef7020d6e5 ("net: stmmac: add support for hash table size 128/256 in 
dwmac4")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 9b4b5f69fc02..2cb9c53f93b8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -401,8 +401,11 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
int numhashregs = (hw->multicast_filter_bins >> 5);
int mcbitslog2 = hw->mcast_bits_log2;
unsigned int value;
+   u32 mc_filter[8];
int i;
 
+   memset(mc_filter, 0, sizeof(mc_filter));
+
value = readl(ioaddr + GMAC_PACKET_FILTER);
value &= ~GMAC_PACKET_FILTER_HMC;
value &= ~GMAC_PACKET_FILTER_HPF;
@@ -416,16 +419,13 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
/* Pass all multi */
value |= GMAC_PACKET_FILTER_PM;
/* Set all the bits of the HASH tab */
-   for (i = 0; i < numhashregs; i++)
-   writel(0x, ioaddr + GMAC_HASH_TAB(i));
+   memset(mc_filter, 0xff, sizeof(mc_filter));
} else if (!netdev_mc_empty(dev)) {
struct netdev_hw_addr *ha;
-   u32 mc_filter[8];
 
/* Hash filter for multicast */
value |= GMAC_PACKET_FILTER_HMC;
 
-   memset(mc_filter, 0, sizeof(mc_filter));
netdev_for_each_mc_addr(ha, dev) {
/* The upper n bits of the calculated CRC are used to
 * index the contents of the hash table. The number of
@@ -440,10 +440,11 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
 */
mc_filter[bit_nr >> 5] |= (1 << (bit_nr & 0x1f));
}
-   for (i = 0; i < numhashregs; i++)
-   writel(mc_filter[i], ioaddr + GMAC_HASH_TAB(i));
}
 
+   for (i = 0; i < numhashregs; i++)
+   writel(mc_filter[i], ioaddr + GMAC_HASH_TAB(i));
+
value |= GMAC_PACKET_FILTER_HPF;
 
/* Handle multiple unicast addresses */
-- 
2.7.4



[PATCH net 1/8] net: stmmac: xgmac: Not all Unicast addresses may be available

2019-09-27 Thread Jose Abreu
Some setups may not have all Unicast addresses filters available. Let's
check this before trying to setup filters.

Fixes: 0efedbf11f07 ("net: stmmac: xgmac: Fix XGMAC selftests")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 2b277b2c586b..6d8ac2ef4fc2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -472,7 +472,7 @@ static void dwxgmac2_set_filter(struct mac_device_info *hw,
dwxgmac2_set_mchash(ioaddr, mc_filter, mcbitslog2);
 
/* Handle multiple unicast addresses */
-   if (netdev_uc_count(dev) > XGMAC_ADDR_MAX) {
+   if (netdev_uc_count(dev) > hw->unicast_filter_entries) {
value |= XGMAC_FILTER_PR;
} else {
struct netdev_hw_addr *ha;
-- 
2.7.4



[PATCH net 2/8] net: stmmac: xgmac: Detect Hash Table size dinamically

2019-09-27 Thread Jose Abreu
Since commit b8ef7020d6e5 ("net: stmmac: add support for hash table size
128/256 in dwmac4"), we can detect the Hash Table dinamically.

Let's implement this feature in XGMAC cores and fix possible setups that
don't support the maximum size for Hash Table.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h | 1 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index 5923ca62d793..f7eb06f8fb37 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -122,6 +122,7 @@
 #define XGMAC_HWFEAT_GMIISEL   BIT(1)
 #define XGMAC_HW_FEATURE1  0x0120
 #define XGMAC_HWFEAT_L3L4FNUM  GENMASK(30, 27)
+#define XGMAC_HWFEAT_HASHTBLSZ GENMASK(25, 24)
 #define XGMAC_HWFEAT_RSSEN BIT(20)
 #define XGMAC_HWFEAT_TSOEN BIT(18)
 #define XGMAC_HWFEAT_SPHEN BIT(17)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
index 53c4a40d8386..965cbe3e6f51 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
@@ -380,6 +380,7 @@ static void dwxgmac2_get_hw_feature(void __iomem *ioaddr,
/* MAC HW feature 1 */
hw_cap = readl(ioaddr + XGMAC_HW_FEATURE1);
dma_cap->l3l4fnum = (hw_cap & XGMAC_HWFEAT_L3L4FNUM) >> 27;
+   dma_cap->hash_tb_sz = (hw_cap & XGMAC_HWFEAT_HASHTBLSZ) >> 24;
dma_cap->rssen = (hw_cap & XGMAC_HWFEAT_RSSEN) >> 20;
dma_cap->tsoen = (hw_cap & XGMAC_HWFEAT_TSOEN) >> 18;
dma_cap->sphen = (hw_cap & XGMAC_HWFEAT_SPHEN) >> 17;
-- 
2.7.4



[PATCH net 5/8] net: stmmac: Correctly take timestamp for PTPv2

2019-09-27 Thread Jose Abreu
The case for PTPV2_EVENT requires event packets to be captured so add
this setting to the list of enabled captures.

Fixes: 891434b18ec0 ("stmmac: add IEEE PTPv1 and PTPv2 support.")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 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 d3232738fb25..31a237ec73bc 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -629,6 +629,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, 
struct ifreq *ifr)
config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
ptp_v2 = PTP_TCR_TSVER2ENA;
snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
+   ts_event_en = PTP_TCR_TSEVNTENA;
ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
ptp_over_ethernet = PTP_TCR_TSIPENA;
-- 
2.7.4



[PATCH net 8/8] net: stmmac: xgmac: Fix RSS not writing all Keys to HW

2019-09-27 Thread Jose Abreu
The sizeof(cfg->key) is != ARRAY_SIZE(cfg->key). Fix it.

Reported-by: kbuild test robot 
Reported-by: Nick Desaulniers 
Fixes: 76067459c686 ("net: stmmac: Implement RSS and enable it in XGMAC core")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: Nick Desaulniers 
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 6d8ac2ef4fc2..4a1f52474dbc 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -533,7 +533,7 @@ static int dwxgmac2_rss_configure(struct mac_device_info 
*hw,
return 0;
}
 
-   for (i = 0; i < (sizeof(cfg->key) / sizeof(u32)); i++) {
+   for (i = 0; i < (ARRAY_SIZE(cfg->key) / sizeof(u32)); i++) {
ret = dwxgmac2_rss_write_reg(ioaddr, true, i, cfg->key[i]);
if (ret)
return ret;
-- 
2.7.4



[PATCH net 3/8] net: stmmac: selftests: Always use max DMA size in Jumbo Test

2019-09-27 Thread Jose Abreu
Although some XGMAC setups support frames larger than DMA size, some of
them may not. As we can't know before-hand which ones support let's use
the maximum DMA buffer size in the Jumbo Tests.

User can always reconfigure the MTU to achieve larger frames.

Fixes: 427849e8c37f ("net: stmmac: selftests: Add Jumbo Frame tests")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 5f66f6161629..cc76a42c7466 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -1564,10 +1564,6 @@ static int __stmmac_test_jumbo(struct stmmac_priv *priv, 
u16 queue)
struct stmmac_packet_attrs attr = { };
int size = priv->dma_buf_sz;
 
-   /* Only XGMAC has SW support for multiple RX descs in same packet */
-   if (priv->plat->has_xgmac)
-   size = priv->dev->max_mtu;
-
attr.dst = priv->dev->dev_addr;
attr.max_size = size - ETH_FCS_LEN;
attr.queue_mapping = queue;
-- 
2.7.4



[PATCH net v2] net: stmmac: selftests: Flow Control test can also run with ASYM Pause

2019-09-23 Thread Jose Abreu
The Flow Control selftest is also available with ASYM Pause. Lets add
this check to the test and fix eventual false positive failures.

Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 9c8d210b2d6a..5f66f6161629 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -670,7 +670,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv)
unsigned int pkt_count;
int i, ret = 0;
 
-   if (!phydev || !phydev->pause)
+   if (!phydev || (!phydev->pause && !phydev->asym_pause))
return -EOPNOTSUPP;
 
tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
-- 
2.7.4



RE: [PATCH net] net: stmmac: selftests: Flow Control test can also run with ASYM Pause

2019-09-23 Thread Jose Abreu
From: Jose Abreu 
Date: Sep/23/2019, 08:30:43 (UTC+00:00)

> From: Jose Abreu 
> 
> The Flow Control selftest is also available with ASYM Pause. Lets add
> this check to the test and fix eventual false positive failures.
> 
> Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support")
> Signed-off-by: Jose Abreu 

Oops, "From:" and "Signed-off-by:" are still different. I'll amend this 
and re-submit. Please disregard this one.

---
Thanks,
Jose Miguel Abreu


RE: [PATCH net] net: stmmac: selftests: Flow Control test can also run with ASYM Pause

2019-09-23 Thread Jose Abreu
From: Jakub Kicinski 
Date: Sep/22/2019, 22:56:42 (UTC+00:00)

> On Thu, 19 Sep 2019 12:09:49 +0200, Jose Abreu wrote:
> > The Flow Control selftest is also available with ASYM Pause. Lets add
> > this check to the test and fix eventual false positive failures.
> > 
> > Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support")
> > Signed-off-by: Jose Abreu 
> 
> Hi Jose! 
> 
> Thanks for the patch it looks good, seems like you posted it from 
> a slightly different email address than was used for signoff:
> 
> From: Jose Abreu 
> vs
> Signed-off-by: Jose Abreu 
> 
> Could you please fix and repost? Automation may get upset otherwise.

Yeah that's my external vs. internal email messing around. Any of them 
works though. I resent it using the external one. Can you please take a 
look ?

---
Thanks,
Jose Miguel Abreu


[PATCH net] net: stmmac: selftests: Flow Control test can also run with ASYM Pause

2019-09-23 Thread Jose Abreu
From: Jose Abreu 

The Flow Control selftest is also available with ASYM Pause. Lets add
this check to the test and fix eventual false positive failures.

Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 9c8d210b2d6a..5f66f6161629 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -670,7 +670,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv)
unsigned int pkt_count;
int i, ret = 0;
 
-   if (!phydev || !phydev->pause)
+   if (!phydev || (!phydev->pause && !phydev->asym_pause))
return -EOPNOTSUPP;
 
tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
-- 
2.7.4



RE: [PATCH] [v2] net: stmmac: selftest: avoid large stack usage

2019-09-19 Thread Jose Abreu
From: Arnd Bergmann 
Date: Sep/19/2019, 13:33:43 (UTC+00:00)

> Putting a struct stmmac_rss object on the stack is a bad idea,
> as it exceeds the warning limit for a stack frame on 32-bit architectures:
> 
> drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c:1221:12: error: stack 
> frame size of 1208 bytes in function '__stmmac_test_l3filt' 
> [-Werror,-Wframe-larger-than=]
> drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c:1338:12: error: stack 
> frame size of 1208 bytes in function '__stmmac_test_l4filt' 
> [-Werror,-Wframe-larger-than=]
> 
> As the object is the trivial empty case, change the called function
> to accept a NULL pointer to mean the same thing and remove the
> large variable in the two callers.
> 
> Fixes: 4647e021193d ("net: stmmac: selftests: Add selftest for L3/L4 Filters")
> Signed-off-by: Arnd Bergmann 
> ---
> v2: simply configure function, based on feedback from Jose

Looks good to me. Thanks for the fix :)

Acked-by: Jose Abreu 

---
Thanks,
Jose Miguel Abreu


[PATCH net] net: stmmac: selftests: Flow Control test can also run with ASYM Pause

2019-09-19 Thread Jose Abreu
The Flow Control selftest is also available with ASYM Pause. Lets add
this check to the test and fix eventual false positive failures.

Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support")
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index c56e89e1ae56..4b4b03245f6e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -670,7 +670,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv)
unsigned int pkt_count;
int i, ret = 0;
 
-   if (!phydev || !phydev->pause)
+   if (!phydev || (!phydev->pause && !phydev->asym_pause))
return -EOPNOTSUPP;
 
tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
-- 
2.7.4



RE: [PATCH] stmmac: selftest: avoid large stack usage

2019-09-19 Thread Jose Abreu
From: Arnd Bergmann 
Date: Sep/18/2019, 20:54:34 (UTC+00:00)

> + if (!cfg || !cfg->enable) {
>   value &= ~XGMAC_RSSE;
>   writel(value, ioaddr + XGMAC_RSS_CTRL);
>   return 0;
>   }
>  
>   for (i = 0; i < (sizeof(cfg->key) / sizeof(u32)); i++) {
> - ret = dwxgmac2_rss_write_reg(ioaddr, true, i, *key++);
> + if (cfg)
> + ret = dwxgmac2_rss_write_reg(ioaddr, true, i, 
> cfg->key[i]);
> + else
> + ret = dwxgmac2_rss_write_reg(ioaddr, true, i, 0);
> +
>   if (ret)
>   return ret;
>   }
>  
>   for (i = 0; i < ARRAY_SIZE(cfg->table); i++) {
> - ret = dwxgmac2_rss_write_reg(ioaddr, false, i, cfg->table[i]);
> + if (cfg)
> + ret = dwxgmac2_rss_write_reg(ioaddr, false, i, 
> cfg->table[i]);
> + else
> + ret = dwxgmac2_rss_write_reg(ioaddr, false, i, 0);
> +

I don't get these "if (cfg)" checks. You already check earlier if cfg is 
NULL and return if so. I don't think you need these extra checks.

Also, your subject line should be something like: "net: stmmac: 
selftests: ..."

---
Thanks,
Jose Miguel Abreu


RE: [PATCH] net: stmmac: Fix ASSERT_RTNL() warning on suspend/resume

2019-09-17 Thread Jose Abreu
From: Loys Ollivier 
Date: Sep/17/2019, 11:02:36 (UTC+00:00)

> rtnl_lock needs to be taken before calling phylink_start/stop to lock the
> network stack.
> Fix ASSERT_RTNL() warnings by protecting such calls with lock/unlock.
> 
> Fixes: 74371272f97f ("net: stmmac: Convert to phylink and remove phylib 
> logic")
> Signed-off-by: Loys Ollivier 

I already sent a fix for this. Please see in -net:

https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/commit/driv
ers/net/ethernet/stmicro/stmmac?id=19e13cb27b998ff49f07e399b5871bfe5ba7e3
f0

---
Thanks,
Jose Miguel Abreu


[PATCH net] net: stmmac: Hold rtnl lock in suspend/resume callbacks

2019-09-13 Thread Jose Abreu
We need to hold rnl lock in suspend and resume callbacks because phylink
requires it. Otherwise we will get a WARN() in suspend and resume.

Also, move phylink start and stop callbacks to inside device's internal
lock so that we prevent concurrent HW accesses.

Fixes: 74371272f97f ("net: stmmac: Convert to phylink and remove phylib logic")
Reported-by: Christophe ROULLIER 
Tested-by: Christophe ROULLIER 
Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: Christophe ROULLIER 
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index fd54c7c87485..b19ab09cb18f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4451,10 +4451,12 @@ int stmmac_suspend(struct device *dev)
if (!ndev || !netif_running(ndev))
return 0;
 
-   phylink_stop(priv->phylink);
-
mutex_lock(>lock);
 
+   rtnl_lock();
+   phylink_stop(priv->phylink);
+   rtnl_unlock();
+
netif_device_detach(ndev);
stmmac_stop_all_queues(priv);
 
@@ -4558,9 +4560,11 @@ int stmmac_resume(struct device *dev)
 
stmmac_start_all_queues(priv);
 
-   mutex_unlock(>lock);
-
+   rtnl_lock();
phylink_start(priv->phylink);
+   rtnl_unlock();
+
+   mutex_unlock(>lock);
 
return 0;
 }
-- 
2.7.4



RE: [PATCH net-next 0/6] net: stmmac: Improvements for -next

2019-09-11 Thread Jose Abreu
From: David Miller 
Date: Sep/11/2019, 09:21:55 (UTC+00:00)

> From: Jose Abreu 
> Date: Tue, 10 Sep 2019 16:41:21 +0200
> 
> > Misc patches for -next. It includes:
> >  - Two fixes for features in -next only
> >  - New features support for GMAC cores (which includes GMAC4 and GMAC5)
> 
> Series applied, but what exactly does "ARP offload" even do?

ARP Offload allows the IP to reply to ARP_REQUEST packets automatically 
without passing by the application.

As net doesn't support this offloading I'm currently using this feature 
to test endianness issues in the IP and check if MAC Address is 
correctly configured, the logic is as follows:
 - MAC is set in loopback mode and ARP offload is activated
 - selftests create a dummy ARP_REQUEST packet and send it out
 - IP will detect the ARP_REQUEST packet and generate an ARP_REPLY 
packet
 - As MAC is in loopback mode then selftests will receive the ARP_REPLY 
packet
 - selftests logic will check if ARP_REPLY packet is correct (i.e. MAC 
address and packet type)

This way if this test fails it probably indicates that MAC address of IP 
is not correctly configured or that endianness of the IP was changed 
from default setting (which is LE).

By default the feature is off because user may not want to reply to 
ARP_REQUEST and I'm more using it as a diagnose facility. Let me know if 
you agree with this approach.

---
Thanks,
Jose Miguel Abreu


RE: [PATCH net-next 0/6] net: stmmac: Improvements for -next

2019-09-10 Thread Jose Abreu
From: Jose Abreu 
Date: Sep/10/2019, 15:41:21 (UTC+00:00)

> Misc patches for -next. It includes:
>  - Two fixes for features in -next only
>  - New features support for GMAC cores (which includes GMAC4 and GMAC5)

BTW, just for reference (and because I forgot to attach it earlier), 
this is the selftests output for GMAC5.10 after this patchset:

# ethtool -t ens4
The test result is PASS
The test extra info:
 1. MAC Loopback 0
 2. PHY Loopback 0
 3. MMC Counters 0
 4. EEE  -95
 5. Hash Filter MC   0
 6. Perfect Filter UC0
 7. MC Filter0
 8. UC Filter0
 9. Flow Control 0
10. RSS  -95
11. VLAN Filtering   0
12. Double VLAN Filtering0
13. Flexible RX Parser   0
14. SA Insertion (desc)  0
15. SA Replacement (desc)0
16. SA Insertion (reg)   0
17. SA Replacement (reg) 0
18. VLAN TX Insertion0
19. SVLAN TX Insertion   0
20. L3 DA Filtering  -95
21. L3 SA Filtering  -95
22. L4 DA TCP Filtering  -95
23. L4 SA TCP Filtering  -95
24. L4 DA UDP Filtering  -95
25. L4 SA UDP Filtering  -95
26. ARP Offload  0
27. Jumbo Frame  0
28. Multichannel Jumbo   0
29. Split Header -95

---
Thanks,
Jose Miguel Abreu


[PATCH net-next 2/6] net: stmmac: Add VLAN HASH filtering support in GMAC4+

2019-09-10 Thread Jose Abreu
Adds the support for VLAN HASH Filtering in GMAC4/5 cores.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h  | 11 
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 31 +++
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c  |  2 +-
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index 03301ffc0391..4dfa69850040 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -16,6 +16,8 @@
 #define GMAC_CONFIG0x
 #define GMAC_PACKET_FILTER 0x0008
 #define GMAC_HASH_TAB(x)   (0x10 + (x) * 4)
+#define GMAC_VLAN_TAG  0x0050
+#define GMAC_VLAN_HASH_TABLE   0x0058
 #define GMAC_RX_FLOW_CTRL  0x0090
 #define GMAC_QX_TX_FLOW_CTRL(x)(0x70 + x * 4)
 #define GMAC_TXQ_PRTY_MAP0 0x98
@@ -62,9 +64,18 @@
 #define GMAC_PACKET_FILTER_PM  BIT(4)
 #define GMAC_PACKET_FILTER_PCF BIT(7)
 #define GMAC_PACKET_FILTER_HPF BIT(10)
+#define GMAC_PACKET_FILTER_VTFEBIT(16)
 
 #define GMAC_MAX_PERFECT_ADDRESSES 128
 
+/* MAC VLAN */
+#define GMAC_VLAN_EDVLPBIT(26)
+#define GMAC_VLAN_VTHM BIT(25)
+#define GMAC_VLAN_DOVLTC   BIT(20)
+#define GMAC_VLAN_ESVL BIT(18)
+#define GMAC_VLAN_ETV  BIT(16)
+#define GMAC_VLAN_VID  GENMASK(15, 0)
+
 /* MAC RX Queue Enable */
 #define GMAC_RX_QUEUE_CLEAR(queue) ~(GENMASK(1, 0) << ((queue) * 2))
 #define GMAC_RX_AV_QUEUE_ENABLE(queue) BIT((queue) * 2)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 596311a80d1c..5b43a8df1536 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -731,6 +731,34 @@ static void dwmac4_set_mac_loopback(void __iomem *ioaddr, 
bool enable)
writel(value, ioaddr + GMAC_CONFIG);
 }
 
+static void dwmac4_update_vlan_hash(struct mac_device_info *hw, u32 hash,
+   bool is_double)
+{
+   void __iomem *ioaddr = hw->pcsr;
+
+   writel(hash, ioaddr + GMAC_VLAN_HASH_TABLE);
+
+   if (hash) {
+   u32 value = GMAC_VLAN_VTHM | GMAC_VLAN_ETV;
+   if (is_double) {
+   value |= GMAC_VLAN_EDVLP;
+   value |= GMAC_VLAN_ESVL;
+   value |= GMAC_VLAN_DOVLTC;
+   }
+
+   writel(value, ioaddr + GMAC_VLAN_TAG);
+   } else {
+   u32 value = readl(ioaddr + GMAC_VLAN_TAG);
+
+   value &= ~(GMAC_VLAN_VTHM | GMAC_VLAN_ETV);
+   value &= ~(GMAC_VLAN_EDVLP | GMAC_VLAN_ESVL);
+   value &= ~GMAC_VLAN_DOVLTC;
+   value &= ~GMAC_VLAN_VID;
+
+   writel(value, ioaddr + GMAC_VLAN_TAG);
+   }
+}
+
 const struct stmmac_ops dwmac4_ops = {
.core_init = dwmac4_core_init,
.set_mac = stmmac_set_mac,
@@ -761,6 +789,7 @@ const struct stmmac_ops dwmac4_ops = {
.debug = dwmac4_debug,
.set_filter = dwmac4_set_filter,
.set_mac_loopback = dwmac4_set_mac_loopback,
+   .update_vlan_hash = dwmac4_update_vlan_hash,
 };
 
 const struct stmmac_ops dwmac410_ops = {
@@ -793,6 +822,7 @@ const struct stmmac_ops dwmac410_ops = {
.debug = dwmac4_debug,
.set_filter = dwmac4_set_filter,
.set_mac_loopback = dwmac4_set_mac_loopback,
+   .update_vlan_hash = dwmac4_update_vlan_hash,
 };
 
 const struct stmmac_ops dwmac510_ops = {
@@ -830,6 +860,7 @@ const struct stmmac_ops dwmac510_ops = {
.rxp_config = dwmac5_rxp_config,
.flex_pps_config = dwmac5_flex_pps_config,
.set_mac_loopback = dwmac4_set_mac_loopback,
+   .update_vlan_hash = dwmac4_update_vlan_hash,
 };
 
 int dwmac4_setup(struct stmmac_priv *priv)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
index 3ed5508586ef..2456f421aac9 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
@@ -333,7 +333,7 @@ static void dwmac4_get_hw_feature(void __iomem *ioaddr,
dma_cap->mbps_10_100 = (hw_cap & GMAC_HW_FEAT_MIISEL);
dma_cap->mbps_1000 = (hw_cap & GMAC_HW_FEAT_GMIISEL) >> 1;
dma_cap->half_duplex = (hw_cap & GMAC_HW_FEAT_HDSEL) >> 2;
-   dma_cap->has

[PATCH net-next 1/6] net: stmmac: Prevent divide-by-zero

2019-09-10 Thread Jose Abreu
When RX Coalesce settings are set to all zero (which is a valid setting)
we will currently get a divide-by-zero error. Fix it.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 686b82068142..6e44013b20cc 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3418,7 +3418,9 @@ static inline void stmmac_rx_refill(struct stmmac_priv 
*priv, u32 queue)
stmmac_refill_desc3(priv, rx_q, p);
 
rx_q->rx_count_frames++;
-   rx_q->rx_count_frames %= priv->rx_coal_frames;
+   rx_q->rx_count_frames += priv->rx_coal_frames;
+   if (rx_q->rx_count_frames > priv->rx_coal_frames)
+   rx_q->rx_count_frames = 0;
use_rx_wd = priv->use_riwt && rx_q->rx_count_frames;
 
dma_wmb();
-- 
2.7.4



[PATCH net-next 4/6] net: stmmac: Add support for SA Insertion/Replacement in GMAC4+

2019-09-10 Thread Jose Abreu
Add the support for Source Address Insertion and Replacement in GMAC4
and GMAC5 cores. Two methods are supported: Descriptor based and
register based.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h   |  3 +++
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c  | 13 +
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c |  8 
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h |  1 +
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c   |  1 +
 5 files changed, 26 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index 4dfa69850040..fad121cbfe0e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -160,6 +160,8 @@ enum power_event {
 #define GMAC_DEBUG_RPESTS  BIT(0)
 
 /* MAC config */
+#define GMAC_CONFIG_SARC   GENMASK(30, 28)
+#define GMAC_CONFIG_SARC_SHIFT 28
 #define GMAC_CONFIG_IPCBIT(27)
 #define GMAC_CONFIG_2K BIT(22)
 #define GMAC_CONFIG_ACSBIT(20)
@@ -175,6 +177,7 @@ enum power_event {
 #define GMAC_CONFIG_RE BIT(0)
 
 /* MAC HW features0 bitmap */
+#define GMAC_HW_FEAT_SAVLANINS BIT(27)
 #define GMAC_HW_FEAT_ADDMACBIT(18)
 #define GMAC_HW_FEAT_RXCOESEL  BIT(16)
 #define GMAC_HW_FEAT_TXCOSEL   BIT(14)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 5b43a8df1536..73dbfd810fca 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -759,6 +759,16 @@ static void dwmac4_update_vlan_hash(struct mac_device_info 
*hw, u32 hash,
}
 }
 
+static void dwmac4_sarc_configure(void __iomem *ioaddr, int val)
+{
+   u32 value = readl(ioaddr + GMAC_CONFIG);
+
+   value &= ~GMAC_CONFIG_SARC;
+   value |= val << GMAC_CONFIG_SARC_SHIFT;
+
+   writel(value, ioaddr + GMAC_CONFIG);
+}
+
 const struct stmmac_ops dwmac4_ops = {
.core_init = dwmac4_core_init,
.set_mac = stmmac_set_mac,
@@ -790,6 +800,7 @@ const struct stmmac_ops dwmac4_ops = {
.set_filter = dwmac4_set_filter,
.set_mac_loopback = dwmac4_set_mac_loopback,
.update_vlan_hash = dwmac4_update_vlan_hash,
+   .sarc_configure = dwmac4_sarc_configure,
 };
 
 const struct stmmac_ops dwmac410_ops = {
@@ -823,6 +834,7 @@ const struct stmmac_ops dwmac410_ops = {
.set_filter = dwmac4_set_filter,
.set_mac_loopback = dwmac4_set_mac_loopback,
.update_vlan_hash = dwmac4_update_vlan_hash,
+   .sarc_configure = dwmac4_sarc_configure,
 };
 
 const struct stmmac_ops dwmac510_ops = {
@@ -861,6 +873,7 @@ const struct stmmac_ops dwmac510_ops = {
.flex_pps_config = dwmac5_flex_pps_config,
.set_mac_loopback = dwmac4_set_mac_loopback,
.update_vlan_hash = dwmac4_update_vlan_hash,
+   .sarc_configure = dwmac4_sarc_configure,
 };
 
 int dwmac4_setup(struct stmmac_priv *priv)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
index dbde23e7e169..8edc9f8787cc 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
@@ -443,6 +443,13 @@ static void dwmac4_clear(struct dma_desc *p)
p->des3 = 0;
 }
 
+static void dwmac4_set_sarc(struct dma_desc *p, u32 sarc_type)
+{
+   sarc_type <<= TDES3_SA_INSERT_CTRL_SHIFT;
+
+   p->des3 |= cpu_to_le32(sarc_type & TDES3_SA_INSERT_CTRL_MASK);
+}
+
 static int set_16kib_bfsize(int mtu)
 {
int ret = 0;
@@ -476,6 +483,7 @@ const struct stmmac_desc_ops dwmac4_desc_ops = {
.get_addr = dwmac4_get_addr,
.set_addr = dwmac4_set_addr,
.clear = dwmac4_clear,
+   .set_sarc = dwmac4_set_sarc,
 };
 
 const struct stmmac_mode_ops dwmac4_ring_mode_ops = {
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h
index f58191174287..6089d76a00d3 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h
@@ -32,6 +32,7 @@
 #define TDES3_HDR_LEN_SHIFT19
 #define TDES3_SLOT_NUMBER_MASK GENMASK(22, 19)
 #define TDES3_SA_INSERT_CTRL_MASK  GENMASK(25, 23)
+#define TDES3_SA_INSERT_CTRL_SHIFT 23
 #define TDES3_CRC_PAD_CTRL_MASKGENMASK(27, 26)
 
 /* TDES3 (write back format) */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c 
b/drivers/net/ethern

[PATCH net-next 5/6] net: stmmac: Add support for VLAN Insertion Offload in GMAC4+

2019-09-10 Thread Jose Abreu
Adds support for TX VLAN Offload using descriptors based features
available in GMAC4/5.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h   |  6 
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c  | 16 ++
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c | 35 ++
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h |  8 +
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c   |  1 +
 5 files changed, 66 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index fad121cbfe0e..e88dac1dd765 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -19,6 +19,7 @@
 #define GMAC_VLAN_TAG  0x0050
 #define GMAC_VLAN_HASH_TABLE   0x0058
 #define GMAC_RX_FLOW_CTRL  0x0090
+#define GMAC_VLAN_INCL 0x0060
 #define GMAC_QX_TX_FLOW_CTRL(x)(0x70 + x * 4)
 #define GMAC_TXQ_PRTY_MAP0 0x98
 #define GMAC_TXQ_PRTY_MAP1 0x9C
@@ -75,6 +76,10 @@
 #define GMAC_VLAN_ESVL BIT(18)
 #define GMAC_VLAN_ETV  BIT(16)
 #define GMAC_VLAN_VID  GENMASK(15, 0)
+#define GMAC_VLAN_VLTI BIT(20)
+#define GMAC_VLAN_CSVL BIT(19)
+#define GMAC_VLAN_VLC  GENMASK(17, 16)
+#define GMAC_VLAN_VLC_SHIFT16
 
 /* MAC RX Queue Enable */
 #define GMAC_RX_QUEUE_CLEAR(queue) ~(GENMASK(1, 0) << ((queue) * 2))
@@ -212,6 +217,7 @@ enum power_event {
 #define GMAC_HW_FEAT_FRPES GENMASK(14, 13)
 #define GMAC_HW_FEAT_FRPBS GENMASK(12, 11)
 #define GMAC_HW_FEAT_FRPSELBIT(10)
+#define GMAC_HW_FEAT_DVLAN BIT(5)
 
 /* MAC HW ADDR regs */
 #define GMAC_HI_DCSGENMASK(18, 16)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 73dbfd810fca..a99effe61325 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -769,6 +769,19 @@ static void dwmac4_sarc_configure(void __iomem *ioaddr, 
int val)
writel(value, ioaddr + GMAC_CONFIG);
 }
 
+static void dwmac4_enable_vlan(struct mac_device_info *hw, u32 type)
+{
+   void __iomem *ioaddr = hw->pcsr;
+   u32 value;
+
+   value = readl(ioaddr + GMAC_VLAN_INCL);
+   value |= GMAC_VLAN_VLTI;
+   value |= GMAC_VLAN_CSVL; /* Only use SVLAN */
+   value &= ~GMAC_VLAN_VLC;
+   value |= (type << GMAC_VLAN_VLC_SHIFT) & GMAC_VLAN_VLC;
+   writel(value, ioaddr + GMAC_VLAN_INCL);
+}
+
 const struct stmmac_ops dwmac4_ops = {
.core_init = dwmac4_core_init,
.set_mac = stmmac_set_mac,
@@ -801,6 +814,7 @@ const struct stmmac_ops dwmac4_ops = {
.set_mac_loopback = dwmac4_set_mac_loopback,
.update_vlan_hash = dwmac4_update_vlan_hash,
.sarc_configure = dwmac4_sarc_configure,
+   .enable_vlan = dwmac4_enable_vlan,
 };
 
 const struct stmmac_ops dwmac410_ops = {
@@ -835,6 +849,7 @@ const struct stmmac_ops dwmac410_ops = {
.set_mac_loopback = dwmac4_set_mac_loopback,
.update_vlan_hash = dwmac4_update_vlan_hash,
.sarc_configure = dwmac4_sarc_configure,
+   .enable_vlan = dwmac4_enable_vlan,
 };
 
 const struct stmmac_ops dwmac510_ops = {
@@ -874,6 +889,7 @@ const struct stmmac_ops dwmac510_ops = {
.set_mac_loopback = dwmac4_set_mac_loopback,
.update_vlan_hash = dwmac4_update_vlan_hash,
.sarc_configure = dwmac4_sarc_configure,
+   .enable_vlan = dwmac4_enable_vlan,
 };
 
 int dwmac4_setup(struct stmmac_priv *priv)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
index 8edc9f8787cc..15eb1abba91d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
@@ -459,6 +459,39 @@ static int set_16kib_bfsize(int mtu)
return ret;
 }
 
+static void dwmac4_set_vlan_tag(struct dma_desc *p, u16 tag, u16 inner_tag,
+   u32 inner_type)
+{
+   p->des0 = 0;
+   p->des1 = 0;
+   p->des2 = 0;
+   p->des3 = 0;
+
+   /* Inner VLAN */
+   if (inner_type) {
+   u32 des = inner_tag << TDES2_IVT_SHIFT;
+
+   des &= TDES2_IVT_MASK;
+   p->des2 = cpu_to_le32(des);
+
+   des = inner_type << TDES3_IVTIR_SHIFT;
+   des &= TDES3_IVTIR_MASK;
+   p->des3 = cpu_to_le32(d

[PATCH net-next 0/6] net: stmmac: Improvements for -next

2019-09-10 Thread Jose Abreu
Misc patches for -next. It includes:
 - Two fixes for features in -next only
 - New features support for GMAC cores (which includes GMAC4 and GMAC5)

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---

Jose Abreu (6):
  net: stmmac: Prevent divide-by-zero
  net: stmmac: Add VLAN HASH filtering support in GMAC4+
  net: stmmac: xgmac: Reinitialize correctly a variable
  net: stmmac: Add support for SA Insertion/Replacement in GMAC4+
  net: stmmac: Add support for VLAN Insertion Offload in GMAC4+
  net: stmmac: ARP Offload for GMAC4+ Cores

 drivers/net/ethernet/stmicro/stmmac/dwmac4.h   | 23 +++
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c  | 79 ++
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c | 43 
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h |  9 +++
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c   |  5 +-
 .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c|  2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |  4 +-
 7 files changed, 162 insertions(+), 3 deletions(-)

-- 
2.7.4



[PATCH net-next 6/6] net: stmmac: ARP Offload for GMAC4+ Cores

2019-09-10 Thread Jose Abreu
Implement the ARP Offload feature in GMAC4 and GMAC5 cores.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h  |  3 +++
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 19 +++
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c  |  1 +
 3 files changed, 23 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index e88dac1dd765..89a3420eba42 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -40,6 +40,7 @@
 #define GMAC_HW_FEATURE3   0x0128
 #define GMAC_MDIO_ADDR 0x0200
 #define GMAC_MDIO_DATA 0x0204
+#define GMAC_ARP_ADDR  0x0210
 #define GMAC_ADDR_HIGH(reg)(0x300 + reg * 8)
 #define GMAC_ADDR_LOW(reg) (0x304 + reg * 8)
 
@@ -165,6 +166,7 @@ enum power_event {
 #define GMAC_DEBUG_RPESTS  BIT(0)
 
 /* MAC config */
+#define GMAC_CONFIG_ARPEN  BIT(31)
 #define GMAC_CONFIG_SARC   GENMASK(30, 28)
 #define GMAC_CONFIG_SARC_SHIFT 28
 #define GMAC_CONFIG_IPCBIT(27)
@@ -188,6 +190,7 @@ enum power_event {
 #define GMAC_HW_FEAT_TXCOSEL   BIT(14)
 #define GMAC_HW_FEAT_EEESELBIT(13)
 #define GMAC_HW_FEAT_TSSEL BIT(12)
+#define GMAC_HW_FEAT_ARPOFFSEL BIT(9)
 #define GMAC_HW_FEAT_MMCSELBIT(8)
 #define GMAC_HW_FEAT_MGKSELBIT(7)
 #define GMAC_HW_FEAT_RWKSELBIT(6)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index a99effe61325..9b4b5f69fc02 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -782,6 +782,22 @@ static void dwmac4_enable_vlan(struct mac_device_info *hw, 
u32 type)
writel(value, ioaddr + GMAC_VLAN_INCL);
 }
 
+static void dwmac4_set_arp_offload(struct mac_device_info *hw, bool en,
+  u32 addr)
+{
+   void __iomem *ioaddr = hw->pcsr;
+   u32 value;
+
+   writel(addr, ioaddr + GMAC_ARP_ADDR);
+
+   value = readl(ioaddr + GMAC_CONFIG);
+   if (en)
+   value |= GMAC_CONFIG_ARPEN;
+   else
+   value &= ~GMAC_CONFIG_ARPEN;
+   writel(value, ioaddr + GMAC_CONFIG);
+}
+
 const struct stmmac_ops dwmac4_ops = {
.core_init = dwmac4_core_init,
.set_mac = stmmac_set_mac,
@@ -815,6 +831,7 @@ const struct stmmac_ops dwmac4_ops = {
.update_vlan_hash = dwmac4_update_vlan_hash,
.sarc_configure = dwmac4_sarc_configure,
.enable_vlan = dwmac4_enable_vlan,
+   .set_arp_offload = dwmac4_set_arp_offload,
 };
 
 const struct stmmac_ops dwmac410_ops = {
@@ -850,6 +867,7 @@ const struct stmmac_ops dwmac410_ops = {
.update_vlan_hash = dwmac4_update_vlan_hash,
.sarc_configure = dwmac4_sarc_configure,
.enable_vlan = dwmac4_enable_vlan,
+   .set_arp_offload = dwmac4_set_arp_offload,
 };
 
 const struct stmmac_ops dwmac510_ops = {
@@ -890,6 +908,7 @@ const struct stmmac_ops dwmac510_ops = {
.update_vlan_hash = dwmac4_update_vlan_hash,
.sarc_configure = dwmac4_sarc_configure,
.enable_vlan = dwmac4_enable_vlan,
+   .set_arp_offload = dwmac4_set_arp_offload,
 };
 
 int dwmac4_setup(struct stmmac_priv *priv)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
index f3ca0236450d..68c157979b94 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
@@ -349,6 +349,7 @@ static void dwmac4_get_hw_feature(void __iomem *ioaddr,
dma_cap->tx_coe = (hw_cap & GMAC_HW_FEAT_TXCOSEL) >> 14;
dma_cap->rx_coe =  (hw_cap & GMAC_HW_FEAT_RXCOESEL) >> 16;
dma_cap->vlins = (hw_cap & GMAC_HW_FEAT_SAVLANINS) >> 27;
+   dma_cap->arpoffsel = (hw_cap & GMAC_HW_FEAT_ARPOFFSEL) >> 9;
 
/* MAC HW feature1 */
hw_cap = readl(ioaddr + GMAC_HW_FEATURE1);
-- 
2.7.4



[PATCH net-next 3/6] net: stmmac: xgmac: Reinitialize correctly a variable

2019-09-10 Thread Jose Abreu
'value' was being or'ed with a value from another register. This is a
typo and could cause new written value to be wrong. Fix it.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 78ac659da279..d5173dd02a71 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -568,7 +568,7 @@ static void dwxgmac2_update_vlan_hash(struct 
mac_device_info *hw, u32 hash,
 
writel(value, ioaddr + XGMAC_PACKET_FILTER);
 
-   value |= XGMAC_VLAN_VTHM | XGMAC_VLAN_ETV;
+   value = XGMAC_VLAN_VTHM | XGMAC_VLAN_ETV;
if (is_double) {
value |= XGMAC_VLAN_EDVLP;
value |= XGMAC_VLAN_ESVL;
-- 
2.7.4



[PATCH net-next] net: stmmac: pci: Add HAPS support using GMAC5

2019-09-09 Thread Jose Abreu
Add the support for Synopsys HAPS board that uses GMAC5.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 71 
 1 file changed, 71 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
index 20906287b6d4..292045f4581f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
@@ -375,6 +375,75 @@ static const struct stmmac_pci_info quark_pci_info = {
.setup = quark_default_data,
 };
 
+static int snps_gmac5_default_data(struct pci_dev *pdev,
+  struct plat_stmmacenet_data *plat)
+{
+   int i;
+
+   plat->clk_csr = 5;
+   plat->has_gmac4 = 1;
+   plat->force_sf_dma_mode = 1;
+   plat->tso_en = 1;
+   plat->pmt = 1;
+
+   plat->mdio_bus_data->phy_mask = 0;
+
+   /* Set default value for multicast hash bins */
+   plat->multicast_filter_bins = HASH_TABLE_SIZE;
+
+   /* Set default value for unicast filter entries */
+   plat->unicast_filter_entries = 1;
+
+   /* Set the maxmtu to a default of JUMBO_LEN */
+   plat->maxmtu = JUMBO_LEN;
+
+   /* Set default number of RX and TX queues to use */
+   plat->tx_queues_to_use = 4;
+   plat->rx_queues_to_use = 4;
+
+   plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WRR;
+   for (i = 0; i < plat->tx_queues_to_use; i++) {
+   plat->tx_queues_cfg[i].use_prio = false;
+   plat->tx_queues_cfg[i].mode_to_use = MTL_QUEUE_DCB;
+   plat->tx_queues_cfg[i].weight = 25;
+   }
+
+   plat->rx_sched_algorithm = MTL_RX_ALGORITHM_SP;
+   for (i = 0; i < plat->rx_queues_to_use; i++) {
+   plat->rx_queues_cfg[i].use_prio = false;
+   plat->rx_queues_cfg[i].mode_to_use = MTL_QUEUE_DCB;
+   plat->rx_queues_cfg[i].pkt_route = 0x0;
+   plat->rx_queues_cfg[i].chan = i;
+   }
+
+   plat->bus_id = 1;
+   plat->phy_addr = -1;
+   plat->interface = PHY_INTERFACE_MODE_GMII;
+
+   plat->dma_cfg->pbl = 32;
+   plat->dma_cfg->pblx8 = true;
+
+   /* Axi Configuration */
+   plat->axi = devm_kzalloc(>dev, sizeof(*plat->axi), GFP_KERNEL);
+   if (!plat->axi)
+   return -ENOMEM;
+
+   plat->axi->axi_wr_osr_lmt = 31;
+   plat->axi->axi_rd_osr_lmt = 31;
+
+   plat->axi->axi_fb = false;
+   plat->axi->axi_blen[0] = 4;
+   plat->axi->axi_blen[1] = 8;
+   plat->axi->axi_blen[2] = 16;
+   plat->axi->axi_blen[3] = 32;
+
+   return 0;
+}
+
+static const struct stmmac_pci_info snps_gmac5_pci_info = {
+   .setup = snps_gmac5_default_data,
+};
+
 /**
  * stmmac_pci_probe
  *
@@ -518,6 +587,7 @@ static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_pci_suspend, 
stmmac_pci_resume);
 #define STMMAC_EHL_RGMII1G_ID  0x4b30
 #define STMMAC_EHL_SGMII1G_ID  0x4b31
 #define STMMAC_TGL_SGMII1G_ID  0xa0ac
+#define STMMAC_GMAC5_ID0x7102
 
 #define STMMAC_DEVICE(vendor_id, dev_id, info) {   \
PCI_VDEVICE(vendor_id, dev_id), \
@@ -531,6 +601,7 @@ static const struct pci_device_id stmmac_id_table[] = {
STMMAC_DEVICE(INTEL, STMMAC_EHL_RGMII1G_ID, ehl_rgmii1g_pci_info),
STMMAC_DEVICE(INTEL, STMMAC_EHL_SGMII1G_ID, ehl_sgmii1g_pci_info),
STMMAC_DEVICE(INTEL, STMMAC_TGL_SGMII1G_ID, tgl_sgmii1g_pci_info),
+   STMMAC_DEVICE(SYNOPSYS, STMMAC_GMAC5_ID, snps_gmac5_pci_info),
{}
 };
 
-- 
2.7.4



RE: [PATCH v3 net-next] net: stmmac: Add support for MDIO interrupts

2019-09-06 Thread Jose Abreu
From: Andrew Lunn 
Date: Sep/06/2019, 15:24:46 (UTC+00:00)

> On Fri, Sep 06, 2019 at 01:31:14PM +0000, Jose Abreu wrote:
> > From: Voon Weifeng 
> > Date: Sep/05/2019, 13:05:30 (UTC+00:00)
> > 
> > > DW EQoS v5.xx controllers added capability for interrupt generation
> > > when MDIO interface is done (GMII Busy bit is cleared).
> > > This patch adds support for this interrupt on supported HW to avoid
> > > polling on GMII Busy bit.
> > 
> > Better leave the enabling of this optional because the support for it is 
> > also optional depending on the IP HW configuration.
> 
> Hi Jose
> 
> If there a register which indicates if this feature is part of the IP?

Yes. That would be SMASEL which is Bit 5 of register MAC_HW_Feature0.

---
Thanks,
Jose Miguel Abreu


RE: [PATCH v3 net-next] net: stmmac: Add support for MDIO interrupts

2019-09-06 Thread Jose Abreu
From: Voon Weifeng 
Date: Sep/05/2019, 13:05:30 (UTC+00:00)

> DW EQoS v5.xx controllers added capability for interrupt generation
> when MDIO interface is done (GMII Busy bit is cleared).
> This patch adds support for this interrupt on supported HW to avoid
> polling on GMII Busy bit.

Better leave the enabling of this optional because the support for it is 
also optional depending on the IP HW configuration.

---
Thanks,
Jose Miguel Abreu


RE: [RFC net-next v2 4/5] net: phy: introducing support for DWC xPCS logics for EHL & TGL

2019-09-06 Thread Jose Abreu
From: Ong Boon Leong 
Date: Aug/28/2019, 18:47:21 (UTC+00:00)

> xPCS is DWC Ethernet Physical Coding Sublayer that can be integrated with
> Ethernet MAC controller and acts as converter between GMII and SGMII. 

You have to be careful here because xPCS supports much more than these 
interfaces and speeds.

I would implement this thinking about the future integrations and 
leaving margin for more speeds.

As for this being a converter I'm not sure about the implementation 
logic because sometimes you can have a setup like:

MAC <-> xPCS <-> SERDES <-> SFP

SERDES and SFP may not require configuration nor even have MDIO access 
so in my view the "PHY" would then be the xPCS, no ?

---
Thanks,
Jose Miguel Abreu


[PATCH net-next 5/5] net: stmmac: Limit max speeds of XGMAC if asked to

2019-09-06 Thread Jose Abreu
We may have some SoCs that can't achieve XGMAC max speed. Limit it if
asked to.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 25 +++
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index c3baca9f587b..686b82068142 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -831,15 +831,22 @@ static void stmmac_validate(struct phylink_config *config,
phylink_set(mask, 1000baseT_Full);
phylink_set(mask, 1000baseX_Full);
} else if (priv->plat->has_xgmac) {
-   phylink_set(mac_supported, 2500baseT_Full);
-   phylink_set(mac_supported, 5000baseT_Full);
-   phylink_set(mac_supported, 1baseSR_Full);
-   phylink_set(mac_supported, 1baseLR_Full);
-   phylink_set(mac_supported, 1baseER_Full);
-   phylink_set(mac_supported, 1baseLRM_Full);
-   phylink_set(mac_supported, 1baseT_Full);
-   phylink_set(mac_supported, 1baseKX4_Full);
-   phylink_set(mac_supported, 1baseKR_Full);
+   if (!max_speed || (max_speed >= 2500)) {
+   phylink_set(mac_supported, 2500baseT_Full);
+   phylink_set(mac_supported, 2500baseX_Full);
+   }
+   if (!max_speed || (max_speed >= 5000)) {
+   phylink_set(mac_supported, 5000baseT_Full);
+   }
+   if (!max_speed || (max_speed >= 1)) {
+   phylink_set(mac_supported, 1baseSR_Full);
+   phylink_set(mac_supported, 1baseLR_Full);
+   phylink_set(mac_supported, 1baseER_Full);
+   phylink_set(mac_supported, 1baseLRM_Full);
+   phylink_set(mac_supported, 1baseT_Full);
+   phylink_set(mac_supported, 1baseKX4_Full);
+   phylink_set(mac_supported, 1baseKR_Full);
+   }
}
 
/* Half-Duplex can only work with single queue */
-- 
2.7.4



[PATCH net-next 2/5] net: stmmac: selftests: Set RX tail pointer in Flow Control test

2019-09-06 Thread Jose Abreu
We need to set the RX tail pointer so that RX engine starts working
again after finishing the Flow Control test.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index dce34c081a1e..2943943bec43 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -722,8 +722,14 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv)
 
for (i = 0; i < rx_cnt; i++) {
struct stmmac_channel *ch = >channel[i];
+   u32 tail;
 
+   tail = priv->rx_queue[i].dma_rx_phy +
+   (DMA_RX_SIZE * sizeof(struct dma_desc));
+
+   stmmac_set_rx_tail_ptr(priv, priv->ioaddr, tail, i);
stmmac_start_rx(priv, priv->ioaddr, i);
+
local_bh_disable();
napi_reschedule(>rx_napi);
local_bh_enable();
-- 
2.7.4



[PATCH net-next 0/5] net: stmmac: Improvements and fixes for -next

2019-09-06 Thread Jose Abreu
Improvements and fixes for recently introduced features. All for -next tree.
More info in commit logs.

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---

Jose Abreu (5):
  net: stmmac: selftests: Add missing checks for support of SA
  net: stmmac: selftests: Set RX tail pointer in Flow Control test
  net: stmmac: dwmac4: Enable RX Jumbo frame support
  net: stmmac: selftests: Add Split Header test
  net: stmmac: Limit max speeds of XGMAC if asked to

 drivers/net/ethernet/stmicro/stmmac/dwmac4.h   |  3 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c  |  6 ---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 25 +
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 60 ++
 4 files changed, 78 insertions(+), 16 deletions(-)

-- 
2.7.4



[PATCH net-next 1/5] net: stmmac: selftests: Add missing checks for support of SA

2019-09-06 Thread Jose Abreu
Add checks for support of Source Address Insertion/Replacement before
running the test.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 305d24935cf4..dce34c081a1e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -1057,6 +1057,9 @@ static int stmmac_test_desc_sai(struct stmmac_priv *priv)
struct stmmac_packet_attrs attr = { };
int ret;
 
+   if (!priv->dma_cap.vlins)
+   return -EOPNOTSUPP;
+
attr.remove_sa = true;
attr.sarc = true;
attr.src = src;
@@ -1076,6 +1079,9 @@ static int stmmac_test_desc_sar(struct stmmac_priv *priv)
struct stmmac_packet_attrs attr = { };
int ret;
 
+   if (!priv->dma_cap.vlins)
+   return -EOPNOTSUPP;
+
attr.sarc = true;
attr.src = src;
attr.dst = priv->dev->dev_addr;
@@ -1094,6 +1100,9 @@ static int stmmac_test_reg_sai(struct stmmac_priv *priv)
struct stmmac_packet_attrs attr = { };
int ret;
 
+   if (!priv->dma_cap.vlins)
+   return -EOPNOTSUPP;
+
attr.remove_sa = true;
attr.sarc = true;
attr.src = src;
@@ -1114,6 +1123,9 @@ static int stmmac_test_reg_sar(struct stmmac_priv *priv)
struct stmmac_packet_attrs attr = { };
int ret;
 
+   if (!priv->dma_cap.vlins)
+   return -EOPNOTSUPP;
+
attr.sarc = true;
attr.src = src;
attr.dst = priv->dev->dev_addr;
-- 
2.7.4



[PATCH net-next 3/5] net: stmmac: dwmac4: Enable RX Jumbo frame support

2019-09-06 Thread Jose Abreu
We are already doing it by default in the TX path so we can also enable
Jumbo Frame support in the RX path independently of MTU value.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h  | 3 ++-
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 6 --
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index 2ed11a581d80..03301ffc0391 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -352,7 +352,8 @@ enum power_event {
 
 /* Default operating mode of the MAC */
 #define GMAC_CORE_INIT (GMAC_CONFIG_JD | GMAC_CONFIG_PS | \
-   GMAC_CONFIG_BE | GMAC_CONFIG_DCRS)
+   GMAC_CONFIG_BE | GMAC_CONFIG_DCRS | \
+   GMAC_CONFIG_JE)
 
 /* To dump the core regs excluding  the Address Registers */
 #defineGMAC_REG_NUM132
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index fc9954e4a772..596311a80d1c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -25,15 +25,9 @@ static void dwmac4_core_init(struct mac_device_info *hw,
 {
void __iomem *ioaddr = hw->pcsr;
u32 value = readl(ioaddr + GMAC_CONFIG);
-   int mtu = dev->mtu;
 
value |= GMAC_CORE_INIT;
 
-   if (mtu > 1500)
-   value |= GMAC_CONFIG_2K;
-   if (mtu > 2000)
-   value |= GMAC_CONFIG_JE;
-
if (hw->ps) {
value |= GMAC_CONFIG_TE;
 
-- 
2.7.4



[PATCH net-next 4/5] net: stmmac: selftests: Add Split Header test

2019-09-06 Thread Jose Abreu
Add a test to validate that Split Header feature is working correctly.
It works by using the rececently introduced counter that increments each
time a packet with split header is received.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 42 ++
 1 file changed, 42 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 2943943bec43..c56e89e1ae56 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -1603,6 +1603,44 @@ static int stmmac_test_mjumbo(struct stmmac_priv *priv)
return 0;
 }
 
+static int stmmac_test_sph(struct stmmac_priv *priv)
+{
+   unsigned long cnt_end, cnt_start = priv->xstats.rx_split_hdr_pkt_n;
+   struct stmmac_packet_attrs attr = { };
+   int ret;
+
+   if (!priv->sph)
+   return -EOPNOTSUPP;
+
+   /* Check for UDP first */
+   attr.dst = priv->dev->dev_addr;
+   attr.tcp = false;
+
+   ret = __stmmac_test_loopback(priv, );
+   if (ret)
+   return ret;
+
+   cnt_end = priv->xstats.rx_split_hdr_pkt_n;
+   if (cnt_end <= cnt_start)
+   return -EINVAL;
+
+   /* Check for TCP now */
+   cnt_start = cnt_end;
+
+   attr.dst = priv->dev->dev_addr;
+   attr.tcp = true;
+
+   ret = __stmmac_test_loopback(priv, );
+   if (ret)
+   return ret;
+
+   cnt_end = priv->xstats.rx_split_hdr_pkt_n;
+   if (cnt_end <= cnt_start)
+   return -EINVAL;
+
+   return 0;
+}
+
 #define STMMAC_LOOPBACK_NONE   0
 #define STMMAC_LOOPBACK_MAC1
 #define STMMAC_LOOPBACK_PHY2
@@ -1724,6 +1762,10 @@ static const struct stmmac_test {
.name = "Multichannel Jumbo  ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_mjumbo,
+   }, {
+   .name = "Split Header",
+   .lb = STMMAC_LOOPBACK_PHY,
+   .fn = stmmac_test_sph,
},
 };
 
-- 
2.7.4



[PATCH net-next] net: phy: Do not check Link status when loopback is enabled

2019-09-05 Thread Jose Abreu
While running stmmac selftests I found that in my 1G setup some tests
were failling when running with PHY loopback enabled.

It looks like when loopback is enabled the PHY will report that Link is
down even though there is a valid connection.

As in loopback mode the data will not be sent anywhere we can bypass the
logic of checking if Link is valid thus saving unecessary reads.

Signed-off-by: Jose Abreu 

---
Cc: Andrew Lunn 
Cc: Florian Fainelli 
Cc: Heiner Kallweit 
Cc: "David S. Miller" 
Cc: net...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/phy/phy.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 35d29a823af8..7c92afd36bbe 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -525,6 +525,12 @@ static int phy_check_link_status(struct phy_device *phydev)
 
WARN_ON(!mutex_is_locked(>lock));
 
+   /* Keep previous state if loopback is enabled because some PHYs
+* report that Link is Down when loopback is enabled.
+*/
+   if (phydev->loopback_enabled)
+   return 0;
+
err = phy_read_status(phydev);
if (err)
return err;
-- 
2.7.4



[PATCH v2 net-next 12/13] net: stmmac: xgmac: Enable RX Jumbo frame support

2019-09-04 Thread Jose Abreu
We are already doing it by default in the TX path so we can also enable
Jumbo Frame support in the RX path independently of MTU value.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h  |  3 ++-
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 11 ---
 2 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index f942ac975c29..5923ca62d793 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -44,7 +44,8 @@
 #define XGMAC_CONFIG_CST   BIT(2)
 #define XGMAC_CONFIG_ACS   BIT(1)
 #define XGMAC_CONFIG_REBIT(0)
-#define XGMAC_CORE_INIT_RX 0
+#define XGMAC_CORE_INIT_RX (XGMAC_CONFIG_GPSLCE | XGMAC_CONFIG_WD 
| \
+(XGMAC_JUMBO_LEN << 
XGMAC_CONFIG_GPSL_SHIFT))
 #define XGMAC_PACKET_FILTER0x0008
 #define XGMAC_FILTER_RABIT(31)
 #define XGMAC_FILTER_IPFE  BIT(20)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 36262ef8b70a..78ac659da279 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -15,7 +15,6 @@ static void dwxgmac2_core_init(struct mac_device_info *hw,
   struct net_device *dev)
 {
void __iomem *ioaddr = hw->pcsr;
-   int mtu = dev->mtu;
u32 tx, rx;
 
tx = readl(ioaddr + XGMAC_TX_CONFIG);
@@ -24,16 +23,6 @@ static void dwxgmac2_core_init(struct mac_device_info *hw,
tx |= XGMAC_CORE_INIT_TX;
rx |= XGMAC_CORE_INIT_RX;
 
-   if (mtu >= 9000) {
-   rx |= XGMAC_CONFIG_GPSLCE;
-   rx |= XGMAC_JUMBO_LEN << XGMAC_CONFIG_GPSL_SHIFT;
-   rx |= XGMAC_CONFIG_WD;
-   } else if (mtu > 2000) {
-   rx |= XGMAC_CONFIG_JE;
-   } else if (mtu > 1500) {
-   rx |= XGMAC_CONFIG_S2KP;
-   }
-
if (hw->ps) {
tx |= XGMAC_CONFIG_TE;
tx &= ~hw->link.speed_mask;
-- 
2.7.4



[PATCH v2 net-next 08/13] net: stmmac: Only consider RX error when HW Timestamping is not enabled

2019-09-04 Thread Jose Abreu
Only consider that we have an error when HW Timestamping is not enabled
as this can give false positives due to the fact the RX Timestamping in
XGMAC and GMAC cores comes from context descriptors.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index c59c232aca64..5271c6129f0e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3511,9 +3511,10 @@ static int stmmac_rx(struct stmmac_priv *priv, int 
limit, u32 queue)
>xstats, rx_q->dma_erx + entry);
if (unlikely(status == discard_frame)) {
page_pool_recycle_direct(rx_q->page_pool, buf->page);
-   priv->dev->stats.rx_errors++;
buf->page = NULL;
error = 1;
+   if (!priv->hwts_rx_en)
+   priv->dev->stats.rx_errors++;
}
 
if (unlikely(error && (status & rx_not_ls)))
-- 
2.7.4



[PATCH v2 net-next 09/13] net: stmmac: ethtool: Let user configure TX coalesce without RIWT

2019-09-04 Thread Jose Abreu
When RX Watchdog is disabled its currently not possible to configure TX
coalesce settings. Let user configure it anyway.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c| 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index 1c450105e5a6..1a768837ca72 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -746,8 +746,15 @@ static int stmmac_set_coalesce(struct net_device *dev,
(ec->tx_max_coalesced_frames_high) || (ec->rate_sample_interval))
return -EOPNOTSUPP;
 
-   if (ec->rx_coalesce_usecs == 0)
-   return -EINVAL;
+   if (priv->use_riwt && (ec->rx_coalesce_usecs > 0)) {
+   rx_riwt = stmmac_usec2riwt(ec->rx_coalesce_usecs, priv);
+
+   if ((rx_riwt > MAX_DMA_RIWT) || (rx_riwt < MIN_DMA_RIWT))
+   return -EINVAL;
+
+   priv->rx_riwt = rx_riwt;
+   stmmac_rx_watchdog(priv, priv->ioaddr, priv->rx_riwt, rx_cnt);
+   }
 
if ((ec->tx_coalesce_usecs == 0) &&
(ec->tx_max_coalesced_frames == 0))
@@ -757,20 +764,10 @@ static int stmmac_set_coalesce(struct net_device *dev,
(ec->tx_max_coalesced_frames > STMMAC_TX_MAX_FRAMES))
return -EINVAL;
 
-   rx_riwt = stmmac_usec2riwt(ec->rx_coalesce_usecs, priv);
-
-   if ((rx_riwt > MAX_DMA_RIWT) || (rx_riwt < MIN_DMA_RIWT))
-   return -EINVAL;
-   else if (!priv->use_riwt)
-   return -EOPNOTSUPP;
-
/* Only copy relevant parameters, ignore all others. */
priv->tx_coal_frames = ec->tx_max_coalesced_frames;
priv->tx_coal_timer = ec->tx_coalesce_usecs;
priv->rx_coal_frames = ec->rx_max_coalesced_frames;
-   priv->rx_riwt = rx_riwt;
-   stmmac_rx_watchdog(priv, priv->ioaddr, priv->rx_riwt, rx_cnt);
-
return 0;
 }
 
-- 
2.7.4



[PATCH v2 net-next 04/13] net: stmmac: Implement L3/L4 Filters using TC Flower

2019-09-04 Thread Jose Abreu
Implement filters for Layer 3 and Layer 4 using TC Flower API. Add the
corresponding callbacks in XGMAC core.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/common.h   |   1 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h |  30 +++
 .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c| 177 +++
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c |   1 +
 drivers/net/ethernet/stmicro/stmmac/hwif.h |  16 ++
 drivers/net/ethernet/stmicro/stmmac/stmmac.h   |  12 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |   9 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c| 244 +
 8 files changed, 488 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index 49aa56ca09cc..19538057c24e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -360,6 +360,7 @@ struct dma_features {
unsigned int sphen;
unsigned int vlins;
unsigned int dvlan;
+   unsigned int l3l4fnum;
 };
 
 /* GMAC TX FIFO is 8K, Rx FIFO is 16K */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index 7357b8bdc128..f942ac975c29 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -47,6 +47,7 @@
 #define XGMAC_CORE_INIT_RX 0
 #define XGMAC_PACKET_FILTER0x0008
 #define XGMAC_FILTER_RABIT(31)
+#define XGMAC_FILTER_IPFE  BIT(20)
 #define XGMAC_FILTER_VTFE  BIT(16)
 #define XGMAC_FILTER_HPF   BIT(10)
 #define XGMAC_FILTER_PCF   BIT(7)
@@ -119,6 +120,7 @@
 #define XGMAC_HWFEAT_VLHASHBIT(4)
 #define XGMAC_HWFEAT_GMIISEL   BIT(1)
 #define XGMAC_HW_FEATURE1  0x0120
+#define XGMAC_HWFEAT_L3L4FNUM  GENMASK(30, 27)
 #define XGMAC_HWFEAT_RSSEN BIT(20)
 #define XGMAC_HWFEAT_TSOEN BIT(18)
 #define XGMAC_HWFEAT_SPHEN BIT(17)
@@ -150,6 +152,34 @@
 #define XGMAC_DCS  GENMASK(19, 16)
 #define XGMAC_DCS_SHIFT16
 #define XGMAC_ADDRx_LOW(x) (0x0304 + (x) * 0x8)
+#define XGMAC_L3L4_ADDR_CTRL   0x0c00
+#define XGMAC_IDDR GENMASK(15, 8)
+#define XGMAC_IDDR_SHIFT   8
+#define XGMAC_IDDR_FNUM4
+#define XGMAC_TT   BIT(1)
+#define XGMAC_XB   BIT(0)
+#define XGMAC_L3L4_DATA0x0c04
+#define XGMAC_L3L4_CTRL0x0
+#define XGMAC_L4DPIM0  BIT(21)
+#define XGMAC_L4DPM0   BIT(20)
+#define XGMAC_L4SPIM0  BIT(19)
+#define XGMAC_L4SPM0   BIT(18)
+#define XGMAC_L4PEN0   BIT(16)
+#define XGMAC_L3HDBM0  GENMASK(15, 11)
+#define XGMAC_L3HSBM0  GENMASK(10, 6)
+#define XGMAC_L3DAIM0  BIT(5)
+#define XGMAC_L3DAM0   BIT(4)
+#define XGMAC_L3SAIM0  BIT(3)
+#define XGMAC_L3SAM0   BIT(2)
+#define XGMAC_L3PEN0   BIT(0)
+#define XGMAC_L4_ADDR  0x1
+#define XGMAC_L4DP0GENMASK(31, 16)
+#define XGMAC_L4DP0_SHIFT  16
+#define XGMAC_L4SP0GENMASK(15, 0)
+#define XGMAC_L3_ADDR0 0x4
+#define XGMAC_L3_ADDR1 0x5
+#define XGMAC_L3_ADDR2 0x6
+#define XMGAC_L3_ADDR3 0x7
 #define XGMAC_ARP_ADDR 0x0c10
 #define XGMAC_RSS_CTRL 0x0c80
 #define XGMAC_UDP4TE   BIT(3)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index e534a3aaf4a3..9f568b54b339 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -1163,6 +1163,181 @@ static void dwxgmac2_enable_vlan(struct mac_device_info 
*hw, u32 type)
writel(value, ioaddr + XGMAC_VLAN_INCL);
 }
 
+static int dwxgmac2_filter_wait(struct mac_device_info *hw)
+{
+   void __iomem *ioaddr = hw->pcsr;
+   u32 value;
+
+   if (readl_poll_timeout(ioaddr + XGMAC_L3L4_ADDR_CTRL, value,
+  !(value & XGMAC_XB), 100, 1))
+   return -EBUSY;
+   return 0;
+}
+
+static int dwxgmac2_filter_read(struct mac_device_info *hw, u32 filter_no,
+   u8 reg, u32 *data)
+{
+  

[PATCH v2 net-next 13/13] net: stmmac: selftests: Add Jumbo Frame tests

2019-09-04 Thread Jose Abreu
Add a test to validate the Jumbo Frame support in stmmac in single
channel and multichannel mode.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 65 +-
 1 file changed, 62 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 8446b414b44d..305d24935cf4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -43,9 +43,11 @@ struct stmmac_packet_attrs {
int dont_wait;
int timeout;
int size;
+   int max_size;
int remove_sa;
u8 id;
int sarc;
+   u16 queue_mapping;
 };
 
 static u8 stmmac_test_next_id;
@@ -73,12 +75,14 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
else
size += sizeof(struct udphdr);
 
-   skb = netdev_alloc_skb(priv->dev, size);
+   if (attr->max_size && (attr->max_size > size))
+   size = attr->max_size;
+
+   skb = netdev_alloc_skb_ip_align(priv->dev, size);
if (!skb)
return NULL;
 
prefetchw(skb->data);
-   skb_reserve(skb, NET_IP_ALIGN);
 
if (attr->vlan > 1)
ehdr = skb_push(skb, ETH_HLEN + 8);
@@ -147,6 +151,9 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
uhdr->source = htons(attr->sport);
uhdr->dest = htons(attr->dport);
uhdr->len = htons(sizeof(*shdr) + sizeof(*uhdr) + attr->size);
+   if (attr->max_size)
+   uhdr->len = htons(attr->max_size -
+ (sizeof(*ihdr) + sizeof(*ehdr)));
uhdr->check = 0;
}
 
@@ -162,6 +169,10 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
iplen += sizeof(*thdr);
else
iplen += sizeof(*uhdr);
+
+   if (attr->max_size)
+   iplen = attr->max_size - sizeof(*ehdr);
+
ihdr->tot_len = htons(iplen);
ihdr->frag_off = 0;
ihdr->saddr = htonl(attr->ip_src);
@@ -178,6 +189,8 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
 
if (attr->size)
skb_put(skb, attr->size);
+   if (attr->max_size && (attr->max_size > skb->len))
+   skb_put(skb, attr->max_size - skb->len);
 
skb->csum = 0;
skb->ip_summed = CHECKSUM_PARTIAL;
@@ -324,7 +337,7 @@ static int __stmmac_test_loopback(struct stmmac_priv *priv,
goto cleanup;
}
 
-   skb_set_queue_mapping(skb, 0);
+   skb_set_queue_mapping(skb, attr->queue_mapping);
ret = dev_queue_xmit(skb);
if (ret)
goto cleanup;
@@ -1534,6 +1547,44 @@ static int stmmac_test_arpoffload(struct stmmac_priv 
*priv)
return ret;
 }
 
+static int __stmmac_test_jumbo(struct stmmac_priv *priv, u16 queue)
+{
+   struct stmmac_packet_attrs attr = { };
+   int size = priv->dma_buf_sz;
+
+   /* Only XGMAC has SW support for multiple RX descs in same packet */
+   if (priv->plat->has_xgmac)
+   size = priv->dev->max_mtu;
+
+   attr.dst = priv->dev->dev_addr;
+   attr.max_size = size - ETH_FCS_LEN;
+   attr.queue_mapping = queue;
+
+   return __stmmac_test_loopback(priv, );
+}
+
+static int stmmac_test_jumbo(struct stmmac_priv *priv)
+{
+   return __stmmac_test_jumbo(priv, 0);
+}
+
+static int stmmac_test_mjumbo(struct stmmac_priv *priv)
+{
+   u32 chan, tx_cnt = priv->plat->tx_queues_to_use;
+   int ret;
+
+   if (tx_cnt <= 1)
+   return -EOPNOTSUPP;
+
+   for (chan = 0; chan < tx_cnt; chan++) {
+   ret = __stmmac_test_jumbo(priv, chan);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
 #define STMMAC_LOOPBACK_NONE   0
 #define STMMAC_LOOPBACK_MAC1
 #define STMMAC_LOOPBACK_PHY2
@@ -1647,6 +1698,14 @@ static const struct stmmac_test {
.name = "ARP Offload ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_arpoffload,
+   }, {
+   .name = "Jumbo Frame ",
+   .lb = STMMAC_LOOPBACK_PHY,
+   .fn = stmmac_test_jumbo,
+   }, {
+   .name = "Multichannel Jumbo  ",
+   .lb = STMMAC_LOOPBACK_PHY,
+   .fn = stmmac_test_mjumbo,
},
 };
 
-- 
2.7.4



[PATCH v2 net-next 01/13] net: stmmac: selftests: Return proper error code to userspace

2019-09-04 Thread Jose Abreu
We can do better than just return 1 to userspace. Lets return a proper
Linux error code.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index ecc8602c6799..d3234338a0ca 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -318,7 +318,7 @@ static int __stmmac_test_loopback(struct stmmac_priv *priv,
attr->timeout = STMMAC_LB_TIMEOUT;
 
wait_for_completion_timeout(>comp, attr->timeout);
-   ret = !tpriv->ok;
+   ret = tpriv->ok ? 0 : -ETIMEDOUT;
 
 cleanup:
if (!attr->dont_wait)
@@ -480,7 +480,7 @@ static int stmmac_test_hfilt(struct stmmac_priv *priv)
 
/* Shall NOT receive packet */
ret = __stmmac_test_loopback(priv, );
-   ret = !ret;
+   ret = ret ? 0 : -EINVAL;
 
 cleanup:
dev_mc_del(priv->dev, gd_addr);
@@ -512,7 +512,7 @@ static int stmmac_test_pfilt(struct stmmac_priv *priv)
 
/* Shall NOT receive packet */
ret = __stmmac_test_loopback(priv, );
-   ret = !ret;
+   ret = ret ? 0 : -EINVAL;
 
 cleanup:
dev_uc_del(priv->dev, gd_addr);
@@ -562,7 +562,7 @@ static int stmmac_test_mcfilt(struct stmmac_priv *priv)
 
/* Shall NOT receive packet */
ret = __stmmac_test_loopback(priv, );
-   ret = !ret;
+   ret = ret ? 0 : -EINVAL;
 
 cleanup:
dev_uc_del(priv->dev, uc_addr);
@@ -600,7 +600,7 @@ static int stmmac_test_ucfilt(struct stmmac_priv *priv)
 
/* Shall NOT receive packet */
ret = __stmmac_test_loopback(priv, );
-   ret = !ret;
+   ret = ret ? 0 : -EINVAL;
 
 cleanup:
dev_mc_del(priv->dev, mc_addr);
@@ -699,7 +699,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv)
}
 
wait_for_completion_timeout(>comp, STMMAC_LB_TIMEOUT);
-   ret = !tpriv->ok;
+   ret = tpriv->ok ? 0 : -ETIMEDOUT;
 
 cleanup:
dev_mc_del(priv->dev, paddr);
@@ -833,11 +833,11 @@ static int stmmac_test_vlanfilt(struct stmmac_priv *priv)
goto vlan_del;
 
wait_for_completion_timeout(>comp, STMMAC_LB_TIMEOUT);
-   ret = !tpriv->ok;
+   ret = tpriv->ok ? 0 : -ETIMEDOUT;
if (ret && !i) {
goto vlan_del;
} else if (!ret && i) {
-   ret = -1;
+   ret = -EINVAL;
goto vlan_del;
} else {
ret = 0;
@@ -909,11 +909,11 @@ static int stmmac_test_dvlanfilt(struct stmmac_priv *priv)
goto vlan_del;
 
wait_for_completion_timeout(>comp, STMMAC_LB_TIMEOUT);
-   ret = !tpriv->ok;
+   ret = tpriv->ok ? 0 : -ETIMEDOUT;
if (ret && !i) {
goto vlan_del;
} else if (!ret && i) {
-   ret = -1;
+   ret = -EINVAL;
goto vlan_del;
} else {
ret = 0;
@@ -998,7 +998,7 @@ static int stmmac_test_rxp(struct stmmac_priv *priv)
attr.src = addr;
 
ret = __stmmac_test_loopback(priv, );
-   ret = !ret; /* Shall NOT receive packet */
+   ret = ret ? 0 : -EINVAL; /* Shall NOT receive packet */
 
cls_u32.command = TC_CLSU32_DELETE_KNODE;
stmmac_tc_setup_cls_u32(priv, priv, _u32);
-- 
2.7.4



[PATCH v2 net-next 05/13] net: stmmac: selftests: Add selftest for L3/L4 Filters

2019-09-04 Thread Jose Abreu
Adds the selftests for L3 and L4 filters with DA/SA/DP/SP support.

Changes from v1:
- Reduce stack usage (kbuild test robot)

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 286 -
 1 file changed, 285 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index d3234338a0ca..36f74ee95295 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -164,7 +164,7 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
iplen += sizeof(*uhdr);
ihdr->tot_len = htons(iplen);
ihdr->frag_off = 0;
-   ihdr->saddr = 0;
+   ihdr->saddr = htonl(attr->ip_src);
ihdr->daddr = htonl(attr->ip_dst);
ihdr->tos = 0;
ihdr->id = 0;
@@ -1168,6 +1168,266 @@ static int stmmac_test_svlanoff(struct stmmac_priv 
*priv)
return stmmac_test_vlanoff_common(priv, true);
 }
 
+#ifdef CONFIG_NET_CLS_ACT
+static int __stmmac_test_l3filt(struct stmmac_priv *priv, u32 dst, u32 src,
+   u32 dst_mask, u32 src_mask)
+{
+   struct flow_dissector_key_ipv4_addrs key, mask;
+   unsigned long dummy_cookie = 0xdeadbeef;
+   struct stmmac_packet_attrs attr = { };
+   struct flow_dissector *dissector;
+   struct flow_cls_offload *cls;
+   struct flow_rule *rule;
+   int ret;
+
+   if (!tc_can_offload(priv->dev))
+   return -EOPNOTSUPP;
+   if (!priv->dma_cap.l3l4fnum)
+   return -EOPNOTSUPP;
+   if (priv->rss.enable) {
+   struct stmmac_rss rss = { .enable = false, };
+
+   stmmac_rss_configure(priv, priv->hw, ,
+priv->plat->rx_queues_to_use);
+   }
+
+   dissector = kzalloc(sizeof(*dissector), GFP_KERNEL);
+   if (!dissector) {
+   ret = -ENOMEM;
+   goto cleanup_rss;
+   }
+
+   dissector->used_keys |= (1 << FLOW_DISSECTOR_KEY_IPV4_ADDRS);
+   dissector->offset[FLOW_DISSECTOR_KEY_IPV4_ADDRS] = 0;
+
+   cls = kzalloc(sizeof(*cls), GFP_KERNEL);
+   if (!cls) {
+   ret = -ENOMEM;
+   goto cleanup_dissector;
+   }
+
+   cls->common.chain_index = 0;
+   cls->command = FLOW_CLS_REPLACE;
+   cls->cookie = dummy_cookie;
+
+   rule = kzalloc(struct_size(rule, action.entries, 1), GFP_KERNEL);
+   if (!rule) {
+   ret = -ENOMEM;
+   goto cleanup_cls;
+   }
+
+   rule->match.dissector = dissector;
+   rule->match.key = (void *)
+   rule->match.mask = (void *)
+
+   key.src = htonl(src);
+   key.dst = htonl(dst);
+   mask.src = src_mask;
+   mask.dst = dst_mask;
+
+   cls->rule = rule;
+
+   rule->action.entries[0].id = FLOW_ACTION_DROP;
+   rule->action.num_entries = 1;
+
+   attr.dst = priv->dev->dev_addr;
+   attr.ip_dst = dst;
+   attr.ip_src = src;
+
+   /* Shall receive packet */
+   ret = __stmmac_test_loopback(priv, );
+   if (ret)
+   goto cleanup_rule;
+
+   ret = stmmac_tc_setup_cls(priv, priv, cls);
+   if (ret)
+   goto cleanup_rule;
+
+   /* Shall NOT receive packet */
+   ret = __stmmac_test_loopback(priv, );
+   ret = ret ? 0 : -EINVAL;
+
+   cls->command = FLOW_CLS_DESTROY;
+   stmmac_tc_setup_cls(priv, priv, cls);
+cleanup_rule:
+   kfree(rule);
+cleanup_cls:
+   kfree(cls);
+cleanup_dissector:
+   kfree(dissector);
+cleanup_rss:
+   if (priv->rss.enable) {
+   stmmac_rss_configure(priv, priv->hw, >rss,
+priv->plat->rx_queues_to_use);
+   }
+
+   return ret;
+}
+#else
+static int __stmmac_test_l3filt(struct stmmac_priv *priv, u32 dst, u32 src,
+   u32 dst_mask, u32 src_mask)
+{
+   return -EOPNOTSUPP;
+}
+#endif
+
+static int stmmac_test_l3filt_da(struct stmmac_priv *priv)
+{
+   u32 addr = 0x10203040;
+
+   return __stmmac_test_l3filt(priv, addr, 0, ~0, 0);
+}
+
+static int stmmac_test_l3filt_sa(struct stmmac_priv *priv)
+{
+   u32 addr = 0x10203040;
+
+   return __stmmac_test_l3filt(priv, 0, addr, 0, ~0);
+}
+
+#ifdef CONFIG_NET_CLS_ACT
+static int __stmmac_test_l4filt(struct stmmac_priv *priv, u32 dst, u32 src,
+   u32 dst_mask, u32 src_mask, bool udp)
+{
+   struct {
+   struct flow_diss

[PATCH v2 net-next 10/13] net: stmmac: xgmac: Correct RAVSEL field interpretation

2019-09-04 Thread Jose Abreu
RAVSEL means that only RX side is available for AVB features. As we use
both TX and RX features we need to check if RAVSEL is selected and
disable AVB if only RX side is available.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
index fd60bf5e0a72..53c4a40d8386 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
@@ -369,7 +369,7 @@ static void dwxgmac2_get_hw_feature(void __iomem *ioaddr,
dma_cap->eee = (hw_cap & XGMAC_HWFEAT_EEESEL) >> 13;
dma_cap->atime_stamp = (hw_cap & XGMAC_HWFEAT_TSSEL) >> 12;
dma_cap->av = (hw_cap & XGMAC_HWFEAT_AVSEL) >> 11;
-   dma_cap->av &= (hw_cap & XGMAC_HWFEAT_RAVSEL) >> 10;
+   dma_cap->av &= !(hw_cap & XGMAC_HWFEAT_RAVSEL) >> 10;
dma_cap->arpoffsel = (hw_cap & XGMAC_HWFEAT_ARPOFFSEL) >> 9;
dma_cap->rmon = (hw_cap & XGMAC_HWFEAT_MMCSEL) >> 8;
dma_cap->pmt_magic_frame = (hw_cap & XGMAC_HWFEAT_MGKSEL) >> 7;
-- 
2.7.4



[PATCH v2 net-next 03/13] net: stmmac: Do not return error code in TC Initialization

2019-09-04 Thread Jose Abreu
As we can still use the remaining TC callbacks, e.g. CBS. We should not
fail in the initialization only because RX Parser is not available.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
index 6c305b6ecad0..8dbbbf181ada 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
@@ -243,8 +243,9 @@ static int tc_init(struct stmmac_priv *priv)
struct dma_features *dma_cap = >dma_cap;
unsigned int count;
 
+   /* Fail silently as we can still use remaining features, e.g. CBS */
if (!dma_cap->frpsel)
-   return -EINVAL;
+   return 0;
 
switch (dma_cap->frpbs) {
case 0x0:
-- 
2.7.4



[PATCH v2 net-next 06/13] net: stmmac: xgmac: Implement ARP Offload

2019-09-04 Thread Jose Abreu
Implement the ARP Offload feature in XGMAC cores.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/common.h|  1 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 17 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c  |  1 +
 drivers/net/ethernet/stmicro/stmmac/hwif.h  |  3 +++
 4 files changed, 22 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index 19538057c24e..912bbb6515b2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -361,6 +361,7 @@ struct dma_features {
unsigned int vlins;
unsigned int dvlan;
unsigned int l3l4fnum;
+   unsigned int arpoffsel;
 };
 
 /* GMAC TX FIFO is 8K, Rx FIFO is 16K */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 9f568b54b339..36262ef8b70a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -1338,6 +1338,22 @@ static int dwxgmac2_config_l4_filter(struct 
mac_device_info *hw, u32 filter_no,
return 0;
 }
 
+static void dwxgmac2_set_arp_offload(struct mac_device_info *hw, bool en,
+u32 addr)
+{
+   void __iomem *ioaddr = hw->pcsr;
+   u32 value;
+
+   writel(addr, ioaddr + XGMAC_ARP_ADDR);
+
+   value = readl(ioaddr + XGMAC_RX_CONFIG);
+   if (en)
+   value |= XGMAC_CONFIG_ARPEN;
+   else
+   value &= ~XGMAC_CONFIG_ARPEN;
+   writel(value, ioaddr + XGMAC_RX_CONFIG);
+}
+
 const struct stmmac_ops dwxgmac210_ops = {
.core_init = dwxgmac2_core_init,
.set_mac = dwxgmac2_set_mac,
@@ -1380,6 +1396,7 @@ const struct stmmac_ops dwxgmac210_ops = {
.enable_vlan = dwxgmac2_enable_vlan,
.config_l3_filter = dwxgmac2_config_l3_filter,
.config_l4_filter = dwxgmac2_config_l4_filter,
+   .set_arp_offload = dwxgmac2_set_arp_offload,
 };
 
 int dwxgmac2_setup(struct stmmac_priv *priv)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
index fb0283b15c77..fd60bf5e0a72 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
@@ -370,6 +370,7 @@ static void dwxgmac2_get_hw_feature(void __iomem *ioaddr,
dma_cap->atime_stamp = (hw_cap & XGMAC_HWFEAT_TSSEL) >> 12;
dma_cap->av = (hw_cap & XGMAC_HWFEAT_AVSEL) >> 11;
dma_cap->av &= (hw_cap & XGMAC_HWFEAT_RAVSEL) >> 10;
+   dma_cap->arpoffsel = (hw_cap & XGMAC_HWFEAT_ARPOFFSEL) >> 9;
dma_cap->rmon = (hw_cap & XGMAC_HWFEAT_MMCSEL) >> 8;
dma_cap->pmt_magic_frame = (hw_cap & XGMAC_HWFEAT_MGKSEL) >> 7;
dma_cap->pmt_remote_wake_up = (hw_cap & XGMAC_HWFEAT_RWKSEL) >> 6;
diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h 
b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index 47c8ad9ec671..ddb851d99618 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -370,6 +370,7 @@ struct stmmac_ops {
int (*config_l4_filter)(struct mac_device_info *hw, u32 filter_no,
bool en, bool udp, bool sa, bool inv,
u32 match);
+   void (*set_arp_offload)(struct mac_device_info *hw, bool en, u32 addr);
 };
 
 #define stmmac_core_init(__priv, __args...) \
@@ -454,6 +455,8 @@ struct stmmac_ops {
stmmac_do_callback(__priv, mac, config_l3_filter, __args)
 #define stmmac_config_l4_filter(__priv, __args...) \
stmmac_do_callback(__priv, mac, config_l4_filter, __args)
+#define stmmac_set_arp_offload(__priv, __args...) \
+   stmmac_do_void_callback(__priv, mac, set_arp_offload, __args)
 
 /* PTP and HW Timer helpers */
 struct stmmac_hwtimestamp {
-- 
2.7.4



[PATCH v2 net-next 00/13] net: stmmac: Improvements for -next

2019-09-04 Thread Jose Abreu
Couple of improvements for -next tree. More info in commit logs.

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---

Jose Abreu (13):
  net: stmmac: selftests: Return proper error code to userspace
  net: stmmac: xgmac: Add RBU handling in DMA interrupt
  net: stmmac: Do not return error code in TC Initialization
  net: stmmac: Implement L3/L4 Filters using TC Flower
  net: stmmac: selftests: Add selftest for L3/L4 Filters
  net: stmmac: xgmac: Implement ARP Offload
  net: stmmac: selftests: Implement the ARP Offload test
  net: stmmac: Only consider RX error when HW Timestamping is not
enabled
  net: stmmac: ethtool: Let user configure TX coalesce without RIWT
  net: stmmac: xgmac: Correct RAVSEL field interpretation
  net: stmmac: Correctly assing MAX MTU in XGMAC cores case
  net: stmmac: xgmac: Enable RX Jumbo frame support
  net: stmmac: selftests: Add Jumbo Frame tests

 drivers/net/ethernet/stmicro/stmmac/common.h   |   2 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h |  33 +-
 .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c| 205 -
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c |   8 +-
 drivers/net/ethernet/stmicro/stmmac/hwif.h |  19 +
 drivers/net/ethernet/stmicro/stmmac/stmmac.h   |  12 +
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   |  21 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |  18 +-
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 483 -
 drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c| 247 ++-
 10 files changed, 1001 insertions(+), 47 deletions(-)

-- 
2.7.4



[PATCH v2 net-next 07/13] net: stmmac: selftests: Implement the ARP Offload test

2019-09-04 Thread Jose Abreu
Implement a test for ARP Offload feature.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 110 +
 1 file changed, 110 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 36f74ee95295..8446b414b44d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -196,6 +196,24 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
return skb;
 }
 
+static struct sk_buff *stmmac_test_get_arp_skb(struct stmmac_priv *priv,
+  struct stmmac_packet_attrs *attr)
+{
+   __be32 ip_src = htonl(attr->ip_src);
+   __be32 ip_dst = htonl(attr->ip_dst);
+   struct sk_buff *skb = NULL;
+
+   skb = arp_create(ARPOP_REQUEST, ETH_P_ARP, ip_dst, priv->dev, ip_src,
+NULL, attr->src, attr->dst);
+   if (!skb)
+   return NULL;
+
+   skb->pkt_type = PACKET_HOST;
+   skb->dev = priv->dev;
+
+   return skb;
+}
+
 struct stmmac_test_priv {
struct stmmac_packet_attrs *packet;
struct packet_type pt;
@@ -1428,6 +1446,94 @@ static int stmmac_test_l4filt_sa_udp(struct stmmac_priv 
*priv)
return __stmmac_test_l4filt(priv, 0, dummy_port, 0, ~0, true);
 }
 
+static int stmmac_test_arp_validate(struct sk_buff *skb,
+   struct net_device *ndev,
+   struct packet_type *pt,
+   struct net_device *orig_ndev)
+{
+   struct stmmac_test_priv *tpriv = pt->af_packet_priv;
+   struct ethhdr *ehdr;
+   struct arphdr *ahdr;
+
+   ehdr = (struct ethhdr *)skb_mac_header(skb);
+   if (!ether_addr_equal(ehdr->h_dest, tpriv->packet->src))
+   goto out;
+
+   ahdr = arp_hdr(skb);
+   if (ahdr->ar_op != htons(ARPOP_REPLY))
+   goto out;
+
+   tpriv->ok = true;
+   complete(>comp);
+out:
+   kfree_skb(skb);
+   return 0;
+}
+
+static int stmmac_test_arpoffload(struct stmmac_priv *priv)
+{
+   unsigned char src[ETH_ALEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
+   unsigned char dst[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+   struct stmmac_packet_attrs attr = { };
+   struct stmmac_test_priv *tpriv;
+   struct sk_buff *skb = NULL;
+   u32 ip_addr = 0xdeadcafe;
+   u32 ip_src = 0xdeadbeef;
+   int ret;
+
+   if (!priv->dma_cap.arpoffsel)
+   return -EOPNOTSUPP;
+
+   tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
+   if (!tpriv)
+   return -ENOMEM;
+
+   tpriv->ok = false;
+   init_completion(>comp);
+
+   tpriv->pt.type = htons(ETH_P_ARP);
+   tpriv->pt.func = stmmac_test_arp_validate;
+   tpriv->pt.dev = priv->dev;
+   tpriv->pt.af_packet_priv = tpriv;
+   tpriv->packet = 
+   dev_add_pack(>pt);
+
+   attr.src = src;
+   attr.ip_src = ip_src;
+   attr.dst = dst;
+   attr.ip_dst = ip_addr;
+
+   skb = stmmac_test_get_arp_skb(priv, );
+   if (!skb) {
+   ret = -ENOMEM;
+   goto cleanup;
+   }
+
+   ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr);
+   if (ret)
+   goto cleanup;
+
+   ret = dev_set_promiscuity(priv->dev, 1);
+   if (ret)
+   goto cleanup;
+
+   skb_set_queue_mapping(skb, 0);
+   ret = dev_queue_xmit(skb);
+   if (ret)
+   goto cleanup_promisc;
+
+   wait_for_completion_timeout(>comp, STMMAC_LB_TIMEOUT);
+   ret = tpriv->ok ? 0 : -ETIMEDOUT;
+
+cleanup_promisc:
+   dev_set_promiscuity(priv->dev, -1);
+cleanup:
+   stmmac_set_arp_offload(priv, priv->hw, false, 0x0);
+   dev_remove_pack(>pt);
+   kfree(tpriv);
+   return ret;
+}
+
 #define STMMAC_LOOPBACK_NONE   0
 #define STMMAC_LOOPBACK_MAC1
 #define STMMAC_LOOPBACK_PHY2
@@ -1537,6 +1643,10 @@ static const struct stmmac_test {
.name = "L4 SA UDP Filtering ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_l4filt_sa_udp,
+   }, {
+   .name = "ARP Offload ",
+   .lb = STMMAC_LOOPBACK_PHY,
+   .fn = stmmac_test_arpoffload,
},
 };
 
-- 
2.7.4



[PATCH v2 net-next 11/13] net: stmmac: Correctly assing MAX MTU in XGMAC cores case

2019-09-04 Thread Jose Abreu
Maximum MTU for XGMAC cores is 16k thus the check for presence of XGMAC
shall be done first in order to assign correct value.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 5271c6129f0e..c3baca9f587b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4542,10 +4542,10 @@ int stmmac_dvr_probe(struct device *device,
 
/* MTU range: 46 - hw-specific max */
ndev->min_mtu = ETH_ZLEN - ETH_HLEN;
-   if ((priv->plat->enh_desc) || (priv->synopsys_id >= DWMAC_CORE_4_00))
-   ndev->max_mtu = JUMBO_LEN;
-   else if (priv->plat->has_xgmac)
+   if (priv->plat->has_xgmac)
ndev->max_mtu = XGMAC_JUMBO_LEN;
+   else if ((priv->plat->enh_desc) || (priv->synopsys_id >= 
DWMAC_CORE_4_00))
+   ndev->max_mtu = JUMBO_LEN;
else
ndev->max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);
/* Will not overwrite ndev->max_mtu if plat->maxmtu > ndev->max_mtu
-- 
2.7.4



[PATCH v2 net-next 02/13] net: stmmac: xgmac: Add RBU handling in DMA interrupt

2019-09-04 Thread Jose Abreu
Add the handling of Receive Buffer Unavailable interrupt in the DMA
handler of XGMAC cores.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
index 64956465c030..e77eb0ddf9b5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
@@ -322,6 +322,10 @@ static int dwxgmac2_dma_interrupt(void __iomem *ioaddr,
 
/* ABNORMAL interrupts */
if (unlikely(intr_status & XGMAC_AIS)) {
+   if (unlikely(intr_status & XGMAC_RBU)) {
+   x->rx_buf_unav_irq++;
+   ret |= handle_rx;
+   }
if (unlikely(intr_status & XGMAC_TPS)) {
x->tx_process_stopped_irq++;
ret |= tx_hard_error;
-- 
2.7.4



[PATCH net-next 05/13] net: stmmac: selftests: Add selftest for L3/L4 Filters

2019-09-02 Thread Jose Abreu
Adds the selftests for L3 and L4 filters with DA/SA/DP/SP support.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 254 -
 1 file changed, 253 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index d3234338a0ca..8e9d0aeda817 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -164,7 +164,7 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
iplen += sizeof(*uhdr);
ihdr->tot_len = htons(iplen);
ihdr->frag_off = 0;
-   ihdr->saddr = 0;
+   ihdr->saddr = htonl(attr->ip_src);
ihdr->daddr = htonl(attr->ip_dst);
ihdr->tos = 0;
ihdr->id = 0;
@@ -1168,6 +1168,234 @@ static int stmmac_test_svlanoff(struct stmmac_priv 
*priv)
return stmmac_test_vlanoff_common(priv, true);
 }
 
+#ifdef CONFIG_NET_CLS_ACT
+static int __stmmac_test_l3filt(struct stmmac_priv *priv, u32 dst, u32 src,
+   u32 dst_mask, u32 src_mask)
+{
+   struct flow_dissector_key_ipv4_addrs key, mask;
+   unsigned long dummy_cookie = 0xdeadbeef;
+   struct flow_dissector dissector = { };
+   struct stmmac_packet_attrs attr = { };
+   struct flow_cls_offload cls = { };
+   struct flow_rule *rule;
+   int ret;
+
+   if (!tc_can_offload(priv->dev))
+   return -EOPNOTSUPP;
+   if (!priv->dma_cap.l3l4fnum)
+   return -EOPNOTSUPP;
+   if (priv->rss.enable) {
+   struct stmmac_rss rss = { .enable = false, };
+
+   stmmac_rss_configure(priv, priv->hw, ,
+priv->plat->rx_queues_to_use);
+   }
+
+   dissector.used_keys |= (1 << FLOW_DISSECTOR_KEY_IPV4_ADDRS);
+   dissector.offset[FLOW_DISSECTOR_KEY_IPV4_ADDRS] = 0;
+
+   cls.common.chain_index = 0;
+   cls.command = FLOW_CLS_REPLACE;
+   cls.cookie = dummy_cookie;
+
+   rule = kzalloc(struct_size(rule, action.entries, 1), GFP_KERNEL);
+   if (!rule) {
+   ret = -ENOMEM;
+   goto cleanup_rss;
+   }
+
+   rule->match.dissector = 
+   rule->match.key = (void *)
+   rule->match.mask = (void *)
+
+   key.src = htonl(src);
+   key.dst = htonl(dst);
+   mask.src = src_mask;
+   mask.dst = dst_mask;
+
+   cls.rule = rule;
+
+   rule->action.entries[0].id = FLOW_ACTION_DROP;
+   rule->action.num_entries = 1;
+
+   attr.dst = priv->dev->dev_addr;
+   attr.ip_dst = dst;
+   attr.ip_src = src;
+
+   /* Shall receive packet */
+   ret = __stmmac_test_loopback(priv, );
+   if (ret)
+   goto cleanup_rule;
+
+   ret = stmmac_tc_setup_cls(priv, priv, );
+   if (ret)
+   goto cleanup_rule;
+
+   /* Shall NOT receive packet */
+   ret = __stmmac_test_loopback(priv, );
+   ret = ret ? 0 : -EINVAL;
+
+   cls.command = FLOW_CLS_DESTROY;
+   stmmac_tc_setup_cls(priv, priv, );
+cleanup_rule:
+   kfree(rule);
+cleanup_rss:
+   if (priv->rss.enable) {
+   stmmac_rss_configure(priv, priv->hw, >rss,
+priv->plat->rx_queues_to_use);
+   }
+
+   return ret;
+}
+#else
+static int __stmmac_test_l3filt(struct stmmac_priv *priv, u32 dst, u32 src,
+   u32 dst_mask, u32 src_mask)
+{
+   return -EOPNOTSUPP;
+}
+#endif
+
+static int stmmac_test_l3filt_da(struct stmmac_priv *priv)
+{
+   u32 addr = 0x10203040;
+
+   return __stmmac_test_l3filt(priv, addr, 0, ~0, 0);
+}
+
+static int stmmac_test_l3filt_sa(struct stmmac_priv *priv)
+{
+   u32 addr = 0x10203040;
+
+   return __stmmac_test_l3filt(priv, 0, addr, 0, ~0);
+}
+
+#ifdef CONFIG_NET_CLS_ACT
+static int __stmmac_test_l4filt(struct stmmac_priv *priv, u32 dst, u32 src,
+   u32 dst_mask, u32 src_mask, bool udp)
+{
+   struct {
+   struct flow_dissector_key_basic bkey;
+   struct flow_dissector_key_ports key;
+   } __aligned(BITS_PER_LONG / 8) keys;
+   struct {
+   struct flow_dissector_key_basic bmask;
+   struct flow_dissector_key_ports mask;
+   } __aligned(BITS_PER_LONG / 8) masks;
+   unsigned long dummy_cookie = 0xdeadbeef;
+   struct flow_dissector dissector = { };
+   struct stmmac_packet_attrs attr = { };
+   struct flow_cls_offload cls = { };
+   struct flow_rule *ru

[PATCH net-next 07/13] net: stmmac: selftests: Implement the ARP Offload test

2019-09-02 Thread Jose Abreu
Implement a test for ARP Offload feature.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 110 +
 1 file changed, 110 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 8e9d0aeda817..f531dbe038df 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -196,6 +196,24 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
return skb;
 }
 
+static struct sk_buff *stmmac_test_get_arp_skb(struct stmmac_priv *priv,
+  struct stmmac_packet_attrs *attr)
+{
+   __be32 ip_src = htonl(attr->ip_src);
+   __be32 ip_dst = htonl(attr->ip_dst);
+   struct sk_buff *skb = NULL;
+
+   skb = arp_create(ARPOP_REQUEST, ETH_P_ARP, ip_dst, priv->dev, ip_src,
+NULL, attr->src, attr->dst);
+   if (!skb)
+   return NULL;
+
+   skb->pkt_type = PACKET_HOST;
+   skb->dev = priv->dev;
+
+   return skb;
+}
+
 struct stmmac_test_priv {
struct stmmac_packet_attrs *packet;
struct packet_type pt;
@@ -1396,6 +1414,94 @@ static int stmmac_test_l4filt_sa_udp(struct stmmac_priv 
*priv)
return __stmmac_test_l4filt(priv, 0, dummy_port, 0, ~0, true);
 }
 
+static int stmmac_test_arp_validate(struct sk_buff *skb,
+   struct net_device *ndev,
+   struct packet_type *pt,
+   struct net_device *orig_ndev)
+{
+   struct stmmac_test_priv *tpriv = pt->af_packet_priv;
+   struct ethhdr *ehdr;
+   struct arphdr *ahdr;
+
+   ehdr = (struct ethhdr *)skb_mac_header(skb);
+   if (!ether_addr_equal(ehdr->h_dest, tpriv->packet->src))
+   goto out;
+
+   ahdr = arp_hdr(skb);
+   if (ahdr->ar_op != htons(ARPOP_REPLY))
+   goto out;
+
+   tpriv->ok = true;
+   complete(>comp);
+out:
+   kfree_skb(skb);
+   return 0;
+}
+
+static int stmmac_test_arpoffload(struct stmmac_priv *priv)
+{
+   unsigned char src[ETH_ALEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
+   unsigned char dst[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+   struct stmmac_packet_attrs attr = { };
+   struct stmmac_test_priv *tpriv;
+   struct sk_buff *skb = NULL;
+   u32 ip_addr = 0xdeadcafe;
+   u32 ip_src = 0xdeadbeef;
+   int ret;
+
+   if (!priv->dma_cap.arpoffsel)
+   return -EOPNOTSUPP;
+
+   tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
+   if (!tpriv)
+   return -ENOMEM;
+
+   tpriv->ok = false;
+   init_completion(>comp);
+
+   tpriv->pt.type = htons(ETH_P_ARP);
+   tpriv->pt.func = stmmac_test_arp_validate;
+   tpriv->pt.dev = priv->dev;
+   tpriv->pt.af_packet_priv = tpriv;
+   tpriv->packet = 
+   dev_add_pack(>pt);
+
+   attr.src = src;
+   attr.ip_src = ip_src;
+   attr.dst = dst;
+   attr.ip_dst = ip_addr;
+
+   skb = stmmac_test_get_arp_skb(priv, );
+   if (!skb) {
+   ret = -ENOMEM;
+   goto cleanup;
+   }
+
+   ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr);
+   if (ret)
+   goto cleanup;
+
+   ret = dev_set_promiscuity(priv->dev, 1);
+   if (ret)
+   goto cleanup;
+
+   skb_set_queue_mapping(skb, 0);
+   ret = dev_queue_xmit(skb);
+   if (ret)
+   goto cleanup_promisc;
+
+   wait_for_completion_timeout(>comp, STMMAC_LB_TIMEOUT);
+   ret = tpriv->ok ? 0 : -ETIMEDOUT;
+
+cleanup_promisc:
+   dev_set_promiscuity(priv->dev, -1);
+cleanup:
+   stmmac_set_arp_offload(priv, priv->hw, false, 0x0);
+   dev_remove_pack(>pt);
+   kfree(tpriv);
+   return ret;
+}
+
 #define STMMAC_LOOPBACK_NONE   0
 #define STMMAC_LOOPBACK_MAC1
 #define STMMAC_LOOPBACK_PHY2
@@ -1505,6 +1611,10 @@ static const struct stmmac_test {
.name = "L4 SA UDP Filtering ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_l4filt_sa_udp,
+   }, {
+   .name = "ARP Offload ",
+   .lb = STMMAC_LOOPBACK_PHY,
+   .fn = stmmac_test_arpoffload,
},
 };
 
-- 
2.7.4



[PATCH net-next 12/13] net: stmmac: xgmac: Enable RX Jumbo frame support

2019-09-02 Thread Jose Abreu
We are already doing it by default in the TX path so we can also enable
Jumbo Frame support in the RX path independently of MTU value.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h  |  3 ++-
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 11 ---
 2 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index f942ac975c29..5923ca62d793 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -44,7 +44,8 @@
 #define XGMAC_CONFIG_CST   BIT(2)
 #define XGMAC_CONFIG_ACS   BIT(1)
 #define XGMAC_CONFIG_REBIT(0)
-#define XGMAC_CORE_INIT_RX 0
+#define XGMAC_CORE_INIT_RX (XGMAC_CONFIG_GPSLCE | XGMAC_CONFIG_WD 
| \
+(XGMAC_JUMBO_LEN << 
XGMAC_CONFIG_GPSL_SHIFT))
 #define XGMAC_PACKET_FILTER0x0008
 #define XGMAC_FILTER_RABIT(31)
 #define XGMAC_FILTER_IPFE  BIT(20)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 36262ef8b70a..78ac659da279 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -15,7 +15,6 @@ static void dwxgmac2_core_init(struct mac_device_info *hw,
   struct net_device *dev)
 {
void __iomem *ioaddr = hw->pcsr;
-   int mtu = dev->mtu;
u32 tx, rx;
 
tx = readl(ioaddr + XGMAC_TX_CONFIG);
@@ -24,16 +23,6 @@ static void dwxgmac2_core_init(struct mac_device_info *hw,
tx |= XGMAC_CORE_INIT_TX;
rx |= XGMAC_CORE_INIT_RX;
 
-   if (mtu >= 9000) {
-   rx |= XGMAC_CONFIG_GPSLCE;
-   rx |= XGMAC_JUMBO_LEN << XGMAC_CONFIG_GPSL_SHIFT;
-   rx |= XGMAC_CONFIG_WD;
-   } else if (mtu > 2000) {
-   rx |= XGMAC_CONFIG_JE;
-   } else if (mtu > 1500) {
-   rx |= XGMAC_CONFIG_S2KP;
-   }
-
if (hw->ps) {
tx |= XGMAC_CONFIG_TE;
tx &= ~hw->link.speed_mask;
-- 
2.7.4



[PATCH net-next 13/13] net: stmmac: selftests: Add Jumbo Frame tests

2019-09-02 Thread Jose Abreu
Add a test to validate the Jumbo Frame support in stmmac in single
channel and multichannel mode.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 65 +-
 1 file changed, 62 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index f531dbe038df..ff499b91ea9f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -43,9 +43,11 @@ struct stmmac_packet_attrs {
int dont_wait;
int timeout;
int size;
+   int max_size;
int remove_sa;
u8 id;
int sarc;
+   u16 queue_mapping;
 };
 
 static u8 stmmac_test_next_id;
@@ -73,12 +75,14 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
else
size += sizeof(struct udphdr);
 
-   skb = netdev_alloc_skb(priv->dev, size);
+   if (attr->max_size && (attr->max_size > size))
+   size = attr->max_size;
+
+   skb = netdev_alloc_skb_ip_align(priv->dev, size);
if (!skb)
return NULL;
 
prefetchw(skb->data);
-   skb_reserve(skb, NET_IP_ALIGN);
 
if (attr->vlan > 1)
ehdr = skb_push(skb, ETH_HLEN + 8);
@@ -147,6 +151,9 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
uhdr->source = htons(attr->sport);
uhdr->dest = htons(attr->dport);
uhdr->len = htons(sizeof(*shdr) + sizeof(*uhdr) + attr->size);
+   if (attr->max_size)
+   uhdr->len = htons(attr->max_size -
+ (sizeof(*ihdr) + sizeof(*ehdr)));
uhdr->check = 0;
}
 
@@ -162,6 +169,10 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
iplen += sizeof(*thdr);
else
iplen += sizeof(*uhdr);
+
+   if (attr->max_size)
+   iplen = attr->max_size - sizeof(*ehdr);
+
ihdr->tot_len = htons(iplen);
ihdr->frag_off = 0;
ihdr->saddr = htonl(attr->ip_src);
@@ -178,6 +189,8 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct 
stmmac_priv *priv,
 
if (attr->size)
skb_put(skb, attr->size);
+   if (attr->max_size && (attr->max_size > skb->len))
+   skb_put(skb, attr->max_size - skb->len);
 
skb->csum = 0;
skb->ip_summed = CHECKSUM_PARTIAL;
@@ -324,7 +337,7 @@ static int __stmmac_test_loopback(struct stmmac_priv *priv,
goto cleanup;
}
 
-   skb_set_queue_mapping(skb, 0);
+   skb_set_queue_mapping(skb, attr->queue_mapping);
ret = dev_queue_xmit(skb);
if (ret)
goto cleanup;
@@ -1502,6 +1515,44 @@ static int stmmac_test_arpoffload(struct stmmac_priv 
*priv)
return ret;
 }
 
+static int __stmmac_test_jumbo(struct stmmac_priv *priv, u16 queue)
+{
+   struct stmmac_packet_attrs attr = { };
+   int size = priv->dma_buf_sz;
+
+   /* Only XGMAC has SW support for multiple RX descs in same packet */
+   if (priv->plat->has_xgmac)
+   size = priv->dev->max_mtu;
+
+   attr.dst = priv->dev->dev_addr;
+   attr.max_size = size - ETH_FCS_LEN;
+   attr.queue_mapping = queue;
+
+   return __stmmac_test_loopback(priv, );
+}
+
+static int stmmac_test_jumbo(struct stmmac_priv *priv)
+{
+   return __stmmac_test_jumbo(priv, 0);
+}
+
+static int stmmac_test_mjumbo(struct stmmac_priv *priv)
+{
+   u32 chan, tx_cnt = priv->plat->tx_queues_to_use;
+   int ret;
+
+   if (tx_cnt <= 1)
+   return -EOPNOTSUPP;
+
+   for (chan = 0; chan < tx_cnt; chan++) {
+   ret = __stmmac_test_jumbo(priv, chan);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
 #define STMMAC_LOOPBACK_NONE   0
 #define STMMAC_LOOPBACK_MAC1
 #define STMMAC_LOOPBACK_PHY2
@@ -1615,6 +1666,14 @@ static const struct stmmac_test {
.name = "ARP Offload ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_arpoffload,
+   }, {
+   .name = "Jumbo Frame ",
+   .lb = STMMAC_LOOPBACK_PHY,
+   .fn = stmmac_test_jumbo,
+   }, {
+   .name = "Multichannel Jumbo  ",
+   .lb = STMMAC_LOOPBACK_PHY,
+   .fn = stmmac_test_mjumbo,
},
 };
 
-- 
2.7.4



[PATCH net-next 04/13] net: stmmac: Implement L3/L4 Filters using TC Flower

2019-09-02 Thread Jose Abreu
Implement filters for Layer 3 and Layer 4 using TC Flower API. Add the
corresponding callbacks in XGMAC core.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/common.h   |   1 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h |  30 +++
 .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c| 177 +++
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c |   1 +
 drivers/net/ethernet/stmicro/stmmac/hwif.h |  16 ++
 drivers/net/ethernet/stmicro/stmmac/stmmac.h   |  12 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |   9 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c| 244 +
 8 files changed, 488 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index 49aa56ca09cc..19538057c24e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -360,6 +360,7 @@ struct dma_features {
unsigned int sphen;
unsigned int vlins;
unsigned int dvlan;
+   unsigned int l3l4fnum;
 };
 
 /* GMAC TX FIFO is 8K, Rx FIFO is 16K */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index 7357b8bdc128..f942ac975c29 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -47,6 +47,7 @@
 #define XGMAC_CORE_INIT_RX 0
 #define XGMAC_PACKET_FILTER0x0008
 #define XGMAC_FILTER_RABIT(31)
+#define XGMAC_FILTER_IPFE  BIT(20)
 #define XGMAC_FILTER_VTFE  BIT(16)
 #define XGMAC_FILTER_HPF   BIT(10)
 #define XGMAC_FILTER_PCF   BIT(7)
@@ -119,6 +120,7 @@
 #define XGMAC_HWFEAT_VLHASHBIT(4)
 #define XGMAC_HWFEAT_GMIISEL   BIT(1)
 #define XGMAC_HW_FEATURE1  0x0120
+#define XGMAC_HWFEAT_L3L4FNUM  GENMASK(30, 27)
 #define XGMAC_HWFEAT_RSSEN BIT(20)
 #define XGMAC_HWFEAT_TSOEN BIT(18)
 #define XGMAC_HWFEAT_SPHEN BIT(17)
@@ -150,6 +152,34 @@
 #define XGMAC_DCS  GENMASK(19, 16)
 #define XGMAC_DCS_SHIFT16
 #define XGMAC_ADDRx_LOW(x) (0x0304 + (x) * 0x8)
+#define XGMAC_L3L4_ADDR_CTRL   0x0c00
+#define XGMAC_IDDR GENMASK(15, 8)
+#define XGMAC_IDDR_SHIFT   8
+#define XGMAC_IDDR_FNUM4
+#define XGMAC_TT   BIT(1)
+#define XGMAC_XB   BIT(0)
+#define XGMAC_L3L4_DATA0x0c04
+#define XGMAC_L3L4_CTRL0x0
+#define XGMAC_L4DPIM0  BIT(21)
+#define XGMAC_L4DPM0   BIT(20)
+#define XGMAC_L4SPIM0  BIT(19)
+#define XGMAC_L4SPM0   BIT(18)
+#define XGMAC_L4PEN0   BIT(16)
+#define XGMAC_L3HDBM0  GENMASK(15, 11)
+#define XGMAC_L3HSBM0  GENMASK(10, 6)
+#define XGMAC_L3DAIM0  BIT(5)
+#define XGMAC_L3DAM0   BIT(4)
+#define XGMAC_L3SAIM0  BIT(3)
+#define XGMAC_L3SAM0   BIT(2)
+#define XGMAC_L3PEN0   BIT(0)
+#define XGMAC_L4_ADDR  0x1
+#define XGMAC_L4DP0GENMASK(31, 16)
+#define XGMAC_L4DP0_SHIFT  16
+#define XGMAC_L4SP0GENMASK(15, 0)
+#define XGMAC_L3_ADDR0 0x4
+#define XGMAC_L3_ADDR1 0x5
+#define XGMAC_L3_ADDR2 0x6
+#define XMGAC_L3_ADDR3 0x7
 #define XGMAC_ARP_ADDR 0x0c10
 #define XGMAC_RSS_CTRL 0x0c80
 #define XGMAC_UDP4TE   BIT(3)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index e534a3aaf4a3..9f568b54b339 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -1163,6 +1163,181 @@ static void dwxgmac2_enable_vlan(struct mac_device_info 
*hw, u32 type)
writel(value, ioaddr + XGMAC_VLAN_INCL);
 }
 
+static int dwxgmac2_filter_wait(struct mac_device_info *hw)
+{
+   void __iomem *ioaddr = hw->pcsr;
+   u32 value;
+
+   if (readl_poll_timeout(ioaddr + XGMAC_L3L4_ADDR_CTRL, value,
+  !(value & XGMAC_XB), 100, 1))
+   return -EBUSY;
+   return 0;
+}
+
+static int dwxgmac2_filter_read(struct mac_device_info *hw, u32 filter_no,
+   u8 reg, u32 *data)
+{
+  

[PATCH net-next 01/13] net: stmmac: selftests: Return proper error code to userspace

2019-09-02 Thread Jose Abreu
We can do better than just return 1 to userspace. Lets return a proper
Linux error code.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index ecc8602c6799..d3234338a0ca 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -318,7 +318,7 @@ static int __stmmac_test_loopback(struct stmmac_priv *priv,
attr->timeout = STMMAC_LB_TIMEOUT;
 
wait_for_completion_timeout(>comp, attr->timeout);
-   ret = !tpriv->ok;
+   ret = tpriv->ok ? 0 : -ETIMEDOUT;
 
 cleanup:
if (!attr->dont_wait)
@@ -480,7 +480,7 @@ static int stmmac_test_hfilt(struct stmmac_priv *priv)
 
/* Shall NOT receive packet */
ret = __stmmac_test_loopback(priv, );
-   ret = !ret;
+   ret = ret ? 0 : -EINVAL;
 
 cleanup:
dev_mc_del(priv->dev, gd_addr);
@@ -512,7 +512,7 @@ static int stmmac_test_pfilt(struct stmmac_priv *priv)
 
/* Shall NOT receive packet */
ret = __stmmac_test_loopback(priv, );
-   ret = !ret;
+   ret = ret ? 0 : -EINVAL;
 
 cleanup:
dev_uc_del(priv->dev, gd_addr);
@@ -562,7 +562,7 @@ static int stmmac_test_mcfilt(struct stmmac_priv *priv)
 
/* Shall NOT receive packet */
ret = __stmmac_test_loopback(priv, );
-   ret = !ret;
+   ret = ret ? 0 : -EINVAL;
 
 cleanup:
dev_uc_del(priv->dev, uc_addr);
@@ -600,7 +600,7 @@ static int stmmac_test_ucfilt(struct stmmac_priv *priv)
 
/* Shall NOT receive packet */
ret = __stmmac_test_loopback(priv, );
-   ret = !ret;
+   ret = ret ? 0 : -EINVAL;
 
 cleanup:
dev_mc_del(priv->dev, mc_addr);
@@ -699,7 +699,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv)
}
 
wait_for_completion_timeout(>comp, STMMAC_LB_TIMEOUT);
-   ret = !tpriv->ok;
+   ret = tpriv->ok ? 0 : -ETIMEDOUT;
 
 cleanup:
dev_mc_del(priv->dev, paddr);
@@ -833,11 +833,11 @@ static int stmmac_test_vlanfilt(struct stmmac_priv *priv)
goto vlan_del;
 
wait_for_completion_timeout(>comp, STMMAC_LB_TIMEOUT);
-   ret = !tpriv->ok;
+   ret = tpriv->ok ? 0 : -ETIMEDOUT;
if (ret && !i) {
goto vlan_del;
} else if (!ret && i) {
-   ret = -1;
+   ret = -EINVAL;
goto vlan_del;
} else {
ret = 0;
@@ -909,11 +909,11 @@ static int stmmac_test_dvlanfilt(struct stmmac_priv *priv)
goto vlan_del;
 
wait_for_completion_timeout(>comp, STMMAC_LB_TIMEOUT);
-   ret = !tpriv->ok;
+   ret = tpriv->ok ? 0 : -ETIMEDOUT;
if (ret && !i) {
goto vlan_del;
} else if (!ret && i) {
-   ret = -1;
+   ret = -EINVAL;
goto vlan_del;
} else {
ret = 0;
@@ -998,7 +998,7 @@ static int stmmac_test_rxp(struct stmmac_priv *priv)
attr.src = addr;
 
ret = __stmmac_test_loopback(priv, );
-   ret = !ret; /* Shall NOT receive packet */
+   ret = ret ? 0 : -EINVAL; /* Shall NOT receive packet */
 
cls_u32.command = TC_CLSU32_DELETE_KNODE;
stmmac_tc_setup_cls_u32(priv, priv, _u32);
-- 
2.7.4



[PATCH net-next 06/13] net: stmmac: xgmac: Implement ARP Offload

2019-09-02 Thread Jose Abreu
Implement the ARP Offload feature in XGMAC cores.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/common.h|  1 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 17 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c  |  1 +
 drivers/net/ethernet/stmicro/stmmac/hwif.h  |  3 +++
 4 files changed, 22 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h 
b/drivers/net/ethernet/stmicro/stmmac/common.h
index 19538057c24e..912bbb6515b2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -361,6 +361,7 @@ struct dma_features {
unsigned int vlins;
unsigned int dvlan;
unsigned int l3l4fnum;
+   unsigned int arpoffsel;
 };
 
 /* GMAC TX FIFO is 8K, Rx FIFO is 16K */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 9f568b54b339..36262ef8b70a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -1338,6 +1338,22 @@ static int dwxgmac2_config_l4_filter(struct 
mac_device_info *hw, u32 filter_no,
return 0;
 }
 
+static void dwxgmac2_set_arp_offload(struct mac_device_info *hw, bool en,
+u32 addr)
+{
+   void __iomem *ioaddr = hw->pcsr;
+   u32 value;
+
+   writel(addr, ioaddr + XGMAC_ARP_ADDR);
+
+   value = readl(ioaddr + XGMAC_RX_CONFIG);
+   if (en)
+   value |= XGMAC_CONFIG_ARPEN;
+   else
+   value &= ~XGMAC_CONFIG_ARPEN;
+   writel(value, ioaddr + XGMAC_RX_CONFIG);
+}
+
 const struct stmmac_ops dwxgmac210_ops = {
.core_init = dwxgmac2_core_init,
.set_mac = dwxgmac2_set_mac,
@@ -1380,6 +1396,7 @@ const struct stmmac_ops dwxgmac210_ops = {
.enable_vlan = dwxgmac2_enable_vlan,
.config_l3_filter = dwxgmac2_config_l3_filter,
.config_l4_filter = dwxgmac2_config_l4_filter,
+   .set_arp_offload = dwxgmac2_set_arp_offload,
 };
 
 int dwxgmac2_setup(struct stmmac_priv *priv)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
index fb0283b15c77..fd60bf5e0a72 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
@@ -370,6 +370,7 @@ static void dwxgmac2_get_hw_feature(void __iomem *ioaddr,
dma_cap->atime_stamp = (hw_cap & XGMAC_HWFEAT_TSSEL) >> 12;
dma_cap->av = (hw_cap & XGMAC_HWFEAT_AVSEL) >> 11;
dma_cap->av &= (hw_cap & XGMAC_HWFEAT_RAVSEL) >> 10;
+   dma_cap->arpoffsel = (hw_cap & XGMAC_HWFEAT_ARPOFFSEL) >> 9;
dma_cap->rmon = (hw_cap & XGMAC_HWFEAT_MMCSEL) >> 8;
dma_cap->pmt_magic_frame = (hw_cap & XGMAC_HWFEAT_MGKSEL) >> 7;
dma_cap->pmt_remote_wake_up = (hw_cap & XGMAC_HWFEAT_RWKSEL) >> 6;
diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h 
b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index 47c8ad9ec671..ddb851d99618 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -370,6 +370,7 @@ struct stmmac_ops {
int (*config_l4_filter)(struct mac_device_info *hw, u32 filter_no,
bool en, bool udp, bool sa, bool inv,
u32 match);
+   void (*set_arp_offload)(struct mac_device_info *hw, bool en, u32 addr);
 };
 
 #define stmmac_core_init(__priv, __args...) \
@@ -454,6 +455,8 @@ struct stmmac_ops {
stmmac_do_callback(__priv, mac, config_l3_filter, __args)
 #define stmmac_config_l4_filter(__priv, __args...) \
stmmac_do_callback(__priv, mac, config_l4_filter, __args)
+#define stmmac_set_arp_offload(__priv, __args...) \
+   stmmac_do_void_callback(__priv, mac, set_arp_offload, __args)
 
 /* PTP and HW Timer helpers */
 struct stmmac_hwtimestamp {
-- 
2.7.4



[PATCH net-next 02/13] net: stmmac: xgmac: Add RBU handling in DMA interrupt

2019-09-02 Thread Jose Abreu
Add the handling of Receive Buffer Unavailable interrupt in the DMA
handler of XGMAC cores.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
index 64956465c030..e77eb0ddf9b5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
@@ -322,6 +322,10 @@ static int dwxgmac2_dma_interrupt(void __iomem *ioaddr,
 
/* ABNORMAL interrupts */
if (unlikely(intr_status & XGMAC_AIS)) {
+   if (unlikely(intr_status & XGMAC_RBU)) {
+   x->rx_buf_unav_irq++;
+   ret |= handle_rx;
+   }
if (unlikely(intr_status & XGMAC_TPS)) {
x->tx_process_stopped_irq++;
ret |= tx_hard_error;
-- 
2.7.4



[PATCH net-next 09/13] net: stmmac: ethtool: Let user configure TX coalesce without RIWT

2019-09-02 Thread Jose Abreu
When RX Watchdog is disabled its currently not possible to configure TX
coalesce settings. Let user configure it anyway.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c| 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index 1c450105e5a6..1a768837ca72 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -746,8 +746,15 @@ static int stmmac_set_coalesce(struct net_device *dev,
(ec->tx_max_coalesced_frames_high) || (ec->rate_sample_interval))
return -EOPNOTSUPP;
 
-   if (ec->rx_coalesce_usecs == 0)
-   return -EINVAL;
+   if (priv->use_riwt && (ec->rx_coalesce_usecs > 0)) {
+   rx_riwt = stmmac_usec2riwt(ec->rx_coalesce_usecs, priv);
+
+   if ((rx_riwt > MAX_DMA_RIWT) || (rx_riwt < MIN_DMA_RIWT))
+   return -EINVAL;
+
+   priv->rx_riwt = rx_riwt;
+   stmmac_rx_watchdog(priv, priv->ioaddr, priv->rx_riwt, rx_cnt);
+   }
 
if ((ec->tx_coalesce_usecs == 0) &&
(ec->tx_max_coalesced_frames == 0))
@@ -757,20 +764,10 @@ static int stmmac_set_coalesce(struct net_device *dev,
(ec->tx_max_coalesced_frames > STMMAC_TX_MAX_FRAMES))
return -EINVAL;
 
-   rx_riwt = stmmac_usec2riwt(ec->rx_coalesce_usecs, priv);
-
-   if ((rx_riwt > MAX_DMA_RIWT) || (rx_riwt < MIN_DMA_RIWT))
-   return -EINVAL;
-   else if (!priv->use_riwt)
-   return -EOPNOTSUPP;
-
/* Only copy relevant parameters, ignore all others. */
priv->tx_coal_frames = ec->tx_max_coalesced_frames;
priv->tx_coal_timer = ec->tx_coalesce_usecs;
priv->rx_coal_frames = ec->rx_max_coalesced_frames;
-   priv->rx_riwt = rx_riwt;
-   stmmac_rx_watchdog(priv, priv->ioaddr, priv->rx_riwt, rx_cnt);
-
return 0;
 }
 
-- 
2.7.4



[PATCH net-next 03/13] net: stmmac: Do not return error code in TC Initialization

2019-09-02 Thread Jose Abreu
As we can still use the remaining TC callbacks, e.g. CBS. We should not
fail in the initialization only because RX Parser is not available.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
index 6c305b6ecad0..8dbbbf181ada 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
@@ -243,8 +243,9 @@ static int tc_init(struct stmmac_priv *priv)
struct dma_features *dma_cap = >dma_cap;
unsigned int count;
 
+   /* Fail silently as we can still use remaining features, e.g. CBS */
if (!dma_cap->frpsel)
-   return -EINVAL;
+   return 0;
 
switch (dma_cap->frpbs) {
case 0x0:
-- 
2.7.4



[PATCH net-next 10/13] net: stmmac: xgmac: Correct RAVSEL field interpretation

2019-09-02 Thread Jose Abreu
RAVSEL means that only RX side is available for AVB features. As we use
both TX and RX features we need to check if RAVSEL is selected and
disable AVB if only RX side is available.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
index fd60bf5e0a72..53c4a40d8386 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
@@ -369,7 +369,7 @@ static void dwxgmac2_get_hw_feature(void __iomem *ioaddr,
dma_cap->eee = (hw_cap & XGMAC_HWFEAT_EEESEL) >> 13;
dma_cap->atime_stamp = (hw_cap & XGMAC_HWFEAT_TSSEL) >> 12;
dma_cap->av = (hw_cap & XGMAC_HWFEAT_AVSEL) >> 11;
-   dma_cap->av &= (hw_cap & XGMAC_HWFEAT_RAVSEL) >> 10;
+   dma_cap->av &= !(hw_cap & XGMAC_HWFEAT_RAVSEL) >> 10;
dma_cap->arpoffsel = (hw_cap & XGMAC_HWFEAT_ARPOFFSEL) >> 9;
dma_cap->rmon = (hw_cap & XGMAC_HWFEAT_MMCSEL) >> 8;
dma_cap->pmt_magic_frame = (hw_cap & XGMAC_HWFEAT_MGKSEL) >> 7;
-- 
2.7.4



[PATCH net-next 08/13] net: stmmac: Only consider RX error when HW Timestamping is not enabled

2019-09-02 Thread Jose Abreu
Only consider that we have an error when HW Timestamping is not enabled
as this can give false positives due to the fact the RX Timestamping in
XGMAC and GMAC cores comes from context descriptors.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index c59c232aca64..5271c6129f0e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3511,9 +3511,10 @@ static int stmmac_rx(struct stmmac_priv *priv, int 
limit, u32 queue)
>xstats, rx_q->dma_erx + entry);
if (unlikely(status == discard_frame)) {
page_pool_recycle_direct(rx_q->page_pool, buf->page);
-   priv->dev->stats.rx_errors++;
buf->page = NULL;
error = 1;
+   if (!priv->hwts_rx_en)
+   priv->dev->stats.rx_errors++;
}
 
if (unlikely(error && (status & rx_not_ls)))
-- 
2.7.4



[PATCH net-next 11/13] net: stmmac: Correctly assing MAX MTU in XGMAC cores case

2019-09-02 Thread Jose Abreu
Maximum MTU for XGMAC cores is 16k thus the check for presence of XGMAC
shall be done first in order to assign correct value.

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 5271c6129f0e..c3baca9f587b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4542,10 +4542,10 @@ int stmmac_dvr_probe(struct device *device,
 
/* MTU range: 46 - hw-specific max */
ndev->min_mtu = ETH_ZLEN - ETH_HLEN;
-   if ((priv->plat->enh_desc) || (priv->synopsys_id >= DWMAC_CORE_4_00))
-   ndev->max_mtu = JUMBO_LEN;
-   else if (priv->plat->has_xgmac)
+   if (priv->plat->has_xgmac)
ndev->max_mtu = XGMAC_JUMBO_LEN;
+   else if ((priv->plat->enh_desc) || (priv->synopsys_id >= 
DWMAC_CORE_4_00))
+   ndev->max_mtu = JUMBO_LEN;
else
ndev->max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);
/* Will not overwrite ndev->max_mtu if plat->maxmtu > ndev->max_mtu
-- 
2.7.4



[PATCH net-next 00/13] net: stmmac: Improvements for -next

2019-09-02 Thread Jose Abreu
Couple of improvements for -next tree. More info in commit logs. Some of them
includes fixes for features that are only in -next tree.

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---

Jose Abreu (13):
  net: stmmac: selftests: Return proper error code to userspace
  net: stmmac: xgmac: Add RBU handling in DMA interrupt
  net: stmmac: Do not return error code in TC Initialization
  net: stmmac: Implement L3/L4 Filters using TC Flower
  net: stmmac: selftests: Add selftest for L3/L4 Filters
  net: stmmac: xgmac: Implement ARP Offload
  net: stmmac: selftests: Implement the ARP Offload test
  net: stmmac: Only consider RX error when HW Timestamping is not
enabled
  net: stmmac: ethtool: Let user configure TX coalesce without RIWT
  net: stmmac: xgmac: Correct RAVSEL field interpretation
  net: stmmac: Correctly assing MAX MTU in XGMAC cores case
  net: stmmac: xgmac: Enable RX Jumbo frame support
  net: stmmac: selftests: Add Jumbo Frame tests

 drivers/net/ethernet/stmicro/stmmac/common.h   |   2 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h |  33 +-
 .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c| 205 +-
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c |   8 +-
 drivers/net/ethernet/stmicro/stmmac/hwif.h |  19 +
 drivers/net/ethernet/stmicro/stmmac/stmmac.h   |  12 +
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   |  21 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |  18 +-
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 451 -
 drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c| 247 ++-
 10 files changed, 969 insertions(+), 47 deletions(-)

-- 
2.7.4



[PATCH net-next v3 02/12] net: stmmac: Prepare to add Split Header support

2019-08-17 Thread Jose Abreu
In order to add Split Header support, stmmac_rx() needs to take into
account that packet may be split accross multiple descriptors.

Refactor the logic of this function in order to support this scenario.

Changes from v2:
- Fixup if condition detection (Jakub)
- Don't stop NAPI with unfinished packet (Jakub)
- Use napi_alloc_skb() (Jakub)

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  |   6 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 149 +-
 2 files changed, 95 insertions(+), 60 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h 
b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index 80276587048a..56158e1448ac 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -74,6 +74,12 @@ struct stmmac_rx_queue {
u32 rx_zeroc_thresh;
dma_addr_t dma_rx_phy;
u32 rx_tail_addr;
+   unsigned int state_saved;
+   struct {
+   struct sk_buff *skb;
+   unsigned int len;
+   unsigned int error;
+   } state;
 };
 
 struct stmmac_channel {
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index b2e5f4ecd551..05f0fa7a6f02 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3353,9 +3353,10 @@ static int stmmac_rx(struct stmmac_priv *priv, int 
limit, u32 queue)
 {
struct stmmac_rx_queue *rx_q = >rx_queue[queue];
struct stmmac_channel *ch = >channel[queue];
+   unsigned int count = 0, error = 0, len = 0;
+   int status = 0, coe = priv->hw->rx_csum;
unsigned int next_entry = rx_q->cur_rx;
-   int coe = priv->hw->rx_csum;
-   unsigned int count = 0;
+   struct sk_buff *skb = NULL;
 
if (netif_msg_rx_status(priv)) {
void *rx_head;
@@ -3369,10 +3370,28 @@ static int stmmac_rx(struct stmmac_priv *priv, int 
limit, u32 queue)
stmmac_display_ring(priv, rx_head, DMA_RX_SIZE, true);
}
while (count < limit) {
+   enum pkt_hash_types hash_type;
struct stmmac_rx_buffer *buf;
+   unsigned int prev_len = 0;
struct dma_desc *np, *p;
-   int entry, status;
+   int entry;
+   u32 hash;
 
+   if (!count && rx_q->state_saved) {
+   skb = rx_q->state.skb;
+   error = rx_q->state.error;
+   len = rx_q->state.len;
+   } else {
+   rx_q->state_saved = false;
+   skb = NULL;
+   error = 0;
+   len = 0;
+   }
+
+   if (count >= limit)
+   break;
+
+read_again:
entry = next_entry;
buf = _q->buf_pool[entry];
 
@@ -3407,28 +3426,24 @@ static int stmmac_rx(struct stmmac_priv *priv, int 
limit, u32 queue)
page_pool_recycle_direct(rx_q->page_pool, buf->page);
priv->dev->stats.rx_errors++;
buf->page = NULL;
+   error = 1;
+   }
+
+   if (unlikely(error && (status & rx_not_ls)))
+   goto read_again;
+   if (unlikely(error)) {
+   if (skb)
+   dev_kfree_skb(skb);
+   continue;
+   }
+
+   /* Buffer is good. Go on. */
+
+   if (likely(status & rx_not_ls)) {
+   len += priv->dma_buf_sz;
} else {
-   enum pkt_hash_types hash_type;
-   struct sk_buff *skb;
-   unsigned int des;
-   int frame_len;
-   u32 hash;
-
-   stmmac_get_desc_addr(priv, p, );
-   frame_len = stmmac_get_rx_frame_len(priv, p, coe);
-
-   /*  If frame length is greater than skb buffer size
-*  (preallocated during init) then the packet is
-*  ignored
-*/
-   if (frame_len > priv->dma_buf_sz) {
-   if (net_ratelimit())
-   netdev_err(priv->dev,
-  "len %d larger than size 
(%d)\n",
- 

[PATCH net-next v3 09/12] net: stmmac: selftests: Add tests for SA Insertion/Replacement

2019-08-17 Thread Jose Abreu
Add 4 new tests:
- SA Insertion (register based)
- SA Insertion (descriptor based)
- SA Replacament (register based)
- SA Replacement (descriptor based)

Signed-off-by: Jose Abreu 

---
Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: Jose Abreu 
Cc: "David S. Miller" 
Cc: Maxime Coquelin 
Cc: net...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 98 +-
 1 file changed, 97 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index abab84f2ef8b..acfab86431b1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -45,6 +45,7 @@ struct stmmac_packet_attrs {
int size;
int remove_sa;
u8 id;
+   int sarc;
 };
 
 static u8 stmmac_test_next_id;
@@ -230,7 +231,10 @@ static int stmmac_test_loopback_validate(struct sk_buff 
*skb,
if (!ether_addr_equal(ehdr->h_dest, tpriv->packet->dst))
goto out;
}
-   if (tpriv->packet->src) {
+   if (tpriv->packet->sarc) {
+   if (!ether_addr_equal(ehdr->h_source, ehdr->h_dest))
+   goto out;
+   } else if (tpriv->packet->src) {
if (!ether_addr_equal(ehdr->h_source, tpriv->packet->src))
goto out;
}
@@ -1004,6 +1008,82 @@ static int stmmac_test_rxp(struct stmmac_priv *priv)
 }
 #endif
 
+static int stmmac_test_desc_sai(struct stmmac_priv *priv)
+{
+   unsigned char src[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+   struct stmmac_packet_attrs attr = { };
+   int ret;
+
+   attr.remove_sa = true;
+   attr.sarc = true;
+   attr.src = src;
+   attr.dst = priv->dev->dev_addr;
+
+   priv->sarc_type = 0x1;
+
+   ret = __stmmac_test_loopback(priv, );
+
+   priv->sarc_type = 0x0;
+   return ret;
+}
+
+static int stmmac_test_desc_sar(struct stmmac_priv *priv)
+{
+   unsigned char src[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+   struct stmmac_packet_attrs attr = { };
+   int ret;
+
+   attr.sarc = true;
+   attr.src = src;
+   attr.dst = priv->dev->dev_addr;
+
+   priv->sarc_type = 0x2;
+
+   ret = __stmmac_test_loopback(priv, );
+
+   priv->sarc_type = 0x0;
+   return ret;
+}
+
+static int stmmac_test_reg_sai(struct stmmac_priv *priv)
+{
+   unsigned char src[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+   struct stmmac_packet_attrs attr = { };
+   int ret;
+
+   attr.remove_sa = true;
+   attr.sarc = true;
+   attr.src = src;
+   attr.dst = priv->dev->dev_addr;
+
+   if (stmmac_sarc_configure(priv, priv->ioaddr, 0x2))
+   return -EOPNOTSUPP;
+
+   ret = __stmmac_test_loopback(priv, );
+
+   stmmac_sarc_configure(priv, priv->ioaddr, 0x0);
+   return ret;
+}
+
+static int stmmac_test_reg_sar(struct stmmac_priv *priv)
+{
+   unsigned char src[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+   struct stmmac_packet_attrs attr = { };
+   int ret;
+
+   attr.sarc = true;
+   attr.src = src;
+   attr.dst = priv->dev->dev_addr;
+
+   if (stmmac_sarc_configure(priv, priv->ioaddr, 0x3))
+   return -EOPNOTSUPP;
+
+   ret = __stmmac_test_loopback(priv, );
+
+   stmmac_sarc_configure(priv, priv->ioaddr, 0x0);
+   return ret;
+}
+
 #define STMMAC_LOOPBACK_NONE   0
 #define STMMAC_LOOPBACK_MAC1
 #define STMMAC_LOOPBACK_PHY2
@@ -1065,6 +1145,22 @@ static const struct stmmac_test {
.name = "Flexible RX Parser   ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_rxp,
+   }, {
+   .name = "SA Insertion (desc)  ",
+   .lb = STMMAC_LOOPBACK_PHY,
+   .fn = stmmac_test_desc_sai,
+   }, {
+   .name = "SA Replacement (desc)",
+   .lb = STMMAC_LOOPBACK_PHY,
+   .fn = stmmac_test_desc_sar,
+   }, {
+   .name = "SA Insertion (reg)  ",
+   .lb = STMMAC_LOOPBACK_PHY,
+   .fn = stmmac_test_reg_sai,
+   }, {
+   .name = "SA Replacement (reg)",
+   .lb = STMMAC_LOOPBACK_PHY,
+   .fn = stmmac_test_reg_sar,
},
 };
 
-- 
2.7.4



  1   2   3   4   5   6   7   8   9   10   >