From patchwork Tue Apr 4 06:16:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 96668 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp47922qgd; Mon, 3 Apr 2017 23:17:07 -0700 (PDT) X-Received: by 10.98.77.69 with SMTP id a66mr21895535pfb.4.1491286627023; Mon, 03 Apr 2017 23:17:07 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m188si16434436pfc.145.2017.04.03.23.17.06; Mon, 03 Apr 2017 23:17:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752415AbdDDGRG (ORCPT + 6 others); Tue, 4 Apr 2017 02:17:06 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:36510 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751350AbdDDGRF (ORCPT ); Tue, 4 Apr 2017 02:17:05 -0400 Received: by mail-pg0-f42.google.com with SMTP id g2so140784620pge.3 for ; Mon, 03 Apr 2017 23:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9kzwUdPxD7Tmaremnkx0FnAxJcom5K86C8c5v11yIxg=; b=J5ajEieVCZdAgTthFEMrnxTxs3sNsc42O+ZMLDBvGfvwd2v07LvSa05h6add27gDs7 gKO0YAA7PwMLn7JE/7OIC4OakqOiGBe5nd6VnLd+IF/msjsNEEMSTGJRfbEELgY6FJrX ZFtc0Sy97Y/wwUc7LbCbzjx4BbJAwbWyitsRg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9kzwUdPxD7Tmaremnkx0FnAxJcom5K86C8c5v11yIxg=; b=dIVv7GJVN2jGywchO2FRbrK62aSpsGHmkqKfRNou2c4wQn6G9DLSV0DhzQubMZFyjR JNDK27mx+boMmS0WLPli+RFnDukC7M5U0/MBpmVi9pKbGspC60MCPxyp7SNM+9/2BSc9 GrxC/446/hJbqDR5Lv5imZYfdF0j8M+O4YUi93NWlJsl2o8zx77yHiR0C/1xqVA+lgMP ArcpOvLXzok24BEnJ5fllHezt7VEXaE8qIBazMG2QKQsal163KhNHZUl/l02uTZ2v9rc kOmK1IuNCO7XEPOGeGFMDjdeeeYvolecPtBhHbjlxDunwidQiJEImdfHPR/GzRQdkkrE RhEA== X-Gm-Message-State: AFeK/H3P2dVXSAfEL0E7HNA6MO4xKrz/8rVyyTPbEXvYB6gVTD6/dcEWifNWUByHDR5fwbgW X-Received: by 10.99.103.193 with SMTP id b184mr1241777pgc.35.1491286625069; Mon, 03 Apr 2017 23:17:05 -0700 (PDT) Received: from localhost.localdomain ([106.51.240.246]) by smtp.gmail.com with ESMTPSA id f81sm29247068pfe.61.2017.04.03.23.17.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Apr 2017 23:17:04 -0700 (PDT) From: Amit Pundir To: gregkh@linuxfoundation.org Cc: stable@vger.kernel.org, =?utf-8?q?Noralf_Tr=C3=B8nnes?= , Wolfram Sang Subject: [PATCH 06/33] i2c: bcm2835: Fix hang for writing messages larger than 16 bytes Date: Tue, 4 Apr 2017 11:46:54 +0530 Message-Id: <1491286617-31131-3-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491286617-31131-1-git-send-email-amit.pundir@linaro.org> References: <1491286617-31131-1-git-send-email-amit.pundir@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Noralf Trønnes Writing messages larger than the FIFO size results in a hang, rendering the machine unusable. This is because the RXD status flag is set on the first interrupt which results in bcm2835_drain_rxfifo() stealing bytes from the buffer. The controller continues to trigger interrupts waiting for the missing bytes, but bcm2835_fill_txfifo() has none to give. In this situation wait_for_completion_timeout() apparently is unable to stop the madness. The BCM2835 ARM Peripherals datasheet has this to say about the flags: TXD: is set when the FIFO has space for at least one byte of data. RXD: is set when the FIFO contains at least one byte of data. TXW: is set during a write transfer and the FIFO is less than full. RXR: is set during a read transfer and the FIFO is or more full. Implementing the logic from the downstream i2c-bcm2708 driver solved the hang problem. Signed-off-by: Noralf Trønnes Reviewed-by: Eric Anholt Reviewed-by: Martin Sperl Signed-off-by: Wolfram Sang (cherry picked from commit e2474541032db65d02bf88b6a8c2f954654b443f) Signed-off-by: Amit Pundir --- drivers/i2c/busses/i2c-bcm2835.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c index d4f3239..f283b71 100644 --- a/drivers/i2c/busses/i2c-bcm2835.c +++ b/drivers/i2c/busses/i2c-bcm2835.c @@ -64,6 +64,7 @@ struct bcm2835_i2c_dev { int irq; struct i2c_adapter adapter; struct completion completion; + struct i2c_msg *curr_msg; u32 msg_err; u8 *msg_buf; size_t msg_buf_remaining; @@ -126,14 +127,13 @@ static irqreturn_t bcm2835_i2c_isr(int this_irq, void *data) return IRQ_HANDLED; } - if (val & BCM2835_I2C_S_RXD) { - bcm2835_drain_rxfifo(i2c_dev); - if (!(val & BCM2835_I2C_S_DONE)) - return IRQ_HANDLED; - } - if (val & BCM2835_I2C_S_DONE) { - if (i2c_dev->msg_buf_remaining) + if (i2c_dev->curr_msg->flags & I2C_M_RD) { + bcm2835_drain_rxfifo(i2c_dev); + val = bcm2835_i2c_readl(i2c_dev, BCM2835_I2C_S); + } + + if ((val & BCM2835_I2C_S_RXD) || i2c_dev->msg_buf_remaining) i2c_dev->msg_err = BCM2835_I2C_S_LEN; else i2c_dev->msg_err = 0; @@ -141,11 +141,16 @@ static irqreturn_t bcm2835_i2c_isr(int this_irq, void *data) return IRQ_HANDLED; } - if (val & BCM2835_I2C_S_TXD) { + if (val & BCM2835_I2C_S_TXW) { bcm2835_fill_txfifo(i2c_dev); return IRQ_HANDLED; } + if (val & BCM2835_I2C_S_RXR) { + bcm2835_drain_rxfifo(i2c_dev); + return IRQ_HANDLED; + } + return IRQ_NONE; } @@ -155,6 +160,7 @@ static int bcm2835_i2c_xfer_msg(struct bcm2835_i2c_dev *i2c_dev, u32 c; unsigned long time_left; + i2c_dev->curr_msg = msg; i2c_dev->msg_buf = msg->buf; i2c_dev->msg_buf_remaining = msg->len; reinit_completion(&i2c_dev->completion);