Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4262491imu; Mon, 12 Nov 2018 08:14:50 -0800 (PST) X-Google-Smtp-Source: AJdET5fRrln+7gsFyMao7Djpl8I8UavNU5KjOE5HmzMfZTWwTDAaLOfXAFBsyTZqLzkUoNuHXppy X-Received: by 2002:a62:d148:: with SMTP id t8-v6mr1468433pfl.212.1542039290508; Mon, 12 Nov 2018 08:14:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542039290; cv=none; d=google.com; s=arc-20160816; b=dI1Up2Vy5FRn3NQ3cX3FTOCVqDbq934iBD4nXho9UkSDP9HcLe5Yqz0GZczD2BhFt0 Pgdi5zJP2du912wAKuJiD/jMwfcGr47PX+JqAblGC/0ecdgYSc6f6UaEhwkFwY1L0uPQ cZXxq6PfuyStNFer1lKJm0NRCbCdSHwpt+1u7e45mDqizW09jlW/aXkR+v8rFKASWnH/ 1wJkd7HOrUwBKzmNshtnXtl40LurQboq9hBAH1NZsSzbnrNKEsxUOHd8H75tkSxko81f DbyZc/gsFMFXq9lvmzYc0ffHnqp5VIFwL0OfQ0KzldBlg7GIZ+UqNvEp9spNwacHT0Jq 1EmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=lstWbDKDYcq0l3tFQBMtl1NAnzn1JZXRb7JSOJSo2cQ=; b=QPRqKfq8ydyqMaDTlx0LZ85DupUy8I7d4HIoPzKx7l5cZ7XAaT91MDg5h8w/RMpHA1 z3rppU2a5M/TE28wIF81WmYxA2Pje95IuFmQABV6h+A6I0CqGOOYZKgqxIYJWtC2CQG3 pS0gmxRLj8Q+yb6oHjmuLrq0sI3VWg2QHHh5BjL3gLJTePaepsQCtmZggRZksXIzNdxv SD/PyvFZA7JFs3IrPc1p2mC5DoGr+eKclCh8v6wuCQAFDqIKKuhoS/KCM8E6ZoMz9x0d dWEemZXnJeQYNJpXQD7N4WPH7Xs/XMMbVfSrCYauwUG9CJwDjurnMdkKHdzq3JB+O5fA dF3Q== ARC-Authentication-Results: i=1; mx.google.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 u15-v6si18285121plq.353.2018.11.12.08.14.14; Mon, 12 Nov 2018 08:14:50 -0800 (PST) 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; 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 S1729825AbeKMCHs convert rfc822-to-8bit (ORCPT + 99 others); Mon, 12 Nov 2018 21:07:48 -0500 Received: from mail.bootlin.com ([62.4.15.54]:52020 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727976AbeKMCHs (ORCPT ); Mon, 12 Nov 2018 21:07:48 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id BF088207CF; Mon, 12 Nov 2018 17:13:51 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.2 Received: from xps13 (aaubervilliers-681-1-30-49.w90-88.abo.wanadoo.fr [90.88.15.49]) by mail.bootlin.com (Postfix) with ESMTPSA id 4923320701; Mon, 12 Nov 2018 17:13:51 +0100 (CET) Date: Mon, 12 Nov 2018 17:13:51 +0100 From: Miquel Raynal To: Boris Brezillon Cc: Liang Yang , Rob Herring , Hanjie Lin , Victor Wan , Jianxin Pan , Neil Armstrong , Martin Blumenstingl , Richard Weinberger , Yixun Lan , linux-kernel@vger.kernel.org, Marek Vasut , Jian Hu , linux-mtd@lists.infradead.org, Kevin Hilman , Carlo Caione , linux-amlogic@lists.infradead.org, Brian Norris , David Woodhouse , linux-arm-kernel@lists.infradead.org, Jerome Brunet Subject: Re: [PATCH v6 2/2] mtd: rawnand: meson: add support for Amlogic NAND flash controller Message-ID: <20181112171351.4ac3506b@xps13> In-Reply-To: <20181106112206.65a70a81@bbrezillon> References: <1541090542-19618-1-git-send-email-jianxin.pan@amlogic.com> <1541090542-19618-3-git-send-email-jianxin.pan@amlogic.com> <20181105165321.7ea2b45f@bbrezillon> <20181106102851.61deb97a@bbrezillon> <20181106112206.65a70a81@bbrezillon> Organization: Bootlin X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, Boris Brezillon wrote on Tue, 6 Nov 2018 11:22:06 +0100: > On Tue, 6 Nov 2018 18:00:37 +0800 > Liang Yang wrote: > > > On 2018/11/6 17:28, Boris Brezillon wrote: > > > On Tue, 6 Nov 2018 17:08:00 +0800 > > > Liang Yang wrote: > > > > > >> On 2018/11/5 23:53, Boris Brezillon wrote: > > >>> On Fri, 2 Nov 2018 00:42:21 +0800 > > >>> Jianxin Pan wrote: > > >>> > > >>>> + > > >>>> +static inline u8 meson_nfc_read_byte(struct mtd_info *mtd) > > >>>> +{ > > >>>> + struct nand_chip *nand = mtd_to_nand(mtd); > > >>>> + struct meson_nfc *nfc = nand_get_controller_data(nand); > > >>>> + u32 cmd; > > >>>> + > > >>>> + cmd = nfc->param.chip_select | NFC_CMD_DRD | 0; > > >>>> + writel(cmd, nfc->reg_base + NFC_REG_CMD); > > >>>> + > > >>>> + meson_nfc_drain_cmd(nfc); > > >>> > > >>> You probably don't want to drain the FIFO every time you read a byte on > > >>> the bus, and I guess the INPUT FIFO is at least as big as the CMD > > >>> FIFO, right? If that's the case, you should queue as much DRD cmd as > > >>> possible and only sync when the user explicitly requests it or when > > >>> the INPUT/READ FIFO is full. > > >>> > > >> Register 'NFC_REG_BUF' can holds only 4 bytes, also DRD sends only one > > >> nand cycle to read one byte and covers the 1st byte every time reading. > > >> i think nfc controller is faster than nand cycle, but really it is not > > >> high efficiency when reading so many bytes once. > > >> Or use dma command here like read_page and read_page_raw. > > > > > > Yep, that's also an alternative, though you'll have to make sure the > > > buffer passed through the nand_op_inst is DMA-safe, and use a bounce > > > buffer when that's not the case. > > > > > ok, i will try dma here. > > We should probably expose the bounce buf handling as generic helpers at > the rawnand level: > > void *nand_op_get_dma_safe_input_buf(struct nand_op_instr *instr) > { > void *buf; > > if (WARN_ON(instr->type != NAND_OP_DATA_IN_INSTR)) > return NULL; > > if (virt_addr_valid(instr->data.in) && > !object_is_on_stack(instr->data.buf.in)) > return instr->data.buf.in; > > return kzalloc(instr->data.len, GFP_KERNEL); > } > > void nand_op_put_dma_safe_input_buf(struct nand_op_instr *instr, > void *buf) > { > if (WARN_ON(instr->type != NAND_OP_DATA_IN_INSTR) || > WARN_ON(!buf)) > return; > > if (buf == instr->data.buf.in) > return; > > memcpy(instr->data.buf.in, buf, instr->data.len); > kfree(buf); > } > > const void *nand_op_get_dma_safe_output_buf(struct nand_op_instr *instr) > { > void *buf; > > if (WARN_ON(instr->type != NAND_OP_DATA_OUT_INSTR)) > return NULL; > > if (virt_addr_valid(instr->data.out) && > !object_is_on_stack(instr->data.buf.out)) > return instr->data.buf.out; > > return kmemdup(instr->data.buf.out, GFP_KERNEL); > } > > void nand_op_put_dma_safe_output_buf(struct nand_op_instr *instr, > void *buf) > { > if (WARN_ON(instr->type != NAND_OP_DATA_OUT_INSTR) || > WARN_ON(!buf)) > return; > > if (buf != instr->data.buf.out) > kfree(buf); > } Not that I am against such function, but maybe they should come with comments stating that there is no reliable way to find if a buffer is DMA-able at runtime and these are just sanity checks (ie. required, but probably not enough). This is my understanding of Wolfram's recent talk at ELCE [1]. I suppose using the CONFIG_DMA_API_DEBUG option could help more reliably to find such issues. [1] https://www.youtube.com/watch?v=JDwaMClvV-s Thanks, Miquèl