Skip to contentSkip to conversation

dsa: Broadcom Starfighter 2 switch support

PATCH David Miller 3 participants 4 messages Aug 28, 2014 – Sep 10, 2014 5 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

David Miller

author maintainer
#2 lore raw
In reply to a message not in the archive

From: David Miller <[email protected]>
Date: Wed, 27 Aug 2014 18:12:29 -0700 (PDT)

Quoted 10 lines

From: Florian Fainelli <[email protected]>
Date: Wed, 27 Aug 2014 17:04:14 -0700

Quoted 5 lines

This patch series adds support for the Broadcom Starfighter 2 (Roboswitch successor) using the existing DSA infrastructure. This integrated switch is heavily used in Set Top Box, Cable gateways and DSL gateways products from Broadcom, and to a larger extent the new ARM-based Wi-Fi routers although slightly differently.

Series applied, thanks Florian.

Florian, I had to make an adjustment to make your series work.

The Tulip dmfe driver internally has static functions named phy_read() and phy_write(). I had to add a commit to rename them before your series.

Please when adjusting globally visible interfaces, do an allmodconfig build to catch these kinds of problems.

Thanks.

#3 lore raw

2014-08-27 18:30 GMT-07:00 David Miller <[email protected]>:

Quoted 12 lines

From: David Miller <[email protected]>
Date: Wed, 27 Aug 2014 18:12:29 -0700 (PDT)

Quoted 9 lines

From: Florian Fainelli <[email protected]>
Date: Wed, 27 Aug 2014 17:04:14 -0700

Quoted 5 lines

This patch series adds support for the Broadcom Starfighter 2 (Roboswitch successor) using the existing DSA infrastructure. This integrated switch is heavily used in Set Top Box, Cable gateways and DSL gateways products from Broadcom, and to a larger extent the new ARM-based Wi-Fi routers although slightly differently.

Quoted 7 lines
Quoted 1 line

Series applied, thanks Florian.

Florian, I had to make an adjustment to make your series work.

The Tulip dmfe driver internally has static functions named phy_read() and phy_write(). I had to add a commit to rename them before your series.

Ah, I should have caught that.

Quoted 3 lines

Please when adjusting globally visible interfaces, do an allmodconfig build to catch these kinds of problems.

Will do next time, thanks!

Quoted 2 lines

Thanks.

Signature · 1 line
Florian
#7 lore raw

Re: [PATCH net-next v5 11/13] net: dsa: add Broadcom SF2 switch driver

In reply to a message not in the archive
Quoted 71 lines · Florian Fainelli
Quoted 46 lines · Alexander Duyck
Quoted 36 lines · Florian Fainelli

Add support for the Broadcom Starfigther 2 switch chip using a DSA driver. This switch driver supports the following features:

- configuration of the external switch port interface: MII, RevMII, RGMII and RGMII_NO_ID are supported
- support for the per-port MIB counters
- support for link interrupts for special ports (e.g: MoCA)
- powering up/down of switch memories to conserve power when ports are unused

Finally, update the compatible property for the DSA core code to match our switch top-level compatible node.

---
Changes in v4:
- fixed typo on the word Starfighter
- fixed a few checkpatch.pl warnings

No changes in v3

Changes in v2:
- add support for reading to special MDIO phys (0 and 30)
- added more power down optimization
- added VLAN separation

 drivers/net/dsa/Kconfig        |  11 +
 drivers/net/dsa/Makefile       |   1 +
 drivers/net/dsa/bcm_sf2.c      | 626 +++++++++++++++++++++++++++++++++++++++++
 drivers/net/dsa/bcm_sf2.h      | 140 +++++++++
 drivers/net/dsa/bcm_sf2_regs.h | 227 +++++++++++++++
 net/dsa/dsa.c                  |   1 +
 6 files changed, 1006 insertions(+)
 create mode 100644 drivers/net/dsa/bcm_sf2.c
 create mode 100644 drivers/net/dsa/bcm_sf2.h
 create mode 100644 drivers/net/dsa/bcm_sf2_regs.h

[...]

Quoted 5 lines
drivers/net/dsa/bcm_sf2.c new file +0 -0
new file mode 100644
index 000000000000..bb7cb8e283b1

[...]

Quoted 11 lines

drivers/net/dsa/bcm_sf2.c

Quoted 5 lines
drivers/net/dsa/bcm_sf2.c new file +5 -0
+static char *bcm_sf2_sw_probe(struct mii_bus *bus, int sw_addr)
+{
+       return "Broadcom Starfighter 2";
+}
+

I hadn't noticed before but with this driver it seems like you could potentially load on any DSA enabled device could you not? It seems like this would be problematic since you could end up registering before another DSA driver and prevent it from being able to load since you always return success. Isn't there any test you could run to determine if the switch is actually there or not?

Unfortunately the current DSA device/driver model is kind of messed up for that, which is something I plan on fixing, although it would take a little bit more time. The way it works currently is:

- you register a DSA platform device, feed it with Device Tree or C-struct configuration data
- you register a switch driver
- the DSA platform code will eventually iterate over all switch devices, call into their probe function and based on a non-NULL return, accept to register this switch device
- the probe function only accepts MDIO connected switches, anything else has to find another way to tell that it is there

Quoted 7 lines

so all of this works okay until you have a switch which is memory-mapped into the CPU address space and which is not on the MDIO bus.

A short term solution could be to change the probe argument to be more generic and pass a void *bus pointer or something allowing us to do a tad more things, including verifying a register to see if the switch is there.

I would probably just rewrite the call to accept dsa_chip_data instead of passing it the mii_bus and sw_addr. Then you can just access data like the of_node directly. I'm also thinking it might make more sense to make the mii_bus pointer in the dsa_chip_data a bit more type agnostic by simply treating it as a parent device. It seems like most of the code is already there in dsa via the dev_find_class check that is checking for "mdio_bus".

Quoted 11 lines

The way I would like to fix this model though is to allow switch drivers to:

- specify their own configuration data, since for instance, external switches usually have a pretty fixed set of configuration options:
number of ports, fixed CPU port, while keeping platform-driven configuration data as well

- be backed by their host interface device/driver, e.g: allow a SPI, PHY, PCI(e), USB drivers to register a switch driver, such that there really is a struct device pointer we can refer to for various operations (DMA, PM...)

This is the kind of situation I am looking at. In my case I have a PCIe interface with one of the BARs providing access to switch registers. As such I would want to be able to provide a PCI device and sort out the eligibility to run the driver by checking for the PCI vendor and device ID.

Quoted 3 lines

I will cook some patches that do that in the next few days. --
Florian

I'll keep an eye open for them. I might start submitting a few patches myself as I should be pushing my driver in the next week or two.

Thanks,

Alex

#8 lore raw

Re: [PATCH net-next v5 11/13] net: dsa: add Broadcom SF2 switch driver

On 09/09/14 19:17, Alexander Duyck wrote:

[snip]

Quoted 33 lines
Quoted 25 lines
Quoted 12 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
+static char *bcm_sf2_sw_probe(struct mii_bus *bus, int sw_addr)
+{
+       return "Broadcom Starfighter 2";
+}
+

I hadn't noticed before but with this driver it seems like you could potentially load on any DSA enabled device could you not? It seems like this would be problematic since you could end up registering before another DSA driver and prevent it from being able to load since you always return success. Isn't there any test you could run to determine if the switch is actually there or not?

Unfortunately the current DSA device/driver model is kind of messed up for that, which is something I plan on fixing, although it would take a little bit more time. The way it works currently is:

- you register a DSA platform device, feed it with Device Tree or C-struct configuration data
- you register a switch driver
- the DSA platform code will eventually iterate over all switch devices, call into their probe function and based on a non-NULL return, accept to register this switch device
- the probe function only accepts MDIO connected switches, anything else has to find another way to tell that it is there

Quoted 7 lines

so all of this works okay until you have a switch which is memory-mapped into the CPU address space and which is not on the MDIO bus.

A short term solution could be to change the probe argument to be more generic and pass a void *bus pointer or something allowing us to do a tad more things, including verifying a register to see if the switch is there.

Quoted 7 lines

I would probably just rewrite the call to accept dsa_chip_data instead of passing it the mii_bus and sw_addr. Then you can just access data like the of_node directly. I'm also thinking it might make more sense to make the mii_bus pointer in the dsa_chip_data a bit more type agnostic by simply treating it as a parent device. It seems like most of the code is already there in dsa via the dev_find_class check that is checking for "mdio_bus".

Yes, I like that.

Quoted 13 lines
Quoted 8 lines

The way I would like to fix this model though is to allow switch drivers to:

- specify their own configuration data, since for instance, external switches usually have a pretty fixed set of configuration options:
number of ports, fixed CPU port, while keeping platform-driven configuration data as well

Quoted 4 lines

- be backed by their host interface device/driver, e.g: allow a SPI, PHY, PCI(e), USB drivers to register a switch driver, such that there really is a struct device pointer we can refer to for various operations (DMA, PM...)

Quoted 4 lines

This is the kind of situation I am looking at. In my case I have a PCIe interface with one of the BARs providing access to switch registers. As such I would want to be able to provide a PCI device and sort out the eligibility to run the driver by checking for the PCI vendor and device ID.

I see, bcm_sf2 is kind of similar here, thanks to Device Tree we can do a lot of things without being backed by an actual struct device, but there are other situations where this is not desirable, like yours. In my case a platform_device/driver would be more appropriate anyway.

Quoted 7 lines
Quoted 4 lines

I will cook some patches that do that in the next few days. --
Florian

I'll keep an eye open for them. I might start submitting a few patches myself as I should be pushing my driver in the next week or two.

Great! I will also keep an eye on it too, I got some patches I would like to send that add suspend/resume support, Wake-on-LAN and EEE to DSA/bcm_sf2; but we should probably get the device/driver model right first.

Those are pretty trivial patches anyway that just add some layering around the DSA and the DSA switch drivers.

NB: I have not yet addressed your suggestion of replacing tag_protocol with an enum, feel free to send that first. --
Florian