Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp801725imm; Fri, 17 Aug 2018 06:58:33 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyBwbwWqR+xi7zfiBKrC5KQEYlTJGV7x/ntBM5IJLlW6ngVMUT5fIJ0UAg2S7dIsotsHNID X-Received: by 2002:a17:902:a713:: with SMTP id w19-v6mr33325074plq.271.1534514313702; Fri, 17 Aug 2018 06:58:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534514313; cv=none; d=google.com; s=arc-20160816; b=LJwlgr7eXPWG6+MVquijyeA1foZjbIpeqD/klFt7yAjEM/AH/u5BZa2uLhZvBXwg6c vagzpm6VR4cihwkRGWG4yUr2L4EAKbdjpoj1uc2vU39bhyiaS7mOL+OscpBeuSqZ0qzk h0Z5NWstdMxDvJ06i+WW0amP3yknz/+BRWBQ7R9p1rdk1qwwbUSTd0NPNwRsLaBfVQRI h4AOvSy2ZdaMfg+HLsIcgscO6gbnMYOokCkdi8GSFZf0G8QlP73A5HVolDdcgAQG8pJp FdvkoGWP+t3zq4Qu0rz/AZqaLd6rQ2NDySP2h/n3f///MyHo+veBJ0Oia1QOcXhiKzHI Be+g== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=8JSusGWoLhHPYPd3szJw9P4xW4RnuMTfSyaWwDzbD3Y=; b=W5QNIxOOuufDR7Rm+Yjt5n7LKIRLieQdFkSuTKKCcutLpmS5pysPsqgMpOsstWBb7m MHH3W+HQ5iNUkTP/3bh8wGOYi1jHyonnChKa5lhwfGSMOONdN51Pa1WqhKbv0zMMc72p iwYvZ8/aFH4IRAV8omCdGXopWYSnV49yj7RrAWLUg2kvmFmf4gesJOy8EKrHbLxFT3ZZ ZaMjoRFeS36WMMDHwYWQ1xWyls7sgBv9MRmRgz7jqLY2ZDcRINJEpkRUYza5l1y1qo0T rqmo1EWGieb6v8gAQ4Jc/yAFLCUcgGlKakkXBXkz2ZwqkSICRrRgwdic13XUJojzDrmP JtnQ== 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 78-v6si2169892pfn.205.2018.08.17.06.58.04; Fri, 17 Aug 2018 06:58:33 -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; 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 S1726495AbeHQQ7j (ORCPT + 99 others); Fri, 17 Aug 2018 12:59:39 -0400 Received: from mail.bootlin.com ([62.4.15.54]:52098 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725800AbeHQQ7j (ORCPT ); Fri, 17 Aug 2018 12:59:39 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 13516207C8; Fri, 17 Aug 2018 15:56:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (91-160-177-164.subs.proxad.net [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id 97EBE207B3; Fri, 17 Aug 2018 15:56:08 +0200 (CEST) Date: Fri, 17 Aug 2018 15:56:08 +0200 From: Boris Brezillon To: Liang Yang Cc: Yixun Lan , , Rob Herring , "Neil Armstrong" , Martin Blumenstingl , Richard Weinberger , , Marek Vasut , Jian Hu , Kevin Hilman , Carlo Caione , , Brian Norris , David Woodhouse , , Jerome Brunet Subject: Re: [RFC PATCH v2 2/2] mtd: rawnand: meson: add support for Amlogic NAND flash controller Message-ID: <20180817155608.5929b37a@bbrezillon> In-Reply-To: <42877a0d-9830-0626-3f64-e49a326eaa3c@amlogic.com> References: <20180719094612.5833-1-yixun.lan@amlogic.com> <20180719094612.5833-3-yixun.lan@amlogic.com> <20180801235045.5b4d8211@bbrezillon> <42877a0d-9830-0626-3f64-e49a326eaa3c@amlogic.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 17 Aug 2018 21:03:59 +0800 Liang Yang wrote: > Hi Boris, > On 2018/8/2 5:50, Boris Brezillon wrote: > > > Hi Yixun, > > > > On Thu, 19 Jul 2018 17:46:12 +0800 > > Yixun Lan wrote: > > > > I haven't finished reviewing the driver yet (I'll try to do that later > > this week), but I already pointed a few things to fix/improve. > > > >> + > >> +static int meson_nfc_exec_op(struct nand_chip *chip, > >> + const struct nand_operation *op, bool check_only) > >> +{ > >> + struct mtd_info *mtd = nand_to_mtd(chip); > >> + struct meson_nfc *nfc = nand_get_controller_data(chip); > >> + const struct nand_op_instr *instr = NULL; > >> + int ret = 0, cmd; > >> + unsigned int op_id; > >> + int i; > >> + > >> + for (op_id = 0; op_id < op->ninstrs; op_id++) { > >> + instr = &op->instrs[op_id]; > >> + switch (instr->type) { > >> + case NAND_OP_CMD_INSTR: > >> + cmd = nfc->param.chip_select | NFC_CMD_CLE; > >> + cmd |= instr->ctx.cmd.opcode & 0xff; > >> + writel(cmd, nfc->reg_base + NFC_REG_CMD); > >> + meson_nfc_cmd_idle(nfc, NAND_TWB_TIME_CYCLE); > > This is not necessarily TWB you have to wait after a CMD cycle. It can > > be tWHR. And you should definitely not hardcode the value, since, > > AFAIR, it depends on the selected SDR timings. Probably something you > > should calculate in ->setup_data_interface(). > > Indeed. TWB is not necessarily. And tWHR will be promised by NFC. > so I will delete it. Are you sure the engine always applies a tWHR delay, even when tWB is expected? tWB should be applied everytime you are about to wait for a R/B transition. tWHR is about switching IO pins from input to output on the NAND chip side. > > >> + meson_nfc_drain_cmd(nfc); > > I don't know exactly how the NAND controller works, but it's usually > > not a good idea to execute the operation right away, especially if you > > have address/cmd/data cycles following this cmd and those can be > > packed in the same controller operation. > > it doesn't need meson_nfc_drain_cmd(nfc) here. i will delete it next version What's the CMD queue depth? I think you'll have to ensure the requested op fits in the CMD FIFO and split things in several sub-ops if it does not. > > >> + break; > >> + > >> + case NAND_OP_ADDR_INSTR: > >> + for (i = 0; i < instr->ctx.addr.naddrs; i++) { > >> + cmd = nfc->param.chip_select | NFC_CMD_ALE; > >> + cmd |= instr->ctx.addr.addrs[i] & 0xff; > >> + writel(cmd, nfc->reg_base + NFC_REG_CMD); > >> + } > >> + break; > >> + > >> + case NAND_OP_DATA_IN_INSTR: > >> + meson_nfc_read_buf(mtd, instr->ctx.data.buf.in, > >> + instr->ctx.data.len); > >> + break; > >> + > >> + case NAND_OP_DATA_OUT_INSTR: > >> + meson_nfc_write_buf(mtd, instr->ctx.data.buf.out, > >> + instr->ctx.data.len); > > Well, I'm not entirely sure what happens when you call > > read/write_buf(), but it seems you're doing that one byte at a time, > > and that sounds not so efficient given the operation you do for each > > byte read/written. Don't you have a way to tell the engine that you > > want to read/write X bytes? > > As i known, there is no way to read/write X bytes once. Okay, then maybe you can queue several byte read/write reqs before flushing the queue (meson_nfc_drain_cmd() + meson_nfc_wait_cmd_finish()). > > >> + break; > >> + > >> + case NAND_OP_WAITRDY_INSTR: > >> + mdelay(instr->ctx.waitrdy.timeout_ms); > >> + ret = nand_soft_waitrdy(chip, > >> + instr->ctx.waitrdy.timeout_ms); > > Hm, i'd be surprised if the controller does not have a way to optimize > > waits on R/B transitions. > > When i delete the delay here, erasing operation will be failed. > Does it mean NFC send 0x70 to nand device when rb is busy(low)? I was not even talking about the delay, but yes, mdelay() seems way too big. Remember that it's a timeout, and you usually don't have to wait that much. You can do ndelay(instr->ctx.delay_ns) before calling nand_soft_waitrdy() to make sure tWB is enforced. Anyway, that's not what I was initially referring to. What I meant is that nand_soft_waitrdy() should be replaced by native R/B pin or status polling wait logic so that the CPU is released while waiting for a R/B transition. > If so, i will ask our NFC designer for comfirmation or grasping the waveform. You have to wait tWB, that's for sure. > > >> + break; > >> + } > >> + } > >> + return ret; > >> +} > >> + > >> +static int meson_ooblayout_ecc(struct mtd_info *mtd, int section, > >> + struct mtd_oob_region *oobregion) > >> +{ > >> + struct nand_chip *chip = mtd_to_nand(mtd); > >> + int free_oob; > >> + > >> + if (section >= chip->ecc.steps) > >> + return -ERANGE; > >> + > >> + free_oob = (section + 1) * 2; > >> + oobregion->offset = section * chip->ecc.bytes + free_oob; > > Hm, this offset calculation looks weird. Are you sure it's correct? > > I'd bet on something like: > > > > oobregion->offset = 2 + (section * (chip->ecc.bytes + 4)); > > Each ecc page have 2 user bytes. Assume one 2KB+64B page size nand > flash using ECC8/1KB which ecc parity bytes is 14B. > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > | | | | | | | not | > | 1KB |2B| 14B | 1KB |2B| 14B | used | (layout on nand) > |_ _ _ _ _ _ _|_ |_ _ _ | _ _ _ _ _ _ |_ |_ _ _|_ _ _ _| > (2KB + 64B) > when reading from nand, I will format the page as follow: > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > | | | | | | | not | > | 1KB | 1KB |2B| 14B |2B| 14B | used |(layout on ddr) > |_ _ _ _ _ _ _|_ _ _ _ _ _ _|_ |_ _ _|_ |_ _ _ |_ _ _ _| > (2KB + 64B) > So i get "oobregion->offset = section * chip->ecc.bytes + free_oob". Okay, but I prefer when it's written like that: oobregion->offset = 2 + (section * (2 + chip->ecc.bytes)); > Maybe i don't get what does 'section' mean. i think it means the ecc page number. Section is just the free OOB or ECC section number. It starts at 0 and goes up to N - 1, where N usually is the number of ECC steps you have in a page.