From nobody Sat Nov 07 22:15:00 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 4jMVj60rpRz6xtcW for ; Sat, 07 Nov 2026 22:15:06 +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 4jMVj54SwBz4Mvt for ; Sat, 07 Nov 2026 22:15:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794089705; 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=ROo88IM3Z+1NC+PiarIGZexRtjBhVbgKoV3hYY/lFaU=; b=LYlQ3K9pYbN/BEHOEV8lA1sk0l4d/yQFB8SSxUh+yRd65U2Brl9JUrY7Hdr/QOv+b+ejrG m/ihSPoquImOEmfm1t9NjITG79L2qPu/ubwtopUiRQTCOM48bjfRMnxPtBTcj0b7MW5g5X JrsOMNz/kiXOU/u0KRW5yOR6B7HOW1ZPrJO8k8Xg3PC6ujMN1rrzdjXbiEJOPG0CdSL8PP Au3QY7Old88ODfh2Yt/TS3qgyO4bSRbmEHISyA1L9lHYidqbZwjogQtkzAXO+qZ/+3Zl5k FkC8sv3he+2QwM4XY5E0kF7dogWJzymWhnys30Xh1UA87YlfiMYNO3E0uvLhyg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794089705; b=R+Y5Slh2WxxTrAeEa0tkW3qPC04mRlGd6Ksx+HBtn4PNKMEwTQ8jqWfARvn99ESEleyuCq ojchLSUUJT2jOor61Qa4hZh22u+n4xAsuTHs/wvbQN4hdE+OPQq6+l8vG5KOB8Wls6VZx2 h/NK+hvjQ/PxPGnW3uvCfMe2vtml1AD+jAfwe8AFILCgAnwhno5Bo/hsm8ZTeHVDcoe8H+ BChHdX49q9kIhSUg4u4xvKd83O3e3SqKHluMWUeyVnmEJXXZnu9lk0KTsc/E6AyaUVx8Bq bZ7SXSfD4fO0E5pS4X0dsM7zdAngyVNC4CPzDXRx/GvW97FuRtdhdFibQe4PzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794089705; 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=ROo88IM3Z+1NC+PiarIGZexRtjBhVbgKoV3hYY/lFaU=; b=XRtsK5ZaPGu8PS7JIAYvh9/gBdOoIgYALvZgDTZ51JwCEldrb5riErEy+XDCDyc+4gal/n 3qUN3yoxOweCRbuDPp3w6CS+epYKvjQDBCNbT+cBe5ZGeeAQJApQYODGlYuCql7+kq8r0/ EWL4z326hF7rnkBQKba8gRm5Gl/n0XRtz0CGStkEb5xBn+TuRfADTj083puf9B0mJpjknQ ND5FzF6MJtslGArklZ76414Q7RY6esit1rGxabLYfvJ8BkHxLCEsWAHUi+QPP+KcryDDej FDuyVIv3iwY5ecuy+zxvFT0tuhnKraBy71/7A2U3HO4QQ+cyL+drMASXQqhgSg== 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 4jMVj53YzRzgXS for ; Sat, 07 Nov 2026 22:15:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 40071 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 07 Nov 2026 22:15:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Abdelkader Boudih Subject: git: 5ac6a4154b77 - main - asmc: factor out the PIO data port byte loops 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: 5ac6a4154b77164bb04d892401ccbc2513f582df Auto-Submitted: auto-generated Date: Sat, 07 Nov 2026 22:15:00 +0000 Message-Id: <6aefa2e4.40071.41b996b0@gitrepo.freebsd.org> The branch main has been updated by seuros: URL: https://cgit.FreeBSD.org/src/commit/?id=5ac6a4154b77164bb04d892401ccbc2513f582df commit 5ac6a4154b77164bb04d892401ccbc2513f582df Author: Abdelkader Boudih AuthorDate: 2026-11-07 20:25:59 +0000 Commit: Abdelkader Boudih CommitDate: 2026-11-07 20:25:59 +0000 asmc: factor out the PIO data port byte loops Reuse existing pattern and evict magic numbers No functional change: the port access sequence and the per-caller retry and error reporting behaviour are unchanged. Reviewed by: adrian Differential Revision: https://reviews.freebsd.org/D61283 --- sys/dev/asmc/asmc.c | 139 +++++++++++++++++++++++++++------------------------- 1 file changed, 71 insertions(+), 68 deletions(-) diff --git a/sys/dev/asmc/asmc.c b/sys/dev/asmc/asmc.c index 182f6d585080..9906f4acd28c 100644 --- a/sys/dev/asmc/asmc.c +++ b/sys/dev/asmc/asmc.c @@ -90,6 +90,10 @@ static int asmc_init(device_t dev); static int asmc_command(device_t dev, uint8_t command); static int asmc_wait(device_t dev, uint8_t val); static int asmc_wait_ack(device_t dev, uint8_t val, int amount); +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_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, @@ -1208,11 +1212,41 @@ asmc_command(device_t dev, uint8_t command) return (1); } +/* Push len bytes out the data port, awaiting status after each. */ +static int +asmc_pio_send(device_t dev, const uint8_t *buf, int len, uint8_t status) +{ + struct asmc_softc *sc = device_get_softc(dev); + + for (int i = 0; i < len; i++) { + ASMC_DATAPORT_WRITE(sc, buf[i]); + if (asmc_wait(dev, status)) + return (1); + } + + return (0); +} + +/* Await status then pull each of len bytes from the data port. */ +static int +asmc_pio_recv(device_t dev, uint8_t *buf, int len, uint8_t status) +{ + struct asmc_softc *sc = device_get_softc(dev); + + for (int i = 0; i < len; i++) { + if (asmc_wait(dev, status)) + return (1); + buf[i] = ASMC_DATAPORT_READ(sc); + } + + return (0); +} + static int asmc_key_read(device_t dev, const char *key, uint8_t *buf, uint8_t len) { struct asmc_softc *sc = device_get_softc(dev); - int i, error = 1, try = 0; + int error = 1, try = 0; if (sc->sc_is_mmio) return (asmc_mmio_key_read(dev, key, buf, len)); @@ -1223,19 +1257,14 @@ begin: if (asmc_command(dev, ASMC_CMDREAD)) goto out; - for (i = 0; i < 4; i++) { - ASMC_DATAPORT_WRITE(sc, key[i]); - if (asmc_wait(dev, 0x04)) - goto out; - } + if (asmc_pio_send(dev, (const uint8_t *)key, ASMC_KEYLEN, + ASMC_STATUS_AWAIT_DATA)) + goto out; ASMC_DATAPORT_WRITE(sc, len); - for (i = 0; i < len; i++) { - if (asmc_wait(dev, 0x05)) - goto out; - buf[i] = ASMC_DATAPORT_READ(sc); - } + if (asmc_pio_recv(dev, buf, len, ASMC_STATUS_DATA_READY)) + goto out; error = 0; out: @@ -1295,37 +1324,28 @@ begin: if (asmc_command(dev, ASMC_CMDGETBYINDEX)) goto out; - for (i = 0; i < ASMC_KEYLEN; i++) { - ASMC_DATAPORT_WRITE(sc, index[i]); - if (asmc_wait(dev, ASMC_STATUS_AWAIT_DATA)) - goto out; - } + if (asmc_pio_send(dev, index, ASMC_KEYLEN, ASMC_STATUS_AWAIT_DATA)) + goto out; ASMC_DATAPORT_WRITE(sc, ASMC_KEYLEN); - for (i = 0; i < ASMC_KEYLEN; i++) { - if (asmc_wait(dev, ASMC_STATUS_DATA_READY)) - goto out; - key[i] = ASMC_DATAPORT_READ(sc); - } + if (asmc_pio_recv(dev, (uint8_t *)key, ASMC_KEYLEN, + ASMC_STATUS_DATA_READY)) + goto out; /* Get key info (length + type). */ if (asmc_command(dev, ASMC_CMDGETINFO)) goto out; - for (i = 0; i < ASMC_KEYLEN; i++) { - ASMC_DATAPORT_WRITE(sc, key[i]); - if (asmc_wait(dev, ASMC_STATUS_AWAIT_DATA)) - 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); - for (i = 0; i < ASMC_KEYINFO_RESPLEN; i++) { - if (asmc_wait(dev, ASMC_STATUS_DATA_READY)) - goto out; - type[i] = ASMC_DATAPORT_READ(sc); - } + if (asmc_pio_recv(dev, (uint8_t *)type, ASMC_KEYINFO_RESPLEN, + ASMC_STATUS_DATA_READY)) + goto out; error = 0; out: @@ -1387,19 +1407,15 @@ begin: if (asmc_command(dev, ASMC_CMDGETINFO)) goto out; - for (i = 0; i < ASMC_KEYLEN; i++) { - ASMC_DATAPORT_WRITE(sc, key[i]); - if (asmc_wait(dev, ASMC_STATUS_AWAIT_DATA)) - 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); - for (i = 0; i < ASMC_KEYINFO_RESPLEN; i++) { - if (asmc_wait(dev, ASMC_STATUS_DATA_READY)) - goto out; - info[i] = ASMC_DATAPORT_READ(sc); - } + if (asmc_pio_recv(dev, info, ASMC_KEYINFO_RESPLEN, + ASMC_STATUS_DATA_READY)) + goto out; error = 0; out: @@ -1857,7 +1873,6 @@ asmc_key_dump_by_index(device_t dev, int index, char *key_out, uint8_t key_buf[ASMC_KEYLEN]; uint8_t info_buf[ASMC_KEYINFO_RESPLEN]; int error = ENXIO, try = 0; - int i; if (sc->sc_is_mmio) { error = asmc_mmio_key_getbyindex(dev, index, key_out); @@ -1878,36 +1893,25 @@ begin: if (asmc_command(dev, ASMC_CMDGETBYINDEX)) goto out; - for (i = 0; i < ASMC_KEYLEN; i++) { - ASMC_DATAPORT_WRITE(sc, index_buf[i]); - if (asmc_wait(dev, ASMC_STATUS_AWAIT_DATA)) - goto out; - } + if (asmc_pio_send(dev, index_buf, ASMC_KEYLEN, ASMC_STATUS_AWAIT_DATA)) + goto out; ASMC_DATAPORT_WRITE(sc, ASMC_KEYLEN); - for (i = 0; i < ASMC_KEYLEN; i++) { - if (asmc_wait(dev, ASMC_STATUS_DATA_READY)) - goto out; - key_buf[i] = ASMC_DATAPORT_READ(sc); - } + if (asmc_pio_recv(dev, key_buf, ASMC_KEYLEN, ASMC_STATUS_DATA_READY)) + goto out; if (asmc_command(dev, ASMC_CMDGETINFO)) goto out; - for (i = 0; i < ASMC_KEYLEN; i++) { - ASMC_DATAPORT_WRITE(sc, key_buf[i]); - if (asmc_wait(dev, ASMC_STATUS_AWAIT_DATA)) - goto out; - } + if (asmc_pio_send(dev, key_buf, ASMC_KEYLEN, ASMC_STATUS_AWAIT_DATA)) + goto out; ASMC_DATAPORT_WRITE(sc, ASMC_KEYINFO_RESPLEN); - for (i = 0; i < ASMC_KEYINFO_RESPLEN; i++) { - if (asmc_wait(dev, ASMC_STATUS_DATA_READY)) - goto out; - info_buf[i] = ASMC_DATAPORT_READ(sc); - } + if (asmc_pio_recv(dev, info_buf, ASMC_KEYINFO_RESPLEN, + ASMC_STATUS_DATA_READY)) + goto out; memcpy(key_out, key_buf, ASMC_KEYLEN); key_out[ASMC_KEYLEN] = '\0'; @@ -1974,17 +1978,16 @@ begin: goto out; ASMC_DPRINTF(("data port: key\n")); - for (i = 0; i < 4; i++) { - ASMC_DATAPORT_WRITE(sc, key[i]); - if (asmc_wait(dev, 0x04)) - goto out; - } + if (asmc_pio_send(dev, (const uint8_t *)key, ASMC_KEYLEN, + ASMC_STATUS_AWAIT_DATA)) + goto out; + ASMC_DPRINTF(("data port: length\n")); ASMC_DATAPORT_WRITE(sc, len); ASMC_DPRINTF(("data port: buffer\n")); for (i = 0; i < len; i++) { - if (asmc_wait(dev, 0x04)) + if (asmc_wait(dev, ASMC_STATUS_AWAIT_DATA)) goto out; ASMC_DATAPORT_WRITE(sc, buf[i]); }