Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp834005ybe; Wed, 11 Sep 2019 05:33:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyM5Fp1FC5AxBIUVujFasVMFi/AffU836k86kDKacpicUM4BxaPahm/DAVrPROnLfvHuZYu X-Received: by 2002:a50:935d:: with SMTP id n29mr36220408eda.294.1568205206060; Wed, 11 Sep 2019 05:33:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568205206; cv=none; d=google.com; s=arc-20160816; b=r5hHUnj1IY1qIv3nwvTTqB7jc+xAZ5+7E5CN6LXYKzNeV+oPKonFtZZw7ItV8zHT1Y hFqZDS7C8zkUaOUnZkR35aUgEkbIypx1TPsDbQNJP8aZxMPTJ73BNzUIgNcOA4AlThOv HbWIMDEv/tfH0nzBx0a19ydjNXRE1pnV4r1rHi4/3BwmIGET7rgwxcw0m/enHkfxZEx1 2YXPXw5YY9zmQfVvXAXM8vb8FLrURhcTLPtbacZnPo/T72Yvwf4jiM8JbNKYNMn9DuTh BK4ydwig8KuvU2qePNrMW4D66TYrMOz+YhtY5A4lFNWMrSXsdW42cdrUmr0TQfGmSrgd NIPA== 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=cPVBHGlWkgB+sf9nTH0a69XvmKmJnQ7PT0u9BEwnjKY=; b=Kcmnb1VUwaUZHIb0MePK2MKjF6p3zVW60Iv6IJb550VdcWXu1+ESCZPM0/Xu/lVNEA JqkTXgHpmt0yJF/+2r9wWfyRBze2Ql8FA23eMs0M+ISKe7oXI0d0xzhDzo9gZfuGXXSP CX9PPMydoeGS7iukrCCVf5vAAt1oWl5o+ViR9pfNCWDAk6ZjYQURbfBi/2KvrvkDkWqL qD2QFeFvB5ydc9Tr2JmwkwtkfE+I9gbEusxksVtFiXZsGL4axdRyNcWZaKc+z4NL9tIO ztHSXg/EE2+6X8xLJZEmOvyCgPMpYg4nKWC0rf3b/x60rXoqojT1u7zldolL+W4fXIxN J9Og== 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 m6si12239505edv.288.2019.09.11.05.33.01; Wed, 11 Sep 2019 05:33:26 -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 S1727973AbfIKM3H convert rfc822-to-8bit (ORCPT + 99 others); Wed, 11 Sep 2019 08:29:07 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:46477 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727696AbfIKM3H (ORCPT ); Wed, 11 Sep 2019 08:29:07 -0400 X-Originating-IP: 148.69.85.38 Received: from xps13 (unknown [148.69.85.38]) (Authenticated sender: miquel.raynal@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 43624FF812; Wed, 11 Sep 2019 12:29:03 +0000 (UTC) Date: Wed, 11 Sep 2019 14:29:01 +0200 From: Miquel Raynal To: Piotr Sroka Cc: , Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Paul Burton , Geert Uytterhoeven , Arnd Bergmann , Marcel Ziswiler , Dmitry Osipenko , Stefan Agner , , Kazuhiro Kasai Subject: Re: [v5 1/2] mtd: nand: Add new Cadence NAND driver to MTD subsystem Message-ID: <20190911142901.317f8f8e@xps13> In-Reply-To: <20190911094354.GA14863@global.cadence.com> References: <20190725145804.8886-1-piotrs@cadence.com> <20190725150012.14416-1-piotrs@cadence.com> <20190830114645.59898cfe@xps13> <20190911094354.GA14863@global.cadence.com> Organization: Bootlin X-Mailer: Claws Mail 3.17.3 (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 Hi Piotr, Piotr Sroka wrote on Wed, 11 Sep 2019 10:43:56 +0100: > The 08/30/2019 11:46, Miquel Raynal wrote: > >EXTERNAL MAIL > > > > > >Hi Piotr, > > > >Piotr Sroka wrote on Thu, 25 Jul 2019 16:00:12 > >+0100: > > > >Subject should be: mtd: rawnand: > > > >Last few nits in your driver which overall looks good (see below). > > > >Now I'm waiting for Rob's ack on the bindings. This driver should be a > >good candidate for 5.5. > > I think that Rob alredy review it. You can find hist review on > https://patchwork.ozlabs.org/patch/1136932/ > Let me know if something else should be improved or fixed. Oh right I missed it. Then just don't forget to carry the tag in your next iteration and we'll be fine! [...] > >> +static irqreturn_t cadence_nand_isr(int irq, void *dev_id) > >> +{ > >> + struct cdns_nand_ctrl *cdns_ctrl = dev_id; > >> + struct cadence_nand_irq_status irq_status; > >> + irqreturn_t result = IRQ_NONE; > >> + > >> + spin_lock(&cdns_ctrl->irq_lock); > >> + > >> + if (irq_detected(cdns_ctrl, &irq_status)) { > >> + /* Handle interrupt. */ > >> + /* First acknowledge it. */ > >> + cadence_nand_clear_interrupt(cdns_ctrl, &irq_status); > >> + /* Status in the device context for someone to read. */ > >> + cdns_ctrl->irq_status.status |= irq_status.status; > >> + cdns_ctrl->irq_status.trd_status |= irq_status.trd_status; > >> + cdns_ctrl->irq_status.trd_error |= irq_status.trd_error; > >> + /* Notify anyone who cares that it happened. */ > >> + complete(&cdns_ctrl->complete); > >> + /* Tell the OS that we've handled this. */ > >> + result = IRQ_HANDLED; > >> + } > >> + spin_unlock(&cdns_ctrl->irq_lock); > > > >Your locking scheme seems wrong (maybe I'm not going deep enough in the > >code), can you please try with LOCKDEP enabled? > > > I will check it. > At the time I can see only one problem: the cadence_nand_reset_irq function should use spin_lock_irqsave instead of spin_lock. > Can you see any other problems? It just felt bizarre. Just run with LOCKDEP enabled and we'll be fixed. [...] > >> +/* Hardware initialization. */ > >> +static int cadence_nand_hw_init(struct cdns_nand_ctrl *cdns_ctrl) > >> +{ > >> + int status; > >> + u32 reg; > >> + > >> + status = cadence_nand_wait_for_value(cdns_ctrl, CTRL_STATUS, > >> + 1000000, > >> + CTRL_STATUS_INIT_COMP, false); > >> + if (status) > >> + return status; > >> + > >> + reg = readl_relaxed(cdns_ctrl->reg + CTRL_VERSION); > >> + > >> + dev_info(cdns_ctrl->dev, > >> + "%s: cadence nand controller version reg %x\n", > >> + __func__, reg); > >> + > >> + /* Disable cache and multiplane. */ > >> + writel_relaxed(0, cdns_ctrl->reg + MULTIPLANE_CFG); > >> + writel_relaxed(0, cdns_ctrl->reg + CACHE_CFG); > > > >Cache? > > > If feature is enabled then The NAND Flash Controller will sequence the multi-page read commands as cache read or cache program sequence. Not used by Linux driver because driver has possibility to program/read only a single page. Indeed, that's fine then. [...] > >> + > >> + switch (status) { > >> + case STAT_ECC_UNCORR: > >> + mtd->ecc_stats.failed++; > >> + ecc_err_count++; > >> + break; > >> + case STAT_ECC_CORR: > >> + ecc_err_count = FIELD_GET(CDMA_CS_MAXERR, > >> + cdns_ctrl->cdma_desc->status); > >> + mtd->ecc_stats.corrected += ecc_err_count; > > > >Is this value the maximum number of bitflips in each chunk of the page? > >If it returns the total number of bitflips corrected in the entire page > >we have a problem. > > > It is a maximum number of corrections applied to any ECC sector in the > transaction. > it looks like folowing. > mtd->ecc_stats.corrected += max(bitflips_chunk1, bitflips_chunk2, ....) > > Transaction will be marked uncorrectable if any one of the sectors is > uncorrectable. > It looks like following. > if (is_chunk1_fail || is_chunk2_fail .....) > mtd->ecc_stats.failed++; Fine > > >> + break; > >> + case STAT_ERASED: > >> + case STAT_OK: > >> + break; > >> + default: > >> + dev_err(cdns_ctrl->dev, "read page failed\n"); > >> + return -EIO; > >> + } > >> + > >> + if (oob_required) > >> + if (cadence_nand_read_bbm(chip, page, chip->oob_poi)) > >> + return -EIO; > > > >Do we really care about the BBM at this level? If we are requested to > >read the page, I suppose we must do what is in our hands to return the > >data? Normally this is handled in userspace directly. > It is because when ECC is enabled then position of "logic" spare area is > moved. That's sad. > Lets say we have page size 4096 and sector size is 1024. > Manufacturer use begining of spare area as BBM. Spare area started at > 4096. > In case ECC is enabled. 4096 offset is somewhere in sector 4. Start of spare are is 4096 + 3 * ecc_size. So BBM is taken from bad > place. > > > Therefore we need to read BBM from proper place. > There are two "problems" which make us to read BBM separatelly. > > 1. During build BBT the BBM is read by functions which are expected to use ECC. 2. Controller interleaves the data with ECC. > Thanks, Miquèl