netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter
@ 2020-02-14 16:07 H. Nikolaus Schaller
  2020-02-14 16:32 ` Andrew Lunn
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: H. Nikolaus Schaller @ 2020-02-14 16:07 UTC (permalink / raw)
  To: Andrew Lunn, Paul Cercueil, David S. Miller, Petr Štetiar,
	Richard Fontana, Thomas Gleixner, Heiner Kallweit
  Cc: netdev, linux-kernel, letux-kernel, kernel, H. Nikolaus Schaller

The MIPS Ingenic CI20 board is shipped with a quite old u-boot
(ci20-v2013.10 see https://elinux.org/CI20_Dev_Zone). This passes
the MAC address through dm9000.mac_addr=xx:xx:xx:xx:xx:xx
kernel module parameter to give the board a fixed MAC address.

This is not processed by the dm9000 driver which assigns a random
MAC address on each boot, making DHCP assign a new IP address
each time.

So we add a check for the mac_addr module parameter as a last
resort before assigning a random one. This mechanism can also
be used outside of u-boot to provide a value through modprobe
config.

To parse the MAC address in a new function get_mac_addr() we
use an copy adapted from the ksz884x.c driver which provides
the same functionality.

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

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);
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter
  2020-02-14 16:07 [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter H. Nikolaus Schaller
@ 2020-02-14 16:32 ` Andrew Lunn
  2020-02-14 17:51 ` David Miller
  2020-02-14 18:47 ` Paul Cercueil
  2 siblings, 0 replies; 9+ messages in thread
From: Andrew Lunn @ 2020-02-14 16:32 UTC (permalink / raw)
  To: H. Nikolaus Schaller
  Cc: Paul Cercueil, David S. Miller, Petr Štetiar,
	Richard Fontana, Thomas Gleixner, Heiner Kallweit, netdev,
	linux-kernel, letux-kernel, kernel

On Fri, Feb 14, 2020 at 05:07:35PM +0100, H. Nikolaus Schaller wrote:
> The MIPS Ingenic CI20 board is shipped with a quite old u-boot
> (ci20-v2013.10 see https://elinux.org/CI20_Dev_Zone). This passes
> the MAC address through dm9000.mac_addr=xx:xx:xx:xx:xx:xx
> kernel module parameter to give the board a fixed MAC address.

I think this will get ACKed.

There is a well defined way to pass the MAC address via DT. The driver
supports that already.

uboot for this board appears to be open:

https://github.com/MIPS/CI20_u-boot

and it is documented to how build it.

So there is no reason why it cannot be made to support the standard
mechanism.

	Andrew

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter
  2020-02-14 16:07 [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter H. Nikolaus Schaller
  2020-02-14 16:32 ` Andrew Lunn
@ 2020-02-14 17:51 ` David Miller
  2020-02-14 18:47 ` Paul Cercueil
  2 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2020-02-14 17:51 UTC (permalink / raw)
  To: hns
  Cc: andrew, paul, ynezz, rfontana, tglx, hkallweit1, netdev,
	linux-kernel, letux-kernel, kernel

From: "H. Nikolaus Schaller" <hns@goldelico.com>
Date: Fri, 14 Feb 2020 17:07:35 +0100

> The MIPS Ingenic CI20 board is shipped with a quite old u-boot
> (ci20-v2013.10 see https://elinux.org/CI20_Dev_Zone). This passes
> the MAC address through dm9000.mac_addr=xx:xx:xx:xx:xx:xx
> kernel module parameter to give the board a fixed MAC address.
> 
> This is not processed by the dm9000 driver which assigns a random
> MAC address on each boot, making DHCP assign a new IP address
> each time.
> 
> So we add a check for the mac_addr module parameter as a last
> resort before assigning a random one. This mechanism can also
> be used outside of u-boot to provide a value through modprobe
> config.
> 
> To parse the MAC address in a new function get_mac_addr() we
> use an copy adapted from the ksz884x.c driver which provides
> the same functionality.
> 
> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>

Sorry, this is not appropriate.  Module parameters in networking
drivers never are.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter
  2020-02-14 16:07 [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter H. Nikolaus Schaller
  2020-02-14 16:32 ` Andrew Lunn
  2020-02-14 17:51 ` David Miller
@ 2020-02-14 18:47 ` Paul Cercueil
  2020-02-14 19:24   ` H. Nikolaus Schaller
  2 siblings, 1 reply; 9+ messages in thread
From: Paul Cercueil @ 2020-02-14 18:47 UTC (permalink / raw)
  To: H. Nikolaus Schaller
  Cc: Andrew Lunn, David S. Miller, Petr Štetiar, Richard Fontana,
	Thomas Gleixner, Heiner Kallweit, netdev, linux-kernel,
	letux-kernel, kernel

Hi Nikolaus,

What I'd suggest is to write a NVMEM driver for the efuse and retrieve 
the MAC address cleanly with nvmem_get_mac_address().

It shouldn't be hard to do (there's already code for it in the 
non-upstream 3.18 kernel for the CI20) and you remove the dependency on 
uboot.

-Paul


Le ven., févr. 14, 2020 at 17:07, H. Nikolaus Schaller 
<hns@goldelico.com> a écrit :
> The MIPS Ingenic CI20 board is shipped with a quite old u-boot
> (ci20-v2013.10 see https://elinux.org/CI20_Dev_Zone). This passes
> the MAC address through dm9000.mac_addr=xx:xx:xx:xx:xx:xx
> kernel module parameter to give the board a fixed MAC address.
> 
> This is not processed by the dm9000 driver which assigns a random
> MAC address on each boot, making DHCP assign a new IP address
> each time.
> 
> So we add a check for the mac_addr module parameter as a last
> resort before assigning a random one. This mechanism can also
> be used outside of u-boot to provide a value through modprobe
> config.
> 
> To parse the MAC address in a new function get_mac_addr() we
> use an copy adapted from the ksz884x.c driver which provides
> the same functionality.
> 
> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
> ---
>  drivers/net/ethernet/davicom/dm9000.c | 42 
> +++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
> 
> 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);
> --
> 2.23.0
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter
  2020-02-14 18:47 ` Paul Cercueil
@ 2020-02-14 19:24   ` H. Nikolaus Schaller
  2020-02-14 19:38     ` [Letux-kernel] " H. Nikolaus Schaller
  0 siblings, 1 reply; 9+ messages in thread
From: H. Nikolaus Schaller @ 2020-02-14 19:24 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Andrew Lunn, David S. Miller, Petr Štetiar, Richard Fontana,
	Thomas Gleixner, Heiner Kallweit, netdev, linux-kernel,
	letux-kernel, kernel


> Am 14.02.2020 um 19:47 schrieb Paul Cercueil <paul@crapouillou.net>:
> 
> Hi Nikolaus,
> 
> What I'd suggest is to write a NVMEM driver for the efuse and retrieve the MAC address cleanly with nvmem_get_mac_address().
> 
> It shouldn't be hard to do (there's already code for it in the non-upstream 3.18 kernel for the CI20) and you remove the dependency on uboot.

Interesting approach. I have found this:

https://lore.kernel.org/patchwork/patch/868158/

but it looks as if it was never finished (I could not locate a V3 or anything mainline?)
and and it tries to solve other problems as well.

And it looks to be much more complex than my "solution" to the immediate problem.

I have to study it to know if I can write a nvmem_get_mac_address().

BR,
Nikolaus

> 
> -Paul
> 
> 
> Le ven., févr. 14, 2020 at 17:07, H. Nikolaus Schaller <hns@goldelico.com> a écrit :
>> The MIPS Ingenic CI20 board is shipped with a quite old u-boot
>> (ci20-v2013.10 see https://elinux.org/CI20_Dev_Zone). This passes
>> the MAC address through dm9000.mac_addr=xx:xx:xx:xx:xx:xx
>> kernel module parameter to give the board a fixed MAC address.
>> This is not processed by the dm9000 driver which assigns a random
>> MAC address on each boot, making DHCP assign a new IP address
>> each time.
>> So we add a check for the mac_addr module parameter as a last
>> resort before assigning a random one. This mechanism can also
>> be used outside of u-boot to provide a value through modprobe
>> config.
>> To parse the MAC address in a new function get_mac_addr() we
>> use an copy adapted from the ksz884x.c driver which provides
>> the same functionality.
>> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
>> ---
>> drivers/net/ethernet/davicom/dm9000.c | 42 +++++++++++++++++++++++++++
>> 1 file changed, 42 insertions(+)
>> 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);
>> --
>> 2.23.0
> 
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Letux-kernel] [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter
  2020-02-14 19:24   ` H. Nikolaus Schaller
@ 2020-02-14 19:38     ` H. Nikolaus Schaller
  2020-02-14 19:57       ` Paul Cercueil
  2020-02-14 20:05       ` H. Nikolaus Schaller
  0 siblings, 2 replies; 9+ messages in thread
From: H. Nikolaus Schaller @ 2020-02-14 19:38 UTC (permalink / raw)
  To: Discussions about the Letux Kernel
  Cc: Paul Cercueil, Andrew Lunn, netdev, linux-kernel,
	David S. Miller, Richard Fontana, kernel, Petr Štetiar,
	Thomas Gleixner, Heiner Kallweit


> Am 14.02.2020 um 20:24 schrieb H. Nikolaus Schaller <hns@goldelico.com>:
> 
> 
>> Am 14.02.2020 um 19:47 schrieb Paul Cercueil <paul@crapouillou.net>:
>> 
>> Hi Nikolaus,
>> 
>> What I'd suggest is to write a NVMEM driver for the efuse and retrieve the MAC address cleanly with nvmem_get_mac_address().
>> 
>> It shouldn't be hard to do (there's already code for it in the non-upstream 3.18 kernel for the CI20) and you remove the dependency on uboot.
> 
> Interesting approach. I have found this:
> 
> https://lore.kernel.org/patchwork/patch/868158/
> 
> but it looks as if it was never finished (I could not locate a V3 or anything mainline?)
> and and it tries to solve other problems as well.
> 
> And it looks to be much more complex than my "solution" to the immediate problem.
> 
> I have to study it to know if I can write a nvmem_get_mac_address().

Another question is how to link this very jz4780 specific code to the generic davicom dm9000 driver?
And where should the new code live. In some jz4780 specific file or elsewhere?

> 
> BR,
> Nikolaus
> 
>> 
>> -Paul
>> 
>> 
>> Le ven., févr. 14, 2020 at 17:07, H. Nikolaus Schaller <hns@goldelico.com> a écrit :
>>> The MIPS Ingenic CI20 board is shipped with a quite old u-boot
>>> (ci20-v2013.10 see https://elinux.org/CI20_Dev_Zone). This passes
>>> the MAC address through dm9000.mac_addr=xx:xx:xx:xx:xx:xx
>>> kernel module parameter to give the board a fixed MAC address.
>>> This is not processed by the dm9000 driver which assigns a random
>>> MAC address on each boot, making DHCP assign a new IP address
>>> each time.
>>> So we add a check for the mac_addr module parameter as a last
>>> resort before assigning a random one. This mechanism can also
>>> be used outside of u-boot to provide a value through modprobe
>>> config.
>>> To parse the MAC address in a new function get_mac_addr() we
>>> use an copy adapted from the ksz884x.c driver which provides
>>> the same functionality.
>>> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
>>> ---
>>> drivers/net/ethernet/davicom/dm9000.c | 42 +++++++++++++++++++++++++++
>>> 1 file changed, 42 insertions(+)
>>> 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);
>>> --
>>> 2.23.0
>> 
>> 
> 
> _______________________________________________
> http://projects.goldelico.com/p/gta04-kernel/
> Letux-kernel mailing list
> Letux-kernel@openphoenux.org
> http://lists.goldelico.com/mailman/listinfo.cgi/letux-kernel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Letux-kernel] [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter
  2020-02-14 19:38     ` [Letux-kernel] " H. Nikolaus Schaller
@ 2020-02-14 19:57       ` Paul Cercueil
  2020-02-14 20:05       ` H. Nikolaus Schaller
  1 sibling, 0 replies; 9+ messages in thread
From: Paul Cercueil @ 2020-02-14 19:57 UTC (permalink / raw)
  To: H. Nikolaus Schaller
  Cc: Discussions about the Letux Kernel, Andrew Lunn, netdev,
	linux-kernel, David S. Miller, Richard Fontana, kernel,
	Petr Štetiar, Thomas Gleixner, Heiner Kallweit



Le ven., févr. 14, 2020 at 20:38, H. Nikolaus Schaller 
<hns@goldelico.com> a écrit :
>>  Am 14.02.2020 um 20:24 schrieb H. Nikolaus Schaller 
>> <hns@goldelico.com>:
>> 
>> 
>>>  Am 14.02.2020 um 19:47 schrieb Paul Cercueil 
>>> <paul@crapouillou.net>:
>>> 
>>>  Hi Nikolaus,
>>> 
>>>  What I'd suggest is to write a NVMEM driver for the efuse and 
>>> retrieve the MAC address cleanly with nvmem_get_mac_address().
>>> 
>>>  It shouldn't be hard to do (there's already code for it in the 
>>> non-upstream 3.18 kernel for the CI20) and you remove the 
>>> dependency on uboot.
>> 
>>  Interesting approach. I have found this:
>> 
>>  https://lore.kernel.org/patchwork/patch/868158/
>> 
>>  but it looks as if it was never finished (I could not locate a V3 
>> or anything mainline?)
>>  and and it tries to solve other problems as well.
>> 

Yes, I think it's a bit too complex - it's probably fine to just read 
chunks of 4 bytes.

>> 
>>  And it looks to be much more complex than my "solution" to the 
>> immediate problem.
>> 

Yes, a proper fix usually means more work ;)
>> 
>>  I have to study it to know if I can write a nvmem_get_mac_address().
> 
> Another question is how to link this very jz4780 specific code to the 
> generic davicom dm9000 driver?
> And where should the new code live. In some jz4780 specific file or 
> elsewhere?

In the dm9000's devicetree node you'd have a "mac-address = 
<&mac_addr>;". The "mac-address" is already a standard property, and 
the davicom driver already supports it.

The "mac_addr" should be a pointer to the efuse cell that corresponds 
to the MAC address. See the examples at the bottom of 
Documentation/devicetree/bindings/nvmem/nvmem.yaml and 
Documentation/devicetree/bindings/nvmem/nvmem-consumer.yaml.

-Paul

> 
>> 
>>  BR,
>>  Nikolaus
>> 
>>> 
>>>  -Paul
>>> 
>>> 
>>>  Le ven., févr. 14, 2020 at 17:07, H. Nikolaus Schaller 
>>> <hns@goldelico.com> a écrit :
>>>>  The MIPS Ingenic CI20 board is shipped with a quite old u-boot
>>>>  (ci20-v2013.10 see https://elinux.org/CI20_Dev_Zone). This passes
>>>>  the MAC address through dm9000.mac_addr=xx:xx:xx:xx:xx:xx
>>>>  kernel module parameter to give the board a fixed MAC address.
>>>>  This is not processed by the dm9000 driver which assigns a random
>>>>  MAC address on each boot, making DHCP assign a new IP address
>>>>  each time.
>>>>  So we add a check for the mac_addr module parameter as a last
>>>>  resort before assigning a random one. This mechanism can also
>>>>  be used outside of u-boot to provide a value through modprobe
>>>>  config.
>>>>  To parse the MAC address in a new function get_mac_addr() we
>>>>  use an copy adapted from the ksz884x.c driver which provides
>>>>  the same functionality.
>>>>  Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
>>>>  ---
>>>>  drivers/net/ethernet/davicom/dm9000.c | 42 
>>>> +++++++++++++++++++++++++++
>>>>  1 file changed, 42 insertions(+)
>>>>  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);
>>>>  --
>>>>  2.23.0
>>> 
>>> 
>> 
>>  _______________________________________________
>>  http://projects.goldelico.com/p/gta04-kernel/
>>  Letux-kernel mailing list
>>  Letux-kernel@openphoenux.org
>>  http://lists.goldelico.com/mailman/listinfo.cgi/letux-kernel



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Letux-kernel] [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter
  2020-02-14 19:38     ` [Letux-kernel] " H. Nikolaus Schaller
  2020-02-14 19:57       ` Paul Cercueil
@ 2020-02-14 20:05       ` H. Nikolaus Schaller
  2020-02-14 20:17         ` Paul Cercueil
  1 sibling, 1 reply; 9+ messages in thread
From: H. Nikolaus Schaller @ 2020-02-14 20:05 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Andrew Lunn, netdev, Linux Kernel Mailing List, Richard Fontana,
	Thomas Gleixner, kernel, Petr Štetiar, David S. Miller,
	Heiner Kallweit, Discussions about the Letux Kernel


> Am 14.02.2020 um 20:38 schrieb H. Nikolaus Schaller <hns@goldelico.com>:
> 
> 
>> Am 14.02.2020 um 20:24 schrieb H. Nikolaus Schaller <hns@goldelico.com>:
>> 
>> 
>>> Am 14.02.2020 um 19:47 schrieb Paul Cercueil <paul@crapouillou.net>:
>>> 
>>> Hi Nikolaus,
>>> 
>>> What I'd suggest is to write a NVMEM driver for the efuse and retrieve the MAC address cleanly with nvmem_get_mac_address().
>>> 
>>> It shouldn't be hard to do (there's already code for it in the non-upstream 3.18 kernel for the CI20) and you remove the dependency on uboot.
>> 
>> Interesting approach. I have found this:
>> 
>> https://lore.kernel.org/patchwork/patch/868158/
>> 
>> but it looks as if it was never finished (I could not locate a V3 or anything mainline?)
>> and and it tries to solve other problems as well.
>> 
>> And it looks to be much more complex than my "solution" to the immediate problem.
>> 
>> I have to study it to know if I can write a nvmem_get_mac_address().
> 
> Another question is how to link this very jz4780 specific code to the generic davicom dm9000 driver?
> And where should the new code live. In some jz4780 specific file or elsewhere?

Ok, got it.

nvmem_get_mac_address() is looking for a nvmem cell "mac-address".

So some jz4780 specific driver must provide such cells.

There aren't many examples but it appears as if arch/arm/mach-davinci/board-da830-evm.c
defines and registers nvmem cells.

But maybe it is not difficult to teach the 2018 driver to provide such cells.

BR and thanks,
Nikolaus


> 
>> 
>> BR,
>> Nikolaus
>> 
>>> 
>>> -Paul
>>> 
>>> 
>>> Le ven., févr. 14, 2020 at 17:07, H. Nikolaus Schaller <hns@goldelico.com> a écrit :
>>>> The MIPS Ingenic CI20 board is shipped with a quite old u-boot
>>>> (ci20-v2013.10 see https://elinux.org/CI20_Dev_Zone). This passes
>>>> the MAC address through dm9000.mac_addr=xx:xx:xx:xx:xx:xx
>>>> kernel module parameter to give the board a fixed MAC address.
>>>> This is not processed by the dm9000 driver which assigns a random
>>>> MAC address on each boot, making DHCP assign a new IP address
>>>> each time.
>>>> So we add a check for the mac_addr module parameter as a last
>>>> resort before assigning a random one. This mechanism can also
>>>> be used outside of u-boot to provide a value through modprobe
>>>> config.
>>>> To parse the MAC address in a new function get_mac_addr() we
>>>> use an copy adapted from the ksz884x.c driver which provides
>>>> the same functionality.
>>>> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
>>>> ---
>>>> drivers/net/ethernet/davicom/dm9000.c | 42 +++++++++++++++++++++++++++
>>>> 1 file changed, 42 insertions(+)
>>>> 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);
>>>> --
>>>> 2.23.0
>>> 
>>> 
>> 
>> _______________________________________________
>> http://projects.goldelico.com/p/gta04-kernel/
>> Letux-kernel mailing list
>> Letux-kernel@openphoenux.org
>> http://lists.goldelico.com/mailman/listinfo.cgi/letux-kernel
> 
> _______________________________________________
> http://projects.goldelico.com/p/gta04-kernel/
> Letux-kernel mailing list
> Letux-kernel@openphoenux.org
> http://lists.goldelico.com/mailman/listinfo.cgi/letux-kernel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Letux-kernel] [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter
  2020-02-14 20:05       ` H. Nikolaus Schaller
@ 2020-02-14 20:17         ` Paul Cercueil
  0 siblings, 0 replies; 9+ messages in thread
From: Paul Cercueil @ 2020-02-14 20:17 UTC (permalink / raw)
  To: H. Nikolaus Schaller
  Cc: Andrew Lunn, netdev, Linux Kernel Mailing List, Richard Fontana,
	Thomas Gleixner, kernel, Petr Štetiar, David S. Miller,
	Heiner Kallweit, Discussions about the Letux Kernel



Le ven., févr. 14, 2020 at 21:05, H. Nikolaus Schaller 
<hns@goldelico.com> a écrit :
> 
>>  Am 14.02.2020 um 20:38 schrieb H. Nikolaus Schaller 
>> <hns@goldelico.com>:
>> 
>> 
>>>  Am 14.02.2020 um 20:24 schrieb H. Nikolaus Schaller 
>>> <hns@goldelico.com>:
>>> 
>>> 
>>>>  Am 14.02.2020 um 19:47 schrieb Paul Cercueil 
>>>> <paul@crapouillou.net>:
>>>> 
>>>>  Hi Nikolaus,
>>>> 
>>>>  What I'd suggest is to write a NVMEM driver for the efuse and 
>>>> retrieve the MAC address cleanly with nvmem_get_mac_address().
>>>> 
>>>>  It shouldn't be hard to do (there's already code for it in the 
>>>> non-upstream 3.18 kernel for the CI20) and you remove the 
>>>> dependency on uboot.
>>> 
>>>  Interesting approach. I have found this:
>>> 
>>>  https://lore.kernel.org/patchwork/patch/868158/
>>> 
>>>  but it looks as if it was never finished (I could not locate a V3 
>>> or anything mainline?)
>>>  and and it tries to solve other problems as well.
>>> 
>>>  And it looks to be much more complex than my "solution" to the 
>>> immediate problem.
>>> 
>>>  I have to study it to know if I can write a 
>>> nvmem_get_mac_address().
>> 
>>  Another question is how to link this very jz4780 specific code to 
>> the generic davicom dm9000 driver?
>>  And where should the new code live. In some jz4780 specific file or 
>> elsewhere?
> 
> Ok, got it.
> 
> nvmem_get_mac_address() is looking for a nvmem cell "mac-address".
> 
> So some jz4780 specific driver must provide such cells.

No, the jz4780 specific driver should just provide the functionality.

The cells are provided in devicetree, just like in the two 
documentation files I listed before.

-Paul

> 
> There aren't many examples but it appears as if 
> arch/arm/mach-davinci/board-da830-evm.c
> defines and registers nvmem cells.
> 
> But maybe it is not difficult to teach the 2018 driver to provide 
> such cells.
> 
> BR and thanks,
> Nikolaus
> 
> 
>> 
>>> 
>>>  BR,
>>>  Nikolaus
>>> 
>>>> 
>>>>  -Paul
>>>> 
>>>> 
>>>>  Le ven., févr. 14, 2020 at 17:07, H. Nikolaus Schaller 
>>>> <hns@goldelico.com> a écrit :
>>>>>  The MIPS Ingenic CI20 board is shipped with a quite old u-boot
>>>>>  (ci20-v2013.10 see https://elinux.org/CI20_Dev_Zone). This passes
>>>>>  the MAC address through dm9000.mac_addr=xx:xx:xx:xx:xx:xx
>>>>>  kernel module parameter to give the board a fixed MAC address.
>>>>>  This is not processed by the dm9000 driver which assigns a random
>>>>>  MAC address on each boot, making DHCP assign a new IP address
>>>>>  each time.
>>>>>  So we add a check for the mac_addr module parameter as a last
>>>>>  resort before assigning a random one. This mechanism can also
>>>>>  be used outside of u-boot to provide a value through modprobe
>>>>>  config.
>>>>>  To parse the MAC address in a new function get_mac_addr() we
>>>>>  use an copy adapted from the ksz884x.c driver which provides
>>>>>  the same functionality.
>>>>>  Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
>>>>>  ---
>>>>>  drivers/net/ethernet/davicom/dm9000.c | 42 
>>>>> +++++++++++++++++++++++++++
>>>>>  1 file changed, 42 insertions(+)
>>>>>  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);
>>>>>  --
>>>>>  2.23.0
>>>> 
>>>> 
>>> 
>>>  _______________________________________________
>>>  http://projects.goldelico.com/p/gta04-kernel/
>>>  Letux-kernel mailing list
>>>  Letux-kernel@openphoenux.org
>>>  http://lists.goldelico.com/mailman/listinfo.cgi/letux-kernel
>> 
>>  _______________________________________________
>>  http://projects.goldelico.com/p/gta04-kernel/
>>  Letux-kernel mailing list
>>  Letux-kernel@openphoenux.org
>>  http://lists.goldelico.com/mailman/listinfo.cgi/letux-kernel
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-02-14 20:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-14 16:07 [PATCH v2] net: davicom: dm9000: allow to pass MAC address through mac_addr module parameter H. Nikolaus Schaller
2020-02-14 16:32 ` Andrew Lunn
2020-02-14 17:51 ` David Miller
2020-02-14 18:47 ` Paul Cercueil
2020-02-14 19:24   ` H. Nikolaus Schaller
2020-02-14 19:38     ` [Letux-kernel] " H. Nikolaus Schaller
2020-02-14 19:57       ` Paul Cercueil
2020-02-14 20:05       ` H. Nikolaus Schaller
2020-02-14 20:17         ` Paul Cercueil

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).