From nobody Fri Nov 26 14:24:02 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id DCC0218A2AF5; Fri, 26 Nov 2021 14:24:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J0xnb5F2sz4cKD; Fri, 26 Nov 2021 14:24:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 30E242055; Fri, 26 Nov 2021 14:24:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AQEO2dj002471; Fri, 26 Nov 2021 14:24:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AQEO20X002470; Fri, 26 Nov 2021 14:24:02 GMT (envelope-from git) Date: Fri, 26 Nov 2021 14:24:02 GMT Message-Id: <202111261424.1AQEO20X002470@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andriy Gapon Subject: git: a4fe8922085d - main - twsi: unify error handling, explicitly handle more conditions List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a4fe8922085dfc1e5e6a6bac73ccc738e373165f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637936644; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ww5aJgvTxk336ToykBYXtP92dmEJEl702YvQj4OUywo=; b=U0BZovkCj3p07FJOZ9Yo9fWzVeLfNJppUyllpnbQ9flxLb2NFpaCqYgkINv5eH3vCnMAyH CTwzPzF/qK7MM1oPWbL3iElUd+wvt6JIty2QM5HW/UfBUZf18ya+dso4hCgx9rCL26Z/+b gcMx87TL/j9eRyf0l6C1NZnqzX6VXIIG8acM6BhMF41bnUI9rTZijxV7H8JmZkysid02n/ uWXFHmbMwRTQTvhvHnb7PIZaFkpBcVd4aH6/VFOayFeEHIXw5GMfaoeQ8T4dY2ONBRCJof CI0LaloT6X/cYB7C7sPaaxFjGSWGWfIMvAq54HHauI9MYULTlytbh3ATRotH0w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637936644; a=rsa-sha256; cv=none; b=rKHS1+WZ+9JdpQfoS8lQ3kLsQxBIevwq9lPO2Oi+9aK6I3XpVeLPEOlcHdWciG8rxiVK41 6fEDPUyPH4c8mYLkaS7+5OtGwYn5uWS5Zh/IUnAf9aZmpXheHerb8kDn69j73OqotDHok6 JPOCHl7nQqiZBWjE7YW741qd+oe9ZSRl3Q8tYdFX6WyxfQo1sxs038Dg06D/6djzhGTBcC 7F+xhsQ4MlaULlueRFou3/u8+a2iT/JCR3LyFKjASNZh3xT7bJHbRe2o14/M0Y+7pGkY8Y 9BK11YqYf7GCXTtDZoQknaG6Q7PQqfIsyvx0Fp7KlkDfR1ffMEWN1zR/X8NdSA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=a4fe8922085dfc1e5e6a6bac73ccc738e373165f commit a4fe8922085dfc1e5e6a6bac73ccc738e373165f Author: Andriy Gapon AuthorDate: 2021-11-26 07:44:30 +0000 Commit: Andriy Gapon CommitDate: 2021-11-26 14:16:21 +0000 twsi: unify error handling, explicitly handle more conditions twsi_error() is a new function that stops the current transfer and sets up softc when an error condition is detected. TWSI_STATUS_DATA_WR_NACK, TWSI_STATUS_BUS_ERROR and TWSI_STATUS_ARBITRATION_LOST are now handled explicitly rather than via the catch-all unknown status. Also, twsi_intr() now calls wakeup() in a single place when the transfer is finished. MFC after: 2 weeks --- sys/dev/iicbus/twsi/twsi.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/sys/dev/iicbus/twsi/twsi.c b/sys/dev/iicbus/twsi/twsi.c index 384e19e120b9..ecadfade04d9 100644 --- a/sys/dev/iicbus/twsi/twsi.c +++ b/sys/dev/iicbus/twsi/twsi.c @@ -543,6 +543,19 @@ twsi_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs) return (error); } +static void +twsi_error(struct twsi_softc *sc, int err) +{ + /* + * Must send stop condition to abort the current transfer. + */ + debugf(sc, "Sending STOP condition for error %d\n", err); + sc->transfer = 0; + sc->error = err; + sc->control_val = 0; + TWSI_WRITE(sc, sc->reg_control, sc->control_val | TWSI_CONTROL_STOP); +} + static void twsi_intr(void *arg) { @@ -604,13 +617,13 @@ twsi_intr(void *arg) case TWSI_STATUS_ADDR_W_NACK: case TWSI_STATUS_ADDR_R_NACK: - debugf(sc, "No ack received after transmitting the address\n"); - sc->transfer = 0; - sc->error = IIC_ENOACK; - sc->control_val = 0; - wakeup(sc); + debugf(sc, "Address NACK-ed\n"); + twsi_error(sc, IIC_ENOACK); + break; + case TWSI_STATUS_DATA_WR_NACK: + debugf(sc, "Data byte NACK-ed\n"); + twsi_error(sc, IIC_ENOACK); break; - case TWSI_STATUS_DATA_WR_ACK: debugf(sc, "Ack received after transmitting data\n"); if (sc->sent_bytes == sc->msgs[sc->msg_idx].len) { @@ -684,12 +697,17 @@ twsi_intr(void *arg) sc->error = 0; break; + case TWSI_STATUS_BUS_ERROR: + debugf(sc, "Bus error\n"); + twsi_error(sc, IIC_EBUSERR); + break; + case TWSI_STATUS_ARBITRATION_LOST: + debugf(sc, "Arbitration lost\n"); + twsi_error(sc, IIC_EBUSBSY); + break; default: - debugf(sc, "status=%x hot handled\n", status); - sc->transfer = 0; - sc->error = IIC_EBUSERR; - sc->control_val = 0; - wakeup(sc); + debugf(sc, "unexpected status 0x%x\n", status); + twsi_error(sc, IIC_ESTATUS); break; } debugf(sc, "Refresh reg_control\n"); @@ -701,11 +719,11 @@ end: TWSI_WRITE(sc, sc->reg_control, sc->control_val | (sc->iflag_w1c ? TWSI_CONTROL_IFLG : 0)); - debugf(sc, "Done with interrupts\n\n"); - if (transfer_done == 1) { + if (transfer_done == 1) sc->transfer = 0; + debugf(sc, "Done with interrupt, transfer = %d\n", sc->transfer); + if (sc->transfer == 0) wakeup(sc); - } mtx_unlock(&sc->mutex); }