From patchwork Tue Sep 11 22:24:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jae Hyun Yoo X-Patchwork-Id: 10596411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E433014BD for ; Tue, 11 Sep 2018 22:27:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD22829E18 for ; Tue, 11 Sep 2018 22:27:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFAF929E3D; Tue, 11 Sep 2018 22:27:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,URIBL_SBL autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1804529E18 for ; Tue, 11 Sep 2018 22:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ngdWws8nncJcpaul2BxHOCpDjYN1b0dpr2irRIhR6Xg=; b=o9LUMa7aYV1yk+Wx14u09JxjjL ti4SzKLvKkTnSnGcKg7AMmHOkfNJsAQYKeo5dOE39o5K6WW13XLDkc6UVzu8YbsCucnhLB3+SfJ/E iyg67/b7R2QxfpT0odh7MyJ59MZME4a38qGJR/XHp6b5ny8ttrebKIyZPUKfgfG5tOn7e+Dr8E+bK g2JaaNj1HXxnDmcQaIOmMb2vi17/e3tB06VvYl606ugsFbqPptka8+9DFv8GAYCHOYPuYrTll0M8r x3Hk348UMseBZkjg2CJLgddfsmgO+6+09mhE/RS4xuUENVTJoPbhvkVAtmhGfAgpmEkXRXbTSGXzD ITWs3BwQ==; 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 1fzr7h-0000dB-7u; Tue, 11 Sep 2018 22:27:05 +0000 Received: from mga01.intel.com ([192.55.52.88]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fzr7e-0000br-D6 for linux-arm-kernel@lists.infradead.org; Tue, 11 Sep 2018 22:27:04 +0000 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2018 15:26:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,362,1531810800"; d="scan'208";a="72435018" Received: from maru.jf.intel.com ([10.54.51.80]) by orsmga008.jf.intel.com with ESMTP; 11 Sep 2018 15:25:32 -0700 From: Jae Hyun Yoo To: Brendan Higgins , Benjamin Herrenschmidt , Joel Stanley , Andrew Jeffery , linux-i2c@vger.kernel.org, openbmc@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] Revert "i2c: aspeed: Handle master/slave combined irq events properly" Date: Tue, 11 Sep 2018 15:24:45 -0700 Message-Id: <20180911222445.18064-1-jae.hyun.yoo@linux.intel.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180911_152702_455622_0B904E32 X-CRM114-Status: GOOD ( 19.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jae Hyun Yoo , Vernon Mauery , Jarkko Nikula , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Guenter Roeck , James Feist MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit 3e9efc3299dd "i2c: aspeed: Handle master/slave combined irq events properly" to fix an issue which is reported from QEMU v3.0 environment. Signed-off-by: Jae Hyun Yoo Cc: Guenter Roeck --- drivers/i2c/busses/i2c-aspeed.c | 131 ++++++++++++++------------------ 1 file changed, 55 insertions(+), 76 deletions(-) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index c258c4d9a4c0..a4f956c6d567 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -82,11 +82,6 @@ #define ASPEED_I2CD_INTR_RX_DONE BIT(2) #define ASPEED_I2CD_INTR_TX_NAK BIT(1) #define ASPEED_I2CD_INTR_TX_ACK BIT(0) -#define ASPEED_I2CD_INTR_MASTER_ERRORS \ - (ASPEED_I2CD_INTR_SDA_DL_TIMEOUT | \ - ASPEED_I2CD_INTR_SCL_TIMEOUT | \ - ASPEED_I2CD_INTR_ABNORMAL | \ - ASPEED_I2CD_INTR_ARBIT_LOSS) #define ASPEED_I2CD_INTR_ALL \ (ASPEED_I2CD_INTR_SDA_DL_TIMEOUT | \ ASPEED_I2CD_INTR_BUS_RECOVER_DONE | \ @@ -232,26 +227,32 @@ static int aspeed_i2c_recover_bus(struct aspeed_i2c_bus *bus) } #if IS_ENABLED(CONFIG_I2C_SLAVE) -static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) +static bool aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus) { - u32 command, irq_handled = 0; + u32 command, irq_status, status_ack = 0; struct i2c_client *slave = bus->slave; + bool irq_handled = true; u8 value; - if (!slave) - return 0; + if (!slave) { + irq_handled = false; + goto out; + } command = readl(bus->base + ASPEED_I2C_CMD_REG); + irq_status = readl(bus->base + ASPEED_I2C_INTR_STS_REG); /* Slave was requested, restart state machine. */ if (irq_status & ASPEED_I2CD_INTR_SLAVE_MATCH) { - irq_handled |= ASPEED_I2CD_INTR_SLAVE_MATCH; + status_ack |= ASPEED_I2CD_INTR_SLAVE_MATCH; bus->slave_state = ASPEED_I2C_SLAVE_START; } /* Slave is not currently active, irq was for someone else. */ - if (bus->slave_state == ASPEED_I2C_SLAVE_STOP) - return irq_handled; + if (bus->slave_state == ASPEED_I2C_SLAVE_STOP) { + irq_handled = false; + goto out; + } dev_dbg(bus->dev, "slave irq status 0x%08x, cmd 0x%08x\n", irq_status, command); @@ -268,31 +269,31 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) bus->slave_state = ASPEED_I2C_SLAVE_WRITE_REQUESTED; } - irq_handled |= ASPEED_I2CD_INTR_RX_DONE; + status_ack |= ASPEED_I2CD_INTR_RX_DONE; } /* Slave was asked to stop. */ if (irq_status & ASPEED_I2CD_INTR_NORMAL_STOP) { - irq_handled |= ASPEED_I2CD_INTR_NORMAL_STOP; + status_ack |= ASPEED_I2CD_INTR_NORMAL_STOP; bus->slave_state = ASPEED_I2C_SLAVE_STOP; } if (irq_status & ASPEED_I2CD_INTR_TX_NAK) { - irq_handled |= ASPEED_I2CD_INTR_TX_NAK; + status_ack |= ASPEED_I2CD_INTR_TX_NAK; bus->slave_state = ASPEED_I2C_SLAVE_STOP; } - if (irq_status & ASPEED_I2CD_INTR_TX_ACK) - irq_handled |= ASPEED_I2CD_INTR_TX_ACK; switch (bus->slave_state) { case ASPEED_I2C_SLAVE_READ_REQUESTED: if (irq_status & ASPEED_I2CD_INTR_TX_ACK) dev_err(bus->dev, "Unexpected ACK on read request.\n"); bus->slave_state = ASPEED_I2C_SLAVE_READ_PROCESSED; + i2c_slave_event(slave, I2C_SLAVE_READ_REQUESTED, &value); writel(value, bus->base + ASPEED_I2C_BYTE_BUF_REG); writel(ASPEED_I2CD_S_TX_CMD, bus->base + ASPEED_I2C_CMD_REG); break; case ASPEED_I2C_SLAVE_READ_PROCESSED: + status_ack |= ASPEED_I2CD_INTR_TX_ACK; if (!(irq_status & ASPEED_I2CD_INTR_TX_ACK)) dev_err(bus->dev, "Expected ACK after processed read.\n"); @@ -316,6 +317,13 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) break; } + if (status_ack != irq_status) + dev_err(bus->dev, + "irq handled != irq. expected %x, but was %x\n", + irq_status, status_ack); + writel(status_ack, bus->base + ASPEED_I2C_INTR_STS_REG); + +out: return irq_handled; } #endif /* CONFIG_I2C_SLAVE */ @@ -372,21 +380,21 @@ static int aspeed_i2c_is_irq_error(u32 irq_status) return 0; } -static u32 aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus, u32 irq_status) +static bool aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus) { - u32 irq_handled = 0, command = 0; + u32 irq_status, status_ack = 0, command = 0; struct i2c_msg *msg; u8 recv_byte; int ret; + irq_status = readl(bus->base + ASPEED_I2C_INTR_STS_REG); + /* Ack all interrupt bits. */ + writel(irq_status, bus->base + ASPEED_I2C_INTR_STS_REG); + if (irq_status & ASPEED_I2CD_INTR_BUS_RECOVER_DONE) { bus->master_state = ASPEED_I2C_MASTER_INACTIVE; - irq_handled |= ASPEED_I2CD_INTR_BUS_RECOVER_DONE; + status_ack |= ASPEED_I2CD_INTR_BUS_RECOVER_DONE; goto out_complete; - } else { - /* Master is not currently active, irq was for someone else. */ - if (bus->master_state == ASPEED_I2C_MASTER_INACTIVE) - goto out_no_complete; } /* @@ -395,22 +403,19 @@ static u32 aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus, u32 irq_status) * INACTIVE state. */ ret = aspeed_i2c_is_irq_error(irq_status); - if (ret) { + if (ret < 0) { dev_dbg(bus->dev, "received error interrupt: 0x%08x\n", irq_status); bus->cmd_err = ret; bus->master_state = ASPEED_I2C_MASTER_INACTIVE; - irq_handled |= (irq_status & ASPEED_I2CD_INTR_MASTER_ERRORS); goto out_complete; } /* We are in an invalid state; reset bus to a known state. */ if (!bus->msgs) { - dev_err(bus->dev, "bus in unknown state. irq_status: 0x%x\n", - irq_status); + dev_err(bus->dev, "bus in unknown state\n"); bus->cmd_err = -EIO; - if (bus->master_state != ASPEED_I2C_MASTER_STOP && - bus->master_state != ASPEED_I2C_MASTER_INACTIVE) + if (bus->master_state != ASPEED_I2C_MASTER_STOP) aspeed_i2c_do_stop(bus); goto out_no_complete; } @@ -423,18 +428,13 @@ static u32 aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus, u32 irq_status) */ if (bus->master_state == ASPEED_I2C_MASTER_START) { if (unlikely(!(irq_status & ASPEED_I2CD_INTR_TX_ACK))) { - if (unlikely(!(irq_status & ASPEED_I2CD_INTR_TX_NAK))) { - bus->cmd_err = -ENXIO; - bus->master_state = ASPEED_I2C_MASTER_INACTIVE; - goto out_complete; - } pr_devel("no slave present at %02x\n", msg->addr); - irq_handled |= ASPEED_I2CD_INTR_TX_NAK; + status_ack |= ASPEED_I2CD_INTR_TX_NAK; bus->cmd_err = -ENXIO; aspeed_i2c_do_stop(bus); goto out_no_complete; } - irq_handled |= ASPEED_I2CD_INTR_TX_ACK; + status_ack |= ASPEED_I2CD_INTR_TX_ACK; if (msg->len == 0) { /* SMBUS_QUICK */ aspeed_i2c_do_stop(bus); goto out_no_complete; @@ -449,13 +449,13 @@ static u32 aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus, u32 irq_status) case ASPEED_I2C_MASTER_TX: if (unlikely(irq_status & ASPEED_I2CD_INTR_TX_NAK)) { dev_dbg(bus->dev, "slave NACKed TX\n"); - irq_handled |= ASPEED_I2CD_INTR_TX_NAK; + status_ack |= ASPEED_I2CD_INTR_TX_NAK; goto error_and_stop; } else if (unlikely(!(irq_status & ASPEED_I2CD_INTR_TX_ACK))) { dev_err(bus->dev, "slave failed to ACK TX\n"); goto error_and_stop; } - irq_handled |= ASPEED_I2CD_INTR_TX_ACK; + status_ack |= ASPEED_I2CD_INTR_TX_ACK; /* fallthrough intended */ case ASPEED_I2C_MASTER_TX_FIRST: if (bus->buf_index < msg->len) { @@ -478,7 +478,7 @@ static u32 aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus, u32 irq_status) dev_err(bus->dev, "master failed to RX\n"); goto error_and_stop; } - irq_handled |= ASPEED_I2CD_INTR_RX_DONE; + status_ack |= ASPEED_I2CD_INTR_RX_DONE; recv_byte = readl(bus->base + ASPEED_I2C_BYTE_BUF_REG) >> 8; msg->buf[bus->buf_index++] = recv_byte; @@ -506,13 +506,11 @@ static u32 aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus, u32 irq_status) goto out_no_complete; case ASPEED_I2C_MASTER_STOP: if (unlikely(!(irq_status & ASPEED_I2CD_INTR_NORMAL_STOP))) { - dev_err(bus->dev, - "master failed to STOP. irq_status:0x%x\n", - irq_status); + dev_err(bus->dev, "master failed to STOP\n"); bus->cmd_err = -EIO; /* Do not STOP as we have already tried. */ } else { - irq_handled |= ASPEED_I2CD_INTR_NORMAL_STOP; + status_ack |= ASPEED_I2CD_INTR_NORMAL_STOP; } bus->master_state = ASPEED_I2C_MASTER_INACTIVE; @@ -542,52 +540,33 @@ static u32 aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus, u32 irq_status) bus->master_xfer_result = bus->msgs_index + 1; complete(&bus->cmd_complete); out_no_complete: - return irq_handled; + if (irq_status != status_ack) + dev_err(bus->dev, + "irq handled != irq. expected 0x%08x, but was 0x%08x\n", + irq_status, status_ack); + return !!irq_status; } static irqreturn_t aspeed_i2c_bus_irq(int irq, void *dev_id) { struct aspeed_i2c_bus *bus = dev_id; - u32 irq_received, irq_remaining, irq_handled; + bool ret; spin_lock(&bus->lock); - irq_received = readl(bus->base + ASPEED_I2C_INTR_STS_REG); - irq_remaining = irq_received; #if IS_ENABLED(CONFIG_I2C_SLAVE) - /* - * In most cases, interrupt bits will be set one by one, although - * multiple interrupt bits could be set at the same time. It's also - * possible that master interrupt bits could be set along with slave - * interrupt bits. Each case needs to be handled using corresponding - * handlers depending on the current state. - */ - if (bus->master_state != ASPEED_I2C_MASTER_INACTIVE) { - irq_handled = aspeed_i2c_master_irq(bus, irq_remaining); - irq_remaining &= ~irq_handled; - if (irq_remaining) - irq_handled |= aspeed_i2c_slave_irq(bus, irq_remaining); - } else { - irq_handled = aspeed_i2c_slave_irq(bus, irq_remaining); - irq_remaining &= ~irq_handled; - if (irq_remaining) - irq_handled |= aspeed_i2c_master_irq(bus, - irq_remaining); + if (aspeed_i2c_slave_irq(bus)) { + dev_dbg(bus->dev, "irq handled by slave.\n"); + ret = true; + goto out; } -#else - irq_handled = aspeed_i2c_master_irq(bus, irq_remaining); #endif /* CONFIG_I2C_SLAVE */ - irq_remaining &= ~irq_handled; - if (irq_remaining) - dev_err(bus->dev, - "irq handled != irq. expected 0x%08x, but was 0x%08x\n", - irq_received, irq_handled); + ret = aspeed_i2c_master_irq(bus); - /* Ack all interrupt bits. */ - writel(irq_received, bus->base + ASPEED_I2C_INTR_STS_REG); +out: spin_unlock(&bus->lock); - return irq_remaining ? IRQ_NONE : IRQ_HANDLED; + return ret ? IRQ_HANDLED : IRQ_NONE; } static int aspeed_i2c_master_xfer(struct i2c_adapter *adap,