net: dsa: mv88e6xxx: Only reconfigure MAC when something changes
authorAndrew Lunn <andrew@lunn.ch>
Thu, 18 Apr 2019 01:11:39 +0000 (03:11 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 19 Apr 2019 21:08:21 +0000 (14:08 -0700)
phylink will call the mac_config() callback once per second when
polling a PHY or a fixed link. The MAC driver is not supposed to
reconfigure the MAC if nothing has changed.

Make the mv88e6xxx driver look at the current configuration of the
port, and return early if nothing has changed.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/mv88e6xxx/chip.c

index 65da6709a17336faf348d3935ed82eb3679f72c1..bfd5a7faef3b878338b414c8e1b0dc01f85e8b29 100644 (file)
@@ -553,11 +553,28 @@ int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port, int link,
                             int speed, int duplex, int pause,
                             phy_interface_t mode)
 {
+       struct phylink_link_state state;
        int err;
 
        if (!chip->info->ops->port_set_link)
                return 0;
 
+       if (!chip->info->ops->port_link_state)
+               return 0;
+
+       err = chip->info->ops->port_link_state(chip, port, &state);
+       if (err)
+               return err;
+
+       /* Has anything actually changed? We don't expect the
+        * interface mode to change without one of the other
+        * parameters also changing
+        */
+       if (state.link == link &&
+           state.speed == speed &&
+           state.duplex == duplex)
+               return 0;
+
        /* Port's MAC control must not be changed unless the link is down */
        err = chip->info->ops->port_set_link(chip, port, 0);
        if (err)