2021-04-09 08:39:08

by Joakim Zhang

[permalink] [raw]
Subject: [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem

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


2021-04-09 08:39:46

by Joakim Zhang

[permalink] [raw]
Subject: [PATCH net-next 2/3] net: ethernet: add property "nvmem_macaddr_swap" to swap macaddr bytes order

From: Fugang Duan <[email protected]>

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 <[email protected]>
Signed-off-by: Joakim Zhang <[email protected]>
---
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

2021-04-09 08:39:56

by Joakim Zhang

[permalink] [raw]
Subject: [PATCH net-next 1/3] dt-bindings: net: add new properties for of_get_mac_address from nvmem

From: Fugang Duan <[email protected]>

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 <[email protected]>
Signed-off-by: Joakim Zhang <[email protected]>
---
.../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

2021-04-09 08:40:10

by Joakim Zhang

[permalink] [raw]
Subject: [PATCH net-next 3/3] of_net: add property "nvmem-mac-address" for of_get_mac_addr()

From: Fugang Duan <[email protected]>

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 <[email protected]>
Signed-off-by: Joakim Zhang <[email protected]>
---
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

2021-04-09 09:07:27

by Joakim Zhang

[permalink] [raw]
Subject: RE: [PATCH net-next 0/3] net: add new properties for of_get_mac_address from nvmem


Hi,

Please ignore this patch set version, I will resend it, sorry.

Best Regards,
Joakim Zhang

> -----Original Message-----
> From: Joakim Zhang <[email protected]>
> Sent: 2021??4??9?? 16:38
> To: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]
> Cc: [email protected]; [email protected];
> [email protected]
> Subject: [PATCH net-next 0/3] net: add new properties for of_get_mac_address
> from nvmem
>
> 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