From nobody Fri Jan 19 17:09:49 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 4TGmM16dgMz56wc1; Fri, 19 Jan 2024 17:09:49 +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 4TGmM15qB0z4Jkc; Fri, 19 Jan 2024 17:09:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705684189; 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=0NkZzRrk8oPRCm+GhFQQ11NizFXwv9hm2oyKTQxt7vk=; b=Gcfrch94QSmgf0QZO0XDgZinpekoDGKZFXQ4zAm4bGyrRpDyootmdIQ61Ko5HONCWfoGjB pUJoftySqjR6KKvZnH/sfl1JcnwgZdeWFN9HVFDGJBZedRVnbodMsb7Jj9kDNINSZPPbTM rZS8I9uTDLtcP29il0ZWZX5Rc9XNwBCEsT2GSNyx0tx/+8mNp6jqhZTAnSqeiGMUDEZIRI bWORYOSNQSIUx+XWFaXgP0ZpAJT4J4bblbfPossQcimMbkxWXxVWlfOOlN2GeqINdb6/me 9oafru9CiMYbxg+/eSnqMreJn1x4Zba6iVD2kGc0jWLd7sp52uc0yvBZG2fEDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705684189; 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=0NkZzRrk8oPRCm+GhFQQ11NizFXwv9hm2oyKTQxt7vk=; b=fRKZpOK1e2igsMj8AHAZoJ1DtRs9+uJlEwEG3eyuuTWKt3NdjQRUrnR7//mEqo+bKh+K+R 1pZ6ngLSZjHRuPyKAiyOzWBtQrX1z1xc8MxhWxk7F+VwMT/1E7W34dkr33RFay6dlWxyKw WS9S1avirjfEZl9ygflDHbkrRo6m1S4Kda82Wd1tA8F9e9KZKlcoYphpkimUXmdYJLnLk1 uxk3ZRhEaG+ouurMX9/cPzAm24pI6GntK6IFuQyphtMS7WpRK1epd33n93h7sIwiXTicbT /banZMPc1rm9A/5mu3R7mPyluphg2gIlw/ZrEehuVRUpFRYMWLKmC2Bq6BaqAQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705684189; a=rsa-sha256; cv=none; b=UdY3540hLnP4UW41732re19lLCnZA+N1ETX5Iae/CX/JVswgtBjm2vfH985dpBWpteBXYo fYV2mCbMvw2OzAXk2+lk41bPNVGfKMNAYjW4jnOBVeez+gK8nl8GmYj6S5sGPAqSHuEuCL 5Sh5sVlkTKnIBgKjD0YVG2f9A8PcwWB6bdyXg6utrLJmoWOVR/LGBfLw3AIZ4uTj8KjUsp G8pfShvOyUL4Xu6Sn8naXqQvHcXOd4p6JlRPHE7n7/wHHoB7e2JyKhVAHKueTDyBWYz0VP gziQLf8aBosoR1HufAf9M44LAgEZ8TGv/zL+lykxSh/P8xMlIxVQ6syrQZQP0A== 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 4TGmM14td9z10QC; Fri, 19 Jan 2024 17:09:49 +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 40JH9nR3079540; Fri, 19 Jan 2024 17:09:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40JH9nF3079537; Fri, 19 Jan 2024 17:09:49 GMT (envelope-from git) Date: Fri, 19 Jan 2024 17:09:49 GMT Message-Id: <202401191709.40JH9nF3079537@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 8d8f348c8fe7 - stable/13 - ig4: Actively use FIFO thresholds 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: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 8d8f348c8fe782c7de4b326e6bc80d36ba7bfba7 Auto-Submitted: auto-generated The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=8d8f348c8fe782c7de4b326e6bc80d36ba7bfba7 commit 8d8f348c8fe782c7de4b326e6bc80d36ba7bfba7 Author: Alexander Motin AuthorDate: 2023-12-24 23:18:11 +0000 Commit: Alexander Motin CommitDate: 2024-01-19 17:04:38 +0000 ig4: Actively use FIFO thresholds Before every wait for FIFO interrupt set how much data/space do we want to see there. Previous code was not using it for receive, as result aggregating interrupts only within processing latency. The new code needs only one interrupt per transfer per FIFO length. On my Dell XPS 13 9310 with iichid(4) touchscreen and touchpad this reduces the interrupt rate per device down to 2 per sample or 16-20 per second when idle and 120-160 per second when actively touched. MFC after: 1 month (cherry picked from commit 13037eaabede7fb7fbc25f4e84b549c73f9acb3c) --- sys/dev/ichiic/ig4_iic.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/sys/dev/ichiic/ig4_iic.c b/sys/dev/ichiic/ig4_iic.c index 96909dd2d3f3..83238274d33f 100644 --- a/sys/dev/ichiic/ig4_iic.c +++ b/sys/dev/ichiic/ig4_iic.c @@ -347,6 +347,7 @@ set_slave_addr(ig4iic_softc_t *sc, uint8_t slave) /* * Wait for TXFIFO to drain before disabling the controller. */ + reg_write(sc, IG4_REG_TX_TL, 0); wait_intr(sc, IG4_INTR_TX_EMPTY); set_controller(sc, 0); @@ -434,16 +435,20 @@ ig4iic_read(ig4iic_softc_t *sc, uint8_t *buf, uint16_t len, return (0); while (received < len) { + /* Ensure we have some free space in TXFIFO */ burst = sc->cfg.txfifo_depth - (reg_read(sc, IG4_REG_TXFLR) & IG4_FIFOLVL_MASK); if (burst <= 0) { + reg_write(sc, IG4_REG_TX_TL, IG4_FIFO_LOWAT); error = wait_intr(sc, IG4_INTR_TX_EMPTY); if (error) break; - burst = sc->cfg.txfifo_depth; + burst = sc->cfg.txfifo_depth - + (reg_read(sc, IG4_REG_TXFLR) & IG4_FIFOLVL_MASK); } /* Ensure we have enough free space in RXFIFO */ - burst = MIN(burst, sc->cfg.rxfifo_depth - lowat); + burst = MIN(burst, sc->cfg.rxfifo_depth - + (requested - received)); target = MIN(requested + burst, (int)len); while (requested < target) { cmd = IG4_DATA_COMMAND_RD; @@ -460,13 +465,15 @@ ig4iic_read(ig4iic_softc_t *sc, uint8_t *buf, uint16_t len, lowat = IG4_FIFO_LOWAT; /* After TXFLR fills up, clear it by reading available data */ while (received < requested - lowat) { - burst = MIN((int)len - received, + burst = MIN(requested - received, reg_read(sc, IG4_REG_RXFLR) & IG4_FIFOLVL_MASK); if (burst > 0) { while (burst--) buf[received++] = 0xFF & reg_read(sc, IG4_REG_DATA_CMD); } else { + reg_write(sc, IG4_REG_RX_TL, + requested - received - lowat - 1); error = wait_intr(sc, IG4_INTR_RX_FULL); if (error) goto out; @@ -484,8 +491,7 @@ ig4iic_write(ig4iic_softc_t *sc, uint8_t *buf, uint16_t len, uint32_t cmd; int sent = 0; int burst, target; - int error; - bool lowat_set = false; + int error, lowat; if (len == 0) return (0); @@ -494,12 +500,7 @@ ig4iic_write(ig4iic_softc_t *sc, uint8_t *buf, uint16_t len, burst = sc->cfg.txfifo_depth - (reg_read(sc, IG4_REG_TXFLR) & IG4_FIFOLVL_MASK); target = MIN(sent + burst, (int)len); - /* Leave some data queued to maintain the hardware pipeline */ - if (!lowat_set && target != len) { - lowat_set = true; - reg_write(sc, IG4_REG_TX_TL, IG4_FIFO_LOWAT); - } - while(sent < target) { + while (sent < target) { cmd = buf[sent]; if (repeated_start && sent == 0) cmd |= IG4_DATA_RESTART; @@ -509,13 +510,16 @@ ig4iic_write(ig4iic_softc_t *sc, uint8_t *buf, uint16_t len, sent++; } if (sent < len) { + if (len - sent <= sc->cfg.txfifo_depth) + lowat = sc->cfg.txfifo_depth - (len - sent); + else + lowat = IG4_FIFO_LOWAT; + reg_write(sc, IG4_REG_TX_TL, lowat); error = wait_intr(sc, IG4_INTR_TX_EMPTY); if (error) break; } } - if (lowat_set) - reg_write(sc, IG4_REG_TX_TL, 0); return (error); } @@ -971,13 +975,6 @@ ig4iic_set_config(ig4iic_softc_t *sc, bool reset) (sc->cfg.bus_speed & IG4_CTL_SPEED_MASK) == IG4_CTL_SPEED_STD ? sc->cfg.ss_sda_hold : sc->cfg.fs_sda_hold); - /* - * Use a threshold of 1 so we get interrupted on each character, - * allowing us to use mtx_sleep() in our poll code. Not perfect - * but this is better than using DELAY() for receiving data. - * - * See ig4_var.h for details on interrupt handler synchronization. - */ reg_write(sc, IG4_REG_RX_TL, 0); reg_write(sc, IG4_REG_TX_TL, 0);