From nobody Sat Nov 07 22:15:02 2026 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 4jMVj328XNz6xtsb for ; Sat, 07 Nov 2026 22:15:03 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jMVj24dx2z4MZ9 for ; Sat, 07 Nov 2026 22:15:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794089702; 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=kkMJODVkh1cJ3tKm31UaEH82KyeKRqx79pbQRI5kI20=; b=Bj1SvwN8v3mn0FsRpavi+hcOx1J7kkmIuXoggD3YJUjdmszZDgyGJ0kK9MRqpOT31xENlL FtgUiqp6R8nTDrVX9yBKYhCWaBoa/QhO1Y5qg06Wnvno7ioVniZPH0sL5aT7cY/VlkTgCO jONEtXIGXPCFtISgfjMdTKVNzZhz2W2nyAD9kYfFT/FCIwNC5CQszspHnRFwvXinpbJQST 1mhxFQkrFzwDZj2jh96Kbw59BRZKU0IUj3RrKlMh9Gi/5L3w/B0LGAQjrEGi/g1jG+rQ00 n5msv4vtjlD69gs8DZCtg4RlnN1xS6o8X9+R3F4sAXOfqAq4b07ftbFXGbTV2A== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794089702; b=RXgE0sEQ8uq4vB7MFfV8HVXqDg9gzx2deCIy1VRhSAEW5gaw84hCJYqtTdZ1ciwZbLasJV p4TCmRIWFfoTpt7cwWLqWUcN0Z0USKO97+vney0rsPHcbbHv4byrLfEQcIEmnCKakRQB+A PiBnTrkiNrKubOpc62ke3qRoak594ph+ae/DH3nTHGZrg3hMU/7v2HUTsWhCm9KPIRdm2W xahsl/Cl09hqObJQ/oK0TL/EaazdSoDuGH7Ffz0MVhL46Z9ym4Rjx6qhM1/RZ96695cDxb QcWxv6ipCf/J11MYB88cc/Zbq6jABkCr0jCimUSkbsfQORuaLFLi3uXhJtiGMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794089702; 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=kkMJODVkh1cJ3tKm31UaEH82KyeKRqx79pbQRI5kI20=; b=KQfxFlxBCudldZIv8KpziP4V/hwABbU4BfTiWzKxzBh/VZR24+/pkPcRGgSKNrrwrzminm XpMjPaMCTU0yGbhNhen7cydEtzEZM88YGyf7EkzQ9/yOn4wZbMAm8lwHK6HMYI+NrnoGAC 2YyJnINNyZMmFkLzdiC6Ri6yaF5+MLxear5koo/8hHPDvkDEaNDEiTr3N5BMI/hK+zHVKL 4VJR0BPgKid6PprOwBkmornZoUZSzyjAC4Vh7A8ggAh6LA5jKeFgBuM4zZTzp9MBsneHgZ AE4VFcw/H2w+kTtQwXV8wKjcQ7J4IQlvM3Sv14rfiSytN7VrfhGxxcymDMGXrA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jMVj23NpszggN for ; Sat, 07 Nov 2026 22:15:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3f626 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 07 Nov 2026 22:15:02 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Abdelkader Boudih Subject: git: 880b166b02e1 - main - asmc: share the getinfo and getbyindex PIO transactions List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: seuros X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 880b166b02e1454bdb261d8947cbcb18f6580bf6 Auto-Submitted: auto-generated Date: Sat, 07 Nov 2026 22:15:02 +0000 Message-Id: <6aefa2e6.3f626.28d84484@gitrepo.freebsd.org> The branch main has been updated by seuros: URL: https://cgit.FreeBSD.org/src/commit/?id=880b166b02e1454bdb261d8947cbcb18f6580bf6 commit 880b166b02e1454bdb261d8947cbcb18f6580bf6 Author: Abdelkader Boudih AuthorDate: 2026-11-07 20:26:25 +0000 Commit: Abdelkader Boudih CommitDate: 2026-11-07 20:26:25 +0000 asmc: share the getinfo and getbyindex PIO transactions asmc_key_getinfo() and asmc_key_dump_by_index() both ran the command 0x13 transaction, the latter after a command 0x12. Put each behind a helper that assumes the caller holds sc_mtx, and fold the shared response decode into asmc_keyinfo_decode(). The index bytes are now derived inside the helper, so they are recomputed per retry. Same value all the time. Reviewed by: adrian Differential Revision: https://reviews.freebsd.org/D61285 --- sys/dev/asmc/asmc.c | 148 +++++++++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 66 deletions(-) diff --git a/sys/dev/asmc/asmc.c b/sys/dev/asmc/asmc.c index 3fe647818e4e..17da56b5ceb4 100644 --- a/sys/dev/asmc/asmc.c +++ b/sys/dev/asmc/asmc.c @@ -94,6 +94,12 @@ static int asmc_pio_send(device_t dev, const uint8_t *buf, int len, uint8_t status); static int asmc_pio_recv(device_t dev, uint8_t *buf, int len, uint8_t status); +static int asmc_pio_getbyindex_locked(device_t dev, int index, + uint8_t *key); +static int asmc_pio_getinfo_locked(device_t dev, const uint8_t *key, + uint8_t *info); +static void asmc_keyinfo_decode(const uint8_t *info, uint8_t *len, + char *type); static int asmc_key_write(device_t dev, const char *key, uint8_t *buf, uint8_t len); static int asmc_key_read(device_t dev, const char *key, uint8_t *buf, @@ -1242,6 +1248,59 @@ asmc_pio_recv(device_t dev, uint8_t *buf, int len, uint8_t status) return (0); } +/* Fetch the name of the index'th key; the caller holds sc_mtx. */ +static int +asmc_pio_getbyindex_locked(device_t dev, int index, uint8_t *key) +{ + struct asmc_softc *sc = device_get_softc(dev); + uint8_t index_buf[ASMC_KEYLEN]; + + index_buf[0] = (index >> 24) & 0xff; + index_buf[1] = (index >> 16) & 0xff; + index_buf[2] = (index >> 8) & 0xff; + index_buf[3] = index & 0xff; + + if (asmc_command(dev, ASMC_CMDGETBYINDEX)) + return (1); + + if (asmc_pio_send(dev, index_buf, ASMC_KEYLEN, ASMC_STATUS_AWAIT_DATA)) + return (1); + + ASMC_DATAPORT_WRITE(sc, ASMC_KEYLEN); + + return (asmc_pio_recv(dev, key, ASMC_KEYLEN, ASMC_STATUS_DATA_READY)); +} + +/* Fetch the raw key info response; the caller holds sc_mtx. */ +static int +asmc_pio_getinfo_locked(device_t dev, const uint8_t *key, uint8_t *info) +{ + struct asmc_softc *sc = device_get_softc(dev); + + if (asmc_command(dev, ASMC_CMDGETINFO)) + return (1); + + if (asmc_pio_send(dev, key, ASMC_KEYLEN, ASMC_STATUS_AWAIT_DATA)) + return (1); + + ASMC_DATAPORT_WRITE(sc, ASMC_KEYINFO_RESPLEN); + + return (asmc_pio_recv(dev, info, ASMC_KEYINFO_RESPLEN, + ASMC_STATUS_DATA_READY)); +} + +/* Split a key info response; type needs ASMC_TYPELEN + 1 bytes. */ +static void +asmc_keyinfo_decode(const uint8_t *info, uint8_t *len, char *type) +{ + if (len != NULL) + *len = info[0]; + if (type != NULL) { + memcpy(type, &info[1], ASMC_TYPELEN); + type[ASMC_TYPELEN] = '\0'; + } +} + static int asmc_key_read(device_t dev, const char *key, uint8_t *buf, uint8_t len) { @@ -1325,42 +1384,26 @@ asmc_key_getinfo(device_t dev, const char *key, uint8_t *len, char *type) { struct asmc_softc *sc = device_get_softc(dev); uint8_t info[ASMC_KEYINFO_RESPLEN]; - int i, error = -1, try = 0; + int error = -1, try = 0; if (sc->sc_is_mmio) return (asmc_mmio_key_getinfo(dev, key, len, type)); mtx_lock_spin(&sc->sc_mtx); -begin: - if (asmc_command(dev, ASMC_CMDGETINFO)) - goto out; - - if (asmc_pio_send(dev, (const uint8_t *)key, ASMC_KEYLEN, - ASMC_STATUS_AWAIT_DATA)) - goto out; - - ASMC_DATAPORT_WRITE(sc, ASMC_KEYINFO_RESPLEN); - - if (asmc_pio_recv(dev, info, ASMC_KEYINFO_RESPLEN, - ASMC_STATUS_DATA_READY)) - goto out; + do { + if (asmc_pio_getinfo_locked(dev, (const uint8_t *)key, + info) == 0) { + error = 0; + break; + } + } while (++try < ASMC_MAXRETRIES); - error = 0; -out: - if (error && ++try < ASMC_MAXRETRIES) - goto begin; mtx_unlock_spin(&sc->sc_mtx); - if (error == 0) { - if (len != NULL) - *len = info[0]; - if (type != NULL) { - for (i = 0; i < ASMC_TYPELEN; i++) - type[i] = info[i + 1]; - type[ASMC_TYPELEN] = '\0'; - } - } + if (error == 0) + asmc_keyinfo_decode(info, len, type); + return (error); } @@ -1798,7 +1841,6 @@ asmc_key_dump_by_index(device_t dev, int index, char *key_out, char *type_out, uint8_t *len_out) { struct asmc_softc *sc = device_get_softc(dev); - uint8_t index_buf[ASMC_KEYLEN]; uint8_t key_buf[ASMC_KEYLEN]; uint8_t info_buf[ASMC_KEYINFO_RESPLEN]; int error = ENXIO, try = 0; @@ -1813,50 +1855,24 @@ asmc_key_dump_by_index(device_t dev, int index, char *key_out, mtx_lock_spin(&sc->sc_mtx); - index_buf[0] = (index >> 24) & 0xff; - index_buf[1] = (index >> 16) & 0xff; - index_buf[2] = (index >> 8) & 0xff; - index_buf[3] = index & 0xff; - -begin: - if (asmc_command(dev, ASMC_CMDGETBYINDEX)) - goto out; - - if (asmc_pio_send(dev, index_buf, ASMC_KEYLEN, ASMC_STATUS_AWAIT_DATA)) - goto out; - - ASMC_DATAPORT_WRITE(sc, ASMC_KEYLEN); - - if (asmc_pio_recv(dev, key_buf, ASMC_KEYLEN, ASMC_STATUS_DATA_READY)) - goto out; - - if (asmc_command(dev, ASMC_CMDGETINFO)) - goto out; - - if (asmc_pio_send(dev, key_buf, ASMC_KEYLEN, ASMC_STATUS_AWAIT_DATA)) - goto out; + do { + if (asmc_pio_getbyindex_locked(dev, index, key_buf) == 0 && + asmc_pio_getinfo_locked(dev, key_buf, info_buf) == 0) { + error = 0; + break; + } + } while (++try < ASMC_MAXRETRIES); - ASMC_DATAPORT_WRITE(sc, ASMC_KEYINFO_RESPLEN); + mtx_unlock_spin(&sc->sc_mtx); - if (asmc_pio_recv(dev, info_buf, ASMC_KEYINFO_RESPLEN, - ASMC_STATUS_DATA_READY)) - goto out; + if (error != 0) + return (error); memcpy(key_out, key_buf, ASMC_KEYLEN); key_out[ASMC_KEYLEN] = '\0'; - *len_out = info_buf[0]; - memcpy(type_out, &info_buf[1], ASMC_TYPELEN); - type_out[ASMC_TYPELEN] = '\0'; - error = 0; + asmc_keyinfo_decode(info_buf, len_out, type_out); -out: - if (error) { - if (++try < ASMC_MAXRETRIES) - goto begin; - } - - mtx_unlock_spin(&sc->sc_mtx); - return (error); + return (0); } /*