dsa: add support for the Marvell 88E6060 switch chip
Subsystems (3)
PATCH v3 5/5 dsa: add support for the Marvell 88E6060 switch chip
Add support for the Marvell 88E6060 switch chip. This chip only supports the Header and Trailer tagging formats, and we use it in Trailer mode since that mode is slightly easier to handle than Header mode.
--- net/dsa/Kconfig | 7 ++ net/dsa/Makefile | 1 + net/dsa/mv88e6060.c | 287 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+), 0 deletions(-) create mode 100644 net/dsa/mv88e6060.c
net/dsa/Kconfig +7 -0
@@ -28,6 +28,13 @@ config NET_DSA_MV88E6XXX bool default n +config NET_DSA_MV88E6060 + bool "Marvell 88E6060 ethernet switch chip support" + select NET_DSA_TAG_TRAILER + ---help--- + This enables support for the Marvell 88E6060 ethernet switch + chip. + config NET_DSA_MV88E6XXX_NEED_PPU bool default n
net/dsa/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o # switch drivers obj-$(CONFIG_NET_DSA_MV88E6XXX) += mv88e6xxx.o +obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o obj-$(CONFIG_NET_DSA_MV88E6123_61_65) += mv88e6123_61_65.o obj-$(CONFIG_NET_DSA_MV88E6131) += mv88e6131.o
net/dsa/mv88e6060.c new file +287 -0
287 lines not on this page · raw message
Signature · 1 line
1.5.6.4
net/dsa/mv88e6060.c line 22
Quoted 5 lines · Lennert Buytenhek
net/dsa/mv88e6060.c new file +5
-0+ +static int reg_read (struct dsa_switch *ds,int addr,int reg) +{ +return mdiobus_read (ds->master_mii_bus, addr, reg); +}
Instead of all the code to add the mdio buses to the device tree and exporting mdiobus_read(), could you have just added the switch chip as a "phy" on the mdio bus? Then used phy_read/write() on it? I know it's not a phy, but you don't need to use the phy state machine and so on.
Freescale gianfar MACs configure the serdes for SGMII using a virtual "TBI" device on the MDIO bus. Supposedly Andy has patch that adds them as devices on the MDIO bus, isn't of the gianfar specific MDIO back-door they currently use.
net/dsa/mv88e6060.c line 32
Quoted 9 lines
net/dsa/mv88e6060.c new file +9
-0+#define REG_READ (addr, reg) \ + ({ \ + int __ret; \ + \ + __ret = reg_read(ds, addr, reg); \ + if (__ret < 0) \ + return __ret; \ + __ret; \ + })
Macro with a hidden use of a local ('ds') and a hidden return? The former is discouraged (but can sure save a lot of typing) but the latter seems like it's just begging to cause a missing unlock or free on an error path.
Quoted 9 lines · Trent Piepho
net/dsa/mv88e6060.c line 22
Quoted 4 lines
net/dsa/mv88e6060.c new file +4
-0+static int reg_read (struct dsa_switch *ds,int addr,int reg) +{ +return mdiobus_read (ds->master_mii_bus, addr, reg); +}Instead of all the code to add the mdio buses to the device tree and exporting
mdiobus_read(), could you have just added the switch chip as a "phy" on the mdio bus? Then used phy_read/write() on it? I know it's not a phy, but you don't need to use the phy state machine and so on.
At least the switches that are supported now don't take up only one MII bus address, but use all 32, so I wouldn't be able to use phy_{read,write}() on them.
And the first 5-10 of those addresses generally look like normal PHYs, but you wouldn't want to attach PHY drivers to them directly (since you need to wrap accesses to the PHYs on some switches to disable the internal PHY polling that the switch does first), which would complicate autoprobing quite a bit.
Quoted 4 lines
Freescale gianfar MACs configure the serdes for SGMII using a virtual "TBI" device on the MDIO bus. Supposedly Andy has patch that adds them as devices on the MDIO bus, isn't of the gianfar specific MDIO back-door they currently use.
I think with gianfar, the MDIO bus drivers are separate platform devices, and you can then get at the struct mii_bus * by taking the platform device private data pointer -- which is a bit of an ugly way of doing it, IMHO.
Quoted 6 lines
Quoted 6 lines
net/dsa/mv88e6060.c new file +6
-0+#define REG_READ (addr, reg) \ + ({ \ + int __ret; \ + \ + __ret = reg_read(ds, addr, reg); \ + if (__ret < 0) \
Quoted 8 lines
net/dsa/mv88e6060.c line 32
Quoted 3 lines
net/dsa/mv88e6060.c new file +3
-0+return __ret; \ + __ret; \ + })Macro with a hidden use of a local ('ds') and a hidden return? The former is discouraged (but can sure save a lot of typing) but the latter seems like it's just begging to cause a missing unlock or free on an error path.
Yeah, well, that was intentional (Nicolas Pitre suggested it, and I figured it made sense to do it). I think there are a couple more places in the tree that do this, and it very much increases readability because you no longer need to check the return value explicitly every single time you do an MII access.
Quoted 18 lines · Lennert Buytenhek
Quoted 10 lines · Trent Piepho
net/dsa/mv88e6060.c line 32
Quoted 9 lines
net/dsa/mv88e6060.c new file +9
-0+#define REG_READ (addr, reg) \ + ({ \ + int __ret; \ + \ + __ret = reg_read(ds, addr, reg); \ + if (__ret < 0) \ + return __ret; \ + __ret; \ + })Quoted 4 lines
Macro with a hidden use of a local ('ds') and a hidden return? The former is discouraged (but can sure save a lot of typing) but the latter seems like it's just begging to cause a missing unlock or free on an error path.
Quoted 5 lines
Yeah, well, that was intentional (Nicolas Pitre suggested it, and I figured it made sense to do it). I think there are a couple more places in the tree that do this, and it very much increases readability because you no longer need to check the return value explicitly every single time you do an MII access.
I agree with Trent, it only increases readability in the sense that you have to read less when scanning over the code. To me, that is the least important sort of readability. This sort of macro just creates hidden traps. I know it's annoying to check that return value every time, but that's why we get paid the big bucks. ;)
If, for some reason, the community feels this is the right way to go, at *least* rename the macro to make it clear that it returns on an error, and make ds an explicit parameter.
Andy
Quoted 21 lines · Andy Fleming
Quoted 15 lines
Quoted 10 lines
net/dsa/mv88e6060.c line 32
Quoted 9 lines
net/dsa/mv88e6060.c new file +9
-0+#define REG_READ (addr, reg) \ + ({ \ + int __ret; \ + \ + __ret = reg_read(ds, addr, reg); \ + if (__ret < 0) \ + return __ret; \ + __ret; \ + })Quoted 4 lines
Macro with a hidden use of a local ('ds') and a hidden return? The former is discouraged (but can sure save a lot of typing) but the latter seems like it's just begging to cause a missing unlock or free on an error path.
Quoted 5 lines
Yeah, well, that was intentional (Nicolas Pitre suggested it, and I figured it made sense to do it). I think there are a couple more places in the tree that do this, and it very much increases readability because you no longer need to check the return value explicitly every single time you do an MII access.
Quoted 5 lines
I agree with Trent, it only increases readability in the sense that you have to read less when scanning over the code. To me, that is the least important sort of readability. This sort of macro just creates hidden traps. I know it's annoying to check that return value every time, but that's why we get paid the big bucks. ;)
Well, I think I picked this up from reading kernel sources. :) And some quick grepping shows that there's plenty of places that do this (implicit argument and/or implicit return):
arch/powerpc/boot/libfdt/fdt_ro.c:
#define CHECK_HEADER(fdt) \
{ \
int err; \
if ((err = fdt_check_header(fdt)) != 0) \
return err; \
}drivers/net/e1000e/ethtool.c:
#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
do { \
if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
return 1; \
} while (0)drivers/net/wireless/ath5k/eeprom.h:
define AR5K_ASSERT_ENTRY(_e, _s) do { \
if (_e >= _s) \
return (false); \
} while (0)I'd agree that there is some potential for lossage, but I wouldn't say that the implicit return thing is all that bad. I guess I just got used to the construct.
Quoted 3 lines
If, for some reason, the community feels this is the right way to go, at *least* rename the macro to make it clear that it returns on an error, and make ds an explicit parameter.
Explicit parameter, fine with me.
How about renaming REG_{READ,WRITE} to REG_{READ,WRITE}_RETURN_ON_ERR or somesuch?