]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: dsa: b53: convert to phylink_pcs
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Fri, 29 Apr 2022 16:43:03 +0000 (09:43 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sun, 1 May 2022 16:51:06 +0000 (17:51 +0100)
Convert B53 to use phylink_pcs for the serdes rather than hooking it
into the MAC-layer callbacks.

Fixes: 5df47164bbbf ("net: dsa: b53: mark as non-legacy")
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Tested-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/b53/b53_common.c
drivers/net/dsa/b53/b53_priv.h
drivers/net/dsa/b53/b53_serdes.c
drivers/net/dsa/b53/b53_serdes.h
drivers/net/dsa/b53/b53_srab.c

index 77501f9c59159e4ad3870ba7b2cd9ef14108dc93..fbb32aa49b2412fcbfbb03c50cd1b7035df1fa07 100644 (file)
@@ -1354,46 +1354,25 @@ static void b53_phylink_get_caps(struct dsa_switch *ds, int port,
        config->legacy_pre_march2020 = false;
 }
 
-int b53_phylink_mac_link_state(struct dsa_switch *ds, int port,
-                              struct phylink_link_state *state)
+static struct phylink_pcs *b53_phylink_mac_select_pcs(struct dsa_switch *ds,
+                                                     int port,
+                                                     phy_interface_t interface)
 {
        struct b53_device *dev = ds->priv;
-       int ret = -EOPNOTSUPP;
 
-       if ((phy_interface_mode_is_8023z(state->interface) ||
-            state->interface == PHY_INTERFACE_MODE_SGMII) &&
-            dev->ops->serdes_link_state)
-               ret = dev->ops->serdes_link_state(dev, port, state);
+       if (!dev->ops->phylink_mac_select_pcs)
+               return NULL;
 
-       return ret;
+       return dev->ops->phylink_mac_select_pcs(dev, port, interface);
 }
-EXPORT_SYMBOL(b53_phylink_mac_link_state);
 
 void b53_phylink_mac_config(struct dsa_switch *ds, int port,
                            unsigned int mode,
                            const struct phylink_link_state *state)
 {
-       struct b53_device *dev = ds->priv;
-
-       if (mode == MLO_AN_PHY || mode == MLO_AN_FIXED)
-               return;
-
-       if ((phy_interface_mode_is_8023z(state->interface) ||
-            state->interface == PHY_INTERFACE_MODE_SGMII) &&
-            dev->ops->serdes_config)
-               dev->ops->serdes_config(dev, port, mode, state);
 }
 EXPORT_SYMBOL(b53_phylink_mac_config);
 
-void b53_phylink_mac_an_restart(struct dsa_switch *ds, int port)
-{
-       struct b53_device *dev = ds->priv;
-
-       if (dev->ops->serdes_an_restart)
-               dev->ops->serdes_an_restart(dev, port);
-}
-EXPORT_SYMBOL(b53_phylink_mac_an_restart);
-
 void b53_phylink_mac_link_down(struct dsa_switch *ds, int port,
                               unsigned int mode,
                               phy_interface_t interface)
@@ -2269,9 +2248,8 @@ static const struct dsa_switch_ops b53_switch_ops = {
        .phy_write              = b53_phy_write16,
        .adjust_link            = b53_adjust_link,
        .phylink_get_caps       = b53_phylink_get_caps,
-       .phylink_mac_link_state = b53_phylink_mac_link_state,
+       .phylink_mac_select_pcs = b53_phylink_mac_select_pcs,
        .phylink_mac_config     = b53_phylink_mac_config,
-       .phylink_mac_an_restart = b53_phylink_mac_an_restart,
        .phylink_mac_link_down  = b53_phylink_mac_link_down,
        .phylink_mac_link_up    = b53_phylink_mac_link_up,
        .port_enable            = b53_enable_port,
index 3085b6cc7d407e935b98a262d65d04853b9f591f..795cbffd5c2be43a468c46371fe8c2aa161ef507 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <linux/kernel.h>
 #include <linux/mutex.h>
-#include <linux/phy.h>
+#include <linux/phylink.h>
 #include <linux/etherdevice.h>
 #include <net/dsa.h>
 
@@ -29,7 +29,6 @@
 
 struct b53_device;
 struct net_device;
-struct phylink_link_state;
 
 struct b53_io_ops {
        int (*read8)(struct b53_device *dev, u8 page, u8 reg, u8 *value);
@@ -48,13 +47,10 @@ struct b53_io_ops {
        void (*irq_disable)(struct b53_device *dev, int port);
        void (*phylink_get_caps)(struct b53_device *dev, int port,
                                 struct phylink_config *config);
+       struct phylink_pcs *(*phylink_mac_select_pcs)(struct b53_device *dev,
+                                                     int port,
+                                                     phy_interface_t interface);
        u8 (*serdes_map_lane)(struct b53_device *dev, int port);
-       int (*serdes_link_state)(struct b53_device *dev, int port,
-                                struct phylink_link_state *state);
-       void (*serdes_config)(struct b53_device *dev, int port,
-                             unsigned int mode,
-                             const struct phylink_link_state *state);
-       void (*serdes_an_restart)(struct b53_device *dev, int port);
        void (*serdes_link_set)(struct b53_device *dev, int port,
                                unsigned int mode, phy_interface_t interface,
                                bool link_up);
@@ -85,8 +81,15 @@ enum {
        BCM7278_DEVICE_ID = 0x7278,
 };
 
+struct b53_pcs {
+       struct phylink_pcs pcs;
+       struct b53_device *dev;
+       u8 lane;
+};
+
 #define B53_N_PORTS    9
 #define B53_N_PORTS_25 6
+#define B53_N_PCS      2
 
 struct b53_port {
        u16             vlan_ctl_mask;
@@ -143,6 +146,8 @@ struct b53_device {
        bool vlan_enabled;
        unsigned int num_ports;
        struct b53_port *ports;
+
+       struct b53_pcs pcs[B53_N_PCS];
 };
 
 #define b53_for_each_port(dev, i) \
@@ -336,12 +341,9 @@ int b53_br_flags(struct dsa_switch *ds, int port,
                 struct netlink_ext_ack *extack);
 int b53_setup_devlink_resources(struct dsa_switch *ds);
 void b53_port_event(struct dsa_switch *ds, int port);
-int b53_phylink_mac_link_state(struct dsa_switch *ds, int port,
-                              struct phylink_link_state *state);
 void b53_phylink_mac_config(struct dsa_switch *ds, int port,
                            unsigned int mode,
                            const struct phylink_link_state *state);
-void b53_phylink_mac_an_restart(struct dsa_switch *ds, int port);
 void b53_phylink_mac_link_down(struct dsa_switch *ds, int port,
                               unsigned int mode,
                               phy_interface_t interface);
index 555e5b3723215d5d69ef9a975f699b908250ad3f..0690210770ffec1d26a4366236c6d1bf50636e1e 100644 (file)
 #include "b53_serdes.h"
 #include "b53_regs.h"
 
+static inline struct b53_pcs *pcs_to_b53_pcs(struct phylink_pcs *pcs)
+{
+       return container_of(pcs, struct b53_pcs, pcs);
+}
+
 static void b53_serdes_write_blk(struct b53_device *dev, u8 offset, u16 block,
                                 u16 value)
 {
@@ -60,51 +65,47 @@ static u16 b53_serdes_read(struct b53_device *dev, u8 lane,
        return b53_serdes_read_blk(dev, offset, block);
 }
 
-void b53_serdes_config(struct b53_device *dev, int port, unsigned int mode,
-                      const struct phylink_link_state *state)
+static int b53_serdes_config(struct phylink_pcs *pcs, unsigned int mode,
+                            phy_interface_t interface,
+                            const unsigned long *advertising,
+                            bool permit_pause_to_mac)
 {
-       u8 lane = b53_serdes_map_lane(dev, port);
+       struct b53_device *dev = pcs_to_b53_pcs(pcs)->dev;
+       u8 lane = pcs_to_b53_pcs(pcs)->lane;
        u16 reg;
 
-       if (lane == B53_INVALID_LANE)
-               return;
-
        reg = b53_serdes_read(dev, lane, B53_SERDES_DIGITAL_CONTROL(1),
                              SERDES_DIGITAL_BLK);
-       if (state->interface == PHY_INTERFACE_MODE_1000BASEX)
+       if (interface == PHY_INTERFACE_MODE_1000BASEX)
                reg |= FIBER_MODE_1000X;
        else
                reg &= ~FIBER_MODE_1000X;
        b53_serdes_write(dev, lane, B53_SERDES_DIGITAL_CONTROL(1),
                         SERDES_DIGITAL_BLK, reg);
+
+       return 0;
 }
-EXPORT_SYMBOL(b53_serdes_config);
 
-void b53_serdes_an_restart(struct b53_device *dev, int port)
+static void b53_serdes_an_restart(struct phylink_pcs *pcs)
 {
-       u8 lane = b53_serdes_map_lane(dev, port);
+       struct b53_device *dev = pcs_to_b53_pcs(pcs)->dev;
+       u8 lane = pcs_to_b53_pcs(pcs)->lane;
        u16 reg;
 
-       if (lane == B53_INVALID_LANE)
-               return;
-
        reg = b53_serdes_read(dev, lane, B53_SERDES_MII_REG(MII_BMCR),
                              SERDES_MII_BLK);
        reg |= BMCR_ANRESTART;
        b53_serdes_write(dev, lane, B53_SERDES_MII_REG(MII_BMCR),
                         SERDES_MII_BLK, reg);
 }
-EXPORT_SYMBOL(b53_serdes_an_restart);
 
-int b53_serdes_link_state(struct b53_device *dev, int port,
-                         struct phylink_link_state *state)
+static void b53_serdes_get_state(struct phylink_pcs *pcs,
+                                 struct phylink_link_state *state)
 {
-       u8 lane = b53_serdes_map_lane(dev, port);
+       struct b53_device *dev = pcs_to_b53_pcs(pcs)->dev;
+       u8 lane = pcs_to_b53_pcs(pcs)->lane;
        u16 dig, bmsr;
 
-       if (lane == B53_INVALID_LANE)
-               return 1;
-
        dig = b53_serdes_read(dev, lane, B53_SERDES_DIGITAL_STATUS,
                              SERDES_DIGITAL_BLK);
        bmsr = b53_serdes_read(dev, lane, B53_SERDES_MII_REG(MII_BMSR),
@@ -133,10 +134,7 @@ int b53_serdes_link_state(struct b53_device *dev, int port,
                state->pause |= MLO_PAUSE_RX;
        if (dig & PAUSE_RESOLUTION_TX_SIDE)
                state->pause |= MLO_PAUSE_TX;
-
-       return 0;
 }
-EXPORT_SYMBOL(b53_serdes_link_state);
 
 void b53_serdes_link_set(struct b53_device *dev, int port, unsigned int mode,
                         phy_interface_t interface, bool link_up)
@@ -158,6 +156,12 @@ void b53_serdes_link_set(struct b53_device *dev, int port, unsigned int mode,
 }
 EXPORT_SYMBOL(b53_serdes_link_set);
 
+static const struct phylink_pcs_ops b53_pcs_ops = {
+       .pcs_get_state = b53_serdes_get_state,
+       .pcs_config = b53_serdes_config,
+       .pcs_an_restart = b53_serdes_an_restart,
+};
+
 void b53_serdes_phylink_get_caps(struct b53_device *dev, int port,
                                 struct phylink_config *config)
 {
@@ -187,9 +191,28 @@ void b53_serdes_phylink_get_caps(struct b53_device *dev, int port,
 }
 EXPORT_SYMBOL(b53_serdes_phylink_get_caps);
 
+struct phylink_pcs *b53_serdes_phylink_mac_select_pcs(struct b53_device *dev,
+                                                     int port,
+                                                     phy_interface_t interface)
+{
+       u8 lane = b53_serdes_map_lane(dev, port);
+
+       if (lane == B53_INVALID_LANE || lane >= B53_N_PCS ||
+           !dev->pcs[lane].dev)
+               return NULL;
+
+       if (!phy_interface_mode_is_8023z(interface) &&
+           interface != PHY_INTERFACE_MODE_SGMII)
+               return NULL;
+
+       return &dev->pcs[lane].pcs;
+}
+EXPORT_SYMBOL(b53_serdes_phylink_mac_select_pcs);
+
 int b53_serdes_init(struct b53_device *dev, int port)
 {
        u8 lane = b53_serdes_map_lane(dev, port);
+       struct b53_pcs *pcs;
        u16 id0, msb, lsb;
 
        if (lane == B53_INVALID_LANE)
@@ -212,6 +235,11 @@ int b53_serdes_init(struct b53_device *dev, int port)
                 (id0 >> SERDES_ID0_REV_NUM_SHIFT) & SERDES_ID0_REV_NUM_MASK,
                 (u32)msb << 16 | lsb);
 
+       pcs = &dev->pcs[lane];
+       pcs->dev = dev;
+       pcs->lane = lane;
+       pcs->pcs.ops = &b53_pcs_ops;
+
        return 0;
 }
 EXPORT_SYMBOL(b53_serdes_init);
index f47d5caa75576a8d2f10328d477668fdf2a34411..ef81f5da5f81fec0007b3b2987fa6c2786844043 100644 (file)
@@ -107,14 +107,11 @@ static inline u8 b53_serdes_map_lane(struct b53_device *dev, int port)
        return dev->ops->serdes_map_lane(dev, port);
 }
 
-int b53_serdes_get_link(struct b53_device *dev, int port);
-int b53_serdes_link_state(struct b53_device *dev, int port,
-                         struct phylink_link_state *state);
-void b53_serdes_config(struct b53_device *dev, int port, unsigned int mode,
-                      const struct phylink_link_state *state);
-void b53_serdes_an_restart(struct b53_device *dev, int port);
 void b53_serdes_link_set(struct b53_device *dev, int port, unsigned int mode,
                         phy_interface_t interface, bool link_up);
+struct phylink_pcs *b53_serdes_phylink_mac_select_pcs(struct b53_device *dev,
+                                                     int port,
+                                                     phy_interface_t interface);
 void b53_serdes_phylink_get_caps(struct b53_device *dev, int port,
                                 struct phylink_config *config);
 #if IS_ENABLED(CONFIG_B53_SERDES)
index c51b716657db3b75cdd8f31cec76cc5bfd20a761..da0b889880f6af57dd4ed4189e06efb68ee003b5 100644 (file)
@@ -491,10 +491,8 @@ static const struct b53_io_ops b53_srab_ops = {
        .irq_disable = b53_srab_irq_disable,
        .phylink_get_caps = b53_srab_phylink_get_caps,
 #if IS_ENABLED(CONFIG_B53_SERDES)
+       .phylink_mac_select_pcs = b53_serdes_phylink_mac_select_pcs,
        .serdes_map_lane = b53_srab_serdes_map_lane,
-       .serdes_link_state = b53_serdes_link_state,
-       .serdes_config = b53_serdes_config,
-       .serdes_an_restart = b53_serdes_an_restart,
        .serdes_link_set = b53_serdes_link_set,
 #endif
 };