net: dsa: qca8k: Add SGMII configuration options
Subsystems (4)
cover net: dsa: qca8k: Add SGMII configuration options
This pair of patches adds some SGMII device tree configuration options for the QCA8K switch driver, and the associated documentation.
At present the driver does no configuration of the SGMII port, even if it is selected. These changes allow configuration of how it is connected up (i.e. connected to an external phy, or to a CPU, or to an SFP cage) as well as allowing for autonegotiation to be disabled and a delay configured.
Tested on a MikroTik RB3011; the second switch is connected to the CPU via SGMII.
Jonathan McDowell (2):
dt-bindings: net: dsa: qca8k: document SGMII properties
net: dsa: qca8k: introduce SGMII configuration options
.../devicetree/bindings/net/dsa/qca8k.txt | 4 ++ drivers/net/dsa/qca8k.c | 44 ++++++++++++++++++- drivers/net/dsa/qca8k.h | 12 +++++ 3 files changed, 59 insertions(+), 1 deletion(-)
Signature · 1 line
2.20.1
PATCH 1/2 dt-bindings: net: dsa: qca8k: document SGMII properties
This patch documents the qca8k's SGMII related properties that allow configuration of the SGMII port.
--- Documentation/devicetree/bindings/net/dsa/qca8k.txt | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/net/dsa/qca8k.txt +4 -0
@@ -11,7 +11,11 @@ Required properties: Optional properties: +- disable-serdes-autoneg: Boolean, disables auto-negotiation on the SerDes - reset-gpios: GPIO to be used to reset the whole device +- sgmii-delay: Boolean, presence delays SGMII clock by 2ns +- sgmii-mode: String, operation mode of the SGMII interface. + Supported values are: "basex", "mac", "phy". Subnodes:
Signature · 1 line
2.20.1
PATCH 2/2 net: dsa: qca8k: introduce SGMII configuration options
In reply to Jonathan McDowellThe QCA8337(N) has an SGMII port which can operate in MAC, PHY or BASE-X mode depending on what it's connected to (e.g. CPU vs external PHY or SFP). At present the driver does no configuration of this port even if it is selected.
Add support for making sure the SGMII is enabled if it's in use, and device tree support for configuring the connection details.
--- drivers/net/dsa/qca8k.c | 44 ++++++++++++++++++++++++++++++++++++++++- drivers/net/dsa/qca8k.h | 12 +++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-)
drivers/net/dsa/qca8k.c +43 -1
@@ -418,6 +418,40 @@ qca8k_mib_init(struct qca8k_priv *priv)mutex_unlock (&priv->reg_mutex); } +static int +qca8k_setup_sgmii (struct qca8k_priv *priv) +{ +const char *mode; +u32 val; + + val =qca8k_read (priv,QCA8K_REG_SGMII_CTRL ); + + val |=QCA8K_SGMII_EN_PLL |QCA8K_SGMII_EN_RX | +QCA8K_SGMII_EN_TX |QCA8K_SGMII_EN_SD ; + +if (of_property_read_bool (priv->dev->of_node,"sgmii-delay" )) + val |=QCA8K_SGMII_CLK125M_DELAY ; + +if (of_property_read_string (priv->dev->of_node,"sgmii-mode" , &mode)) { + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; + +if (!strcasecmp (mode,"basex" )) { + val |=QCA8K_SGMII_MODE_CTRL_BASEX ; + }else if (!strcasecmp (mode,"mac" )) { + val |=QCA8K_SGMII_MODE_CTRL_MAC ; + }else if (!strcasecmp (mode,"phy" )) { + val |=QCA8K_SGMII_MODE_CTRL_PHY ; + }else { +pr_err ("Unrecognised SGMII mode %s\n" , mode); +return -EINVAL ; + } + } + +qca8k_write (priv,QCA8K_REG_SGMII_CTRL , val); + +return 0 ; +} +static int qca8k_set_pad_ctrl (struct qca8k_priv *priv,int port,int mode) {
@@ -458,7 +492,8 @@ qca8k_set_pad_ctrl(struct qca8k_priv *priv, int port, int mode)break ;case PHY_INTERFACE_MODE_SGMII :qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); -break ; + +return qca8k_setup_sgmii (priv);default :pr_err ("xMII mode %d not supported\n" , mode);return -EINVAL ;
@@ -661,6 +696,13 @@ qca8k_setup(struct dsa_switch *ds)if (ret)return ret; +if (of_property_read_bool (priv->dev->of_node, +"disable-serdes-autoneg" )) { + mask =qca8k_read (priv,QCA8K_REG_PWS ) | +QCA8K_PWS_SERDES_AEN_DIS ; +qca8k_write (priv,QCA8K_REG_PWS , mask); + } +/* Initialize CPU port pad mode (xMII type, delays...) */ ret =of_get_phy_mode (dsa_to_port (ds,QCA8K_CPU_PORT )->dn, &phy_mode);if (ret) {
drivers/net/dsa/qca8k.h +12 -0
@@ -36,6 +36,8 @@#define QCA8K_MAX_DELAY 3#define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24)#define QCA8K_PORT_PAD_SGMII_EN BIT(7) +#define QCA8K_REG_PWS 0x010 +#define QCA8K_PWS_SERDES_AEN_DIS BIT(7)#define QCA8K_REG_MODULE_EN 0x030#define QCA8K_MODULE_EN_MIB BIT(0)#define QCA8K_REG_MIB 0x034
@@ -77,6 +79,16 @@#define QCA8K_PORT_HDR_CTRL_ALL 2#define QCA8K_PORT_HDR_CTRL_MGMT 1#define QCA8K_PORT_HDR_CTRL_NONE 0 +#define QCA8K_REG_SGMII_CTRL 0x0e0 +#define QCA8K_SGMII_EN_PLL BIT(1) +#define QCA8K_SGMII_EN_RX BIT(2) +#define QCA8K_SGMII_EN_TX BIT(3) +#define QCA8K_SGMII_EN_SD BIT(4) +#define QCA8K_SGMII_CLK125M_DELAY BIT(7) +#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23)) +#define QCA8K_SGMII_MODE_CTRL_BASEX 0 +#define QCA8K_SGMII_MODE_CTRL_PHY BIT(22) +#define QCA8K_SGMII_MODE_CTRL_MAC BIT(23)/* EEE control registers */ #define QCA8K_REG_EEE_CTRL 0x100
Signature · 1 line
2.20.1
Re: [PATCH 2/2] net: dsa: qca8k: introduce SGMII configuration options
Quoted 40 lines · On Fri, 5 Jun 2020 19:10:58 +0100 Jonathan McDowell <[email protected]> wrote:
The QCA8337(N) has an SGMII port which can operate in MAC, PHY or BASE-X mode depending on what it's connected to (e.g. CPU vs external PHY or SFP). At present the driver does no configuration of this port even if it is selected.
Add support for making sure the SGMII is enabled if it's in use, and device tree support for configuring the connection details.
Signed-off-by Jonathan McDowell <[email protected]>--- drivers/net/dsa/qca8k.c | 44 ++++++++++++++++++++++++++++++++++++++++- drivers/net/dsa/qca8k.h | 12 +++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-)drivers/net/dsa/qca8k.c +18
-0@@ -418,6 +418,40 @@ qca8k_mib_init(struct qca8k_priv *priv)mutex_unlock (&priv->reg_mutex); } +static int +qca8k_setup_sgmii (struct qca8k_priv *priv) +{ +const char *mode; +u32 val; + + val =qca8k_read (priv,QCA8K_REG_SGMII_CTRL ); + + val |=QCA8K_SGMII_EN_PLL |QCA8K_SGMII_EN_RX | +QCA8K_SGMII_EN_TX |QCA8K_SGMII_EN_SD ; + +if (of_property_read_bool (priv->dev->of_node,"sgmii-delay" )) + val |=QCA8K_SGMII_CLK125M_DELAY ; + +if (of_property_read_string (priv->dev->of_node,"sgmii-mode" , &mode)) { + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; + +if (!strcasecmp (mode,"basex" )) {
drivers/net/dsa/qca8k.c qca8k_mib_init(struct qca8k_priv *priv) · line 448
Quoted 10 lines
drivers/net/dsa/qca8k.c +10
-0+ val |=QCA8K_SGMII_MODE_CTRL_BASEX ; + }else if (!strcasecmp (mode,"mac" )) { + val |=QCA8K_SGMII_MODE_CTRL_MAC ; + }else if (!strcasecmp (mode,"phy" )) { + val |=QCA8K_SGMII_MODE_CTRL_PHY ; + }else { +pr_err ("Unrecognised SGMII mode %s\n" , mode); +return -EINVAL ; + } + }
There is no sgmii-mode device tree property documented. You should infere this settings from the existing device tree bindings, ie look at phy-mode. You can use of_get_phy_mode function, or something from of_mdio.c, or better yet change the api in this driver to use the new phylink API.
Marek
Quoted 63 lines
drivers/net/dsa/qca8k.c +15
-1+ +qca8k_write (priv,QCA8K_REG_SGMII_CTRL , val); + +return 0 ; +} +static int qca8k_set_pad_ctrl (struct qca8k_priv *priv,int port,int mode) {@@ -458,7 +492,8 @@ qca8k_set_pad_ctrl(struct qca8k_priv *priv, int port, int mode)break ;case PHY_INTERFACE_MODE_SGMII :qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); -break ; + +return qca8k_setup_sgmii (priv);default :pr_err ("xMII mode %d not supported\n" , mode);return -EINVAL ;@@ -661,6 +696,13 @@ qca8k_setup(struct dsa_switch *ds)if (ret)return ret; +if (of_property_read_bool (priv->dev->of_node, +"disable-serdes-autoneg" )) { + mask =qca8k_read (priv,QCA8K_REG_PWS ) | +QCA8K_PWS_SERDES_AEN_DIS ; +qca8k_write (priv,QCA8K_REG_PWS , mask); + } +/* Initialize CPU port pad mode (xMII type, delays...) */ ret =of_get_phy_mode (dsa_to_port (ds,QCA8K_CPU_PORT )->dn, &phy_mode);if (ret) {drivers/net/dsa/qca8k.h +12
-0@@ -36,6 +36,8 @@#define QCA8K_MAX_DELAY 3#define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24)#define QCA8K_PORT_PAD_SGMII_EN BIT(7) +#define QCA8K_REG_PWS 0x010 +#define QCA8K_PWS_SERDES_AEN_DIS BIT(7)#define QCA8K_REG_MODULE_EN 0x030#define QCA8K_MODULE_EN_MIB BIT(0)#define QCA8K_REG_MIB 0x034@@ -77,6 +79,16 @@#define QCA8K_PORT_HDR_CTRL_ALL 2#define QCA8K_PORT_HDR_CTRL_MGMT 1#define QCA8K_PORT_HDR_CTRL_NONE 0 +#define QCA8K_REG_SGMII_CTRL 0x0e0 +#define QCA8K_SGMII_EN_PLL BIT(1) +#define QCA8K_SGMII_EN_RX BIT(2) +#define QCA8K_SGMII_EN_TX BIT(3) +#define QCA8K_SGMII_EN_SD BIT(4) +#define QCA8K_SGMII_CLK125M_DELAY BIT(7) +#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23)) +#define QCA8K_SGMII_MODE_CTRL_BASEX 0 +#define QCA8K_SGMII_MODE_CTRL_PHY BIT(22) +#define QCA8K_SGMII_MODE_CTRL_MAC BIT(23)/* EEE control registers */ #define QCA8K_REG_EEE_CTRL 0x100
Andrew Lunn
maintainerRe: [PATCH 2/2] net: dsa: qca8k: introduce SGMII configuration options
In reply to Jonathan McDowellQuoted 7 lines · Jonathan McDowell
The QCA8337(N) has an SGMII port which can operate in MAC, PHY or BASE-X mode depending on what it's connected to (e.g. CPU vs external PHY or SFP). At present the driver does no configuration of this port even if it is selected.
Add support for making sure the SGMII is enabled if it's in use, and device tree support for configuring the connection details.
Hi Jonathan
It is good to include Russell King in Cc: for patches like this.
Also, netdev is closed at the moment, so please post patches as RFC.
It sounds like the hardware has a PCS which can support SGMII or 1000BaseX. phylink will tell you what mode to configure it to. e.g. A fibre SFP module will want 1000BaseX. A copper SFP module will want SGMII. A switch is likely to want 1000BaseX. A PHY is likely to want SGMII. So remove the "sgmii-mode" property and configure it as phylink is requesting.
What exactly does sgmii-delay do?
drivers/net/dsa/qca8k.h line 91
Quoted 10 lines
drivers/net/dsa/qca8k.h +10
-0+#define QCA8K_REG_SGMII_CTRL 0x0e0 +#define QCA8K_SGMII_EN_PLL BIT(1) +#define QCA8K_SGMII_EN_RX BIT(2) +#define QCA8K_SGMII_EN_TX BIT(3) +#define QCA8K_SGMII_EN_SD BIT(4) +#define QCA8K_SGMII_CLK125M_DELAY BIT(7) +#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23)) +#define QCA8K_SGMII_MODE_CTRL_BASEX 0 +#define QCA8K_SGMII_MODE_CTRL_PHY BIT(22) +#define QCA8K_SGMII_MODE_CTRL_MAC BIT(23)
I guess these are not really bits. You cannot combine QCA8K_SGMII_MODE_CTRL_MAC and QCA8K_SGMII_MODE_CTRL_PHY. So it makes more sense to have:
#define QCA8K_SGMII_MODE_CTRL_BASEX (0x0 << 22) #define QCA8K_SGMII_MODE_CTRL_PHY (0x1 << 22) #define QCA8K_SGMII_MODE_CTRL_MAC (0x2 << 22)
Andrew
Re: [PATCH 2/2] net: dsa: qca8k: introduce SGMII configuration options
Quoted 10 lines · Andrew Lunn
Quoted 7 lines · Jonathan McDowell
The QCA8337(N) has an SGMII port which can operate in MAC, PHY or BASE-X mode depending on what it's connected to (e.g. CPU vs external PHY or SFP). At present the driver does no configuration of this port even if it is selected.
Add support for making sure the SGMII is enabled if it's in use, and device tree support for configuring the connection details.
It is good to include Russell King in Cc: for patches like this.
No problem, I can keep him in the thread; I used get_maintainer for the initial set of people/lists to copy.
Quoted 1 line
Also, netdev is closed at the moment, so please post patches as RFC.
"closed"? If you mean this won't get into 5.8 then I wasn't expecting it to, I'm aware the merge window for that is already open.
Quoted 6 lines
It sounds like the hardware has a PCS which can support SGMII or 1000BaseX. phylink will tell you what mode to configure it to. e.g. A fibre SFP module will want 1000BaseX. A copper SFP module will want SGMII. A switch is likely to want 1000BaseX. A PHY is likely to want SGMII. So remove the "sgmii-mode" property and configure it as phylink is requesting.
It's more than SGMII or 1000BaseX as I read it. The port can act as if it's talking to an SGMII MAC, i.e. a CPU, or an SGMII PHY, i.e. an external PHY, or in BaseX mode for an SFP. I couldn't figure out a way in the current framework to automatically work out if I wanted PHY or MAC mode. For the port tagged CPU I can assume MAC mode, but a port that doesn't have that might still be attached to the CPU rather than an external PHY.
Quoted 1 line
What exactly does sgmii-delay do?
As per the device tree documentation update I sent it delays the SGMII clock by 2ns. From the data sheet:
SGMII_SEL_CLK125M sgmii_clk125m_rx_delay is delayed by 2ns
Quoted 15 lines
drivers/net/dsa/qca8k.h line 91
Quoted 10 lines
drivers/net/dsa/qca8k.h +10
-0+#define QCA8K_REG_SGMII_CTRL 0x0e0 +#define QCA8K_SGMII_EN_PLL BIT(1) +#define QCA8K_SGMII_EN_RX BIT(2) +#define QCA8K_SGMII_EN_TX BIT(3) +#define QCA8K_SGMII_EN_SD BIT(4) +#define QCA8K_SGMII_CLK125M_DELAY BIT(7) +#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23)) +#define QCA8K_SGMII_MODE_CTRL_BASEX 0 +#define QCA8K_SGMII_MODE_CTRL_PHY BIT(22) +#define QCA8K_SGMII_MODE_CTRL_MAC BIT(23)I guess these are not really bits. You cannot combine
QCA8K_SGMII_MODE_CTRL_MACandQCA8K_SGMII_MODE_CTRL_PHY. So it makes more sense to have:
Quoted 3 lines
#define QCA8K_SGMII_MODE_CTRL_BASEX (0x0 << 22) #define QCA8K_SGMII_MODE_CTRL_PHY (0x1 << 22) #define QCA8K_SGMII_MODE_CTRL_MAC (0x2 << 22)
Sure; given there's no 0x3 choice I just went for the bits that need set, but that works too.
J.
Signature · 1 line
Mistakes aren't always regrets.
Re: [PATCH 2/2] net: dsa: qca8k: introduce SGMII configuration options
Quoted 7 lines · Jonathan McDowell
Quoted 6 lines · Andrew Lunn
Quoted 5 lines · Jonathan McDowell
The QCA8337(N) has an SGMII port which can operate in MAC, PHY or BASE-X mode depending on what it's connected to (e.g. CPU vs external PHY or SFP). At present the driver does no configuration of this port even if it is selected.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Add support for making sure the SGMII is enabled if it's in use, and device tree support for configuring the connection details.
It is good to include Russell King in Cc: for patches like this.
No problem, I can keep him in the thread; I used
get_maintainerfor the initial set of people/lists to copy.
get_maintainer is not always "good" at selecting the right people, especially when your patches don't match the criteria; MAINTAINERS contains everything that is sensible, but Andrew is suggesting that you copy me because in his opinion, you should be using phylink - and that's something that you can't encode into a program.
Note that I haven't seen your patches.
Quoted 4 lines
Quoted 1 line
Also, netdev is closed at the moment, so please post patches as RFC.
"closed"? If you mean this won't get into 5.8 then I wasn't expecting it to, I'm aware the merge window for that is already open.
See https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt
"How often do changes from these trees make it to the mainline Linus tree?"
Quoted 7 lines
Quoted 6 lines
It sounds like the hardware has a PCS which can support SGMII or 1000BaseX. phylink will tell you what mode to configure it to. e.g. A fibre SFP module will want 1000BaseX. A copper SFP module will want SGMII. A switch is likely to want 1000BaseX. A PHY is likely to want SGMII. So remove the "sgmii-mode" property and configure it as phylink is requesting.
Quoted 7 lines
It's more than SGMII or 1000BaseX as I read it. The port can act as if it's talking to an SGMII MAC, i.e. a CPU, or an SGMII PHY, i.e. an external PHY, or in BaseX mode for an SFP. I couldn't figure out a way in the current framework to automatically work out if I wanted PHY or MAC mode. For the port tagged CPU I can assume MAC mode, but a port that doesn't have that might still be attached to the CPU rather than an external PHY.
That depends what you're connected to. Some people call the two sides of SGMII "System side" and "Media side". System side is where you're receiving the results of AN from a PHY. Media side is where you're telling the partner what you want it to do.
Media side is only useful if you're connected to another MAC, and unless you have a requirement for it, I would suggest not implementing that - you could come up with something using fixed-link, or it may need some other model if the settings need to change. That depends on the application.
Quoted 6 lines
Quoted 1 line
What exactly does sgmii-delay do?
As per the device tree documentation update I sent it delays the SGMII clock by 2ns. From the data sheet:
SGMII_SEL_CLK125Msgmii_clk125m_rx_delayis delayed by 2ns
This sounds like a new world of RGMII delay pain but for SGMII. There is no mention of "delay" in the SGMII v1.8 specification, so I guess it's something the vendor is doing. Is this device capable of recovering the clock from a single serdes pair carrying the data, or does it always require the separate clock?
Quoted 15 lines
Quoted 15 lines
drivers/net/dsa/qca8k.h line 91
Quoted 10 lines
drivers/net/dsa/qca8k.h +10
-0+#define QCA8K_REG_SGMII_CTRL 0x0e0 +#define QCA8K_SGMII_EN_PLL BIT(1) +#define QCA8K_SGMII_EN_RX BIT(2) +#define QCA8K_SGMII_EN_TX BIT(3) +#define QCA8K_SGMII_EN_SD BIT(4) +#define QCA8K_SGMII_CLK125M_DELAY BIT(7) +#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23)) +#define QCA8K_SGMII_MODE_CTRL_BASEX 0 +#define QCA8K_SGMII_MODE_CTRL_PHY BIT(22) +#define QCA8K_SGMII_MODE_CTRL_MAC BIT(23)I guess these are not really bits. You cannot combine
QCA8K_SGMII_MODE_CTRL_MACandQCA8K_SGMII_MODE_CTRL_PHY. So it makes more sense to have:
Quoted 6 lines
Quoted 3 lines
#define QCA8K_SGMII_MODE_CTRL_BASEX (0x0 << 22) #define QCA8K_SGMII_MODE_CTRL_PHY (0x1 << 22) #define QCA8K_SGMII_MODE_CTRL_MAC (0x2 << 22)Sure; given there's no
0x3choice I just went for the bits that need set, but that works too.
I also prefer Andrew's suggestion, as it makes it clear that it's a two bit field.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC for 0.8m (est. 1762m) line in suburbia: sync at 13.1Mbps down 424kbps up
Re: [PATCH 2/2] net: dsa: qca8k: introduce SGMII configuration options
Quoted 13 lines · Russell King - ARM Linux admin
Quoted 12 lines · Jonathan McDowell
Quoted 10 lines · Andrew Lunn
Quoted 7 lines · Jonathan McDowell
The QCA8337(N) has an SGMII port which can operate in MAC, PHY or BASE-X mode depending on what it's connected to (e.g. CPU vs external PHY or SFP). At present the driver does no configuration of this port even if it is selected.
Add support for making sure the SGMII is enabled if it's in use, and device tree support for configuring the connection details.
It is good to include Russell King in Cc: for patches like this.
Quoted 8 lines
Quoted 2 lines
No problem, I can keep him in the thread; I used
get_maintainerfor the initial set of people/lists to copy.
get_maintaineris not always "good" at selecting the right people, especially when your patches don't match the criteria;MAINTAINERScontains everything that is sensible, but Andrew is suggesting that you copy me because in his opinion, you should be using phylink - and that's something that you can't encode into a program.
Sure, and I appreciate the pointer to appropriate people who might provide helpful comments.
Quoted 1 line
Note that I haven't seen your patches.
I'll make sure to copy you on v2.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Also, netdev is closed at the moment, so please post patches as RFC.
"closed"? If you mean this won't get into 5.8 then I wasn't expecting it to, I'm aware the merge window for that is already open.
See https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt
"How often do changes from these trees make it to the mainline Linus tree?"
Ta. I'll hold off on a v2 until after -rc1 drops.
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
It sounds like the hardware has a PCS which can support SGMII or 1000BaseX. phylink will tell you what mode to configure it to. e.g. A fibre SFP module will want 1000BaseX. A copper SFP module will want SGMII. A switch is likely to want 1000BaseX. A PHY is likely to want SGMII. So remove the "sgmii-mode" property and configure it as phylink is requesting.
Quoted 7 lines
It's more than SGMII or 1000BaseX as I read it. The port can act as if it's talking to an SGMII MAC, i.e. a CPU, or an SGMII PHY, i.e. an external PHY, or in BaseX mode for an SFP. I couldn't figure out a way in the current framework to automatically work out if I wanted PHY or MAC mode. For the port tagged CPU I can assume MAC mode, but a port that doesn't have that might still be attached to the CPU rather than an external PHY.
That depends what you're connected to. Some people call the two sides of SGMII "System side" and "Media side". System side is where you're receiving the results of AN from a PHY. Media side is where you're telling the partner what you want it to do.
Quoted 5 lines
Media side is only useful if you're connected to another MAC, and unless you have a requirement for it, I would suggest not implementing that - you could come up with something using fixed-link, or it may need some other model if the settings need to change. That depends on the application.
So the device in question is a 7 port stand alone switch chip. There's a single SGMII port which is configurable between port 0 + 6 (they can also be configure up as RGMII, while the remaining 5 ports have their own phys).
It sounds like there's a strong preference to try and auto configure things as much as possible, so I should assume the CPU port is in MAC mode, and anything not tagged as a CPU port is talking to a PHY/BASEX.
I assume I can use PHY_INTERFACE_MODE_1000BASEX on the phylink_mac_config call to choose BASEX?
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
What exactly does sgmii-delay do?
As per the device tree documentation update I sent it delays the SGMII clock by 2ns. From the data sheet:
Quoted 7 lines
Quoted 1 line
SGMII_SEL_CLK125Msgmii_clk125m_rx_delayis delayed by 2nsThis sounds like a new world of RGMII delay pain but for SGMII. There is no mention of "delay" in the SGMII v1.8 specification, so I guess it's something the vendor is doing. Is this device capable of recovering the clock from a single serdes pair carrying the data, or does it always require the separate clock?
Pass, but I think I might be able to get away without having to configure that for the moment.
I'll go away and roll a v2 moving qca8k over to phylink and then using that to auto select the appropriate SGMII mode. Thanks for the feedback.
J.
Signature · 1 line
I started out with nothing & still have most of it left.
Re: [PATCH 2/2] net: dsa: qca8k: introduce SGMII configuration options
Quoted 11 lines · Jonathan McDowell
So the device in question is a 7 port stand alone switch chip. There's a single SGMII port which is configurable between port 0 + 6 (they can also be configure up as RGMII, while the remaining 5 ports have their own phys).
It sounds like there's a strong preference to try and auto configure things as much as possible, so I should assume the CPU port is in MAC mode, and anything not tagged as a CPU port is talking to a PHY/BASEX.
I assume I can use
PHY_INTERFACE_MODE_1000BASEXon thephylink_mac_configcall to choose BASEX?
Yes, but from what you've mentioned above, I think I need to ensure that there's a proper understanding here.
1000BASE-X is the IEEE 802.3 defined 1G single lane Serdes protocol. SGMII is different; it's a vendor derivative of 1000BASE-X which has become a de-facto standard.
Both are somewhat compatible with each other; SGMII brings with it additional data replication to achieve 100M and 10M speeds, while keeping the link running at 1.25Gbaud. In both cases, there is a 16-bit "configuration" word that is passed between the partners.
1000BASE-X uses this configuration word to advertise the abilities of each end, which is limited to duplex and pause modes only. This you get by specifying the phy-mode="1000base-x" and managed="in-band-status" in DT.
SGMII uses this configuration word for the media side to inform the system side which mode it wishes to operate the link: the speed and duplex. Some vendors extend it to include EEE parameters as well, or pause modes. You get this via phy-mode="sgmii" and managed="in-band-status" in DT.
Then there are variants where the configuration word is not present. In this case, the link has to be manually configured, and without the configuration word, SGMII operating at 1G is compatible with 1000base-X operating at 1G. Fixed-link can be used for this, although fixed-link will always report that the link is up at the moment; that may change in the future, it's something that is being looked into at the moment.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC for 0.8m (est. 1762m) line in suburbia: sync at 13.1Mbps down 424kbps up
Andrew Lunn
maintainerRe: [PATCH 2/2] net: dsa: qca8k: introduce SGMII configuration options
In reply to Jonathan McDowellQuoted 10 lines
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Also, netdev is closed at the moment, so please post patches as RFC.
"closed"? If you mean this won't get into 5.8 then I wasn't expecting it to, I'm aware the merge window for that is already open.
See https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt
"How often do changes from these trees make it to the mainline Linus tree?"Ta. I'll hold off on a v2 until after -rc1 drops.
You can post at the moment, but you need to put RFC in the subject line, just to make it clear you are only interested in comments.
Andrew
Re: [PATCH 2/2] net: dsa: qca8k: introduce SGMII configuration options
In reply to Russell King - ARM Linux adminQuoted 36 lines · Russell King - ARM Linux admin
Quoted 11 lines · Jonathan McDowell
So the device in question is a 7 port stand alone switch chip. There's a single SGMII port which is configurable between port 0 + 6 (they can also be configure up as RGMII, while the remaining 5 ports have their own phys).
It sounds like there's a strong preference to try and auto configure things as much as possible, so I should assume the CPU port is in MAC mode, and anything not tagged as a CPU port is talking to a PHY/BASEX.
I assume I can use
PHY_INTERFACE_MODE_1000BASEXon thephylink_mac_configcall to choose BASEX?Yes, but from what you've mentioned above, I think I need to ensure that there's a proper understanding here.
1000BASE-X is the IEEE 802.3 defined 1G single lane Serdes protocol. SGMII is different; it's a vendor derivative of 1000BASE-X which has become a de-facto standard.
Both are somewhat compatible with each other; SGMII brings with it additional data replication to achieve 100M and 10M speeds, while keeping the link running at 1.25Gbaud. In both cases, there is a 16-bit "configuration" word that is passed between the partners.
1000BASE-X uses this configuration word to advertise the abilities of each end, which is limited to duplex and pause modes only. This you get by specifying the phy-mode="1000base-x" and managed="in-band-status" in DT.
SGMII uses this configuration word for the media side to inform the system side which mode it wishes to operate the link: the speed and duplex. Some vendors extend it to include EEE parameters as well, or pause modes. You get this via phy-mode="sgmii" and managed="in-band-status" in DT.
Quoted 7 lines
Then there are variants where the configuration word is not present. In this case, the link has to be manually configured, and without the configuration word, SGMII operating at 1G is compatible with 1000base-X operating at 1G. Fixed-link can be used for this, although fixed-link will always report that the link is up at the moment; that may change in the future, it's something that is being looked into at the moment.
The hardware I'm using has the switch connected to the CPU via the SGMII link, and all instances I can find completely disable inband configuration for that case. However the data sheet has an SGMII control register which allows configuration of the various auto-negotiation parameters (as well as whether we're base-x or sgmii) so I think the full flexibility is there.
I've got an initial port over to using phylink and picking up the parameters that way (avoiding any device tree option changes) that seems to be working, but I'll do a bit more testing before sending out a v2 RFC.
J.
Signature · 3 lines
/-\ | There are always at least two ways |@/ Debian GNU/Linux Developer | to program the same thing. \- |
RFC PATCH v2 1/1 net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellQuoted 2 lines · Jonathan McDowell
I'll go away and roll a v2 moving qca8k over to phylink and then using that to auto select the appropriate SGMII mode. Thanks for the feedback.
Ok, take 2. I've switched the driver over to phylink which has let me drop the need for any device tree configuration; if we're a CPU port then we're in SGMII-PHY mode, otherwise we choose between SGMII-MAC + Base-X on what phylink tells us.
----
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.
v2:
- Switch to phylink
- Avoid need for device tree configuration options
drivers/net/dsa/qca8k.c +242 -98
@@ -14,6 +14,7 @@#include <linux/of_platform.h> #include <linux/if_bridge.h> #include <linux/mdio.h> +#include <linux/phylink.h> #include <linux/gpio/consumer.h> #include <linux/etherdevice.h>
@@ -418,55 +419,6 @@ qca8k_mib_init(struct qca8k_priv *priv)mutex_unlock (&priv->reg_mutex); } -static int -qca8k_set_pad_ctrl (struct qca8k_priv *priv,int port,int mode) -{ -u32 reg, val; - -switch (port) { -case 0 : - reg =QCA8K_REG_PORT0_PAD_CTRL ; -break ; -case 6 : - reg =QCA8K_REG_PORT6_PAD_CTRL ; -break ; -default : -pr_err ("Can't set PAD_CTRL on port %d\n" , port); -return -EINVAL ; - } - -/* Configure a port to be directly connected to an external -* PHY or MAC. -*/ -switch (mode) { -case PHY_INTERFACE_MODE_RGMII : -/* RGMII mode means no delay so don't enable the delay */ - val =QCA8K_PORT_PAD_RGMII_EN ; -qca8k_write (priv, reg, val); -break ; -case PHY_INTERFACE_MODE_RGMII_ID : -/* RGMII_ID needs internal delay. This is enabled through -* PORT5_PAD_CTRL for all ports, rather than individual port -* registers -*/ -qca8k_write (priv, reg, -QCA8K_PORT_PAD_RGMII_EN | -QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | -QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY )); -qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , -QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); -break ; -case PHY_INTERFACE_MODE_SGMII : -qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); -break ; -default : -pr_err ("xMII mode %d not supported\n" , mode); -return -EINVAL ; - } - -return 0 ; -} -static void qca8k_port_set_status (struct qca8k_priv *priv,int port,int enable) {
@@ -639,9 +591,7 @@ static int qca8k_setup(struct dsa_switch *ds) {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -phy_interface_t phy_mode =PHY_INTERFACE_MODE_NA ;int ret, i; -u32 mask;/* Make sure that port 0 is the cpu port */ if (!dsa_is_cpu_port (ds,0 )) {
@@ -661,24 +611,9 @@ qca8k_setup(struct dsa_switch *ds)if (ret)return ret; -/* Initialize CPU port pad mode (xMII type, delays...) */ - ret =of_get_phy_mode (dsa_to_port (ds,QCA8K_CPU_PORT )->dn, &phy_mode); -if (ret) { -pr_err ("Can't find phy-mode for master device\n" ); -return ret; - } - ret =qca8k_set_pad_ctrl (priv,QCA8K_CPU_PORT , phy_mode); -if (ret <0 ) -return ret; - -/* Enable CPU Port, force it to maximum bandwidth and full-duplex */ - mask =QCA8K_PORT_STATUS_SPEED_1000 |QCA8K_PORT_STATUS_TXFLOW | -QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_DUPLEX ; -qca8k_write (priv,QCA8K_REG_PORT_STATUS (QCA8K_CPU_PORT ), mask); +/* Enable CPU Port */ qca8k_reg_set (priv,QCA8K_REG_GLOBAL_FW_CTRL0 ,QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN ); -qca8k_port_set_status (priv,QCA8K_CPU_PORT ,1 ); - priv->port_sts[QCA8K_CPU_PORT ].enabled =1 ;/* Enable MIB counters */ qca8k_mib_init (priv);
@@ -693,10 +628,9 @@ qca8k_setup(struct dsa_switch *ds)qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (i),QCA8K_PORT_LOOKUP_MEMBER ,0 ); -/* Disable MAC by default on all user ports */ +/* Disable MAC by default on all ports */ for (i =1 ; i <QCA8K_NUM_PORTS ; i++) -if (dsa_is_user_port (ds, i)) -qca8k_port_set_status (priv, i,0 ); +qca8k_port_set_status (priv, i,0 );/* Forward all unknown frames to CPU port for Linux processing */ qca8k_write(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
@@ -713,7 +647,7 @@ qca8k_setup(struct dsa_switch *ds) QCA8K_PORT_LOOKUP_MEMBER, dsa_user_ports(ds)); } -/* Invividual user ports get connected to CPU port only */ +/* Individual user ports get connected to CPU port only */ if (dsa_is_user_port (ds, i)) {int shift =16 * (i %2 );
@@ -743,44 +677,252 @@ qca8k_setup(struct dsa_switch *ds) }static void -qca8k_adjust_link (struct dsa_switch *ds,int port,struct phy_device *phy) +qca8k_phylink_mac_config (struct dsa_switch *ds,int port,unsigned int mode, +const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv; -u32 reg; +u32 reg, val; -/* Force fixed-link setting for CPU port, skip others. */ -if (!phy_is_pseudo_fixed_link (phy)) +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) +return ; + + reg =QCA8K_REG_PORT0_PAD_CTRL ; +break ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY, nothing to do */ return ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) +return ; -/* Set port speed */ -switch (phy->speed) { -case 10 : - reg =QCA8K_PORT_STATUS_SPEED_10 ; + reg =QCA8K_REG_PORT6_PAD_CTRL ;break ; -case 100 : - reg =QCA8K_PORT_STATUS_SPEED_100 ; +default : +dev_err (ds->dev,"%s: unsupported port: %i\n" , __func__, port); +return ; + } + +if (port !=6 &&phylink_autoneg_inband (mode)) { +dev_err (ds->dev,"%s: in-band negotiation unsupported\n" , + __func__); +return ; + } + +switch (state->interface) { +case PHY_INTERFACE_MODE_RGMII : +/* RGMII mode means no delay so don't enable the delay */ + val =QCA8K_PORT_PAD_RGMII_EN ; +qca8k_write (priv, reg, val);break ; -case 1000 : - reg =QCA8K_PORT_STATUS_SPEED_1000 ; +case PHY_INTERFACE_MODE_RGMII_ID : +/* RGMII_ID needs internal delay. This is enabled through +* PORT5_PAD_CTRL for all ports, rather than individual port +* registers +*/ +qca8k_write (priv, reg, +QCA8K_PORT_PAD_RGMII_EN | +QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | +QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY )); +qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , +QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); +break ; +case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_1000BASEX : +/* Enable SGMII on the port */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); + +/* Enable/disable SerDes auto-negotiation as necessary */ + val =qca8k_read (priv,QCA8K_REG_PWS ); +if (phylink_autoneg_inband (mode)) + val &= ~QCA8K_PWS_SERDES_AEN_DIS ; +else + val |=QCA8K_PWS_SERDES_AEN_DIS ; +qca8k_write (priv,QCA8K_REG_PWS , val); + +/* Configure the SGMII parameters */ + val =qca8k_read (priv,QCA8K_REG_SGMII_CTRL ); + + val |=QCA8K_SGMII_EN_PLL |QCA8K_SGMII_EN_RX | +QCA8K_SGMII_EN_TX |QCA8K_SGMII_EN_SD ; + + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; +if (dsa_is_cpu_port (ds, port)) { +/* CPU port, we're talking to the CPU MAC, be a PHY */ + val |=QCA8K_SGMII_MODE_CTRL_PHY ; + }else if (state->interface ==PHY_INTERFACE_MODE_SGMII ) { + val |=QCA8K_SGMII_MODE_CTRL_MAC ; + }else { + val |=QCA8K_SGMII_MODE_CTRL_BASEX ; + } + +qca8k_write (priv,QCA8K_REG_SGMII_CTRL , val);break ;default : -dev_dbg (priv->dev,"port%d link speed %dMbps not supported.\n" , - port, phy->speed); +dev_err (ds->dev,"xMII mode %s not supported for port %d\n" , +phy_modes (state->interface), port);return ; } +} + +static void +qca8k_phylink_validate (struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state) +{ +__ETHTOOL_DECLARE_LINK_MODE_MASK (mask) = {0 , }; + +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) + goto unsupported; +break ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_GMII ) + goto unsupported; +break ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) + goto unsupported; +break ; +default : +dev_err (ds->dev,"%s: unsupported port: %i\n" , __func__, port); +unsupported: +linkmode_zero (supported); +return ; + } + +phylink_set_port_modes (mask); +phylink_set (mask, Autoneg); + + phylink_set(mask, 1000baseT_Full); + phylink_set(mask, 10baseT_Half); + phylink_set(mask, 10baseT_Full); + phylink_set(mask, 100baseT_Half); + phylink_set(mask, 100baseT_Full); + +if (state->interface ==PHY_INTERFACE_MODE_1000BASEX ) + phylink_set(mask, 1000baseX_Full); + +phylink_set (mask, Pause); +phylink_set (mask, Asym_Pause); + +linkmode_and (supported, supported, mask); +linkmode_and (state->advertising, state->advertising, mask); +} + +static int +qca8k_phylink_mac_link_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; + + reg =qca8k_read (priv,QCA8K_REG_PORT_STATUS (port)); + + state->link = (reg &QCA8K_PORT_STATUS_LINK_UP ); + state->an_complete = state->link; + state->an_enabled = (reg &QCA8K_PORT_STATUS_LINK_AUTO ); + state->duplex = (reg &QCA8K_PORT_STATUS_DUPLEX ) ?DUPLEX_FULL : +DUPLEX_HALF ; + +switch (reg &QCA8K_PORT_STATUS_SPEED ) { +case QCA8K_PORT_STATUS_SPEED_10 : + state->speed =SPEED_10 ; +break ; +case QCA8K_PORT_STATUS_SPEED_100 : + state->speed =SPEED_100 ; +break ; +case QCA8K_PORT_STATUS_SPEED_1000 : + state->speed =SPEED_1000 ; +break ; +default : + state->speed =SPEED_UNKNOWN ; +break ; + } -/* Set duplex mode */ -if (phy->duplex ==DUPLEX_FULL ) - reg |=QCA8K_PORT_STATUS_DUPLEX ; + state->pause =MLO_PAUSE_NONE ; +if (reg &QCA8K_PORT_STATUS_RXFLOW ) + state->pause |=MLO_PAUSE_RX ; +if (reg &QCA8K_PORT_STATUS_TXFLOW ) + state->pause |=MLO_PAUSE_TX ; +if (reg &QCA8K_PORT_STATUS_FLOW_AUTO ) + state->pause |=MLO_PAUSE_AN ; -/* Force flow control */ -if (dsa_is_cpu_port (ds, port)) - reg |=QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_TXFLOW ; +return 1 ; +} + +static void +qca8k_phylink_mac_link_down (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface) +{ +struct qca8k_priv *priv = ds->priv; -/* Force link down before changing MAC options */ qca8k_port_set_status (priv, port,0 ); +} + +static void +qca8k_phylink_mac_link_up (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface,struct phy_device *phydev, +int speed,int duplex,bool tx_pause,bool rx_pause) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; + +if (phylink_autoneg_inband (mode)) { + reg =QCA8K_PORT_STATUS_LINK_AUTO ; + }else { +switch (speed) { +case SPEED_10 : + reg =QCA8K_PORT_STATUS_SPEED_10 ; +break ; +case SPEED_100 : + reg =QCA8K_PORT_STATUS_SPEED_100 ; +break ; +case SPEED_1000 : + reg =QCA8K_PORT_STATUS_SPEED_1000 ; +break ; +default : + reg =QCA8K_PORT_STATUS_LINK_AUTO ; +break ; + } + +if (duplex ==DUPLEX_FULL ) + reg |=QCA8K_PORT_STATUS_DUPLEX ; + +if (rx_pause |dsa_is_cpu_port (ds, port)) + reg |=QCA8K_PORT_STATUS_RXFLOW ; + +if (tx_pause |dsa_is_cpu_port (ds, port)) + reg |=QCA8K_PORT_STATUS_TXFLOW ; + } + + reg |=QCA8K_PORT_STATUS_TXMAC |QCA8K_PORT_STATUS_RXMAC ; +qca8k_write (priv,QCA8K_REG_PORT_STATUS (port), reg); -qca8k_port_set_status (priv, port,1 ); } static void
@@ -937,13 +1079,11 @@ qca8k_port_enable(struct dsa_switch *ds, int port, {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -if (!dsa_is_user_port (ds, port)) -return 0 ; -qca8k_port_set_status (priv, port,1 ); priv->port_sts[port].enabled =1 ; -phy_support_asym_pause (phy); +if (dsa_is_user_port (ds, port)) +phy_support_asym_pause (phy);return 0 ; }
@@ -1026,7 +1166,6 @@ qca8k_get_tag_protocol(struct dsa_switch *ds, int port,static const struct dsa_switch_ops qca8k_switch_ops = { .get_tag_protocol = qca8k_get_tag_protocol, .setup = qca8k_setup, - .adjust_link = qca8k_adjust_link, .get_strings = qca8k_get_strings, .get_ethtool_stats = qca8k_get_ethtool_stats, .get_sset_count = qca8k_get_sset_count,
@@ -1040,6 +1179,11 @@ static const struct dsa_switch_ops qca8k_switch_ops = { .port_fdb_add = qca8k_port_fdb_add, .port_fdb_del = qca8k_port_fdb_del, .port_fdb_dump = qca8k_port_fdb_dump, + .phylink_validate = qca8k_phylink_validate, + .phylink_mac_link_state = qca8k_phylink_mac_link_state, + .phylink_mac_config = qca8k_phylink_mac_config, + .phylink_mac_link_down = qca8k_phylink_mac_link_down, + .phylink_mac_link_up = qca8k_phylink_mac_link_up, }; static int
drivers/net/dsa/qca8k.h +13 -0
@@ -36,6 +36,8 @@#define QCA8K_MAX_DELAY 3#define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24)#define QCA8K_PORT_PAD_SGMII_EN BIT(7) +#define QCA8K_REG_PWS 0x010 +#define QCA8K_PWS_SERDES_AEN_DIS BIT(7)#define QCA8K_REG_MODULE_EN 0x030#define QCA8K_MODULE_EN_MIB BIT(0)#define QCA8K_REG_MIB 0x034
@@ -69,6 +71,7 @@#define QCA8K_PORT_STATUS_LINK_UP BIT(8)#define QCA8K_PORT_STATUS_LINK_AUTO BIT(9)#define QCA8K_PORT_STATUS_LINK_PAUSE BIT(10) +#define QCA8K_PORT_STATUS_FLOW_AUTO BIT(12)#define QCA8K_REG_PORT_HDR_CTRL (_i) (0x9c + (_i * 4))#define QCA8K_PORT_HDR_CTRL_RX_MASK GENMASK(3, 2)#define QCA8K_PORT_HDR_CTRL_RX_S 2
@@ -77,6 +80,16 @@#define QCA8K_PORT_HDR_CTRL_ALL 2#define QCA8K_PORT_HDR_CTRL_MGMT 1#define QCA8K_PORT_HDR_CTRL_NONE 0 +#define QCA8K_REG_SGMII_CTRL 0x0e0 +#define QCA8K_SGMII_EN_PLL BIT(1) +#define QCA8K_SGMII_EN_RX BIT(2) +#define QCA8K_SGMII_EN_TX BIT(3) +#define QCA8K_SGMII_EN_SD BIT(4) +#define QCA8K_SGMII_CLK125M_DELAY BIT(7) +#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23)) +#define QCA8K_SGMII_MODE_CTRL_BASEX (0 << 22) +#define QCA8K_SGMII_MODE_CTRL_PHY (1 << 22) +#define QCA8K_SGMII_MODE_CTRL_MAC (2 << 22)/* EEE control registers */ #define QCA8K_REG_EEE_CTRL 0x100
Andrew Lunn
maintainerRe: [RFC PATCH v2] net: dsa: qca8k: Improve SGMII interface handling
Quoted 8 lines · Jonathan McDowell
Quoted 2 lines · Jonathan McDowell
I'll go away and roll a v2 moving qca8k over to phylink and then using that to auto select the appropriate SGMII mode. Thanks for the feedback.
Ok, take 2. I've switched the driver over to phylink which has let me drop the need for any device tree configuration; if we're a CPU port then we're in SGMII-PHY mode, otherwise we choose between SGMII-MAC + Base-X on what phylink tells us.
Hi Johnathan
Could you split this into two parts. One or more patches which converts to phylink, and a patch which adds new functionality. If it breaks, we then have a better idea what broke it.
Conversions to phylink are not easy to review because a lot of code gets moved around. It sometimes helps if you can turn existing code into helpers, rather than inline them.
Andrew
Re: [RFC PATCH v2] net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellHi Jonathan,
A quick read through on the first review...
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 848
Quoted 12 lines · Jonathan McDowell
drivers/net/dsa/qca8k.c +12
-0+static int +qca8k_phylink_mac_link_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; + + reg =qca8k_read (priv,QCA8K_REG_PORT_STATUS (port)); + + state->link = (reg &QCA8K_PORT_STATUS_LINK_UP ); + state->an_complete = state->link; + state->an_enabled = (reg &QCA8K_PORT_STATUS_LINK_AUTO );
I much prefer to use !!(reg & ...) since these are single-bit bitfields.
Quoted 18 lines
drivers/net/dsa/qca8k.c +17
-0+ state->duplex = (reg &QCA8K_PORT_STATUS_DUPLEX ) ?DUPLEX_FULL : +DUPLEX_HALF ; + +switch (reg &QCA8K_PORT_STATUS_SPEED ) { +case QCA8K_PORT_STATUS_SPEED_10 : + state->speed =SPEED_10 ; +break ; +case QCA8K_PORT_STATUS_SPEED_100 : + state->speed =SPEED_100 ; +break ; +case QCA8K_PORT_STATUS_SPEED_1000 : + state->speed =SPEED_1000 ; +break ; +default : + state->speed =SPEED_UNKNOWN ; +break ; + }
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 873
Quoted 10 lines
drivers/net/dsa/qca8k.c +7
-3-/* Set duplex mode */ -if (phy->duplex ==DUPLEX_FULL ) - reg |=QCA8K_PORT_STATUS_DUPLEX ; + state->pause =MLO_PAUSE_NONE ; +if (reg &QCA8K_PORT_STATUS_RXFLOW ) + state->pause |=MLO_PAUSE_RX ; +if (reg &QCA8K_PORT_STATUS_TXFLOW ) + state->pause |=MLO_PAUSE_TX ; +if (reg &QCA8K_PORT_STATUS_FLOW_AUTO ) + state->pause |=MLO_PAUSE_AN ;
There is no need to report back MLO_PAUSE_AN.
From the quick read of this, nothing else obviously stood out.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC for 0.8m (est. 1762m) line in suburbia: sync at 13.1Mbps down 503kbps up
v3 cover net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellOk, take 3. This splits out the PHYLINK change to a separate patch which should have no effect on functionality, and then adds the SGMII clean-ups (i.e. the missing initialisation) on top of that as a second patch.
As before, 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.
v3:
- Move phylink changes to separate patch
- Address rmk review comments
v2:
- Switch to phylink
- Avoid need for device tree configuration options
Jonathan McDowell (2):
net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
net: dsa: qca8k: Improve SGMII interface handling
drivers/net/dsa/qca8k.c | 337 ++++++++++++++++++++++++++++------------ drivers/net/dsa/qca8k.h | 13 ++ 2 files changed, 252 insertions(+), 98 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/2 net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
Update the driver to use the new PHYLINK callbacks, removing the legacy adjust_link callback.
--- drivers/net/dsa/qca8k.c | 309 +++++++++++++++++++++++++++------------- 1 file changed, 212 insertions(+), 97 deletions(-)
drivers/net/dsa/qca8k.c +212 -97
@@ -14,6 +14,7 @@#include <linux/of_platform.h> #include <linux/if_bridge.h> #include <linux/mdio.h> +#include <linux/phylink.h> #include <linux/gpio/consumer.h> #include <linux/etherdevice.h>
@@ -418,55 +419,6 @@ qca8k_mib_init(struct qca8k_priv *priv)mutex_unlock (&priv->reg_mutex); } -static int -qca8k_set_pad_ctrl (struct qca8k_priv *priv,int port,int mode) -{ -u32 reg, val; - -switch (port) { -case 0 : - reg =QCA8K_REG_PORT0_PAD_CTRL ; -break ; -case 6 : - reg =QCA8K_REG_PORT6_PAD_CTRL ; -break ; -default : -pr_err ("Can't set PAD_CTRL on port %d\n" , port); -return -EINVAL ; - } - -/* Configure a port to be directly connected to an external -* PHY or MAC. -*/ -switch (mode) { -case PHY_INTERFACE_MODE_RGMII : -/* RGMII mode means no delay so don't enable the delay */ - val =QCA8K_PORT_PAD_RGMII_EN ; -qca8k_write (priv, reg, val); -break ; -case PHY_INTERFACE_MODE_RGMII_ID : -/* RGMII_ID needs internal delay. This is enabled through -* PORT5_PAD_CTRL for all ports, rather than individual port -* registers -*/ -qca8k_write (priv, reg, -QCA8K_PORT_PAD_RGMII_EN | -QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | -QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY )); -qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , -QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); -break ; -case PHY_INTERFACE_MODE_SGMII : -qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); -break ; -default : -pr_err ("xMII mode %d not supported\n" , mode); -return -EINVAL ; - } - -return 0 ; -} -static void qca8k_port_set_status (struct qca8k_priv *priv,int port,int enable) {
@@ -639,9 +591,7 @@ static int qca8k_setup(struct dsa_switch *ds) {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -phy_interface_t phy_mode =PHY_INTERFACE_MODE_NA ;int ret, i; -u32 mask;/* Make sure that port 0 is the cpu port */ if (!dsa_is_cpu_port (ds,0 )) {
@@ -661,24 +611,9 @@ qca8k_setup(struct dsa_switch *ds)if (ret)return ret; -/* Initialize CPU port pad mode (xMII type, delays...) */ - ret =of_get_phy_mode (dsa_to_port (ds,QCA8K_CPU_PORT )->dn, &phy_mode); -if (ret) { -pr_err ("Can't find phy-mode for master device\n" ); -return ret; - } - ret =qca8k_set_pad_ctrl (priv,QCA8K_CPU_PORT , phy_mode); -if (ret <0 ) -return ret; - -/* Enable CPU Port, force it to maximum bandwidth and full-duplex */ - mask =QCA8K_PORT_STATUS_SPEED_1000 |QCA8K_PORT_STATUS_TXFLOW | -QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_DUPLEX ; -qca8k_write (priv,QCA8K_REG_PORT_STATUS (QCA8K_CPU_PORT ), mask); +/* Enable CPU Port */ qca8k_reg_set (priv,QCA8K_REG_GLOBAL_FW_CTRL0 ,QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN ); -qca8k_port_set_status (priv,QCA8K_CPU_PORT ,1 ); - priv->port_sts[QCA8K_CPU_PORT ].enabled =1 ;/* Enable MIB counters */ qca8k_mib_init (priv);
@@ -693,10 +628,9 @@ qca8k_setup(struct dsa_switch *ds)qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (i),QCA8K_PORT_LOOKUP_MEMBER ,0 ); -/* Disable MAC by default on all user ports */ +/* Disable MAC by default on all ports */ for (i =1 ; i <QCA8K_NUM_PORTS ; i++) -if (dsa_is_user_port (ds, i)) -qca8k_port_set_status (priv, i,0 ); +qca8k_port_set_status (priv, i,0 );/* Forward all unknown frames to CPU port for Linux processing */ qca8k_write(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
@@ -713,7 +647,7 @@ qca8k_setup(struct dsa_switch *ds) QCA8K_PORT_LOOKUP_MEMBER, dsa_user_ports(ds)); } -/* Invividual user ports get connected to CPU port only */ +/* Individual user ports get connected to CPU port only */ if (dsa_is_user_port (ds, i)) {int shift =16 * (i %2 );
@@ -743,44 +677,223 @@ qca8k_setup(struct dsa_switch *ds) }static void -qca8k_adjust_link (struct dsa_switch *ds,int port,struct phy_device *phy) +qca8k_phylink_mac_config (struct dsa_switch *ds,int port,unsigned int mode, +const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv;u32 reg; -/* Force fixed-link setting for CPU port, skip others. */ -if (!phy_is_pseudo_fixed_link (phy)) +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) +return ; + + reg =QCA8K_REG_PORT0_PAD_CTRL ; +break ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY, nothing to do */ +return ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) +return ; + + reg =QCA8K_REG_PORT6_PAD_CTRL ; +break ; +default : +dev_err (ds->dev,"%s: unsupported port: %i\n" , __func__, port); +return ; + } + +if (port !=6 &&phylink_autoneg_inband (mode)) { +dev_err (ds->dev,"%s: in-band negotiation unsupported\n" , + __func__); +return ; + } + +switch (state->interface) { +case PHY_INTERFACE_MODE_RGMII : +/* RGMII mode means no delay so don't enable the delay */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_RGMII_EN ); +break ; +case PHY_INTERFACE_MODE_RGMII_ID : +/* RGMII_ID needs internal delay. This is enabled through +* PORT5_PAD_CTRL for all ports, rather than individual port +* registers +*/ +qca8k_write (priv, reg, +QCA8K_PORT_PAD_RGMII_EN | +QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | +QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY )); +qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , +QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); +break ; +case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_1000BASEX : +/* Enable SGMII on the port */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); +break ; +default : +dev_err (ds->dev,"xMII mode %s not supported for port %d\n" , +phy_modes (state->interface), port);return ; + } +} -/* Set port speed */ -switch (phy->speed) { -case 10 : - reg =QCA8K_PORT_STATUS_SPEED_10 ; +static void +qca8k_phylink_validate (struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state) +{ +__ETHTOOL_DECLARE_LINK_MODE_MASK (mask) = {0 , }; + +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) + goto unsupported;break ; -case 100 : - reg =QCA8K_PORT_STATUS_SPEED_100 ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_GMII ) + goto unsupported;break ; -case 1000 : - reg =QCA8K_PORT_STATUS_SPEED_1000 ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) + goto unsupported;break ;default : -dev_dbg (priv->dev,"port%d link speed %dMbps not supported.\n" , - port, phy->speed); +dev_err (ds->dev,"%s: unsupported port: %i\n" , __func__, port); +unsupported: +linkmode_zero (supported);return ; } -/* Set duplex mode */ -if (phy->duplex ==DUPLEX_FULL ) - reg |=QCA8K_PORT_STATUS_DUPLEX ; +phylink_set_port_modes (mask); +phylink_set (mask, Autoneg); + + phylink_set(mask, 1000baseT_Full); + phylink_set(mask, 10baseT_Half); + phylink_set(mask, 10baseT_Full); + phylink_set(mask, 100baseT_Half); + phylink_set(mask, 100baseT_Full); + +if (state->interface ==PHY_INTERFACE_MODE_1000BASEX ) + phylink_set(mask, 1000baseX_Full); + +phylink_set (mask, Pause); +phylink_set (mask, Asym_Pause); + +linkmode_and (supported, supported, mask); +linkmode_and (state->advertising, state->advertising, mask); +} + +static int +qca8k_phylink_mac_link_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; -/* Force flow control */ -if (dsa_is_cpu_port (ds, port)) - reg |=QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_TXFLOW ; + reg =qca8k_read (priv,QCA8K_REG_PORT_STATUS (port)); + + state->link = !!(reg &QCA8K_PORT_STATUS_LINK_UP ); + state->an_complete = state->link; + state->an_enabled = !!(reg &QCA8K_PORT_STATUS_LINK_AUTO ); + state->duplex = (reg &QCA8K_PORT_STATUS_DUPLEX ) ?DUPLEX_FULL : +DUPLEX_HALF ; + +switch (reg &QCA8K_PORT_STATUS_SPEED ) { +case QCA8K_PORT_STATUS_SPEED_10 : + state->speed =SPEED_10 ; +break ; +case QCA8K_PORT_STATUS_SPEED_100 : + state->speed =SPEED_100 ; +break ; +case QCA8K_PORT_STATUS_SPEED_1000 : + state->speed =SPEED_1000 ; +break ; +default : + state->speed =SPEED_UNKNOWN ; +break ; + } + + state->pause =MLO_PAUSE_NONE ; +if (reg &QCA8K_PORT_STATUS_RXFLOW ) + state->pause |=MLO_PAUSE_RX ; +if (reg &QCA8K_PORT_STATUS_TXFLOW ) + state->pause |=MLO_PAUSE_TX ; + +return 1 ; +} + +static void +qca8k_phylink_mac_link_down (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface) +{ +struct qca8k_priv *priv = ds->priv; -/* Force link down before changing MAC options */ qca8k_port_set_status (priv, port,0 ); +} + +static void +qca8k_phylink_mac_link_up (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface,struct phy_device *phydev, +int speed,int duplex,bool tx_pause,bool rx_pause) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; + +if (phylink_autoneg_inband (mode)) { + reg =QCA8K_PORT_STATUS_LINK_AUTO ; + }else { +switch (speed) { +case SPEED_10 : + reg =QCA8K_PORT_STATUS_SPEED_10 ; +break ; +case SPEED_100 : + reg =QCA8K_PORT_STATUS_SPEED_100 ; +break ; +case SPEED_1000 : + reg =QCA8K_PORT_STATUS_SPEED_1000 ; +break ; +default : + reg =QCA8K_PORT_STATUS_LINK_AUTO ; +break ; + } + +if (duplex ==DUPLEX_FULL ) + reg |=QCA8K_PORT_STATUS_DUPLEX ; + +if (rx_pause |dsa_is_cpu_port (ds, port)) + reg |=QCA8K_PORT_STATUS_RXFLOW ; + +if (tx_pause |dsa_is_cpu_port (ds, port)) + reg |=QCA8K_PORT_STATUS_TXFLOW ; + } + + reg |=QCA8K_PORT_STATUS_TXMAC |QCA8K_PORT_STATUS_RXMAC ; +qca8k_write (priv,QCA8K_REG_PORT_STATUS (port), reg); -qca8k_port_set_status (priv, port,1 ); } static void
@@ -937,13 +1050,11 @@ qca8k_port_enable(struct dsa_switch *ds, int port, {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -if (!dsa_is_user_port (ds, port)) -return 0 ; -qca8k_port_set_status (priv, port,1 ); priv->port_sts[port].enabled =1 ; -phy_support_asym_pause (phy); +if (dsa_is_user_port (ds, port)) +phy_support_asym_pause (phy);return 0 ; }
@@ -1026,7 +1137,6 @@ qca8k_get_tag_protocol(struct dsa_switch *ds, int port,static const struct dsa_switch_ops qca8k_switch_ops = { .get_tag_protocol = qca8k_get_tag_protocol, .setup = qca8k_setup, - .adjust_link = qca8k_adjust_link, .get_strings = qca8k_get_strings, .get_ethtool_stats = qca8k_get_ethtool_stats, .get_sset_count = qca8k_get_sset_count,
@@ -1040,6 +1150,11 @@ static const struct dsa_switch_ops qca8k_switch_ops = { .port_fdb_add = qca8k_port_fdb_add, .port_fdb_del = qca8k_port_fdb_del, .port_fdb_dump = qca8k_port_fdb_dump, + .phylink_validate = qca8k_phylink_validate, + .phylink_mac_link_state = qca8k_phylink_mac_link_state, + .phylink_mac_config = qca8k_phylink_mac_config, + .phylink_mac_link_down = qca8k_phylink_mac_link_down, + .phylink_mac_link_up = qca8k_phylink_mac_link_up, }; static int
Signature · 1 line
2.20.1
PATCH 2/2 net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellThis 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.
--- drivers/net/dsa/qca8k.c | 28 +++++++++++++++++++++++++++- drivers/net/dsa/qca8k.h | 13 +++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-)
drivers/net/dsa/qca8k.c +27 -1
@@ -681,7 +681,7 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv; -u32 reg; +u32 reg, val;switch (port) {case 0 :/* 1st CPU port */
@@ -740,6 +740,32 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,case PHY_INTERFACE_MODE_1000BASEX :/* Enable SGMII on the port */ qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); + +/* Enable/disable SerDes auto-negotiation as necessary */ + val =qca8k_read (priv,QCA8K_REG_PWS ); +if (phylink_autoneg_inband (mode)) + val &= ~QCA8K_PWS_SERDES_AEN_DIS ; +else + val |=QCA8K_PWS_SERDES_AEN_DIS ; +qca8k_write (priv,QCA8K_REG_PWS , val); + +/* Configure the SGMII parameters */ + val =qca8k_read (priv,QCA8K_REG_SGMII_CTRL ); + + val |=QCA8K_SGMII_EN_PLL |QCA8K_SGMII_EN_RX | +QCA8K_SGMII_EN_TX |QCA8K_SGMII_EN_SD ; + + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; +if (dsa_is_cpu_port (ds, port)) { +/* CPU port, we're talking to the CPU MAC, be a PHY */ + val |=QCA8K_SGMII_MODE_CTRL_PHY ; + }else if (state->interface ==PHY_INTERFACE_MODE_SGMII ) { + val |=QCA8K_SGMII_MODE_CTRL_MAC ; + }else { + val |=QCA8K_SGMII_MODE_CTRL_BASEX ; + } + +qca8k_write (priv,QCA8K_REG_SGMII_CTRL , val);break ;default : dev_err(ds->dev, "xMII mode %s not supported for port %d\n",
drivers/net/dsa/qca8k.h +13 -0
@@ -36,6 +36,8 @@#define QCA8K_MAX_DELAY 3#define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24)#define QCA8K_PORT_PAD_SGMII_EN BIT(7) +#define QCA8K_REG_PWS 0x010 +#define QCA8K_PWS_SERDES_AEN_DIS BIT(7)#define QCA8K_REG_MODULE_EN 0x030#define QCA8K_MODULE_EN_MIB BIT(0)#define QCA8K_REG_MIB 0x034
@@ -69,6 +71,7 @@#define QCA8K_PORT_STATUS_LINK_UP BIT(8)#define QCA8K_PORT_STATUS_LINK_AUTO BIT(9)#define QCA8K_PORT_STATUS_LINK_PAUSE BIT(10) +#define QCA8K_PORT_STATUS_FLOW_AUTO BIT(12)#define QCA8K_REG_PORT_HDR_CTRL (_i) (0x9c + (_i * 4))#define QCA8K_PORT_HDR_CTRL_RX_MASK GENMASK(3, 2)#define QCA8K_PORT_HDR_CTRL_RX_S 2
@@ -77,6 +80,16 @@#define QCA8K_PORT_HDR_CTRL_ALL 2#define QCA8K_PORT_HDR_CTRL_MGMT 1#define QCA8K_PORT_HDR_CTRL_NONE 0 +#define QCA8K_REG_SGMII_CTRL 0x0e0 +#define QCA8K_SGMII_EN_PLL BIT(1) +#define QCA8K_SGMII_EN_RX BIT(2) +#define QCA8K_SGMII_EN_TX BIT(3) +#define QCA8K_SGMII_EN_SD BIT(4) +#define QCA8K_SGMII_CLK125M_DELAY BIT(7) +#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23)) +#define QCA8K_SGMII_MODE_CTRL_BASEX (0 << 22) +#define QCA8K_SGMII_MODE_CTRL_PHY (1 << 22) +#define QCA8K_SGMII_MODE_CTRL_MAC (2 << 22)/* EEE control registers */ #define QCA8K_REG_EEE_CTRL 0x100
Signature · 1 line
2.20.1
David Miller
maintainerRe: [RFC PATCH v3 0/2] net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellPlease, when you post an RFC patch set, put "RFC" into the Subject lines of the patches as well as the introductory posting.
This helps me categorize changes properly in patchwork.
Thank you.
Re: [PATCH 1/2] net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
In reply to Jonathan McDowellQuoted 4 lines · Jonathan McDowell
Update the driver to use the new PHYLINK callbacks, removing the legacy
adjust_linkcallback.Signed-off-by Jonathan McDowell <[email protected]>
This looks reasonable to me, Russell would be the person you want to get an Acked-by/Reviewed-by tag from.
Signature · 1 line
Florian
Re: [PATCH 2/2] net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellQuoted 43 lines · Jonathan McDowell
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 <[email protected]>--- drivers/net/dsa/qca8k.c | 28 +++++++++++++++++++++++++++- drivers/net/dsa/qca8k.h | 13 +++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-)drivers/net/dsa/qca8k.c +10
-1@@ -681,7 +681,7 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv; -u32 reg; +u32 reg, val;switch (port) {case 0 :/* 1st CPU port */ @@ -740,6 +740,32 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,case PHY_INTERFACE_MODE_1000BASEX :/* Enable SGMII on the port */ qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); + +/* Enable/disable SerDes auto-negotiation as necessary */ + val =qca8k_read (priv,QCA8K_REG_PWS ); +if (phylink_autoneg_inband (mode)) + val &= ~QCA8K_PWS_SERDES_AEN_DIS ; +else + val |=QCA8K_PWS_SERDES_AEN_DIS ; +qca8k_write (priv,QCA8K_REG_PWS , val); +
drivers/net/dsa/qca8k.c qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, · line 761
Quoted 10 lines
drivers/net/dsa/qca8k.c +10
-0+/* Configure the SGMII parameters */ + val =qca8k_read (priv,QCA8K_REG_SGMII_CTRL ); + + val |=QCA8K_SGMII_EN_PLL |QCA8K_SGMII_EN_RX | +QCA8K_SGMII_EN_TX |QCA8K_SGMII_EN_SD ; + + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; +if (dsa_is_cpu_port (ds, port)) { +/* CPU port, we're talking to the CPU MAC, be a PHY */ + val |=QCA8K_SGMII_MODE_CTRL_PHY ;
Since port 6 can be interfaced to an external PHY, do not you have to differentiate here whether this port is connected to an actual PHY, versus connected to a MAC? You should be able to use mode == MLO_AN_PHY to differentiate that case from the others.
drivers/net/dsa/qca8k.c qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, · line 765
Quoted 4 lines
drivers/net/dsa/qca8k.c +4
-0+ }else if (state->interface ==PHY_INTERFACE_MODE_SGMII ) { + val |=QCA8K_SGMII_MODE_CTRL_MAC ; + }else { + val |=QCA8K_SGMII_MODE_CTRL_BASEX ;
Better make this explicit and check for PHY_INTERFACE_MODE_1000BASEX, even if those are the only two possible values covered by this part of the case statement.
Signature · 1 line
Florian
Re: [PATCH 1/2] net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
In reply to Jonathan McDowellQuoted 2 lines · Jonathan McDowell
Update the driver to use the new PHYLINK callbacks, removing the legacy
adjust_linkcallback.
Looks good, there's a couple of issues / questions
Quoted 8 lines
static void
drivers/net/dsa/qca8k.c +3
-0+qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, + const struct phylink_link_state *state) { struct qca8k_priv *priv = ds->priv;u32 reg; +switch (port) {
...
Quoted 9 lines
drivers/net/dsa/qca8k.c +9
-0+case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) +return ; + + reg =QCA8K_REG_PORT6_PAD_CTRL ; +break ;
...
Quoted 9 lines
drivers/net/dsa/qca8k.c +9
-0+ } + +if (port !=6 &&phylink_autoneg_inband (mode)) { +dev_err (ds->dev,"%s: in-band negotiation unsupported\n" , + __func__); +return ; + } + +switch (state->interface) {
...
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 743
Quoted 5 lines
drivers/net/dsa/qca8k.c +5
-0+case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_1000BASEX : +/* Enable SGMII on the port */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); +break ;
Is inband mode configurable? What if the link partner does/doesn't send the configuration word? How is the link state communicated to the MAC?
Quoted 17 lines
drivers/net/dsa/qca8k.c +16
-0+static int +qca8k_phylink_mac_link_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; + reg =qca8k_read (priv,QCA8K_REG_PORT_STATUS (port)); + + state->link = !!(reg &QCA8K_PORT_STATUS_LINK_UP ); + state->an_complete = state->link; + state->an_enabled = !!(reg &QCA8K_PORT_STATUS_LINK_AUTO ); + state->duplex = (reg &QCA8K_PORT_STATUS_DUPLEX ) ?DUPLEX_FULL : +DUPLEX_HALF ; + +switch (reg &QCA8K_PORT_STATUS_SPEED ) { +case QCA8K_PORT_STATUS_SPEED_10 :
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 836
Quoted 10 lines
drivers/net/dsa/qca8k.c +10
-0+ state->speed =SPEED_10 ; +break ; +case QCA8K_PORT_STATUS_SPEED_100 : + state->speed =SPEED_100 ; +break ; +case QCA8K_PORT_STATUS_SPEED_1000 : + state->speed =SPEED_1000 ; +break ; +default : + state->speed =SPEED_UNKNOWN ;
Maybe also force the link down in this case, since the state is invalid?
Do you have access to the link partner's configuration word? If you do, you should use that to fill in state->lp_advertising.
Quoted 9 lines
drivers/net/dsa/qca8k.c +9
-0+break ; + } + + state->pause =MLO_PAUSE_NONE ; +if (reg &QCA8K_PORT_STATUS_RXFLOW ) + state->pause |=MLO_PAUSE_RX ; +if (reg &QCA8K_PORT_STATUS_TXFLOW ) + state->pause |=MLO_PAUSE_TX ; +
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 855
Quoted 10 lines
drivers/net/dsa/qca8k.c +8
-0+return 1 ; +} + +static void +qca8k_phylink_mac_link_down (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface) +{ +struct qca8k_priv *priv = ds->priv;qca8k_port_set_status (priv, port,0 );
If operating in in-band mode, forcing the link down unconditionally will prevent the link coming up if the SGMII/1000base-X block automatically updates the MAC, and if this takes precedence.
When using in-band mode, you need to call dsa_port_phylink_mac_change() to keep phylink updated with the link status.
Alternatively, phylink supports polling mode, but due to the layered way DSA is written, DSA drivers don't have access to that as that is in the DSA upper levels in net/dsa/slave.c (dsa_slave_phy_setup(), it would be dp->pl_config.pcs_poll).
Apart from those points, I think it looks fine, thanks.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC for 0.8m (est. 1762m) line in suburbia: sync at 13.1Mbps down 503kbps up
Vladimir Oltean
maintainerRe: [PATCH 1/2] net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
In reply to Jonathan McDowellHi Jonathan,
Quoted 188 lines · Jonathan McDowell
Update the driver to use the new PHYLINK callbacks, removing the legacy
adjust_linkcallback.Signed-off-by Jonathan McDowell <[email protected]>--- drivers/net/dsa/qca8k.c | 309 +++++++++++++++++++++++++++------------- 1 file changed, 212 insertions(+), 97 deletions(-)drivers/net/dsa/qca8k.c +47
-74@@ -14,6 +14,7 @@#include <linux/of_platform.h> #include <linux/if_bridge.h> #include <linux/mdio.h> +#include <linux/phylink.h> #include <linux/gpio/consumer.h> #include <linux/etherdevice.h> @@ -418,55 +419,6 @@ qca8k_mib_init(struct qca8k_priv *priv)mutex_unlock (&priv->reg_mutex); } -static int -qca8k_set_pad_ctrl (struct qca8k_priv *priv,int port,int mode) -{ -u32 reg, val; - -switch (port) { -case 0 : - reg =QCA8K_REG_PORT0_PAD_CTRL ; -break ; -case 6 : - reg =QCA8K_REG_PORT6_PAD_CTRL ; -break ; -default : -pr_err ("Can't set PAD_CTRL on port %d\n" , port); -return -EINVAL ; - } - -/* Configure a port to be directly connected to an external -* PHY or MAC. -*/ -switch (mode) { -case PHY_INTERFACE_MODE_RGMII : -/* RGMII mode means no delay so don't enable the delay */ - val =QCA8K_PORT_PAD_RGMII_EN ; -qca8k_write (priv, reg, val); -break ; -case PHY_INTERFACE_MODE_RGMII_ID : -/* RGMII_ID needs internal delay. This is enabled through -* PORT5_PAD_CTRL for all ports, rather than individual port -* registers -*/ -qca8k_write (priv, reg, -QCA8K_PORT_PAD_RGMII_EN | -QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | -QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY )); -qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , -QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); -break ; -case PHY_INTERFACE_MODE_SGMII : -qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); -break ; -default : -pr_err ("xMII mode %d not supported\n" , mode); -return -EINVAL ; - } - -return 0 ; -} -static void qca8k_port_set_status (struct qca8k_priv *priv,int port,int enable) {@@ -639,9 +591,7 @@ static int qca8k_setup(struct dsa_switch *ds) {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -phy_interface_t phy_mode =PHY_INTERFACE_MODE_NA ;int ret, i; -u32 mask;/* Make sure that port 0 is the cpu port */ if (!dsa_is_cpu_port (ds,0 )) {@@ -661,24 +611,9 @@ qca8k_setup(struct dsa_switch *ds)if (ret)return ret; -/* Initialize CPU port pad mode (xMII type, delays...) */ - ret =of_get_phy_mode (dsa_to_port (ds,QCA8K_CPU_PORT )->dn, &phy_mode); -if (ret) { -pr_err ("Can't find phy-mode for master device\n" ); -return ret; - } - ret =qca8k_set_pad_ctrl (priv,QCA8K_CPU_PORT , phy_mode); -if (ret <0 ) -return ret; - -/* Enable CPU Port, force it to maximum bandwidth and full-duplex */ - mask =QCA8K_PORT_STATUS_SPEED_1000 |QCA8K_PORT_STATUS_TXFLOW | -QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_DUPLEX ; -qca8k_write (priv,QCA8K_REG_PORT_STATUS (QCA8K_CPU_PORT ), mask); +/* Enable CPU Port */ qca8k_reg_set (priv,QCA8K_REG_GLOBAL_FW_CTRL0 ,QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN ); -qca8k_port_set_status (priv,QCA8K_CPU_PORT ,1 ); - priv->port_sts[QCA8K_CPU_PORT ].enabled =1 ;/* Enable MIB counters */ qca8k_mib_init (priv);@@ -693,10 +628,9 @@ qca8k_setup(struct dsa_switch *ds)qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (i),QCA8K_PORT_LOOKUP_MEMBER ,0 ); -/* Disable MAC by default on all user ports */ +/* Disable MAC by default on all ports */ for (i =1 ; i <QCA8K_NUM_PORTS ; i++) -if (dsa_is_user_port (ds, i)) -qca8k_port_set_status (priv, i,0 ); +qca8k_port_set_status (priv, i,0 );/* Forward all unknown frames to CPU port for Linux processing */ qca8k_write(priv, QCA8K_REG_GLOBAL_FW_CTRL1,@@ -713,7 +647,7 @@ qca8k_setup(struct dsa_switch *ds) QCA8K_PORT_LOOKUP_MEMBER, dsa_user_ports(ds)); } -/* Invividual user ports get connected to CPU port only */ +/* Individual user ports get connected to CPU port only */ if (dsa_is_user_port (ds, i)) {int shift =16 * (i %2 );@@ -743,44 +677,223 @@ qca8k_setup(struct dsa_switch *ds) }static void -qca8k_adjust_link (struct dsa_switch *ds,int port,struct phy_device *phy) +qca8k_phylink_mac_config (struct dsa_switch *ds,int port,unsigned int mode, +const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv;u32 reg; -/* Force fixed-link setting for CPU port, skip others. */ -if (!phy_is_pseudo_fixed_link (phy)) +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) +return ; + + reg =QCA8K_REG_PORT0_PAD_CTRL ; +break ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY, nothing to do */ +return ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) +return ; + + reg =QCA8K_REG_PORT6_PAD_CTRL ; +break ; +default : +dev_err (ds->dev,"%s: unsupported port: %i\n" , __func__, port); +return ; + } + +if (port !=6 &&phylink_autoneg_inband (mode)) { +dev_err (ds->dev,"%s: in-band negotiation unsupported\n" , + __func__); +return ; + } + +switch (state->interface) { +case PHY_INTERFACE_MODE_RGMII : +/* RGMII mode means no delay so don't enable the delay */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_RGMII_EN );
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 735
Quoted 10 lines
drivers/net/dsa/qca8k.c +10
-0+break ; +case PHY_INTERFACE_MODE_RGMII_ID : +/* RGMII_ID needs internal delay. This is enabled through +* PORT5_PAD_CTRL for all ports, rather than individual port +* registers +*/ +qca8k_write (priv, reg, +QCA8K_PORT_PAD_RGMII_EN | +QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | +QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY ));
3 points here:
- Should you prevalidate the device tree bindings that in case rgmii* mode are used, same delay settings are applied to all ports?
- Can any RGMII port be connected to a PHY? If it can, won't the PHY enable delays too for RGMII_ID? Will the link work in that case?
- Should you treat RGMII_TX_DELAY and RGMII_RX_DELAY independently for the case where there may be PCB traces?
Quoted 50 lines
drivers/net/dsa/qca8k.c +38
-8+qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , +QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); +break ; +case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_1000BASEX : +/* Enable SGMII on the port */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); +break ; +default : +dev_err (ds->dev,"xMII mode %s not supported for port %d\n" , +phy_modes (state->interface), port);return ; + } +} -/* Set port speed */ -switch (phy->speed) { -case 10 : - reg =QCA8K_PORT_STATUS_SPEED_10 ; +static void +qca8k_phylink_validate (struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state) +{ +__ETHTOOL_DECLARE_LINK_MODE_MASK (mask) = {0 , }; + +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) + goto unsupported;break ; -case 100 : - reg =QCA8K_PORT_STATUS_SPEED_100 ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_GMII ) + goto unsupported;break ; -case 1000 : - reg =QCA8K_PORT_STATUS_SPEED_1000 ; +case 6 :/* 2nd CPU port / external PHY */ + if (state->interface != PHY_INTERFACE_MODE_NA &&
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 785
Quoted 10 lines
drivers/net/dsa/qca8k.c +6
-2+ state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface != PHY_INTERFACE_MODE_1000BASEX) + goto unsupported;break ;default : -dev_dbg (priv->dev,"port%d link speed %dMbps not supported.\n" , - port, phy->speed); +dev_err (ds->dev,"%s: unsupported port: %i\n" , __func__, port);
phylink has a better validation error message than this, I'd say this is unnecessary.
Quoted 99 lines
drivers/net/dsa/qca8k.c +86
-7+unsupported: +linkmode_zero (supported);return ; } -/* Set duplex mode */ -if (phy->duplex ==DUPLEX_FULL ) - reg |=QCA8K_PORT_STATUS_DUPLEX ; +phylink_set_port_modes (mask); +phylink_set (mask, Autoneg); + + phylink_set(mask, 1000baseT_Full); + phylink_set(mask, 10baseT_Half); + phylink_set(mask, 10baseT_Full); + phylink_set(mask, 100baseT_Half); + phylink_set(mask, 100baseT_Full); + +if (state->interface ==PHY_INTERFACE_MODE_1000BASEX ) + phylink_set(mask, 1000baseX_Full); + +phylink_set (mask, Pause); +phylink_set (mask, Asym_Pause); + +linkmode_and (supported, supported, mask); +linkmode_and (state->advertising, state->advertising, mask); +} + +static int +qca8k_phylink_mac_link_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; -/* Force flow control */ -if (dsa_is_cpu_port (ds, port)) - reg |=QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_TXFLOW ; + reg =qca8k_read (priv,QCA8K_REG_PORT_STATUS (port)); + + state->link = !!(reg &QCA8K_PORT_STATUS_LINK_UP ); + state->an_complete = state->link; + state->an_enabled = !!(reg &QCA8K_PORT_STATUS_LINK_AUTO ); + state->duplex = (reg &QCA8K_PORT_STATUS_DUPLEX ) ?DUPLEX_FULL : +DUPLEX_HALF ; + +switch (reg &QCA8K_PORT_STATUS_SPEED ) { +case QCA8K_PORT_STATUS_SPEED_10 : + state->speed =SPEED_10 ; +break ; +case QCA8K_PORT_STATUS_SPEED_100 : + state->speed =SPEED_100 ; +break ; +case QCA8K_PORT_STATUS_SPEED_1000 : + state->speed =SPEED_1000 ; +break ; +default : + state->speed =SPEED_UNKNOWN ; +break ; + } + + state->pause =MLO_PAUSE_NONE ; +if (reg &QCA8K_PORT_STATUS_RXFLOW ) + state->pause |=MLO_PAUSE_RX ; +if (reg &QCA8K_PORT_STATUS_TXFLOW ) + state->pause |=MLO_PAUSE_TX ; + +return 1 ; +} + +static void +qca8k_phylink_mac_link_down (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface) +{ +struct qca8k_priv *priv = ds->priv; -/* Force link down before changing MAC options */ qca8k_port_set_status (priv, port,0 ); +} + +static void +qca8k_phylink_mac_link_up (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface,struct phy_device *phydev, +int speed,int duplex,bool tx_pause,bool rx_pause) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; + +if (phylink_autoneg_inband (mode)) { + reg =QCA8K_PORT_STATUS_LINK_AUTO ; + }else { +switch (speed) { +case SPEED_10 : + reg =QCA8K_PORT_STATUS_SPEED_10 ; +break ; +case SPEED_100 : + reg =QCA8K_PORT_STATUS_SPEED_100 ; +break ; +case SPEED_1000 : + reg =QCA8K_PORT_STATUS_SPEED_1000 ;
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 887
Quoted 10 lines
drivers/net/dsa/qca8k.c +10
-0+break ; +default : + reg =QCA8K_PORT_STATUS_LINK_AUTO ; +break ; + } + +if (duplex ==DUPLEX_FULL ) + reg |=QCA8K_PORT_STATUS_DUPLEX ; + +if (rx_pause |dsa_is_cpu_port (ds, port))
I think it is odd to do bitwise OR on booleans.
Quoted 50 lines
drivers/net/dsa/qca8k.c +15
-7+ reg |=QCA8K_PORT_STATUS_RXFLOW ; + +if (tx_pause |dsa_is_cpu_port (ds, port)) + reg |=QCA8K_PORT_STATUS_TXFLOW ; + } + + reg |=QCA8K_PORT_STATUS_TXMAC |QCA8K_PORT_STATUS_RXMAC ; +qca8k_write (priv,QCA8K_REG_PORT_STATUS (port), reg); -qca8k_port_set_status (priv, port,1 ); } static void@@ -937,13 +1050,11 @@ qca8k_port_enable(struct dsa_switch *ds, int port, {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -if (!dsa_is_user_port (ds, port)) -return 0 ; -qca8k_port_set_status (priv, port,1 ); priv->port_sts[port].enabled =1 ; -phy_support_asym_pause (phy); +if (dsa_is_user_port (ds, port)) +phy_support_asym_pause (phy);return 0 ; }@@ -1026,7 +1137,6 @@ qca8k_get_tag_protocol(struct dsa_switch *ds, int port,static const struct dsa_switch_ops qca8k_switch_ops = { .get_tag_protocol = qca8k_get_tag_protocol, .setup = qca8k_setup, - .adjust_link = qca8k_adjust_link, .get_strings = qca8k_get_strings, .get_ethtool_stats = qca8k_get_ethtool_stats, .get_sset_count = qca8k_get_sset_count,@@ -1040,6 +1150,11 @@ static const struct dsa_switch_ops qca8k_switch_ops = { .port_fdb_add = qca8k_port_fdb_add, .port_fdb_del = qca8k_port_fdb_del, .port_fdb_dump = qca8k_port_fdb_dump, + .phylink_validate = qca8k_phylink_validate, + .phylink_mac_link_state = qca8k_phylink_mac_link_state, + .phylink_mac_config = qca8k_phylink_mac_config, + .phylink_mac_link_down = qca8k_phylink_mac_link_down, + .phylink_mac_link_up = qca8k_phylink_mac_link_up, }; static int --
Quoted 2 lines
2.20.1
Cheers,
-Vladimir
Re: [PATCH 2/2] net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellQuoted 50 lines · Jonathan McDowell
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 <[email protected]>--- drivers/net/dsa/qca8k.c | 28 +++++++++++++++++++++++++++- drivers/net/dsa/qca8k.h | 13 +++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-)drivers/net/dsa/qca8k.c +17
-1@@ -681,7 +681,7 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv; -u32 reg; +u32 reg, val;switch (port) {case 0 :/* 1st CPU port */ @@ -740,6 +740,32 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,case PHY_INTERFACE_MODE_1000BASEX :/* Enable SGMII on the port */ qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); + +/* Enable/disable SerDes auto-negotiation as necessary */ + val =qca8k_read (priv,QCA8K_REG_PWS ); +if (phylink_autoneg_inband (mode)) + val &= ~QCA8K_PWS_SERDES_AEN_DIS ; +else + val |=QCA8K_PWS_SERDES_AEN_DIS ; +qca8k_write (priv,QCA8K_REG_PWS , val); + +/* Configure the SGMII parameters */ + val =qca8k_read (priv,QCA8K_REG_SGMII_CTRL ); + + val |=QCA8K_SGMII_EN_PLL |QCA8K_SGMII_EN_RX | +QCA8K_SGMII_EN_TX |QCA8K_SGMII_EN_SD ; + + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ;
drivers/net/dsa/qca8k.c qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, · line 768
Quoted 10 lines
drivers/net/dsa/qca8k.c +10
-0+if (dsa_is_cpu_port (ds, port)) { +/* CPU port, we're talking to the CPU MAC, be a PHY */ + val |=QCA8K_SGMII_MODE_CTRL_PHY ; + }else if (state->interface ==PHY_INTERFACE_MODE_SGMII ) { + val |=QCA8K_SGMII_MODE_CTRL_MAC ; + }else { + val |=QCA8K_SGMII_MODE_CTRL_BASEX ; + } + +qca8k_write (priv,QCA8K_REG_SGMII_CTRL , val);
Ah, here it is! Hmm, I suppose as the two patches will be applied together, it's fine to split it like this.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC for 0.8m (est. 1762m) line in suburbia: sync at 13.1Mbps down 503kbps up
Vladimir Oltean
maintainerRe: [PATCH 1/2] net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
In reply to Russell King - ARM Linux adminHi Russell,
Quoted 8 lines · Russell King - ARM Linux admin
Alternatively, phylink supports polling mode, but due to the layered way DSA is written, DSA drivers don't have access to that as that is in the DSA upper levels in
net/dsa/slave.c(dsa_slave_phy_setup(), it would bedp->pl_config.pcs_poll).
They do, see https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/drivers/net/dsa/ocelot/felix.c#n606
Quoted 4 lines
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC for 0.8m (est. 1762m) line in suburbia: sync at 13.1Mbps down 503kbps up
Thanks,
-Vladimir
Re: [PATCH 1/2] net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
In reply to Vladimir OlteanQuoted 8 lines · Vladimir Oltean
Hi Jonathan,
Quoted 5 lines · Jonathan McDowell
Update the driver to use the new PHYLINK callbacks, removing the legacy
adjust_linkcallback.Signed-off-by Jonathan McDowell <[email protected]>
...
Quoted 61 lines
Quoted 50 lines
static void
drivers/net/dsa/qca8k.c +42
-3-qca8k_adjust_link(struct dsa_switch *ds, int port, struct phy_device *phy) +qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, + const struct phylink_link_state *state) { struct qca8k_priv *priv = ds->priv;u32 reg; -/* Force fixed-link setting for CPU port, skip others. */ -if (!phy_is_pseudo_fixed_link (phy)) +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) +return ; + + reg =QCA8K_REG_PORT0_PAD_CTRL ; +break ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY, nothing to do */ +return ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) +return ; + + reg =QCA8K_REG_PORT6_PAD_CTRL ; +break ; +default : +dev_err (ds->dev,"%s: unsupported port: %i\n" , __func__, port); +return ; + } + +if (port !=6 &&phylink_autoneg_inband (mode)) { +dev_err (ds->dev,"%s: in-band negotiation unsupported\n" , + __func__); +return ; + } + +switch (state->interface) { +case PHY_INTERFACE_MODE_RGMII : +/* RGMII mode means no delay so don't enable the delay */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_RGMII_EN );drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 735
Quoted 10 lines
drivers/net/dsa/qca8k.c +10
-0+break ; +case PHY_INTERFACE_MODE_RGMII_ID : +/* RGMII_ID needs internal delay. This is enabled through +* PORT5_PAD_CTRL for all ports, rather than individual port +* registers +*/ +qca8k_write (priv, reg, +QCA8K_PORT_PAD_RGMII_EN | +QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | +QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY ));
Quoted 7 lines
3 points here:
- Should you prevalidate the device tree bindings that in case rgmii* mode are used, same delay settings are applied to all ports?
- Can any RGMII port be connected to a PHY? If it can, won't the PHY enable delays too forRGMII_ID? Will the link work in that case?
- Should you treatRGMII_TX_DELAYandRGMII_RX_DELAYindependently for the case where there may be PCB traces?
The intent with this patch was to pull out the conversion to PHYLINK to be stand-alone, with no functional changes, as request by Andrew. I think there's room for some future clean-up here around the RGMII options, but my main purpose in this patch set is to improve the SGMII portion which my hardware uses that doesn't work with mainline.
Quoted 36 lines
Quoted 36 lines
drivers/net/dsa/qca8k.c +30
-4+static void +qca8k_phylink_validate (struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state) +{ +__ETHTOOL_DECLARE_LINK_MODE_MASK (mask) = {0 , }; + +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) + goto unsupported;break ; -case 100 : - reg =QCA8K_PORT_STATUS_SPEED_100 ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_GMII ) + goto unsupported;break ; -case 1000 : - reg =QCA8K_PORT_STATUS_SPEED_1000 ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) + goto unsupported;
Quoted 8 lines
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 785
Quoted 5 lines
break; default:drivers/net/dsa/qca8k.c +1
-2-dev_dbg (priv->dev,"port%d link speed %dMbps not supported.\n" , - port, phy->speed); +dev_err (ds->dev,"%s: unsupported port: %i\n" , __func__, port);phylink has a better validation error message than this, I'd say this is unnecessary.
Ok.
Quoted 24 lines
Quoted 24 lines
drivers/net/dsa/qca8k.c +24
-0+static void +qca8k_phylink_mac_link_up (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface,struct phy_device *phydev, +int speed,int duplex,bool tx_pause,bool rx_pause) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; + +if (phylink_autoneg_inband (mode)) { + reg =QCA8K_PORT_STATUS_LINK_AUTO ; + }else { +switch (speed) { +case SPEED_10 : + reg =QCA8K_PORT_STATUS_SPEED_10 ; +break ; +case SPEED_100 : + reg =QCA8K_PORT_STATUS_SPEED_100 ; +break ; +case SPEED_1000 : + reg =QCA8K_PORT_STATUS_SPEED_1000 ; +break ; +default : + reg =QCA8K_PORT_STATUS_LINK_AUTO ; +break ;
Quoted 8 lines
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 887
Quoted 6 lines
drivers/net/dsa/qca8k.c +6
-0+ } + +if (duplex ==DUPLEX_FULL ) + reg |=QCA8K_PORT_STATUS_DUPLEX ; + +if (rx_pause |dsa_is_cpu_port (ds, port))I think it is odd to do bitwise OR on booleans.
I agree; will fix in the next spin.
J.
Signature · 1 line
I get the feeling that I've been cheated.
Re: [PATCH 2/2] net: dsa: qca8k: Improve SGMII interface handling
In reply to Florian FainelliQuoted 51 lines · Florian Fainelli
Quoted 50 lines · Jonathan McDowell
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 <[email protected]>--- drivers/net/dsa/qca8k.c | 28 +++++++++++++++++++++++++++- drivers/net/dsa/qca8k.h | 13 +++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-)drivers/net/dsa/qca8k.c +17
-1@@ -681,7 +681,7 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv; -u32 reg; +u32 reg, val;switch (port) {case 0 :/* 1st CPU port */ @@ -740,6 +740,32 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,case PHY_INTERFACE_MODE_1000BASEX :/* Enable SGMII on the port */ qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); + +/* Enable/disable SerDes auto-negotiation as necessary */ + val =qca8k_read (priv,QCA8K_REG_PWS ); +if (phylink_autoneg_inband (mode)) + val &= ~QCA8K_PWS_SERDES_AEN_DIS ; +else + val |=QCA8K_PWS_SERDES_AEN_DIS ; +qca8k_write (priv,QCA8K_REG_PWS , val); + +/* Configure the SGMII parameters */ + val =qca8k_read (priv,QCA8K_REG_SGMII_CTRL ); + + val |=QCA8K_SGMII_EN_PLL |QCA8K_SGMII_EN_RX | +QCA8K_SGMII_EN_TX |QCA8K_SGMII_EN_SD ; + + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ;
Quoted 8 lines
drivers/net/dsa/qca8k.c qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, · line 761
Quoted 3 lines
drivers/net/dsa/qca8k.c +3
-0+if (dsa_is_cpu_port (ds, port)) { +/* CPU port, we're talking to the CPU MAC, be a PHY */ + val |=QCA8K_SGMII_MODE_CTRL_PHY ;Since port 6 can be interfaced to an external PHY, do not you have to differentiate here whether this port is connected to an actual PHY, versus connected to a MAC? You should be able to use mode ==
MLO_AN_PHYto differentiate that case from the others.
I don't think MLO_AN_PHY is sufficient? If it's a fixed link we'll have MLO_AN_FIXED and that could be talking to a PHY?
The logic I've gone for is assuming that a port hooked up to the CPU should look like a PHY, and otherwise we're hooked up to a PHY so we're acting as a MAC. That means we don't cope with the situation that we're hooked up to something that isn't the CPU but wants us to look like a PHY, but I don't think we have any current way to describe that.
Quoted 8 lines
drivers/net/dsa/qca8k.c qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, · line 765
Quoted 4 lines
drivers/net/dsa/qca8k.c +4
-0+ }else if (state->interface ==PHY_INTERFACE_MODE_SGMII ) { + val |=QCA8K_SGMII_MODE_CTRL_MAC ; + }else { + val |=QCA8K_SGMII_MODE_CTRL_BASEX ;Better make this explicit and check for
PHY_INTERFACE_MODE_1000BASEX, even if those are the only two possible values covered by this part of the case statement.
Sure. I'll move the mask inside the if block too in that case, so we don't change the setting if we get fed something invalid.
J.
Signature · 1 line
Beware of programmers carrying screwdrivers.
Re: [PATCH 1/2] net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
In reply to Russell King - ARM Linux adminQuoted 35 lines · Russell King - ARM Linux admin
Quoted 2 lines · Jonathan McDowell
Update the driver to use the new PHYLINK callbacks, removing the legacy
adjust_linkcallback.Looks good, there's a couple of issues / questions
Quoted 8 lines
static void
drivers/net/dsa/qca8k.c +3
-0+qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, + const struct phylink_link_state *state) { struct qca8k_priv *priv = ds->priv;u32 reg; +switch (port) {...
Quoted 9 lines
drivers/net/dsa/qca8k.c +9
-0+case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) +return ; + + reg =QCA8K_REG_PORT6_PAD_CTRL ; +break ;...
Quoted 9 lines
drivers/net/dsa/qca8k.c +9
-0+ } + +if (port !=6 &&phylink_autoneg_inband (mode)) { +dev_err (ds->dev,"%s: in-band negotiation unsupported\n" , + __func__); +return ; + } + +switch (state->interface) {...
Quoted 9 lines
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 743
Quoted 5 lines
drivers/net/dsa/qca8k.c +5
-0+case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_1000BASEX : +/* Enable SGMII on the port */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); +break ;Is inband mode configurable? What if the link partner does/doesn't send the configuration word? How is the link state communicated to the MAC?
I moved those over to the second patch on the request of Andrew Lunn, who wanted the phylink change to be separate from the addition of the SGMII changes. This first patch should result in no change of behaviour, just the move to phylink.
Quoted 30 lines
Quoted 17 lines
drivers/net/dsa/qca8k.c +16
-0+static int +qca8k_phylink_mac_link_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; + reg =qca8k_read (priv,QCA8K_REG_PORT_STATUS (port)); + + state->link = !!(reg &QCA8K_PORT_STATUS_LINK_UP ); + state->an_complete = state->link; + state->an_enabled = !!(reg &QCA8K_PORT_STATUS_LINK_AUTO ); + state->duplex = (reg &QCA8K_PORT_STATUS_DUPLEX ) ?DUPLEX_FULL : +DUPLEX_HALF ; + +switch (reg &QCA8K_PORT_STATUS_SPEED ) { +case QCA8K_PORT_STATUS_SPEED_10 :drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 836
Quoted 10 lines
drivers/net/dsa/qca8k.c +10
-0+ state->speed =SPEED_10 ; +break ; +case QCA8K_PORT_STATUS_SPEED_100 : + state->speed =SPEED_100 ; +break ; +case QCA8K_PORT_STATUS_SPEED_1000 : + state->speed =SPEED_1000 ; +break ; +default : + state->speed =SPEED_UNKNOWN ;Maybe also force the link down in this case, since the state is invalid?
Quoted 2 lines
Do you have access to the link partner's configuration word? If you do, you should use that to fill in
state->lp_advertising.
It doesn't seem to be available from my reading of the data sheet.
Quoted 24 lines
Quoted 9 lines
drivers/net/dsa/qca8k.c +9
-0+break ; + } + + state->pause =MLO_PAUSE_NONE ; +if (reg &QCA8K_PORT_STATUS_RXFLOW ) + state->pause |=MLO_PAUSE_RX ; +if (reg &QCA8K_PORT_STATUS_TXFLOW ) + state->pause |=MLO_PAUSE_TX ; +drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 855
Quoted 10 lines
drivers/net/dsa/qca8k.c +8
-0+return 1 ; +} + +static void +qca8k_phylink_mac_link_down (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface) +{ +struct qca8k_priv *priv = ds->priv;qca8k_port_set_status (priv, port,0 );If operating in in-band mode, forcing the link down unconditionally will prevent the link coming up if the SGMII/1000base-X block automatically updates the MAC, and if this takes precedence.
Quoted 7 lines
When using in-band mode, you need to call
dsa_port_phylink_mac_change()to keep phylink updated with the link status.Alternatively, phylink supports polling mode, but due to the layered way DSA is written, DSA drivers don't have access to that as that is in the DSA upper levels in
net/dsa/slave.c(dsa_slave_phy_setup(), it would bedp->pl_config.pcs_poll).
My reading of Vladimir's mail is I can set pcs_poll to get that functionality, and from the data sheet the link detection is keyed off a separate bit than the mac link down piece so I think I'm ok there.
Quoted 1 line
Apart from those points, I think it looks fine, thanks.
Thanks for the review. I'll get a new version out soon.
J.
Signature · 1 line
If a program is useless, it must be documented.
v4 cover net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellHopefully getting there, thanks for all the review comments.
This 2 patch series migrates the qca8k switch driver over to PHYLINK, and then adds the SGMII clean-ups (i.e. the missing initialisation) on top of that as a second patch.
As before, 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.
v4:
- Enable pcs_poll so we keep phylink updated when doing in-band negotiation
- Explicitly check for PHY_INTERFACE_MODE_1000BASEX when setting SGMII port mode.
- Address Vladimir's review comments
v3:
- Move phylink changes to separate patch
- Address rmk review comments
v2:
- Switch to phylink
- Avoid need for device tree configuration options
Jonathan McDowell (2):
net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
net: dsa: qca8k: Improve SGMII interface handling
drivers/net/dsa/qca8k.c | 341 ++++++++++++++++++++++++++++------------ drivers/net/dsa/qca8k.h | 13 ++ 2 files changed, 256 insertions(+), 98 deletions(-)
Signature · 1 line
2.20.1
RFC PATCH v4 1/2 net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
Update the driver to use the new PHYLINK callbacks, removing the legacy adjust_link callback.
--- drivers/net/dsa/qca8k.c | 308 +++++++++++++++++++++++++++------------- 1 file changed, 211 insertions(+), 97 deletions(-)
drivers/net/dsa/qca8k.c +211 -97
@@ -14,6 +14,7 @@#include <linux/of_platform.h> #include <linux/if_bridge.h> #include <linux/mdio.h> +#include <linux/phylink.h> #include <linux/gpio/consumer.h> #include <linux/etherdevice.h>
@@ -418,55 +419,6 @@ qca8k_mib_init(struct qca8k_priv *priv)mutex_unlock (&priv->reg_mutex); } -static int -qca8k_set_pad_ctrl (struct qca8k_priv *priv,int port,int mode) -{ -u32 reg, val; - -switch (port) { -case 0 : - reg =QCA8K_REG_PORT0_PAD_CTRL ; -break ; -case 6 : - reg =QCA8K_REG_PORT6_PAD_CTRL ; -break ; -default : -pr_err ("Can't set PAD_CTRL on port %d\n" , port); -return -EINVAL ; - } - -/* Configure a port to be directly connected to an external -* PHY or MAC. -*/ -switch (mode) { -case PHY_INTERFACE_MODE_RGMII : -/* RGMII mode means no delay so don't enable the delay */ - val =QCA8K_PORT_PAD_RGMII_EN ; -qca8k_write (priv, reg, val); -break ; -case PHY_INTERFACE_MODE_RGMII_ID : -/* RGMII_ID needs internal delay. This is enabled through -* PORT5_PAD_CTRL for all ports, rather than individual port -* registers -*/ -qca8k_write (priv, reg, -QCA8K_PORT_PAD_RGMII_EN | -QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | -QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY )); -qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , -QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); -break ; -case PHY_INTERFACE_MODE_SGMII : -qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); -break ; -default : -pr_err ("xMII mode %d not supported\n" , mode); -return -EINVAL ; - } - -return 0 ; -} -static void qca8k_port_set_status (struct qca8k_priv *priv,int port,int enable) {
@@ -639,9 +591,7 @@ static int qca8k_setup(struct dsa_switch *ds) {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -phy_interface_t phy_mode =PHY_INTERFACE_MODE_NA ;int ret, i; -u32 mask;/* Make sure that port 0 is the cpu port */ if (!dsa_is_cpu_port (ds,0 )) {
@@ -661,24 +611,9 @@ qca8k_setup(struct dsa_switch *ds)if (ret)return ret; -/* Initialize CPU port pad mode (xMII type, delays...) */ - ret =of_get_phy_mode (dsa_to_port (ds,QCA8K_CPU_PORT )->dn, &phy_mode); -if (ret) { -pr_err ("Can't find phy-mode for master device\n" ); -return ret; - } - ret =qca8k_set_pad_ctrl (priv,QCA8K_CPU_PORT , phy_mode); -if (ret <0 ) -return ret; - -/* Enable CPU Port, force it to maximum bandwidth and full-duplex */ - mask =QCA8K_PORT_STATUS_SPEED_1000 |QCA8K_PORT_STATUS_TXFLOW | -QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_DUPLEX ; -qca8k_write (priv,QCA8K_REG_PORT_STATUS (QCA8K_CPU_PORT ), mask); +/* Enable CPU Port */ qca8k_reg_set (priv,QCA8K_REG_GLOBAL_FW_CTRL0 ,QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN ); -qca8k_port_set_status (priv,QCA8K_CPU_PORT ,1 ); - priv->port_sts[QCA8K_CPU_PORT ].enabled =1 ;/* Enable MIB counters */ qca8k_mib_init (priv);
@@ -693,10 +628,9 @@ qca8k_setup(struct dsa_switch *ds)qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (i),QCA8K_PORT_LOOKUP_MEMBER ,0 ); -/* Disable MAC by default on all user ports */ +/* Disable MAC by default on all ports */ for (i =1 ; i <QCA8K_NUM_PORTS ; i++) -if (dsa_is_user_port (ds, i)) -qca8k_port_set_status (priv, i,0 ); +qca8k_port_set_status (priv, i,0 );/* Forward all unknown frames to CPU port for Linux processing */ qca8k_write(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
@@ -713,7 +647,7 @@ qca8k_setup(struct dsa_switch *ds) QCA8K_PORT_LOOKUP_MEMBER, dsa_user_ports(ds)); } -/* Invividual user ports get connected to CPU port only */ +/* Individual user ports get connected to CPU port only */ if (dsa_is_user_port (ds, i)) {int shift =16 * (i %2 );
@@ -743,44 +677,222 @@ qca8k_setup(struct dsa_switch *ds) }static void -qca8k_adjust_link (struct dsa_switch *ds,int port,struct phy_device *phy) +qca8k_phylink_mac_config (struct dsa_switch *ds,int port,unsigned int mode, +const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv;u32 reg; -/* Force fixed-link setting for CPU port, skip others. */ -if (!phy_is_pseudo_fixed_link (phy)) +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) +return ; + + reg =QCA8K_REG_PORT0_PAD_CTRL ; +break ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY, nothing to do */ +return ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) +return ; + + reg =QCA8K_REG_PORT6_PAD_CTRL ; +break ; +default : +dev_err (ds->dev,"%s: unsupported port: %i\n" , __func__, port); +return ; + } + +if (port !=6 &&phylink_autoneg_inband (mode)) { +dev_err (ds->dev,"%s: in-band negotiation unsupported\n" , + __func__); +return ; + } + +switch (state->interface) { +case PHY_INTERFACE_MODE_RGMII : +/* RGMII mode means no delay so don't enable the delay */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_RGMII_EN ); +break ; +case PHY_INTERFACE_MODE_RGMII_ID : +/* RGMII_ID needs internal delay. This is enabled through +* PORT5_PAD_CTRL for all ports, rather than individual port +* registers +*/ +qca8k_write (priv, reg, +QCA8K_PORT_PAD_RGMII_EN | +QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | +QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY )); +qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , +QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); +break ; +case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_1000BASEX : +/* Enable SGMII on the port */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); +break ; +default : +dev_err (ds->dev,"xMII mode %s not supported for port %d\n" , +phy_modes (state->interface), port);return ; + } +} -/* Set port speed */ -switch (phy->speed) { -case 10 : - reg =QCA8K_PORT_STATUS_SPEED_10 ; +static void +qca8k_phylink_validate (struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state) +{ +__ETHTOOL_DECLARE_LINK_MODE_MASK (mask) = {0 , }; + +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) + goto unsupported;break ; -case 100 : - reg =QCA8K_PORT_STATUS_SPEED_100 ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_GMII ) + goto unsupported;break ; -case 1000 : - reg =QCA8K_PORT_STATUS_SPEED_1000 ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) + goto unsupported;break ;default : -dev_dbg (priv->dev,"port%d link speed %dMbps not supported.\n" , - port, phy->speed); +unsupported: +linkmode_zero (supported);return ; } -/* Set duplex mode */ -if (phy->duplex ==DUPLEX_FULL ) - reg |=QCA8K_PORT_STATUS_DUPLEX ; +phylink_set_port_modes (mask); +phylink_set (mask, Autoneg); + + phylink_set(mask, 1000baseT_Full); + phylink_set(mask, 10baseT_Half); + phylink_set(mask, 10baseT_Full); + phylink_set(mask, 100baseT_Half); + phylink_set(mask, 100baseT_Full); + +if (state->interface ==PHY_INTERFACE_MODE_1000BASEX ) + phylink_set(mask, 1000baseX_Full); + +phylink_set (mask, Pause); +phylink_set (mask, Asym_Pause); + +linkmode_and (supported, supported, mask); +linkmode_and (state->advertising, state->advertising, mask); +} + +static int +qca8k_phylink_mac_link_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; -/* Force flow control */ -if (dsa_is_cpu_port (ds, port)) - reg |=QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_TXFLOW ; + reg =qca8k_read (priv,QCA8K_REG_PORT_STATUS (port)); + + state->link = !!(reg &QCA8K_PORT_STATUS_LINK_UP ); + state->an_complete = state->link; + state->an_enabled = !!(reg &QCA8K_PORT_STATUS_LINK_AUTO ); + state->duplex = (reg &QCA8K_PORT_STATUS_DUPLEX ) ?DUPLEX_FULL : +DUPLEX_HALF ; + +switch (reg &QCA8K_PORT_STATUS_SPEED ) { +case QCA8K_PORT_STATUS_SPEED_10 : + state->speed =SPEED_10 ; +break ; +case QCA8K_PORT_STATUS_SPEED_100 : + state->speed =SPEED_100 ; +break ; +case QCA8K_PORT_STATUS_SPEED_1000 : + state->speed =SPEED_1000 ; +break ; +default : + state->speed =SPEED_UNKNOWN ; +break ; + } + + state->pause =MLO_PAUSE_NONE ; +if (reg &QCA8K_PORT_STATUS_RXFLOW ) + state->pause |=MLO_PAUSE_RX ; +if (reg &QCA8K_PORT_STATUS_TXFLOW ) + state->pause |=MLO_PAUSE_TX ; + +return 1 ; +} + +static void +qca8k_phylink_mac_link_down (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface) +{ +struct qca8k_priv *priv = ds->priv; -/* Force link down before changing MAC options */ qca8k_port_set_status (priv, port,0 ); +} + +static void +qca8k_phylink_mac_link_up (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface,struct phy_device *phydev, +int speed,int duplex,bool tx_pause,bool rx_pause) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; + +if (phylink_autoneg_inband (mode)) { + reg =QCA8K_PORT_STATUS_LINK_AUTO ; + }else { +switch (speed) { +case SPEED_10 : + reg =QCA8K_PORT_STATUS_SPEED_10 ; +break ; +case SPEED_100 : + reg =QCA8K_PORT_STATUS_SPEED_100 ; +break ; +case SPEED_1000 : + reg =QCA8K_PORT_STATUS_SPEED_1000 ; +break ; +default : + reg =QCA8K_PORT_STATUS_LINK_AUTO ; +break ; + } + +if (duplex ==DUPLEX_FULL ) + reg |=QCA8K_PORT_STATUS_DUPLEX ; + +if (rx_pause ||dsa_is_cpu_port (ds, port)) + reg |=QCA8K_PORT_STATUS_RXFLOW ; + +if (tx_pause ||dsa_is_cpu_port (ds, port)) + reg |=QCA8K_PORT_STATUS_TXFLOW ; + } + + reg |=QCA8K_PORT_STATUS_TXMAC |QCA8K_PORT_STATUS_RXMAC ; +qca8k_write (priv,QCA8K_REG_PORT_STATUS (port), reg); -qca8k_port_set_status (priv, port,1 ); } static void
@@ -937,13 +1049,11 @@ qca8k_port_enable(struct dsa_switch *ds, int port, {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -if (!dsa_is_user_port (ds, port)) -return 0 ; -qca8k_port_set_status (priv, port,1 ); priv->port_sts[port].enabled =1 ; -phy_support_asym_pause (phy); +if (dsa_is_user_port (ds, port)) +phy_support_asym_pause (phy);return 0 ; }
@@ -1026,7 +1136,6 @@ qca8k_get_tag_protocol(struct dsa_switch *ds, int port,static const struct dsa_switch_ops qca8k_switch_ops = { .get_tag_protocol = qca8k_get_tag_protocol, .setup = qca8k_setup, - .adjust_link = qca8k_adjust_link, .get_strings = qca8k_get_strings, .get_ethtool_stats = qca8k_get_ethtool_stats, .get_sset_count = qca8k_get_sset_count,
@@ -1040,6 +1149,11 @@ static const struct dsa_switch_ops qca8k_switch_ops = { .port_fdb_add = qca8k_port_fdb_add, .port_fdb_del = qca8k_port_fdb_del, .port_fdb_dump = qca8k_port_fdb_dump, + .phylink_validate = qca8k_phylink_validate, + .phylink_mac_link_state = qca8k_phylink_mac_link_state, + .phylink_mac_config = qca8k_phylink_mac_config, + .phylink_mac_link_down = qca8k_phylink_mac_link_down, + .phylink_mac_link_up = qca8k_phylink_mac_link_up, }; static int
Signature · 1 line
2.20.1
RFC PATCH v4 2/2 net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellThis 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.
--- drivers/net/dsa/qca8k.c | 33 ++++++++++++++++++++++++++++++++- drivers/net/dsa/qca8k.h | 13 +++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-)
drivers/net/dsa/qca8k.c +32 -1
@@ -673,6 +673,9 @@ qca8k_setup(struct dsa_switch *ds)/* Flush the FDB table */ qca8k_fdb_flush (priv); +/* We don't have interrupts for link changes, so we need to poll */ + priv->ds->pcs_poll = true; +return 0 ; }
@@ -681,7 +684,7 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv; -u32 reg; +u32 reg, val;switch (port) {case 0 :/* 1st CPU port */
@@ -740,6 +743,34 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,case PHY_INTERFACE_MODE_1000BASEX :/* Enable SGMII on the port */ qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); + +/* Enable/disable SerDes auto-negotiation as necessary */ + val =qca8k_read (priv,QCA8K_REG_PWS ); +if (phylink_autoneg_inband (mode)) + val &= ~QCA8K_PWS_SERDES_AEN_DIS ; +else + val |=QCA8K_PWS_SERDES_AEN_DIS ; +qca8k_write (priv,QCA8K_REG_PWS , val); + +/* Configure the SGMII parameters */ + val =qca8k_read (priv,QCA8K_REG_SGMII_CTRL ); + + val |=QCA8K_SGMII_EN_PLL |QCA8K_SGMII_EN_RX | +QCA8K_SGMII_EN_TX |QCA8K_SGMII_EN_SD ; + +if (dsa_is_cpu_port (ds, port)) { +/* CPU port, we're talking to the CPU MAC, be a PHY */ + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; + val |=QCA8K_SGMII_MODE_CTRL_PHY ; + }else if (state->interface ==PHY_INTERFACE_MODE_SGMII ) { + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; + val |=QCA8K_SGMII_MODE_CTRL_MAC ; + }else if (state->interface ==PHY_INTERFACE_MODE_1000BASEX ) { + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; + val |=QCA8K_SGMII_MODE_CTRL_BASEX ; + } + +qca8k_write (priv,QCA8K_REG_SGMII_CTRL , val);break ;default : dev_err(ds->dev, "xMII mode %s not supported for port %d\n",
drivers/net/dsa/qca8k.h +13 -0
@@ -36,6 +36,8 @@#define QCA8K_MAX_DELAY 3#define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24)#define QCA8K_PORT_PAD_SGMII_EN BIT(7) +#define QCA8K_REG_PWS 0x010 +#define QCA8K_PWS_SERDES_AEN_DIS BIT(7)#define QCA8K_REG_MODULE_EN 0x030#define QCA8K_MODULE_EN_MIB BIT(0)#define QCA8K_REG_MIB 0x034
@@ -69,6 +71,7 @@#define QCA8K_PORT_STATUS_LINK_UP BIT(8)#define QCA8K_PORT_STATUS_LINK_AUTO BIT(9)#define QCA8K_PORT_STATUS_LINK_PAUSE BIT(10) +#define QCA8K_PORT_STATUS_FLOW_AUTO BIT(12)#define QCA8K_REG_PORT_HDR_CTRL (_i) (0x9c + (_i * 4))#define QCA8K_PORT_HDR_CTRL_RX_MASK GENMASK(3, 2)#define QCA8K_PORT_HDR_CTRL_RX_S 2
@@ -77,6 +80,16 @@#define QCA8K_PORT_HDR_CTRL_ALL 2#define QCA8K_PORT_HDR_CTRL_MGMT 1#define QCA8K_PORT_HDR_CTRL_NONE 0 +#define QCA8K_REG_SGMII_CTRL 0x0e0 +#define QCA8K_SGMII_EN_PLL BIT(1) +#define QCA8K_SGMII_EN_RX BIT(2) +#define QCA8K_SGMII_EN_TX BIT(3) +#define QCA8K_SGMII_EN_SD BIT(4) +#define QCA8K_SGMII_CLK125M_DELAY BIT(7) +#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23)) +#define QCA8K_SGMII_MODE_CTRL_BASEX (0 << 22) +#define QCA8K_SGMII_MODE_CTRL_PHY (1 << 22) +#define QCA8K_SGMII_MODE_CTRL_MAC (2 << 22)/* EEE control registers */ #define QCA8K_REG_EEE_CTRL 0x100
Signature · 1 line
2.20.1
Vladimir Oltean
maintainerRe: [RFC PATCH v4 1/2] net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
In reply to Jonathan McDowellQuoted 127 lines · Jonathan McDowell
Update the driver to use the new PHYLINK callbacks, removing the legacy
adjust_linkcallback.Signed-off-by Jonathan McDowell <[email protected]>--- drivers/net/dsa/qca8k.c | 308 +++++++++++++++++++++++++++------------- 1 file changed, 211 insertions(+), 97 deletions(-)drivers/net/dsa/qca8k.c +4
-70@@ -14,6 +14,7 @@#include <linux/of_platform.h> #include <linux/if_bridge.h> #include <linux/mdio.h> +#include <linux/phylink.h> #include <linux/gpio/consumer.h> #include <linux/etherdevice.h> @@ -418,55 +419,6 @@ qca8k_mib_init(struct qca8k_priv *priv)mutex_unlock (&priv->reg_mutex); } -static int -qca8k_set_pad_ctrl (struct qca8k_priv *priv,int port,int mode) -{ -u32 reg, val; - -switch (port) { -case 0 : - reg =QCA8K_REG_PORT0_PAD_CTRL ; -break ; -case 6 : - reg =QCA8K_REG_PORT6_PAD_CTRL ; -break ; -default : -pr_err ("Can't set PAD_CTRL on port %d\n" , port); -return -EINVAL ; - } - -/* Configure a port to be directly connected to an external -* PHY or MAC. -*/ -switch (mode) { -case PHY_INTERFACE_MODE_RGMII : -/* RGMII mode means no delay so don't enable the delay */ - val =QCA8K_PORT_PAD_RGMII_EN ; -qca8k_write (priv, reg, val); -break ; -case PHY_INTERFACE_MODE_RGMII_ID : -/* RGMII_ID needs internal delay. This is enabled through -* PORT5_PAD_CTRL for all ports, rather than individual port -* registers -*/ -qca8k_write (priv, reg, -QCA8K_PORT_PAD_RGMII_EN | -QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | -QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY )); -qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , -QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); -break ; -case PHY_INTERFACE_MODE_SGMII : -qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); -break ; -default : -pr_err ("xMII mode %d not supported\n" , mode); -return -EINVAL ; - } - -return 0 ; -} -static void qca8k_port_set_status (struct qca8k_priv *priv,int port,int enable) {@@ -639,9 +591,7 @@ static int qca8k_setup(struct dsa_switch *ds) {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -phy_interface_t phy_mode =PHY_INTERFACE_MODE_NA ;int ret, i; -u32 mask;/* Make sure that port 0 is the cpu port */ if (!dsa_is_cpu_port (ds,0 )) {@@ -661,24 +611,9 @@ qca8k_setup(struct dsa_switch *ds)if (ret)return ret; -/* Initialize CPU port pad mode (xMII type, delays...) */ - ret =of_get_phy_mode (dsa_to_port (ds,QCA8K_CPU_PORT )->dn, &phy_mode); -if (ret) { -pr_err ("Can't find phy-mode for master device\n" ); -return ret; - } - ret =qca8k_set_pad_ctrl (priv,QCA8K_CPU_PORT , phy_mode); -if (ret <0 ) -return ret; - -/* Enable CPU Port, force it to maximum bandwidth and full-duplex */ - mask =QCA8K_PORT_STATUS_SPEED_1000 |QCA8K_PORT_STATUS_TXFLOW | -QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_DUPLEX ; -qca8k_write (priv,QCA8K_REG_PORT_STATUS (QCA8K_CPU_PORT ), mask); +/* Enable CPU Port */ qca8k_reg_set (priv,QCA8K_REG_GLOBAL_FW_CTRL0 ,QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN ); -qca8k_port_set_status (priv,QCA8K_CPU_PORT ,1 ); - priv->port_sts[QCA8K_CPU_PORT ].enabled =1 ;/* Enable MIB counters */ qca8k_mib_init (priv);@@ -693,10 +628,9 @@ qca8k_setup(struct dsa_switch *ds)qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (i),QCA8K_PORT_LOOKUP_MEMBER ,0 ); -/* Disable MAC by default on all user ports */ +/* Disable MAC by default on all ports */ for (i =1 ; i <QCA8K_NUM_PORTS ; i++) -if (dsa_is_user_port (ds, i)) -qca8k_port_set_status (priv, i,0 ); +qca8k_port_set_status (priv, i,0 );/* Forward all unknown frames to CPU port for Linux processing */ qca8k_write(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 650
Quoted 5 lines
drivers/net/dsa/qca8k.c +1
-1@@ -713,7 +647,7 @@ qca8k_setup(struct dsa_switch *ds) QCA8K_PORT_LOOKUP_MEMBER, dsa_user_ports(ds)); } -/* Invividual user ports get connected to CPU port only */ +/* Individual user ports get connected to CPU port only */
I would split typo fixes into separate patches.
Quoted 286 lines
drivers/net/dsa/qca8k.c +206
-27if (dsa_is_user_port (ds, i)) {int shift =16 * (i %2 );@@ -743,44 +677,222 @@ qca8k_setup(struct dsa_switch *ds) }static void -qca8k_adjust_link (struct dsa_switch *ds,int port,struct phy_device *phy) +qca8k_phylink_mac_config (struct dsa_switch *ds,int port,unsigned int mode, +const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv;u32 reg; -/* Force fixed-link setting for CPU port, skip others. */ -if (!phy_is_pseudo_fixed_link (phy)) +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) +return ; + + reg =QCA8K_REG_PORT0_PAD_CTRL ; +break ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY, nothing to do */ +return ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) +return ; + + reg =QCA8K_REG_PORT6_PAD_CTRL ; +break ; +default : +dev_err (ds->dev,"%s: unsupported port: %i\n" , __func__, port); +return ; + } + +if (port !=6 &&phylink_autoneg_inband (mode)) { +dev_err (ds->dev,"%s: in-band negotiation unsupported\n" , + __func__); +return ; + } + +switch (state->interface) { +case PHY_INTERFACE_MODE_RGMII : +/* RGMII mode means no delay so don't enable the delay */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_RGMII_EN ); +break ; +case PHY_INTERFACE_MODE_RGMII_ID : +/* RGMII_ID needs internal delay. This is enabled through +* PORT5_PAD_CTRL for all ports, rather than individual port +* registers +*/ +qca8k_write (priv, reg, +QCA8K_PORT_PAD_RGMII_EN | +QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | +QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY )); +qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , +QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); +break ; +case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_1000BASEX : +/* Enable SGMII on the port */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); +break ; +default : +dev_err (ds->dev,"xMII mode %s not supported for port %d\n" , +phy_modes (state->interface), port);return ; + } +} -/* Set port speed */ -switch (phy->speed) { -case 10 : - reg =QCA8K_PORT_STATUS_SPEED_10 ; +static void +qca8k_phylink_validate (struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state) +{ +__ETHTOOL_DECLARE_LINK_MODE_MASK (mask) = {0 , }; + +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) + goto unsupported;break ; -case 100 : - reg =QCA8K_PORT_STATUS_SPEED_100 ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_GMII ) + goto unsupported;break ; -case 1000 : - reg =QCA8K_PORT_STATUS_SPEED_1000 ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) + goto unsupported;break ;default : -dev_dbg (priv->dev,"port%d link speed %dMbps not supported.\n" , - port, phy->speed); +unsupported: +linkmode_zero (supported);return ; } -/* Set duplex mode */ -if (phy->duplex ==DUPLEX_FULL ) - reg |=QCA8K_PORT_STATUS_DUPLEX ; +phylink_set_port_modes (mask); +phylink_set (mask, Autoneg); + + phylink_set(mask, 1000baseT_Full); + phylink_set(mask, 10baseT_Half); + phylink_set(mask, 10baseT_Full); + phylink_set(mask, 100baseT_Half); + phylink_set(mask, 100baseT_Full); + +if (state->interface ==PHY_INTERFACE_MODE_1000BASEX ) + phylink_set(mask, 1000baseX_Full); + +phylink_set (mask, Pause); +phylink_set (mask, Asym_Pause); + +linkmode_and (supported, supported, mask); +linkmode_and (state->advertising, state->advertising, mask); +} + +static int +qca8k_phylink_mac_link_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; -/* Force flow control */ -if (dsa_is_cpu_port (ds, port)) - reg |=QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_TXFLOW ; + reg =qca8k_read (priv,QCA8K_REG_PORT_STATUS (port)); + + state->link = !!(reg &QCA8K_PORT_STATUS_LINK_UP ); + state->an_complete = state->link; + state->an_enabled = !!(reg &QCA8K_PORT_STATUS_LINK_AUTO ); + state->duplex = (reg &QCA8K_PORT_STATUS_DUPLEX ) ?DUPLEX_FULL : +DUPLEX_HALF ; + +switch (reg &QCA8K_PORT_STATUS_SPEED ) { +case QCA8K_PORT_STATUS_SPEED_10 : + state->speed =SPEED_10 ; +break ; +case QCA8K_PORT_STATUS_SPEED_100 : + state->speed =SPEED_100 ; +break ; +case QCA8K_PORT_STATUS_SPEED_1000 : + state->speed =SPEED_1000 ; +break ; +default : + state->speed =SPEED_UNKNOWN ; +break ; + } + + state->pause =MLO_PAUSE_NONE ; +if (reg &QCA8K_PORT_STATUS_RXFLOW ) + state->pause |=MLO_PAUSE_RX ; +if (reg &QCA8K_PORT_STATUS_TXFLOW ) + state->pause |=MLO_PAUSE_TX ; + +return 1 ; +} + +static void +qca8k_phylink_mac_link_down (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface) +{ +struct qca8k_priv *priv = ds->priv; -/* Force link down before changing MAC options */ qca8k_port_set_status (priv, port,0 ); +} + +static void +qca8k_phylink_mac_link_up (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface,struct phy_device *phydev, +int speed,int duplex,bool tx_pause,bool rx_pause) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; + +if (phylink_autoneg_inband (mode)) { + reg =QCA8K_PORT_STATUS_LINK_AUTO ; + }else { +switch (speed) { +case SPEED_10 : + reg =QCA8K_PORT_STATUS_SPEED_10 ; +break ; +case SPEED_100 : + reg =QCA8K_PORT_STATUS_SPEED_100 ; +break ; +case SPEED_1000 : + reg =QCA8K_PORT_STATUS_SPEED_1000 ; +break ; +default : + reg =QCA8K_PORT_STATUS_LINK_AUTO ; +break ; + } + +if (duplex ==DUPLEX_FULL ) + reg |=QCA8K_PORT_STATUS_DUPLEX ; + +if (rx_pause ||dsa_is_cpu_port (ds, port)) + reg |=QCA8K_PORT_STATUS_RXFLOW ; + +if (tx_pause ||dsa_is_cpu_port (ds, port)) + reg |=QCA8K_PORT_STATUS_TXFLOW ; + } + + reg |=QCA8K_PORT_STATUS_TXMAC |QCA8K_PORT_STATUS_RXMAC ; +qca8k_write (priv,QCA8K_REG_PORT_STATUS (port), reg); -qca8k_port_set_status (priv, port,1 ); } static void@@ -937,13 +1049,11 @@ qca8k_port_enable(struct dsa_switch *ds, int port, {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -if (!dsa_is_user_port (ds, port)) -return 0 ; -qca8k_port_set_status (priv, port,1 ); priv->port_sts[port].enabled =1 ; -phy_support_asym_pause (phy); +if (dsa_is_user_port (ds, port)) +phy_support_asym_pause (phy);return 0 ; }@@ -1026,7 +1136,6 @@ qca8k_get_tag_protocol(struct dsa_switch *ds, int port,static const struct dsa_switch_ops qca8k_switch_ops = { .get_tag_protocol = qca8k_get_tag_protocol, .setup = qca8k_setup, - .adjust_link = qca8k_adjust_link, .get_strings = qca8k_get_strings, .get_ethtool_stats = qca8k_get_ethtool_stats, .get_sset_count = qca8k_get_sset_count,@@ -1040,6 +1149,11 @@ static const struct dsa_switch_ops qca8k_switch_ops = { .port_fdb_add = qca8k_port_fdb_add, .port_fdb_del = qca8k_port_fdb_del, .port_fdb_dump = qca8k_port_fdb_dump, + .phylink_validate = qca8k_phylink_validate, + .phylink_mac_link_state = qca8k_phylink_mac_link_state, + .phylink_mac_config = qca8k_phylink_mac_config, + .phylink_mac_link_down = qca8k_phylink_mac_link_down, + .phylink_mac_link_up = qca8k_phylink_mac_link_up, }; static int --2.20.1
Vladimir Oltean
maintainerRe: [RFC PATCH v4 2/2] net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellQuoted 23 lines · Jonathan McDowell
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 <[email protected]>--- drivers/net/dsa/qca8k.c | 33 ++++++++++++++++++++++++++++++++- drivers/net/dsa/qca8k.h | 13 +++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-)drivers/net/dsa/qca8k.c +0
-0
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 678
Quoted 6 lines
drivers/net/dsa/qca8k.c +3
-0@@ -673,6 +673,9 @@ qca8k_setup(struct dsa_switch *ds)/* Flush the FDB table */ qca8k_fdb_flush (priv); +/* We don't have interrupts for link changes, so we need to poll */ + priv->ds->pcs_poll = true; +
You can access ds directly here.
Quoted 22 lines
drivers/net/dsa/qca8k.c +7
-1return 0 ; }@@ -681,7 +684,7 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv; -u32 reg; +u32 reg, val;switch (port) {case 0 :/* 1st CPU port */ @@ -740,6 +743,34 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,case PHY_INTERFACE_MODE_1000BASEX :/* Enable SGMII on the port */ qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); + +/* Enable/disable SerDes auto-negotiation as necessary */ + val =qca8k_read (priv,QCA8K_REG_PWS ); +if (phylink_autoneg_inband (mode)) + val &= ~QCA8K_PWS_SERDES_AEN_DIS ; +else
drivers/net/dsa/qca8k.c qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, · line 761
Quoted 10 lines
drivers/net/dsa/qca8k.c +10
-0+ val |=QCA8K_PWS_SERDES_AEN_DIS ; +qca8k_write (priv,QCA8K_REG_PWS , val); + +/* Configure the SGMII parameters */ + val =qca8k_read (priv,QCA8K_REG_SGMII_CTRL ); + + val |=QCA8K_SGMII_EN_PLL |QCA8K_SGMII_EN_RX | +QCA8K_SGMII_EN_TX |QCA8K_SGMII_EN_SD ; + +if (dsa_is_cpu_port (ds, port)) {
I don't see any device tree in mainline for qca,qca8334 that uses SGMII on the CPU port, but there are some assumptions being made here, and there are also going to be some assumptions made in the MAC driver, and I just want to make sure that those assumptions are not going to be incompatible, so I would like you to make some clarifications.
So there's a single SGMII interface which can go to port 0 (the CPU port) or to port 6, right? The SGMII port can behave as an AN master or as an AN slave, depending on whether MODE_CTRL is 1 or 2, or can have a forced speed (if SERDES_AEN is disabled)?
We don't have a standard way to describe an SGMII AN master that is not a PHY in the device tree, because I don't think anybody needed to do that so far.
Typically a MAC would describe the link towards the CPU port of the switch as a fixed-link. In that case, if the phy-mode is sgmii, it would disable in-band autoneg, because there's nothing really to negotiate (the link speed and duplex is fixed). For these, I think the expectation is that the switch does not enable in-band autoneg either, and has a fixed-link too. Per your configuration, you would disable SerDes AN, and you would configure the port as SGMII AN master (PHY), but that setting would be ignored because AN is disabled. In other configurations, the MAC might want to receive in-band status from the CPU port. In those cases, your answer to that problem seems to be to implement phylink ops on both drivers, and to set both to managed = "in-band-status" (MLO_AN_INBAND). This isn't a use case explicitly described by phylink (I would even go as far as saying that MLO_AN_INBAND means to be an SGMII AN slave), but it would work because of the check that we are a CPU port.
As for the case of a cascaded qca8334-to-qca8334 setup, this would again work, because on one of the switches, dsa_is_cpu_port would be true and on the other one it would be false.
So I'm not suggesting we should change anything, I just want to make sure I understand if this is the reason why you are configuring it like this.
Quoted 56 lines
drivers/net/dsa/qca8k.c +12
-0+/* CPU port, we're talking to the CPU MAC, be a PHY */ + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; + val |=QCA8K_SGMII_MODE_CTRL_PHY ; + }else if (state->interface ==PHY_INTERFACE_MODE_SGMII ) { + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; + val |=QCA8K_SGMII_MODE_CTRL_MAC ; + }else if (state->interface ==PHY_INTERFACE_MODE_1000BASEX ) { + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; + val |=QCA8K_SGMII_MODE_CTRL_BASEX ; + } + +qca8k_write (priv,QCA8K_REG_SGMII_CTRL , val);break ;default : dev_err(ds->dev, "xMII mode %s not supported for port %d\n",drivers/net/dsa/qca8k.h +13
-1@@ -36,6 +36,8 @@#define QCA8K_MAX_DELAY 3#define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24)#define QCA8K_PORT_PAD_SGMII_EN BIT(7) +#define QCA8K_REG_PWS 0x010 +#define QCA8K_PWS_SERDES_AEN_DIS BIT(7)#define QCA8K_REG_MODULE_EN 0x030#define QCA8K_MODULE_EN_MIB BIT(0)#define QCA8K_REG_MIB 0x034@@ -69,6 +71,7 @@#define QCA8K_PORT_STATUS_LINK_UP BIT(8)#define QCA8K_PORT_STATUS_LINK_AUTO BIT(9)#define QCA8K_PORT_STATUS_LINK_PAUSE BIT(10) +#define QCA8K_PORT_STATUS_FLOW_AUTO BIT(12)#define QCA8K_REG_PORT_HDR_CTRL (_i) (0x9c + (_i * 4))#define QCA8K_PORT_HDR_CTRL_RX_MASK GENMASK(3, 2)#define QCA8K_PORT_HDR_CTRL_RX_S 2@@ -77,6 +80,16 @@#define QCA8K_PORT_HDR_CTRL_ALL 2#define QCA8K_PORT_HDR_CTRL_MGMT 1#define QCA8K_PORT_HDR_CTRL_NONE 0 +#define QCA8K_REG_SGMII_CTRL 0x0e0 +#define QCA8K_SGMII_EN_PLL BIT(1) +#define QCA8K_SGMII_EN_RX BIT(2) +#define QCA8K_SGMII_EN_TX BIT(3) +#define QCA8K_SGMII_EN_SD BIT(4) +#define QCA8K_SGMII_CLK125M_DELAY BIT(7) +#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23)) +#define QCA8K_SGMII_MODE_CTRL_BASEX (0 << 22) +#define QCA8K_SGMII_MODE_CTRL_PHY (1 << 22) +#define QCA8K_SGMII_MODE_CTRL_MAC (2 << 22)/* EEE control registers */ #define QCA8K_REG_EEE_CTRL 0x100 --2.20.1
Re: [RFC PATCH v4 2/2] net: dsa: qca8k: Improve SGMII interface handling
Quoted 27 lines · Vladimir Oltean
Quoted 26 lines · Jonathan McDowell
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 <[email protected]>--- drivers/net/dsa/qca8k.c | 33 ++++++++++++++++++++++++++++++++- drivers/net/dsa/qca8k.h | 13 +++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-)drivers/net/dsa/qca8k.c +0
-0@@ -673,6 +673,9 @@ qca8k_setup(struct dsa_switch *ds)/* Flush the FDB table */ qca8k_fdb_flush (priv);
Quoted 5 lines
drivers/net/dsa/qca8k.c qca8k_setup(struct dsa_switch *ds) · line 678
Quoted 3 lines
drivers/net/dsa/qca8k.c +3
-0+/* We don't have interrupts for link changes, so we need to poll */ + priv->ds->pcs_poll = true; +You can access ds directly here.
Good point, thanks.
Quoted 31 lines
Quoted 31 lines
drivers/net/dsa/qca8k.c +16
-1return 0 ; }@@ -681,7 +684,7 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv; -u32 reg; +u32 reg, val;switch (port) {case 0 :/* 1st CPU port */ @@ -740,6 +743,34 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,case PHY_INTERFACE_MODE_1000BASEX :/* Enable SGMII on the port */ qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); + +/* Enable/disable SerDes auto-negotiation as necessary */ + val =qca8k_read (priv,QCA8K_REG_PWS ); +if (phylink_autoneg_inband (mode)) + val &= ~QCA8K_PWS_SERDES_AEN_DIS ; +else + val |=QCA8K_PWS_SERDES_AEN_DIS ; +qca8k_write (priv,QCA8K_REG_PWS , val); + +/* Configure the SGMII parameters */ + val =qca8k_read (priv,QCA8K_REG_SGMII_CTRL ); + + val |=QCA8K_SGMII_EN_PLL |QCA8K_SGMII_EN_RX | +QCA8K_SGMII_EN_TX |QCA8K_SGMII_EN_SD ; +
Quoted 8 lines
drivers/net/dsa/qca8k.c qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, · line 761
Quoted 1 line
drivers/net/dsa/qca8k.c +1
-0+if (dsa_is_cpu_port (ds, port)) {I don't see any device tree in mainline for qca,qca8334 that uses SGMII on the CPU port, but there are some assumptions being made here, and there are also going to be some assumptions made in the MAC driver, and I just want to make sure that those assumptions are not going to be incompatible, so I would like you to make some clarifications.
FWIW I have a DTS for the MikroTik RB3011 that should hopefully make it to 5.9 via the linux-msm tree, which has 2 qca,qca8337 devices, one connected via rgmii, one connected via sgmii. Sadly not chained to each other, instead connected to different CPU ethernet ports.
Quoted 4 lines
So there's a single SGMII interface which can go to port 0 (the CPU port) or to port 6, right? The SGMII port can behave as an AN master or as an AN slave, depending on whether
MODE_CTRLis 1 or 2, or can have a forced speed (ifSERDES_AENis disabled)?
Yes.
Quoted 4 lines
We don't have a standard way to describe an SGMII AN master that is not a PHY in the device tree, because I don't think anybody needed to do that so far.
Quoted 8 lines
Typically a MAC would describe the link towards the CPU port of the switch as a fixed-link. In that case, if the phy-mode is sgmii, it would disable in-band autoneg, because there's nothing really to negotiate (the link speed and duplex is fixed). For these, I think the expectation is that the switch does not enable in-band autoneg either, and has a fixed-link too. Per your configuration, you would disable SerDes AN, and you would configure the port as SGMII AN master (PHY), but that setting would be ignored because AN is disabled.
Right; this is the situation with my device. There's a fixed-link stanza in the DT.
Quoted 8 lines
In other configurations, the MAC might want to receive in-band status from the CPU port. In those cases, your answer to that problem seems to be to implement phylink ops on both drivers, and to set both to managed = "in-band-status" (
MLO_AN_INBAND). This isn't a use case explicitly described by phylink (I would even go as far as saying thatMLO_AN_INBANDmeans to be an SGMII AN slave), but it would work because of the check that we are a CPU port.
Quoted 7 lines
As for the case of a cascaded qca8334-to-qca8334 setup, this would again work, because on one of the switches,
dsa_is_cpu_portwould be true and on the other one it would be false.So I'm not suggesting we should change anything, I just want to make sure I understand if this is the reason why you are configuring it like this.
My primary concern was not breaking any existing users; after a reset the switch enabled AN on the SGMII port. I agree it's unlikely that this would be the case, but I erred on the side of caution, while also trying to handle what seem to be the sensible common cases.
J.
Signature · 1 line
He's weird? It's ok, I'm fluent in weird.
Rob Herring
maintainerRe: [PATCH 1/2] dt-bindings: net: dsa: qca8k: document SGMII properties
In reply to Jonathan McDowellQuoted 13 lines · Jonathan McDowell
This patch documents the qca8k's SGMII related properties that allow configuration of the SGMII port.
Signed-off-by Jonathan McDowell <[email protected]>--- Documentation/devicetree/bindings/net/dsa/qca8k.txt | 4 ++++ 1 file changed, 4 insertions(+)Documentation/devicetree/bindings/net/dsa/qca8k.txt +0
-0
Documentation/devicetree/bindings/net/dsa/qca8k.txt Required properties: · line 18
Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/qca8k.txt +4
-0@@ -11,7 +11,11 @@ Required properties: Optional properties: +- disable-serdes-autoneg: Boolean, disables auto-negotiation on the SerDes - reset-gpios: GPIO to be used to reset the whole device +- sgmii-delay: Boolean, presence delays SGMII clock by 2ns +- sgmii-mode: String, operation mode of the SGMII interface. + Supported values are: "basex", "mac", "phy".
Either these should be common properties and documented in a common spot or they need vendor prefixes. They seem like they former to me (though 'sgmii-delay' would need to be more general and take a time).
Rob
Re: [PATCH 1/2] dt-bindings: net: dsa: qca8k: document SGMII properties
Quoted 17 lines · Rob Herring
Quoted 16 lines · Jonathan McDowell
This patch documents the qca8k's SGMII related properties that allow configuration of the SGMII port.
Signed-off-by Jonathan McDowell <[email protected]>--- Documentation/devicetree/bindings/net/dsa/qca8k.txt | 4 ++++ 1 file changed, 4 insertions(+)Documentation/devicetree/bindings/net/dsa/qca8k.txt +0
-0@@ -11,7 +11,11 @@ Required properties: Optional properties:
Quoted 9 lines
Documentation/devicetree/bindings/net/dsa/qca8k.txt Required properties: · line 18
Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/qca8k.txt +4
-0+- disable-serdes-autoneg: Boolean, disables auto-negotiation on the SerDes - reset-gpios: GPIO to be used to reset the whole device +- sgmii-delay: Boolean, presence delays SGMII clock by 2ns +- sgmii-mode: String, operation mode of the SGMII interface. + Supported values are: "basex", "mac", "phy".Either these should be common properties and documented in a common spot or they need vendor prefixes. They seem like they former to me (though 'sgmii-delay' would need to be more general and take a time).
I've managed to spin a subsequent revision which avoids the need for a device tree change, based on comments similar to yours. I'll keep them in mind should it become necessary to re-introduce the DT options.
J.
Signature · 4 lines
] https://www.earth.li/~noodles/ [] I'm a creep, I'm a weirdo, what [ ] PGP/GPG Key @ the.earth.li [] the hell am I doing here? [ ] via keyserver, web or email. [] [ ] RSA: 4096/0x94FA372B2DA8B985 [] [
Re: [PATCH 2/2] net: dsa: qca8k: introduce SGMII configuration options
In reply to Jonathan McDowellHi Jonathan,
url: https://github.com/0day-ci/linux/commits/Jonathan-McDowell/net-dsa-qca8k-Add-SGMII-configuration-options/20200606-021254 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: i386-randconfig-m021-20200618 (attached as .config) compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
If you fix the issue, kindly add following tag as appropriate
smatch warnings:drivers/net/dsa/qca8k.c:438 qca8k_setup_sgmii() error: uninitialized symbol 'mode'.
# https://github.com/0day-ci/linux/commit/27dd896d27e5048d2c402879fb04f6e23536ea72
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 27dd896d27e5048d2c402879fb04f6e23536ea72
vim +/mode +438 drivers/net/dsa/qca8k.c
27dd896d27e5048 Jonathan McDowell 2020-06-05 421 static int
27dd896d27e5048 Jonathan McDowell 2020-06-05 422 qca8k_setup_sgmii(struct qca8k_priv *priv)
27dd896d27e5048 Jonathan McDowell 2020-06-05 423 {
27dd896d27e5048 Jonathan McDowell 2020-06-05 424 const char *mode;
^^^^27dd896d27e5048 Jonathan McDowell 2020-06-05 425 u32 val;
27dd896d27e5048 Jonathan McDowell 2020-06-05 426
27dd896d27e5048 Jonathan McDowell 2020-06-05 427 val = qca8k_read(priv, QCA8K_REG_SGMII_CTRL);
27dd896d27e5048 Jonathan McDowell 2020-06-05 428
27dd896d27e5048 Jonathan McDowell 2020-06-05 429 val |= QCA8K_SGMII_EN_PLL | QCA8K_SGMII_EN_RX |
27dd896d27e5048 Jonathan McDowell 2020-06-05 430 QCA8K_SGMII_EN_TX | QCA8K_SGMII_EN_SD;
27dd896d27e5048 Jonathan McDowell 2020-06-05 431
27dd896d27e5048 Jonathan McDowell 2020-06-05 432 if (of_property_read_bool(priv->dev->of_node, "sgmii-delay"))
27dd896d27e5048 Jonathan McDowell 2020-06-05 433 val |= QCA8K_SGMII_CLK125M_DELAY;
27dd896d27e5048 Jonathan McDowell 2020-06-05 434
27dd896d27e5048 Jonathan McDowell 2020-06-05 435 if (of_property_read_string(priv->dev->of_node, "sgmii-mode", &mode)) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^This if condition is reversed.
27dd896d27e5048 Jonathan McDowell 2020-06-05 436 val &= ~QCA8K_SGMII_MODE_CTRL_MASK;27dd896d27e5048 Jonathan McDowell 2020-06-05 437
27dd896d27e5048 Jonathan McDowell 2020-06-05 @438 if (!strcasecmp(mode, "basex")) {
27dd896d27e5048 Jonathan McDowell 2020-06-05 439 val |= QCA8K_SGMII_MODE_CTRL_BASEX;
27dd896d27e5048 Jonathan McDowell 2020-06-05 440 } else if (!strcasecmp(mode, "mac")) {
27dd896d27e5048 Jonathan McDowell 2020-06-05 441 val |= QCA8K_SGMII_MODE_CTRL_MAC;
27dd896d27e5048 Jonathan McDowell 2020-06-05 442 } else if (!strcasecmp(mode, "phy")) {
27dd896d27e5048 Jonathan McDowell 2020-06-05 443 val |= QCA8K_SGMII_MODE_CTRL_PHY;
27dd896d27e5048 Jonathan McDowell 2020-06-05 444 } else {
27dd896d27e5048 Jonathan McDowell 2020-06-05 445 pr_err("Unrecognised SGMII mode %s\n", mode);
27dd896d27e5048 Jonathan McDowell 2020-06-05 446 return -EINVAL;
27dd896d27e5048 Jonathan McDowell 2020-06-05 447 }
27dd896d27e5048 Jonathan McDowell 2020-06-05 448 }
27dd896d27e5048 Jonathan McDowell 2020-06-05 449
27dd896d27e5048 Jonathan McDowell 2020-06-05 450 qca8k_write(priv, QCA8K_REG_SGMII_CTRL, val);
27dd896d27e5048 Jonathan McDowell 2020-06-05 451
27dd896d27e5048 Jonathan McDowell 2020-06-05 452 return 0;
27dd896d27e5048 Jonathan McDowell 2020-06-05 453 }---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
v5 cover net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellThis 3 patch series migrates the qca8k switch driver over to PHYLINK, and then adds the SGMII clean-ups (i.e. the missing initialisation) on top of that as a second patch. The final patch is a simple spelling fix in a comment.
As before, 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.
v5:
- Move spelling fix to separate patch
- Use ds directly rather than ds->priv
v4:
- Enable pcs_poll so we keep phylink updated when doing in-band negotiation
- Explicitly check for PHY_INTERFACE_MODE_1000BASEX when setting SGMII port mode.
- Address Vladimir's review comments
v3:
- Move phylink changes to separate patch
- Address rmk review comments
v2:
- Switch to phylink
- Avoid need for device tree configuration options
Jonathan McDowell (3):
net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
net: dsa: qca8k: Improve SGMII interface handling
net: dsa: qca8k: Minor comment spelling fix
drivers/net/dsa/qca8k.c | 341 ++++++++++++++++++++++++++++------------ drivers/net/dsa/qca8k.h | 13 ++ 2 files changed, 256 insertions(+), 98 deletions(-)
Signature · 1 line
2.20.1
PATCH v5 2/3 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.
--- drivers/net/dsa/qca8k.c | 33 ++++++++++++++++++++++++++++++++- drivers/net/dsa/qca8k.h | 13 +++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-)
drivers/net/dsa/qca8k.c +32 -1
@@ -673,6 +673,9 @@ qca8k_setup(struct dsa_switch *ds)/* Flush the FDB table */ qca8k_fdb_flush (priv); +/* We don't have interrupts for link changes, so we need to poll */ + ds->pcs_poll = true; +return 0 ; }
@@ -681,7 +684,7 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv; -u32 reg; +u32 reg, val;switch (port) {case 0 :/* 1st CPU port */
@@ -740,6 +743,34 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,case PHY_INTERFACE_MODE_1000BASEX :/* Enable SGMII on the port */ qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); + +/* Enable/disable SerDes auto-negotiation as necessary */ + val =qca8k_read (priv,QCA8K_REG_PWS ); +if (phylink_autoneg_inband (mode)) + val &= ~QCA8K_PWS_SERDES_AEN_DIS ; +else + val |=QCA8K_PWS_SERDES_AEN_DIS ; +qca8k_write (priv,QCA8K_REG_PWS , val); + +/* Configure the SGMII parameters */ + val =qca8k_read (priv,QCA8K_REG_SGMII_CTRL ); + + val |=QCA8K_SGMII_EN_PLL |QCA8K_SGMII_EN_RX | +QCA8K_SGMII_EN_TX |QCA8K_SGMII_EN_SD ; + +if (dsa_is_cpu_port (ds, port)) { +/* CPU port, we're talking to the CPU MAC, be a PHY */ + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; + val |=QCA8K_SGMII_MODE_CTRL_PHY ; + }else if (state->interface ==PHY_INTERFACE_MODE_SGMII ) { + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; + val |=QCA8K_SGMII_MODE_CTRL_MAC ; + }else if (state->interface ==PHY_INTERFACE_MODE_1000BASEX ) { + val &= ~QCA8K_SGMII_MODE_CTRL_MASK ; + val |=QCA8K_SGMII_MODE_CTRL_BASEX ; + } + +qca8k_write (priv,QCA8K_REG_SGMII_CTRL , val);break ;default : dev_err(ds->dev, "xMII mode %s not supported for port %d\n",
drivers/net/dsa/qca8k.h +13 -0
@@ -36,6 +36,8 @@#define QCA8K_MAX_DELAY 3#define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24)#define QCA8K_PORT_PAD_SGMII_EN BIT(7) +#define QCA8K_REG_PWS 0x010 +#define QCA8K_PWS_SERDES_AEN_DIS BIT(7)#define QCA8K_REG_MODULE_EN 0x030#define QCA8K_MODULE_EN_MIB BIT(0)#define QCA8K_REG_MIB 0x034
@@ -69,6 +71,7 @@#define QCA8K_PORT_STATUS_LINK_UP BIT(8)#define QCA8K_PORT_STATUS_LINK_AUTO BIT(9)#define QCA8K_PORT_STATUS_LINK_PAUSE BIT(10) +#define QCA8K_PORT_STATUS_FLOW_AUTO BIT(12)#define QCA8K_REG_PORT_HDR_CTRL (_i) (0x9c + (_i * 4))#define QCA8K_PORT_HDR_CTRL_RX_MASK GENMASK(3, 2)#define QCA8K_PORT_HDR_CTRL_RX_S 2
@@ -77,6 +80,16 @@#define QCA8K_PORT_HDR_CTRL_ALL 2#define QCA8K_PORT_HDR_CTRL_MGMT 1#define QCA8K_PORT_HDR_CTRL_NONE 0 +#define QCA8K_REG_SGMII_CTRL 0x0e0 +#define QCA8K_SGMII_EN_PLL BIT(1) +#define QCA8K_SGMII_EN_RX BIT(2) +#define QCA8K_SGMII_EN_TX BIT(3) +#define QCA8K_SGMII_EN_SD BIT(4) +#define QCA8K_SGMII_CLK125M_DELAY BIT(7) +#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23)) +#define QCA8K_SGMII_MODE_CTRL_BASEX (0 << 22) +#define QCA8K_SGMII_MODE_CTRL_PHY (1 << 22) +#define QCA8K_SGMII_MODE_CTRL_MAC (2 << 22)/* EEE control registers */ #define QCA8K_REG_EEE_CTRL 0x100
Signature · 1 line
2.20.1
PATCH v5 1/3 net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB
In reply to Jonathan McDowellUpdate the driver to use the new PHYLINK callbacks, removing the legacy adjust_link callback.
--- drivers/net/dsa/qca8k.c | 306 +++++++++++++++++++++++++++------------- 1 file changed, 210 insertions(+), 96 deletions(-)
drivers/net/dsa/qca8k.c +210 -96
@@ -14,6 +14,7 @@#include <linux/of_platform.h> #include <linux/if_bridge.h> #include <linux/mdio.h> +#include <linux/phylink.h> #include <linux/gpio/consumer.h> #include <linux/etherdevice.h>
@@ -418,55 +419,6 @@ qca8k_mib_init(struct qca8k_priv *priv)mutex_unlock (&priv->reg_mutex); } -static int -qca8k_set_pad_ctrl (struct qca8k_priv *priv,int port,int mode) -{ -u32 reg, val; - -switch (port) { -case 0 : - reg =QCA8K_REG_PORT0_PAD_CTRL ; -break ; -case 6 : - reg =QCA8K_REG_PORT6_PAD_CTRL ; -break ; -default : -pr_err ("Can't set PAD_CTRL on port %d\n" , port); -return -EINVAL ; - } - -/* Configure a port to be directly connected to an external -* PHY or MAC. -*/ -switch (mode) { -case PHY_INTERFACE_MODE_RGMII : -/* RGMII mode means no delay so don't enable the delay */ - val =QCA8K_PORT_PAD_RGMII_EN ; -qca8k_write (priv, reg, val); -break ; -case PHY_INTERFACE_MODE_RGMII_ID : -/* RGMII_ID needs internal delay. This is enabled through -* PORT5_PAD_CTRL for all ports, rather than individual port -* registers -*/ -qca8k_write (priv, reg, -QCA8K_PORT_PAD_RGMII_EN | -QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | -QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY )); -qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , -QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); -break ; -case PHY_INTERFACE_MODE_SGMII : -qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); -break ; -default : -pr_err ("xMII mode %d not supported\n" , mode); -return -EINVAL ; - } - -return 0 ; -} -static void qca8k_port_set_status (struct qca8k_priv *priv,int port,int enable) {
@@ -639,9 +591,7 @@ static int qca8k_setup(struct dsa_switch *ds) {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -phy_interface_t phy_mode =PHY_INTERFACE_MODE_NA ;int ret, i; -u32 mask;/* Make sure that port 0 is the cpu port */ if (!dsa_is_cpu_port (ds,0 )) {
@@ -661,24 +611,9 @@ qca8k_setup(struct dsa_switch *ds)if (ret)return ret; -/* Initialize CPU port pad mode (xMII type, delays...) */ - ret =of_get_phy_mode (dsa_to_port (ds,QCA8K_CPU_PORT )->dn, &phy_mode); -if (ret) { -pr_err ("Can't find phy-mode for master device\n" ); -return ret; - } - ret =qca8k_set_pad_ctrl (priv,QCA8K_CPU_PORT , phy_mode); -if (ret <0 ) -return ret; - -/* Enable CPU Port, force it to maximum bandwidth and full-duplex */ - mask =QCA8K_PORT_STATUS_SPEED_1000 |QCA8K_PORT_STATUS_TXFLOW | -QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_DUPLEX ; -qca8k_write (priv,QCA8K_REG_PORT_STATUS (QCA8K_CPU_PORT ), mask); +/* Enable CPU Port */ qca8k_reg_set (priv,QCA8K_REG_GLOBAL_FW_CTRL0 ,QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN ); -qca8k_port_set_status (priv,QCA8K_CPU_PORT ,1 ); - priv->port_sts[QCA8K_CPU_PORT ].enabled =1 ;/* Enable MIB counters */ qca8k_mib_init (priv);
@@ -693,10 +628,9 @@ qca8k_setup(struct dsa_switch *ds)qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (i),QCA8K_PORT_LOOKUP_MEMBER ,0 ); -/* Disable MAC by default on all user ports */ +/* Disable MAC by default on all ports */ for (i =1 ; i <QCA8K_NUM_PORTS ; i++) -if (dsa_is_user_port (ds, i)) -qca8k_port_set_status (priv, i,0 ); +qca8k_port_set_status (priv, i,0 );/* Forward all unknown frames to CPU port for Linux processing */ qca8k_write(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
@@ -743,44 +677,222 @@ qca8k_setup(struct dsa_switch *ds) }static void -qca8k_adjust_link (struct dsa_switch *ds,int port,struct phy_device *phy) +qca8k_phylink_mac_config (struct dsa_switch *ds,int port,unsigned int mode, +const struct phylink_link_state *state) {struct qca8k_priv *priv = ds->priv;u32 reg; -/* Force fixed-link setting for CPU port, skip others. */ -if (!phy_is_pseudo_fixed_link (phy)) +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) +return ; + + reg =QCA8K_REG_PORT0_PAD_CTRL ; +break ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY, nothing to do */ +return ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) +return ; + + reg =QCA8K_REG_PORT6_PAD_CTRL ; +break ; +default : +dev_err (ds->dev,"%s: unsupported port: %i\n" , __func__, port); +return ; + } + +if (port !=6 &&phylink_autoneg_inband (mode)) { +dev_err (ds->dev,"%s: in-band negotiation unsupported\n" , + __func__); +return ; + } + +switch (state->interface) { +case PHY_INTERFACE_MODE_RGMII : +/* RGMII mode means no delay so don't enable the delay */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_RGMII_EN ); +break ; +case PHY_INTERFACE_MODE_RGMII_ID : +/* RGMII_ID needs internal delay. This is enabled through +* PORT5_PAD_CTRL for all ports, rather than individual port +* registers +*/ +qca8k_write (priv, reg, +QCA8K_PORT_PAD_RGMII_EN | +QCA8K_PORT_PAD_RGMII_TX_DELAY (QCA8K_MAX_DELAY ) | +QCA8K_PORT_PAD_RGMII_RX_DELAY (QCA8K_MAX_DELAY )); +qca8k_write (priv,QCA8K_REG_PORT5_PAD_CTRL , +QCA8K_PORT_PAD_RGMII_RX_DELAY_EN ); +break ; +case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_1000BASEX : +/* Enable SGMII on the port */ +qca8k_write (priv, reg,QCA8K_PORT_PAD_SGMII_EN ); +break ; +default : +dev_err (ds->dev,"xMII mode %s not supported for port %d\n" , +phy_modes (state->interface), port);return ; + } +} -/* Set port speed */ -switch (phy->speed) { -case 10 : - reg =QCA8K_PORT_STATUS_SPEED_10 ; +static void +qca8k_phylink_validate (struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state) +{ +__ETHTOOL_DECLARE_LINK_MODE_MASK (mask) = {0 , }; + +switch (port) { +case 0 :/* 1st CPU port */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII ) + goto unsupported;break ; -case 100 : - reg =QCA8K_PORT_STATUS_SPEED_100 ; +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +/* Internal PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_GMII ) + goto unsupported;break ; -case 1000 : - reg =QCA8K_PORT_STATUS_SPEED_1000 ; +case 6 :/* 2nd CPU port / external PHY */ +if (state->interface !=PHY_INTERFACE_MODE_NA && + state->interface !=PHY_INTERFACE_MODE_RGMII && + state->interface !=PHY_INTERFACE_MODE_RGMII_ID && + state->interface !=PHY_INTERFACE_MODE_SGMII && + state->interface !=PHY_INTERFACE_MODE_1000BASEX ) + goto unsupported;break ;default : -dev_dbg (priv->dev,"port%d link speed %dMbps not supported.\n" , - port, phy->speed); +unsupported: +linkmode_zero (supported);return ; } -/* Set duplex mode */ -if (phy->duplex ==DUPLEX_FULL ) - reg |=QCA8K_PORT_STATUS_DUPLEX ; +phylink_set_port_modes (mask); +phylink_set (mask, Autoneg); + + phylink_set(mask, 1000baseT_Full); + phylink_set(mask, 10baseT_Half); + phylink_set(mask, 10baseT_Full); + phylink_set(mask, 100baseT_Half); + phylink_set(mask, 100baseT_Full); + +if (state->interface ==PHY_INTERFACE_MODE_1000BASEX ) + phylink_set(mask, 1000baseX_Full); + +phylink_set (mask, Pause); +phylink_set (mask, Asym_Pause); + +linkmode_and (supported, supported, mask); +linkmode_and (state->advertising, state->advertising, mask); +} + +static int +qca8k_phylink_mac_link_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; -/* Force flow control */ -if (dsa_is_cpu_port (ds, port)) - reg |=QCA8K_PORT_STATUS_RXFLOW |QCA8K_PORT_STATUS_TXFLOW ; + reg =qca8k_read (priv,QCA8K_REG_PORT_STATUS (port)); + + state->link = !!(reg &QCA8K_PORT_STATUS_LINK_UP ); + state->an_complete = state->link; + state->an_enabled = !!(reg &QCA8K_PORT_STATUS_LINK_AUTO ); + state->duplex = (reg &QCA8K_PORT_STATUS_DUPLEX ) ?DUPLEX_FULL : +DUPLEX_HALF ; + +switch (reg &QCA8K_PORT_STATUS_SPEED ) { +case QCA8K_PORT_STATUS_SPEED_10 : + state->speed =SPEED_10 ; +break ; +case QCA8K_PORT_STATUS_SPEED_100 : + state->speed =SPEED_100 ; +break ; +case QCA8K_PORT_STATUS_SPEED_1000 : + state->speed =SPEED_1000 ; +break ; +default : + state->speed =SPEED_UNKNOWN ; +break ; + } + + state->pause =MLO_PAUSE_NONE ; +if (reg &QCA8K_PORT_STATUS_RXFLOW ) + state->pause |=MLO_PAUSE_RX ; +if (reg &QCA8K_PORT_STATUS_TXFLOW ) + state->pause |=MLO_PAUSE_TX ; + +return 1 ; +} + +static void +qca8k_phylink_mac_link_down (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface) +{ +struct qca8k_priv *priv = ds->priv; -/* Force link down before changing MAC options */ qca8k_port_set_status (priv, port,0 ); +} + +static void +qca8k_phylink_mac_link_up (struct dsa_switch *ds,int port,unsigned int mode, +phy_interface_t interface,struct phy_device *phydev, +int speed,int duplex,bool tx_pause,bool rx_pause) +{ +struct qca8k_priv *priv = ds->priv; +u32 reg; + +if (phylink_autoneg_inband (mode)) { + reg =QCA8K_PORT_STATUS_LINK_AUTO ; + }else { +switch (speed) { +case SPEED_10 : + reg =QCA8K_PORT_STATUS_SPEED_10 ; +break ; +case SPEED_100 : + reg =QCA8K_PORT_STATUS_SPEED_100 ; +break ; +case SPEED_1000 : + reg =QCA8K_PORT_STATUS_SPEED_1000 ; +break ; +default : + reg =QCA8K_PORT_STATUS_LINK_AUTO ; +break ; + } + +if (duplex ==DUPLEX_FULL ) + reg |=QCA8K_PORT_STATUS_DUPLEX ; + +if (rx_pause ||dsa_is_cpu_port (ds, port)) + reg |=QCA8K_PORT_STATUS_RXFLOW ; + +if (tx_pause ||dsa_is_cpu_port (ds, port)) + reg |=QCA8K_PORT_STATUS_TXFLOW ; + } + + reg |=QCA8K_PORT_STATUS_TXMAC |QCA8K_PORT_STATUS_RXMAC ; +qca8k_write (priv,QCA8K_REG_PORT_STATUS (port), reg); -qca8k_port_set_status (priv, port,1 ); } static void
@@ -937,13 +1049,11 @@ qca8k_port_enable(struct dsa_switch *ds, int port, {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -if (!dsa_is_user_port (ds, port)) -return 0 ; -qca8k_port_set_status (priv, port,1 ); priv->port_sts[port].enabled =1 ; -phy_support_asym_pause (phy); +if (dsa_is_user_port (ds, port)) +phy_support_asym_pause (phy);return 0 ; }
@@ -1026,7 +1136,6 @@ qca8k_get_tag_protocol(struct dsa_switch *ds, int port,static const struct dsa_switch_ops qca8k_switch_ops = { .get_tag_protocol = qca8k_get_tag_protocol, .setup = qca8k_setup, - .adjust_link = qca8k_adjust_link, .get_strings = qca8k_get_strings, .get_ethtool_stats = qca8k_get_ethtool_stats, .get_sset_count = qca8k_get_sset_count,
@@ -1040,6 +1149,11 @@ static const struct dsa_switch_ops qca8k_switch_ops = { .port_fdb_add = qca8k_port_fdb_add, .port_fdb_del = qca8k_port_fdb_del, .port_fdb_dump = qca8k_port_fdb_dump, + .phylink_validate = qca8k_phylink_validate, + .phylink_mac_link_state = qca8k_phylink_mac_link_state, + .phylink_mac_config = qca8k_phylink_mac_config, + .phylink_mac_link_down = qca8k_phylink_mac_link_down, + .phylink_mac_link_up = qca8k_phylink_mac_link_up, }; static int
Signature · 1 line
2.20.1
PATCH v5 3/3 net: dsa: qca8k: Minor comment spelling fix
In reply to Jonathan McDowell--- drivers/net/dsa/qca8k.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/qca8k.c +1 -1
@@ -647,7 +647,7 @@ qca8k_setup(struct dsa_switch *ds) QCA8K_PORT_LOOKUP_MEMBER, dsa_user_ports(ds)); } -/* Invividual user ports get connected to CPU port only */ +/* Individual user ports get connected to CPU port only */ if (dsa_is_user_port (ds, i)) {int shift =16 * (i %2 );
Signature · 1 line
2.20.1
David Miller
maintainerRe: [PATCH net-next v5 0/3] net: dsa: qca8k: Improve SGMII interface handling
In reply to Jonathan McDowellFrom: Jonathan McDowell <[email protected]>
Date: Sat, 20 Jun 2020 11:30:03 +0100
Quoted 9 lines
This 3 patch series migrates the qca8k switch driver over to PHYLINK, and then adds the SGMII clean-ups (i.e. the missing initialisation) on top of that as a second patch. The final patch is a simple spelling fix in a comment.
As before, 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.
...
Series applied, thanks.