From nobody Sun Jan 28 12:54:55 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 4TNBGl3c7Fz58XKh; Sun, 28 Jan 2024 12:54:55 +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 4TNBGl2llcz4vfJ; Sun, 28 Jan 2024 12:54:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706446495; 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=mpX3nKUk6vgqOb0zYbGp6FBsS5exo+BXsHYW8XOnG3M=; b=bANQ7CoPq+BVb26FEXb2JH9MAMwan50BQimH4F3yfwzdipkVlhducf1VZadTSO1++h0Nqj ANuwCZY9r/BsOfLIMrsaF9WDHP4IxMSZuRDOVXJw3Rh1jCXcp0HOp2xDrLREQzyVldVbqB d+WJyh3BedZxd6WJmqtREQJ3kcuuXHfdIPqpPhWPfSLhHSDSV1I5FbkHrs2vuzpc7oFo0e bxa1GkLaKh9dWfpwZ011DV0p07FUPLVoj0QlgCYfmHBYC1HG0h0JiVBI6ieO8/nyBHzBbE nKKba9IW9k0DNJmoikgvYcWYAfEth7lyKt4IQvwb/5/bBJnAl2CkPRF1bo/1DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706446495; 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=mpX3nKUk6vgqOb0zYbGp6FBsS5exo+BXsHYW8XOnG3M=; b=e6JIH1s3qB+cJLk7jk0qwUwyhzkzQfwab+nidzwtqwD1Jd+KBH+I+zltq2P6Bm3RpnlyhB QDurpb6A2/HD7C+nXELYrtk0BjknW/Ah2g04rb+rhZ/595gpR+I66dwQz6oR9N+PM0DvH/ 7kjg+XZw5fbK+0B3mtSp7QQVtxaFmBnf7IfWmgTaUc4i/8EYWh2Hw9nATt2AWG/UT020L0 UuUvdXO/Ksnn8HqhHvODY2SgtslOvEuh1VxFx/nO+BMzjRMzFOjdpCy5JAa22Wfj5brKWY AEuKJXfAyqSdlpcYJHSLGj8xTLdH1jy0K/rcOIKS0DlVV9UQkPngP4e11D0p1A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706446495; a=rsa-sha256; cv=none; b=oaV634bXPNKugSWte7uGC3AudgppZo2ESIPjrsCP3ZRcFePcsfWyPcavCfV7Uox4kswEiX Iz+35mJwSX6f6ctQROt5H0mwVHjFl5K93Z59VdObuU6pA9rO4OF3Zu5SGDra19D7DGkHp8 SRa/qa75z9wmk4lK3SmL7HjEbwBrkSkxri1kJH0rg4jOqKuSpUiaT1EWB2+sSbFTBBRFk/ eWSlzuT2utcqoD0JdVdVV2F4R3xFSvOvnUI1aKQgoSqRKIhFdaY9MO9osdyRtz01A/VwOu ee8Ntcj8wJjDl6jOOTxbOXeb5G4pcV25Mbd0/xrURoVOgp0kXQCL4J31SUU2EQ== 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 4TNBGl1msGz17jS; Sun, 28 Jan 2024 12:54:55 +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 40SCstRr005204; Sun, 28 Jan 2024 12:54:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40SCstTd005201; Sun, 28 Jan 2024 12:54:55 GMT (envelope-from git) Date: Sun, 28 Jan 2024 12:54:55 GMT Message-Id: <202401281254.40SCstTd005201@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: cbf7c81b608b - main - 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/main X-Git-Reftype: branch X-Git-Commit: cbf7c81b608bb9311e50df9481447dc843083a0e Auto-Submitted: auto-generated The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=cbf7c81b608bb9311e50df9481447dc843083a0e commit cbf7c81b608bb9311e50df9481447dc843083a0e Author: Andriy Gapon AuthorDate: 2022-09-13 21:26:35 +0000 Commit: Andriy Gapon CommitDate: 2024-01-28 12:54:19 +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. --- 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;