Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1503577imm; Thu, 19 Jul 2018 02:54:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc4ZvsAa4UdBxjPhktmug72sag+Pidg3sDdez33QGXCA+SQyr5n0gvGC3WdtQaDc7Wd0KK/ X-Received: by 2002:a62:9645:: with SMTP id c66-v6mr8703971pfe.56.1531994094456; Thu, 19 Jul 2018 02:54:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531994094; cv=none; d=google.com; s=arc-20160816; b=pH0c1NG6yFxOTU1GHohJTvD8xLje09lajJ/7dYaYRI8R95N1uqwBZXTRYL693gZVK/ sGj8Q+dyK8L4WJ3bz+niadgiKCa0pdLnwHvk9M6Vgjnk35SbhbI57owXa9H+oEcvDmkl FnKVv2b3ZMieAjW2dI5YLPF+Q1YMn1wd7t2VL7yhjIwm/FQDdcVxsPkHZc0eWXcdAFge DFxY7oj3nB2Z5RulGvNBuR9W/DyOJ6jQJlOPM01edZEwGy9+2guXXPinAybE8mQhtKxD NokZG1E6iU/492g9o2kfK6zuhuP5ImfL7VspFQPCN8Cw+kJBRYNBbKAEU6eEphrYuVKz c8Xg== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=v88R4ykjduv23XYfTEOJHgnNav9EqhZUlg6wyJS09vE=; b=El2pVatnmSJoKuq3dUsA7FUJdjzhMcpmH6mhGMEtDRAkG9mWSTeNDpcX5eQM48lFh0 P284hDaZfKOODID8RojHNByctl1Y0abzETKvpoh6lSTU4wy1b4FF1MqF6qGM5EBh6IpS lUhDQKJIz0hMmIE2bUU78SeuGkR7ksTSSdlBgcDRgsbLck8JuBTyph1WVLsU3uJTIc5k R0RsiDCZ/n/Ly+DUDRkgbUNMuCZAuRckR1kR//kSnqtzxTcebCUaXDeOrtd1jj2CPUql R5v2/y6Y3PYGkk+aMJay/N/9/IpG/jzqI2K9jeuM+94eZKkKbYwhAoBgssS3msViYQR8 9/EQ== 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 x18-v6si5045055pll.193.2018.07.19.02.54.39; Thu, 19 Jul 2018 02:54:54 -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 S1727553AbeGSKgV (ORCPT + 99 others); Thu, 19 Jul 2018 06:36:21 -0400 Received: from mail-sh2.amlogic.com ([58.32.228.45]:8191 "EHLO mail-sh2.amlogic.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726893AbeGSKgU (ORCPT ); Thu, 19 Jul 2018 06:36:20 -0400 Received: from [192.168.90.200] (10.18.20.235) by mail-sh2.amlogic.com (10.18.11.6) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Thu, 19 Jul 2018 17:53:16 +0800 Subject: Re: [PATCH 2/2] mtd: rawnand: meson: add support for Amlogic NAND flash controller To: Boris Brezillon 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> <20180719103953.26164eb6@bbrezillon> 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 From: Yixun Lan Message-ID: Date: Thu, 19 Jul 2018 17:53:24 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20180719103953.26164eb6@bbrezillon> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.18.20.235] X-ClientProxiedBy: mail-sh2.amlogic.com (10.18.11.6) To mail-sh2.amlogic.com (10.18.11.6) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org HI Boris On 07/19/18 16:39, Boris Brezillon wrote: > 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]. > great, thanks for the info. we fixed this in patch v2 >>>>>> + 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. > will trace this, then get back to you >> >>>> >>>>> 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). > much clear about this, thanks Yixun