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: 9539731 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 D4628604A0 for ; Thu, 26 Jan 2017 16:25:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C30F2205F6 for ; Thu, 26 Jan 2017 16:25:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5D9C28138; Thu, 26 Jan 2017 16:25:02 +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=-1.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 705CD205F6 for ; Thu, 26 Jan 2017 16:25:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cWmr5-000789-Ig; Thu, 26 Jan 2017 16:24:59 +0000 Received: from mail-pg0-f47.google.com ([74.125.83.47]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cWmpe-0005ye-8B for linux-mediatek@lists.infradead.org; Thu, 26 Jan 2017 16:23:32 +0000 Received: by mail-pg0-f47.google.com with SMTP id 194so73556415pgd.2 for ; Thu, 26 Jan 2017 08:23: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=mXknVpHU3lI8MR0cRbu6rQgJEW8e4SfQoPnLJzdMObBZ7IGWOAQuS75Bu+siCHZOpM B60P8SYPQIo0Y3SICLtZCJtP7oSykUhGB65r5uYHH8/gFR+oRUDR1PBOxiv8dsfRikGC 8Xj/oN5rSOl13qImhPszAmVb2m6wUbFkW7RvGMHkhbDAiVASzi1BaOej0xh995//KcAG ViUKwS5qhNrR/XDggX1XDAC++JIRInmQ06NFKQq7+rzB4j/sFaEmVxAbhpRW4GI4vIYB kCfqh6li0zMbwdCc2alhDybUbYeRlptSfnJiO/nk32SFJtMG28fkKmw4sxpeiVxtZLwo +p7Q== X-Gm-Message-State: AIkVDXIYatvHpe6tBRmK4cDlMvIrKkFNwDmpPesFiGMJ1ivXe87d/+xQIRpCg3G9fBdRbG5K 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 To: 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170126_082330_334297_BD0BD99E X-CRM114-Status: GOOD ( 13.24 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: drinkcat@chromium.org, Leilk Liu , dtor@chromium.org, open list , "open list:SPI SUBSYSTEM" , Matthias Brugger , Mark Brown , "moderated list:ARM/Mediatek SoC support" , groeck@chromium.org, Robin Murphy , "moderated list:ARM/Mediatek SoC support" MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.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))