From patchwork Wed Oct 8 04:38:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ray Jui X-Patchwork-Id: 38446 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A82A52057C for ; Wed, 8 Oct 2014 04:38:16 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id cc10sf3599143wib.7 for ; Tue, 07 Oct 2014 21:38:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=4+K4JAy567YO5FeC5RsHbliYvWUuWr4Kq/jj8ichmwo=; b=OKh1duJGZTgIv4EYs1bZSBYcC5oRI9jeea1pZys9DtTsWj7o5JXVikccl6IbddQcq4 TcymY0IqASoHGTDpF5Nc3zQcBnTnmU4uBSHG1Q5UmsbHGbZ+upWE5YFiCqWXFapixJvh GRUxoMRUm2NCHfPARbjb8KmNR6YRIa8dP5cCyvsPdyI4EpkJdCKD5OY165I876+9kzrq PJ9CUGrMRBkv7X90df1Y75xBSjV2Tjlvw29RJcBvFLty5/zDUEK6CfE8wHK/Cbljpz5G 0cpHV65l4WWFl9btb3vIxmQmK1P0f1TXeKWfx1AEokt3iB1nkG/c/h0LrWSkpFjK17TD RZEA== X-Gm-Message-State: ALoCoQn5pGY4pJgFNWjy7n9OvllwvCvnujnXvTYNoUXpziz6+UqOJInAQBHoL9zqqAwq3sACCA5g X-Received: by 10.112.220.8 with SMTP id ps8mr1195260lbc.5.1412743095412; Tue, 07 Oct 2014 21:38:15 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.169 with SMTP id ld9ls16510lab.12.gmail; Tue, 07 Oct 2014 21:38:15 -0700 (PDT) X-Received: by 10.152.234.76 with SMTP id uc12mr8637107lac.50.1412743094993; Tue, 07 Oct 2014 21:38:14 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com [209.85.215.51]) by mx.google.com with ESMTPS id t10si13735225lat.82.2014.10.07.21.38.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Oct 2014 21:38:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id ge10so7527159lab.24 for ; Tue, 07 Oct 2014 21:38:14 -0700 (PDT) X-Received: by 10.112.5.133 with SMTP id s5mr464188lbs.102.1412743094737; Tue, 07 Oct 2014 21:38:14 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.130.169 with SMTP id of9csp459311lbb; Tue, 7 Oct 2014 21:38:13 -0700 (PDT) X-Received: by 10.68.222.168 with SMTP id qn8mr7883041pbc.114.1412743093183; Tue, 07 Oct 2014 21:38:13 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k5si14630339pdn.89.2014.10.07.21.38.12 for ; Tue, 07 Oct 2014 21:38:13 -0700 (PDT) Received-SPF: none (google.com: linux-spi-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754692AbaJHEiL (ORCPT + 2 others); Wed, 8 Oct 2014 00:38:11 -0400 Received: from mail-gw3-out.broadcom.com ([216.31.210.64]:29304 "EHLO mail-gw3-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754547AbaJHEiK (ORCPT ); Wed, 8 Oct 2014 00:38:10 -0400 X-IronPort-AV: E=Sophos;i="5.04,674,1406617200"; d="scan'208";a="47521092" Received: from irvexchcas06.broadcom.com (HELO IRVEXCHCAS06.corp.ad.broadcom.com) ([10.9.208.53]) by mail-gw3-out.broadcom.com with ESMTP; 07 Oct 2014 21:40:44 -0700 Received: from IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) by IRVEXCHCAS06.corp.ad.broadcom.com (10.9.208.53) with Microsoft SMTP Server (TLS) id 14.3.174.1; Tue, 7 Oct 2014 21:38:16 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) with Microsoft SMTP Server id 14.3.174.1; Tue, 7 Oct 2014 21:38:16 -0700 Received: from mail.broadcom.com (lbrmn-lnxub44.ric.broadcom.com [10.136.8.49]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 57B7440FED; Tue, 7 Oct 2014 21:37:59 -0700 (PDT) From: Ray Jui To: Mark Brown CC: , , JD Zheng , Scott Branden , Ray Jui Subject: [PATCH] spi: pl022: Fix broken spidev when DMA is enabled Date: Tue, 7 Oct 2014 21:38:47 -0700 Message-ID: <1412743127-4523-1-git-send-email-rjui@broadcom.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rjui@broadcom.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The PL022 SPI driver maps the DMA RX buffer before the DMA TX buffer. In most cases, the sequence of the mapping does not matter. But in cases where TX and RX happen to use the same buffer, e.g., spidev, it causes the cached TX data not written to memory, because the same memory has been marked invalid when dma_map_sg on the RX buffer is called The solution is to reverse the sequence so it maps the TX buffer before the RX buffer Signed-off-by: Ray Jui Reviewed-by: JD (Jiandong) Zheng Tested-by: Scott Branden Reviewed-by: Scott Branden --- drivers/spi/spi-pl022.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c index 1189cfd..edb7298 100644 --- a/drivers/spi/spi-pl022.c +++ b/drivers/spi/spi-pl022.c @@ -773,10 +773,10 @@ static void *next_transfer(struct pl022 *pl022) static void unmap_free_dma_scatter(struct pl022 *pl022) { /* Unmap and free the SG tables */ - dma_unmap_sg(pl022->dma_tx_channel->device->dev, pl022->sgt_tx.sgl, - pl022->sgt_tx.nents, DMA_TO_DEVICE); dma_unmap_sg(pl022->dma_rx_channel->device->dev, pl022->sgt_rx.sgl, pl022->sgt_rx.nents, DMA_FROM_DEVICE); + dma_unmap_sg(pl022->dma_tx_channel->device->dev, pl022->sgt_tx.sgl, + pl022->sgt_tx.nents, DMA_TO_DEVICE); sg_free_table(&pl022->sgt_rx); sg_free_table(&pl022->sgt_tx); } @@ -1026,16 +1026,16 @@ static int configure_dma(struct pl022 *pl022) pl022->cur_transfer->len, &pl022->sgt_tx); /* Map DMA buffers */ - rx_sglen = dma_map_sg(rxchan->device->dev, pl022->sgt_rx.sgl, - pl022->sgt_rx.nents, DMA_FROM_DEVICE); - if (!rx_sglen) - goto err_rx_sgmap; - tx_sglen = dma_map_sg(txchan->device->dev, pl022->sgt_tx.sgl, pl022->sgt_tx.nents, DMA_TO_DEVICE); if (!tx_sglen) goto err_tx_sgmap; + rx_sglen = dma_map_sg(rxchan->device->dev, pl022->sgt_rx.sgl, + pl022->sgt_rx.nents, DMA_FROM_DEVICE); + if (!rx_sglen) + goto err_rx_sgmap; + /* Send both scatterlists */ rxdesc = dmaengine_prep_slave_sg(rxchan, pl022->sgt_rx.sgl, @@ -1070,12 +1070,12 @@ err_txdesc: dmaengine_terminate_all(txchan); err_rxdesc: dmaengine_terminate_all(rxchan); + dma_unmap_sg(rxchan->device->dev, pl022->sgt_rx.sgl, + pl022->sgt_rx.nents, DMA_FROM_DEVICE); +err_rx_sgmap: dma_unmap_sg(txchan->device->dev, pl022->sgt_tx.sgl, pl022->sgt_tx.nents, DMA_TO_DEVICE); err_tx_sgmap: - dma_unmap_sg(rxchan->device->dev, pl022->sgt_rx.sgl, - pl022->sgt_tx.nents, DMA_FROM_DEVICE); -err_rx_sgmap: sg_free_table(&pl022->sgt_tx); err_alloc_tx_sg: sg_free_table(&pl022->sgt_rx);