Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5469774img; Wed, 27 Mar 2019 09:05:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXYSmK8KKS0eOMd3MmKgvpC+/ElEvSeFODWGX+8uVpcE4PUKTdWM1e4R28DQwAz98gVUdU X-Received: by 2002:a62:293:: with SMTP id 141mr35481259pfc.245.1553702712698; Wed, 27 Mar 2019 09:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553702712; cv=none; d=google.com; s=arc-20160816; b=iFEBZd1x0QGHzMvxAA22KYedyfCv2xMG6zizYxbfX6ZzAw5jtv+5/CX1fZSTxXXzqy NZBCzQNflGApSniD5GOz9Qm1G/myQhr4wtBYE63ud1KiHRxmh1FKVwg86I+lTyjMqwD6 ZrR02FqwjvaBk3AULloO881RhAapZjO0y08Y0SqNcDdhvvtOp9tFroAd4/feZ02pe2ww JuILGJpxWysE9Lb/7//gJm6aNRjakwnPI4Sf7B+JjotBNQmytiIPGHPd6yo07sJWvfYb rKUSOixPAt787/fRY7dC+AdUVw3HbpoTlMb1CRSgM+ZB38xQeHQAgVWXaX3wH5IY8seW MrNA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=bY6i+Gb3B1LRhSlCo7jad+rnNzPpomSDjT2EHAj2YhE=; b=o9rldMwWdzD9rchw7D/K1YsZ7F3S38bz1qDoKW83yRZgjBjH/BbiVUuTWzr+Xt7qfi hAjMSVJgGR7e1bcUXx0hGo3iZAjQgBNelE/FL8xkm/cwE3ZiF1hOvUilKEaHQ0MGI1SA 7QLt+ZwFp69KZmW/yHisYyddMVDe0NpvJ5yy+1Q4qSXcDatVNdm4enAkwqllyy08CsqI wZu9gLzXMXCXSYDSo5e9cw3asiJs/O+1WsyHmMvfgUYdmNwLXzZp68pO2p/2K6JMBDKl tTBu4ZI9w64O0VXngVWAKe3ak+SKrwPyYdKTzOVp20AV5HRRNRBQFAoBgaMUX0BSkBx+ 8IWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=x+nuKIaz; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k19si18649159pfi.31.2019.03.27.09.04.56; Wed, 27 Mar 2019 09:05:12 -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; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=x+nuKIaz; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727632AbfC0QEG (ORCPT + 99 others); Wed, 27 Mar 2019 12:04:06 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:35594 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727389AbfC0QEF (ORCPT ); Wed, 27 Mar 2019 12:04:05 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x2RG3aLv040085; Wed, 27 Mar 2019 11:03:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1553702616; bh=bY6i+Gb3B1LRhSlCo7jad+rnNzPpomSDjT2EHAj2YhE=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=x+nuKIazGsJ/LII5BL7C3FgtqpX7YV+Jc2OFMgPiwV7Wb4emj1kxo8is156QhYvXb QkB6E+CyBeIK+sv0cs9yMDMO9fE4qslVOCIDr5V6VMO5Dkl/J07LavJ78TM948hNGr T0by+ykhjGwCqRU+HpuB7fLnxwYSdplo2TdGZAcI= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x2RG3ZXh126512 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 27 Mar 2019 11:03:35 -0500 Received: from DLEE103.ent.ti.com (157.170.170.33) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Wed, 27 Mar 2019 11:03:35 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Wed, 27 Mar 2019 11:03:35 -0500 Received: from [172.24.190.89] (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id x2RG3V3k102496; Wed, 27 Mar 2019 11:03:32 -0500 Subject: Re: [PATCH v2] mtd: spi-nor: Return error when nor->addr_width does not match the device size To: Liu Xiang CC: Liu Xiang , "bbrezillon@kernel.org" , "richard@nod.at" , "linux-kernel@vger.kernel.org" , "marek.vasut@gmail.com" , "linux-mtd@lists.infradead.org" , "computersforpeace@gmail.com" , "dwmw2@infradead.org" References: <1552484753-3393-1-git-send-email-liu.xiang6@zte.com.cn> <823dcd3f-8b9f-15c5-a072-06625120766e@ti.com> <209ad144.9c0a.169ba96e2ad.Coremail.liuxiang_1999@126.com> From: Vignesh Raghavendra Message-ID: Date: Wed, 27 Mar 2019 21:34:30 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <209ad144.9c0a.169ba96e2ad.Coremail.liuxiang_1999@126.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26/03/19 8:50 PM, Liu Xiang wrote: > At 2019-03-19 13:22:15, "Vignesh Raghavendra" wrote: >> Hi, >> >> On 13/03/19 7:15 PM, Liu Xiang wrote: >>> In some is25lp256, the DWORD1 of JEDEC Basic Flash Parameter Header >>> is 0xfff920e5. So the DWORD1[18:17] Address Bytes bits are 0b00, >>> means that 3-Byte only addressing. But the device size is larger >>> than 16MB, nor->addr_width must be 4 to access the whole address. >>> An error should be returned when nor->addr_width does not match >>> the device size in spi_nor_parse_bfpt(). Then it can go back to >>> use spi_nor_ids[] for setting the right addr_width. >>> >>> Suggested-by: Boris Brezillon >>> Signed-off-by: Liu Xiang >>> --- >>> drivers/mtd/spi-nor/spi-nor.c | 8 ++++++++ >>> 1 file changed, 8 insertions(+) >>> >>> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c >>> index 6e13bbd..63933c7 100644 >>> --- a/drivers/mtd/spi-nor/spi-nor.c >>> +++ b/drivers/mtd/spi-nor/spi-nor.c >>> @@ -2811,6 +2811,14 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, >>> } >>> params->size >>= 3; /* Convert to bytes. */ >>> >>> + /* >>> + * If the device exceeds 16MiB, addr_width must be 4. >>> + * addr_width == 3 means the Address Bytes we are >>> + * reading from BFPT is wrong. >>> + */ >> >> JESD216 standard does not mandate flash devices >16MiB to always support >> 4 byte addressing opcode. So, its okay for flash vendor to support >>> 16MiB flash with 3 byte addressing and Bank/extended address register. >> >>> + if (params->size > 0x1000000 && nor->addr_width == 3) >>> + return -EINVAL; >>> + >> >> Assuming only DWORD1[18:17] bits are wrong, then returning from here >> would mean we miss parsing Sector Erase settings, Quad Enable >> Requirements etc from BFPT which is kind of bad. >> I suggest to move the fix to[1], addr_width indicated in flash_info >> struct of the device can take precedence over SFDP. >> >> [1]https://elixir.bootlin.com/linux/latest/source/drivers/mtd/spi-nor/spi-nor.c#L4106 > > Boris has added a fixup function, do you think this is more better: > > static int > is25lp256_post_bfpt_fixups(struct spi_nor *nor, > const struct sfdp_parameter_header *bfpt_header, > const struct sfdp_bfpt *bfpt, > struct spi_nor_flash_parameter *params) > { > /* > * IS25LP256 supports 4B opcodes. > * Unfortunately, some devices get BFPT_DWORD1_ADDRESS_BYTES_3_ONLY > * from BFPT table for address width. We should fix it. > */ > if (bfpt.dwords[BFPT_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK == > BFPT_DWORD1_ADDRESS_BYTES_3_ONLY) > nor->addr_width = 4; > > return 0; > } > > static struct spi_nor_fixups is25lp256_fixups = { > .post_bfpt = is25lp256_post_bfpt_fixups, > }; > > Sounds fine to me as is25lp256 is the only part that needs this quirk at the moment. -- Regards Vignesh