From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95678C43441 for ; Fri, 16 Nov 2018 11:17:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 33A882084A for ; Fri, 16 Nov 2018 11:17:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="vPxCb8uq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33A882084A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389646AbeKPV3N (ORCPT ); Fri, 16 Nov 2018 16:29:13 -0500 Received: from esa5.microchip.iphmx.com ([216.71.150.166]:63384 "EHLO esa5.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727874AbeKPV3M (ORCPT ); Fri, 16 Nov 2018 16:29:12 -0500 X-IronPort-AV: E=Sophos;i="5.56,240,1539673200"; d="scan'208";a="21230989" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 16 Nov 2018 04:17:18 -0700 Received: from NAM01-BN3-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.76.107) with Microsoft SMTP Server (TLS) id 14.3.352.0; Fri, 16 Nov 2018 04:17:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector1-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DUn3Iy2yeia2SlG6rgGKrOG9EUK6s/cTQc6qMRaEjwA=; b=vPxCb8uqOxd7HRv+JSul3FncTb68MHvVoGM3Mecd0pGLHlFwfJJ25QyFPbFLarL73nScM16LUhpl3EF18ORieN2WWJc2no3rJ3rU/cf3d/+RP0rUDnbUxyON62Cez4hi3WBo+yQdHlASuVPxG07mvAI2eFK1RmiGbQYA8a06cew= Received: from BN6PR11MB1842.namprd11.prod.outlook.com (10.175.99.146) by BN6PR11MB1540.namprd11.prod.outlook.com (10.172.22.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.30; Fri, 16 Nov 2018 11:17:15 +0000 Received: from BN6PR11MB1842.namprd11.prod.outlook.com ([fe80::11b7:21db:803a:7cfa]) by BN6PR11MB1842.namprd11.prod.outlook.com ([fe80::11b7:21db:803a:7cfa%5]) with mapi id 15.20.1294.045; Fri, 16 Nov 2018 11:17:15 +0000 From: To: , , , , , , CC: Subject: [PATCH] mtd: spi-nor: fix selection of uniform erase type in flexible conf Thread-Topic: [PATCH] mtd: spi-nor: fix selection of uniform erase type in flexible conf Thread-Index: AQHUfZ3tA+dcLeFrOEOuQb9SrChWeA== Date: Fri, 16 Nov 2018 11:17:14 +0000 Message-ID: <20181116111708.30259-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR08CA0147.eurprd08.prod.outlook.com (2603:10a6:800:d5::25) To BN6PR11MB1842.namprd11.prod.outlook.com (2603:10b6:404:103::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Tudor.Ambarus@microchip.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [94.177.32.154] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BN6PR11MB1540;6:f41k6ieRO/a0wNwctEfOdw0ffVQqUZuCPozpL72O1LcaRNbQOYSyCCvSgv09itwJIaxn5Co3yZBKndI/VIX8QvUc+K1L1V1FFH5mLUBCxfYKr+tu2A3xHsLbloxAlFCaKOZKn9ts1idY8GeR/7pMkVt5h62q1peN+ayEDHLlKK23bZKO4JVXzaMzq1oA+DSfxljfN6LoSqk3MdQ32c+VVxxJASuEhIPSuunfKMF8EKsgjkTz4Tfu2bQ/MQeIrzQAqJBBcLq0Ka67zfjYV92+jrdaokgm/RkdX1s/LHU65enjYc6JYHpVn39dgT2LD4ulXysAIIl9tJEklOCD9ESSHXlUtxXj71n/mdS8FYab9QbQ6FkOW1/yo6Sgfmxai/RKiW9ughrw/nvW4FqNYz0+l8Z+fXgtP5/XzJgJ67VRGHbwVPIR3w6G/Jpf4NH8xfFnOMs4R5PtXOtLYWfJlyTYgA==;5:OxvCrGy1O512Yn4E6bYYYhtAlIxzA4fGh2Q6kV7dLayf/qp/5P+2dE61QPwZwLQTq141JTSx7Z5nr+2mMSVnLz/4XSJWZExHALMjghpwDjC7x0PzE05Od/LJcJoQy2hLnzCrAnUxoxQIsa7zmG9OehPYhB5im2OxNOWwgFUIqpE=;7:Zyl14Bmwb305B0E/dbHTU0AdbJ+Oky5fRpASGPyAZOkecyvjCGGAsM7HjTF6KaZp683AlCltyjH+i1z+7Yee+iOLze5g1+OHGAIyFRkJFxzGLDai4Qd6XeCtdQYyPpd6HhneLseWGnRphC0+qECujQ== x-ms-office365-filtering-correlation-id: ba4f4241-39d2-44f2-c413-08d64bb50fcc x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:BN6PR11MB1540; x-ms-traffictypediagnostic: BN6PR11MB1540: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(3231415)(944501410)(52105112)(10201501046)(93006095)(93001095)(3002001)(148016)(149066)(150057)(6041310)(20161123562045)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051)(76991095);SRVR:BN6PR11MB1540;BCL:0;PCL:0;RULEID:;SRVR:BN6PR11MB1540; x-forefront-prvs: 0858FF8026 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(366004)(136003)(346002)(39860400002)(376002)(396003)(189003)(199004)(107886003)(72206003)(68736007)(478600001)(25786009)(97736004)(36756003)(4326008)(110136005)(316002)(39060400002)(2906002)(52116002)(99286004)(386003)(2201001)(14454004)(6116002)(2501003)(26005)(1076002)(186003)(102836004)(86362001)(6506007)(5660300001)(1857600001)(3846002)(2900100001)(14444005)(2616005)(66066001)(106356001)(476003)(105586002)(71190400001)(71200400001)(256004)(8676002)(486006)(81166006)(53936002)(305945005)(6512007)(7736002)(81156014)(6486002)(6436002)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR11MB1540;H:BN6PR11MB1842.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: hZHY0GZ+vZrSvsJYHVKh9/d/oHbtk7I5GHoizcZ58PnetDBSO4kr/ovuWHaysCeZEAvO6LZEnVYJZBOBw5LjDSOcSgLCPBXtqzwhhBXwifeD0c19PVHzG8+VxWHuZuHe03hh4U4AHpL550o6M7/6918VE78yE+hT3iR1x1xxAEriLpUCfKv9ypyJyrGUlSAxYG/xhHQKzjy7EQT1faGGGIcmEzOhIUN/qOC99fw0I+oz5SjiAZMbM05y8R/vGJM4KcLK+Zd7ea96oaV8dnY99YPhtDOUxArByVS46C+hz9HGBQHnsO/R9LUOkM+ImPlBEQWFA1kUiY6VxekyKzCHvhbhmRanjcAR9uqecBbJN/4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: ba4f4241-39d2-44f2-c413-08d64bb50fcc X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Nov 2018 11:17:14.8267 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB1540 X-OriginatorOrg: microchip.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are uniform, non-uniform and flexible erase flash configurations. The non-uniform erase types, are the erase types that can _not_ erase the entire flash by their own. As the code was, in case flashes had flexible erase capabilities (support both uniform and non-uniform erase types in the same flash configuration) and supported multiple uniform erase type sizes, the code did not sort the uniform erase types, and could select the wrong erase type size. Sort the uniform erase mask in case of flexible erase flash configurations, in order to select the best uniform erase type size. Uniform, non-uniform, and flexible configurations with just a valid uniform erase type, are not affected by this change. Uniform erase tested on mx25l3273fm2i-08g and sst26vf064B-104i/sn. Non uniform erase tested on sst26vf064B-104i/sn. Fixes: 5390a8df769e ("mtd: spi-nor: add support to non-uniform SFDP SPI NOR= flash memories") Signed-off-by: Tudor Ambarus --- drivers/mtd/spi-nor/spi-nor.c | 52 +++++++++++++++++++++++++++++++--------= ---- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 69784b3b8ca1..4c595cf686e2 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -2529,6 +2529,34 @@ static int spi_nor_map_cmp_erase_type(const void *l,= const void *r) } =20 /** + * spi_nor_sort_erase_mask() - sort erase mask + * @map: the erase map of the SPI NOR + * @erase_mask: the erase type mask to be sorted + * + * Replicate the sort done for the map's erase types in BFPT: sort the era= se + * mask in ascending order with the smallest erase type size starting from + * BIT(0) in the sorted erase mask. + * + * Return: sorted erase mask. + */ +static u8 spi_nor_sort_erase_mask(struct spi_nor_erase_map *map, u8 erase_= mask) +{ + struct spi_nor_erase_type *erase_type =3D map->erase_type; + int i; + u8 sorted_erase_mask =3D 0; + + if (!erase_mask) + return 0; + + /* Replicate the sort done for the map's erase types. */ + for (i =3D 0; i < SNOR_ERASE_TYPE_MAX; i++) + if (erase_type[i].size && erase_mask & BIT(erase_type[i].idx)) + sorted_erase_mask |=3D BIT(i); + + return sorted_erase_mask; +} + +/** * spi_nor_regions_sort_erase_types() - sort erase types in each region * @map: the erase map of the SPI NOR * @@ -2543,19 +2571,13 @@ static int spi_nor_map_cmp_erase_type(const void *l= , const void *r) static void spi_nor_regions_sort_erase_types(struct spi_nor_erase_map *map= ) { struct spi_nor_erase_region *region =3D map->regions; - struct spi_nor_erase_type *erase_type =3D map->erase_type; - int i; u8 region_erase_mask, sorted_erase_mask; =20 while (region) { region_erase_mask =3D region->offset & SNOR_ERASE_TYPE_MASK; =20 - /* Replicate the sort done for the map's erase types. */ - sorted_erase_mask =3D 0; - for (i =3D 0; i < SNOR_ERASE_TYPE_MAX; i++) - if (erase_type[i].size && - region_erase_mask & BIT(erase_type[i].idx)) - sorted_erase_mask |=3D BIT(i); + sorted_erase_mask =3D spi_nor_sort_erase_mask(map, + region_erase_mask); =20 /* Overwrite erase mask. */ region->offset =3D (region->offset & ~SNOR_ERASE_TYPE_MASK) | @@ -2729,9 +2751,8 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, * uniform_erase_type bitmask. The bitmask will be used later on when * selecting the uniform erase. */ - spi_nor_regions_sort_erase_types(map); - map->uniform_erase_type =3D map->uniform_region.offset & - SNOR_ERASE_TYPE_MASK; + map->uniform_erase_type =3D spi_nor_sort_erase_mask(map, + map->uniform_erase_type); =20 /* Stop here if not JESD216 rev A or later. */ if (bfpt_header->length < BFPT_DWORD_MAX) @@ -2985,7 +3006,7 @@ static int spi_nor_init_non_uniform_erase_map(struct = spi_nor *nor, u64 offset; u32 region_count; int i, j; - u8 erase_type; + u8 erase_type, uniform_erase_type; =20 region_count =3D SMPT_MAP_REGION_COUNT(*smpt); /* @@ -2998,7 +3019,7 @@ static int spi_nor_init_non_uniform_erase_map(struct = spi_nor *nor, return -ENOMEM; map->regions =3D region; =20 - map->uniform_erase_type =3D 0xff; + uniform_erase_type =3D 0xff; offset =3D 0; /* Populate regions. */ for (i =3D 0; i < region_count; i++) { @@ -3013,12 +3034,15 @@ static int spi_nor_init_non_uniform_erase_map(struc= t spi_nor *nor, * Save the erase types that are supported in all regions and * can erase the entire flash memory. */ - map->uniform_erase_type &=3D erase_type; + uniform_erase_type &=3D erase_type; =20 offset =3D (region[i].offset & ~SNOR_ERASE_FLAGS_MASK) + region[i].size; } =20 + map->uniform_erase_type =3D spi_nor_sort_erase_mask(map, + uniform_erase_type); + spi_nor_region_mark_end(®ion[i - 1]); =20 return 0; --=20 2.9.4