Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3650114imm; Fri, 20 Jul 2018 23:39:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdzJm3lCnZuYrKM6jbD0ffdHobeTiAAindO8cgti9l9FVvuvAYPg4kdbLZPNWvvj3Miv1Xk X-Received: by 2002:a63:d309:: with SMTP id b9-v6mr4636127pgg.163.1532155140822; Fri, 20 Jul 2018 23:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532155140; cv=none; d=google.com; s=arc-20160816; b=z71G/21vJ1qqNjctaTUDJObVw9VKyl5kitUzHkd5g/D1C2HMQvC6SQF4ZP22ZD7oY5 UQao9STxsvqW+Mles08IEawozEZ0FDl6jJzdt1XDCU/Rzz5kOnZNhCcalOubAbV9pjh8 ei437llEjrEsYu9iIfwWXhABZov2tkNQUtvO4gImqtz1IHCyM/EAu4qZvLVjBoj1D5p0 /H4VwY5ZEitlqw+69ejxi6iYikuAXUuP2+8t36Cu1hKJsaYIzMQs+hnI1/iLZZy/RuGJ dSPa+gB7X9lbCu1kFG+yskMrImA7R/lE7YEw5k+PP2tO7jl8eJ4rX0ejAmkSKQp5TR0s NnKw== 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=DSDkWrFoOMnjTSjSdCX/IEJ1lfnGlCihdHlZzKBqqss=; b=sjL22tyMuDXKOqpTiKmJOgpj4PQesFjciVm56/4VedNy/qLukAYqWnXL/C3j1VRnxn BY/cF+pog2grY3jKEObABDLtHDy54LRI3TyVBFe+0XJHxFYL3hj3UaP3uWi2vdQLdvK7 NfuNN/a8tpUi4UC/RxkbDDfmWWD1USb760g3b6WWEVMN8y9xQzH9LHnTuJkpYMobeyUO FQRzwkuujjsmgqEjrOttrViSKW5NKsBdxU7VQk3vxmxFizHPr6zEhrdGydpq8A2wAJbb 8AF0v+MxVLfPaEfGsKN1R4eZ3hQ0I38yWRYYPvwuj+4ZvRf0FEHT4bxcZLv1or6LCNhU GlOw== 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 o64-v6si3395867pfb.20.2018.07.20.23.38.33; Fri, 20 Jul 2018 23:39:00 -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 S1727486AbeGUH1V (ORCPT + 99 others); Sat, 21 Jul 2018 03:27:21 -0400 Received: from mail.bootlin.com ([62.4.15.54]:42391 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727137AbeGUH1V (ORCPT ); Sat, 21 Jul 2018 03:27:21 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 2FFF2207AD; Sat, 21 Jul 2018 08:35:45 +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 (unknown [37.173.220.171]) by mail.bootlin.com (Postfix) with ESMTPSA id 19A222069C; Sat, 21 Jul 2018 08:35:43 +0200 (CEST) Date: Sat, 21 Jul 2018 08:35:41 +0200 From: Boris Brezillon To: Miquel Raynal Cc: Wenyou Yang , Josh Wu , Tudor Ambarus , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Nicolas Ferre , Alexandre Belloni , Kamal Dasu , Masahiro Yamada , Han Xu , Harvey Hunt , Vladimir Zapolskiy , Sylvain Lemieux , Xiaolei Li , Matthias Brugger , Maxime Ripard , Chen-Yu Tsai , Marc Gonzalez , Mans Rullgard , Stefan Agner , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-mediatek@lists.infradead.org Subject: Re: [PATCH v4 02/35] mtd: rawnand: cafe: convert driver to nand_scan() Message-ID: <20180721083541.5a52771a@bbrezillon> In-Reply-To: <20180720151527.16038-3-miquel.raynal@bootlin.com> References: <20180720151527.16038-1-miquel.raynal@bootlin.com> <20180720151527.16038-3-miquel.raynal@bootlin.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, 20 Jul 2018 17:14:54 +0200 Miquel Raynal wrote: > Two helpers have been added to the core to make ECC-related > configuration between the detection phase and the final NAND scan. Use > these hooks and convert the driver to just use nand_scan() instead of > both nand_scan_ident() and nand_scan_tail(). > > Signed-off-by: Miquel Raynal > --- > drivers/mtd/nand/raw/cafe_nand.c | 130 +++++++++++++++++++++++---------------- > 1 file changed, 76 insertions(+), 54 deletions(-) > > diff --git a/drivers/mtd/nand/raw/cafe_nand.c b/drivers/mtd/nand/raw/cafe_nand.c > index ac0be933a490..c303c261dd8d 100644 > --- a/drivers/mtd/nand/raw/cafe_nand.c > +++ b/drivers/mtd/nand/raw/cafe_nand.c > @@ -71,7 +71,9 @@ struct cafe_priv { > unsigned char *dmabuf; > }; > > -static int usedma = 1; > +#define CAFE_DEFAULT_DMA 1 > + > +static int usedma = CAFE_DEFAULT_DMA; Not sure you need a macro for that. > module_param(usedma, int, 0644); > > static int skipbbt = 0; > @@ -593,6 +595,76 @@ static int cafe_mul(int x) > return gf4096_mul(x, 0xe01); > } > > +static int cafe_nand_attach_chip(struct nand_chip *chip) > +{ > + struct mtd_info *mtd = nand_to_mtd(chip); > + struct cafe_priv *cafe = nand_get_controller_data(chip); > + int err = 0; > + > + cafe->dmabuf = dma_alloc_coherent(&cafe->pdev->dev, 2112, > + &cafe->dmaaddr, GFP_KERNEL); > + if (!cafe->dmabuf) > + return -ENOMEM; > + > + /* Set up DMA address */ > + cafe_writel(cafe, lower_32_bits(cafe->dmaaddr), NAND_DMA_ADDR0); > + cafe_writel(cafe, upper_32_bits(cafe->dmaaddr), NAND_DMA_ADDR1); > + > + cafe_dev_dbg(&cafe->pdev->dev, "Set DMA address to %x (virt %p)\n", > + cafe_readl(cafe, NAND_DMA_ADDR0), cafe->dmabuf); > + > + /* Restore the DMA flag */ > + usedma = CAFE_DEFAULT_DMA; This is wrong. The user might have passed a different value to usedma when loading the module (or on the kernel cmdline), and you're simply ignoring it. I see 2 solutions to solve that: 1/ add a ->usedma field to the cafe_priv struct which you initialize to 0 in the probe function (already done if you kzalloc() the struct) and update it here: cafe->usedma = usedma. then you have to patch all places where usedma was tested and replace this test by a test on cafe->usedma 2/ add a static in old_usedma which you assign to usedma value in the probe and then restore the usedma value here: usedma = old_usedma I prefer option #1.