From patchwork Mon May 25 12:44:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sperl X-Patchwork-Id: 6474461 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A11309F401 for ; Mon, 25 May 2015 12:45:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8E477203DC for ; Mon, 25 May 2015 12:45:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 49574203EC for ; Mon, 25 May 2015 12:45:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750771AbbEYMpH (ORCPT ); Mon, 25 May 2015 08:45:07 -0400 Received: from 212-186-180-163.dynamic.surfer.at ([212.186.180.163]:50909 "EHLO cgate.sperl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750732AbbEYMpH (ORCPT ); Mon, 25 May 2015 08:45:07 -0400 Received: from raspb.intern.sperl.org (account martin@sperl.org [10.10.10.32] verified) by sperl.org (CommuniGate Pro SMTP 6.1.2) with ESMTPSA id 6330060; Mon, 25 May 2015 12:45:00 +0000 From: kernel@martin.sperl.org To: Mark Brown , Stephen Warren , Lee Jones , linux-spi@vger.kernel.org, linux-rpi-kernel@lists.infradead.org Cc: Martin Sperl Subject: [PATCH 3/4] spi: add flags SPI_MASTER_MUST_*_SG to api Date: Mon, 25 May 2015 12:44:25 +0000 Message-Id: <1432557867-2427-4-git-send-email-kernel@martin.sperl.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1432557867-2427-1-git-send-email-kernel@martin.sperl.org> References: <2B971A09-33E3-42BC-B13D-49B6DD3D2E7A@martin.sperl.org> <1432557867-2427-1-git-send-email-kernel@martin.sperl.org> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Sperl This avoid unnecessary mapping of null pages in sg_lists for masters that do not need a sg_list when rx_buf/tx_buff == NULL avoid. Only spi-masters that require a mapped scatter-gather map need to set this, but they would not need to set SPI_MASTER_MUST_RX/TX. Signed-off-by: Martin Sperl --- drivers/spi/spi.c | 38 +++++++++++++++++++------------------- include/linux/spi/spi.h | 2 ++ 2 files changed, 21 insertions(+), 19 deletions(-) Note that this is an optional patch to avoid the overhead for spi_masters that do not need the dummy-page functionality. diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 7e1a12c..9205928 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -570,25 +570,25 @@ static int __spi_map_msg(struct spi_master *master, struct spi_message *msg) if (!master->can_dma(master, msg->spi, xfer)) continue; - /* potentially add a flag to spi_master - * (SPI_MASTER_MUST_TX_SG) to avoid unnecessary mapping - */ - ret = spi_map_buf(master, tx_dev, &xfer->tx_sg, - (void *)xfer->tx_buf, xfer->len, - DMA_TO_DEVICE); - if (ret != 0) - return ret; - - /* potentially add a flag to spi_master - * (SPI_MASTER_MUST_RX_SG) to avoid unnecessary mapping - */ - ret = spi_map_buf(master, rx_dev, &xfer->rx_sg, - xfer->rx_buf, xfer->len, - DMA_FROM_DEVICE); - if (ret != 0) { - spi_unmap_buf(master, tx_dev, &xfer->tx_sg, - DMA_TO_DEVICE); - return ret; + if (xfer->tx_buf || + (master->flags & SPI_MASTER_MUST_TX_SG)) { + ret = spi_map_buf(master, tx_dev, &xfer->tx_sg, + (void *)xfer->tx_buf, xfer->len, + DMA_TO_DEVICE); + if (ret != 0) + return ret; + } + + if (xfer->rx_buf || + (master->flags & SPI_MASTER_MUST_RX_SG)) { + ret = spi_map_buf(master, rx_dev, &xfer->rx_sg, + xfer->rx_buf, xfer->len, + DMA_FROM_DEVICE); + if (ret != 0) { + spi_unmap_buf(master, tx_dev, &xfer->tx_sg, + DMA_TO_DEVICE); + return ret; + } } } diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 9ffa506..8b70419 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -357,6 +357,8 @@ struct spi_master { #define SPI_MASTER_NO_TX BIT(2) /* can't do buffer write */ #define SPI_MASTER_MUST_RX BIT(3) /* requires rx */ #define SPI_MASTER_MUST_TX BIT(4) /* requires tx */ +#define SPI_MASTER_MUST_RX_SG BIT(5) /* requires rx sg_list */ +#define SPI_MASTER_MUST_TX_SG BIT(6) /* requires tx sg_list */ /* lock and mutex for SPI bus locking */ spinlock_t bus_lock_spinlock;