From nobody Fri Dec 10 12:30:23 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 59FB618CFEEF; Fri, 10 Dec 2021 12:30:25 +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 4J9Vc01WCdz3rXg; Fri, 10 Dec 2021 12:30:24 +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 4782C1A471; Fri, 10 Dec 2021 12:30:23 +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 1BACUNX7065000; Fri, 10 Dec 2021 12:30:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BACUNsR064999; Fri, 10 Dec 2021 12:30:23 GMT (envelope-from git) Date: Fri, 10 Dec 2021 12:30:23 GMT Message-Id: <202112101230.1BACUNsR064999@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andriy Gapon Subject: git: 0f048f199e69 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 0f048f199e69da73936665c72550a3a5fe8c4f1d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639139424; 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=iY3g75g1NRR5iuAvPq2GPGboJI213QOsIuncJRlza0E=; b=y0IjQAAfpTZUpdGzDaGPMqb9zS6KcnCLJlWYD3qwYJscNDyBM8/iM/btMSKr9bk7EM8G3z HOgajbG4k0QQKTufl9tfXdkqWhw+B4gcL7hXSY5K+mysODE5+3f9FP0+H7qjnfULH26EE6 Fq1LYGp7l7gwYX363khqjfUuT26z+iKO0ZxgIM5rRrUHCZAP5iSWm6Qagsuavg1splxMI0 alFOJRh6br0fUzGxzUH8TFpRfZCLJwZmw1XQdUsF4W2PPrVv+FW+ffv+E6iIS17GPNh5cQ GmtuZqfYwvNvm3lplX2R+LVPcBkFYt17pyszb93cgFI7oJEGb7s62l8XYfoFIg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639139424; a=rsa-sha256; cv=none; b=OSJfXe+9vPvqWSm6ojO2frWla0J0EbEPmaLeHNieAmaGD1sy0RLvp8nE+2UFmRX9RsNArE PHajG0mfTFiAKVtawm7rQtzAFnHXL7jvVCySf38cj8JtIQi7pYz6nvs5l1eTukrEI69FbD oxk0WJyxQUJOtFTGPAIP4KHe+tJgCCqApu27lINOGJVWQ3Bg8qY+3mwZ9P1CMz/m01YG15 och57f0Lc4nicN3xg3qFDH7Q/1UctM+F4Kw2FaQlzvfL4LJPunyyLUtadW8eUSpKC+aIvg 7iBX1K11PL7r2F+fhL+VgWTohB29F9PYQltHmx2DcY8heIAPye/Yr/kS6F2TqQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=0f048f199e69da73936665c72550a3a5fe8c4f1d commit 0f048f199e69da73936665c72550a3a5fe8c4f1d Author: Andriy Gapon AuthorDate: 2021-11-26 07:44:30 +0000 Commit: Andriy Gapon CommitDate: 2021-12-10 12:30:12 +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. (cherry picked from commit a4fe8922085dfc1e5e6a6bac73ccc738e373165f) --- 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); }