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,URIBL_BLOCKED,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 C0B77C43381 for ; Wed, 13 Mar 2019 08:21:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 367592183F for ; Wed, 13 Mar 2019 08:21:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nokia.onmicrosoft.com header.i=@nokia.onmicrosoft.com header.b="JWT7wWJY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726539AbfCMIVu (ORCPT ); Wed, 13 Mar 2019 04:21:50 -0400 Received: from mail-eopbgr80117.outbound.protection.outlook.com ([40.107.8.117]:50176 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726130AbfCMIVu (ORCPT ); Wed, 13 Mar 2019 04:21:50 -0400 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=6mZzVM3WCyGXgaOhnIi/wLRwtZlf4jFIqBC8XQwtAOc=; b=JWT7wWJYXHx2U4Lx+uQbWvQQWoS4wJri256R7NyL/nzfp/RK8YgjUAJ7pFpw2k5qevF7Pzgr98DAxxTi9Oo6boASHcJvmunR/HrOIe+DdEkW/j1H1o0IGZUAVN6HD0S9XOSjWArIYS8SKpBLQJHZO0+mJEthIQT7vRteuYzZBDQ= Received: from VI1PR07MB5902.eurprd07.prod.outlook.com (20.177.202.154) by VI1PR07MB5328.eurprd07.prod.outlook.com (20.178.11.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.8; Wed, 13 Mar 2019 08:21:46 +0000 Received: from VI1PR07MB5902.eurprd07.prod.outlook.com ([fe80::e8f9:b49a:ad04:a8e5]) by VI1PR07MB5902.eurprd07.prod.outlook.com ([fe80::e8f9:b49a:ad04:a8e5%2]) with mapi id 15.20.1709.011; Wed, 13 Mar 2019 08:21:46 +0000 From: "Sverdlin, Alexander (Nokia - DE/Ulm)" To: "linux-mtd@lists.infradead.org" , Mika Westerberg CC: "Sverdlin, Alexander (Nokia - DE/Ulm)" , Marek Vasut , Tudor Ambarus , David Woodhouse , Brian Norris , Boris Brezillon , Richard Weinberger , Bin Meng , "Porte, Romain (Nokia - FR/Paris-Saclay)" , "Fabreges, Pascal (Nokia - FR/Paris-Saclay)" , "stable@vger.kernel.org" Subject: [PATCH v3] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write Thread-Topic: [PATCH v3] spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write Thread-Index: AQHU2XXMQ+jSwdChMUilG2pNVzdJLg== Date: Wed, 13 Mar 2019 08:21:46 +0000 Message-ID: <20190313082120.17913-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.21.0 x-clientproxiedby: HE1PR0701CA0066.eurprd07.prod.outlook.com (2603:10a6:3:9e::34) 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: 8ec377ab-a2ce-4d24-d752-08d6a78ceea4 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:VI1PR07MB5328; x-ms-traffictypediagnostic: VI1PR07MB5328: x-microsoft-antispam-prvs: x-forefront-prvs: 09752BC779 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(396003)(376002)(136003)(366004)(346002)(189003)(199004)(54534003)(26005)(102836004)(186003)(3846002)(8936002)(6506007)(6512007)(386003)(5660300002)(6486002)(52116002)(86362001)(476003)(2616005)(97736004)(50226002)(4326008)(68736007)(25786009)(6116002)(36756003)(486006)(14454004)(478600001)(105586002)(14444005)(53936002)(256004)(71200400001)(66066001)(71190400001)(2501003)(1076003)(7416002)(6436002)(81156014)(8676002)(81166006)(99286004)(2906002)(110136005)(54906003)(316002)(7736002)(305945005)(106356001);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR07MB5328;H:VI1PR07MB5902.eurprd07.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A: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: 5fHBkWwfadKv0D9EJu7yhpAynNuQtI2z8cbyqwuiKS1oHCsU0KoTJekixK/R0cSjjVP53Jwgx0mT9XqFGUpHs6ZzlkztqWxRDIQKdd20RRrZGnOyZQUqcTMLS4V5ZgeXv0Tsb2f22gHfWUf5aDPfk+qmV7lDErvDCeLhD9kEPH5bnmhQjIgRso1eyqWuxWWOMXdO0TbQ0iz67p2eGVCD9Z4dwrb7YFgXAoVbvBgSmzSW2G7oH+NmkkInvJ+JUiTh1DqCLtRab3D/JTE+b+dpshLy39Ne7FV2pfI8umTlH92tQiE2Q02KXaQhy+AUF7hddPl8fh7hGGUyP8ZfhJnSvf+213EG7huzjKEazd+u5phQpGS7P92MHVOu9oOLwumbkMb5cWUU7xAdNDAKh9paH1SeDF4KCdE/AHkSty/wC3E= 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: 8ec377ab-a2ce-4d24-d752-08d6a78ceea4 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Mar 2019 08:21:46.3206 (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: VI1PR07MB5328 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 --- Changelog: v2: More macros! As suggested by Mika. v3: Actually compiled. Sorry Mika, the lines are really long now. 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..d60cbf2 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 */ + block_size =3D min_t(loff_t, from + block_size, + round_up(from + 1, SZ_4K)) - from; + 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 */ + block_size =3D min_t(loff_t, to + block_size, + round_up(to + 1, SZ_4K)) - to; + writel(to, ispi->base + FADDR); =20 val =3D readl(ispi->base + HSFSTS_CTL); --=20 2.4.6