ath79: use downstream ag71xx for Kernel 5.4

The ag71xx driver from Linux 5.4 currently has various shortcomings
when used with OpenWrt compared to our downstream version.

For example, the upstream driver does not support modifying the ethernet
clock and configuring RGMII delays on the MAC side.

While we should certainly switch to the upstream driver, the amount of
necessary patches would make it cumbersome to work with. It's also
highly likely we won't be able to finish patching the upstream driver in
time for a Linux 5.4 release.

Tested on Siemens WS-AP3610.

CC: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: David Bauer <mail@david-bauer.net>
Acked-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
David Bauer 2020-03-13 01:07:39 +01:00
parent 0933d1363b
commit 32726846c8
14 changed files with 37 additions and 178 deletions

View File

@ -1,4 +1,6 @@
CONFIG_AG71XX=y
# CONFIG_AG71XX_DEBUG is not set
CONFIG_AG71XX_DEBUG_FS=y
CONFIG_AR8216_PHY=y
CONFIG_AR8216_PHY_LEDS=y
CONFIG_ARCH_32BIT_OFF_T=y

View File

@ -1581,11 +1581,15 @@ static int ag71xx_probe(struct platform_device *pdev)
ag->stop_desc->next = (u32) ag->stop_desc_dma;
mac_addr = of_get_mac_address(np);
if (mac_addr)
memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
if (!mac_addr || !is_valid_ether_addr(dev->dev_addr)) {
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0))
if (!mac_addr || !is_valid_ether_addr(mac_addr)) {
#else
if (IS_ERR(mac_addr) || !is_valid_ether_addr(mac_addr)) {
#endif
dev_err(&pdev->dev, "invalid MAC address, using random address\n");
eth_random_addr(dev->dev_addr);
} else {
memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
}
ag->phy_if_mode = of_get_phy_mode(np);

View File

@ -1,61 +0,0 @@
From 2cee757eaf5cc6175bc0ac7b0b808794124ec40a Mon Sep 17 00:00:00 2001
From: Hauke Mehrtens <hauke@hauke-m.de>
Date: Mon, 17 Feb 2020 23:40:14 +0100
Subject: [PATCH 1/3] ag71xx: Handle allocation errors in ag71xx_rings_init()
Free the allocated resources in ag71xx_rings_init() in case
ag71xx_ring_rx_init() returns an error.
This is only a potential problem, I did not ran into this one.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Fixes: d51b6ce441d3 ("net: ethernet: add ag71xx driver")
---
drivers/net/ethernet/atheros/ag71xx.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
--- a/drivers/net/ethernet/atheros/ag71xx.c
+++ b/drivers/net/ethernet/atheros/ag71xx.c
@@ -1133,6 +1133,7 @@ static int ag71xx_rings_init(struct ag71
struct ag71xx_ring *tx = &ag->tx_ring;
struct ag71xx_ring *rx = &ag->rx_ring;
int ring_size, tx_size;
+ int ret;
ring_size = BIT(tx->order) + BIT(rx->order);
tx_size = BIT(tx->order);
@@ -1145,9 +1146,8 @@ static int ag71xx_rings_init(struct ag71
ring_size * AG71XX_DESC_SIZE,
&tx->descs_dma, GFP_KERNEL);
if (!tx->descs_cpu) {
- kfree(tx->buf);
- tx->buf = NULL;
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto err_free_buf;
}
rx->buf = &tx->buf[tx_size];
@@ -1155,7 +1155,21 @@ static int ag71xx_rings_init(struct ag71
rx->descs_dma = tx->descs_dma + tx_size * AG71XX_DESC_SIZE;
ag71xx_ring_tx_init(ag);
- return ag71xx_ring_rx_init(ag);
+ ret = ag71xx_ring_rx_init(ag);
+ if (ret)
+ goto err_free_dma;
+
+ return 0;
+
+err_free_dma:
+ dma_free_coherent(&ag->pdev->dev, ring_size * AG71XX_DESC_SIZE,
+ tx->descs_cpu, tx->descs_dma);
+ rx->buf = NULL;
+err_free_buf:
+ kfree(tx->buf);
+ tx->buf = NULL;
+
+ return ret;
}
static void ag71xx_rings_free(struct ag71xx *ag)

View File

@ -1,45 +0,0 @@
From 2f8c5a68d0030ae5e65fca1bf5ca44929d5b3b06 Mon Sep 17 00:00:00 2001
From: Hauke Mehrtens <hauke@hauke-m.de>
Date: Mon, 17 Feb 2020 23:50:23 +0100
Subject: [PATCH 2/3] ag71xx: Call ag71xx_hw_disable() in case phy_conenct
fails
When the ag71xx_phy_connect() failed only parts of the actions done
previously in this function wrere reverted, because only
ag71xx_rings_cleanup() was called. My system crashed the next time
open() was called because napi_disable() was not called again and this
resulted in two calls to napi_enable(), which is not allowed.
Fix this by disabling the device again.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Fixes: d51b6ce441d3 ("net: ethernet: add ag71xx driver")
---
drivers/net/ethernet/atheros/ag71xx.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--- a/drivers/net/ethernet/atheros/ag71xx.c
+++ b/drivers/net/ethernet/atheros/ag71xx.c
@@ -1263,18 +1263,18 @@ static int ag71xx_open(struct net_device
ret = ag71xx_hw_enable(ag);
if (ret)
- goto err;
+ return ret;
ret = ag71xx_phy_connect(ag);
if (ret)
- goto err;
+ goto err_hw_disable;
phy_start(ndev->phydev);
return 0;
-err:
- ag71xx_rings_cleanup(ag);
+err_hw_disable:
+ ag71xx_hw_disable(ag);
return ret;
}

View File

@ -1,69 +0,0 @@
From d42c6bf2752a46bdf3931bd6e56db419742fbb20 Mon Sep 17 00:00:00 2001
From: Hauke Mehrtens <hauke@hauke-m.de>
Date: Mon, 17 Feb 2020 23:55:22 +0100
Subject: [PATCH 3/3] ag71xx: Run ag71xx_link_adjust() only when needed
My system printed this line every second:
ag71xx 19000000.eth eth0: Link is Up - 1Gbps/Full - flow control off
The function ag71xx_phy_link_adjust() was called by the PHY layer every
second even when nothing changed.
With this patch the old status is stored and the real
ag71xx_link_adjust() function is only called when when something really
changed. This way the update and also this print is only done once any
more.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Fixes: d51b6ce441d3 ("net: ethernet: add ag71xx driver")
---
drivers/net/ethernet/atheros/ag71xx.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
--- a/drivers/net/ethernet/atheros/ag71xx.c
+++ b/drivers/net/ethernet/atheros/ag71xx.c
@@ -307,6 +307,10 @@ struct ag71xx {
u32 msg_enable;
const struct ag71xx_dcfg *dcfg;
+ unsigned int link;
+ unsigned int speed;
+ int duplex;
+
/* From this point onwards we're not looking at per-packet fields. */
void __iomem *mac_base;
@@ -854,6 +858,7 @@ static void ag71xx_link_adjust(struct ag
if (!phydev->link && update) {
ag71xx_hw_stop(ag);
+ phy_print_status(phydev);
return;
}
@@ -907,8 +912,25 @@ static void ag71xx_link_adjust(struct ag
static void ag71xx_phy_link_adjust(struct net_device *ndev)
{
struct ag71xx *ag = netdev_priv(ndev);
+ struct phy_device *phydev = ndev->phydev;
+ int status_change = 0;
+
+ if (phydev->link) {
+ if (ag->duplex != phydev->duplex
+ || ag->speed != phydev->speed) {
+ status_change = 1;
+ }
+ }
+
+ if (phydev->link != ag->link)
+ status_change = 1;
+
+ ag->link = phydev->link;
+ ag->duplex = phydev->duplex;
+ ag->speed = phydev->speed;
- ag71xx_link_adjust(ag, true);
+ if (status_change)
+ ag71xx_link_adjust(ag, true);
}
static int ag71xx_phy_connect(struct ag71xx *ag)

View File

@ -0,0 +1,28 @@
--- a/drivers/net/ethernet/atheros/Kconfig
+++ b/drivers/net/ethernet/atheros/Kconfig
@@ -17,13 +17,7 @@ config NET_VENDOR_ATHEROS
if NET_VENDOR_ATHEROS
-config AG71XX
- tristate "Atheros AR7XXX/AR9XXX built-in ethernet mac support"
- depends on ATH79
- select PHYLIB
- help
- If you wish to compile a kernel for AR7XXX/91XXX and enable
- ethernet support, then you should always answer Y to this.
+source "drivers/net/ethernet/atheros/ag71xx/Kconfig"
config ATL2
tristate "Atheros L2 Fast Ethernet support"
--- a/drivers/net/ethernet/atheros/Makefile
+++ b/drivers/net/ethernet/atheros/Makefile
@@ -3,7 +3,7 @@
# Makefile for the Atheros network device drivers.
#
-obj-$(CONFIG_AG71XX) += ag71xx.o
+obj-$(CONFIG_AG71XX) += ag71xx/
obj-$(CONFIG_ATL1) += atlx/
obj-$(CONFIG_ATL2) += atlx/
obj-$(CONFIG_ATL1E) += atl1e/