Received: by 10.192.165.148 with SMTP id m20csp351505imm; Thu, 26 Apr 2018 23:20:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqMNsry+hAx2hXDJ2wJZZInZrmZvGGw2KmCEqWfbyjRCaFS034hbN7gf40FAQVz2Rn9STF5 X-Received: by 2002:a65:55ca:: with SMTP id k10-v6mr1043265pgs.422.1524810049276; Thu, 26 Apr 2018 23:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524810049; cv=none; d=google.com; s=arc-20160816; b=YwyXJlT8cbpsgyLhP36m/VNBBmdNRWnWM19mET73WOkNbW4eGtwdxszu+B9o9HrKDx wT6wJoOjrKtGcVDTU+/Zh1Yhij6QIbR7bAxlEayie51Ma7dXtjBtztzyh7c+iA0L+sm9 /+ANusTYJQGwFbgSMe2E4FNjxAwzBbBiYI98JYqOQG82RQypzJVnf8HH+Nn6fGxVl0eI tJYRXdlxehMKulayB5mbnYvceFBj9D3ccZZ4XybWMjDBJNlU16RGe0VJO3YK8pJtQVJC fA8JG6qyO9PX1eAhoYCykPi+ntU6bPkw3fJsPs6KbAYq21gy2p86BzCEcc7+C+SbXCJH UOmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:cc:subject:date :to:from:arc-authentication-results; bh=cmZbHMuasFjsD//rKsoQG6/uLGshHVqROJxlOf+Yl5k=; b=HvkQNQHt4NO0CeNqOpVVKxyKRDVswEZlyxuwzANzOCyW+39lO8j+dFSk7j/HX0uyCm iVB1zb83yTPdxogJ22ObAkyLFRYwHZVN5NDEOacMdlkEdFpAv05CYs9rrmUr6oMA0qwF 1qconVIsh+FmB66dChcLnn5BzxX0H/KSGX0kD4CVMVloQ3+UeW2LNRmpp7qgclwcdP1V eFqtF8rTH8MV9QAiCsG4bv+hzvuv72J5TyIdnwr/5PRoVwPhCWZhMl+nKvzBI+09SWuo Ag3ev5yhsHeB/T8KMlzdsq+A13OkJoK/DbbcgUUkWnxmn/EzpEKCTf0lQ6o99WITv7mc jVAA== 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 l16-v6si629520pgc.177.2018.04.26.23.20.35; Thu, 26 Apr 2018 23:20:49 -0700 (PDT) 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 S1757438AbeD0GST (ORCPT + 99 others); Fri, 27 Apr 2018 02:18:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:57907 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757286AbeD0GSR (ORCPT ); Fri, 27 Apr 2018 02:18:17 -0400 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. cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Message-ID: <87efj1kw9u.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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-wri= te-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 =2D----------------------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 =2D-- 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 =2D-- 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, =20 t[data_idx].tx_buf =3D buf; t[data_idx].tx_nbits =3D data_nbits; =2D t[data_idx].len =3D len; + t[data_idx].len =3D min3(len, spi_max_transfer_size(spi), + spi_max_message_size(spi) - cmd_sz); spi_message_add_tail(&t[data_idx], &m); =20 ret =3D 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 =2D-- 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 +=3D written; i +=3D written; =2D if (written !=3D page_remain) { =2D dev_err(nor->dev, =2D "While writing %zu bytes written %zd bytes\n", =2D page_remain, written); =2D ret =3D -EIO; =2D goto write_err; =2D } } =20 write_err: =2D-=20 2.14.0.rc0.dirty --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlriwJ4ACgkQOeye3VZi gbmRwBAAwi4AdVg4ovvqDLYTp/CuEgtnrWESRutah65+tJ54Gvn1pRWfmuUC2WuT DSwHd/l4QtvVGMUvfD/2j5mHjfdLrqfDLWok9Q1mMDH0mg8tYHOshHvpXlB0bj7T SpQ1RQQoQnLJKg6y5tvvTr5DK/PRKUZaF5Yule7JknSxVeRFsnnuB9AdzbCH1Hzz 7iJH3Tgu4g2YzsaXRRwaI1+rMSGZEGSwsGXX3g6zXY9aSEaipK42t2gfnQ5r8Ysu HBHOVGY8v2/A+iD5NgOGeZ4LUjznYHQNPlj7+T+zG3fqYKqKYNgw/Lwjl09c1QjW mBTn7+DD/p/p8gLy/4uB2RLAMbunCAWBFqCL+AnSQ9A7mK5s9N0VjkRcvYYJvygM WO2qqMQ1i7q9m8fC33gW085Nl12AtcZqctYscqtc+OrBDyrp+GE41PFpnTR5p0Oz kBbnkYF8flY+zX81W7XwnKkOaeOfvESlagSOTCLs5n75Hrpr1Ve50pUuD3tyPqNU VyL8BcvkzYBAf7drKVTz+pnlTur52+eWCvGA+IeRE/WJUSh4hSZ3nI/reAsC7Hoh DowFOpi3+YenTskDsmIp+hzLY1sxbn06lHaDnMz5i40fWX4iRHTikjkNceN+oXzR TOkZ7T6Pf9mMyiY1rclRzNiEXI0kcHddOpYpFHQUwH+Dbtwmwn0= =XTh7 -----END PGP SIGNATURE----- --=-=-=--