From patchwork Tue Jun 13 05:04:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 103695 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp236123qgd; Mon, 12 Jun 2017 22:07:34 -0700 (PDT) X-Received: by 10.84.133.162 with SMTP id f31mr24408377plf.83.1497330454607; Mon, 12 Jun 2017 22:07:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497330454; cv=none; d=google.com; s=arc-20160816; b=MHmwIeCRoAgXpuUKKK9KGr6CVbtzQi0p/nJPjNYC4XWrxbSLtZAnn3wOzeUeG83cwH df2aLLENnV8bhm/D4ALQHkSHBMe4gAM5vSQuQEYHsLe9MPiJKfqBykWenTZL/vqDodT0 6imLqj3kIwLeBz/H3dUZALWgEbjsHPtBs0QgC2tc9IOsRLj9lfEI7x4N+0PwbfKocDeO n90lKSI6/wqPzkYh9hH7rb201YdMS/WDtzfp8AMOZGLLnuKaW4qMqkCfLP+IFS0ySYCI +duZmFkV2njuikrfMc46PYme8HyPWSCUO+bwi+8GFdS8qQJ4jxRaiLoWd9Eo+TzgllTc TI0Q== 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=F322FTLwIWqCo24BEOoCsk75MXxka1nNSAdFN2jZIQ4=; b=Z3J3Dy/fi08cKEn9APF5vO9AtVuE7gHvGAl92NmrtZ5U5kUVBzfPA332vMuIZEm0AW /oOK3nSDHaG4EY6rdF4DD+26WbqlYDg8W5oE+2W6stQy5MkXbnoj2P/8Lq3Ro04R2W8O 0rn3ZamBpRpj3wh/iYVk1U6h37nArWTksbHlxwaUu66Al58FDLRmduu2vM+561HFKCU1 nREgiTMoDD+iPRBXhj6dQFEFOXrwc8vN73QfmgFxjGuz7gjCgMNTSMNTV3TzSdC++ZHG LIJrzdlpjcmieno6PjVGGRf49L1JyYZMx1PhiJ/7lXgp5qZK6LK26GQJvpGfoRYF4F73 sXhQ== 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 d1si8488967pli.110.2017.06.12.22.07.34; Mon, 12 Jun 2017 22:07:34 -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 S1752389AbdFMFHR (ORCPT + 25 others); Tue, 13 Jun 2017 01:07:17 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:47513 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752349AbdFMFHO (ORCPT ); Tue, 13 Jun 2017 01:07:14 -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 v5D54ENt023096; Tue, 13 Jun 2017 14:04:32 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v5D54ENt023096 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1497330273; bh=F322FTLwIWqCo24BEOoCsk75MXxka1nNSAdFN2jZIQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mr/HVoSTRoC1lvrvZiSuczmGf1Fu1jAKadYsSPWx8aa65/foSIi0KFJNNl0zY43nk oKMoiH9pQ3YVYWswLbanaGAVTglVlfBgmKnFcjmem3Ouq18EyOzpYHmBPcB3ClmeKi Pbmi1TVB9R770Hr0fKgiwAlVzCE2tDsiC05QrNne70AhY8E4+S7bwWg5uLb0kXYOMZ Wtnhgfql51cq2z9th3WneeerIPPDrdRBqX9ciqGLKQeKxi0bCS5CfCes/1+VSv8FHP f+c2pJSSjrOHtaKfHkrbNrxmAdBLskC6n8a83o9+lMR4I+hXVOFuxEYI4U1T626xN2 dj95pUTrJWG7g== 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 v6 15/18] mtd: nand: denali: skip driver internal bounce buffer when possible Date: Tue, 13 Jun 2017 14:04:07 +0900 Message-Id: <1497330250-17348-16-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497330250-17348-1-git-send-email-yamada.masahiro@socionext.com> References: <1497330250-17348-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 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 1ded7cc00b1a..918b9b9bbe53 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -592,12 +592,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) { /* @@ -628,7 +632,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); @@ -814,12 +818,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) @@ -923,10 +925,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) @@ -1365,14 +1365,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; } /* @@ -1462,16 +1456,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);