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=-9.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT 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 59375C43381 for ; Tue, 26 Feb 2019 11:23:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1C43F206B8 for ; Tue, 26 Feb 2019 11:23:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nokia.onmicrosoft.com header.i=@nokia.onmicrosoft.com header.b="ijZbevGt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726692AbfBZLXz (ORCPT ); Tue, 26 Feb 2019 06:23:55 -0500 Received: from mail-eopbgr00114.outbound.protection.outlook.com ([40.107.0.114]:49379 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726240AbfBZLXz (ORCPT ); Tue, 26 Feb 2019 06:23:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector1-nokia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EWTQJkHleLdow8noY8K/FsrOaX1Yg6ktQMzw06Nmuak=; b=ijZbevGtf3NnSjKF2IUJQ4yzknempZNsWTVtTYbWft62sWhbeqr3XmKTkGGofXYorklRkXw9cEFCImDrimU7FhyVvaqr5iHcvmh2VakkZNM4uWTpX44YUgEGpYeG5lEVuDI/41NfNj33uphIuD8FciSCjSEE7GO5e/gxB4ylQ3c= Received: from VI1PR07MB5902.eurprd07.prod.outlook.com (20.177.202.154) by VI1PR07MB5136.eurprd07.prod.outlook.com (20.178.9.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1665.14; Tue, 26 Feb 2019 11:23:49 +0000 Received: from VI1PR07MB5902.eurprd07.prod.outlook.com ([fe80::8899:2ceb:9508:1c00]) by VI1PR07MB5902.eurprd07.prod.outlook.com ([fe80::8899:2ceb:9508:1c00%5]) with mapi id 15.20.1665.012; Tue, 26 Feb 2019 11:23:49 +0000 From: "Sverdlin, Alexander (Nokia - DE/Ulm)" To: "linux-mtd@lists.infradead.org" CC: "Sverdlin, Alexander (Nokia - DE/Ulm)" , Marek Vasut , Tudor Ambarus , David Woodhouse , Brian Norris , Boris Brezillon , Richard Weinberger , Bin Meng , Mika Westerberg , "Porte, Romain (Nokia - FR/Paris-Saclay)" , "Fabreges, Pascal (Nokia - FR/Paris-Saclay)" , "stable@vger.kernel.org" Subject: [PATCH] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write Thread-Topic: [PATCH] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write Thread-Index: AQHUzcW+bDXgxFVkf0awRsRkik1DPA== Date: Tue, 26 Feb 2019 11:23:49 +0000 Message-ID: <20190226112334.401-1-alexander.sverdlin@nokia.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [131.228.32.181] x-mailer: git-send-email 2.19.1 x-clientproxiedby: HE1PR0502CA0018.eurprd05.prod.outlook.com (2603:10a6:3:e3::28) To VI1PR07MB5902.eurprd07.prod.outlook.com (2603:10a6:803:9a::26) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alexander.sverdlin@nokia.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5380a806-1304-45c8-faaa-08d69bdce11d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7193020);SRVR:VI1PR07MB5136; x-ms-traffictypediagnostic: VI1PR07MB5136: x-microsoft-exchange-diagnostics: =?iso-8859-1?Q?1;VI1PR07MB5136;23:yPhmf32px/sO+A7xaguXqs8QdEof3wK38nfH9hV?= =?iso-8859-1?Q?VcXwH1/JKRtzbCxoOlzOe3Zx5QU59sgzxQBDESRzfsa8Si0rM1X3p7eAut?= =?iso-8859-1?Q?M9rtHqaGPQJn69hSnrPIMU7e1SxeNx03hY0u25VZ2XopyyI4JXlxXUi3wn?= =?iso-8859-1?Q?5CfGrWB3uY9IcPDLjhqMbNH0LzCj+g75b3TeXm8U5BTL3gcHstX+/5F5r3?= =?iso-8859-1?Q?88+6UjNxZhkUavB0tv/MzwWNVzZRU03f6wj5gAoroQp4r8X4kFuJlwzDoL?= =?iso-8859-1?Q?eBknWB0UWYq0/vorw7oXYC09ShBWbSnQpTFmnum0ghPZ4yUGkAaUOJeBdr?= =?iso-8859-1?Q?qJCA51+iLF9NZZNpT+wLxtty3I7Rifg8TVHz84amZ84iWQKvhRT1vcxaST?= =?iso-8859-1?Q?Ayo5wjrwdcS04hBrnt3gQRGPL5nMTLXCf6bkIzIUZAcQNhx4zi5yNLWEbZ?= =?iso-8859-1?Q?gSA1/eHOi4YDa/bEiSxCG39MHhMp6HHz5L1otS4y+Nozu1wYUB9hdBeqyP?= =?iso-8859-1?Q?0jcCzb5ZqRltCVwoCVmu3shCsY0YFssjveFsfRPfmzQlAJrtoB2QYTwp9z?= =?iso-8859-1?Q?873kuWNvbk0MPZIg+aBcZaR7hETF7VtOC3F+GEE3p4bgmr98YQgOBsqzD5?= =?iso-8859-1?Q?1C7VhMkwc40cXPQf32v5JGTqtYfsiNftmC2VdTEAzKBc20/wE/wvyXmPqI?= =?iso-8859-1?Q?LL5ovPj2MBxZOUlXCcYxIiEusJAneVZU6J9ITeTcajALELZ0eBU5Fjh/e9?= =?iso-8859-1?Q?X2ijJrhPbIaIgyaOcUZKy69Qn/M7WtxOpHsik+LEaPVBd3pRYFmad2XplS?= =?iso-8859-1?Q?bKUdGZA9bfZfh/01xu5DRw6xaX9/jD7J4rBM03Yivd7WLjRYhVRP8jqdy8?= =?iso-8859-1?Q?IyGbT5ht57D/8CkljJ/KYyCpaG8RzHdp8km6AeBwFsfZa31HABZPH7ntVy?= =?iso-8859-1?Q?TiVPOATFr+VVaPWog5+b6kz0kMGBSICBmW+QWQosQ6c1KYeQQU6cxtVEdb?= =?iso-8859-1?Q?+n8sbmPj8Bq4DaPU5lo/D4gzjvexzSJOPB1EHfMGID9MqbX9OaWCUeuUfk?= =?iso-8859-1?Q?dsQ0ooqhhhAky8vYsF/IsN8GCuPAsIg7+jzlOkh5OGa+tp5QiMrD1ItGju?= =?iso-8859-1?Q?AtAD/ahX7UPDBQ/JG9EppwX9vQX0DgSg4Jqfc0OhUU6hsfRI0q5pKs0Z8s?= =?iso-8859-1?Q?HyuSdLwFTdjP4zrTOeLo/9ZboL+8QaCP0Naf5jgpdqlLjfuHN2R9gae9UY?= =?iso-8859-1?Q?+7NuXEFgCw/6kb4sar5Uyy2hrwTgIaLn2M7Nfbdu2wZHagnpQoyAYJcdqd?= =?iso-8859-1?Q?wM=3D?= x-microsoft-antispam-prvs: x-forefront-prvs: 096029FF66 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(136003)(366004)(396003)(346002)(39860400002)(376002)(199004)(189003)(6916009)(54906003)(186003)(99286004)(68736007)(106356001)(105586002)(305945005)(2351001)(71190400001)(71200400001)(7736002)(478600001)(7416002)(6116002)(26005)(3846002)(8936002)(86362001)(25786009)(102836004)(50226002)(386003)(6506007)(316002)(5660300002)(2616005)(2906002)(4326008)(52116002)(486006)(476003)(97736004)(6512007)(66066001)(256004)(5640700003)(14454004)(1076003)(6486002)(81166006)(6436002)(2501003)(8676002)(36756003)(81156014)(53936002)(14444005);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR07MB5136;H:VI1PR07MB5902.eurprd07.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: nokia.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: p9dp7F5zcA4loJxT24+njLl6lYimBp/LcnTLIgTZ57Ofh2KaAbei+gMk+AMeb+aYVz9ciLUHrgpMz8Cswuy+xs6tuhHoLUV7jW1GOX/Edxd67mhuroRzv1ExNqc0NHr8vcBaaf6VU3QeGhV8PA8YCf6q/N8e98gGU7enMGkyf48JfQvZzhPNuWj3BWg4E3i8TQEi8s7HcTMx6uLci0ps1B6O6nPsLGGCy8VL7U1wBT1HfkVJ4vu/RbTH2M+3Gi4sIEdbn4yk/tihsJY9GQrtoOU4vb2U7s9XsuZMjOO+CGcZxm4doVRRZ7222skvTybHu7ljedFhDBrLcNJjdNzSRkn2A6JjPJw9FXahRF9WWrBEnJ4GLX1kl/VziKIORW2208+i3lVtaLhcH5v2yWb2cNm9ysy/Sd6557inBRZu9ME= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5380a806-1304-45c8-faaa-08d69bdce11d X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Feb 2019 11:23:49.5075 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB5136 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org It was observed that reads crossing 4K address boundary are failing. This limitation is mentioned in Intel documents: Intel(R) 9 Series Chipset Family Platform Controller Hub (PCH) Datasheet: "5.26.3 Flash Access Program Register Access: * Program Register Accesses are not allowed to cross a 4 KB boundary..." Enhanced Serial Peripheral Interface (eSPI) Interface Base Specification (for Client and Server Platforms): "5.1.4 Address For other memory transactions, the address may start or end at any byte boundary. However, the address and payload length combination must not cross the naturally aligned address boundary of the corresponding Maximum Payload Size. It must not cross a 4 KB address boundary." Avoid this by splitting an operation crossing the boundary into two operations. Cc: stable@vger.kernel.org Reported-by: Romain Porte Tested-by: Pascal Fabreges Signed-off-by: Alexander Sverdlin --- drivers/mtd/spi-nor/intel-spi.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/mtd/spi-nor/intel-spi.c b/drivers/mtd/spi-nor/intel-sp= i.c index af0a220..b83ea79 100644 --- a/drivers/mtd/spi-nor/intel-spi.c +++ b/drivers/mtd/spi-nor/intel-spi.c @@ -632,6 +632,10 @@ static ssize_t intel_spi_read(struct spi_nor *nor, lof= f_t from, size_t len, while (len > 0) { block_size =3D min_t(size_t, len, INTEL_SPI_FIFO_SZ); =20 + /* Read cannot cross 4K boundary */ + if ((from ^ (from + block_size - 1)) & ~(SZ_4K - 1LL)) + block_size -=3D (from + block_size) & (SZ_4K - 1); + writel(from, ispi->base + FADDR); =20 val =3D readl(ispi->base + HSFSTS_CTL); @@ -685,6 +689,10 @@ static ssize_t intel_spi_write(struct spi_nor *nor, lo= ff_t to, size_t len, while (len > 0) { block_size =3D min_t(size_t, len, INTEL_SPI_FIFO_SZ); =20 + /* Write cannot cross 4K boundary */ + if ((to ^ (to + block_size - 1)) & ~(SZ_4K - 1LL)) + block_size -=3D (to + block_size) & (SZ_4K - 1); + writel(to, ispi->base + FADDR); =20 val =3D readl(ispi->base + HSFSTS_CTL); --=20 2.4.6