Author: nbd
Date: 2015-01-24 20:41:55 +0100 (Sat, 24 Jan 2015)
New Revision: 44102

Modified:
   trunk/target/linux/generic/files/drivers/net/phy/ar8216.c
   trunk/target/linux/generic/files/drivers/net/phy/ar8216.h
Log:
ar8216: add link change detection for switch ports

Check for switch port link changes and
- flush ATU in case of a change
- report link change via syslog

Signed-off-by: Heiner Kallweit <[email protected]>

Modified: trunk/target/linux/generic/files/drivers/net/phy/ar8216.c
===================================================================
--- trunk/target/linux/generic/files/drivers/net/phy/ar8216.c   2015-01-24 
19:41:51 UTC (rev 44101)
+++ trunk/target/linux/generic/files/drivers/net/phy/ar8216.c   2015-01-24 
19:41:55 UTC (rev 44102)
@@ -1707,12 +1707,47 @@
        return 0;
 }
 
+static bool
+ar8xxx_check_link_states(struct ar8xxx_priv *priv)
+{
+       bool link_new, changed = false;
+       u32 status;
+       int i;
+
+       mutex_lock(&priv->reg_mutex);
+
+       for (i = 0; i < priv->dev.ports; i++) {
+               status = priv->chip->read_port_status(priv, i);
+               link_new = !!(status & AR8216_PORT_STATUS_LINK_UP);
+               if (link_new == priv->link_up[i])
+                       continue;
+
+               priv->link_up[i] = link_new;
+               changed = true;
+               dev_info(&priv->phy->dev, "Port %d is %s\n",
+                        i, link_new ? "up" : "down");
+       }
+
+       if (changed)
+               priv->chip->atu_flush(priv);
+
+       mutex_unlock(&priv->reg_mutex);
+
+       return changed;
+}
+
 static int
 ar8xxx_phy_read_status(struct phy_device *phydev)
 {
        struct ar8xxx_priv *priv = phydev->priv;
        struct switch_port_link link;
 
+       /* check for link changes and flush ATU
+        * if a change was detected
+        */
+       if (phydev->state == PHY_CHANGELINK)
+               ar8xxx_check_link_states(priv);
+
        if (phydev->addr != 0)
                return genphy_read_status(phydev);
 

Modified: trunk/target/linux/generic/files/drivers/net/phy/ar8216.h
===================================================================
--- trunk/target/linux/generic/files/drivers/net/phy/ar8216.h   2015-01-24 
19:41:51 UTC (rev 44101)
+++ trunk/target/linux/generic/files/drivers/net/phy/ar8216.h   2015-01-24 
19:41:55 UTC (rev 44102)
@@ -396,6 +396,7 @@
        bool initialized;
        bool port4_phy;
        char buf[2048];
+       bool link_up[AR8X16_MAX_PORTS];
 
        bool init;
 
_______________________________________________
openwrt-commits mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-commits

Reply via email to