From patchwork Fri Apr 27 06:18:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 905507 X-Patchwork-Delegate: cyrille.pitchen@atmel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=brown.name Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="N6grFeFy"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40XNzk5kFjz9s08 for ; Fri, 27 Apr 2018 16:18:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: MIME-Version:Message-ID:Subject:Date:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=upIWQ8nTCy8IX9NWNfB0B/d3+BuAGxqqPrT2LjUMsNI=; b=N6g rFeFyOwqsMOliaoX5EFFlGucUYXRtae13oJ7tcDxjf6H/u8w1j34iuJXWdMXO1EE+TLNV44PQNRSo SUTy7z3jD5cDC5ufU9RE/cKeNe6xXUdsiwpXbXnUTphh5sAASQVsMcIHhbDIdwhLRiL1Q8U89tfig MPuAoPWn5IEnwRvJaV75FYYI3uEOClH9oJ1+k2ENh5wpHqnJ5Y5jrs/PyXQ4AZJs+VmpjsXRtXWlc XSo+uTGSqgh7ga+8BPIkYBzOrB97PQcDuUwmxuVoqxAqqb4pwrscu4uXc4tZJXhVfbY+qezhx/EDZ rI+RrUObynOIWLJj9PkwP6iFVd5Io0A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fBwiM-0001oE-Cf; Fri, 27 Apr 2018 06:18:38 +0000 Received: from mx2.suse.de ([195.135.220.15]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fBwiF-0001mJ-CY for linux-mtd@lists.infradead.org; Fri, 27 Apr 2018 06:18:36 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1ECADAC0D; Fri, 27 Apr 2018 06:18:16 +0000 (UTC) From: NeilBrown To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger Date: Fri, 27 Apr 2018 16:18:05 +1000 Subject: [PATCH/RFC] mtd: spi-nor: honour max_message_size for spi-nor writes. Message-ID: <87efj1kw9u.fsf@notabene.neil.brown.name> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180426_231835_167651_BC6C2E3B X-CRM114-Status: GOOD ( 17.94 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [195.135.220.15 listed in list.dnswl.org] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Hi, I've labeled this an RFC because I'm really not sure about removing the error path from spi_nor_write() -- maybe that really matters. But on my hardware, performing multiple small spi writes to the flash seems to work. The spi driver is drivers/staging/mt7621-spi. Possibly this needs to use DMA instead of a FIFO (assuming the hardware can) - or maybe drivers/spi/spi-mt65xx.c can be made to work on this hardware, though that is for an ARM SOC and mt7621 is a MIPS SOC. I note that openwrt has similar patches: target/linux/generic/pending-4.14/450-mtd-spi-nor-allow-NOR-driver-to-write-fewer-bytes-th.patch They also change the spi driver to do a short write, rather than change m25p80 to request a short write. Is there something horribly wrong with this? Thanks, NeilBrown -----------------------8<------------------------ m25p80 honours max_message_size and max_transfer_size for reads, but not for writes. I have a driver that has a max message size of 36 bytes (command, address, 32 bytes data, all places in a FIFO in the controller). This requires m25p80_write() to honour the size limits. For that to work, spi-nor needs to quietly accept partial writes. With this, I can successfully re-flash my device. Signed-off-by: NeilBrown --- drivers/mtd/devices/m25p80.c | 3 ++- drivers/mtd/spi-nor/spi-nor.c | 7 ------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index a4e18f6aaa33..7ded13507604 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -117,7 +117,8 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len, t[data_idx].tx_buf = buf; t[data_idx].tx_nbits = data_nbits; - t[data_idx].len = len; + t[data_idx].len = min3(len, spi_max_transfer_size(spi), + spi_max_message_size(spi) - cmd_sz); spi_message_add_tail(&t[data_idx], &m); ret = spi_sync(spi, &m); diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 42ae9a1529bb..cfa15f2801ad 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1445,13 +1445,6 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, goto write_err; *retlen += written; i += written; - if (written != page_remain) { - dev_err(nor->dev, - "While writing %zu bytes written %zd bytes\n", - page_remain, written); - ret = -EIO; - goto write_err; - } } write_err: