From patchwork Tue Jun 13 13:45:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 105339 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp414523qgd; Tue, 13 Jun 2017 06:48:41 -0700 (PDT) X-Received: by 10.98.192.195 with SMTP id g64mr38551828pfk.26.1497361721142; Tue, 13 Jun 2017 06:48:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497361721; cv=none; d=google.com; s=arc-20160816; b=domiAzcg9rTEPdr2xOFm1khtmX1FWVqNzgMjbLM9sB/HnXzx72gPf3d/YYlSxj2wTN o3hGoeVugUHn1N7zmWN1qUB5y6bGSjukD14OGnGh/g5vmyEOohmzd8vHHYQJJ/+GClj9 6C05deA3c9G4QR+lwbwGhqyF+4Lnf4t89cIZ8Gc4oXKCF3zL3RUmWre8MNjLJUWktZ3g ry8+YO8b/lRm1mX0UfH0EmIaCbAFfUkWeV1tAo+WXNPZwfAEX4m3A4Cxa3s7Ip5z4cLm UjELE7w2+G3HZYqV6QUxlLIh3W6YuLKPc/elphDfsVNYBSq3Hif1La0QzdOpMA8GuGS3 tzJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=5ySPdNi5SDnJ2GRj2qUEU7cnF9dPiBh4/ZAMknYR83o=; b=hMDEfqOwOEhmvnNVbI4iA8LDDmceCX51ClOGE5xzIeKEF1d+0MZ0PIyDzTS5VmGHpq btBfyBl6gGThxYiwMvq6e+9HrUP8hU4s/eyEa2Zyghk/TnNly4a4d7pjVIyw6ilCfdod XQ/Hexp1EfSkVV9ww+fRfhqK++rfajI18ymh9zXQjZCsgSeNPaeILGrAj7CINFoWNDdL bu9tWJ0BQlMCapY+/opkrPofhRXtOCu+SeJrXNB4mT77epCmI6eCB4lMKyxruehvcsxs 2UDIruckKHETQ44pr6gnCFQifuySqV4iLaQAxQ4a6FE77165m+OZtZk09dtOmKkxl0i8 LDlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t20si10163902plj.520.2017.06.13.06.48.40; Tue, 13 Jun 2017 06:48:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753505AbdFMNsX (ORCPT + 25 others); Tue, 13 Jun 2017 09:48:23 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:30623 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752369AbdFMNsW (ORCPT ); Tue, 13 Jun 2017 09:48:22 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id v5DDjxiw031338; Tue, 13 Jun 2017 22:46:20 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v5DDjxiw031338 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1497361581; bh=5ySPdNi5SDnJ2GRj2qUEU7cnF9dPiBh4/ZAMknYR83o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a3ziZQRV+t3fS/4NRJFX1mH70bHJmVBAnTOmND/5leKBP+6Me2fibiOCIYPkLXs3S PvnMLhjnR/k5Gq42FZWn9v6X9eLSVwDG0GBfKN3QSd46SzzQU5ptVzd7PKxPzdjEKH zsXROrtSxqkHkx7fN8HLw/+5QWrhKxTW+rSruViGMIcICIhrWkCGpWGFdA9zYfVAUH W7qCcf/sHNbHhSPGzznRnvtTW7cEm25JxM4UCP3ciaAucvBT595+vw3vQkeJI78Tyu 8psAtjEIvLm8p323SwY27+RhkeiHV40Ido7rLh7QaaLTXTSGBDqFf1cAXJ0iAosCRR KuKBiPdJVR/JQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Cc: Enrico Jorns , Artem Bityutskiy , Dinh Nguyen , Boris Brezillon , Marek Vasut , David Woodhouse , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , Masahiro Yamada , Cyrille Pitchen , linux-kernel@vger.kernel.org, Brian Norris , Richard Weinberger Subject: [PATCH v7 13/16] mtd: nand: denali: skip driver internal bounce buffer when possible Date: Tue, 13 Jun 2017 22:45:47 +0900 Message-Id: <1497361550-8115-14-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497361550-8115-1-git-send-email-yamada.masahiro@socionext.com> References: <1497361550-8115-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For ecc->read_page() and ecc->write_page(), it is possible to call dma_map_single() against the given buffer. This bypasses the driver internal bounce buffer and save the memcpy(). Signed-off-by: Masahiro Yamada --- Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: - Remove dma_unmap_single() from denali_remove() Changes in v3: - Set chip->buf_align to 16 Changes in v2: - Newly added drivers/mtd/nand/denali.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) -- 2.7.4 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c index e8d8e6c6f45e..ec5fc8da5f9a 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -600,12 +600,16 @@ static int denali_pio_xfer(struct denali_nand_info *denali, void *buf, static int denali_dma_xfer(struct denali_nand_info *denali, void *buf, size_t size, int page, int raw, int write) { - dma_addr_t dma_addr = denali->dma_addr; + dma_addr_t dma_addr; uint32_t irq_mask, irq_status, ecc_err_mask; enum dma_data_direction dir = write ? DMA_TO_DEVICE : DMA_FROM_DEVICE; int ret = 0; - dma_sync_single_for_device(denali->dev, dma_addr, size, dir); + dma_addr = dma_map_single(denali->dev, buf, size, dir); + if (dma_mapping_error(denali->dev, dma_addr)) { + dev_dbg(denali->dev, "Failed to DMA-map buffer. Trying PIO.\n"); + return denali_pio_xfer(denali, buf, size, page, raw, write); + } if (write) { /* @@ -636,7 +640,7 @@ static int denali_dma_xfer(struct denali_nand_info *denali, void *buf, ret = -EBADMSG; denali_enable_dma(denali, false); - dma_sync_single_for_cpu(denali->dev, dma_addr, size, dir); + dma_unmap_single(denali->dev, dma_addr, size, dir); if (irq_status & INTR__ERASED_PAGE) memset(buf, 0xff, size); @@ -822,12 +826,10 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip, int stat = 0; int ret; - ret = denali_data_xfer(denali, denali->buf, mtd->writesize, page, 0, 0); + ret = denali_data_xfer(denali, buf, mtd->writesize, page, 0, 0); if (ret && ret != -EBADMSG) return ret; - memcpy(buf, denali->buf, mtd->writesize); - if (denali->caps & DENALI_CAP_HW_ECC_FIXUP) stat = denali_hw_ecc_fixup(mtd, denali, &uncor_ecc_flags); else if (ret == -EBADMSG) @@ -931,10 +933,8 @@ static int denali_write_page(struct mtd_info *mtd, struct nand_chip *chip, { struct denali_nand_info *denali = mtd_to_denali(mtd); - memcpy(denali->buf, buf, mtd->writesize); - - return denali_data_xfer(denali, denali->buf, mtd->writesize, page, - 0, 1); + return denali_data_xfer(denali, (void *)buf, mtd->writesize, + page, 0, 1); } static void denali_select_chip(struct mtd_info *mtd, int chip) @@ -1374,14 +1374,8 @@ int denali_init(struct denali_nand_info *denali) } if (denali->dma_avail) { - denali->dma_addr = dma_map_single(denali->dev, denali->buf, - mtd->writesize + mtd->oobsize, - DMA_BIDIRECTIONAL); - if (dma_mapping_error(denali->dev, denali->dma_addr)) { - dev_info(denali->dev, - "Failed to map DMA buffer. Disabling DMA.\n"); - denali->dma_avail = 0; - }; + chip->options |= NAND_USE_BOUNCE_BUFFER; + chip->buf_align = 16; } /* @@ -1471,16 +1465,8 @@ EXPORT_SYMBOL(denali_init); void denali_remove(struct denali_nand_info *denali) { struct mtd_info *mtd = nand_to_mtd(&denali->nand); - /* - * Pre-compute DMA buffer size to avoid any problems in case - * nand_release() ever changes in a way that mtd->writesize and - * mtd->oobsize are not reliable after this call. - */ - int bufsize = mtd->writesize + mtd->oobsize; nand_release(mtd); denali_disable_irq(denali); - dma_unmap_single(denali->dev, denali->dma_addr, bufsize, - DMA_BIDIRECTIONAL); } EXPORT_SYMBOL(denali_remove);