* [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem
@ 2021-04-09 9:07 Joakim Zhang
2021-04-09 9:07 ` [PATCH net-next 1/3] dt-bindings: " Joakim Zhang
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Joakim Zhang @ 2021-04-09 9:07 UTC (permalink / raw)
To: davem, kuba, robh+dt, andrew, hkallweit1, linux, frowand.list
Cc: netdev, devicetree, linux-kernel, linux-imx
This patch set adds new properties for of_get_mac_address from nvmem.
Fugang Duan (3):
dt-bindings: net: add new properties for of_get_mac_address from nvmem
net: ethernet: add property "nvmem_macaddr_swap" to swap macaddr bytes
order
of_net: add property "nvmem-mac-address" for of_get_mac_addr()
.../bindings/net/ethernet-controller.yaml | 14 +++++++++++
drivers/of/of_net.c | 4 +++
net/ethernet/eth.c | 25 +++++++++++++++----
3 files changed, 38 insertions(+), 5 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next 1/3] dt-bindings: net: add new properties for of_get_mac_address from nvmem
2021-04-09 9:07 [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem Joakim Zhang
@ 2021-04-09 9:07 ` Joakim Zhang
2021-04-09 13:49 ` Rob Herring
2021-04-09 9:07 ` [PATCH net-next 2/3] net: ethernet: add property "nvmem_macaddr_swap" to swap macaddr bytes order Joakim Zhang
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Joakim Zhang @ 2021-04-09 9:07 UTC (permalink / raw)
To: davem, kuba, robh+dt, andrew, hkallweit1, linux, frowand.list
Cc: netdev, devicetree, linux-kernel, linux-imx
From: Fugang Duan <fugang.duan@nxp.com>
Currently, of_get_mac_address supports NVMEM, some platforms
MAC address that read from NVMEM efuse requires to swap bytes
order, so add new property "nvmem_macaddr_swap" to specify the
behavior. If the MAC address is valid from NVMEM, add new property
"nvmem-mac-address" in ethernet node.
Update these two properties in the binding documentation.
Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
.../bindings/net/ethernet-controller.yaml | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/Documentation/devicetree/bindings/net/ethernet-controller.yaml b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
index e8f04687a3e0..c868c295aabf 100644
--- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml
+++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
@@ -32,6 +32,15 @@ properties:
- minItems: 6
maxItems: 6
+ nvmem-mac-address:
+ allOf:
+ - $ref: /schemas/types.yaml#definitions/uint8-array
+ - minItems: 6
+ maxItems: 6
+ description:
+ Specifies the MAC address that was read from nvmem-cells and dynamically
+ add the property in device node;
+
max-frame-size:
$ref: /schemas/types.yaml#/definitions/uint32
description:
@@ -52,6 +61,11 @@ properties:
nvmem-cell-names:
const: mac-address
+ nvmem_macaddr_swap:
+ $ref: /schemas/types.yaml#/definitions/flag
+ description:
+ swap bytes order for the 6 bytes of MAC address
+
phy-connection-type:
description:
Specifies interface type between the Ethernet device and a physical
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next 2/3] net: ethernet: add property "nvmem_macaddr_swap" to swap macaddr bytes order
2021-04-09 9:07 [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem Joakim Zhang
2021-04-09 9:07 ` [PATCH net-next 1/3] dt-bindings: " Joakim Zhang
@ 2021-04-09 9:07 ` Joakim Zhang
2021-04-09 9:07 ` [PATCH net-next 3/3] of_net: add property "nvmem-mac-address" for of_get_mac_addr() Joakim Zhang
2021-04-09 18:43 ` [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem Jakub Kicinski
3 siblings, 0 replies; 9+ messages in thread
From: Joakim Zhang @ 2021-04-09 9:07 UTC (permalink / raw)
To: davem, kuba, robh+dt, andrew, hkallweit1, linux, frowand.list
Cc: netdev, devicetree, linux-kernel, linux-imx
From: Fugang Duan <fugang.duan@nxp.com>
ethernet controller driver call .of_get_mac_address() to get
the mac address from devictree tree, if these properties are
not present, then try to read from nvmem.
For example, read MAC address from nvmem:
of_get_mac_address()
of_get_mac_addr_nvmem()
nvmem_get_mac_address()
i.MX6x/7D/8MQ/8MM platforms ethernet MAC address read from
nvmem ocotp eFuses, but it requires to swap the six bytes
order.
The patch add optional property "nvmem_macaddr_swap" to swap
macaddr bytes order.
Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
net/ethernet/eth.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 4106373180c6..11057671a9d6 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -534,8 +534,10 @@ EXPORT_SYMBOL(eth_platform_get_mac_address);
int nvmem_get_mac_address(struct device *dev, void *addrbuf)
{
struct nvmem_cell *cell;
- const void *mac;
+ const unsigned char *mac;
+ unsigned char macaddr[ETH_ALEN];
size_t len;
+ int i = 0;
cell = nvmem_cell_get(dev, "mac-address");
if (IS_ERR(cell))
@@ -547,14 +549,27 @@ int nvmem_get_mac_address(struct device *dev, void *addrbuf)
if (IS_ERR(mac))
return PTR_ERR(mac);
- if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
- kfree(mac);
- return -EINVAL;
+ if (len != ETH_ALEN)
+ goto invalid_addr;
+
+ if (dev->of_node &&
+ of_property_read_bool(dev->of_node, "nvmem_macaddr_swap")) {
+ for (i = 0; i < ETH_ALEN; i++)
+ macaddr[i] = mac[ETH_ALEN - i - 1];
+ } else {
+ ether_addr_copy(macaddr, mac);
}
- ether_addr_copy(addrbuf, mac);
+ if (!is_valid_ether_addr(macaddr))
+ goto invalid_addr;
+
+ ether_addr_copy(addrbuf, macaddr);
kfree(mac);
return 0;
+
+invalid_addr:
+ kfree(mac);
+ return -EINVAL;
}
EXPORT_SYMBOL(nvmem_get_mac_address);
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next 3/3] of_net: add property "nvmem-mac-address" for of_get_mac_addr()
2021-04-09 9:07 [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem Joakim Zhang
2021-04-09 9:07 ` [PATCH net-next 1/3] dt-bindings: " Joakim Zhang
2021-04-09 9:07 ` [PATCH net-next 2/3] net: ethernet: add property "nvmem_macaddr_swap" to swap macaddr bytes order Joakim Zhang
@ 2021-04-09 9:07 ` Joakim Zhang
2021-04-09 18:43 ` [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem Jakub Kicinski
3 siblings, 0 replies; 9+ messages in thread
From: Joakim Zhang @ 2021-04-09 9:07 UTC (permalink / raw)
To: davem, kuba, robh+dt, andrew, hkallweit1, linux, frowand.list
Cc: netdev, devicetree, linux-kernel, linux-imx
From: Fugang Duan <fugang.duan@nxp.com>
If MAC address read from nvmem cell and it is valid mac address,
.of_get_mac_addr_nvmem() add new property "nvmem-mac-address" in
ethernet node. Once user call .of_get_mac_address() to get MAC
address again, it can read valid MAC address from device tree in
directly.
Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
drivers/of/of_net.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index 6e411821583e..20c3ae17f95f 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -116,6 +116,10 @@ const void *of_get_mac_address(struct device_node *np)
if (addr)
return addr;
+ addr = of_get_mac_addr(np, "nvmem-mac-address");
+ if (addr)
+ return addr;
+
return of_get_mac_addr_nvmem(np);
}
EXPORT_SYMBOL(of_get_mac_address);
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 1/3] dt-bindings: net: add new properties for of_get_mac_address from nvmem
2021-04-09 9:07 ` [PATCH net-next 1/3] dt-bindings: " Joakim Zhang
@ 2021-04-09 13:49 ` Rob Herring
2021-04-12 6:38 ` Joakim Zhang
0 siblings, 1 reply; 9+ messages in thread
From: Rob Herring @ 2021-04-09 13:49 UTC (permalink / raw)
To: Joakim Zhang
Cc: David Miller, Jakub Kicinski, Andrew Lunn, Heiner Kallweit,
Russell King, Frank Rowand, netdev, devicetree, linux-kernel,
NXP Linux Team
On Fri, Apr 9, 2021 at 4:07 AM Joakim Zhang <qiangqing.zhang@nxp.com> wrote:
>
> From: Fugang Duan <fugang.duan@nxp.com>
>
> Currently, of_get_mac_address supports NVMEM, some platforms
What's of_get_mac_address? This is a binding patch. Don't mix Linux
things in it.
> MAC address that read from NVMEM efuse requires to swap bytes
> order, so add new property "nvmem_macaddr_swap" to specify the
> behavior. If the MAC address is valid from NVMEM, add new property
> "nvmem-mac-address" in ethernet node.
>
> Update these two properties in the binding documentation.
>
> Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
> Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
> ---
> .../bindings/net/ethernet-controller.yaml | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/net/ethernet-controller.yaml b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
> index e8f04687a3e0..c868c295aabf 100644
> --- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml
> +++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
> @@ -32,6 +32,15 @@ properties:
> - minItems: 6
> maxItems: 6
>
> + nvmem-mac-address:
> + allOf:
> + - $ref: /schemas/types.yaml#definitions/uint8-array
> + - minItems: 6
> + maxItems: 6
> + description:
> + Specifies the MAC address that was read from nvmem-cells and dynamically
> + add the property in device node;
Why can't you use local-mac-address or mac-address? Those too can come
from some other source.
> +
> max-frame-size:
> $ref: /schemas/types.yaml#/definitions/uint32
> description:
> @@ -52,6 +61,11 @@ properties:
> nvmem-cell-names:
> const: mac-address
>
> + nvmem_macaddr_swap:
> + $ref: /schemas/types.yaml#/definitions/flag
> + description:
> + swap bytes order for the 6 bytes of MAC address
So 'nvmem-mac-address' needs to be swapped or it's swapped before
writing? In any case, this belongs in the nvmem provider.
Rob
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem
2021-04-09 9:07 [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem Joakim Zhang
` (2 preceding siblings ...)
2021-04-09 9:07 ` [PATCH net-next 3/3] of_net: add property "nvmem-mac-address" for of_get_mac_addr() Joakim Zhang
@ 2021-04-09 18:43 ` Jakub Kicinski
2021-04-12 6:41 ` Joakim Zhang
3 siblings, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2021-04-09 18:43 UTC (permalink / raw)
To: Joakim Zhang
Cc: davem, robh+dt, andrew, hkallweit1, linux, frowand.list, netdev,
devicetree, linux-kernel, linux-imx
On Fri, 9 Apr 2021 17:07:08 +0800 Joakim Zhang wrote:
> This patch set adds new properties for of_get_mac_address from nvmem.
Apart from addressing Rob's (and potentially other comments to come)
please also make sure to rebase before posting. This series doesn't
seem to apply to net-next.
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH net-next 1/3] dt-bindings: net: add new properties for of_get_mac_address from nvmem
2021-04-09 13:49 ` Rob Herring
@ 2021-04-12 6:38 ` Joakim Zhang
0 siblings, 0 replies; 9+ messages in thread
From: Joakim Zhang @ 2021-04-12 6:38 UTC (permalink / raw)
To: Rob Herring
Cc: David Miller, Jakub Kicinski, Andrew Lunn, Heiner Kallweit,
Russell King, Frank Rowand, netdev, devicetree, linux-kernel,
dl-linux-imx
Hi Rob,
> -----Original Message-----
> From: Rob Herring <robh+dt@kernel.org>
> Sent: 2021年4月9日 21:50
> To: Joakim Zhang <qiangqing.zhang@nxp.com>
> Cc: David Miller <davem@davemloft.net>; Jakub Kicinski <kuba@kernel.org>;
> Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit <hkallweit1@gmail.com>;
> Russell King <linux@armlinux.org.uk>; Frank Rowand
> <frowand.list@gmail.com>; netdev <netdev@vger.kernel.org>;
> devicetree@vger.kernel.org; linux-kernel@vger.kernel.org; dl-linux-imx
> <linux-imx@nxp.com>
> Subject: Re: [PATCH net-next 1/3] dt-bindings: net: add new properties for
> of_get_mac_address from nvmem
>
> On Fri, Apr 9, 2021 at 4:07 AM Joakim Zhang <qiangqing.zhang@nxp.com>
> wrote:
> >
> > From: Fugang Duan <fugang.duan@nxp.com>
> >
> > Currently, of_get_mac_address supports NVMEM, some platforms
>
> What's of_get_mac_address? This is a binding patch. Don't mix Linux things in
> it.
Ok, will improve it.
> > MAC address that read from NVMEM efuse requires to swap bytes order,
> > so add new property "nvmem_macaddr_swap" to specify the behavior. If
> > the MAC address is valid from NVMEM, add new property
> > "nvmem-mac-address" in ethernet node.
> >
> > Update these two properties in the binding documentation.
> >
> > Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
> > Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
> > ---
> > .../bindings/net/ethernet-controller.yaml | 14 ++++++++++++++
> > 1 file changed, 14 insertions(+)
> >
> > diff --git
> > a/Documentation/devicetree/bindings/net/ethernet-controller.yaml
> > b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
> > index e8f04687a3e0..c868c295aabf 100644
> > --- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml
> > +++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
> > @@ -32,6 +32,15 @@ properties:
> > - minItems: 6
> > maxItems: 6
> >
> > + nvmem-mac-address:
> > + allOf:
> > + - $ref: /schemas/types.yaml#definitions/uint8-array
> > + - minItems: 6
> > + maxItems: 6
> > + description:
> > + Specifies the MAC address that was read from nvmem-cells and
> dynamically
> > + add the property in device node;
>
> Why can't you use local-mac-address or mac-address? Those too can come
> from some other source.
I also don't understand what Andy's do for this, per his commit message "If the MAC address is valid from NVMEM, add new property "nvmem-mac-address" in ethernet node.".
He said this done _DYNAMICALLY_, but I have not found where ""nvmem-mac-address" property been added, and can't find it from ethernet node. So I send out patch first to see if reviewers
can give a hint, or point out this is actually incorrect.
> > +
> > max-frame-size:
> > $ref: /schemas/types.yaml#/definitions/uint32
> > description:
> > @@ -52,6 +61,11 @@ properties:
> > nvmem-cell-names:
> > const: mac-address
> >
> > + nvmem_macaddr_swap:
> > + $ref: /schemas/types.yaml#/definitions/flag
> > + description:
> > + swap bytes order for the 6 bytes of MAC address
>
> So 'nvmem-mac-address' needs to be swapped or it's swapped before writing?
> In any case, this belongs in the nvmem provider.
MAC address read from NVMEM cell needs to be swapped. The order of bytes that NVMEM provider provided is fixed, so I think we should swap at the NVMEM consumer side.
It is more reasonable and common add a property in Documentation/devicetree/bindings/nvmem/nvmem-consumer.yaml, and swap the data in nvmem_cell_read() function.
Best Regards,
Joakim Zhang
> Rob
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem
2021-04-09 18:43 ` [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem Jakub Kicinski
@ 2021-04-12 6:41 ` Joakim Zhang
0 siblings, 0 replies; 9+ messages in thread
From: Joakim Zhang @ 2021-04-12 6:41 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, robh+dt, andrew, hkallweit1, linux, frowand.list, netdev,
devicetree, linux-kernel, dl-linux-imx
Hi Jabuk,
> -----Original Message-----
> From: Jakub Kicinski <kuba@kernel.org>
> Sent: 2021年4月10日 2:44
> To: Joakim Zhang <qiangqing.zhang@nxp.com>
> Cc: davem@davemloft.net; robh+dt@kernel.org; andrew@lunn.ch;
> hkallweit1@gmail.com; linux@armlinux.org.uk; frowand.list@gmail.com;
> netdev@vger.kernel.org; devicetree@vger.kernel.org;
> linux-kernel@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH net-next 0/3] net: add new properties for
> of_get_mac_address from nvmem
>
> On Fri, 9 Apr 2021 17:07:08 +0800 Joakim Zhang wrote:
> > This patch set adds new properties for of_get_mac_address from nvmem.
>
> Apart from addressing Rob's (and potentially other comments to come) please
> also make sure to rebase before posting. This series doesn't seem to apply to
> net-next.
This patch set can be applied to latest net-next branch, the top commits as below, not sure where is the issue from, sorry.
5b489fea977c (origin/master, origin/HEAD) Merge branch 'ipa-next'
927c5043459e net: ipa: add IPA v4.11 configuration data
fbb763e7e736 net: ipa: add IPA v4.5 configuration data
Best Regards,
Joakim Zhang
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next 1/3] dt-bindings: net: add new properties for of_get_mac_address from nvmem
2021-04-09 8:37 Joakim Zhang
@ 2021-04-09 8:37 ` Joakim Zhang
0 siblings, 0 replies; 9+ messages in thread
From: Joakim Zhang @ 2021-04-09 8:37 UTC (permalink / raw)
To: davem, kuba, robh+dt, andrew, hkallweit1, linux, frowand.list
Cc: netdev, devicetree, linux-kernel
From: Fugang Duan <fugang.duan@nxp.com>
Currently, of_get_mac_address supports NVMEM, some platforms
MAC address that read from NVMEM efuse requires to swap bytes
order, so add new property "nvmem_macaddr_swap" to specify the
behavior. If the MAC address is valid from NVMEM, add new property
"nvmem-mac-address" in ethernet node.
Update these two properties in the binding documentation.
Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
.../bindings/net/ethernet-controller.yaml | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/Documentation/devicetree/bindings/net/ethernet-controller.yaml b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
index e8f04687a3e0..c868c295aabf 100644
--- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml
+++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
@@ -32,6 +32,15 @@ properties:
- minItems: 6
maxItems: 6
+ nvmem-mac-address:
+ allOf:
+ - $ref: /schemas/types.yaml#definitions/uint8-array
+ - minItems: 6
+ maxItems: 6
+ description:
+ Specifies the MAC address that was read from nvmem-cells and dynamically
+ add the property in device node;
+
max-frame-size:
$ref: /schemas/types.yaml#/definitions/uint32
description:
@@ -52,6 +61,11 @@ properties:
nvmem-cell-names:
const: mac-address
+ nvmem_macaddr_swap:
+ $ref: /schemas/types.yaml#/definitions/flag
+ description:
+ swap bytes order for the 6 bytes of MAC address
+
phy-connection-type:
description:
Specifies interface type between the Ethernet device and a physical
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-04-12 6:41 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-09 9:07 [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem Joakim Zhang
2021-04-09 9:07 ` [PATCH net-next 1/3] dt-bindings: " Joakim Zhang
2021-04-09 13:49 ` Rob Herring
2021-04-12 6:38 ` Joakim Zhang
2021-04-09 9:07 ` [PATCH net-next 2/3] net: ethernet: add property "nvmem_macaddr_swap" to swap macaddr bytes order Joakim Zhang
2021-04-09 9:07 ` [PATCH net-next 3/3] of_net: add property "nvmem-mac-address" for of_get_mac_addr() Joakim Zhang
2021-04-09 18:43 ` [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem Jakub Kicinski
2021-04-12 6:41 ` Joakim Zhang
-- strict thread matches above, loose matches on Subject: below --
2021-04-09 8:37 Joakim Zhang
2021-04-09 8:37 ` [PATCH net-next 1/3] dt-bindings: " Joakim Zhang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.