net: dsa: yt921x: Add support for Motorcomm YT921x
Subsystems (5)
David Yang
maintainerv5 cover net: dsa: yt921x: Add support for Motorcomm YT921x
Motorcomm YT921x is a series of ethernet switches developed by Shanghai Motorcomm Electronic Technology, including:
- YT9215S / YT9215RB / YT9215SC: 5 GbE phys
- YT9213NB / YT9214NB: 2 GbE phys
- YT9218N / YT9218MB: 8 GbE phys
and up to 2 serdes interfaces.
This patch adds basic support for a working DSA switch.
v4: https://lore.kernel.org/r/[email protected]
- remove switchid from dt binding
- remove hsr from tag driver
- use ratelimited log in tag driver
v3: https://lore.kernel.org/r/[email protected]
- fix words and warnings in dt binding
- remove unnecessary dev_warn_ratelimited and u64_from_u32
- remove lag and mst
- check for mdio results and fix a unlocked write in conduit_state_change
v2: https://lore.kernel.org/r/[email protected]
- fix words in dt binding
- add support for lag and mst
v1: https://lore.kernel.org/r/[email protected]
- fix coding style
- add dt binding
- add support for fdb, vlan and bridge
David Yang (3):
dt-bindings: net: dsa: yt921x: Add Motorcomm YT921x switch support
net: dsa: tag_yt921x: add support for Motorcomm YT921x tags
net: dsa: yt921x: Add support for Motorcomm YT921x
.../bindings/net/dsa/motorcomm,yt921x.yaml | 150 + drivers/net/dsa/Kconfig | 7 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/yt921x.c | 3584 +++++++++++++++++ include/net/dsa.h | 2 + net/dsa/Kconfig | 6 + net/dsa/Makefile | 1 + net/dsa/tag_yt921x.c | 126 + 8 files changed, 3877 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml create mode 100644 drivers/net/dsa/yt921x.c create mode 100644 net/dsa/tag_yt921x.c
Signature · 1 line
2.50.1
David Yang
maintainerPATCH v5 1/3 dt-bindings: net: dsa: yt921x: Add Motorcomm YT921x switch support
The Motorcomm YT921x series is a family of Ethernet switches with up to 8 internal GbE PHYs and up to 2 GMACs.
--- .../bindings/net/dsa/motorcomm,yt921x.yaml | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml
Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml new file +150 -0
@@ -0,0 +1,150 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/dsa/motorcomm,yt921x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Motorcomm YT921x Ethernet switch family + +maintainers: + - David Yang <[email protected]> + +description: | + The Motorcomm YT921x series is a family of Ethernet switches with up to 8 + internal GbE PHYs and up to 2 GMACs, including: + + - YT9215S / YT9215RB / YT9215SC: 5 GbE PHYs (Port 0-4) + 2 GMACs (Port 8-9) + - YT9213NB: 2 GbE PHYs (Port 1/3) + 1 GMAC (Port 9) + - YT9214NB: 2 GbE PHYs (Port 1/3) + 2 GMACs (Port 8-9) + - YT9218N: 8 GbE PHYs (Port 0-7) + - YT9218MB: 8 GbE PHYs (Port 0-7) + 2 GMACs (Port 8-9) + + Any port can be used as the CPU port. + +properties: + compatible: + const: motorcomm,yt9215 + + reg: + maxItems: 1 + + reset-gpios: + maxItems: 1 + + mdio: + $ref: /schemas/net/mdio.yaml# + unevaluatedProperties: false + description: | + Internal MDIO bus for the internal GbE PHYs. PHYs 0-7 are used for Port + 0-7 respectively. + + mdio-external: + $ref: /schemas/net/mdio.yaml# + unevaluatedProperties: false + description: | + External MDIO bus to access external components. External PHYs for GMACs + (Port 8-9) are expected to be connected to the external MDIO bus in + vendor's reference design, but that is not a hard limitation from the + chip. + +allOf: + - $ref: dsa.yaml#/$defs/ethernet-ports + +required: + - compatible + - reg + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + switch@1d { + compatible = "motorcomm,yt9215"; + /* default 0x1d, alternate 0x0 */ + reg = <0x1d>; + reset-gpios = <&tlmm 39 GPIO_ACTIVE_LOW>; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + sw_phy0: phy@0 { + reg = <0x0>; + }; + }; + + mdio-external { + #address-cells = <1>; + #size-cells = <0>; + + phy1: phy@b { + reg = <0xb>; + }; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* phy-handle is optional for internal PHYs */ + port@0 { + reg = <0>; + label = "lan1"; + phy-mode = "internal"; + phy-handle = <&sw_phy0>; + }; + + port@1 { + reg = <1>; + label = "lan2"; + phy-mode = "internal"; + }; + + port@2 { + reg = <2>; + label = "lan3"; + phy-mode = "internal"; + }; + + port@3 { + reg = <3>; + label = "lan4"; + phy-mode = "internal"; + }; + + port@4 { + reg = <4>; + label = "lan5"; + phy-mode = "internal"; + }; + + /* CPU port */ + port@8 { + reg = <8>; + phy-mode = "sgmii"; + ethernet = <ð0>; + + fixed-link { + speed = <1000>; + full-duplex; + pause; + asym-pause; + }; + }; + + /* if external phy is connected to a MAC */ + port@9 { + reg = <9>; + label = "wan"; + phy-mode = "rgmii"; + phy-handle = <&phy1>; + }; + }; + }; + };
Signature · 1 line
2.50.1
Re: [net-next v5 1/3] dt-bindings: net: dsa: yt921x: Add Motorcomm YT921x switch support
Quoted 2 lines · David Yang
The Motorcomm YT921x series is a family of Ethernet switches with up to 8 internal GbE PHYs and up to 2 GMACs.
Please use standard email subjects, so with the PATCH keyword in the title. 'git format-patch -vX' helps here to create proper versioned patches. Another useful tool is b4. Skipping the PATCH keyword makes filtering of emails more difficult thus making the review process less convenient.
Quoted 6 lines
Signed-off-by David Yang <[email protected]>--- .../bindings/net/dsa/motorcomm,yt921x.yaml | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml
...
Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml line 50
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml new file +10
-0+ mdio-external: + $ref: /schemas/net/mdio.yaml# + unevaluatedProperties: false + description: | + External MDIO bus to access external components. External PHYs for GMACs + (Port 8-9) are expected to be connected to the external MDIO bus in + vendor's reference design, but that is not a hard limitation from the + chip. + +allOf:
This goes after required: block.
But don't resend just for that.
Best regards,
Krzysztof
Andrew Lunn
maintainerRe: [net-next v5 1/3] dt-bindings: net: dsa: yt921x: Add Motorcomm YT921x switch support
In reply to David YangDocumentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml line 70
Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml new file +4
-0+ switch@1d { + compatible = "motorcomm,yt9215"; + /* default 0x1d, alternate 0x0 */ + reg = <0x1d>;
Just curious, what does alternative 0x0 mean? Does this switch have only one strapping pin for address, so it either uses address 0x1d or 0x0?
Andrew
Yangfl
maintainerRe: [net-next v5 1/3] dt-bindings: net: dsa: yt921x: Add Motorcomm YT921x switch support
Quoted 11 lines · Andrew Lunn
Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml line 70
Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml new file +4
-0+ switch@1d { + compatible = "motorcomm,yt9215"; + /* default 0x1d, alternate 0x0 */ + reg = <0x1d>;Just curious, what does alternative
0x0mean? Does this switch have only one strapping pin for address, so it either uses address0x1dor0x0?Andrew
Yes. I've seen this approach on other chips (offering two MDIO phyaddrs), so this should be a common practice.
Andrew Lunn
maintainerRe: [net-next v5 1/3] dt-bindings: net: dsa: yt921x: Add Motorcomm YT921x switch support
Quoted 7 lines · Yangfl
Quoted 6 lines · Andrew Lunn
Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml new file +4
-0+ switch@1d { + compatible = "motorcomm,yt9215"; + /* default 0x1d, alternate 0x0 */ + reg = <0x1d>;
Quoted 8 lines
Quoted 5 lines
Just curious, what does alternative
0x0mean? Does this switch have only one strapping pin for address, so it either uses address0x1dor0x0?Andrew
Yes. I've seen this approach on other chips (offering two MDIO phyaddrs), so this should be a common practice.
If it only supports two addresses, you could add a constrain in the binding that reg is [0x0, 0x1d].
Andrew
David Yang
maintainerPATCH v5 2/3 net: dsa: tag_yt921x: add support for Motorcomm YT921x tags
In reply to David YangAdd support for Motorcomm YT921x tags, which includes a proper configurable ethertype field (default to 0x9988).
--- include/net/dsa.h | 2 + net/dsa/Kconfig | 6 +++ net/dsa/Makefile | 1 + net/dsa/tag_yt921x.c | 126 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 net/dsa/tag_yt921x.c
include/net/dsa.h +2 -0
@@ -55,6 +55,7 @@ struct tc_action;#define DSA_TAG_PROTO_LAN937X_VALUE 27#define DSA_TAG_PROTO_VSC73XX_8021Q_VALUE 28#define DSA_TAG_PROTO_BRCM_LEGACY_FCS_VALUE 29 +#define DSA_TAG_PROTO_YT921X_VALUE 30enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -87,6 +88,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_RZN1_A5PSW =DSA_TAG_PROTO_RZN1_A5PSW_VALUE ,DSA_TAG_PROTO_LAN937X =DSA_TAG_PROTO_LAN937X_VALUE ,DSA_TAG_PROTO_VSC73XX_8021Q =DSA_TAG_PROTO_VSC73XX_8021Q_VALUE , + DSA_TAG_PROTO_YT921X = DSA_TAG_PROTO_YT921X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +6 -0
@@ -190,4 +190,10 @@ config NET_DSA_TAG_XRS700X Say Y or M if you want to enable support for tagging frames for Arrow SpeedChips XRS700x switches that use a single byte tag trailer. +config NET_DSA_TAG_YT921X + tristate "Tag driver for Motorcomm YT921x switches" + help + Say Y or M if you want to enable support for tagging frames for + Motorcomm YT921x switches. + endif
net/dsa/Makefile +1 -0
@@ -39,6 +39,7 @@ obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o +obj-$(CONFIG_NET_DSA_TAG_YT921X) += tag_yt921x.o # for tracing framework to find trace.h CFLAGS_trace.o := -I$(src)
net/dsa/tag_yt921x.c new file +126 -0
126 lines not on this page · raw message
Signature · 1 line
2.50.1
Re: [net-next v5 2/3] net: dsa: tag_yt921x: add support for Motorcomm YT921x tags
Quoted 4 lines · David Yang
Add support for Motorcomm YT921x tags, which includes a proper configurable ethertype field (default to
0x9988).Signed-off-by David Yang <[email protected]>
Andrew
David Yang
maintainerPATCH v5 3/3 net: dsa: yt921x: Add support for Motorcomm YT921x
In reply to David YangMotorcomm YT921x is a series of ethernet switches developed by Shanghai Motorcomm Electronic Technology, including:
- YT9215S / YT9215RB / YT9215SC: 5 GbE PHYs
- YT9213NB / YT9214NB: 2 GbE PHYs
- YT9218N / YT9218MB: 8 GbE PHYs
and up to 2 GMACs.
Driver verified on a stock wireless router with IPQ5018 + YT9215S.
--- drivers/net/dsa/Kconfig | 7 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/yt921x.c | 3584 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 3592 insertions(+) create mode 100644 drivers/net/dsa/yt921x.c
drivers/net/dsa/Kconfig +7 -0
@@ -152,4 +152,11 @@ config NET_DSA_VITESSE_VSC73XX_PLATFORM This enables support for the Vitesse VSC7385, VSC7388, VSC7395 and VSC7398 SparX integrated ethernet switches, connected over a CPU-attached address bus and work in memory-mapped I/O mode. + +config NET_DSA_YT921X + tristate "Motorcomm YT9215 ethernet switch chip support" + select NET_DSA_TAG_YT921X + help + This enables support for the Motorcomm YT9215 ethernet switch + chip. endmenu
drivers/net/dsa/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-$(CONFIG_NET_DSA_SMSC_LAN9303_MDIO) += lan9303_mdio.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX) += vitesse-vsc73xx-core.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_PLATFORM) += vitesse-vsc73xx-platform.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_SPI) += vitesse-vsc73xx-spi.o +obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o obj-y += b53/ obj-y += hirschmann/ obj-y += microchip/
drivers/net/dsa/yt921x.c new file +3584 -0
2,982 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.50.1
Part of the diff is not shown here. View the raw message.
Quoted 13 lines · David Yang
drivers/net/dsa/yt921x.c new file +13
-0+static int +yt921x_port_config (struct yt921x_priv *priv,int port,unsigned int mode, +const struct phylink_link_state *state) +{ +const struct yt921x_info *info = priv->info; +struct device *dev =to_device (priv); +enum yt921x_fixed fixed; +bool duplex_full; +u32 mask; +u32 ctrl; +int res; + + if (state->interface != PHY_INTERFACE_MODE_INTERNAL &&
drivers/net/dsa/yt921x.c line 2714
Quoted 10 lines
drivers/net/dsa/yt921x.c new file +10
-0+ !yt921x_info_port_is_external(info, port)) { +dev_err (dev,"Wrong mode %d on port %d\n" , + state->interface, port); +return -EINVAL ; + } + + fixed =YT921X_FIXED_NOTFIXED ; + ctrl =YT921X_PORT_LINK ; +if (mode ==MLO_AN_FIXED ) +switch (state->speed) {
Someone clearly doesn't believe in reading the documentation before writing code. This also hasn't been tested in any way. Sorry, but I'm going to put as much effort into this review as you have into understanding the phylink API, and thus my review ends here.
NAK.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Yangfl
maintainerQuoted 31 lines · Russell King (Oracle)
Quoted 13 lines · David Yang
drivers/net/dsa/yt921x.c new file +13
-0+static int +yt921x_port_config (struct yt921x_priv *priv,int port,unsigned int mode, +const struct phylink_link_state *state) +{ +const struct yt921x_info *info = priv->info; +struct device *dev =to_device (priv); +enum yt921x_fixed fixed; +bool duplex_full; +u32 mask; +u32 ctrl; +int res; + + if (state->interface != PHY_INTERFACE_MODE_INTERNAL &&drivers/net/dsa/yt921x.c line 2714
Quoted 10 lines
drivers/net/dsa/yt921x.c new file +10
-0+ !yt921x_info_port_is_external(info, port)) { +dev_err (dev,"Wrong mode %d on port %d\n" , + state->interface, port); +return -EINVAL ; + } + + fixed =YT921X_FIXED_NOTFIXED ; + ctrl =YT921X_PORT_LINK ; +if (mode ==MLO_AN_FIXED ) +switch (state->speed) {Someone clearly doesn't believe in reading the documentation before writing code. This also hasn't been tested in any way. Sorry, but I'm going to put as much effort into this review as you have into understanding the phylink API, and thus my review ends here.
Quoted 5 lines
NAK.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Sorry I'm quite new here. I don't understand very clearly why a different set of calls is involved in dsa_switch_ops, so I referred to other dsa drivers and made a working driver (at least tested on my device), but I would appreciate it much if you could point it out in an earlier version of series.
Sorry for any disturbance.
Quoted 39 lines · Yangfl
Quoted 31 lines · Russell King (Oracle)
Quoted 13 lines · David Yang
drivers/net/dsa/yt921x.c new file +13
-0+static int +yt921x_port_config (struct yt921x_priv *priv,int port,unsigned int mode, +const struct phylink_link_state *state) +{ +const struct yt921x_info *info = priv->info; +struct device *dev =to_device (priv); +enum yt921x_fixed fixed; +bool duplex_full; +u32 mask; +u32 ctrl; +int res; + + if (state->interface != PHY_INTERFACE_MODE_INTERNAL &&drivers/net/dsa/yt921x.c line 2714
Quoted 10 lines
drivers/net/dsa/yt921x.c new file +10
-0+ !yt921x_info_port_is_external(info, port)) { +dev_err (dev,"Wrong mode %d on port %d\n" , + state->interface, port); +return -EINVAL ; + } + + fixed =YT921X_FIXED_NOTFIXED ; + ctrl =YT921X_PORT_LINK ; +if (mode ==MLO_AN_FIXED ) +switch (state->speed) {Someone clearly doesn't believe in reading the documentation before writing code. This also hasn't been tested in any way. Sorry, but I'm going to put as much effort into this review as you have into understanding the phylink API, and thus my review ends here.
Quoted 5 lines
NAK.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Quoted 5 lines
Sorry I'm quite new here. I don't understand very clearly why a different set of calls is involved in
dsa_switch_ops, so I referred to other dsa drivers and made a working driver (at least tested on my device), but I would appreciate it much if you could point it out in an earlier version of series.
This isn't dsa_switch_ops, but phylink_mac_ops, which are well documented in include/linux/phylink.h. Please read the documentation found in that header file detailing the phylink_mac_ops methods. You'll find a brief overview before the struct, and then in the #if 0 section, detailed per-method documentation.
Thanks.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Quoted 16 lines · Russell King (Oracle)
Quoted 7 lines · Yangfl
Quoted 5 lines · Russell King (Oracle)
Someone clearly doesn't believe in reading the documentation before writing code. This also hasn't been tested in any way. Sorry, but I'm going to put as much effort into this review as you have into understanding the phylink API, and thus my review ends here.
Quoted 7 lines
Quoted 1 line
NAK.
Sorry I'm quite new here. I don't understand very clearly why a different set of calls is involved in
dsa_switch_ops, so I referred to other dsa drivers and made a working driver (at least tested on my device), but I would appreciate it much if you could point it out in an earlier version of series.
Quoted 5 lines
This isn't
dsa_switch_ops, butphylink_mac_ops, which are well documented ininclude/linux/phylink.h. Please read the documentation found in that header file detailing thephylink_mac_opsmethods. You'll find a brief overview before the struct, and then in the #if 0 section, detailed per-method documentation.
Also, the reason I state that it hasn't been tested is because when your mac_config method is invoked, and print debug information which includes state->speed and state->duplex, and then go on to use these. Phylink's sole call path to mac_config() does this:
/* Stop drivers incorrectly using these */
linkmode_zero(st.lp_advertising);
st.speed = SPEED_UNKNOWN;
st.duplex = DUPLEX_UNKNOWN;
st.an_complete = false;
st.link = false;
phylink_dbg(pl,
"%s: mode=%s/%s/%s adv=%*pb pause=%02x\n",
__func__, phylink_an_mode_str(pl->act_link_an_mode),
phy_modes(st.interface),
phy_rate_matching_to_str(st.rate_matching),
__ETHTOOL_LINK_MODE_MASK_NBITS, st.advertising,
st.pause);
pl->mac_ops->mac_config(pl->config, pl->act_link_an_mode, &st);and you would've noticed in your debug print that e.g. state->speed and state->duplex are both always -1, and thus are not useful. Note also the debugging that phylink includes.
Note that no other mac_config() implementations refer to state->speed and state->duplex. The only time drivers _write_ to these is in the pcs_get_state() method if they support a PCS.
Therefore, I think your code is completely untested.
I'm also concerned about the SMI locking, which looks to me like you haven't realised that the MDIO bus layer has locking which guarantees that all invocations of the MDIO bus read* and write* methods are serialised.
Thanks.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Yangfl
maintainerQuoted 50 lines · Russell King (Oracle)
Quoted 16 lines · Russell King (Oracle)
Quoted 7 lines · Yangfl
Quoted 5 lines · Russell King (Oracle)
Someone clearly doesn't believe in reading the documentation before writing code. This also hasn't been tested in any way. Sorry, but I'm going to put as much effort into this review as you have into understanding the phylink API, and thus my review ends here.
Quoted 7 lines
Quoted 1 line
NAK.
Sorry I'm quite new here. I don't understand very clearly why a different set of calls is involved in
dsa_switch_ops, so I referred to other dsa drivers and made a working driver (at least tested on my device), but I would appreciate it much if you could point it out in an earlier version of series.Quoted 5 lines
This isn't
dsa_switch_ops, butphylink_mac_ops, which are well documented ininclude/linux/phylink.h. Please read the documentation found in that header file detailing thephylink_mac_opsmethods. You'll find a brief overview before the struct, and then in the #if 0 section, detailed per-method documentation.Also, the reason I state that it hasn't been tested is because when your
mac_configmethod is invoked, and print debug information which includesstate->speedandstate->duplex, and then go on to use these. Phylink's sole call path tomac_config()does this:/* Stop drivers incorrectly using these */ linkmode_zero(st.lp_advertising); st.speed = SPEED_UNKNOWN; st.duplex = DUPLEX_UNKNOWN; st.an_complete = false; st.link = false; phylink_dbg(pl, "%s: mode=%s/%s/%s adv=%*pb pause=%02x\n", __func__, phylink_an_mode_str(pl->act_link_an_mode), phy_modes(st.interface), phy_rate_matching_to_str(st.rate_matching), __ETHTOOL_LINK_MODE_MASK_NBITS, st.advertising, st.pause); pl->mac_ops->mac_config(pl->config, pl->act_link_an_mode, &st);and you would've noticed in your debug print that e.g.
state->speedandstate->duplexare both always -1, and thus are not useful. Note also the debugging that phylink includes.
Quoted 6 lines
Note that no other
mac_config()implementations refer tostate->speedandstate->duplex. The only time drivers _write_ to these is in thepcs_get_state()method if they support a PCS.Therefore, I think your code is completely untested.
Thanks for your help. I didn't notice that since it accidentally configures autonegotiation for me. Anyway I'll take a closer look at relevant apis.
Quoted 4 lines
I'm also concerned about the SMI locking, which looks to me like you haven't realised that the MDIO bus layer has locking which guarantees that all invocations of the MDIO bus read* and write* methods are serialised.
The device takes two sequential u16 MDIO r/w into one op on its internal 32b regs, so we need to serialise SMI ops to avoid race conditions. Strictly speaking only locking the target phyaddr is needed, but I think it won't hurt to lock the MDIO bus as long as I don't perform busy wait while holding the bus lock.
Andrew Lunn
maintainerQuoted 17 lines
drivers/net/dsa/yt921x.c new file +16
-0+#define should_unreachable () \ + pr_err("%s: !!unreachable %d, please report a bug!\n", \ + __func__, __LINE__) +#define consume_retval (res) do { \ + if (unlikely(res)) \ + pr_err("%s: %i\n", __func__, (res)); \ +} while (0) + +static int +yt921x_vid_del (struct yt921x_priv *priv,int port,u16 vid) +{ +struct yt921x_port *pp = &priv->ports[port]; +u32 mask; +u32 ctrl; +u32 val; +int res;
...
drivers/net/dsa/yt921x.c line 1625
Quoted 6 lines
drivers/net/dsa/yt921x.c new file +6
-0+ +if (pp->vids_cnt <=0 ) +should_unreachable (); +else + pp->vids_cnt--; +return 0 ;
Have you seen other drivers do this? If you are doing something which other drivers don't do, it is probably wrong.
What you are more likely to see is WARN_ON(pp->vids_cnt <= 0); You then get a stack trace, to help debug what happened. Kernel developers know what WARN_ON() does, so it is easy to
understand. should_unreachable() is unique, it is unclear what it does, making it harder to understand and review.
Quoted 11 lines
drivers/net/dsa/yt921x.c new file +11
-0+static void +yt921x_dsa_port_bridge_leave (struct dsa_switch *ds,int port, +struct dsa_bridge bridge) +{ +struct yt921x_priv *priv =to_yt921x_priv (ds); +struct device *dev =to_device (priv); +u16 ports_mask; +int res; + + ports_mask =dsa_bridge_ports (ds, bridge.dev); +
drivers/net/dsa/yt921x.c line 2038
Quoted 10 lines
drivers/net/dsa/yt921x.c new file +10
-0+dev_dbg (dev,"%s: port %d, mask 0x%x\n" , __func__, port, ports_mask); + + ports_mask |= priv->cpu_ports_mask; + +yt921x_smi_acquire (priv); + res =yt921x_bridge_force (priv, ports_mask); +yt921x_smi_release (priv); + +consume_retval (res); +}
And this is the same. Every driver you look at would just have the if statement, not a macro.
In order to make drivers easy to maintain, easier to review, easy to debug, they should all look similar.
Andrew