From nobody Sat Feb 17 15:12:28 2024 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 4TcXND5ztMz5BFXc; Sat, 17 Feb 2024 15:12:28 +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 4TcXND2Smyz4YP3; Sat, 17 Feb 2024 15:12:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708182748; 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=jt4DYKJaeIIqOVM/CLuhvfiks6i6zvwL+TovUQr2LbE=; b=WDh4zsnLP33WB6ING5V9/RFdpEIJ6K/o4etpLlSZpfqFuXDHyGr3BqTc2OlifovSSgkDnx oY1ZUvW0gi/foREO7GfT/TwRNM3rdqir2ev22eZ8xExfYIlrd0LBTOoxV8ayIBzkBBhFAE kNufI6W7pI0TXn7FcqZzN3xGmdViXQqM9PlVW9i1tEUJvRj2om1LJyHOAMgQVFbN37gF7s 62/PbNbB+2j23p/28jMuVw9rSbwdBH0j+MF8TCY+B2aHbZzleYd4WH00dXZhlrcRZE+Rgi UeFSDMG/ycSW9nJGi1AVDuGEi1tpQhNOrUayLM71SU0+qfwoc4hOsbzKbkq+uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708182748; 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=jt4DYKJaeIIqOVM/CLuhvfiks6i6zvwL+TovUQr2LbE=; b=P1FJBRSdedznDDx7sYSJTGe15jtVloKU1ft6UN31vRkH07hbrQgDa1pA6bWsFboic7TEvc XehTZdvchzIfN55bdUYdAG0V96xOOC8jb8Goh1VBuVVa3oQ9n7oS301quPcjqOVDJSZpmi f9PlANjtCW+fm6oDmGrhj1i26fVWYJvP5FNk2ekCJQi4TCst2sV2gbtTzDhw0UldYP3mVg xoTWK7Mj5hVC5pOsnhb5ScMklDKgXgDvqXxg766CaRnohCHRBeUb+y1SW/xVR7yPYGCv0G zpLji/ilumLRw9kbvGE26szWhPYUSdGu7nY0+U+HPuiutGel0bPNvgcby5dXCA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708182748; a=rsa-sha256; cv=none; b=k8jTqLAUQp3vwAn9TQ3r3R/p8Bn4JreCkmX+9KqlZ5L9p5O7rVYubKN1+Bdvi8Qm585t6n toHRAn72CwgEWapTY9SNTfNY717Toau/h8dlpyJju32VD4pq6DX6OlpPjV8bs2m4Y/WVXL Er2LWf86sZXvBo4im+aQ6v2uSjJ5Wgt80sXdH5wQ9IlVGFf6TlJt0uthLCyaB54ThnQeiP 38T3fle8/sPziB+rdHGt9QkaWEau67eWhA1qyJECa/PsLJs5L9V6oOg0vzT3qzYhDoUC+C ksK4G9w8VbbIFjTu3K7Q214FK5CBEXYpE/Y0KqVcvWdMBHiDKD6nmdwyDI3Mpw== 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 4TcXND1ZnKz1CG5; Sat, 17 Feb 2024 15:12:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41HFCSeM080753; Sat, 17 Feb 2024 15:12:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41HFCSF1080750; Sat, 17 Feb 2024 15:12:28 GMT (envelope-from git) Date: Sat, 17 Feb 2024 15:12:28 GMT Message-Id: <202402171512.41HFCSF1080750@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: a9bab712eb10 - stable/14 - ichsmb: fix block read operation 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/14 X-Git-Reftype: branch X-Git-Commit: a9bab712eb10de15d28ada67e369e75dcbd09d9e Auto-Submitted: auto-generated The branch stable/14 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=a9bab712eb10de15d28ada67e369e75dcbd09d9e commit a9bab712eb10de15d28ada67e369e75dcbd09d9e Author: Andriy Gapon AuthorDate: 2022-09-13 21:26:35 +0000 Commit: Andriy Gapon CommitDate: 2024-02-17 14:15:11 +0000 ichsmb: fix block read operation First of all and unlike I2C, it's not the master that dictates how many bytes to read in block read operation. It's the device that informs the master how many bytes it's sending back. Thus, for ichsmb_bread() the count parameter is purely an output parameter. The code has been changed to reflect that. The sanity checking of the response length is now done once it (the first byte of the response) is received. While here, handling of ICH_HST_STA_FAILED status bit has been added. Plus some code style improvements and some new code comments in the vicinity of the changed code. (cherry picked from commit cbf7c81b608bb9311e50df9481447dc843083a0e) --- sys/dev/ichsmb/ichsmb.c | 61 ++++++++++++++++++++++++++++++++------------- sys/dev/ichsmb/ichsmb_var.h | 5 ++-- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/sys/dev/ichsmb/ichsmb.c b/sys/dev/ichsmb/ichsmb.c index 7405f625e69f..94fc03d2bc67 100644 --- a/sys/dev/ichsmb/ichsmb.c +++ b/sys/dev/ichsmb/ichsmb.c @@ -389,8 +389,8 @@ ichsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf) return (SMB_EINVAL); bcopy(buf, sc->block_data, count); sc->block_count = count; - sc->block_index = 1; - sc->block_write = 1; + sc->block_index = 1; /* buf[0] is written here */ + sc->block_write = true; mtx_lock(&sc->mutex); sc->ich_cmd = ICH_HST_CNT_SMB_CMD_BLOCK; @@ -413,26 +413,23 @@ ichsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf) const sc_p sc = device_get_softc(dev); int smb_error; - DBG("slave=0x%02x cmd=0x%02x count=%d\n", slave, (u_char)cmd, count); + DBG("slave=0x%02x cmd=0x%02x\n", slave, (u_char)cmd); KASSERT(sc->ich_cmd == -1, ("%s: ich_cmd=%d\n", __func__ , sc->ich_cmd)); - if (*count < 1 || *count > 32) - return (SMB_EINVAL); bzero(sc->block_data, sizeof(sc->block_data)); sc->block_count = 0; sc->block_index = 0; - sc->block_write = 0; + sc->block_write = false; mtx_lock(&sc->mutex); sc->ich_cmd = ICH_HST_CNT_SMB_CMD_BLOCK; bus_write_1(sc->io_res, ICH_XMIT_SLVA, slave | ICH_XMIT_SLVA_READ); bus_write_1(sc->io_res, ICH_HST_CMD, cmd); - bus_write_1(sc->io_res, ICH_D0, *count); /* XXX? */ bus_write_1(sc->io_res, ICH_HST_CNT, ICH_HST_CNT_START | ICH_HST_CNT_INTREN | sc->ich_cmd); if ((smb_error = ichsmb_wait(sc)) == SMB_ENOERR) { - bcopy(sc->block_data, buf, min(sc->block_count, *count)); + bcopy(sc->block_data, buf, sc->block_count); *count = sc->block_count; } mtx_unlock(&sc->mutex); @@ -515,21 +512,35 @@ ichsmb_device_intr(void *cookie) /* Check for unexpected interrupt */ ok_bits = ICH_HST_STA_SMBALERT_STS; - cmd_index = sc->ich_cmd >> 2; + + if (sc->killed) { + sc->killed = 0; + ok_bits |= ICH_HST_STA_FAILED; + bus_write_1(sc->io_res, ICH_HST_CNT, + ICH_HST_CNT_INTREN); + } + if (sc->ich_cmd != -1) { + cmd_index = sc->ich_cmd >> 2; KASSERT(cmd_index < sizeof(ichsmb_state_irqs), ("%s: ich_cmd=%d", device_get_nameunit(dev), sc->ich_cmd)); ok_bits |= ichsmb_state_irqs[cmd_index]; } if ((status & ~ok_bits) != 0) { - device_printf(dev, "irq 0x%02x during %d\n", status, - cmd_index); + device_printf(dev, "irq 0x%02x during 0x%02x\n", status, + sc->ich_cmd); bus_write_1(sc->io_res, ICH_HST_STA, (status & ~ok_bits)); continue; } + /* Check for killed / aborted command */ + if (status & ICH_HST_STA_FAILED) { + sc->smb_error = SMB_EABORT; + goto finished; + } + /* Check for bus error */ if (status & ICH_HST_STA_BUS_ERR) { sc->smb_error = SMB_ECOLLI; /* XXX SMB_EBUSERR? */ @@ -558,6 +569,18 @@ ichsmb_device_intr(void *cookie) if (sc->block_index == 0) { sc->block_count = bus_read_1( sc->io_res, ICH_D0); + if (sc->block_count < 1 || + sc->block_count > 32) { + device_printf(dev, "block read " + "wrong length: %d\n", + sc->block_count); + bus_write_1(sc->io_res, + ICH_HST_CNT, + ICH_HST_CNT_KILL | + ICH_HST_CNT_INTREN); + sc->block_count = 0; + sc->killed = true; + } } /* Get next byte, if any */ @@ -568,15 +591,17 @@ ichsmb_device_intr(void *cookie) bus_read_1(sc->io_res, ICH_BLOCK_DB); - /* Set "LAST_BYTE" bit before reading - the last byte of block data */ - if (sc->block_index - >= sc->block_count - 1) { + /* + * Set "LAST_BYTE" bit before reading + * the last byte of block data + */ + if (sc->block_index == + sc->block_count - 1) { bus_write_1(sc->io_res, ICH_HST_CNT, - ICH_HST_CNT_LAST_BYTE - | ICH_HST_CNT_INTREN - | sc->ich_cmd); + ICH_HST_CNT_LAST_BYTE | + ICH_HST_CNT_INTREN | + sc->ich_cmd); } } } diff --git a/sys/dev/ichsmb/ichsmb_var.h b/sys/dev/ichsmb/ichsmb_var.h index abef219465e6..7fb14804d3c4 100644 --- a/sys/dev/ichsmb/ichsmb_var.h +++ b/sys/dev/ichsmb/ichsmb_var.h @@ -58,8 +58,9 @@ struct ichsmb_softc { int smb_error; /* result of smb command */ int block_count; /* count for block read/write */ int block_index; /* index for block read/write */ - u_char block_write; /* 0=read, 1=write */ - u_char block_data[32]; /* block read/write data */ + bool block_write; /* block write or block read */ + uint8_t block_data[32]; /* block read/write data */ + bool killed; /* killed current transfer */ struct mtx mutex; /* device mutex */ }; typedef struct ichsmb_softc *sc_p;