From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932513AbcHIMuM (ORCPT ); Tue, 9 Aug 2016 08:50:12 -0400 Received: from bear.ext.ti.com ([198.47.19.11]:48030 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752711AbcHIMuJ (ORCPT ); Tue, 9 Aug 2016 08:50:09 -0400 Subject: Re: [PATCH v5] spi: spi-ti-qspi: Add DMA support for QSPI mmap read To: Mark Brown References: <20160809110311.13521-1-vigneshr@ti.com> <20160809113329.GA9347@sirena.org.uk> CC: , , From: Vignesh R Message-ID: <13e676c2-7e2f-d1c5-5312-bc2e11a6b6a1@ti.com> Date: Tue, 9 Aug 2016 18:20:01 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160809113329.GA9347@sirena.org.uk> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday 09 August 2016 05:03 PM, Mark Brown wrote: > On Tue, Aug 09, 2016 at 04:33:11PM +0530, Vignesh R wrote: > >> +static int ti_qspi_map_buf(struct ti_qspi *qspi, void *buf, >> + unsigned int len, struct sg_table *sgt) >> +{ >> + unsigned int max_seg_size = >> + dma_get_max_seg_size(qspi->rx_chan->device->dev); >> + unsigned int desc_len = min_t(int, max_seg_size, PAGE_SIZE); >> + int sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len); >> + struct page *vm_page; >> + size_t min; >> + int i, ret; >> + >> + ret = sg_alloc_table(sgt, sgs, GFP_KERNEL); >> + if (ret) >> + return ret; >> + >> + for (i = 0; i < sgs; i++) { >> + min = min_t(size_t, len, desc_len - >> + offset_in_page(buf)); >> + vm_page = kmap_to_page(buf); >> + if (!vm_page) { >> + sg_free_table(sgt); >> + return -ENOMEM; >> + } >> + sg_set_page(&sgt->sgl[i], vm_page, min, >> + offset_in_page(buf)); >> + buf += min; >> + len -= min; > > This looks a lot like the core code for mapping the buffers - why is > this open coded rather than reused? According to this thread[1], converting virtual address pointer into scatterlist which is then DMA mapped is unsafe on systems with certain cache architecture. Hence, I added code to handle kmap buffers inside the driver rather than updating generic spi-core code. If its okay to update the spi_map_buf() to handle kmap buffers as above then I can submit the patch accordingly. [1]https://patchwork.kernel.org/patch/8712161/ -- Regards Vignesh