net: macb: Disable PCS auto-negotiation for SGMII fixed-link mode
authorRobert Hancock <robert.hancock@calian.com>
Thu, 11 Mar 2021 20:18:13 +0000 (14:18 -0600)
committerDavid S. Miller <davem@davemloft.net>
Sat, 13 Mar 2021 00:44:45 +0000 (16:44 -0800)
When using a fixed-link configuration in SGMII mode, it's not really
sensible to have auto-negotiation enabled since the link settings are
fixed by definition. In other configurations, such as an SGMII
connection to a PHY, it should generally be enabled.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/cadence/macb.h
drivers/net/ethernet/cadence/macb_main.c

index d8c6890..d8d8721 100644 (file)
 #define GEM_PEFTN              0x01f4 /* PTP Peer Event Frame Tx Ns */
 #define GEM_PEFRSL             0x01f8 /* PTP Peer Event Frame Rx Sec Low */
 #define GEM_PEFRN              0x01fc /* PTP Peer Event Frame Rx Ns */
+#define GEM_PCSCNTRL           0x0200 /* PCS Control */
+#define GEM_PCSSTS             0x0204 /* PCS Status */
+#define GEM_PCSPHYTOPID                0x0208 /* PCS PHY Top ID */
+#define GEM_PCSPHYBOTID                0x020c /* PCS PHY Bottom ID */
+#define GEM_PCSANADV           0x0210 /* PCS AN Advertisement */
+#define GEM_PCSANLPBASE                0x0214 /* PCS AN Link Partner Base */
+#define GEM_PCSANEXP           0x0218 /* PCS AN Expansion */
+#define GEM_PCSANNPTX          0x021c /* PCS AN Next Page TX */
+#define GEM_PCSANNPLP          0x0220 /* PCS AN Next Page LP */
+#define GEM_PCSANEXTSTS                0x023c /* PCS AN Extended Status */
 #define GEM_DCFG1              0x0280 /* Design Config 1 */
 #define GEM_DCFG2              0x0284 /* Design Config 2 */
 #define GEM_DCFG3              0x0288 /* Design Config 3 */
 #define GEM_HS_MAC_SPEED_OFFSET                        0
 #define GEM_HS_MAC_SPEED_SIZE                  3
 
+/* Bitfields in PCSCNTRL */
+#define GEM_PCSAUTONEG_OFFSET                  12
+#define GEM_PCSAUTONEG_SIZE                    1
+
 /* Bitfields in DCFG1. */
 #define GEM_IRQCOR_OFFSET                      23
 #define GEM_IRQCOR_SIZE                                1
index ca72a16..e7c123a 100644 (file)
@@ -694,6 +694,22 @@ static void macb_mac_config(struct phylink_config *config, unsigned int mode,
        if (old_ncr ^ ncr)
                macb_or_gem_writel(bp, NCR, ncr);
 
+       /* Disable AN for SGMII fixed link configuration, enable otherwise.
+        * Must be written after PCSSEL is set in NCFGR,
+        * otherwise writes will not take effect.
+        */
+       if (macb_is_gem(bp) && state->interface == PHY_INTERFACE_MODE_SGMII) {
+               u32 pcsctrl, old_pcsctrl;
+
+               old_pcsctrl = gem_readl(bp, PCSCNTRL);
+               if (mode == MLO_AN_FIXED)
+                       pcsctrl = old_pcsctrl & ~GEM_BIT(PCSAUTONEG);
+               else
+                       pcsctrl = old_pcsctrl | GEM_BIT(PCSAUTONEG);
+               if (old_pcsctrl != pcsctrl)
+                       gem_writel(bp, PCSCNTRL, pcsctrl);
+       }
+
        spin_unlock_irqrestore(&bp->lock, flags);
 }