net: dsa: mv88e6xxx: fix external smi for mv88e6176
Subsystems (5)
PATCH v2 1/1 net: dsa: mv88e6xxx: fix external smi for mv88e6176
(Sorry this is my second attempt, I fixed my email client)
I was trying to enable external SMI on a mv88e6176. mv88e6390_g2_scratch_gpio_set_smi() would return -EBUSY when checking the scratch register Config DATA2 p0 mode to ensure that the external smi pins are free, but on my device, bit 4 of p0_mode was always 1, even if the port was completely disabled.
Unless someone with the datasheet can prove me wrong, I believe that at least for the 6176, the mode mask here is 3 bits wide, and the fourth bit is irrelevant or reserved.
To fix this, I add a field in mv88e6xxx_info to denote a p0_mode_mask_override to use. If this is set to the default value of 0, then the definition of MV88E6352_G2_SCRATCH_CONFIG_DATA2_P0_MODE_MASK will be used as normal.
I can confirm that this allows me to use external smi on my mv88e6176!
--- drivers/net/dsa/mv88e6xxx/chip.c | 1 + drivers/net/dsa/mv88e6xxx/chip.h | 7 +++++++ drivers/net/dsa/mv88e6xxx/global2_scratch.c | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-)
drivers/net/dsa/mv88e6xxx/chip.c +1 -0
@@ -6013,6 +6013,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .multi_chip = true, .edsa_support = MV88E6XXX_EDSA_SUPPORTED, .ops = &mv88e6176_ops, + .p0_mode_mask_override = 0x7, }, [MV88E6185] = {
drivers/net/dsa/mv88e6xxx/chip.h +7 -0
@@ -178,6 +178,13 @@ struct mv88e6xxx_info {* port 0, 1 means internal PHYs range starts at port 1, etc */ unsigned int internal_phys_offset; + +/* Some chips use 3 bits for the port mode in scratch +* register CONFIG Data2. +* If this is set to 0x0, it will use the default mask of +* MV88E6352_G2_SCRATCH_CONFIG_DATA2_P0_MODE_MASK +*/ +u8 p0_mode_mask_override; };struct mv88e6xxx_atu_entry {
drivers/net/dsa/mv88e6xxx/global2_scratch.c +6 -1
@@ -255,6 +255,7 @@ int mv88e6390_g2_scratch_gpio_set_smi(struct mv88e6xxx_chip *chip,int config_data1 =MV88E6352_G2_SCRATCH_CONFIG_DATA1 ;int config_data2 =MV88E6352_G2_SCRATCH_CONFIG_DATA2 ;bool no_cpu; +u8 p0_mode_mask;u8 p0_mode;int err;u8 val;
@@ -263,7 +264,11 @@ int mv88e6390_g2_scratch_gpio_set_smi(struct mv88e6xxx_chip *chip,if (err)return err; - p0_mode = val &MV88E6352_G2_SCRATCH_CONFIG_DATA2_P0_MODE_MASK ; + p0_mode_mask = chip->info->p0_mode_mask_override; +if ( p0_mode_mask ==0x0 ) { + p0_mode_mask =MV88E6352_G2_SCRATCH_CONFIG_DATA2_P0_MODE_MASK ; + } + p0_mode = val & p0_mode_mask;if (p0_mode ==0x01 || p0_mode ==0x02 )return -EBUSY ;
Signature · 1 line
2.39.5
Andrew Lunn
maintainerQuoted 3 lines · Robert Cross
(Sorry this is my second attempt, I fixed my email client)
I was trying to enable external SMI on a mv88e6176.
MV88E6XXX_FAMILY_6352, /* 6172 6176 6240 6352 */
So it is part of the 6352 family. That family does not have an internal and external MDIO bus. It has a single bus which is both internal and external.
It is only the 6390 family and above which has two MDIO busses.
Andrew
---
pw-bot: cr
According to the documents I'm looking at, the 88E6172 and 88E6176 both have external MDIO buses. I have brought up a board with two connected 88E6176 chips, each with a PHY that can only be managed with the MDC/MDIO_PHY pins of the 88E6176s.
After applying this patch I was able to successfully manage and control these external PHYs without issue. I'm not sure if you have access to the 88E6176 datasheet specifically, but this chip absolutely does have an external MDIO.
(also, I fixed the problems with the checkpatch.pl, I will submit the fixed version again tomorrow)
- Robert Cross
Quoted 18 lines · Andrew Lunn
Quoted 3 lines · Robert Cross
(Sorry this is my second attempt, I fixed my email client)
I was trying to enable external SMI on a mv88e6176.
MV88E6XXX_FAMILY_6352, /* 6172 6176 6240 6352 */So it is part of the 6352 family. That family does not have an internal and external MDIO bus. It has a single bus which is both internal and external.
It is only the 6390 family and above which has two MDIO busses.
Andrew
---
pw-bot: cr
Andrew Lunn
maintainerQuoted 10 lines · Robert Cross
According to the documents I'm looking at, the 88E6172 and 88E6176 both have external MDIO buses. I have brought up a board with two connected 88E6176 chips, each with a PHY that can only be managed with the MDC/MDIO_PHY pins of the 88E6176s.
After applying this patch I was able to successfully manage and control these external PHYs without issue. I'm not sure if you have access to the 88E6176 datasheet specifically, but this chip absolutely does have an external MDIO.
You are not understanding what i'm saying. This family has a single MDIO bus controller. That controller is used by both the internal PHY devices, plus there are two pins on the chip for external PHYs.
All the PHYs will appear on that one MDIO bus controller.
The MV88E6390_G2_SMI_PHY_CMD_FUNC_EXTERNAL bit is reserved on the 6352 family.
Andrew
Quoted 2 lines
The
MV88E6390_G2_SMI_PHY_CMD_FUNC_EXTERNALbit is reserved on the 6352 family.
Indeed it is...
Quoted 5 lines
You are not understanding what i'm saying. This family has a single MDIO bus controller. That controller is used by both the internal PHY devices, plus there are two pins on the chip for external PHYs.
All the PHYs will appear on that one MDIO bus controller.
So you're saying that if I removed my hack that apparently just sets this reserved bit, and I take my PHY on port 6 and remove it from the mdio_ext { compatible = "marvell,mv88e6xxx-mdio-external"; } entry and put it in my mdio { } node it will direct requests to address 6 to the external phy via the MDC/MDIO_PHY pins just fine?
I'm guessing it will just automatically enable or disable the external SMI pins depending on the state of port 5 which shares pins?
I'm also guessing that ports 0, 1, 2, 3, and 4 will map to the internal PHYs (because there are 5) and then ports 5 and 6 automagically externally...
I shudder to think how by what forbidden voodoo my current device tree actually works with this hack...
Thank you so much for your explanation. Hopefully I'll have a real substantive patch in the future :)
Andrew Lunn
maintainerQuoted 9 lines · Robert Cross
Quoted 2 lines
The
MV88E6390_G2_SMI_PHY_CMD_FUNC_EXTERNALbit is reserved on the 6352 family.Indeed it is...
Quoted 4 lines
You are not understanding what i'm saying. This family has a single MDIO bus controller. That controller is used by both the internal PHY devices, plus there are two pins on the chip for external PHYs.
Quoted 7 lines
Quoted 1 line
All the PHYs will appear on that one MDIO bus controller.
So you're saying that if I removed my hack that apparently just sets this reserved bit, and I take my PHY on port 6 and remove it from the
mdio_ext{ compatible = "marvell,mv88e6xxx-mdio-external"; } entry and put it in my mdio { } node it will direct requests to address 6 to the external phy via the MDC/MDIO_PHY pins just fine?
Yep.
Quoted 2 lines
I'm guessing it will just automatically enable or disable the external SMI pins depending on the state of port 5 which shares pins?
I _think_ you will actually see all MDIO transactions on the external pins. SolidRun got one of their board designs wrong, and put an external PHY on the same address as an internal PHY. That results in both not working because they stomp over each other on the bus.
Andrew
Imagine that, it just works when I set it up like that...
And now I don't get concerning watchdog event messages probably from putting the chip and driver in an undefined state!
[ 145.839142] mv88e6085 gpio-0:04: Watchdog event: 0x003b
Thank you again!
Vladimir Oltean
maintainerHi Andrew,
Quoted 16 lines · Andrew Lunn
Quoted 10 lines · Robert Cross
According to the documents I'm looking at, the 88E6172 and 88E6176 both have external MDIO buses. I have brought up a board with two connected 88E6176 chips, each with a PHY that can only be managed with the MDC/MDIO_PHY pins of the 88E6176s.
After applying this patch I was able to successfully manage and control these external PHYs without issue. I'm not sure if you have access to the 88E6176 datasheet specifically, but this chip absolutely does have an external MDIO.
You are not understanding what i'm saying. This family has a single MDIO bus controller. That controller is used by both the internal PHY devices, plus there are two pins on the chip for external PHYs.
Quoted 6 lines
All the PHYs will appear on that one MDIO bus controller.
The
MV88E6390_G2_SMI_PHY_CMD_FUNC_EXTERNALbit is reserved on the 6352 family.Andrew
Is there any addition to Documentation/devicetree/bindings/net/dsa/marvell,mv88e6xxx.yaml that we could make in order to clarify which switch families have a combined internal+external MDIO bus and which ones have them separate?
As you're saying, this is an area where mistakes happen relatively frequently.
Andrew Lunn
maintainerQuoted 5 lines
Is there any addition to
Documentation/devicetree/bindings/net/dsa/marvell,mv88e6xxx.yamlthat we could make in order to clarify which switch families have a combined internal+external MDIO bus and which ones have them separate?
As you're saying, this is an area where mistakes happen relatively frequently.
It should be possible to add a constraint. Only compatible "marvell,mv88e6190" can use "mdio-external"
Andrew