linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules
@ 2024-09-13 21:07 Lorenzo Bianconi
  2024-09-13 21:07 ` [PATCH 1/4] spi: airoha: fix dirmap_{read,write} operations Lorenzo Bianconi
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Lorenzo Bianconi @ 2024-09-13 21:07 UTC (permalink / raw)
  To: Lorenzo Bianconi, Ray Liu, Mark Brown, AngeloGioacchino Del Regno,
	Andy Shevchenko
  Cc: Christian Marangi, linux-arm-kernel, linux-spi, upstream

Fix errors detected running mtd_test kernel test modules.

---
Lorenzo Bianconi (4):
      spi: airoha: fix dirmap_{read,write} operations
      spi: airoha: fix airoha_snand_{write,read}_data data_len estimation
      spi: airoha: remove read cache in airoha_snand_dirmap_read
      spi: airoha: do not keep {tx,rx} dma buffer always mapped

 drivers/spi/spi-airoha-snfi.c | 199 ++++++++++++++++++------------------------
 1 file changed, 87 insertions(+), 112 deletions(-)
---
base-commit: 58be528df758d3f00c10d6d381d9e02d5c68f23d
change-id: 20240913-airoha-spi-fixes-56bb430fb99f

Best regards,
-- 
Lorenzo Bianconi <lorenzo@kernel.org>


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

* [PATCH 1/4] spi: airoha: fix dirmap_{read,write} operations
  2024-09-13 21:07 [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules Lorenzo Bianconi
@ 2024-09-13 21:07 ` Lorenzo Bianconi
  2024-09-13 21:07 ` [PATCH 2/4] spi: airoha: fix airoha_snand_{write,read}_data data_len estimation Lorenzo Bianconi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Lorenzo Bianconi @ 2024-09-13 21:07 UTC (permalink / raw)
  To: Lorenzo Bianconi, Ray Liu, Mark Brown, AngeloGioacchino Del Regno,
	Andy Shevchenko
  Cc: Christian Marangi, linux-arm-kernel, linux-spi, upstream

SPI_NFI_READ_FROM_CACHE_DONE bit must be written at the end of
dirmap_read operation even if it is already set.
In the same way, SPI_NFI_LOAD_TO_CACHE_DONE bit must be written at the
end of dirmap_write operation even if it is already set.
For this reason use regmap_write_bits() instead of regmap_set_bits().
This patch fixes mtd_pagetest kernel module test.

Fixes: a403997c1201 ("spi: airoha: add SPI-NAND Flash controller driver")
Tested-by: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/spi/spi-airoha-snfi.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
index 9d97ec98881c..be3e4ac42153 100644
--- a/drivers/spi/spi-airoha-snfi.c
+++ b/drivers/spi/spi-airoha-snfi.c
@@ -739,8 +739,13 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc,
 	if (err)
 		return err;
 
-	err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_STA_CTL1,
-			      SPI_NFI_READ_FROM_CACHE_DONE);
+	/*
+	 * SPI_NFI_READ_FROM_CACHE_DONE bit must be written at the end
+	 * of dirmap_read operation even if it is already set.
+	 */
+	err = regmap_write_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_STA_CTL1,
+				SPI_NFI_READ_FROM_CACHE_DONE,
+				SPI_NFI_READ_FROM_CACHE_DONE);
 	if (err)
 		return err;
 
@@ -870,8 +875,13 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
 	if (err)
 		return err;
 
-	err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_STA_CTL1,
-			      SPI_NFI_LOAD_TO_CACHE_DONE);
+	/*
+	 * SPI_NFI_LOAD_TO_CACHE_DONE bit must be written at the end
+	 * of dirmap_write operation even if it is already set.
+	 */
+	err = regmap_write_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_STA_CTL1,
+				SPI_NFI_LOAD_TO_CACHE_DONE,
+				SPI_NFI_LOAD_TO_CACHE_DONE);
 	if (err)
 		return err;
 

-- 
2.46.0


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

* [PATCH 2/4] spi: airoha: fix airoha_snand_{write,read}_data data_len estimation
  2024-09-13 21:07 [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules Lorenzo Bianconi
  2024-09-13 21:07 ` [PATCH 1/4] spi: airoha: fix dirmap_{read,write} operations Lorenzo Bianconi
@ 2024-09-13 21:07 ` Lorenzo Bianconi
  2024-09-13 21:07 ` [PATCH 3/4] spi: airoha: remove read cache in airoha_snand_dirmap_read Lorenzo Bianconi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Lorenzo Bianconi @ 2024-09-13 21:07 UTC (permalink / raw)
  To: Lorenzo Bianconi, Ray Liu, Mark Brown, AngeloGioacchino Del Regno,
	Andy Shevchenko
  Cc: Christian Marangi, linux-arm-kernel, linux-spi, upstream

Fix data length written and read in airoha_snand_write_data and
airoha_snand_read_data routines respectively if it is bigger than
SPI_MAX_TRANSFER_SIZE.

Fixes: a403997c1201 ("spi: airoha: add SPI-NAND Flash controller driver")
Tested-by: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/spi/spi-airoha-snfi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
index be3e4ac42153..c71be702cf6f 100644
--- a/drivers/spi/spi-airoha-snfi.c
+++ b/drivers/spi/spi-airoha-snfi.c
@@ -405,7 +405,7 @@ static int airoha_snand_write_data(struct airoha_snand_ctrl *as_ctrl, u8 cmd,
 	for (i = 0; i < len; i += data_len) {
 		int err;
 
-		data_len = min(len, SPI_MAX_TRANSFER_SIZE);
+		data_len = min(len - i, SPI_MAX_TRANSFER_SIZE);
 		err = airoha_snand_set_fifo_op(as_ctrl, cmd, data_len);
 		if (err)
 			return err;
@@ -427,7 +427,7 @@ static int airoha_snand_read_data(struct airoha_snand_ctrl *as_ctrl, u8 *data,
 	for (i = 0; i < len; i += data_len) {
 		int err;
 
-		data_len = min(len, SPI_MAX_TRANSFER_SIZE);
+		data_len = min(len - i, SPI_MAX_TRANSFER_SIZE);
 		err = airoha_snand_set_fifo_op(as_ctrl, 0xc, data_len);
 		if (err)
 			return err;

-- 
2.46.0


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

* [PATCH 3/4] spi: airoha: remove read cache in airoha_snand_dirmap_read
  2024-09-13 21:07 [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules Lorenzo Bianconi
  2024-09-13 21:07 ` [PATCH 1/4] spi: airoha: fix dirmap_{read,write} operations Lorenzo Bianconi
  2024-09-13 21:07 ` [PATCH 2/4] spi: airoha: fix airoha_snand_{write,read}_data data_len estimation Lorenzo Bianconi
@ 2024-09-13 21:07 ` Lorenzo Bianconi
  2024-09-13 21:07 ` [PATCH 4/4] spi: airoha: do not keep {tx,rx} dma buffer always mapped Lorenzo Bianconi
  2024-09-19  8:29 ` (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules Mark Brown
  4 siblings, 0 replies; 13+ messages in thread
From: Lorenzo Bianconi @ 2024-09-13 21:07 UTC (permalink / raw)
  To: Lorenzo Bianconi, Ray Liu, Mark Brown, AngeloGioacchino Del Regno,
	Andy Shevchenko
  Cc: Christian Marangi, linux-arm-kernel, linux-spi, upstream

Get rid of read cache in airoha_snand_dirmap_read routine since it
introduces errors in mtd_oobtest kernel module test and it does not
add any performance improvements in mtd_speedtest kernel module test.

Fixes: a403997c1201 ("spi: airoha: add SPI-NAND Flash controller driver")
Tested-by: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/spi/spi-airoha-snfi.c | 21 ---------------------
 1 file changed, 21 deletions(-)

diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
index c71be702cf6f..94458df53eae 100644
--- a/drivers/spi/spi-airoha-snfi.c
+++ b/drivers/spi/spi-airoha-snfi.c
@@ -211,9 +211,6 @@ struct airoha_snand_dev {
 
 	u8 *txrx_buf;
 	dma_addr_t dma_addr;
-
-	u64 cur_page_num;
-	bool data_need_update;
 };
 
 struct airoha_snand_ctrl {
@@ -644,11 +641,6 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc,
 	u32 val, rd_mode;
 	int err;
 
-	if (!as_dev->data_need_update)
-		return len;
-
-	as_dev->data_need_update = false;
-
 	switch (op->cmd.opcode) {
 	case SPI_NAND_OP_READ_FROM_CACHE_DUAL:
 		rd_mode = 1;
@@ -895,23 +887,11 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
 static int airoha_snand_exec_op(struct spi_mem *mem,
 				const struct spi_mem_op *op)
 {
-	struct airoha_snand_dev *as_dev = spi_get_ctldata(mem->spi);
 	u8 data[8], cmd, opcode = op->cmd.opcode;
 	struct airoha_snand_ctrl *as_ctrl;
 	int i, err;
 
 	as_ctrl = spi_controller_get_devdata(mem->spi->controller);
-	if (opcode == SPI_NAND_OP_PROGRAM_EXECUTE &&
-	    op->addr.val == as_dev->cur_page_num) {
-		as_dev->data_need_update = true;
-	} else if (opcode == SPI_NAND_OP_PAGE_READ) {
-		if (!as_dev->data_need_update &&
-		    op->addr.val == as_dev->cur_page_num)
-			return 0;
-
-		as_dev->data_need_update = true;
-		as_dev->cur_page_num = op->addr.val;
-	}
 
 	/* switch to manual mode */
 	err = airoha_snand_set_mode(as_ctrl, SPI_MODE_MANUAL);
@@ -996,7 +976,6 @@ static int airoha_snand_setup(struct spi_device *spi)
 	if (dma_mapping_error(as_ctrl->dev, as_dev->dma_addr))
 		return -ENOMEM;
 
-	as_dev->data_need_update = true;
 	spi_set_ctldata(spi, as_dev);
 
 	return 0;

-- 
2.46.0


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

* [PATCH 4/4] spi: airoha: do not keep {tx,rx} dma buffer always mapped
  2024-09-13 21:07 [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules Lorenzo Bianconi
                   ` (2 preceding siblings ...)
  2024-09-13 21:07 ` [PATCH 3/4] spi: airoha: remove read cache in airoha_snand_dirmap_read Lorenzo Bianconi
@ 2024-09-13 21:07 ` Lorenzo Bianconi
  2024-09-19  8:29 ` (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules Mark Brown
  4 siblings, 0 replies; 13+ messages in thread
From: Lorenzo Bianconi @ 2024-09-13 21:07 UTC (permalink / raw)
  To: Lorenzo Bianconi, Ray Liu, Mark Brown, AngeloGioacchino Del Regno,
	Andy Shevchenko
  Cc: Christian Marangi, linux-arm-kernel, linux-spi, upstream

DMA map txrx_buf on demand and do not keep it always mapped.
This patch does not introduce any functional change to the driver, it just
simplifies the code without any performance degradation according to the
results of the mtd_speedtest kernel module test.

Tested-by: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/spi/spi-airoha-snfi.c | 152 +++++++++++++++++++-----------------------
 1 file changed, 69 insertions(+), 83 deletions(-)

diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
index 94458df53eae..16c528883cca 100644
--- a/drivers/spi/spi-airoha-snfi.c
+++ b/drivers/spi/spi-airoha-snfi.c
@@ -206,13 +206,6 @@ enum airoha_snand_cs {
 	SPI_CHIP_SEL_LOW,
 };
 
-struct airoha_snand_dev {
-	size_t buf_len;
-
-	u8 *txrx_buf;
-	dma_addr_t dma_addr;
-};
-
 struct airoha_snand_ctrl {
 	struct device *dev;
 	struct regmap *regmap_ctrl;
@@ -617,9 +610,9 @@ static bool airoha_snand_supports_op(struct spi_mem *mem,
 
 static int airoha_snand_dirmap_create(struct spi_mem_dirmap_desc *desc)
 {
-	struct airoha_snand_dev *as_dev = spi_get_ctldata(desc->mem->spi);
+	u8 *txrx_buf = spi_get_ctldata(desc->mem->spi);
 
-	if (!as_dev->txrx_buf)
+	if (!txrx_buf)
 		return -EINVAL;
 
 	if (desc->info.offset + desc->info.length > U32_MAX)
@@ -634,10 +627,11 @@ static int airoha_snand_dirmap_create(struct spi_mem_dirmap_desc *desc)
 static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc,
 					u64 offs, size_t len, void *buf)
 {
-	struct spi_device *spi = desc->mem->spi;
-	struct airoha_snand_dev *as_dev = spi_get_ctldata(spi);
 	struct spi_mem_op *op = &desc->info.op_tmpl;
+	struct spi_device *spi = desc->mem->spi;
 	struct airoha_snand_ctrl *as_ctrl;
+	u8 *txrx_buf = spi_get_ctldata(spi);
+	dma_addr_t dma_addr;
 	u32 val, rd_mode;
 	int err;
 
@@ -662,14 +656,16 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc,
 	if (err)
 		return err;
 
-	dma_sync_single_for_device(as_ctrl->dev, as_dev->dma_addr,
-				   as_dev->buf_len, DMA_BIDIRECTIONAL);
+	dma_addr = dma_map_single(as_ctrl->dev, txrx_buf, SPI_NAND_CACHE_SIZE,
+				  DMA_FROM_DEVICE);
+	if (dma_mapping_error(as_ctrl->dev, dma_addr))
+		return -ENOMEM;
 
 	/* set dma addr */
 	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_STRADDR,
-			   as_dev->dma_addr);
+			   dma_addr);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	/* set cust sec size */
 	val = as_ctrl->nfi_cfg.sec_size * as_ctrl->nfi_cfg.sec_num;
@@ -678,58 +674,58 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc,
 				 REG_SPI_NFI_SNF_MISC_CTL2,
 				 SPI_NFI_READ_DATA_BYTE_NUM, val);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	/* set read command */
 	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_RD_CTL2,
 			   op->cmd.opcode);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	/* set read mode */
 	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_MISC_CTL,
 			   FIELD_PREP(SPI_NFI_DATA_READ_WR_MODE, rd_mode));
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	/* set read addr */
 	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_RD_CTL3, 0x0);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	/* set nfi read */
 	err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG,
 				 SPI_NFI_OPMODE,
 				 FIELD_PREP(SPI_NFI_OPMODE, 6));
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG,
 			      SPI_NFI_READ_MODE | SPI_NFI_DMA_MODE);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_CMD, 0x0);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	/* trigger dma start read */
 	err = regmap_clear_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CON,
 				SPI_NFI_RD_TRIG);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CON,
 			      SPI_NFI_RD_TRIG);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_read_poll_timeout(as_ctrl->regmap_nfi,
 				       REG_SPI_NFI_SNF_STA_CTL1, val,
 				       (val & SPI_NFI_READ_FROM_CACHE_DONE),
 				       0, 1 * USEC_PER_SEC);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	/*
 	 * SPI_NFI_READ_FROM_CACHE_DONE bit must be written at the end
@@ -739,35 +735,41 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc,
 				SPI_NFI_READ_FROM_CACHE_DONE,
 				SPI_NFI_READ_FROM_CACHE_DONE);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_read_poll_timeout(as_ctrl->regmap_nfi, REG_SPI_NFI_INTR,
 				       val, (val & SPI_NFI_AHB_DONE), 0,
 				       1 * USEC_PER_SEC);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	/* DMA read need delay for data ready from controller to DRAM */
 	udelay(1);
 
-	dma_sync_single_for_cpu(as_ctrl->dev, as_dev->dma_addr,
-				as_dev->buf_len, DMA_BIDIRECTIONAL);
+	dma_unmap_single(as_ctrl->dev, dma_addr, SPI_NAND_CACHE_SIZE,
+			 DMA_FROM_DEVICE);
 	err = airoha_snand_set_mode(as_ctrl, SPI_MODE_MANUAL);
 	if (err < 0)
 		return err;
 
-	memcpy(buf, as_dev->txrx_buf + offs, len);
+	memcpy(buf, txrx_buf + offs, len);
 
 	return len;
+
+error_dma_unmap:
+	dma_unmap_single(as_ctrl->dev, dma_addr, SPI_NAND_CACHE_SIZE,
+			 DMA_FROM_DEVICE);
+	return err;
 }
 
 static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
 					 u64 offs, size_t len, const void *buf)
 {
-	struct spi_device *spi = desc->mem->spi;
-	struct airoha_snand_dev *as_dev = spi_get_ctldata(spi);
 	struct spi_mem_op *op = &desc->info.op_tmpl;
+	struct spi_device *spi = desc->mem->spi;
+	u8 *txrx_buf = spi_get_ctldata(spi);
 	struct airoha_snand_ctrl *as_ctrl;
+	dma_addr_t dma_addr;
 	u32 wr_mode, val;
 	int err;
 
@@ -776,19 +778,19 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
 	if (err < 0)
 		return err;
 
-	dma_sync_single_for_cpu(as_ctrl->dev, as_dev->dma_addr,
-				as_dev->buf_len, DMA_BIDIRECTIONAL);
-	memcpy(as_dev->txrx_buf + offs, buf, len);
-	dma_sync_single_for_device(as_ctrl->dev, as_dev->dma_addr,
-				   as_dev->buf_len, DMA_BIDIRECTIONAL);
+	memcpy(txrx_buf + offs, buf, len);
+	dma_addr = dma_map_single(as_ctrl->dev, txrx_buf, SPI_NAND_CACHE_SIZE,
+				  DMA_TO_DEVICE);
+	if (dma_mapping_error(as_ctrl->dev, dma_addr))
+		return -ENOMEM;
 
 	err = airoha_snand_set_mode(as_ctrl, SPI_MODE_DMA);
 	if (err < 0)
-		return err;
+		goto error_dma_unmap;
 
 	err = airoha_snand_nfi_config(as_ctrl);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	if (op->cmd.opcode == SPI_NAND_OP_PROGRAM_LOAD_QUAD ||
 	    op->cmd.opcode == SPI_NAND_OP_PROGRAM_LOAD_RAMDON_QUAD)
@@ -797,9 +799,9 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
 		wr_mode = 0;
 
 	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_STRADDR,
-			   as_dev->dma_addr);
+			   dma_addr);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	val = FIELD_PREP(SPI_NFI_PROG_LOAD_BYTE_NUM,
 			 as_ctrl->nfi_cfg.sec_size * as_ctrl->nfi_cfg.sec_num);
@@ -807,65 +809,65 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
 				 REG_SPI_NFI_SNF_MISC_CTL2,
 				 SPI_NFI_PROG_LOAD_BYTE_NUM, val);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_PG_CTL1,
 			   FIELD_PREP(SPI_NFI_PG_LOAD_CMD,
 				      op->cmd.opcode));
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_MISC_CTL,
 			   FIELD_PREP(SPI_NFI_DATA_READ_WR_MODE, wr_mode));
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_PG_CTL2, 0x0);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_clear_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG,
 				SPI_NFI_READ_MODE);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG,
 				 SPI_NFI_OPMODE,
 				 FIELD_PREP(SPI_NFI_OPMODE, 3));
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG,
 			      SPI_NFI_DMA_MODE);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_CMD, 0x80);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_clear_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CON,
 				SPI_NFI_WR_TRIG);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CON,
 			      SPI_NFI_WR_TRIG);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_read_poll_timeout(as_ctrl->regmap_nfi, REG_SPI_NFI_INTR,
 				       val, (val & SPI_NFI_AHB_DONE), 0,
 				       1 * USEC_PER_SEC);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	err = regmap_read_poll_timeout(as_ctrl->regmap_nfi,
 				       REG_SPI_NFI_SNF_STA_CTL1, val,
 				       (val & SPI_NFI_LOAD_TO_CACHE_DONE),
 				       0, 1 * USEC_PER_SEC);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
 	/*
 	 * SPI_NFI_LOAD_TO_CACHE_DONE bit must be written at the end
@@ -875,13 +877,20 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
 				SPI_NFI_LOAD_TO_CACHE_DONE,
 				SPI_NFI_LOAD_TO_CACHE_DONE);
 	if (err)
-		return err;
+		goto error_dma_unmap;
 
+	dma_unmap_single(as_ctrl->dev, dma_addr, SPI_NAND_CACHE_SIZE,
+			 DMA_TO_DEVICE);
 	err = airoha_snand_set_mode(as_ctrl, SPI_MODE_MANUAL);
 	if (err < 0)
 		return err;
 
 	return len;
+
+error_dma_unmap:
+	dma_unmap_single(as_ctrl->dev, dma_addr, SPI_NAND_CACHE_SIZE,
+			 DMA_TO_DEVICE);
+	return err;
 }
 
 static int airoha_snand_exec_op(struct spi_mem *mem,
@@ -956,42 +965,20 @@ static const struct spi_controller_mem_ops airoha_snand_mem_ops = {
 static int airoha_snand_setup(struct spi_device *spi)
 {
 	struct airoha_snand_ctrl *as_ctrl;
-	struct airoha_snand_dev *as_dev;
-
-	as_ctrl = spi_controller_get_devdata(spi->controller);
-
-	as_dev = devm_kzalloc(as_ctrl->dev, sizeof(*as_dev), GFP_KERNEL);
-	if (!as_dev)
-		return -ENOMEM;
+	u8 *txrx_buf;
 
 	/* prepare device buffer */
-	as_dev->buf_len = SPI_NAND_CACHE_SIZE;
-	as_dev->txrx_buf = devm_kzalloc(as_ctrl->dev, as_dev->buf_len,
-					GFP_KERNEL);
-	if (!as_dev->txrx_buf)
-		return -ENOMEM;
-
-	as_dev->dma_addr = dma_map_single(as_ctrl->dev, as_dev->txrx_buf,
-					  as_dev->buf_len, DMA_BIDIRECTIONAL);
-	if (dma_mapping_error(as_ctrl->dev, as_dev->dma_addr))
+	as_ctrl = spi_controller_get_devdata(spi->controller);
+	txrx_buf = devm_kzalloc(as_ctrl->dev, SPI_NAND_CACHE_SIZE,
+				GFP_KERNEL);
+	if (!txrx_buf)
 		return -ENOMEM;
 
-	spi_set_ctldata(spi, as_dev);
+	spi_set_ctldata(spi, txrx_buf);
 
 	return 0;
 }
 
-static void airoha_snand_cleanup(struct spi_device *spi)
-{
-	struct airoha_snand_dev *as_dev = spi_get_ctldata(spi);
-	struct airoha_snand_ctrl *as_ctrl;
-
-	as_ctrl = spi_controller_get_devdata(spi->controller);
-	dma_unmap_single(as_ctrl->dev, as_dev->dma_addr,
-			 as_dev->buf_len, DMA_BIDIRECTIONAL);
-	spi_set_ctldata(spi, NULL);
-}
-
 static int airoha_snand_nfi_setup(struct airoha_snand_ctrl *as_ctrl)
 {
 	u32 val, sec_size, sec_num;
@@ -1093,7 +1080,6 @@ static int airoha_snand_probe(struct platform_device *pdev)
 	ctrl->bits_per_word_mask = SPI_BPW_MASK(8);
 	ctrl->mode_bits = SPI_RX_DUAL;
 	ctrl->setup = airoha_snand_setup;
-	ctrl->cleanup = airoha_snand_cleanup;
 	device_set_node(&ctrl->dev, dev_fwnode(dev));
 
 	err = airoha_snand_nfi_setup(as_ctrl);

-- 
2.46.0


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

* Re: (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules
  2024-09-13 21:07 [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules Lorenzo Bianconi
                   ` (3 preceding siblings ...)
  2024-09-13 21:07 ` [PATCH 4/4] spi: airoha: do not keep {tx,rx} dma buffer always mapped Lorenzo Bianconi
@ 2024-09-19  8:29 ` Mark Brown
  2024-09-19  8:59   ` Lorenzo Bianconi
  4 siblings, 1 reply; 13+ messages in thread
From: Mark Brown @ 2024-09-19  8:29 UTC (permalink / raw)
  To: Ray Liu, AngeloGioacchino Del Regno, Andy Shevchenko,
	Lorenzo Bianconi
  Cc: Christian Marangi, linux-arm-kernel, linux-spi, upstream

On Fri, 13 Sep 2024 23:07:12 +0200, Lorenzo Bianconi wrote:
> Fix errors detected running mtd_test kernel test modules.
> 

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/4] spi: airoha: fix dirmap_{read,write} operations
      commit: 2e6bbfe7b0c0607001b784082c2685b134174fac
[2/4] spi: airoha: fix airoha_snand_{write,read}_data data_len estimation
      commit: 0e58637eb968c636725dcd6c7055249b4e5326fb

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


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

* Re: (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules
  2024-09-19  8:29 ` (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules Mark Brown
@ 2024-09-19  8:59   ` Lorenzo Bianconi
  2024-09-19  9:05     ` Mark Brown
  0 siblings, 1 reply; 13+ messages in thread
From: Lorenzo Bianconi @ 2024-09-19  8:59 UTC (permalink / raw)
  To: Mark Brown
  Cc: Ray Liu, AngeloGioacchino Del Regno, Andy Shevchenko,
	Christian Marangi, linux-arm-kernel, linux-spi, upstream

[-- Attachment #1: Type: text/plain, Size: 1505 bytes --]

> On Fri, 13 Sep 2024 23:07:12 +0200, Lorenzo Bianconi wrote:
> > Fix errors detected running mtd_test kernel test modules.
> > 
> 
> Applied to
> 
>    https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
> 
> Thanks!
> 
> [1/4] spi: airoha: fix dirmap_{read,write} operations
>       commit: 2e6bbfe7b0c0607001b784082c2685b134174fac
> [2/4] spi: airoha: fix airoha_snand_{write,read}_data data_len estimation
>       commit: 0e58637eb968c636725dcd6c7055249b4e5326fb
> 
> All being well this means that it will be integrated into the linux-next
> tree (usually sometime in the next 24 hours) and sent to Linus during
> the next merge window (or sooner if it is a bug fix), however if
> problems are discovered then the patch may be dropped or reverted.
> 
> You may get further e-mails resulting from automated or manual testing
> and review of the tree, please engage with people reporting problems and
> send followup patches addressing any issues that are reported if needed.
> 
> If any updates are required or you are submitting further changes they
> should be sent as incremental updates against current git, existing
> patches will not be replaced.
> 
> Please add any relevant lists and maintainers to the CCs when replying
> to this mail.
> 
> Thanks,
> Mark
> 

Hi Mark,

I think we should include even patch 3/4 since it fixes some errors in
mtd_oobtest kernel test module (and even some ubifs reported errors).

Regards,
Lorenzo

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules
  2024-09-19  8:59   ` Lorenzo Bianconi
@ 2024-09-19  9:05     ` Mark Brown
  2024-09-19  9:16       ` Lorenzo Bianconi
  0 siblings, 1 reply; 13+ messages in thread
From: Mark Brown @ 2024-09-19  9:05 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Ray Liu, AngeloGioacchino Del Regno, Andy Shevchenko,
	Christian Marangi, linux-arm-kernel, linux-spi, upstream

[-- Attachment #1: Type: text/plain, Size: 325 bytes --]

On Thu, Sep 19, 2024 at 10:59:20AM +0200, Lorenzo Bianconi wrote:

> I think we should include even patch 3/4 since it fixes some errors in
> mtd_oobtest kernel test module (and even some ubifs reported errors).

Your changelog doesn't actually describe what might be fixed there and
it's not obvious from the change itself.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules
  2024-09-19  9:05     ` Mark Brown
@ 2024-09-19  9:16       ` Lorenzo Bianconi
  2024-09-19 10:44         ` Mark Brown
  0 siblings, 1 reply; 13+ messages in thread
From: Lorenzo Bianconi @ 2024-09-19  9:16 UTC (permalink / raw)
  To: Mark Brown
  Cc: Ray Liu, AngeloGioacchino Del Regno, Andy Shevchenko,
	Christian Marangi, linux-arm-kernel, linux-spi, upstream

[-- Attachment #1: Type: text/plain, Size: 531 bytes --]

> On Thu, Sep 19, 2024 at 10:59:20AM +0200, Lorenzo Bianconi wrote:
> 
> > I think we should include even patch 3/4 since it fixes some errors in
> > mtd_oobtest kernel test module (and even some ubifs reported errors).
> 
> Your changelog doesn't actually describe what might be fixed there and
> it's not obvious from the change itself.

sorry to be no clear on it. Patches 1/4, 2/4 and 3/4 are fixing outstanding
issues while patch 4/4 is an optimization and we can apply it later on, up to
you.

Regards,
Lorenzo

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules
  2024-09-19  9:16       ` Lorenzo Bianconi
@ 2024-09-19 10:44         ` Mark Brown
  2024-09-19 11:18           ` Lorenzo Bianconi
  0 siblings, 1 reply; 13+ messages in thread
From: Mark Brown @ 2024-09-19 10:44 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Ray Liu, AngeloGioacchino Del Regno, Andy Shevchenko,
	Christian Marangi, linux-arm-kernel, linux-spi, upstream

[-- Attachment #1: Type: text/plain, Size: 578 bytes --]

On Thu, Sep 19, 2024 at 11:16:22AM +0200, Lorenzo Bianconi wrote:
> > On Thu, Sep 19, 2024 at 10:59:20AM +0200, Lorenzo Bianconi wrote:

> > Your changelog doesn't actually describe what might be fixed there and
> > it's not obvious from the change itself.

> sorry to be no clear on it. Patches 1/4, 2/4 and 3/4 are fixing outstanding
> issues while patch 4/4 is an optimization and we can apply it later on, up to
> you.

Yes, what I'm saying is that I can't tell what those issues might be for
patch 3.  The changelog for the patch should describe what it's supposed
to fix.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules
  2024-09-19 10:44         ` Mark Brown
@ 2024-09-19 11:18           ` Lorenzo Bianconi
  2024-09-19 12:29             ` Mark Brown
  0 siblings, 1 reply; 13+ messages in thread
From: Lorenzo Bianconi @ 2024-09-19 11:18 UTC (permalink / raw)
  To: Mark Brown
  Cc: Ray Liu, AngeloGioacchino Del Regno, Andy Shevchenko,
	Christian Marangi, linux-arm-kernel, linux-spi, upstream

[-- Attachment #1: Type: text/plain, Size: 1144 bytes --]

> On Thu, Sep 19, 2024 at 11:16:22AM +0200, Lorenzo Bianconi wrote:
> > > On Thu, Sep 19, 2024 at 10:59:20AM +0200, Lorenzo Bianconi wrote:
> 
> > > Your changelog doesn't actually describe what might be fixed there and
> > > it's not obvious from the change itself.
> 
> > sorry to be no clear on it. Patches 1/4, 2/4 and 3/4 are fixing outstanding
> > issues while patch 4/4 is an optimization and we can apply it later on, up to
> > you.
> 
> Yes, what I'm saying is that I can't tell what those issues might be for
> patch 3.  The changelog for the patch should describe what it's supposed
> to fix.

ack. The issue is the 'read cache' logic present in the vendor sdk codebase I
added in the upstream driver is buggy and it is introducing errors reported
by mtd_oobtest kernel test module. Since we do not get any read/write speed
improvement using the cache, in order to fix the mtd_oobtest test, I decided
to get rid of the 'read cache' since it is not useful. Now the driver is passing
all the tests available in mtd_test suite.
Do you want me to repost just this patch updating the commit log?

Regards,
Lorenzo

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules
  2024-09-19 11:18           ` Lorenzo Bianconi
@ 2024-09-19 12:29             ` Mark Brown
  2024-09-19 12:36               ` Lorenzo Bianconi
  0 siblings, 1 reply; 13+ messages in thread
From: Mark Brown @ 2024-09-19 12:29 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Ray Liu, AngeloGioacchino Del Regno, Andy Shevchenko,
	Christian Marangi, linux-arm-kernel, linux-spi, upstream

[-- Attachment #1: Type: text/plain, Size: 767 bytes --]

On Thu, Sep 19, 2024 at 01:18:09PM +0200, Lorenzo Bianconi wrote:

> ack. The issue is the 'read cache' logic present in the vendor sdk codebase I
> added in the upstream driver is buggy and it is introducing errors reported
> by mtd_oobtest kernel test module. Since we do not get any read/write speed
> improvement using the cache, in order to fix the mtd_oobtest test, I decided
> to get rid of the 'read cache' since it is not useful. Now the driver is passing
> all the tests available in mtd_test suite.
> Do you want me to repost just this patch updating the commit log?

It'd be a bit easier to resend this and patch 4 but yes.  Please mention
exactly what the errors that mtd_oobtest finds are and ideally why
removing the cache fixes them in the changelog.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules
  2024-09-19 12:29             ` Mark Brown
@ 2024-09-19 12:36               ` Lorenzo Bianconi
  0 siblings, 0 replies; 13+ messages in thread
From: Lorenzo Bianconi @ 2024-09-19 12:36 UTC (permalink / raw)
  To: Mark Brown
  Cc: Ray Liu, AngeloGioacchino Del Regno, Andy Shevchenko,
	Christian Marangi, linux-arm-kernel, linux-spi, upstream

[-- Attachment #1: Type: text/plain, Size: 876 bytes --]

On Sep 19, Mark Brown wrote:
> On Thu, Sep 19, 2024 at 01:18:09PM +0200, Lorenzo Bianconi wrote:
> 
> > ack. The issue is the 'read cache' logic present in the vendor sdk codebase I
> > added in the upstream driver is buggy and it is introducing errors reported
> > by mtd_oobtest kernel test module. Since we do not get any read/write speed
> > improvement using the cache, in order to fix the mtd_oobtest test, I decided
> > to get rid of the 'read cache' since it is not useful. Now the driver is passing
> > all the tests available in mtd_test suite.
> > Do you want me to repost just this patch updating the commit log?
> 
> It'd be a bit easier to resend this and patch 4 but yes.  Please mention
> exactly what the errors that mtd_oobtest finds are and ideally why
> removing the cache fixes them in the changelog.

ack, I will do.

Regards,
Lorenzo

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

end of thread, other threads:[~2024-09-19 12:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-13 21:07 [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules Lorenzo Bianconi
2024-09-13 21:07 ` [PATCH 1/4] spi: airoha: fix dirmap_{read,write} operations Lorenzo Bianconi
2024-09-13 21:07 ` [PATCH 2/4] spi: airoha: fix airoha_snand_{write,read}_data data_len estimation Lorenzo Bianconi
2024-09-13 21:07 ` [PATCH 3/4] spi: airoha: remove read cache in airoha_snand_dirmap_read Lorenzo Bianconi
2024-09-13 21:07 ` [PATCH 4/4] spi: airoha: do not keep {tx,rx} dma buffer always mapped Lorenzo Bianconi
2024-09-19  8:29 ` (subset) [PATCH 0/4] spi: airoha: Fix errors reported by mtd_test kernel modules Mark Brown
2024-09-19  8:59   ` Lorenzo Bianconi
2024-09-19  9:05     ` Mark Brown
2024-09-19  9:16       ` Lorenzo Bianconi
2024-09-19 10:44         ` Mark Brown
2024-09-19 11:18           ` Lorenzo Bianconi
2024-09-19 12:29             ` Mark Brown
2024-09-19 12:36               ` Lorenzo Bianconi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).