Skip to content

Commit f6dadd5

Browse files
u1f35cdavem330
authored andcommitted
net: dsa: qca8k: Improve SGMII interface handling
This patch improves the handling of the SGMII interface on the QCA8K devices. Previously the driver did no configuration of the port, even if it was selected. We now configure it up in the appropriate PHY/MAC/Base-X mode depending on what phylink tells us we are connected to and ensure it is enabled. Tested with a device where the CPU connection is RGMII (i.e. the common current use case) + one where the CPU connection is SGMII. I don't have any devices where the SGMII interface is brought out to something other than the CPU. Signed-off-by: Jonathan McDowell <noodles@earth.li> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b3591c2 commit f6dadd5

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎drivers/net/dsa/qca8k.c‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,9 @@ qca8k_setup(struct dsa_switch *ds)
673673
/* Flush the FDB table */
674674
qca8k_fdb_flush(priv);
675675

676+
/* We don't have interrupts for link changes, so we need to poll */
677+
ds->pcs_poll = true;
678+
676679
return 0;
677680
}
678681

@@ -681,7 +684,7 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,
681684
const struct phylink_link_state *state)
682685
{
683686
struct qca8k_priv *priv = ds->priv;
684-
u32 reg;
687+
u32 reg, val;
685688

686689
switch (port) {
687690
case 0: /* 1st CPU port */
@@ -740,6 +743,34 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,
740743
case PHY_INTERFACE_MODE_1000BASEX:
741744
/* Enable SGMII on the port */
742745
qca8k_write(priv, reg, QCA8K_PORT_PAD_SGMII_EN);
746+
747+
/* Enable/disable SerDes auto-negotiation as necessary */
748+
val = qca8k_read(priv, QCA8K_REG_PWS);
749+
if (phylink_autoneg_inband(mode))
750+
val &= ~QCA8K_PWS_SERDES_AEN_DIS;
751+
else
752+
val |= QCA8K_PWS_SERDES_AEN_DIS;
753+
qca8k_write(priv, QCA8K_REG_PWS, val);
754+
755+
/* Configure the SGMII parameters */
756+
val = qca8k_read(priv, QCA8K_REG_SGMII_CTRL);
757+
758+
val |= QCA8K_SGMII_EN_PLL | QCA8K_SGMII_EN_RX |
759+
QCA8K_SGMII_EN_TX | QCA8K_SGMII_EN_SD;
760+
761+
if (dsa_is_cpu_port(ds, port)) {
762+
/* CPU port, we're talking to the CPU MAC, be a PHY */
763+
val &= ~QCA8K_SGMII_MODE_CTRL_MASK;
764+
val |= QCA8K_SGMII_MODE_CTRL_PHY;
765+
} else if (state->interface == PHY_INTERFACE_MODE_SGMII) {
766+
val &= ~QCA8K_SGMII_MODE_CTRL_MASK;
767+
val |= QCA8K_SGMII_MODE_CTRL_MAC;
768+
} else if (state->interface == PHY_INTERFACE_MODE_1000BASEX) {
769+
val &= ~QCA8K_SGMII_MODE_CTRL_MASK;
770+
val |= QCA8K_SGMII_MODE_CTRL_BASEX;
771+
}
772+
773+
qca8k_write(priv, QCA8K_REG_SGMII_CTRL, val);
743774
break;
744775
default:
745776
dev_err(ds->dev, "xMII mode %s not supported for port %d\n",

‎drivers/net/dsa/qca8k.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#define QCA8K_MAX_DELAY 3
3737
#define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24)
3838
#define QCA8K_PORT_PAD_SGMII_EN BIT(7)
39+
#define QCA8K_REG_PWS 0x010
40+
#define QCA8K_PWS_SERDES_AEN_DIS BIT(7)
3941
#define QCA8K_REG_MODULE_EN 0x030
4042
#define QCA8K_MODULE_EN_MIB BIT(0)
4143
#define QCA8K_REG_MIB 0x034
@@ -69,6 +71,7 @@
6971
#define QCA8K_PORT_STATUS_LINK_UP BIT(8)
7072
#define QCA8K_PORT_STATUS_LINK_AUTO BIT(9)
7173
#define QCA8K_PORT_STATUS_LINK_PAUSE BIT(10)
74+
#define QCA8K_PORT_STATUS_FLOW_AUTO BIT(12)
7275
#define QCA8K_REG_PORT_HDR_CTRL(_i) (0x9c + (_i * 4))
7376
#define QCA8K_PORT_HDR_CTRL_RX_MASK GENMASK(3, 2)
7477
#define QCA8K_PORT_HDR_CTRL_RX_S 2
@@ -77,6 +80,16 @@
7780
#define QCA8K_PORT_HDR_CTRL_ALL 2
7881
#define QCA8K_PORT_HDR_CTRL_MGMT 1
7982
#define QCA8K_PORT_HDR_CTRL_NONE 0
83+
#define QCA8K_REG_SGMII_CTRL 0x0e0
84+
#define QCA8K_SGMII_EN_PLL BIT(1)
85+
#define QCA8K_SGMII_EN_RX BIT(2)
86+
#define QCA8K_SGMII_EN_TX BIT(3)
87+
#define QCA8K_SGMII_EN_SD BIT(4)
88+
#define QCA8K_SGMII_CLK125M_DELAY BIT(7)
89+
#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23))
90+
#define QCA8K_SGMII_MODE_CTRL_BASEX (0 << 22)
91+
#define QCA8K_SGMII_MODE_CTRL_PHY (1 << 22)
92+
#define QCA8K_SGMII_MODE_CTRL_MAC (2 << 22)
8093

8194
/* EEE control registers */
8295
#define QCA8K_REG_EEE_CTRL 0x100

0 commit comments

Comments
 (0)