Devicetree
 help / color / mirror / Atom feed
* [PATCH v4 0/3] nvmem: Add byte-mask support for non-contiguous byte selection
@ 2026-12-02 11:36 Hongmei Xu
  2026-12-02 11:36 ` [PATCH v4 1/3] dt-bindings: nvmem: add byte-mask property " Hongmei Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Hongmei Xu @ 2026-12-02 11:36 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rafał Miłecki
  Cc: devicetree, linux-kernel, Hongmei Xu

Some hardware stores NVMEM cell data in non-contiguous bytes. For
example, a MAC address cell may span 7 physical bytes with one byte
unused, requiring the driver to skip that byte during readout.

The existing 'bits' property can only selects a contiguous range of
bits within a cell's declared region. This series adds a 'byte-mask'
property to the fixed-cell binding and implements it in the nvmem
core, allowing consumers to describe and read cells whose bytes are
non-contiguous within the NVMEM device.

An example: assume a MAC address is assembled from efuse registers
0xFFFF4320[31:0] (bytes 0-3), 0xFFFF4324[7:0] (byte 4), and
0xFFFF4324[23:16] (byte 6), with 0xFFFF4324[15:8] unused (byte 5).
Map the efuse region as an 8-byte nvmem device and define the cell
skipping byte 5:

  efuse: efuse@ffff4320 {
    compatible = "...";
    reg = <0x0 0xffff4320 0x0 0x8>;
    #address-cells = <1>;
    #size-cells = <1>;

    nvmem-layout {
      compatible = "fixed-layout";
      #address-cells = <1>;
      #size-cells = <1>;

      mac_addr: mac-addr@0 {
        reg = <0x0 0x6>;
        byte-mask = <0x5f>;
      };
    };
  };

  With byte-mask = 0x5f (0101_1111), bytes 0-4 and 6 are selected
  (byte 5 is skipped), forming the 6-byte MAC address output.

Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
Changes in v4:
- Add nvmem-layout eFuse node in Nord dtsi to expose EMAC0/EMAC1
  MAC address cells using the new byte-mask property
- Update cover letter usage example to use nvmem-layout style
- Link to v3: https://patch.msgid.link/20261117-nvmem-byte-mask-for-split-macaddr-v3-0-c02177658f66@oss.qualcomm.com

Changes in v3:
- Align cell->raw_len to word_size in byte-mask branch to avoid false
  unaligned error log
- Remove redundant nvmem_validate_byte_mask() call from
  nvmem_add_cells_from_dt(); validation already happens inside
  nvmem_cell_info_to_nvmem_cell_entry_nodup()
- Fix DT binding commit message: remove misleading "multiple reg
  entries" comparison
- Update cover letter description for bits property limitation
- Link to v2: https://patch.msgid.link/20261116-nvmem-byte-mask-for-split-macaddr-v2-0-96f4a0c08264@oss.qualcomm.com

Changes in v2:
- Move nvmem_validate_byte_mask() before the nbits block so byte_mask+nbits
   is rejected even when nbits is set (mutual exclusion bypass fix).
 - Run nvmem_validate_byte_mask() after fixup_dt_cell_info() in the DT path
   so the provider callback can adjust cell info before validation.
 - Set cell->raw_len = fls(byte_mask) instead of nvmem->size - cell->offset,
   limiting the physical read to only the bytes needed; avoids large
   allocations and read failures on providers with protected trailing regions
   (e.g. sec-qfprom).
 - Tighten the device-size check to ALIGN(fls(byte_mask), word_size) so
   word-alignment cannot push the read past the device end.
 - Zero-fill output bytes beyond the last selected byte with memset.
 - Simplify compaction loop guard from i < raw_len && i < 32 to i < raw_len
   since raw_len is now bounded by fls(byte_mask) <= 32.
- Link to v1: https://patch.msgid.link/20261113-nvmem-byte-mask-for-split-macaddr-v1-0-138f715f18c1@oss.qualcomm.com

---
Hongmei Xu (3):
      dt-bindings: nvmem: add byte-mask property for non-contiguous byte selection
      nvmem: core: add byte-mask support for non-contiguous cell bytes
      arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses

 .../bindings/nvmem/layouts/fixed-cell.yaml         | 21 +++++
 .../devicetree/bindings/nvmem/qcom,qfprom.yaml     |  1 +
 arch/arm64/boot/dts/qcom/nord.dtsi                 | 22 +++++
 drivers/nvmem/core.c                               | 95 ++++++++++++++++++++--
 include/linux/nvmem-provider.h                     |  8 ++
 5 files changed, 141 insertions(+), 6 deletions(-)
---
base-commit: d26955e57475434b59d43ba372b2a50d33d5e0ed
change-id: 20261110-nvmem-byte-mask-for-split-macaddr-a4698a128057

Best regards,
--  
Hongmei Xu <hongmei.xu@oss.qualcomm.com>


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

* [PATCH v4 1/3] dt-bindings: nvmem: add byte-mask property for non-contiguous byte selection
  2026-12-02 11:36 [PATCH v4 0/3] nvmem: Add byte-mask support for non-contiguous byte selection Hongmei Xu
@ 2026-12-02 11:36 ` Hongmei Xu
  2026-12-02 11:45   ` sashiko-bot
  2026-12-02 11:36 ` [PATCH v4 2/3] nvmem: core: add byte-mask support for non-contiguous cell bytes Hongmei Xu
  2026-12-02 11:36 ` [PATCH v4 3/3] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses Hongmei Xu
  2 siblings, 1 reply; 6+ messages in thread
From: Hongmei Xu @ 2026-12-02 11:36 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rafał Miłecki
  Cc: devicetree, linux-kernel, Hongmei Xu

Add the byte-mask property to the fixed-cell binding. This allows
selecting non-contiguous physical bytes from an NVMEM region to form
a logical cell value.

Some SoCs (e.g. Qualcomm efuse controllers) store a logical value such
as a MAC address across non-contiguous physical bytes, with one or more
bytes in between reserved or unused. byte-mask lets the DT describe this
directly in the fixed-cell binding without requiring a device-specific
provider for a common pattern.

Bit N set in byte-mask means physical byte N relative to the cell's
base offset is included in the output; selected bytes are packed into
the output buffer in ascending byte order. The number of set bits must
not exceed the cell's logical size given by reg. byte-mask and bits are
mutually exclusive. Cells using byte-mask are read-only.

Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
 .../bindings/nvmem/layouts/fixed-cell.yaml          | 21 +++++++++++++++++++++
 .../devicetree/bindings/nvmem/qcom,qfprom.yaml      |  1 +
 2 files changed, 22 insertions(+)

diff --git a/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml b/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
index 38e3ad50ff4f..46e1101ee98a 100644
--- a/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
+++ b/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
@@ -34,6 +34,20 @@ properties:
         description:
           Size in bit within the address range specified by reg.
 
+  byte-mask:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 1
+    description: >
+      Bitmask selecting which physical bytes within the NVMEM device region
+      contribute to this cell's output. Bit N set means physical byte N
+      relative to the cell's base offset is included; selected bytes are
+      packed into the output buffer in ascending byte order. Byte positions
+      are relative to the cell's base offset and limited to a 32-byte window.
+      The highest set bit must not reference a byte beyond the device size.
+      The number of set bits must not exceed the cell's logical size given by
+      reg. Cannot be used together with bits. Cells using byte-mask are
+      read-only; write operations are not supported.
+
 allOf:
   - if:
       properties:
@@ -48,6 +62,13 @@ allOf:
           const: 1
       required:
         - "#nvmem-cell-cells"
+  - if:
+      required: [ byte-mask ]
+    then:
+      properties:
+        bits: false
+      description:
+        byte-mask and bits are mutually exclusive.
 
 required:
   - reg
diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
index 566304ed4c78..d7f48d4ed1ba 100644
--- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
+++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
@@ -42,6 +42,7 @@ properties:
           - qcom,msm8976-qfprom
           - qcom,msm8996-qfprom
           - qcom,msm8998-qfprom
+          - qcom,nord-qfprom
           - qcom,qcm2290-qfprom
           - qcom,qcs404-qfprom
           - qcom,qcs615-qfprom

-- 
2.34.1


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

* [PATCH v4 2/3] nvmem: core: add byte-mask support for non-contiguous cell bytes
  2026-12-02 11:36 [PATCH v4 0/3] nvmem: Add byte-mask support for non-contiguous byte selection Hongmei Xu
  2026-12-02 11:36 ` [PATCH v4 1/3] dt-bindings: nvmem: add byte-mask property " Hongmei Xu
@ 2026-12-02 11:36 ` Hongmei Xu
  2026-12-02 11:36 ` [PATCH v4 3/3] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses Hongmei Xu
  2 siblings, 0 replies; 6+ messages in thread
From: Hongmei Xu @ 2026-12-02 11:36 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rafał Miłecki
  Cc: devicetree, linux-kernel, Hongmei Xu

Add support for a byte-mask cell property that selects non-contiguous
physical bytes from an NVMEM device region to form a logical cell value.

When byte-mask is set, bit N set in the mask means physical byte N is
included; selected bytes are packed into the output buffer in ascending
byte order. If fewer bytes are selected than the cell's logical size
given by reg, the remaining output bytes are zero-filled.

Four checks are performed at cell registration:
- byte-mask and bits/bit-offset are mutually exclusive.
- The cell offset must not exceed the device size.
- The number of set bits must not exceed the cell's logical size (reg),
  to prevent output buffer overflow.
- The highest set bit must not reference a byte beyond the NVMEM device
  size.

Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
 drivers/nvmem/core.c           | 95 +++++++++++++++++++++++++++++++++++++++---
 include/linux/nvmem-provider.h |  8 ++++
 2 files changed, 97 insertions(+), 6 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 7d4cce8e2742..8bc657cd9930 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -33,6 +33,7 @@ struct nvmem_cell_entry {
 	int			bytes;
 	int			bit_offset;
 	int			nbits;
+	u32			byte_mask;
 	nvmem_cell_post_process_t read_post_process;
 	void			*priv;
 	struct device_node	*np;
@@ -589,6 +590,47 @@ static void nvmem_cell_entry_add(struct nvmem_cell_entry *cell)
 	blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell);
 }
 
+static int nvmem_validate_byte_mask(struct nvmem_device *nvmem,
+				    const struct nvmem_cell_info *info)
+{
+	int out_bytes;
+
+	if (!info->byte_mask)
+		return 0;
+
+	if (info->nbits || info->bit_offset) {
+		dev_err(&nvmem->dev,
+			"cell %s byte-mask and bits are mutually exclusive\n",
+			info->name ?: "<unknown>");
+		return -EINVAL;
+	}
+
+	if (info->offset >= nvmem->size) {
+		dev_err(&nvmem->dev,
+			"cell %s offset %u exceeds device size %zu\n",
+			info->name ?: "<unknown>", info->offset, nvmem->size);
+		return -EINVAL;
+	}
+
+	out_bytes = hweight32(info->byte_mask);
+	if (out_bytes > info->bytes) {
+		dev_err(&nvmem->dev,
+			"cell %s byte-mask set-bit count %d exceeds reg size %d\n",
+			info->name ?: "<unknown>", out_bytes, info->bytes);
+		return -EINVAL;
+	}
+
+	if (ALIGN(fls(info->byte_mask), nvmem->word_size) > nvmem->size - info->offset) {
+		dev_err(&nvmem->dev,
+			"cell %s byte-mask bit %d exceeds device size %zu\n",
+			info->name ?: "<unknown>",
+			fls(info->byte_mask) - 1, nvmem->size);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
 						     const struct nvmem_cell_info *info,
 						     struct nvmem_cell_entry *cell)
@@ -603,12 +645,22 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
 
 	cell->bit_offset = info->bit_offset;
 	cell->nbits = info->nbits;
+	cell->byte_mask = info->byte_mask;
 	cell->np = info->np;
 
+	if (cell->byte_mask) {
+		int rc = nvmem_validate_byte_mask(nvmem, info);
+
+		if (rc)
+			return rc;
+	}
+
 	if (cell->nbits) {
 		cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset,
 					   BITS_PER_BYTE);
 		cell->raw_len = ALIGN(cell->bytes, nvmem->word_size);
+	} else if (cell->byte_mask) {
+		cell->raw_len = ALIGN(fls(info->byte_mask), nvmem->word_size);
 	}
 
 	if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
@@ -804,7 +856,7 @@ int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
 {
 	struct device *dev = &nvmem->dev;
 	const __be32 *addr;
-	int len, ret;
+	int len, ret = 0;
 
 	for_each_child_of_node_scoped(np, child) {
 		struct nvmem_cell_info info = {0};
@@ -829,10 +881,13 @@ int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
 			    info.nbits < 1 ||
 			    info.bit_offset + info.nbits > BITS_PER_BYTE * info.bytes) {
 				dev_err(dev, "nvmem: invalid bits on %pOF\n", child);
+				kfree(info.name);
 				return -EINVAL;
 			}
 		}
 
+		of_property_read_u32(child, "byte-mask", &info.byte_mask);
+
 		info.np = of_node_get(child);
 
 		if (nvmem->fixup_dt_cell_info)
@@ -1648,28 +1703,52 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
 			     struct nvmem_cell_entry *cell,
 			     void *buf, size_t *len, const char *id, int index)
 {
+	u8 *rawbuf = NULL;
+	void *readbuf = buf;
 	int rc;
 
-	rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->raw_len);
+	if (cell->byte_mask) {
+		rawbuf = kzalloc(cell->raw_len, GFP_KERNEL);
+		if (!rawbuf)
+			return -ENOMEM;
+		readbuf = rawbuf;
+	}
+
+	rc = nvmem_reg_read(nvmem, cell->offset, readbuf, cell->raw_len);
 
 	if (rc)
-		return rc;
+		goto err_exit;
 
 	/* shift bits in-place */
 	if (cell->bit_offset || cell->nbits)
 		nvmem_shift_read_buffer_in_place(cell, buf);
 
+	/* compact non-contiguous bytes selected by byte_mask */
+	if (cell->byte_mask) {
+		int out_idx = 0;
+		int i;
+
+		for (i = 0; i < cell->raw_len; i++) {
+			if (cell->byte_mask & BIT(i))
+				((u8 *)buf)[out_idx++] = rawbuf[i];
+		}
+		memset((u8 *)buf + out_idx, 0, cell->bytes - out_idx);
+	}
+
 	if (cell->read_post_process) {
 		rc = cell->read_post_process(cell->priv, id, index,
-					     cell->offset, buf, cell->raw_len);
+					     cell->offset, buf,
+					     cell->byte_mask ? cell->bytes : cell->raw_len);
 		if (rc)
-			return rc;
+			goto err_exit;
 	}
 
 	if (len)
 		*len = cell->bytes;
 
-	return 0;
+err_exit:
+	kfree(rawbuf);
+	return rc;
 }
 
 /**
@@ -1776,6 +1855,10 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si
 	if (cell->read_post_process)
 		return -EINVAL;
 
+	/* byte-mask cells have no scatter-write implementation yet */
+	if (cell->byte_mask)
+		return -EINVAL;
+
 	if (cell->bit_offset || cell->nbits) {
 		if (len != BITS_TO_BYTES(cell->nbits) && len != cell->bytes)
 			return -EINVAL;
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 6063fe5b7784..066d27bb4284 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -57,6 +57,13 @@ struct nvmem_keepout {
  * @bytes:	Length of the cell.
  * @bit_offset:	Bit offset if cell is smaller than a byte.
  * @nbits:	Number of bits.
+ * @byte_mask:   Bitmask selecting physical bytes to include in the output.
+ *               Bit N=1 means physical byte N relative to the cell's base
+ *               offset is packed into the output buffer; bit N=0 means skip.
+ *               The physical read window extends to the highest set bit,
+ *               aligned to the device word size. The number of set bits must
+ *               not exceed the cell's logical size (bytes). Unselected output
+ *               positions are zero-filled. Zero means no masking.
  * @np:		Optional device_node pointer.
  * @read_post_process:	Callback for optional post processing of cell data
  *			on reads.
@@ -69,6 +76,7 @@ struct nvmem_cell_info {
 	unsigned int		bytes;
 	unsigned int		bit_offset;
 	unsigned int		nbits;
+	u32			byte_mask;
 	struct device_node	*np;
 	nvmem_cell_post_process_t read_post_process;
 	void			*priv;

-- 
2.34.1


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

* [PATCH v4 3/3] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses
  2026-12-02 11:36 [PATCH v4 0/3] nvmem: Add byte-mask support for non-contiguous byte selection Hongmei Xu
  2026-12-02 11:36 ` [PATCH v4 1/3] dt-bindings: nvmem: add byte-mask property " Hongmei Xu
  2026-12-02 11:36 ` [PATCH v4 2/3] nvmem: core: add byte-mask support for non-contiguous cell bytes Hongmei Xu
@ 2026-12-02 11:36 ` Hongmei Xu
  2026-12-02 11:55   ` sashiko-bot
  2 siblings, 1 reply; 6+ messages in thread
From: Hongmei Xu @ 2026-12-02 11:36 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rafał Miłecki
  Cc: devicetree, linux-kernel, Hongmei Xu

Add a QFPROM eFuse node to expose the Ethernet MAC addresses for
EMAC0 and EMAC1 as nvmem cells.

The MAC addresses are stored in OEM_CONFIG8/9 registers starting at
0x360d4320:
  bytes 0-4  shared by both EMACs
  byte  5    last octet of EMAC0 MAC address
  byte  6    last octet of EMAC1 MAC address

EMAC0 reads six consecutive bytes (0-5), requiring no byte selection.
EMAC1 shares bytes 0-4 but takes byte 6 as its last octet, skipping
byte 5. A byte-mask of 0x5F (0b01011111) is used to select bytes
0,1,2,3,4,6 and compact them into the six-byte output buffer.

Only 8 bytes are mapped to avoid overlapping with adjacent QFPROM
devices in the register space.

Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
 arch/arm64/boot/dts/qcom/nord.dtsi | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/nord.dtsi b/arch/arm64/boot/dts/qcom/nord.dtsi
index fdbe290350dd..cfe1f39648fb 100644
--- a/arch/arm64/boot/dts/qcom/nord.dtsi
+++ b/arch/arm64/boot/dts/qcom/nord.dtsi
@@ -1471,6 +1471,28 @@ rng: rng@10c3000 {
 			reg = <0x0 0x010c3000 0x0 0x1000>;
 		};
 
+		efuse: efuse@360d4320 {
+			compatible = "qcom,nord-qfprom", "qcom,qfprom";
+			reg = <0x0 0x360d4320 0x0 0x8>;
+			#address-cells = <1>;
+			#size-cells = <1>;
+
+			nvmem-layout {
+				compatible = "fixed-layout";
+				#address-cells = <1>;
+				#size-cells = <1>;
+
+				mac_addr0: mac-addr0@0 {
+					reg = <0x0 0x6>;
+				};
+
+				mac_addr1: mac-addr1@0,1 {
+					reg = <0x0 0x6>;
+					byte-mask = <0x5f>;
+				};
+			};
+		};
+
 		ufs_mem_hc: ufshc@1d44000 {
 			compatible = "qcom,nord-ufshc",
 				     "qcom,ufshc",

-- 
2.34.1


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

* Re: [PATCH v4 1/3] dt-bindings: nvmem: add byte-mask property for non-contiguous byte selection
  2026-12-02 11:36 ` [PATCH v4 1/3] dt-bindings: nvmem: add byte-mask property " Hongmei Xu
@ 2026-12-02 11:45   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-02 11:45 UTC (permalink / raw)
  To: Hongmei Xu; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] dt-bindings: nvmem: byte-mask redefines reg size and reads
  beyond reg
- [Medium] dt-bindings: nvmem: byte-mask added to fixed-cell against
  maintainer direction
- [Low] dt-bindings: nvmem: unrelated qcom,nord-qfprom addition in
  qcom,qfprom.yaml
--

commit 4a212237811eb974de49d8b89d27971b7e08603b
Author: Hongmei Xu <hongmei.xu@oss.qualcomm.com>

dt-bindings: nvmem: add byte-mask property for non-contiguous byte selection

This commit adds the byte-mask property to the fixed-cell NVMEM layout
binding to support selecting non-contiguous physical bytes for a cell,
and adds the qcom,nord-qfprom compatible string to qcom,qfprom.yaml.

> diff --git a/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml b/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
> index 38e3ad50ff4fb..46e1101ee98ae 100644
> --- a/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
> @@ -34,6 +34,20 @@ properties:
>          description:
>            Size in bit within the address range specified by reg.
>  
> +  byte-mask:
> +    $ref: /schemas/types.yaml#/definitions/uint32
> +    minimum: 1
> +    description: >
> +      Bitmask selecting which physical bytes within the NVMEM device region
> +      contribute to this cell's output. Bit N set means physical byte N
> +      relative to the cell's base offset is included; selected bytes are
> +      packed into the output buffer in ascending byte order. Byte positions
> +      are relative to the cell's base offset and limited to a 32-byte window.
> +      The highest set bit must not reference a byte beyond the device size.
> +      The number of set bits must not exceed the cell's logical size given by
> +      reg. Cannot be used together with bits. Cells using byte-mask are
> +      read-only; write operations are not supported.
> +

[Severity: Medium]
Does byte-mask redefine reg from the cell's physical address range to its
logical output size?

In Devicetree bindings and in fixed-cell.yaml (where bits selects a sub-range
"within the address range specified by reg"), reg = <offset size> describes
the physical address span occupied in the parent NVMEM device.  For any
non-contiguous selection of K bytes, the highest set bit spans at least K + 1
physical bytes.

If a DT author sets the reg size to the logical size K, physical reads extend
beyond the declared [offset, offset + K) reg range and hide physical address
overlaps between sibling cells.  If the author instead sets the reg size to
the full physical span M > K, this description leaves the contents of the
trailing M - K output bytes unspecified, and consumers expecting an exact
K-byte cell (such as a 6-byte MAC address) receive an M-byte buffer.

>  allOf:
>    - if:
>        properties:
> @@ -48,6 +62,13 @@ allOf:
>            const: 1
>        required:
>          - "#nvmem-cell-cells"
> +  - if:
> +      required: [ byte-mask ]
> +    then:
> +      properties:
> +        bits: false
> +      description:
> +        byte-mask and bits are mutually exclusive.
>  
>  required:
>    - reg

[Severity: Medium]
As reported by Srinivas Kandagatla on v3 [1], should non-contiguous byte
selection be handled by an NVMEM layout driver rather than adding a
byte-mask property to fixed-cell.yaml?

The NVMEM layout infrastructure already supports custom multi-byte cell
extraction and post-processing callbacks without extending the generic
fixed-cell binding ABI.

> diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
> index 566304ed4c786..d7f48d4ed1ba7 100644
> --- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
> @@ -42,6 +42,7 @@ properties:
>            - qcom,msm8976-qfprom
>            - qcom,msm8996-qfprom
>            - qcom,msm8998-qfprom
> +          - qcom,nord-qfprom
>            - qcom,qcm2290-qfprom
>            - qcom,qcs404-qfprom
>            - qcom,qcs615-qfprom

[Severity: Low]
Should the addition of qcom,nord-qfprom to qcom,qfprom.yaml be split into a
separate patch?  It is unrelated to the generic fixed-cell byte-mask property
and is not mentioned in the commit message.

[1] https://lore.kernel.org/r/ef5c8902-2a55-4879-8deb-5109f7bd3cd2@kernel.org

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-nvmem-byte-mask-for-split-macaddr-v4-0-039f1b0afeca@oss.qualcomm.com?part=1

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

* Re: [PATCH v4 3/3] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses
  2026-12-02 11:36 ` [PATCH v4 3/3] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses Hongmei Xu
@ 2026-12-02 11:55   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-02 11:55 UTC (permalink / raw)
  To: Hongmei Xu; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] arm64: dts: qcom: nord: efuse@360d4320 maps 8-byte register
  slice as qfprom
- [Low] arm64: dts: qcom: unaligned 6-byte mac-addr0 cell logs dev_err()
  on boot
- [Low] arm64: dts: qcom: efuse@360d4320 placed out of unit-address
  order in soc@0
- [Low] arm64: dts: qcom: unnecessary #address-cells/#size-cells on
  efuse@360d4320
--

commit 0e88df0ea7f12e01b6e2d01adae2774d3c1a1151
Author: Hongmei Xu <hongmei.xu@oss.qualcomm.com>

arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses

This commit adds a QFPROM eFuse node to nord.dtsi to expose the EMAC0 and
EMAC1 Ethernet MAC addresses stored in OEM_CONFIG8/9 as nvmem cells.

> diff --git a/arch/arm64/boot/dts/qcom/nord.dtsi b/arch/arm64/boot/dts/qcom/nord.dtsi
> index fdbe290350ddd..cfe1f39648fbc 100644
> --- a/arch/arm64/boot/dts/qcom/nord.dtsi
> +++ b/arch/arm64/boot/dts/qcom/nord.dtsi
> @@ -1471,6 +1471,28 @@ rng: rng@10c3000 {
>  			reg = <0x0 0x010c3000 0x0 0x1000>;
>  		};
>  
> +		efuse: efuse@360d4320 {
> +			compatible = "qcom,nord-qfprom", "qcom,qfprom";
> +			reg = <0x0 0x360d4320 0x0 0x8>;

[Severity: Medium]
Should this node describe the QFPROM corrected region at its block base
address (0x360d4000) with the MAC address cells at offset 0x320, rather
than mapping only the 8-byte OEM_CONFIG8/9 register slice at 0x360d4320?

In Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml, the reg
property represents the QFPROM corrected region as a whole, with
individual fuses defined as child cells at their register offsets.
Modeling an 8-byte fuse slice as its own qcom,nord-qfprom device prevents
adding other fuse cells from the same QFPROM block later without breaking
the Devicetree ABI or instantiating multiple qcom,qfprom devices for the
same hardware block.

> +			#address-cells = <1>;
> +			#size-cells = <1>;

[Severity: Low]
Are #address-cells and #size-cells needed on efuse@360d4320 itself?

Because the cells are placed inside the nvmem-layout child node (which
has no reg or ranges property and defines its own #address-cells and
#size-cells), building the DTB with W=1 triggers a dtc
avoid_unnecessary_addr_size warning on efuse@360d4320.

> +
> +			nvmem-layout {
> +				compatible = "fixed-layout";
> +				#address-cells = <1>;
> +				#size-cells = <1>;
> +
> +				mac_addr0: mac-addr0@0 {
> +					reg = <0x0 0x6>;
> +				};

[Severity: Low]
Does registering mac-addr0 log an unaligned raw_len error via dev_err() on
every boot?

qfprom_probe() sets word_size = 4, and for a word-aligned cell offset
qfprom_fixup_dt_cell_info() leaves cell->nbits as 0:

drivers/nvmem/qfprom.c:qfprom_fixup_dt_cell_info() {
	unsigned int byte_offset = cell->offset % sizeof(u32);

	cell->bit_offset += byte_offset * BITS_PER_BYTE;
	cell->offset -= byte_offset;
	if (byte_offset && !cell->nbits)
		cell->nbits = cell->bytes * BITS_PER_BYTE;
}

In nvmem_cell_info_to_nvmem_cell_entry_nodup(), cell->raw_len is only
rounded up to nvmem->word_size ahead of the alignment check when
cell->nbits or cell->byte_mask is non-zero.  Because mac-addr0 has neither
bits nor byte-mask, cell->raw_len remains 6 and hits the !IS_ALIGNED()
dev_err() path ("cell mac-addr0 raw len 6 unaligned to nvmem word size
4").

> +
> +				mac_addr1: mac-addr1@0,1 {
> +					reg = <0x0 0x6>;
> +					byte-mask = <0x5f>;
> +				};
> +			};
> +		};
> +
>  		ufs_mem_hc: ufshc@1d44000 {
>  			compatible = "qcom,nord-ufshc",
>  				     "qcom,ufshc",

[Severity: Low]
This isn't a bug, but efuse@360d4320 (0x360d4320) is placed between
rng@10c3000 (0x010c3000) and ufshc@1d44000 (0x01d44000).  To keep the
nodes under soc@0 sorted by unit address, it should be placed after
system-cache-controller@21800000.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-nvmem-byte-mask-for-split-macaddr-v4-0-039f1b0afeca@oss.qualcomm.com?part=3

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

end of thread, other threads:[~2026-12-02 11:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 11:36 [PATCH v4 0/3] nvmem: Add byte-mask support for non-contiguous byte selection Hongmei Xu
2026-12-02 11:36 ` [PATCH v4 1/3] dt-bindings: nvmem: add byte-mask property " Hongmei Xu
2026-12-02 11:45   ` sashiko-bot
2026-12-02 11:36 ` [PATCH v4 2/3] nvmem: core: add byte-mask support for non-contiguous cell bytes Hongmei Xu
2026-12-02 11:36 ` [PATCH v4 3/3] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses Hongmei Xu
2026-12-02 11:55   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox