From nobody Fri Jan 19 16:33:34 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 4TGlYC2bp4z56rJn; Fri, 19 Jan 2024 16:33:35 +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 4TGlYC0x47z4576; Fri, 19 Jan 2024 16:33:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705682015; 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=sZreq9Kvu9UGuanlvWP8ykyl9rClQrTw76zr0r6P9SQ=; b=mIG5/N9tktfLXP2/I3mR08kFEEkEMoM5CZ9P+127anKhxCAdYQsDg3vF5RSGoY7jp++QCo WWOgVYf0llQ1X/0xYXOSPvtUY1pD7MaiGyqwOWZoA/57wOtmzRlm+pP2H847xcgxIVkzKr G7TfuV4BAMM1lwdLg5rb+OUdK532pMglY9r26wEsQv7UBe6eZGkGJ3bcv53PvUjeMXOYOL vkSaFcXe0NLPbGF56tfGk9oMZJlYXUn+EzixFXjvO0sIuwzRZzSLHMyD+ocC4rGoKegrcI 26EK3i4Z95Lco0yYjfZhf+bAnofkhCwalkIRbxCmGhaERuxmvwH5rxipCzuGOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705682015; 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=sZreq9Kvu9UGuanlvWP8ykyl9rClQrTw76zr0r6P9SQ=; b=AFRk1heo84/gUKtnNtKMOcsAlDjHWbWJKjA0EAddstml7vjxaZqYzMhoJ9CzOE2xhiOjkc pkhCH6sFyB4bMru3TFI/jmnNa5i8njUuPXSYNi1TPElmKgwmO1+imZuACC8J2hru8eigMJ Pyx7295jApGDRoH0YaQXy+bPE0SEebv/O5bWQLwCRHC95x02tJemkmYkyB797xAJWL/l0h BTSQkTA3Gl6L6MQ9WtsC0dtYFWquwyQvE92sVDjwo69rhb6lkwZ+UKTM4besgbWbTXUlEB Cr1PN0pve3No26UhxyAd5Yqr7hC1Cr+lTGUfezC2t9rQU2zXjcpb1eYJ3s4MFQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705682015; a=rsa-sha256; cv=none; b=kqjPM8+9VEG37yEEOIpS6kqEKz5uviKFvK/XRfo/aiILKiURnILgXZUcmIKYW/JEVTxlRg 8rGDbyG1r3VnwPwVVeKFEAxt5AUyceLcLpV1o6soqJpTNHPf8Gte9XI7e2NehBOI5QHie8 +2XuY25H9lqW3Mo0H9cOe4+3jK0atmBIBGqQkCCmLr5O2Lj0smIvN6xhQlMy5DNhh93N/3 xAI6v8F9pxQgloF0aGpDWfY6IgoRYrzRlx0armQV6ZyP1b/z/EIcjumMainlfDhZ+m9kRe qwT7Z0WLDjoETI6j0FLOdFfDaiCu0EzbQaTAjaDWGW060GKMvhNrC6p2NrkesA== 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 4TGlYC0150zyZp; Fri, 19 Jan 2024 16:33:35 +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 40JGXYSY025940; Fri, 19 Jan 2024 16:33:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40JGXYj4025937; Fri, 19 Jan 2024 16:33:34 GMT (envelope-from git) Date: Fri, 19 Jan 2024 16:33:34 GMT Message-Id: <202401191633.40JGXYj4025937@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: 60452092dbdf - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 60452092dbdf9c192dddd9b8d38feaa2b797c8b8 Auto-Submitted: auto-generated The branch stable/14 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=60452092dbdf9c192dddd9b8d38feaa2b797c8b8 commit 60452092dbdf9c192dddd9b8d38feaa2b797c8b8 Author: Alexander Motin AuthorDate: 2023-12-24 23:18:11 +0000 Commit: Alexander Motin CommitDate: 2024-01-19 16:33:10 +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 3a3271454738..749a39e25117 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);