From nobody Sat Nov 07 22:15:00 2026 X-Original-To: dev-commits-src-main@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 4jMVj02njMz6xtYp for ; Sat, 07 Nov 2026 22:15:00 +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 4jMVj02JNCz4MTM for ; Sat, 07 Nov 2026 22:15:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794089700; 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=kvx2BsF4JQuZk9NItSvODo+y2a/rTjmX/J8U49meJWMLib9SGt2408b4Fi4b9Ua3+2xAbI WuJPfDwg3AArE82WbtM5lYcbKEpnWfmKnu2kLPX7V/qsjIQ+r+fssIb8c3XrjDspHuk4Kb lJvcKzRA+Yxgx2FoxN5dfUIBxCTnelJoJ29WVoCFQ+5p0tVO7gW6SnHMCbUxYxGTZcm/FJ D4Izlfp/GxCCfLMQcjrj+0Mnz7YrY1PGCDF74P94GOpf7j3HsX3yzurFUKPb9po5QirOa2 XYD/ydcC1lrnzmY6qkM9LlZ4E+ky5jyGT6VTt5Ae8AeIa1Tnq47EIN7Ei89cTQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794089700; b=wZ9Fb1vykzDowxGHL6pWpMyDDuGLIe4HGx48nWHCPFE8qFhZT3Wb6OL5N+LYiBc8huR9Mx JphH3EeVt6N666XMNeUkvHv/hB/F16SuO9ObjGQ2vgOOeR6zTYUvLsttGw70Gg0M4s/3P3 jgiZapUuTAqE2wGDBa16mwufOxKdhox2ZCwwMrGRa0ESjCKeblnZc1uVVgNLSHNefioriS qbB/6F8Czc4fsXpTf/sa65j8NouIfI59xJ6gREMIxsFwBa9vGxS2oqZGUWV//6ri8T7l5a FkBlmC+Xa+1lFV53AbxodaKGRdlwYTX8Yg4RRtkNXijLedTG9AHAEHxcE+wceQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794089700; 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=sIqgEzeQvXAQOKA/uhiU4r9zUDmovgHnKsKVryWzgIKEs6DeRgpG4GUEQVoKh160ZBXlb9 hBTZ8sAo7lf/OFy0sAlFJ3Wb1dkRu85DXE8byCKyMzT47mZJtt/WuI0mjoMYAnuQvmtCqB qcKRNQDzAomYZQF5tHZbUZmcyIcQfjm5Kdsznk5ex3PC/C94DHjE554c7WCNitUWP5oAx2 00GNUTJmCeLGmEjzO9pUml0f5sdEpXSgXPoeUHgIUVsbfufR7A6W97m42E84e+fjc6uaMI AzRq700imH0TyUyNPRdVUA9QtqgDrc8SZaTI01/AX+Z/5L5/lIaK6Kxgr5RpMA== 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 4jMVj01c2qzh4S for ; Sat, 07 Nov 2026 22:15:00 +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-main X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: Commit messages for the main branch 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]); }