Re: [PATCH RFC 19/28] net: dsa: bcm_sf2: make it a real platform driver

2015-12-23 Thread Florian Fainelli
Hi Andrew,

Le 23/12/2015 04:56, Andrew Lunn a écrit :
> diff --git a/Documentation/devicetree/bindings/net/dsa/broadcom.txt 
> b/Documentation/devicetree/bindings/net/dsa/broadcom.txt
> new file mode 100644
> index ..bd92be0ef2c8
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/dsa/broadcom.txt
> @@ -0,0 +1,48 @@
> +* Broadcom Starfighter 2 integrated switch device
> +
> +Required properties:
> +
> +- compatible: should be "brcm,brcm-sf2"
> +- reg: addresses and length of the register sets for the device, must be 6
> +  pairs of register addresses and lengths
> +- interrupts: interrupts for the devices, must be two interrupts
> +
> +Optional properties:
> +
> +- reg-names: litteral names for the device base register addresses,
> +  when present must be: "core", "reg", "intrl2_0", "intrl2_1", "fcb",
> +  "acb"

These are in fact mandatory properties.

> +
> +- interrupt-names: litternal names for the device interrupt lines,
> +  when present must be: "switch_0" and "switch_1"

Likewise

> +
> +- brcm,num-gphy: specify the maximum number of integrated gigabit PHYs
> +  in the switch

Likewise

> +
> +- brcm,num-rgmii-ports: specify the maximum number of RGMII interfaces
> +  supported by the switch
> +
> +- brcm,fcb-pause-override: boolean property, if present indicates that
> +  the switch supports Failover Control Block pause override capability
> +
> +- brcm,acb-packets-inflight: boolean property, if present indicates
> +  that the switch Admission Control Block supports reporting the
> +  number of packets in-flight in a switch queue

All of these above are indeed optional.

Having to introduce a new binding for this driver to be converted is a
major deal breaker, the platforms I use have a frozen, yet wrongly
specified Device Tree binding, but still, we need to keep backward
compatibility with it.

My initial attempt, if you remove the part where I tried to convert
every switch driver into a PHY device handled that:

https://github.com/ffainelli/linux/commit/287fc1b33cdd6155c507a95531fd820a5c6dbaf4

Since we have dsa_of_probe(), that alone should be enough to allow us to
maintain a dsa_platform_data structure along with the old binding. This
is not a whole lot different from your patch 13.

Thanks!
-- 
Florian
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH RFC 19/28] net: dsa: bcm_sf2: make it a real platform driver

2015-12-23 Thread Andrew Lunn
From: Florian Fainelli 

The Broadcom Starfighter 2 switch driver should be a proper platform
driver, now that the DSA code has been updated to allow that, register
a switch device, feed it with the proper configuration data coming
from Device Tree and register our switch device with DSA.

The bulk of the changes consist in moving what bcm_sf2_sw_setup() did
into the component slave bind function.

Signed-off-by: Florian Fainelli 
Signed-off-by: Andrew Lunn 
---
 .../devicetree/bindings/net/dsa/broadcom.txt   |  48 
 drivers/net/dsa/bcm_sf2.c  | 248 -
 2 files changed, 192 insertions(+), 104 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/broadcom.txt

diff --git a/Documentation/devicetree/bindings/net/dsa/broadcom.txt 
b/Documentation/devicetree/bindings/net/dsa/broadcom.txt
new file mode 100644
index ..bd92be0ef2c8
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/dsa/broadcom.txt
@@ -0,0 +1,48 @@
+* Broadcom Starfighter 2 integrated switch device
+
+Required properties:
+
+- compatible: should be "brcm,brcm-sf2"
+- reg: addresses and length of the register sets for the device, must be 6
+  pairs of register addresses and lengths
+- interrupts: interrupts for the devices, must be two interrupts
+
+Optional properties:
+
+- reg-names: litteral names for the device base register addresses,
+  when present must be: "core", "reg", "intrl2_0", "intrl2_1", "fcb",
+  "acb"
+
+- interrupt-names: litternal names for the device interrupt lines,
+  when present must be: "switch_0" and "switch_1"
+
+- brcm,num-gphy: specify the maximum number of integrated gigabit PHYs
+  in the switch
+
+- brcm,num-rgmii-ports: specify the maximum number of RGMII interfaces
+  supported by the switch
+
+- brcm,fcb-pause-override: boolean property, if present indicates that
+  the switch supports Failover Control Block pause override capability
+
+- brcm,acb-packets-inflight: boolean property, if present indicates
+  that the switch Admission Control Block supports reporting the
+  number of packets in-flight in a switch queue
+
+Example:
+
+   switchdev0: switchdev0 {
+   compatible = "brcm,brcm-sf2";
+   reg = <0x0 0x4
+   0x4 0x110
+   0x40340 0x30
+   0x40380 0x30
+   0x40400 0x34
+   0x40600 0x208>;
+   interrupts = <0 0x18 0
+   0 0x19 0>;
+   brcm,num-gphy = <1>;
+   brcm,num-rgmii-ports = <2>;
+   brcm,fcb-pause-override;
+   brcm,acb-packets-inflight;
+   };
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index a0222ebd31c6..4f95e03b8c64 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -9,6 +9,7 @@
  * (at your option) any later version.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -928,81 +929,8 @@ static void bcm_sf2_identify_ports(struct bcm_sf2_priv 
*priv,
 
 static int bcm_sf2_sw_setup(struct dsa_switch *ds, struct device *dev)
 {
-   const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME;
-   struct bcm_sf2_priv *priv;
-   struct device_node *dn;
-   void __iomem **base;
+   struct bcm_sf2_priv *priv = ds_to_priv(ds);
unsigned int port;
-   unsigned int i;
-   u32 reg, rev;
-   int ret;
-
-   priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-   if (!priv)
-   return -ENOMEM;
-
-   spin_lock_init(>indir_lock);
-   mutex_init(>stats_mutex);
-
-   /* All the interesting properties are at the parent device_node
-* level
-*/
-   dn = ds->pd->of_node->parent;
-   bcm_sf2_identify_ports(priv, ds->pd->of_node);
-
-   priv->irq0 = irq_of_parse_and_map(dn, 0);
-   priv->irq1 = irq_of_parse_and_map(dn, 1);
-
-   base = >core;
-   for (i = 0; i < BCM_SF2_REGS_NUM; i++) {
-   *base = of_iomap(dn, i);
-   if (*base == NULL) {
-   pr_err("unable to find register: %s\n", reg_names[i]);
-   ret = -ENOMEM;
-   goto out_unmap;
-   }
-   base++;
-   }
-
-   ret = bcm_sf2_sw_rst(priv);
-   if (ret) {
-   pr_err("unable to software reset switch: %d\n", ret);
-   goto out_unmap;
-   }
-
-   /* Disable all interrupts and request them */
-   bcm_sf2_intr_disable(priv);
-
-   ret = request_irq(priv->irq0, bcm_sf2_switch_0_isr, 0,
- "switch_0", priv);
-   if (ret < 0) {
-   pr_err("failed to request switch_0 IRQ\n");
-   goto out_unmap;
-   }
-
-   ret = request_irq(priv->irq1, bcm_sf2_switch_1_isr, 0,
- "switch_1", priv);
-   if (ret < 0) {
-