[v3,1/2] spi: Add DMA support for spi_flash_read()
diff mbox

Message ID 20160607081810.6640-2-vigneshr@ti.com
State New
Headers show

Commit Message

Vignesh Raghavendra June 7, 2016, 8:18 a.m. UTC
Few SPI devices provide accelerated read interfaces to read from
SPI-NOR flash devices. These hardwares also support DMA to transfer data
from flash to memory either via mem-to-mem DMA or dedicated slave DMA
channels. Hence, add support for DMA in order to improve throughput and
reduce CPU load.
Use spi_map_buf() to get sg table for the buffer and pass it to SPI
driver.

Signed-off-by: Vignesh R <vigneshr@ti.com>
---

v3: No changes.
v2: use cur_msg_mapped flag to indicate success/failure of spi_map_buf()


 drivers/spi/spi.c       | 14 ++++++++++++++
 include/linux/spi/spi.h |  4 ++++
 2 files changed, 18 insertions(+)

Comments

kernel test robot June 7, 2016, 10:29 p.m. UTC | #1
Hi,

[auto build test ERROR on spi/for-next]
[also build test ERROR on v4.7-rc2 next-20160607]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Vignesh-R/spi-Add-DMA-support-for-ti-qspi/20160607-162134
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi for-next
config: m32r-allyesconfig (attached as .config)
compiler: m32r-linux-gcc (GCC) 4.9.0
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=m32r 

All errors (new ones prefixed by >>):

   drivers/spi/spi.c: In function 'spi_flash_read':
>> drivers/spi/spi.c:2758:3: error: implicit declaration of function 'spi_map_buf' [-Werror=implicit-function-declaration]
      ret = spi_map_buf(master, rx_dev, &msg->rx_sg,
      ^
>> drivers/spi/spi.c:2766:3: error: implicit declaration of function 'spi_unmap_buf' [-Werror=implicit-function-declaration]
      spi_unmap_buf(master, rx_dev, &msg->rx_sg,
      ^
   cc1: some warnings being treated as errors

vim +/spi_map_buf +2758 drivers/spi/spi.c

  2752			}
  2753		}
  2754	
  2755		mutex_lock(&master->bus_lock_mutex);
  2756		if (master->dma_rx) {
  2757			rx_dev = master->dma_rx->device->dev;
> 2758			ret = spi_map_buf(master, rx_dev, &msg->rx_sg,
  2759					  msg->buf, msg->len,
  2760					  DMA_FROM_DEVICE);
  2761			if (!ret)
  2762				msg->cur_msg_mapped = true;
  2763		}
  2764		ret = master->spi_flash_read(spi, msg);
  2765		if (msg->cur_msg_mapped)
> 2766			spi_unmap_buf(master, rx_dev, &msg->rx_sg,
  2767				      DMA_FROM_DEVICE);
  2768		mutex_unlock(&master->bus_lock_mutex);
  2769	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Vignesh Raghavendra June 8, 2016, 6:51 a.m. UTC | #2
On Wednesday 08 June 2016 03:59 AM, kbuild test robot wrote:
> Hi,
> 
> [auto build test ERROR on spi/for-next]
> [also build test ERROR on v4.7-rc2 next-20160607]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
> 
> url:    https://github.com/0day-ci/linux/commits/Vignesh-R/spi-Add-DMA-support-for-ti-qspi/20160607-162134
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi for-next
> config: m32r-allyesconfig (attached as .config)
> compiler: m32r-linux-gcc (GCC) 4.9.0
> reproduce:
>         wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # save the attached .config to linux build tree
>         make.cross ARCH=m32r 
> 
> All errors (new ones prefixed by >>):
> 
>    drivers/spi/spi.c: In function 'spi_flash_read':
>>> drivers/spi/spi.c:2758:3: error: implicit declaration of function 'spi_map_buf' [-Werror=implicit-function-declaration]
>       ret = spi_map_buf(master, rx_dev, &msg->rx_sg,
>       ^
>>> drivers/spi/spi.c:2766:3: error: implicit declaration of function 'spi_unmap_buf' [-Werror=implicit-function-declaration]
>       spi_unmap_buf(master, rx_dev, &msg->rx_sg,
>       ^
>    cc1: some warnings being treated as errors
> 


Oops, posted v4 fixing these errors.

Patch
diff mbox

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 77e6e45951f4..da2cbe205654 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2725,6 +2725,7 @@  int spi_flash_read(struct spi_device *spi,
 
 {
 	struct spi_master *master = spi->master;
+	struct device *rx_dev = NULL;
 	int ret;
 
 	if ((msg->opcode_nbits == SPI_NBITS_DUAL ||
@@ -2750,9 +2751,22 @@  int spi_flash_read(struct spi_device *spi,
 			return ret;
 		}
 	}
+
 	mutex_lock(&master->bus_lock_mutex);
+	if (master->dma_rx) {
+		rx_dev = master->dma_rx->device->dev;
+		ret = spi_map_buf(master, rx_dev, &msg->rx_sg,
+				  msg->buf, msg->len,
+				  DMA_FROM_DEVICE);
+		if (!ret)
+			msg->cur_msg_mapped = true;
+	}
 	ret = master->spi_flash_read(spi, msg);
+	if (msg->cur_msg_mapped)
+		spi_unmap_buf(master, rx_dev, &msg->rx_sg,
+			      DMA_FROM_DEVICE);
 	mutex_unlock(&master->bus_lock_mutex);
+
 	if (master->auto_runtime_pm)
 		pm_runtime_put(master->dev.parent);
 
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 1f03483f61e5..7b53af4ba5f8 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -1143,6 +1143,8 @@  static inline ssize_t spi_w8r16be(struct spi_device *spi, u8 cmd)
  * @opcode_nbits: number of lines to send opcode
  * @addr_nbits: number of lines to send address
  * @data_nbits: number of lines for data
+ * @rx_sg: Scatterlist for receive data read from flash
+ * @cur_msg_mapped: message has been mapped for DMA
  */
 struct spi_flash_read_message {
 	void *buf;
@@ -1155,6 +1157,8 @@  struct spi_flash_read_message {
 	u8 opcode_nbits;
 	u8 addr_nbits;
 	u8 data_nbits;
+	struct sg_table rx_sg;
+	bool cur_msg_mapped;
 };
 
 /* SPI core interface for flash read support */