diff mbox

[(net-next.git),2/2] stmmac: fix MDIO settings

Message ID 1458121942-5537-3-git-send-email-peppe.cavallaro@st.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Giuseppe CAVALLARO March 16, 2016, 9:52 a.m. UTC
Initially the phy_bus_name was added to manipulate the
driver name but it was recently just used to manage the
fixed-link and then to take some decision at run-time.
So the patch uses the is_pseudo_fixed_link and removes
the phy_bus_name variable not necessary anymore.

The driver can manage the mdio registration by using phy-handle,
dwmac-mdio and own parameter e.g. snps,phy-addr.
This patch takes care about all these possible configurations
and fixes the mdio registration in case of there is a real
transceiver or a switch (that needs to be managed by using
fixed-link).

Signed-off-by: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Tested-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Cc: Gabriel Fernandez <gabriel.fernandez@linaro.org>
Cc: Dinh Nguyen <dinh.linux@gmail.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Phil Reid <preid@electromag.com.au>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |   16 +---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c  |   19 +----
 .../net/ethernet/stmicro/stmmac/stmmac_platform.c  |   84 +++++++++++++++----
 include/linux/stmmac.h                             |    2 +-
 4 files changed, 73 insertions(+), 48 deletions(-)

Comments

Gabriel Fernandez March 16, 2016, 11:01 a.m. UTC | #1
Hi Pepe,

i have a kernel crash

[    2.714097] Unable to handle kernel NULL pointer dereference at
virtual address 000001d6
[    2.722188] pgd = c0204000
[    2.724886] [000001d6] *pgd=00000000
[    2.728452] Internal error: Oops: 5 [#1] SMP ARM
[    2.733054] Modules linked in:
[    2.736095] CPU: 1 PID: 1 Comm: swapper/0 Not tainted
4.5.0-rc7-01768-g3407893 #36
[    2.743649] Hardware name: STiH415/416 SoC with Flattened Device Tree
[    2.750074] task: ee070000 ti: ee05e000 task.ti: ee05e000
[    2.755467] PC is at stmmac_open+0xcc/0xc40
[    2.759641] LR is at of_phy_connect+0x44/0x5c


> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 4c5ce98..943500b 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -278,7 +278,6 @@ static void stmmac_eee_ctrl_timer(unsigned long arg)
>   */
>  bool stmmac_eee_init(struct stmmac_priv *priv)
>  {
> -       char *phy_bus_name = priv->plat->phy_bus_name;
>         unsigned long flags;
>         bool ret = false;
>
> @@ -290,7 +289,7 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
>                 goto out;
>
>         /* Never init EEE in case of a switch is attached */
> -       if (phy_bus_name && (!strcmp(phy_bus_name, "fixed")))
> +       if (priv->phydev->is_pseudo_fixed_link)

priv->phydev is not yet affected
replace by if (phydev->is_pseudo_fixed_link) instead ?


Best Regard

Gabriel
Andreas Färber March 16, 2016, 11:03 a.m. UTC | #2
Am 16.03.2016 um 12:01 schrieb Gabriel Fernandez:
> Hi Pepe,
> 
> i have a kernel crash
> 
> [    2.714097] Unable to handle kernel NULL pointer dereference at
> virtual address 000001d6
> [    2.722188] pgd = c0204000
> [    2.724886] [000001d6] *pgd=00000000
> [    2.728452] Internal error: Oops: 5 [#1] SMP ARM
> [    2.733054] Modules linked in:
> [    2.736095] CPU: 1 PID: 1 Comm: swapper/0 Not tainted
> 4.5.0-rc7-01768-g3407893 #36
> [    2.743649] Hardware name: STiH415/416 SoC with Flattened Device Tree
> [    2.750074] task: ee070000 ti: ee05e000 task.ti: ee05e000
> [    2.755467] PC is at stmmac_open+0xcc/0xc40
> [    2.759641] LR is at of_phy_connect+0x44/0x5c
> 
> 
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>> index 4c5ce98..943500b 100644
>> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>> @@ -278,7 +278,6 @@ static void stmmac_eee_ctrl_timer(unsigned long arg)
>>   */
>>  bool stmmac_eee_init(struct stmmac_priv *priv)
>>  {
>> -       char *phy_bus_name = priv->plat->phy_bus_name;
>>         unsigned long flags;
>>         bool ret = false;
>>
>> @@ -290,7 +289,7 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
>>                 goto out;
>>
>>         /* Never init EEE in case of a switch is attached */
>> -       if (phy_bus_name && (!strcmp(phy_bus_name, "fixed")))
>> +       if (priv->phydev->is_pseudo_fixed_link)
> 
> priv->phydev is not yet affected
> replace by if (phydev->is_pseudo_fixed_link) instead ?

Indeed that's how I had it in my own patch before. Thanks for spotting.

Regards,
Andreas
Giuseppe CAVALLARO March 16, 2016, 12:53 p.m. UTC | #3
Hello

On 3/16/2016 12:03 PM, Andreas Färber wrote:
> Am 16.03.2016 um 12:01 schrieb Gabriel Fernandez:
>> Hi Pepe,
>>
>> i have a kernel crash
>>
>> [    2.714097] Unable to handle kernel NULL pointer dereference at
>> virtual address 000001d6
>> [    2.722188] pgd = c0204000
>> [    2.724886] [000001d6] *pgd=00000000
>> [    2.728452] Internal error: Oops: 5 [#1] SMP ARM
>> [    2.733054] Modules linked in:
>> [    2.736095] CPU: 1 PID: 1 Comm: swapper/0 Not tainted
>> 4.5.0-rc7-01768-g3407893 #36
>> [    2.743649] Hardware name: STiH415/416 SoC with Flattened Device Tree
>> [    2.750074] task: ee070000 ti: ee05e000 task.ti: ee05e000
>> [    2.755467] PC is at stmmac_open+0xcc/0xc40
>> [    2.759641] LR is at of_phy_connect+0x44/0x5c
>>
>>
>>> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>>> index 4c5ce98..943500b 100644
>>> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>>> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>>> @@ -278,7 +278,6 @@ static void stmmac_eee_ctrl_timer(unsigned long arg)
>>>    */
>>>   bool stmmac_eee_init(struct stmmac_priv *priv)
>>>   {
>>> -       char *phy_bus_name = priv->plat->phy_bus_name;
>>>          unsigned long flags;
>>>          bool ret = false;
>>>
>>> @@ -290,7 +289,7 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
>>>                  goto out;
>>>
>>>          /* Never init EEE in case of a switch is attached */
>>> -       if (phy_bus_name && (!strcmp(phy_bus_name, "fixed")))
>>> +       if (priv->phydev->is_pseudo_fixed_link)
>>
>> priv->phydev is not yet affected
>> replace by if (phydev->is_pseudo_fixed_link) instead ?
>
> Indeed that's how I had it in my own patch before. Thanks for spotting.


thanks for spotting and I have just sent the V2 of these patches
and I have understood why I did not catch it on my test :-(
my fault, sorry !

Cheers
Peppe

>
> Regards,
> Andreas
>
diff mbox

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 4c5ce98..943500b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -278,7 +278,6 @@  static void stmmac_eee_ctrl_timer(unsigned long arg)
  */
 bool stmmac_eee_init(struct stmmac_priv *priv)
 {
-	char *phy_bus_name = priv->plat->phy_bus_name;
 	unsigned long flags;
 	bool ret = false;
 
@@ -290,7 +289,7 @@  bool stmmac_eee_init(struct stmmac_priv *priv)
 		goto out;
 
 	/* Never init EEE in case of a switch is attached */
-	if (phy_bus_name && (!strcmp(phy_bus_name, "fixed")))
+	if (priv->phydev->is_pseudo_fixed_link)
 		goto out;
 
 	/* MAC core supports the EEE feature. */
@@ -827,12 +826,8 @@  static int stmmac_init_phy(struct net_device *dev)
 		phydev = of_phy_connect(dev, priv->plat->phy_node,
 					&stmmac_adjust_link, 0, interface);
 	} else {
-		if (priv->plat->phy_bus_name)
-			snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x",
-				 priv->plat->phy_bus_name, priv->plat->bus_id);
-		else
-			snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
-				 priv->plat->bus_id);
+		snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
+			 priv->plat->bus_id);
 
 		snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
 			 priv->plat->phy_addr);
@@ -871,9 +866,8 @@  static int stmmac_init_phy(struct net_device *dev)
 	}
 
 	/* If attached to a switch, there is no reason to poll phy handler */
-	if (priv->plat->phy_bus_name)
-		if (!strcmp(priv->plat->phy_bus_name, "fixed"))
-			phydev->irq = PHY_IGNORE_INTERRUPT;
+	if (priv->phydev->is_pseudo_fixed_link)
+		phydev->irq = PHY_IGNORE_INTERRUPT;
 
 	pr_debug("stmmac_init_phy:  %s: attached to PHY (UID 0x%x)"
 		 " Link = %d\n", dev->name, phydev->phy_id, phydev->link);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 0faf163..3f5512f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -198,29 +198,12 @@  int stmmac_mdio_register(struct net_device *ndev)
 	struct mii_bus *new_bus;
 	struct stmmac_priv *priv = netdev_priv(ndev);
 	struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data;
+	struct device_node *mdio_node = priv->plat->mdio_node;
 	int addr, found;
-	struct device_node *mdio_node = NULL;
-	struct device_node *child_node = NULL;
 
 	if (!mdio_bus_data)
 		return 0;
 
-	if (IS_ENABLED(CONFIG_OF)) {
-		for_each_child_of_node(priv->device->of_node, child_node) {
-			if (of_device_is_compatible(child_node,
-						    "snps,dwmac-mdio")) {
-				mdio_node = child_node;
-				break;
-			}
-		}
-
-		if (mdio_node) {
-			netdev_dbg(ndev, "FOUND MDIO subnode\n");
-		} else {
-			netdev_warn(ndev, "No MDIO subnode found\n");
-		}
-	}
-
 	new_bus = mdiobus_alloc();
 	if (new_bus == NULL)
 		return -ENOMEM;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 9cf181f..cf37ea5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -132,6 +132,69 @@  static struct stmmac_axi *stmmac_axi_setup(struct platform_device *pdev)
 }
 
 /**
+ * stmmac_dt_phy - parse device-tree driver parameters to allocate PHY resources
+ * @plat: driver data platform structure
+ * @np: device tree node
+ * @dev: device pointer
+ * Description:
+ * The mdio bus will be allocated in case of a phy transceiver is on board;
+ * it will be NULL if the fixed-link is configured.
+ * If there is the "snps,dwmac-mdio" sub-node the mdio will be allocated
+ * in any case (for DSA, mdio must be registered even if fixed-link).
+ * The table below sums the supported configurations:
+ *	-------------------------------
+ *	snps,phy-addr	|     Y
+ *	-------------------------------
+ *	phy-handle	|     Y
+ *	-------------------------------
+ *	fixed-link	|     N
+ *	-------------------------------
+ *	snps,dwmac-mdio	|
+ *	  even if	|     Y
+ *	fixed-link	|
+ *	-------------------------------
+ *
+ * It returns 0 in case of success otherwise -ENODEV.
+ */
+static int stmmac_dt_phy(struct plat_stmmacenet_data *plat,
+			 struct device_node *np, struct device *dev)
+{
+	bool mdio = true;
+
+	/* If phy-handle property is passed from DT, use it as the PHY */
+	plat->phy_node = of_parse_phandle(np, "phy-handle", 0);
+	if (plat->phy_node)
+		dev_dbg(dev, "Found phy-handle subnode\n");
+
+	/* If phy-handle is not specified, check if we have a fixed-phy */
+	if (!plat->phy_node && of_phy_is_fixed_link(np)) {
+		if ((of_phy_register_fixed_link(np) < 0))
+			return -ENODEV;
+
+		dev_dbg(dev, "Found fixed-link subnode\n");
+		plat->phy_node = of_node_get(np);
+		mdio = false;
+	}
+
+	/* If snps,dwmac-mdio is passed from DT, always register the MDIO */
+	for_each_child_of_node(np, plat->mdio_node) {
+		if (of_device_is_compatible(plat->mdio_node, "snps,dwmac-mdio"))
+			break;
+	}
+
+	if (plat->mdio_node) {
+		dev_dbg(dev, "Found MDIO subnode\n");
+		mdio = true;
+	}
+
+	if (mdio)
+		plat->mdio_bus_data =
+			devm_kzalloc(dev, sizeof(struct stmmac_mdio_bus_data),
+				     GFP_KERNEL);
+	return 0;
+}
+
+/**
  * stmmac_probe_config_dt - parse device-tree driver parameters
  * @pdev: platform_device structure
  * @plat: driver data platform structure
@@ -165,30 +228,15 @@  stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
 	/* Default to phy auto-detection */
 	plat->phy_addr = -1;
 
-	/* If we find a phy-handle property, use it as the PHY */
-	plat->phy_node = of_parse_phandle(np, "phy-handle", 0);
-
-	/* If phy-handle is not specified, check if we have a fixed-phy */
-	if (!plat->phy_node && of_phy_is_fixed_link(np)) {
-		if ((of_phy_register_fixed_link(np) < 0))
-			return ERR_PTR(-ENODEV);
-
-		plat->phy_node = of_node_get(np);
-	}
-
 	/* "snps,phy-addr" is not a standard property. Mark it as deprecated
 	 * and warn of its use. Remove this when phy node support is added.
 	 */
 	if (of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr) == 0)
 		dev_warn(&pdev->dev, "snps,phy-addr property is deprecated\n");
 
-	if ((plat->phy_node && !of_phy_is_fixed_link(np)) || plat->phy_bus_name)
-		plat->mdio_bus_data = NULL;
-	else
-		plat->mdio_bus_data =
-			devm_kzalloc(&pdev->dev,
-				     sizeof(struct stmmac_mdio_bus_data),
-				     GFP_KERNEL);
+	/* To Configure PHY by using all device-tree supported properties */
+	if (stmmac_dt_phy(plat, np, &pdev->dev))
+		return ERR_PTR(-ENODEV);
 
 	of_property_read_u32(np, "tx-fifo-depth", &plat->tx_fifo_size);
 
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 6e53fa8..e6bc30a 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -108,12 +108,12 @@  struct stmmac_axi {
 };
 
 struct plat_stmmacenet_data {
-	char *phy_bus_name;
 	int bus_id;
 	int phy_addr;
 	int interface;
 	struct stmmac_mdio_bus_data *mdio_bus_data;
 	struct device_node *phy_node;
+	struct device_node *mdio_node;
 	struct stmmac_dma_cfg *dma_cfg;
 	int clk_csr;
 	int has_gmac;