Unverified Commit 13d0fe84 authored by Gabor Juhos's avatar Gabor Juhos Committed by Mark Brown
Browse files

spi: spi-qpic-snand: fix calculating of ECC OOB regions' properties



The OOB layout used by the driver has two distinct regions which contains
hardware specific ECC data, yet the qcom_spi_ooblayout_ecc() function sets
the same offset and length values for both regions which is clearly wrong.

Change the code to calculate the correct values for both regions.

For reference, the following table shows the computed offset and length
values for various OOB size/ECC strength configurations:

                              +-----------------+-----------------+
                              |before the change| after the change|
  +-------+----------+--------+--------+--------+--------+--------+
  |  OOB  |   ECC    | region | region | region | region | region |
  |  size | strength | index  | offset | length | offset | length |
  +-------+----------+--------+--------+--------+--------+--------+
  |  128  |     8    |    0   |   113  |   15   |    0   |   49   |
  |       |          |    1   |   113  |   15   |   65   |   63   |
  +-------+----------+--------+--------+--------+--------+--------+
  |  128  |     4    |    0   |   117  |   11   |    0   |   37   |
  |       |          |    1   |   117  |   11   |   53   |   75   |
  +-------+----------+--------+--------+--------+--------+--------+
  |   64  |     4    |    0   |    53  |   11   |    0   |   37   |
  |       |          |    1   |    53  |   11   |   53   |   11   |
  +-------+----------+--------+--------+--------+--------+--------+

Fixes: 7304d190 ("spi: spi-qpic: add driver for QCOM SPI NAND flash Interface")
Signed-off-by: default avatarGabor Juhos <j4g8y7@gmail.com>
Reviewed-by: default avatarKonrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Link: https://patch.msgid.link/20250805-qpic-snand-oob-ecc-fix-v2-1-e6f811c70d6f@gmail.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent af357a6a
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -210,15 +210,23 @@ static int qcom_spi_ooblayout_ecc(struct mtd_info *mtd, int section,
	struct qcom_nand_controller *snandc = nand_to_qcom_snand(nand);
	struct qpic_ecc *qecc = snandc->qspi->ecc;

	if (section > 1)
		return -ERANGE;

	oobregion->length = qecc->ecc_bytes_hw + qecc->spare_bytes;
	oobregion->offset = mtd->oobsize - oobregion->length;

	switch (section) {
	case 0:
		oobregion->offset = 0;
		oobregion->length = qecc->bytes * (qecc->steps - 1) +
				    qecc->bbm_size;
		return 0;
	case 1:
		oobregion->offset = qecc->bytes * (qecc->steps - 1) +
				    qecc->bbm_size +
				    qecc->steps * 4;
		oobregion->length = mtd->oobsize - oobregion->offset;
		return 0;
	}

	return -ERANGE;
}

static int qcom_spi_ooblayout_free(struct mtd_info *mtd, int section,
				   struct mtd_oob_region *oobregion)
{