From nobody Fri Dec 10 12:31:28 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 D9F0518D1A0D; Fri, 10 Dec 2021 12:31:30 +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 4J9VdF1nBhz3sj0; Fri, 10 Dec 2021 12:31:29 +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 8DF421A884; Fri, 10 Dec 2021 12:31:28 +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 1BACVSQe066188; Fri, 10 Dec 2021 12:31:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BACVSZq066187; Fri, 10 Dec 2021 12:31:28 GMT (envelope-from git) Date: Fri, 10 Dec 2021 12:31:28 GMT Message-Id: <202112101231.1BACVSZq066187@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: 3507728e59ab - stable/12 - 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/12 X-Git-Reftype: branch X-Git-Commit: 3507728e59ab64f109e7495311f38549b007706b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639139489; 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=1cP57XRI8uNYOGiyEO7zzDlR0djPSXLkH4tKvMqKvJY=; b=Q/gIdGEDW984UKRKStOxcoPWYno0KiYGRDyoZ5SIgq5BtqUYVxE5rosquGhOlAXqIlxilg htoTO6rPup1PMEk+KjpSLqRSG588f6lciw9rWFXArNyNhTJdNA8azTkhqsVk6b/DKwtWGH XdmeWK4jpr/+Gc02d/m4IpWm71jeWmqqzSpfEfIS/EUtTnxNjWYM2EA8z1RGZNt+myBXWZ NvrWfQ2W//M2NVa0UH8sBXwUB4Ax241ENnIltfc9c1Datr13zoVM21B1SRYQL9WZK47es7 yVkiLseRLLnKBizPM4EKLnzIRPoKMriY3chOKxJO5Z18z3g2uyQHMBKMA0GYTg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639139489; a=rsa-sha256; cv=none; b=OQ+1vG+2e+vEAd3k//JjmYKmiiJur4eeKa+YC08qKvHhSOLmb3qeBvt9fq/iTOIcu+Yzh7 uE3ZF6qVmq9hldETawn6OR2Q+BH0JR5XxfKhA5vLLQFvLT0uoEYz8lLB0FFNb0TNxg1K2q OCjGekroHmY2ujYWVpTbZbNhkaa+r5cKPbBNlwn+7bfVTyDqDOF0C+Q3CpwH+pqbQJdAnb AUfZcNEXFwQGrkFziLibY356/8H8fNLDX/UtZa9K3y/74NE47SWKFWf5GOC2rgpS9yYzWV buz6SV6jvKfnnVOymCQzivinV3O3IMHCIUdkv6qSNy+Mn3Lvy9Fk2d/zCfWb1Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=3507728e59ab64f109e7495311f38549b007706b commit 3507728e59ab64f109e7495311f38549b007706b Author: Andriy Gapon AuthorDate: 2021-11-26 07:44:30 +0000 Commit: Andriy Gapon CommitDate: 2021-12-10 12:30:58 +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); }