Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1448471imm; Thu, 19 Jul 2018 01:40:55 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcAxUN8DoXblIK6cd0jyNXcVaVAGmI5fUSifx9soY1QsOEy+xz3c8SlpvD0V7YVgdW5Dx8o X-Received: by 2002:a65:62d8:: with SMTP id m24-v6mr9171177pgv.307.1531989655720; Thu, 19 Jul 2018 01:40:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531989655; cv=none; d=google.com; s=arc-20160816; b=sasaFPQHfzRiTx6UN3CZvr3iUtrkV5dzUc3dmAiHDBJVdRjoSV84PsNMh2bQBqYd7Y u5MIkWA8LC9Lp4XBSdeqOD16fx2viTLRyoeASIBzFn6nOKwzYLCXbMehWBGEypJeXrtr cg7CuTAgw9SQXB9U6JYOB6MfStn3iSpkTgBW9kbbcKUvOOelQJUWAxtsi8aD2CftZMDz qJLTE3a/Y0Q9KgRholD6PnjqbsqUh0U6nczNJyj1QlaspvAUrkFgMqw9XbkUoeJ4BGyU /HrMExNJNpEXf32EMQk3yiGJkm4vN8KqyN7cI9aK7r2K2w5EBFaRHRYJxT/onNvPEYf1 Dq9g== 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=K1GHMZ5k1dtXaDNumvXLTkQp0V+f5eZ6vQBkNtel2sI=; b=0FpvUnKzSs56gDtvQ1pm2txhvAZB6P7mozsDd1omEtf5RY/X2uq1n63dIZOXWutoHW 8krUIR9ZTd5aZihZSTDQDSZb+EORBR3xhKndaysUaPKpPn/3s4EOjNX/Qx3raGkZtcJN +eaN2xBbscn/1emj6BNz0cG7CLtebWtZ01BUhGSuUkCmW0YImCli18J4x5/qOFdQeIx/ RvQB3Rf1ZXS/rLunegABhQ6LEE5Eat7R/HFmPYl+kcq4vOvtbY1KAA6LOmLvqkmvolEq D5l32SAhEAxEb+7RJRfwj1V/LujN709niTTtcFVG39JMmjdHt8Ycn1KePq5pOXZvomgh pn+A== 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 u10-v6si5107918plu.506.2018.07.19.01.40.39; Thu, 19 Jul 2018 01:40:55 -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 S1727516AbeGSJWJ (ORCPT + 99 others); Thu, 19 Jul 2018 05:22:09 -0400 Received: from mail.bootlin.com ([62.4.15.54]:55688 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726494AbeGSJWJ (ORCPT ); Thu, 19 Jul 2018 05:22:09 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id F1705207AD; Thu, 19 Jul 2018 10:40:03 +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 (AAubervilliers-681-1-27-161.w90-88.abo.wanadoo.fr [90.88.147.161]) by mail.bootlin.com (Postfix) with ESMTPSA id 826E6206EE; Thu, 19 Jul 2018 10:39:53 +0200 (CEST) Date: Thu, 19 Jul 2018 10:39:53 +0200 From: Boris Brezillon To: Yixun Lan Cc: Rob Herring , Neil Armstrong , Richard Weinberger , Miquel Raynal , , Marek Vasut , Jian Hu , Liang Yang , , Kevin Hilman , Carlo Caione , , Brian Norris , David Woodhouse , , Jerome Brunet Subject: Re: [PATCH 2/2] mtd: rawnand: meson: add support for Amlogic NAND flash controller Message-ID: <20180719103953.26164eb6@bbrezillon> In-Reply-To: <45c1a96c-0d14-dece-37cf-ac428bb98621@amlogic.com> References: <20180613161314.14894-1-yixun.lan@amlogic.com> <20180613161314.14894-3-yixun.lan@amlogic.com> <20180624213844.2207ca6f@bbrezillon> <76d428ff-376a-dce3-cb51-d238564b7c3e@amlogic.com> <20180718210849.493f0087@bbrezillon> <45c1a96c-0d14-dece-37cf-ac428bb98621@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 Hi Yixun, On Thu, 19 Jul 2018 16:13:47 +0800 Yixun Lan wrote: > >>> You're doing DMA on those buffers, and devm_kzalloc() is not > >>> DMA-friendly (returned buffers are not aligned on a cache line). Also, > >>> you don't have to allocate your own buffers because the core already > >>> allocate them (chip->data_buf, chip->oob_poi). All you need to do is > >>> set the NAND_USE_BOUNCE_BUFFER flag in chip->options to make sure > >>> you're always passed a DMA-able buffer. > >>> > >> > >> thanks for the suggestion, we've migrated to use the > >> dmam_alloc_coherent() API > > > > kzalloc() should be just fine, no need to alloc a DMA coherent region. > > > > we're a little bit confused here, isn't devm_kzalloc (previously we are > using) a variant of kzalloc? and since the NAND controller is doing DMA > here, using DMA coherent API is more proper way? Well, making buffers DMA coherent might be expensive, especially if you access them a lot (unless you have a coherency unit and the cache is kept enabled). Regarding the "why is devm_kzalloc() is not DMA-safe?" question, I'd recommend that you read this discussion [1]. > >>>> + mtd->name = devm_kasprintf(nfc->dev, GFP_KERNEL, > >>>> + "%s:nand", dev_name(dev)); > >>>> + if (!mtd->name) { > >>>> + dev_err(nfc->dev, "Failed to allocate mtd->name\n"); > >>>> + return -ENOMEM; > >>>> + } > >>> > >>> You set the name after nand_scan_ident() and make it conditional (only > >>> if ->name == NULL) so that the label property defined in the DT takes > >>> precedence over the default name. > >> > for setting mtd->name conditional, do you mean doing something like this? > > if (!mtd->name) > mtd->name = devm_kasprintf(..) Yes, that's what I meant. > > but we found mtd->name = "ffe07800.nfc" after function > nand_scan_ident(), which is same value as dev_name(dev).. > and there is no cs information encoded there. Hm, that shouldn't be the case. Maybe you can add traces to find out who is setting mtd->name to this value. > > >> > >>> Also, I recommend suffixing this name > >>> with the CS id, just in case you ever need to support connecting several > >>> chips to the same controller. > >>> > >> > >> we actually didn't get the point here, cs is about chip selection with > >> multiple nand chip? and how to get this information? > > > > Well, you currently seem to only support one chip per controller, but I > > guess the IP can handle several CS lines. So my recommendation is about > > choosing a name so that you can later easily add support for multiple > > chips without breaking setups where mtdparts is used. > > > > To sum-up, assuming your NAND chip is always connected to CS0 (on the > > controller side), I'd suggest doing: > > > yes, this is exactly how the hardware connected. > > mtd->name = devm_kasprintf(nfc->dev, GFP_KERNEL, > > "%s:nand.%d", dev_name(dev), cs_id); > > > > where cs_id is the value you extracted from the reg property of the > > NAND node. > > > Ok, you right. > current, the NAND chip is only use one CS (which CE0) for now, what's in > the DT is > > nand@0 { > reg = < 0 >; > .. > }; > > so for the multiple chips it would something like this in DT? > > nand@0 { > reg = < 0 >; > }; > > nand@1 { > reg = < 1 >; > }; Yep, that's for 2 single-die chips. > > or even > nand@0 { > reg = < 0 2 >; > }; > > nand@1 { nand@3 { > reg = < 3 4 >; > }; And this is describing 2 dual-die chips. > > do we need to encode all the cs information here? not sure if we > understand this correctly, but could send out the patch for review.. Yes, reg should contain an array of controller-side CS lines used to select the chip (or a specific die in a chip, the index in the reg table being the id of the die). Regards, Boris [1]http://linux-arm-kernel.infradead.narkive.com/vyJqy0RQ/question-devm-kmalloc-for-dma