From patchwork Mon Jun 5 23:22:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 103104 Delivered-To: patch@linaro.org Received: by 10.182.29.35 with SMTP id g3csp1008526obh; Mon, 5 Jun 2017 16:25:46 -0700 (PDT) X-Received: by 10.99.140.83 with SMTP id q19mr5749645pgn.225.1496705146360; Mon, 05 Jun 2017 16:25:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496705146; cv=none; d=google.com; s=arc-20160816; b=SOqk42qwO1p08Uw8KL4ISLfOhnBeyCsnFpDKDem+OaLtbxhUZR9gqxET7LLbVmELVL ip7wCdazzrzuzvQUjT9iUqES4LNH844A7hXxaMlzckd3rtIq5hP6KeMDlqJWMa3rWdxM sgzmlHv0InSlZuYfdkc0fa3qcTzrY9BKKguM2sjqlQtqzBgPvpkr/J5zn7WRs1iaIIDd FbGiuDzkhgwBxcZE4sZxaA2Xugs173bwOEuvWcIIbm7AbRvYzroDx6PcI1guRaZilzhn cWzB/GxAJs5UX4WC0XaoxZFFcKSjgtXPmOEEGaUx0d77TxPA5ieQMpK2SFgaeUcc1/sj aNVg== 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=208EqcWGerFdyZNvLo19pHYwq+AKnfE8I6ZnxNf1qnU=; b=GNVDaQ6tFSWmeRmAv3Av5zrjWb0w+SRmDPYGwT2DXOU8J1nW7RdL5Bsv5jP2FESNdG HfPNdhR/ye0/UZPiW7KKdyR1JRQDfHbx7Sg0vURO2YosgO9zNpUlJ8AC9AQfKDoxjDS9 /LoRAJ55NaaJuoqYYwQL7k4GTVJ1/1qA56eH/4Dv4rhY8k6+e0jKvAF1ProIC37RqvWi VB7cePD/GZWusRDBX2e1YK29wM0U3nKBgiojaxugGiBYF+NGuATxzQvfHdsfnEp4LPUP 2Wjh8iAWPezULum6vZ5KzKBJ6ujFAIRmGobA5EO7hNaJtrQVWuHsQfAMEpZu1uN3L+Ml kZ7Q== 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 q20si10759518pfl.414.2017.06.05.16.25.46; Mon, 05 Jun 2017 16:25:46 -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 S1751432AbdFEXZj (ORCPT + 25 others); Mon, 5 Jun 2017 19:25:39 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:32500 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751266AbdFEXZe (ORCPT ); Mon, 5 Jun 2017 19:25:34 -0400 Received: from grover.sesame (FL1-118-110-19-204.osk.mesh.ad.jp [118.110.19.204]) (authenticated) by conuserg-10.nifty.com with ESMTP id v55NMD5v004412; Tue, 6 Jun 2017 08:22:52 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com v55NMD5v004412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1496704973; bh=208EqcWGerFdyZNvLo19pHYwq+AKnfE8I6ZnxNf1qnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MpFuJwD+Ku89uHXTptJi1hs6DE1ZmoaqWQY9t8gsJX3ni9dN7TIpgG228hDQY33zg 5OAowNrpCFN4jsX3ACo4BhdP1lQKqgwgzLY185gF8Skl2zhyeXfP9EVmoni2a8qxJr iHRlLOhxGjLeGHehhGl9wb4HoVbOU+sJAGQYq14lkeN4ZD1vol7Haa7QXJ94HW7eoS 59xi3iJNg1yfPMANrTxrfi1IS3MRiW2b+zbm1aYIHRZCLTnXPZ6zimy3Txmbcr+4qC lybbaig9n1m1f8KD3sqAB4ZHG2/EBSkcxl/K1kO9UKmcjh2LzkhIeukWMHvmbAyumO D+/Ke4hRGfYOw== X-Nifty-SrcIP: [118.110.19.204] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Cc: Enrico Jorns , Artem Bityutskiy , Dinh Nguyen , Boris Brezillon , Marek Vasut , Graham Moore , David Woodhouse , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , Masahiro Yamada , Cyrille Pitchen , linux-kernel@vger.kernel.org, Brian Norris , Richard Weinberger Subject: [PATCH v4 21/23] mtd: nand: denali: skip driver internal bounce buffer when possible Date: Tue, 6 Jun 2017 08:22:00 +0900 Message-Id: <1496704922-12261-22-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496704922-12261-1-git-send-email-yamada.masahiro@socionext.com> References: <1496704922-12261-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 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 42e0620..e4ab397 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -643,12 +643,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) { irq_mask = INTR__DMA_CMD_COMP | INTR__PROGRAM_FAIL; @@ -674,7 +678,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); return ret; } @@ -857,12 +861,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) @@ -966,10 +968,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) @@ -1424,14 +1424,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; } /* @@ -1520,16 +1514,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);