From patchwork Fri Mar 20 10:14:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1258791 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=QNEYAzuK; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48kKQz04pJz9sPF for ; Fri, 20 Mar 2020 21:15:19 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 288B8815B0; Fri, 20 Mar 2020 11:15:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="QNEYAzuK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 551D981286; Fri, 20 Mar 2020 11:15:06 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on071f.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0c::71f]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 74FE1801D2 for ; Fri, 20 Mar 2020 11:15:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nEX884UfrNAnclNqyzwMETONSmeA5zwVTkP6PMg4l84YdP31XHHkTGH7Fv+6Eue6QQCook5348c9aTpKfFRgx1h8g3d1GOzrNZUR9lKCYmGtXTXD8E4HDPLYjPReaTrp2cYoraav8EtzYQLBesDkoh39KH6tnd3WafBOOqO6L3JcrjLbEmt8cJBftgvJwYQQdVWBivaxUj2T2zR3uMers35TMpN71JWe/p2IPhLhzcMqIxSyw2Haa1bRJhZTbXnh9ETsOz8TXXJCACmmJDjHpwkgzoywY0FqspJO0Rf5wwGMU8nBtHxo+LGXvoASJnDerUBDvNoAer3i8bOPCP6iwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2UAm1ovKKBuz18O2Jq9IBSGKFnBqDz8C4/vcrdWW5DE=; b=mKDfGxx7A7GQRdltN+RYdAq/OTS6BzRQz05zjGPpJLely0WFA8V9fYiSvrpCM7V17Gyj4ZHFtuT5HaIrQwylNwBJpxB8VNfAkG/E/cVwpzVrliL4axvFT+v+ysw/zcuRYnyO8qPepD/EKD04O6p0ypZYBBRC9rp3YQHzSR/kDV14BWlJFVFqByoLDxJocj4ataOKf6WTe0GvvWy0GxWUnJl14qvFritXD07j0D47vOk8PVlBdJpSPF5W7aMRYbylS4W6XAmU4TLjMotK+22M9eTGFqfSuwQ9iosGQJQwN5XMFdQeOjUYT3CRNlnNlvKpNPmqzzptaGqOpw23y04VZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2UAm1ovKKBuz18O2Jq9IBSGKFnBqDz8C4/vcrdWW5DE=; b=QNEYAzuKE8o7BSdbbz6RKVBlkk7Xci7cEpbqQQSo45/LCzum7hW2S2PjZmbtjb2z4c76ocZ3E2HpSh+oQAdpMIn7yq+7ve0H28P1Pxhi1nNKw1ApwAkLKo0pyxLnDqmpY9hIPaB2PaRvIvEiLGj1CCnDrlXVITgNswaUAgvBJBw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rasmus.villemoes@prevas.dk; Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (20.178.126.85) by VI1PR10MB3341.EURPRD10.PROD.OUTLOOK.COM (52.133.247.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.20; Fri, 20 Mar 2020 10:15:01 +0000 Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::e58f:1097:b71d:32c7]) by VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::e58f:1097:b71d:32c7%5]) with mapi id 15.20.2835.017; Fri, 20 Mar 2020 10:15:01 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Vignesh R , Jagan Teki , Kuldeep Singh , Rasmus Villemoes Subject: [PATCH v2 2/2] spi: allow calling WATCHDOG_RESET during long reads Date: Fri, 20 Mar 2020 11:14:48 +0100 Message-Id: <20200320101448.10714-2-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200320101448.10714-1-rasmus.villemoes@prevas.dk> References: <20200316201832.28693-1-rasmus.villemoes@prevas.dk> <20200320101448.10714-1-rasmus.villemoes@prevas.dk> X-ClientProxiedBy: AM5PR06CA0019.eurprd06.prod.outlook.com (2603:10a6:206:2::32) To VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:e1::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (5.186.116.45) by AM5PR06CA0019.eurprd06.prod.outlook.com (2603:10a6:206:2::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.18 via Frontend Transport; Fri, 20 Mar 2020 10:14:59 +0000 X-Mailer: git-send-email 2.23.0 X-Originating-IP: [5.186.116.45] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 28fd0cf3-5379-49e0-553b-08d7ccb78c05 X-MS-TrafficTypeDiagnostic: VI1PR10MB3341: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-Forefront-PRVS: 03484C0ABF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(366004)(199004)(52116002)(86362001)(107886003)(4326008)(2616005)(54906003)(44832011)(956004)(6506007)(6916009)(6486002)(1076003)(81166006)(8676002)(8936002)(81156014)(8976002)(6666004)(498600001)(36756003)(5660300002)(16526019)(66556008)(186003)(66476007)(6512007)(26005)(66946007)(2906002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR10MB3341; H:VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: prevas.dk does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UVd+F1vqlAZcGZdGHhWx+A/PVz5OLXiCtPgigKZD1cN+6vdrmtU464DnOfbmlB7INNbkgE0nRMWNVjAJ9iDH98Rax6pB4cr8ZtQ1wVLcpPoyPouwADVxUzKX1rNlg9SHSpQ2WnnB63dQLWgwI47Zn++QsuZOGJTb5f0inJ9/K6vw2XmVdWQ/V6LbW5pAwZ+Ym7YuJAHTHo2AMnyHkHBZqCcyDaVvrdkoKk/J8rK3ZDI6zTMLSmIPnYJJNc+grU5NPfY8eMEG2QLNkhsxqOdjuB+MNFgSjD8+mYHnYR6q4f91wt2eS2Bp4VjipMjQe2Ey+l4MFvTD6aJWAZEEKZ4esrdqo+qHrLMXAIiAZV7SKrrdd9TA2iLA5QO9uViT15aQJhJ2hjWr2W1zqCTj9o2cwyCvX+Srh15mfbXimj2rf+I6VdocmdYCesSe5n8wljyS X-MS-Exchange-AntiSpam-MessageData: PNwLyw22M00gkPtJjpsC8+WZ5OBOMhsdBwLfOO6LMdGLM4/FwIhEvFYD3sd5Gs0oLTUKu6nTTscyNZhbvbc2x6SHKnOHlhEXATTrqITw8tAkbeGy4uppw8Og91Sj0wzDaYO5fzwSG5vjt4W/meD7fw== X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 28fd0cf3-5379-49e0-553b-08d7ccb78c05 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2020 10:15:01.6873 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KA0SQ5QgA4aSgqAV+7gn+Werk3GsFaHnm+sOFtXvu8VNrCzqO14wG2PcKBXzk9IHRzHE/AVffgyTjTVzpPO/xVFrCtWoqKN4rB5OnDn8JPA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR10MB3341 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean Some boards have a watchdog with a short (~1s) timeout and a slowish nor flash. For example, I'm currently working on a board where doing a 2MB read from the flash will cause the board to reset. Similar to the various CHUNKSZ, CHUNKSZ_SHA1 etc. defines that are used to chop hash digest and/or memmove operations into chunks, doing a WATCHDOG_RESET for each, introduce a CONFIG_SPI_FLASH_READ_CHUNKSZ config knob. We keep the default of doing the whole read in one go, but the board config can set a suitable threshold. Signed-off-by: Rasmus Villemoes --- drivers/mtd/spi/Kconfig | 12 ++++++++++++ drivers/mtd/spi/spi-nor-core.c | 4 +++- drivers/mtd/spi/spi-nor-tiny.c | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi/Kconfig b/drivers/mtd/spi/Kconfig index 018e8c597e..9dda0047d2 100644 --- a/drivers/mtd/spi/Kconfig +++ b/drivers/mtd/spi/Kconfig @@ -169,6 +169,18 @@ config SPI_FLASH_USE_4K_SECTORS Please note that some tools/drivers/filesystems may not work with 4096 B erase size (e.g. UBIFS requires 15 KiB as a minimum). +config SPI_FLASH_READ_CHUNKSZ + int "Chunk size for reading from SPI flash" + depends on SPI_FLASH + default 0 + help + Some boards have a watchdog with a very short timeout + period. Doing large reads from a SPI flash on such a board + causes the watchdog to fire and reset the board. Setting + this option to a non-zero value will ensure that + watchdog_reset() gets called after each read of that many + bytes. + config SPI_FLASH_DATAFLASH bool "AT45xxx DataFlash support" depends on SPI_FLASH && DM_SPI_FLASH diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index c5d98debf0..8c846a4b42 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -82,6 +82,7 @@ static ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, SPI_MEM_OP_DUMMY(nor->read_dummy, 1), SPI_MEM_OP_DATA_IN(len, buf, 1)); size_t remaining = len; + size_t chunksz = CONFIG_SPI_FLASH_READ_CHUNKSZ ?: UINT_MAX; int ret; /* get transfer protocols. */ @@ -94,7 +95,7 @@ static ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; while (remaining) { - op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX; + op.data.nbytes = min(remaining, chunksz); ret = spi_mem_adjust_op_size(nor->spi, &op); if (ret) return ret; @@ -102,6 +103,7 @@ static ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, ret = spi_mem_exec_op(nor->spi, &op); if (ret) return ret; + WATCHDOG_RESET(); op.addr.val += op.data.nbytes; remaining -= op.data.nbytes; diff --git a/drivers/mtd/spi/spi-nor-tiny.c b/drivers/mtd/spi/spi-nor-tiny.c index d91989567d..e9d490ba52 100644 --- a/drivers/mtd/spi/spi-nor-tiny.c +++ b/drivers/mtd/spi/spi-nor-tiny.c @@ -81,6 +81,7 @@ static ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, SPI_MEM_OP_DUMMY(nor->read_dummy, 1), SPI_MEM_OP_DATA_IN(len, buf, 1)); size_t remaining = len; + size_t chunksz = CONFIG_SPI_FLASH_READ_CHUNKSZ ?: UINT_MAX; int ret; /* get transfer protocols. */ @@ -93,7 +94,7 @@ static ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; while (remaining) { - op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX; + op.data.nbytes = min(remaining, chunksz); ret = spi_mem_adjust_op_size(nor->spi, &op); if (ret) return ret; @@ -101,6 +102,7 @@ static ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, ret = spi_mem_exec_op(nor->spi, &op); if (ret) return ret; + WATCHDOG_RESET(); op.addr.val += op.data.nbytes; remaining -= op.data.nbytes;