Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4484281ybe; Mon, 9 Sep 2019 09:55:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUvoV7NbvHrA8yoYrK+TcSMtymggufF+BOOSiXn16/kqHB/1qAeW+nMdRxr0W0StlRZOpd X-Received: by 2002:a17:906:2101:: with SMTP id 1mr20318403ejt.221.1568048112842; Mon, 09 Sep 2019 09:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568048112; cv=none; d=google.com; s=arc-20160816; b=dkJZGMVoHb/ujQwTxivCtlatZgcp/LfHH5odNQL6HSkHvgq8KVvS5LDfjRPuM1nYHj DwBdAvp72K2Iq58g/j8F5JhAsFbngwBL0Kx3w4VfqIibRzFEjEVqPD6scovIOb1ABp6B Ll/jjU9aaL0KLo44qjkg4R+joOFsHdiVKAl5RwLpcIlBTV+GnvNTNspG45ZA6/+INK40 iUyhayBBtVfPSBqFEa2ncYgV3wkzsp/YH+VPeFnliCDTvHuWat+602Q+0g1bx7I+CPVn EugFms3Vx2ffVnkWJEqaNXW/nRXVFF+gmpKQaHgPxAD9lbyt0eQ96vAuBZzOcNyOg/2d cYpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fxnyWFIHZqHI5y/Wmu8gU7XONV5U0rdgn1qWszwEnO0=; b=zpBLRebiEN9FH6VyagYriA0nOGZHHUCFUE+VB2X3Xzf5A6xGOkuZGtoq3PTzg2Z/vt 1zyxOIxRAcyp876nVW3c65TaOWe0bUWrlph0LDFG9/+nZhwV6/ACZa10sSSDkd54k6b1 QDXlff4zFYYzLOBWNks1TPr9Obf5DJ9UAbU6HZ3bjODuPsErXsFqaynbBh8UyrxvG7wC uLFbx90D6sPTBvrMO1UcQUuqh/iDmKmnJe3fpFm1Yd1JGjD+oOEDyWWeHhXCP6nQQkKl /UGnc0LArgqQJ7Ff3oJsdq3yanQZdaL94SMo+425nn/I07hsJG5j1NdKXj0lGdgMR5vQ oxpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yt11jyTC; 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 b7si7096852eds.69.2019.09.09.09.54.35; Mon, 09 Sep 2019 09:55:12 -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; dkim=pass header.i=@kernel.org header.s=default header.b=yt11jyTC; 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 S1727249AbfIHNAd (ORCPT + 99 others); Sun, 8 Sep 2019 09:00:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:59202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729797AbfIHMo1 (ORCPT ); Sun, 8 Sep 2019 08:44:27 -0400 Received: from localhost (unknown [62.28.240.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BD5B121920; Sun, 8 Sep 2019 12:44:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567946667; bh=eux4fIGlT+5peVgOwVIJoXwTvuLrYXt5ySKlTBOOM2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yt11jyTCjYF1AqEsqaa5uQ4TtzFpFE0wDtOq0HqLIanxXoCwYuQofvS24smqwG2yl MsnxrEzx2np6Xq6/9FG79YU2vMB/xvvimLpfqkS3BsS+VpHTSHYkV6wX6qdLLnrba3 ABzMjak4xiPx9YUP4o+jLkWFqvMpi2oJdb7nD4dQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hubert Denkmair , Martin Sperl , Stefan Wahren , Mark Brown , Sasha Levin Subject: [PATCH 4.9 21/26] spi: bcm2835aux: fix corruptions for longer spi transfers Date: Sun, 8 Sep 2019 13:42:00 +0100 Message-Id: <20190908121110.075802835@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190908121057.216802689@linuxfoundation.org> References: <20190908121057.216802689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 73b114ee7db1750c0b535199fae383b109bd61d0 ] On long running tests with a mcp2517fd can controller it showed that on rare occations the data read shows corruptions for longer spi transfers. Example of a 22 byte transfer: expected (as captured on logic analyzer): FF FF 78 00 00 00 08 06 00 00 91 20 77 56 84 85 86 87 88 89 8a 8b read by the driver: FF FF 78 00 00 00 08 06 00 00 91 20 77 56 84 88 89 8a 00 00 8b 9b To fix this use BCM2835_AUX_SPI_STAT_RX_LVL to determine when we may read data from the fifo reliably without any corruption. Surprisingly the only values ever empirically read in BCM2835_AUX_SPI_STAT_RX_LVL are 0x00, 0x10, 0x20 and 0x30. So whenever the mask is not 0 we can read from the fifo in a safe manner. The patch has now been tested intensively and we are no longer able to reproduce the "RX" issue any longer. Fixes: 1ea29b39f4c812ec ("spi: bcm2835aux: add bcm2835 auxiliary spi device...") Reported-by: Hubert Denkmair Signed-off-by: Martin Sperl Acked-by: Stefan Wahren Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-bcm2835aux.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-bcm2835aux.c b/drivers/spi/spi-bcm2835aux.c index 4454d9c6a3dd4..5c89bbb05441b 100644 --- a/drivers/spi/spi-bcm2835aux.c +++ b/drivers/spi/spi-bcm2835aux.c @@ -180,12 +180,12 @@ static void bcm2835aux_spi_reset_hw(struct bcm2835aux_spi *bs) static void bcm2835aux_spi_transfer_helper(struct bcm2835aux_spi *bs) { + u32 stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT); + /* check if we have data to read */ - while (bs->rx_len && - (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & - BCM2835_AUX_SPI_STAT_RX_EMPTY))) { + for (; bs->rx_len && (stat & BCM2835_AUX_SPI_STAT_RX_LVL); + stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT)) bcm2835aux_rd_fifo(bs); - } /* check if we have data to write */ while (bs->tx_len && -- 2.20.1