diff mbox series

[03/14] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter

Message ID 4e11dd4183da55012198824ca7b8933b1eb57e4a.1581457290.git.hns@goldelico.com
State New
Headers show
Series MIPS: Fixes and improvements for CI20 board (JZ4780) | expand

Commit Message

H. Nikolaus Schaller Feb. 11, 2020, 9:41 p.m. UTC
This is needed to give the MIPS Ingenic CI20 board a stable MAC address
which can be optionally provided by vendor U-Boot.

For get_mac_addr() we use an adapted copy of from ksz884x.c which
has very similar functionality.

Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
---
 drivers/net/ethernet/davicom/dm9000.c | 42 +++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

Comments

Andrew Lunn Feb. 11, 2020, 10:25 p.m. UTC | #1
On Tue, Feb 11, 2020 at 10:41:20PM +0100, H. Nikolaus Schaller wrote:
> This is needed to give the MIPS Ingenic CI20 board a stable MAC address
> which can be optionally provided by vendor U-Boot.
> 
> For get_mac_addr() we use an adapted copy of from ksz884x.c which
> has very similar functionality.
> 
> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>

Hi Nikolaus

Please split these patches by subsystem. So this one patch needs to go
via netdev.

> +static char *mac_addr = ":";
> +module_param(mac_addr, charp, 0);
> +MODULE_PARM_DESC(mac_addr, "MAC address");

Module parameters are not liked.

Can it be passed via device tree? The driver already has code to get
it out of the device tree.

   Andrew
Geert Uytterhoeven Feb. 12, 2020, 8:07 a.m. UTC | #2
On Tue, Feb 11, 2020 at 11:25 PM Andrew Lunn <andrew@lunn.ch> wrote:
> On Tue, Feb 11, 2020 at 10:41:20PM +0100, H. Nikolaus Schaller wrote:
> > This is needed to give the MIPS Ingenic CI20 board a stable MAC address
> > which can be optionally provided by vendor U-Boot.
> >
> > For get_mac_addr() we use an adapted copy of from ksz884x.c which
> > has very similar functionality.
> >
> > Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
>
> Hi Nikolaus
>
> Please split these patches by subsystem. So this one patch needs to go
> via netdev.
>
> > +static char *mac_addr = ":";
> > +module_param(mac_addr, charp, 0);
> > +MODULE_PARM_DESC(mac_addr, "MAC address");
>
> Module parameters are not liked.
>
> Can it be passed via device tree? The driver already has code to get
> it out of the device tree.

Yep, typically U-Boot adds an appropriate "local-mac-address" property to the
network device's device node, based on the "ethernet0" alias.

However, the real clue here may be "vendor U-Boot", i.e. no support for the
above?

Gr{oetje,eeting}s,

                        Geert
H. Nikolaus Schaller Feb. 12, 2020, 8:13 a.m. UTC | #3
> Am 12.02.2020 um 09:07 schrieb Geert Uytterhoeven <geert@linux-m68k.org>:
> 
> On Tue, Feb 11, 2020 at 11:25 PM Andrew Lunn <andrew@lunn.ch> wrote:
>> On Tue, Feb 11, 2020 at 10:41:20PM +0100, H. Nikolaus Schaller wrote:
>>> This is needed to give the MIPS Ingenic CI20 board a stable MAC address
>>> which can be optionally provided by vendor U-Boot.
>>> 
>>> For get_mac_addr() we use an adapted copy of from ksz884x.c which
>>> has very similar functionality.
>>> 
>>> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
>> 
>> Hi Nikolaus
>> 
>> Please split these patches by subsystem. So this one patch needs to go
>> via netdev.
>> 
>>> +static char *mac_addr = ":";
>>> +module_param(mac_addr, charp, 0);
>>> +MODULE_PARM_DESC(mac_addr, "MAC address");
>> 
>> Module parameters are not liked.
>> 
>> Can it be passed via device tree? The driver already has code to get
>> it out of the device tree.
> 
> Yep, typically U-Boot adds an appropriate "local-mac-address" property to the
> network device's device node, based on the "ethernet0" alias.
> 
> However, the real clue here may be "vendor U-Boot", i.e. no support for the
> above?

Yes. It is a fallback solution like it is implemented for ksz884x.c to make it
work with existing (older) U-Boot installation.

Maybe I should better clarify this in the commit message for v2 (which goes
to netdev only).

BR and thanks,
Nikolaus
diff mbox series

Patch

diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c
index 1ea3372775e6..7402030b0352 100644
--- a/drivers/net/ethernet/davicom/dm9000.c
+++ b/drivers/net/ethernet/davicom/dm9000.c
@@ -1409,6 +1409,43 @@  static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
 	return pdata;
 }
 
+static char *mac_addr = ":";
+module_param(mac_addr, charp, 0);
+MODULE_PARM_DESC(mac_addr, "MAC address");
+
+static void get_mac_addr(struct net_device *ndev, char *macaddr)
+{
+	int i = 0;
+	int j = 0;
+	int got_num = 0;
+	int num = 0;
+
+	while (j < ETH_ALEN) {
+		if (macaddr[i]) {
+			int digit;
+
+			got_num = 1;
+			digit = hex_to_bin(macaddr[i]);
+			if (digit >= 0)
+				num = num * 16 + digit;
+			else if (':' == macaddr[i])
+				got_num = 2;
+			else
+				break;
+		} else if (got_num) {
+			got_num = 2;
+		} else {
+			break;
+		}
+		if (got_num == 2) {
+			ndev->dev_addr[j++] = (u8)num;
+			num = 0;
+			got_num = 0;
+		}
+		i++;
+	}
+}
+
 /*
  * Search DM9000 board, allocate space and register it
  */
@@ -1679,6 +1716,11 @@  dm9000_probe(struct platform_device *pdev)
 			ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
 	}
 
+	if (!is_valid_ether_addr(ndev->dev_addr)) {
+		mac_src = "param";
+		get_mac_addr(ndev, mac_addr);
+	}
+
 	if (!is_valid_ether_addr(ndev->dev_addr)) {
 		inv_mac_addr = true;
 		eth_hw_addr_random(ndev);