Received: by 10.223.164.202 with SMTP id h10csp4498484wrb; Wed, 29 Nov 2017 07:17:41 -0800 (PST) X-Google-Smtp-Source: AGs4zMaNbRMlopw9OsTh8ITmS7WYmykkoi4O3HwPuzwUjucrXhf0CM8dSXvsPd2ZVr0kJkt1hIMa X-Received: by 10.84.248.145 with SMTP id q17mr3142613pll.416.1511968661411; Wed, 29 Nov 2017 07:17:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511968661; cv=none; d=google.com; s=arc-20160816; b=xUC6d2WeScAQ4TUAHSy29UY0VzRqFjgx0l6QG84eDmilR/andoagYDbn9gIQ6QvhEQ kQnmiOHfdf0s5JtjDbCzqEy4QKr8vqWeHgBlwccv6ZhLvtK503glY5Sv530d74BhmE4U 2Vg7F0uVRTXU7zsBGhWsClcD1XEXOl79dPiYEJhtrCwDZ+kkreSV2o+CxUSzyBG3w3rJ zmW1otn/i017n5eoh3McGzbuGrY4l1JaHhUuABSImT+TV0ldis0QSOXIehJnKjLC6qik F0a4x2pCwf11tqQgIfdM6gV76n9YDYpJowYxxcMADmkHa4ahocfuScuZhiPWs3Z4FtPQ oDPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from:arc-authentication-results; bh=HMy480JB/3YXzCKVSboNEdS6haTbtA+km+eHNLzxvSE=; b=JxmgTBjnawkrm2h32b3JQ7HY0F6gqEZwC0AjB9Kz/Y5eNsXQ+kSXH1nreCctC+OleZ UFwrN4NWeyD6bP8q0OfZuJHMq7oxpeOkxIYXeeDDoMH5tf1XXEhgqk21dFehmUuEn9Rp /goyuv7PRoXa81Ln5c2H7+wHiMU5rUs471NIl7NnXUbnLzHVr0GNKlQeUGBs9DGulBUl 1Spa8Td/hqUNhx58/zWw9RDiccoALS5MnV3xnYeiyF3xXBRD47C29ytlhwZ285yu9Vcn OLx+kaAy1KZC5jAptpEb4g/YwadXlpQ/RGWwMHCA1e0b4GJgSIHaptsVljHvDODgVSxW JAJQ== 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 h187si1371106pgc.561.2017.11.29.07.17.28; Wed, 29 Nov 2017 07:17:41 -0800 (PST) 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 S1754997AbdK2PPh convert rfc822-to-8bit (ORCPT + 69 others); Wed, 29 Nov 2017 10:15:37 -0500 Received: from mailout.micron.com ([137.201.242.129]:49139 "EHLO mailout.micron.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751668AbdK2PPg (ORCPT ); Wed, 29 Nov 2017 10:15:36 -0500 Received: from mail.micron.com (bowex17b.micron.com [137.201.21.210]) by mailout.micron.com (8.14.4/8.14.6) with ESMTP id vATFEueh015608; Wed, 29 Nov 2017 08:14:57 -0700 Received: from SIWEX5H.sing.micron.com (10.160.29.166) by bowex17b.micron.com (137.201.21.210) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Wed, 29 Nov 2017 08:14:55 -0700 Received: from SIWEX5A.sing.micron.com (10.160.29.59) by SIWEX5H.sing.micron.com (10.160.29.166) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Wed, 29 Nov 2017 23:14:52 +0800 Received: from SIWEX5A.sing.micron.com ([fe80::2589:3710:2c7d:b4a]) by SIWEX5A.sing.micron.com ([fe80::2589:3710:2c7d:b4a%25]) with mapi id 15.00.1293.002; Wed, 29 Nov 2017 23:14:52 +0800 From: "Bean Huo (beanhuo)" To: "cyrille.pitchen@wedev4u.fr" , "marek.vasut@gmail.com" , "computersforpeace@gmail.com" , Boris Brezillon , "richard@nod.at" CC: "linux-mtd@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "Bean Huo (beanhuo)" Subject: [PATCH] [RESEND] drivers:mtd:spi-nor:checkup FSR error bits Thread-Topic: [PATCH] [RESEND] drivers:mtd:spi-nor:checkup FSR error bits Thread-Index: AdNpJLdN0OCzQ3UXQYyqLe0MJgYXiA== Date: Wed, 29 Nov 2017 15:14:52 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.160.29.124] X-TM-AS-Product-Ver: SMEX-12.0.0.1464-8.100.1062-23498.005 X-TM-AS-Result: No--7.318900-0.000000-31 X-TM-AS-MatchedID: 703788-702942-703543-701177-708712-705861-706719-704318-7 02039-707027-704980-700648-862883-188019-706290-700398-863596-700324-707788 -703454-863828-704713-708804-710375-148004-148050-148980-42000-42003-29961 X-TM-AS-User-Approved-Sender: Yes X-TM-AS-User-Blocked-Sender: No x-mt-checkinternalsenderrule: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 137.201.82.98 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For the Micron SPI NOR, when the erase/program operation fails, especially, for the failure results from intending to modify protected space, spi-nor upper layers still get the return which shows the operation succeeds. This because spi_nor_fsr_ready() only uses bit.7 to device whether ready. For the most cases, even the error of erase/program occurs, SPI NOR device is still ready. The device ready and the error are two different cases. This patch is to fixup this issue and adding FSR (flag status register) error bits checkup. The FSR(flag status register) is a powerful tool to investigate the staus of device, checking information regarding what is actually doing the memory and detecting possible error conditions. Signed-off-by: beanhuo --- drivers/mtd/spi-nor/spi-nor.c | 18 ++++++++++++++++-- include/linux/mtd/spi-nor.h | 6 +++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 19c00072..b87c04f 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -328,8 +328,22 @@ static inline int spi_nor_fsr_ready(struct spi_nor *nor) int fsr = read_fsr(nor); if (fsr < 0) return fsr; - else - return fsr & FSR_READY; + + if (fsr & (FSR_E_ERR | FSR_P_ERR)) { + if (fsr & FSR_E_ERR) + dev_err(nor->dev, "Erase operation failed.\n"); + else + dev_err(nor->dev, "Program operation failed.\n"); + + if (fsr & FSR_PT_ERR) + dev_err(nor->dev, + "Attempted to modify the protected sectors.\n"); + + nor->write_reg(nor, SPINOR_OP_CLFSR, NULL, 0); + return -EIO; + } + + return fsr & FSR_READY; } static int spi_nor_ready(struct spi_nor *nor) diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 1f0a7fc..b6187e3 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -61,6 +61,7 @@ #define SPINOR_OP_RDSFDP 0x5a /* Read SFDP */ #define SPINOR_OP_RDCR 0x35 /* Read configuration register */ #define SPINOR_OP_RDFSR 0x70 /* Read flag status register */ +#define SPINOR_OP_CLFSR 0x50 /* Clear flag status register */ /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */ #define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */ @@ -130,7 +131,10 @@ #define EVCR_QUAD_EN_MICRON BIT(7) /* Micron Quad I/O */ /* Flag Status Register bits */ -#define FSR_READY BIT(7) +#define FSR_READY BIT(7) /* Device status, 0 = Busy,1 = Ready */ +#define FSR_E_ERR BIT(5) /* Erase operation status */ +#define FSR_P_ERR BIT(4) /* Program operation status */ +#define FSR_PT_ERR BIT(1) /* Protection error bit */ /* Configuration Register bits. */ #define CR_QUAD_EN_SPAN BIT(1) /* Spansion Quad I/O */ -- 2.7.4 From 1585225071852861940@xxx Mon Nov 27 13:13:56 +0000 2017 X-GM-THRID: 1585060024044108268 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread