* [PATCH RESEND] net: fec_mpc52xx: Read MAC address from device-tree
@ 2013-02-09 9:48 Stefan Roese
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Roese @ 2013-02-09 9:48 UTC (permalink / raw)
To: net; +Cc: linuxppc-dev, Anatolij Gustschin
Until now, the MPC5200 FEC ethernet driver relied upon the bootloader
(U-Boot) to write the MAC address into the ethernet controller
registers. The Linux driver should not rely on such a thing. So
lets read the MAC address from the DT as it should be done here.
This fixes a problem with a MPC5200 board that uses the SPL U-Boot
version without FEC initialization before Linux booting for
boot speedup.
Additionally a status line will now be printed upon successful
driver probing, also displaying this MAC address.
Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Anatolij Gustschin <agust@denx.de>
---
drivers/net/ethernet/freescale/fec_mpc52xx.c | 30 +++++++++++++++++-----------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/freescale/fec_mpc52xx.c b/drivers/net/ethernet/freescale/fec_mpc52xx.c
index 2933d08..f4c3897 100644
--- a/drivers/net/ethernet/freescale/fec_mpc52xx.c
+++ b/drivers/net/ethernet/freescale/fec_mpc52xx.c
@@ -110,15 +110,6 @@ static void mpc52xx_fec_set_paddr(struct net_device *dev, u8 *mac)
out_be32(&fec->paddr2, (*(u16 *)(&mac[4]) << 16) | FEC_PADDR2_TYPE);
}
-static void mpc52xx_fec_get_paddr(struct net_device *dev, u8 *mac)
-{
- struct mpc52xx_fec_priv *priv = netdev_priv(dev);
- struct mpc52xx_fec __iomem *fec = priv->fec;
-
- *(u32 *)(&mac[0]) = in_be32(&fec->paddr1);
- *(u16 *)(&mac[4]) = in_be32(&fec->paddr2) >> 16;
-}
-
static int mpc52xx_fec_set_mac_address(struct net_device *dev, void *addr)
{
struct sockaddr *sock = addr;
@@ -928,10 +919,22 @@ static int __devinit mpc52xx_fec_probe(struct platform_device *op)
priv->t_irq = bcom_get_task_irq(priv->tx_dmatsk);
/* MAC address init */
- if (!is_zero_ether_addr(mpc52xx_fec_mac_addr))
+ if (!is_zero_ether_addr(mpc52xx_fec_mac_addr)) {
memcpy(ndev->dev_addr, mpc52xx_fec_mac_addr, 6);
- else
- mpc52xx_fec_get_paddr(ndev, ndev->dev_addr);
+ } else {
+ struct device_node *np = op->dev.of_node;
+ const void *p;
+
+ /* Read MAC-address */
+ p = of_get_property(np, "local-mac-address", NULL);
+ if (p == NULL) {
+ dev_err(&ndev->dev, "%s: Can't find local-mac-address property\n",
+ np->full_name);
+ rv = -ENXIO;
+ goto err_irq_dispose;
+ }
+ memcpy(ndev->dev_addr, p, 6);
+ }
priv->msg_enable = netif_msg_init(debug, MPC52xx_MESSAGES_DEFAULT);
@@ -970,11 +973,14 @@ static int __devinit mpc52xx_fec_probe(struct platform_device *op)
/* We're done ! */
dev_set_drvdata(&op->dev, ndev);
+ printk(KERN_INFO "%s: %s MAC %pM\n",
+ ndev->name, op->dev.of_node->full_name, ndev->dev_addr);
return 0;
err_node:
of_node_put(priv->phy_node);
+err_irq_dispose:
irq_dispose_mapping(ndev->irq);
err_rx_tx_dmatsk:
if (priv->rx_dmatsk)
--
1.8.1.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH RESEND] net: fec_mpc52xx: Read MAC address from device-tree
@ 2013-02-09 9:49 Stefan Roese
2013-02-11 18:50 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Roese @ 2013-02-09 9:49 UTC (permalink / raw)
To: netdev; +Cc: linuxppc-dev, Anatolij Gustschin
Until now, the MPC5200 FEC ethernet driver relied upon the bootloader
(U-Boot) to write the MAC address into the ethernet controller
registers. The Linux driver should not rely on such a thing. So
lets read the MAC address from the DT as it should be done here.
This fixes a problem with a MPC5200 board that uses the SPL U-Boot
version without FEC initialization before Linux booting for
boot speedup.
Additionally a status line will now be printed upon successful
driver probing, also displaying this MAC address.
Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Anatolij Gustschin <agust@denx.de>
---
drivers/net/ethernet/freescale/fec_mpc52xx.c | 30 +++++++++++++++++-----------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/freescale/fec_mpc52xx.c b/drivers/net/ethernet/freescale/fec_mpc52xx.c
index 2933d08..f4c3897 100644
--- a/drivers/net/ethernet/freescale/fec_mpc52xx.c
+++ b/drivers/net/ethernet/freescale/fec_mpc52xx.c
@@ -110,15 +110,6 @@ static void mpc52xx_fec_set_paddr(struct net_device *dev, u8 *mac)
out_be32(&fec->paddr2, (*(u16 *)(&mac[4]) << 16) | FEC_PADDR2_TYPE);
}
-static void mpc52xx_fec_get_paddr(struct net_device *dev, u8 *mac)
-{
- struct mpc52xx_fec_priv *priv = netdev_priv(dev);
- struct mpc52xx_fec __iomem *fec = priv->fec;
-
- *(u32 *)(&mac[0]) = in_be32(&fec->paddr1);
- *(u16 *)(&mac[4]) = in_be32(&fec->paddr2) >> 16;
-}
-
static int mpc52xx_fec_set_mac_address(struct net_device *dev, void *addr)
{
struct sockaddr *sock = addr;
@@ -928,10 +919,22 @@ static int __devinit mpc52xx_fec_probe(struct platform_device *op)
priv->t_irq = bcom_get_task_irq(priv->tx_dmatsk);
/* MAC address init */
- if (!is_zero_ether_addr(mpc52xx_fec_mac_addr))
+ if (!is_zero_ether_addr(mpc52xx_fec_mac_addr)) {
memcpy(ndev->dev_addr, mpc52xx_fec_mac_addr, 6);
- else
- mpc52xx_fec_get_paddr(ndev, ndev->dev_addr);
+ } else {
+ struct device_node *np = op->dev.of_node;
+ const void *p;
+
+ /* Read MAC-address */
+ p = of_get_property(np, "local-mac-address", NULL);
+ if (p == NULL) {
+ dev_err(&ndev->dev, "%s: Can't find local-mac-address property\n",
+ np->full_name);
+ rv = -ENXIO;
+ goto err_irq_dispose;
+ }
+ memcpy(ndev->dev_addr, p, 6);
+ }
priv->msg_enable = netif_msg_init(debug, MPC52xx_MESSAGES_DEFAULT);
@@ -970,11 +973,14 @@ static int __devinit mpc52xx_fec_probe(struct platform_device *op)
/* We're done ! */
dev_set_drvdata(&op->dev, ndev);
+ printk(KERN_INFO "%s: %s MAC %pM\n",
+ ndev->name, op->dev.of_node->full_name, ndev->dev_addr);
return 0;
err_node:
of_node_put(priv->phy_node);
+err_irq_dispose:
irq_dispose_mapping(ndev->irq);
err_rx_tx_dmatsk:
if (priv->rx_dmatsk)
--
1.8.1.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND] net: fec_mpc52xx: Read MAC address from device-tree
2013-02-09 9:49 [PATCH RESEND] net: fec_mpc52xx: Read MAC address from device-tree Stefan Roese
@ 2013-02-11 18:50 ` David Miller
0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2013-02-11 18:50 UTC (permalink / raw)
To: sr; +Cc: netdev, agust, linuxppc-dev
From: Stefan Roese <sr@denx.de>
Date: Sat, 9 Feb 2013 10:49:12 +0100
> Until now, the MPC5200 FEC ethernet driver relied upon the bootloader
> (U-Boot) to write the MAC address into the ethernet controller
> registers. The Linux driver should not rely on such a thing. So
> lets read the MAC address from the DT as it should be done here.
>
> This fixes a problem with a MPC5200 board that uses the SPL U-Boot
> version without FEC initialization before Linux booting for
> boot speedup.
>
> Additionally a status line will now be printed upon successful
> driver probing, also displaying this MAC address.
>
> Signed-off-by: Stefan Roese <sr@denx.de>
I don't think this is a conservative enough change.
You have to keep the MAC register reading code around, as a backup
code path in case the OF device node lacks a MAC address, also:
> + if (!is_zero_ether_addr(mpc52xx_fec_mac_addr)) {
I really wish I would have caught this terrible module parameter
when the driver was initially submitted.
I would just get rid of this, and have a priority list of cases:
1) First, try OF node MAC address, if not present or invalid, then:
2) Read from MAC address registers, if invalid, then:
3) Log a warning message, and choose a random MAC address.
That way no matter what happens, the user will at least have a
functioning networking device.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-02-11 18:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-09 9:49 [PATCH RESEND] net: fec_mpc52xx: Read MAC address from device-tree Stefan Roese
2013-02-11 18:50 ` David Miller
-- strict thread matches above, loose matches on Subject: below --
2013-02-09 9:48 Stefan Roese
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).