From patchwork Thu Jan 26 16:21:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kurtz X-Patchwork-Id: 9539723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ACD85604A0 for ; Thu, 26 Jan 2017 16:23:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D2BA204C1 for ; Thu, 26 Jan 2017 16:23:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9150D27F9F; Thu, 26 Jan 2017 16:23:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 171E6204C1 for ; Thu, 26 Jan 2017 16:23:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753269AbdAZQW3 (ORCPT ); Thu, 26 Jan 2017 11:22:29 -0500 Received: from mail-pg0-f53.google.com ([74.125.83.53]:33133 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753071AbdAZQW1 (ORCPT ); Thu, 26 Jan 2017 11:22:27 -0500 Received: by mail-pg0-f53.google.com with SMTP id 204so73691539pge.0 for ; Thu, 26 Jan 2017 08:22:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=PnTiTX2g6UKdiC6uwd8b6oyUYFFXHeO9Mh7XK9snvS0=; b=espJGe4+WEzaaMycq/dla1pET3qJyRfa180Sv5QHtD6ql3uZPZojUikAg4A+LMl0qL YzWJO6BitWkgKiTQQYvHhPWaltV0IFNHJZt03lOC1GvtDXiRXmRmf/wYeYFDDjTlY/Pk NSQILVO0jsXle/eMqq099BpnNgrRU+Kx8SEtM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PnTiTX2g6UKdiC6uwd8b6oyUYFFXHeO9Mh7XK9snvS0=; b=YOlSmjvKPJP+ttNHWfe6s1fCTcrUSn2MFVqWmFHVTCt2K9DxEHxShK1Em0HNvBcF6i 81dr7tg7bELGOKWdJt2idGUujGyusNSzzg+7sQT37kzGxyDvd4259E1nGaLHowggrIDJ Y6HVyhW75RPXa1JoxY4zKs/yJ50bu6lUE9m7aQx3sIyU0BYQcmQ83VFxFd8nr3+3g7dI XAA0NrFGR9lfgRaMJyKApmLOfMnl5N53ONBQQLXP2009oyZxPypsAn/wn0Vd0BlzK1rE XzPNV82MRHy+yec9CwmvVqgLAugKNmlvTFUh4atwuivh7GwpJ60Y95YoybcBH6q6qjRJ bmmA== X-Gm-Message-State: AIkVDXI8A3Pnf///El7DHrCOuYQk6gHy7lh4kfasll9BQLtGtKmvcPEFz8Z3Yt9HST1BDzHd X-Received: by 10.99.51.76 with SMTP id z73mr4036739pgz.137.1485447728945; Thu, 26 Jan 2017 08:22:08 -0800 (PST) Received: from djkurtz-z840.tpe.corp.google.com ([172.30.210.11]) by smtp.gmail.com with ESMTPSA id z77sm4607751pfk.47.2017.01.26.08.22.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Jan 2017 08:22:08 -0800 (PST) From: Daniel Kurtz Cc: dtor@chromium.org, groeck@chromium.org, drinkcat@chromium.org, Robin Murphy , Daniel Kurtz , Leilk Liu , Mark Brown , Matthias Brugger , linux-spi@vger.kernel.org (open list:SPI SUBSYSTEM), linux-kernel@vger.kernel.org (open list), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Mediatek SoC support), linux-mediatek@lists.infradead.org (moderated list:ARM/Mediatek SoC support) Subject: [PATCH 1/2] spi: When no dma_chan map buffers with spi_master's parent Date: Fri, 27 Jan 2017 00:21:53 +0800 Message-Id: <20170126162154.124287-1-djkurtz@chromium.org> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog To: unlisted-recipients:; (no To-header on input) Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Back before commit 1dccb598df54 ("arm64: simplify dma_get_ops"), for arm64, devices for which dma_ops were not explicitly set were automatically configured to use swiotlb_dma_ops, since this was hard-coded as the global "dma_ops" in arm64_dma_init(). Now that global "dma_ops" has been removed, all devices much have their dma_ops explicitly set by a call to arch_setup_dma_ops(), otherwise the device is assigned dummy_dma_ops, and thus calls to map_sg for such a device will fail (return 0). Mediatek SPI uses DMA but does not use a dma channel. Support for this was added by commit c37f45b5f1cd ("spi: support spi without dma channel to use can_dma()"), which uses the master_spi dev to DMA map buffers. The master_spi device is not a platform device, rather it is created in spi_alloc_device(), and therefore its dma_ops are never set. Therefore, when the mediatek SPI driver when it does DMA (for large SPI transactions > 32 bytes), SPI will use spi_map_buf()->dma_map_sg() to map the buffer for use in DMA. But dma_map_sg()->dma_map_sg_attrs() returns 0, because ops->map_sg is dummy_dma_ops->__dummy_map_sg, and hence spi_map_buf() returns -ENOMEM (-12). Fix this by using the real spi_master's parent device which should be a real physical device with DMA properties. Signed-off-by: Daniel Kurtz Fixes: c37f45b5f1cd ("spi: support spi without dma channel to use can_dma()") Cc: Leilk Liu --- drivers/spi/spi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 656dd3e3220c..f4d412e48e1c 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -805,12 +805,12 @@ static int __spi_map_msg(struct spi_master *master, struct spi_message *msg) if (master->dma_tx) tx_dev = master->dma_tx->device->dev; else - tx_dev = &master->dev; + tx_dev = master->dev.parent; if (master->dma_rx) rx_dev = master->dma_rx->device->dev; else - rx_dev = &master->dev; + rx_dev = master->dev.parent; list_for_each_entry(xfer, &msg->transfers, transfer_list) { if (!master->can_dma(master, msg->spi, xfer)) @@ -852,12 +852,12 @@ static int __spi_unmap_msg(struct spi_master *master, struct spi_message *msg) if (master->dma_tx) tx_dev = master->dma_tx->device->dev; else - tx_dev = &master->dev; + tx_dev = master->dev.parent; if (master->dma_rx) rx_dev = master->dma_rx->device->dev; else - rx_dev = &master->dev; + rx_dev = master->dev.parent; list_for_each_entry(xfer, &msg->transfers, transfer_list) { if (!master->can_dma(master, msg->spi, xfer))