2023-07-28 03:02:44

by Daniel Golle

[permalink] [raw]
Subject: [PATCH v2 1/2] dt-bindings: mt76: support setting per-band MAC address

Introduce support for setting individual per-band MAC addresses using
NVMEM cells by adding a 'bands' object with enumerated child nodes
representing the 2.4 GHz, 5 GHz and 6 GHz bands.

In case it is defined, call of_get_mac_address for the per-band child
node, otherwise try with of_get_mac_address on the main device node and
fall back to a random address like it used to be.

While at it, add MAC address related properties also for the main node
and update example to use EEPROM via nvmem-cells instead of deprecated
mediatek,mtd-eeprom property.

Signed-off-by: Daniel Golle <[email protected]>
---
.../bindings/net/wireless/mediatek,mt76.yaml | 59 ++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.yaml b/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.yaml
index 252207adbc54c..2474f4f7e34b0 100644
--- a/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.yaml
+++ b/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.yaml
@@ -37,6 +37,12 @@ properties:
description:
MT7986 should contain 3 regions consys, dcm, and sku, in this order.

+ '#address-cells':
+ const: 1
+
+ '#size-cells':
+ const: 0
+
interrupts:
maxItems: 1

@@ -72,13 +78,23 @@ properties:

ieee80211-freq-limit: true

+ address: true
+
+ local-mac-address: true
+
+ mac-address: true
+
nvmem-cells:
+ minItems: 1
items:
- description: NVMEM cell with EEPROM
+ - description: NVMEM cell with the MAC address

nvmem-cell-names:
+ minItems: 1
items:
- const: eeprom
+ - const: mac-address

mediatek,eeprom-data:
$ref: /schemas/types.yaml#/definitions/uint32-array
@@ -213,6 +229,30 @@ properties:
description:
Half-dBm power delta for different numbers of antennas

+patternProperties:
+ '^band@[0-2]+$':
+ type: object
+ additionalProperties: false
+ properties:
+ reg:
+ maxItems: 1
+
+ address: true
+ local-mac-address: true
+ mac-address: true
+
+ nvmem-cells:
+ description: NVMEM cell with the MAC address
+
+ nvmem-cell-names:
+ items:
+ - const: mac-address
+
+ required:
+ - reg
+
+ unevaluatedProperties: false
+
required:
- compatible
- reg
@@ -225,10 +265,13 @@ examples:
#address-cells = <3>;
#size-cells = <2>;
wifi@0,0 {
+ #address-cells = <1>;
+ #size-cells = <0>;
compatible = "mediatek,mt76";
reg = <0x0000 0 0 0 0>;
ieee80211-freq-limit = <5000000 6000000>;
- mediatek,mtd-eeprom = <&factory 0x8000>;
+ nvmem-cells = <&factory_eeprom>;
+ nvmem-cell-names = "eeprom";
big-endian;

led {
@@ -257,6 +300,20 @@ examples:
};
};
};
+
+ band@0 {
+ /* 2.4 GHz */
+ reg = <0>;
+ nvmem-cells = <&macaddr 0x4>;
+ nvmem-cell-names = "mac-address";
+ };
+
+ band@1 {
+ /* 5 GHz */
+ reg = <1>;
+ nvmem-cells = <&macaddr 0xa>;
+ nvmem-cell-names = "mac-address";
+ };
};
};

--
2.41.0


2023-07-28 03:33:10

by Daniel Golle

[permalink] [raw]
Subject: [PATCH v2 2/2] wifi: mt76: support per-band MAC addresses from OF child nodes

With dual-band-dual-congruent front-ends which appear as two independent
radios it is desirable to assign a per-band MAC address from device-tree,
eg. using nvmem-cells.
Support specifying MAC-address related properties in band-specific child
nodes, e.g.
mt7915@0,0 {
reg = <0x0000 0 0 0 0>;
#addr-cells = <1>;
#size-cells = <0>;

band@0 {
/* 2.4 GHz */
reg = <0>;
nvmem-cells = <&macaddr 2>;
nvmem-cell-names = "mac-address";
};

band@1 {
/* 5 GHz */
reg = <1>;
nvmem-cells = <&macaddr 3>;
nvmem-cell-names = "mac-address";
};
};

Signed-off-by: Daniel Golle <[email protected]>
---
drivers/net/wireless/mediatek/mt76/eeprom.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c
index 36564930aef12..c2b3386cada1c 100644
--- a/drivers/net/wireless/mediatek/mt76/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt76/eeprom.c
@@ -161,9 +161,25 @@ void
mt76_eeprom_override(struct mt76_phy *phy)
{
struct mt76_dev *dev = phy->dev;
- struct device_node *np = dev->dev->of_node;
+ struct device_node *np = dev->dev->of_node, *band_np;
+ bool found_mac = false;
+ u32 reg;
+ int ret;
+
+ for_each_child_of_node(np, band_np) {
+ ret = of_property_read_u32(band_np, "reg", &reg);
+ if (ret)
+ continue;
+
+ if (reg == phy->band_idx) {
+ found_mac = !of_get_mac_address(band_np, phy->macaddr);
+ of_node_put(band_np);
+ break;
+ }
+ }

- of_get_mac_address(np, phy->macaddr);
+ if (!found_mac)
+ of_get_mac_address(np, phy->macaddr);

if (!is_valid_ether_addr(phy->macaddr)) {
eth_random_addr(phy->macaddr);
--
2.41.0

2023-07-29 10:24:23

by Conor Dooley

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] dt-bindings: mt76: support setting per-band MAC address

On Fri, Jul 28, 2023 at 03:50:47AM +0100, Daniel Golle wrote:
> Introduce support for setting individual per-band MAC addresses using
> NVMEM cells by adding a 'bands' object with enumerated child nodes
> representing the 2.4 GHz, 5 GHz and 6 GHz bands.
>
> In case it is defined, call of_get_mac_address for the per-band child
> node, otherwise try with of_get_mac_address on the main device node and
> fall back to a random address like it used to be.
>
> While at it, add MAC address related properties also for the main node
> and update example to use EEPROM via nvmem-cells instead of deprecated
> mediatek,mtd-eeprom property.

Could you mark that deprecated then please?

> +patternProperties:
> + '^band@[0-2]+$':
> + type: object
> + additionalProperties: false
> + properties:
> + reg:
> + maxItems: 1
> +
> + address: true
> + local-mac-address: true
> + mac-address: true
> +
> + nvmem-cells:
> + description: NVMEM cell with the MAC address
> +
> + nvmem-cell-names:
> + items:
> + - const: mac-address

You should not need the items list if you only have one item.

0


Attachments:
(No filename) (1.16 kB)
signature.asc (235.00 B)
Download all attachments