ath79: Make upstream ag71xx driver work
[openwrt/staging/jogo.git] / target / linux / ath79 / patches-5.4 / 202-ag71xx-Run-ag71xx_link_adjust-only-when-needed.patch
1 From d42c6bf2752a46bdf3931bd6e56db419742fbb20 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Mon, 17 Feb 2020 23:55:22 +0100
4 Subject: [PATCH 3/3] ag71xx: Run ag71xx_link_adjust() only when needed
5
6 My system printed this line every second:
7 ag71xx 19000000.eth eth0: Link is Up - 1Gbps/Full - flow control off
8 The function ag71xx_phy_link_adjust() was called by the PHY layer every
9 second even when nothing changed.
10
11 With this patch the old status is stored and the real
12 ag71xx_link_adjust() function is only called when when something really
13 changed. This way the update and also this print is only done once any
14 more.
15
16 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
17 Fixes: d51b6ce441d3 ("net: ethernet: add ag71xx driver")
18 ---
19 drivers/net/ethernet/atheros/ag71xx.c | 24 +++++++++++++++++++++++-
20 1 file changed, 23 insertions(+), 1 deletion(-)
21
22 --- a/drivers/net/ethernet/atheros/ag71xx.c
23 +++ b/drivers/net/ethernet/atheros/ag71xx.c
24 @@ -307,6 +307,10 @@ struct ag71xx {
25 u32 msg_enable;
26 const struct ag71xx_dcfg *dcfg;
27
28 + unsigned int link;
29 + unsigned int speed;
30 + int duplex;
31 +
32 /* From this point onwards we're not looking at per-packet fields. */
33 void __iomem *mac_base;
34
35 @@ -854,6 +858,7 @@ static void ag71xx_link_adjust(struct ag
36
37 if (!phydev->link && update) {
38 ag71xx_hw_stop(ag);
39 + phy_print_status(phydev);
40 return;
41 }
42
43 @@ -907,8 +912,25 @@ static void ag71xx_link_adjust(struct ag
44 static void ag71xx_phy_link_adjust(struct net_device *ndev)
45 {
46 struct ag71xx *ag = netdev_priv(ndev);
47 + struct phy_device *phydev = ndev->phydev;
48 + int status_change = 0;
49 +
50 + if (phydev->link) {
51 + if (ag->duplex != phydev->duplex
52 + || ag->speed != phydev->speed) {
53 + status_change = 1;
54 + }
55 + }
56 +
57 + if (phydev->link != ag->link)
58 + status_change = 1;
59 +
60 + ag->link = phydev->link;
61 + ag->duplex = phydev->duplex;
62 + ag->speed = phydev->speed;
63
64 - ag71xx_link_adjust(ag, true);
65 + if (status_change)
66 + ag71xx_link_adjust(ag, true);
67 }
68
69 static int ag71xx_phy_connect(struct ag71xx *ag)