Re: [U-Boot] [PATCH v2 1/4] net: phy: Add Broadcom BCM53xx switch driver

2017-12-09 Thread Florian Fainelli


On 12/09/2017 10:40 AM, Florian Fainelli wrote:
> Add a minimalistic Broadcom BCM53xx (roboswitch) switch driver similar
> to the Marvell MV88E617x. This takes care of configuring the minimum
> amount out of the switch hardware such that each user visible port
> (configurable) and the CPU port can forward packets between each other
> while preserving isolation with other ports.
> 
> This is useful for e.g: the Lamobo R1 board featuring a Broadcom
> BCM53125 switch.
> 
> Reviewed-by: Stefan Roese 
> Signed-off-by: Florian Fainelli 
> ---

[snip]

> +static int b53_probe(struct phy_device *phydev)
> +{
> + struct b53_device *dev;
> + int ret;
> +
> + dev = malloc(sizeof(*dev));
> + if (!dev)
> + return -ENOMEM;
> +
> + memset(dev, 0, sizeof(*dev));
> +
> + phydev->priv = dev;
> + dev->bus = phydev->bus;
> + dev->cpu_port = CONFIG_B53_CPU_PORT;
> +
> + ret = b53_switch_reset(phydev);
> + if (ret < 0)
> + return ret;
> +
> + phydev->priv = dev;

Looks like I missed Joe's comment here about the redundant assignment,
let me resubmit a v3 with this corrected.
-- 
Florian
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 1/4] net: phy: Add Broadcom BCM53xx switch driver

2017-12-09 Thread Florian Fainelli
Add a minimalistic Broadcom BCM53xx (roboswitch) switch driver similar
to the Marvell MV88E617x. This takes care of configuring the minimum
amount out of the switch hardware such that each user visible port
(configurable) and the CPU port can forward packets between each other
while preserving isolation with other ports.

This is useful for e.g: the Lamobo R1 board featuring a Broadcom
BCM53125 switch.

Reviewed-by: Stefan Roese 
Signed-off-by: Florian Fainelli 
---
 drivers/net/phy/Kconfig  |  14 ++
 drivers/net/phy/Makefile |   1 +
 drivers/net/phy/b53.c| 629 +++
 drivers/net/phy/phy.c|   3 +
 include/phy.h|   1 +
 5 files changed, 648 insertions(+)
 create mode 100644 drivers/net/phy/b53.c

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index e32f1eb1c047..609305b8ebf8 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -12,6 +12,20 @@ menuconfig PHYLIB
 
 if PHYLIB
 
+config B53_SWITCH
+   bool "Broadcom BCM53xx (roboswitch) Ethernet switch PHY support."
+
+if B53_SWITCH
+
+config B53_CPU_PORT
+   int "CPU port"
+   default 8
+
+config B53_PHY_PORTS
+   hex "Bitmask of PHY ports"
+
+endif # B53_SWITCH
+
 config MV88E61XX_SWITCH
bool "Marvel MV88E61xx Ethernet switch PHY support."
 
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 1e264b2f2b03..f1980371c366 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -6,6 +6,7 @@
 #
 
 obj-$(CONFIG_BITBANGMII) += miiphybb.o
+obj-$(CONFIG_B53_SWITCH) += b53.o
 obj-$(CONFIG_MV88E61XX_SWITCH) += mv88e61xx.o
 obj-$(CONFIG_MV88E6352_SWITCH) += mv88e6352.o
 
diff --git a/drivers/net/phy/b53.c b/drivers/net/phy/b53.c
new file mode 100644
index ..fa37d051130b
--- /dev/null
+++ b/drivers/net/phy/b53.c
@@ -0,0 +1,629 @@
+/*
+ * Copyright (C) 2017
+ * Broadcom
+ * Florian Fainelli 
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+/*
+ * PHY driver for Broadcom BCM53xx (roboswitch) Ethernet switches.
+ *
+ * This driver configures the b53 for basic use as a PHY. The switch
+ * supports vendor tags and VLAN configuration that can affect the switching 
decisions.
+ * This driver uses a simple configuration in which all ports are only allowed 
to
+ * send frames to the CPU port and receive frames from the CPU port this 
providing
+ * port isolation (no cross talk).
+ *
+ * The configuration determines which PHY ports to activate using the
+ * CONFIG_B53_PHY_PORTS bitmask. Set bit N will active port N and so on.
+ *
+ * This driver was written primarily for the Lamobo R1 platform using a 
BCM53152
+ * switch but the BCM53xx being largely register compatible, extending it to 
cover
+ * other switches would be trivial.
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+/* Pseudo-PHY address (non configurable) to access internal registers */
+#define BRCM_PSEUDO_PHY_ADDR   30
+
+/* Maximum number of ports possible */
+#define B53_N_PORTS9
+
+#define B53_CTRL_PAGE  0x00 /* Control */
+#define B53_MGMT_PAGE  0x02 /* Management Mode */
+/* Port VLAN Page */
+#define B53_PVLAN_PAGE 0x31
+
+/* Control Page registers */
+#define B53_PORT_CTRL(i)   (0x00 + (i))
+#define   PORT_CTRL_RX_DISABLE BIT(0)
+#define   PORT_CTRL_TX_DISABLE BIT(1)
+#define   PORT_CTRL_RX_BCST_EN BIT(2) /* Broadcast RX (P8 only) */
+#define   PORT_CTRL_RX_MCST_EN BIT(3) /* Multicast RX (P8 only) */
+#define   PORT_CTRL_RX_UCST_EN BIT(4) /* Unicast RX (P8 only) */
+
+/* Switch Mode Control Register (8 bit) */
+#define B53_SWITCH_MODE0x0b
+#define   SM_SW_FWD_MODE   BIT(0)  /* 1 = Managed Mode */
+#define   SM_SW_FWD_EN BIT(1)  /* Forwarding Enable */
+
+/* IMP Port state override register (8 bit) */
+#define B53_PORT_OVERRIDE_CTRL 0x0e
+#define   PORT_OVERRIDE_LINK   BIT(0)
+#define   PORT_OVERRIDE_FULL_DUPLEXBIT(1) /* 0 = Half Duplex */
+#define   PORT_OVERRIDE_SPEED_S2
+#define   PORT_OVERRIDE_SPEED_10M  (0 << PORT_OVERRIDE_SPEED_S)
+#define   PORT_OVERRIDE_SPEED_100M (1 << PORT_OVERRIDE_SPEED_S)
+#define   PORT_OVERRIDE_SPEED_1000M(2 << PORT_OVERRIDE_SPEED_S)
+#define   PORT_OVERRIDE_RV_MII_25  BIT(4) /* BCM5325 only */
+#define   PORT_OVERRIDE_RX_FLOWBIT(4)
+#define   PORT_OVERRIDE_TX_FLOWBIT(5)
+#define   PORT_OVERRIDE_SPEED_2000MBIT(6) /* BCM5301X only, requires 
setting 1000M */
+#define   PORT_OVERRIDE_EN BIT(7) /* Use the register contents */
+
+#define B53_RGMII_CTRL_IMP 0x60
+#define   RGMII_CTRL_ENABLE_GMII   BIT(7)
+#define   RGMII_CTRL_TIMING_SELBIT(2)
+#define   RGMII_CTRL_DLL_RXC   BIT(1)
+#define   RGMII_CTRL_DLL_TXC   BIT(0)
+