From nobody Sat Feb 17 19:22:38 2024 X-Original-To: dev-commits-src-branches@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 4Tcdwv1Zqtz53y5y; Sat, 17 Feb 2024 19:22:39 +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 4Tcdwt6Gt2z4Frl; Sat, 17 Feb 2024 19:22:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708197758; 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=Qv97pJQFwgVPQFwnF3ZgkgHVsJb9R7APwmmDyuepJuI=; b=bjHFkJawXmBNN2YOMrXsLDlk0PU1WCigmBvQavtZ2+46va3VhfNdqFbbLumTw104cFEO0N G7fHkoWBoAzedvCu/tWFIfwUB/3VlvaViA/3785oyC+6MW2MjTHzgIdURVQMnO/3tDYLwL rkP7j3kILcYG9oxLaZOCCKGhDwZh9/ATRc/A11aY+tRHGovX3HJRo7WCasix63HoRdXVal Wnh+2PxL5bGVcbSV8mWHEN+y+MFY+HgkoYDHarMvWXPrC1FXK+qPXcgs07c7kfxWahDb4/ IwqRqy2Aki9MQHRp6VI5nJtfi9Tc+IOjT8p6XsycUT4V+Eb2EbwK0zXVYaQklw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708197758; 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=Qv97pJQFwgVPQFwnF3ZgkgHVsJb9R7APwmmDyuepJuI=; b=BxYR+yGG06jcZoOunL7TzuLNo7gbyud4BwXSvaNJZtbtBDGEE7dfMN23Sd14n8CaLDZsIl 0wfi75SVOOiT+B/kgHfE0/2OLAOhQq6QA3AKzzrtjiMLChsOLydYjljZDwgqtd0U0uytBh PAEl3ZbznJCi7gnoupPm+vVxw3ajpNXjUipwrYRiEyB/0YRVMLJyoHroM/zoVoKBJVSDzZ G/S8KaSPI7qBxhrwbgqnPHH1Y3X8MFp1eh3i/MypqVpdhjuXY0exsotPecyypojsG8P2rZ i9oNjrU354t9sUUgTRoj2vxAm6Wz4oyjHpA2A0K+21QpJStEE0wt+H/b1PiGMw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708197758; a=rsa-sha256; cv=none; b=Q9Os09bferHwlm7Sj5AOAStpDVo66q6UFx9qJ30uJb7nu2g7NmseukVh+nuwkXjGJECyyZ jSFNOw5V/Z9hqVMM/n0WoakaGtdt2T/MHPvxD1Qi4qMD63evPdWgs2NO46YmG97VPn4FHH HU0CURFhTeqWJlu9RXtjes+QqhpwAB+DbZeCRVqdxOtkOxADXi6jeMjVKCXv/b20OT4W2l 549mjLJvNve3yzxSOeA/w0z6wl1dRU5XUz242JwAKKDTpTnWxFysBosEQSi2xBnS6NCbW4 a8ZBTlrIlK7Ige3OsNBywF6wB4XcPmGxjGTuwTxkAEkylrFqMiLqRos0VOgKtg== 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 4Tcdwt4L3rzLHy; Sat, 17 Feb 2024 19:22:38 +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 41HJMco2000650; Sat, 17 Feb 2024 19:22:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41HJMcBT000647; Sat, 17 Feb 2024 19:22:38 GMT (envelope-from git) Date: Sat, 17 Feb 2024 19:22:38 GMT Message-Id: <202402171922.41HJMcBT000647@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: faa59e9ab402 - stable/13 - ichsmb: fix block read operation List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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: faa59e9ab402b12f3c3d3386175a178e45308b22 Auto-Submitted: auto-generated The branch stable/13 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=faa59e9ab402b12f3c3d3386175a178e45308b22 commit faa59e9ab402b12f3c3d3386175a178e45308b22 Author: Andriy Gapon AuthorDate: 2022-09-13 21:26:35 +0000 Commit: Andriy Gapon CommitDate: 2024-02-17 19:22:08 +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 30c408a92c59..9d99838ef2ad 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); @@ -514,16 +511,24 @@ 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; @@ -541,6 +546,12 @@ ichsmb_device_intr(void *cookie) } } + /* 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? */ @@ -569,6 +580,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 */ @@ -579,15 +602,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;