From nobody Fri Jun 12 18:35:57 2026 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BFDB3909AC for ; Wed, 13 May 2026 10:09:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666978; cv=none; b=jkhWzp4WSBCIW6aZeGugBp7f6w8oNHhVh3f8oh6zUx06pOTlgwnb8aawUowueLbDAmrEnLS12b/JsvHC0pjVTWleyuHN/B/BcXPrRuwV/FVP8KTe9/t1c7UCGGdafDUHU375ny9jtRSIHKJBUqoWPRJWX5fH/GY/uQPLwu/XixY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666978; c=relaxed/simple; bh=vYE0xt5ladoi1dJg8uPeJA+CI0rDe1yUCtJxngY5Y/M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dLmSMNaxYRvvBZCp+8q6ZAQsbr8oaB1sCx1QdNxmVeD6Q/TT3HUqtO9AhJJqjKPEQTXoTXBakwMpgWGlmVC490l/aD55slDBP85VCB+unflHvkQgELFbEn3k+3ZyAd1nS1L6BmMkFqP2OoghE7Y3Qaq+qg0ub45U8o9EQp1xa+w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=brQ6bArV; arc=none smtp.client-ip=74.125.82.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="brQ6bArV" Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-13354eb66baso2430901c88.1 for ; Wed, 13 May 2026 03:09:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1778666966; x=1779271766; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=g7geQ29k+vP3kqRpnkR89osFPesRjCTgee3KdQw1Yk8=; b=brQ6bArVfLf/m8YTCIy08EnRdpGkcxGwHGtVm4ouTgT6ZrdR6cBZAUoX0+QZB5sTUe vWwBn1Wp0pmOOxtWA1oxQJb+R4r7dimQLsSaDRx7LxZoHu6d0kbcWk77leeGt2/wOCAF hmhq+x8AYZHzPn3FP/B728wM7ZgRyqr646U3Fnza9Lqb63HB++IphEkmK3p0ekeS2QoN 1X4xE2o5tj2XmZG9uoBIp2hyZjZWaBc1EwqstuzLAJijNDMrpDPGn3dlX2ZP2UzB/MIA bEM+ZW0MkjGkcjhHx8BuAYUZjaFaNC8AHLIc92VOSjtX7DPDvtUpnBXLPmDK7DeWE4ly 2d4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778666966; x=1779271766; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=g7geQ29k+vP3kqRpnkR89osFPesRjCTgee3KdQw1Yk8=; b=oarvfVOOPR24bBweloro1YZ6+F0g8BGMB+5vWOanezyxL66mKoW8hfumFRwNei2LzE pEUHKjbmB8saS16Vg+FOvleorSIMdiSS/DU3mIKjHuvblSxGao9WfeFH23GfzNf1acjW IinesOvwxTh3BNbumROEXNEPhFl9EWvA87p+4VHH+NpYzm3Brhayt6EnqClmcAR4kaBe RHHJQTzA+y4Jg0xo/FpH9pZG9pS5DK3ZirguyMa2xnX1WIT0ewP5F9eULHC22B6hw4tW tdqKb0120BtM8ylUzBPKOa1zc7t1aTLTPFf14jwBtToiQnqNg3oxVVUC6ir5PegvYArr Vv1A== X-Forwarded-Encrypted: i=1; AFNElJ/Kuu160ong4nQze0dzgm+sucZciRKK1vpP6m9s6JT2Kd74dcUTJp0Qwnw75KqXqa+bv0iDktXE+WgVhLU=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9r6YTciyUm4b4X6hBthj2PgTRbsn4aGerCEDgPfQloX7PJjjY D9qNgXWw3N8pmU918DvAGPoju3QVKecivrysOchEBmbIXmaQZaGrIgowrmKce/q7bv9RdEqrkm1 5GXyMUJ4= X-Gm-Gg: Acq92OGDuJ0KwOGJCodlEmSkp+8quuhiw+80UP/rkeMDuezQmTGap3156FPamyUjH4Q Fsl4YFPnoME+aNh9iR82tVD5aGw+pOboSX/N2jFHSoNoUTzjXf5yN2Zhsp6yGUiv+ILadMrdYje fxJ023SLC5ccHTiCqhxXXG6PNK/TGk3J7Be2L66PCR21QRqEO74PqT3MvjH9I6rcZdYH4E5VO0u rGqAH6F/gSkyHKzFOFPtXuphEP4NxCe/3gmiS3HhsflZ3Zt6AHeYIPDqiIoszVuXs8L7E8cRuSU 0jgOlasIIiwHqvTd9WhZflMOiOC6OvJNwY0QZCABTGI6qXLmaT9ER3NsU1V6t9HcXdNRHTawL0Z Jw7I4Y3J/WPdSpZ2P2mkppwS14nBYLwxVmksfvkfzNXsJIJWE1/EkaGQCcieAMmHhhzilUXKlGc ON8JOpcL1rRUUJvhs0uy8Uv/wSeJlcMGu3LHfY X-Received: by 2002:a05:7022:608b:b0:132:5d42:55ba with SMTP id a92af1059eb24-1343677c602mr1602360c88.16.1778666965951; Wed, 13 May 2026 03:09:25 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-132787673ffsm29430265c88.15.2026.05.13.03.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 03:09:25 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 13 May 2026 03:09:22 -0700 Subject: [PATCH v3 1/3] i2c: xiic: preserve PEC byte length in SMBus block read setup Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260513-i2c-xiic-v3-1-ccb3cf70ba03@nexthop.ai> References: <20260513-i2c-xiic-v3-0-ccb3cf70ba03@nexthop.ai> In-Reply-To: <20260513-i2c-xiic-v3-0-ccb3cf70ba03@nexthop.ai> To: Michal Simek , Andi Shyti Cc: linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778666964; l=5594; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=vYE0xt5ladoi1dJg8uPeJA+CI0rDe1yUCtJxngY5Y/M=; b=InRJ8GC47z6CGZfH6AUaiklz7fCO/eo9JoqVc/9hW/iT/SqSQac4WrJ16eBgP9B7Gq7DtEIT6 FVP2FJkUSV8DCTcrfX2MkSjTwNbTA9FOQxwRQ9xmYcaa16VTtjzz9fg X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= xiic_smbus_block_read_setup() recalculates i2c->rx_msg->len based on the length byte returned by the device, but historically clobbered the PEC byte expectation the SMBus core had baked into msg->len. That dropped the PEC byte from the caller's buffer on the normal and chunked receive-fifo branches. Compute pec_len up-front as (i2c->rx_msg->len - 1) and add it to the new length in every branch: - chunked (rxmsg_len + pec_len > IIC_RX_FIFO_DEPTH): set the drain target to rxmsg_len + 1 + pec_len. - deferred (small enough to drain in one fill but >=3D MIN_LEN total): same. - padded (1 + rxmsg_len + pec_len < SMBUS_BLOCK_READ_MIN_LEN): the hardware needs at least 3 bytes on the bus to exit the read cleanly (the second byte is already being clocked in by the time the ISR reads the length byte and is too late to NACK), so we still pad rx_msg->len up to SMBUS_BLOCK_READ_MIN_LEN. The dummy trailing byte that gets drained must then be trimmed off before handing the message back to the SMBus core; otherwise i2c_smbus_check_pec() reads buf[len-1] (=3D dummy) instead of the real PEC byte at buf[1] and rejects every clean zero-length block read with -EBADMSG. Record the true valid byte count in a new field i2c->smbus_actual_len and have xiic_process()'s RX_FULL completion site trim rx_msg->len down to it before clearing rx_msg. Widen the branch condition from the old "(rxmsg_len =3D=3D 1) || (rxmsg_len =3D=3D 0)" to "(1 + rxmsg_len + pec_len) < MIN_LEN" so that user requests with multi-byte trailing bytes (e.g. pec_len =3D=3D 2 on a zero-length block) flow through the deferred branch instead of getting truncated to MIN_LEN here. Signed-off-by: Abdurrahman Hussain Acked-by: Michal Simek --- drivers/i2c/busses/i2c-xiic.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index 3e7735e1dae0..d4308716d461 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -73,6 +73,11 @@ enum i2c_scl_freq { * @prev_msg_tx: Previous message is Tx * @quirks: To hold platform specific bug info * @smbus_block_read: Flag to handle block read + * @smbus_actual_len: For SMBus block reads padded to SMBUS_BLOCK_READ_MIN= _LEN, + * the number of bytes that are actually valid (length byte + payload + + * optional PEC). msg->len gets trimmed to this on transfer completion so + * the SMBus core sees the real PEC byte and not the trailing dummy. + * Zero when no trimming is needed. * @input_clk: Input clock to I2C controller * @i2c_clk: I2C SCL frequency * @atomic: Mode of transfer @@ -98,6 +103,7 @@ struct xiic_i2c { bool prev_msg_tx; u32 quirks; bool smbus_block_read; + unsigned int smbus_actual_len; unsigned long input_clk; unsigned int i2c_clk; bool atomic; @@ -539,6 +545,8 @@ static void xiic_smbus_block_read_setup(struct xiic_i2c= *i2c) =20 /* Check if received length is valid */ if (rxmsg_len <=3D I2C_SMBUS_BLOCK_MAX) { + unsigned int pec_len =3D i2c->rx_msg->len - 1; + /* Set Receive fifo depth */ if (rxmsg_len > IIC_RX_FIFO_DEPTH) { /* @@ -546,23 +554,30 @@ static void xiic_smbus_block_read_setup(struct xiic_i= 2c *i2c) * Receive fifo depth should set to Rx fifo capacity minus 1 */ rfd_set =3D IIC_RX_FIFO_DEPTH - 1; - i2c->rx_msg->len =3D rxmsg_len + 1; - } else if ((rxmsg_len =3D=3D 1) || - (rxmsg_len =3D=3D 0)) { + i2c->rx_msg->len =3D rxmsg_len + 1 + pec_len; + } else if (1 + rxmsg_len + pec_len < SMBUS_BLOCK_READ_MIN_LEN) { /* - * Minimum of 3 bytes required to exit cleanly. 1 byte - * already received, Second byte is being received. Have - * to set NACK in read_rx before receiving the last byte + * Hardware requires at least SMBUS_BLOCK_READ_MIN_LEN + * bytes on the bus to exit the read cleanly: by the + * time the ISR pulls the length byte from the FIFO, + * the second byte is already being clocked in and + * cannot be NACKed in time. Pad the drain target so + * the HW reaches the minimum, but remember the true + * valid byte count and trim msg->len back on transfer + * completion -- otherwise the SMBus core's PEC check + * reads the trailing dummy byte instead of the real + * PEC byte and rejects clean transfers with -EBADMSG. */ rfd_set =3D 0; i2c->rx_msg->len =3D SMBUS_BLOCK_READ_MIN_LEN; + i2c->smbus_actual_len =3D 1 + rxmsg_len + pec_len; } else { /* * When Rx msg len less than Rx fifo capacity * Receive fifo depth should set to Rx msg len minus 2 */ rfd_set =3D rxmsg_len - 2; - i2c->rx_msg->len =3D rxmsg_len + 1; + i2c->rx_msg->len =3D rxmsg_len + 1 + pec_len; } xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rfd_set); =20 @@ -797,6 +812,17 @@ static irqreturn_t xiic_process(int irq, void *dev_id) =20 xiic_read_rx(i2c); if (xiic_rx_space(i2c) =3D=3D 0) { + /* + * If the setup path padded a short SMBus block read up + * to SMBUS_BLOCK_READ_MIN_LEN for the HW exit + * workaround, trim rx_msg->len back to the number of + * bytes that are actually valid so the SMBus core's + * PEC check reads the right index. Must happen before + * the rx_msg =3D NULL below. + */ + if (i2c->rx_msg && i2c->smbus_actual_len) + i2c->rx_msg->len =3D i2c->smbus_actual_len; + /* this is the last part of the message */ i2c->rx_msg =3D NULL; =20 --=20 2.53.0 From nobody Fri Jun 12 18:35:57 2026 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18C373939B5 for ; Wed, 13 May 2026 10:09:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666983; cv=none; b=aPHaDQUU2385ncGFBRcBjBhVfyApXcyi68tPAGDf7HS4FOGIH8Fnl6ZTWCOZHXCcE/Vgr4fdHrF2TtSqWq5JhX9I4ZG8ATIJdAm+LHOzdl5Nx+7t/3yJEN0RI2u1ch0gL6nUl2JwPkAyzwtMmRC08q9S5Jy/Oi8a79vEondAvCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666983; c=relaxed/simple; bh=IcTTcY79qLYulJ6DtpHIU8j/lmilEm/EM7tnCfD/M8w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=swedBBhCt1RVZuzb6XO3Ox6F8tAiMEwgA8kFfZEN2sF8ssGoV6aO/yyrXa+WXQRqi90xejRmuQswzgBpU1TLtn/0wwqyH0Eg4zxZJh+toVpYAkbCRDJ7G9OWhAbHNYm8qOdpwq1kt7EbFIQVewhrGdjValovEl0oMvBrc1ivwHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=AO/z7VQL; arc=none smtp.client-ip=74.125.82.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="AO/z7VQL" Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-1329507c387so4386393c88.1 for ; Wed, 13 May 2026 03:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1778666967; x=1779271767; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=tMy1R3v8/cknJGc/Ns+zpumuALOM+zMl+dD92JAI70U=; b=AO/z7VQLoF5Ai3klzgi+FIjvtnULOh9mlYAP7q8PIAUX7RcrZrpaA/8s8pxhfQXEA5 oBC49e9rGrEwLuaagoZsjIX4m/kSlmIlnkjXMNgsIu0OblWmj6MbD63p4MPJRk+j+Z3L NJsWhDaoUta6b4Hm3+JgJS6tRoDJe0oNbJpuThi3liuDNH8b1m5l6ZZ8l1kPt1v3YoCS FHwM0fS43UxCAY4Hljz9umgXsfOkc6jfJcYkpnu1F3JSnoCNK21l9gfy/Qywqm8VHcLj 83atKQiox+MVRYAl/IXociBKQbamECNAMXtUZrf8tmxSGDSRXTx7qko75/jNpUmg+ug5 PkjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778666967; x=1779271767; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=tMy1R3v8/cknJGc/Ns+zpumuALOM+zMl+dD92JAI70U=; b=H88xmYSAaAcekDV1+zhezIatN4gjm18OcMsyoHybDpDnutbp1Ql9A9PZPurv+/gO5Q mM6PGGFdcTP9TIsPJBbjcLEabyIra609Asg4ni0KpNcGwW6UZW8IBcUuGzHGvC51mNAR G7C4KkFQ4y7yT7Mu22kk2pC+/MMktlffJaGKJM+8Uz1hDIDEM0qEKsKS1mA7iVryemwD wDBR068i/ekk0d8i7BFnYOZ4383Io4DZifMTS+dFeIOovYIbDm94GIDseA/RvtWRgEi3 eLNLZhNNjwlccMY1px1bquxTWDL9hJD1gevB7dwbTMgwX2owOdBPLwBieS4lTSAmC4wx EZhg== X-Forwarded-Encrypted: i=1; AFNElJ/rF0cDEozYqzg3FZsjLHiucSaNuN17BiCsC79GEwsSHX1meZJgcLYcvs/SeIqHncvAkaPBW+pdzqynric=@vger.kernel.org X-Gm-Message-State: AOJu0YzBO1ifcPhDbJLTWrQ9S8aeoZxKQpmH8PM6kK+yESgY4dqhK9D6 NVZs7my48LNVre9pKFrUIFvXGX6ctC1a9dOlkFsVU13jyqC07E2rNTP66cMbXLA9frM0buyNKSY 43a6etLU= X-Gm-Gg: Acq92OFb9m7Mucn001BglV895ysDnCF6BpUQGugtfG7XaT3aUJp8wJGBA7M8NC1jq4V y/PJztDBw/LpbsQf1Yue++n2/xpVSjc86LEe3X2BDYAKMH6zTek2oOmfs5OyjFUvQemAtaWlEBp WRg4jQ/r9LamLEqJ7/aHjDCTXFyUufu27R998yQIMSEIWPs9PmfztgyWmu/Zlyqo+T59YRDFnJY mcw+wnllCWl3H2i8J5jFPfbQWq5DY6f1HeLP+YRkANLRbQl1RbmtZsf9V1PVA5jyzZ5O6MAWLXC fwb4Dlt4dgyDV/7fN/Xw95PY9NUO/Q60owc8kd1iQTn9RH3iRYgESQZs6+e0Er5Cl6BtKadReat njn5Xg713ajGPsadImsujemnkfyxk8UHgG1CwbeejTzuGu5laAkdQ4mXm/g9BvKnBrnbRYKVHBk pJ0agXEF/UTiZRtcPw1a/r2KV55A== X-Received: by 2002:a05:7022:221a:b0:11b:1c7e:27d0 with SMTP id a92af1059eb24-1349a1371cbmr1363410c88.0.1778666966786; Wed, 13 May 2026 03:09:26 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-132787673ffsm29430265c88.15.2026.05.13.03.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 03:09:26 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 13 May 2026 03:09:23 -0700 Subject: [PATCH v3 2/3] i2c: xiic: defer RX_FULL until all trailing bytes are in FIFO Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260513-i2c-xiic-v3-2-ccb3cf70ba03@nexthop.ai> References: <20260513-i2c-xiic-v3-0-ccb3cf70ba03@nexthop.ai> In-Reply-To: <20260513-i2c-xiic-v3-0-ccb3cf70ba03@nexthop.ai> To: Michal Simek , Andi Shyti Cc: linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778666964; l=2850; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=IcTTcY79qLYulJ6DtpHIU8j/lmilEm/EM7tnCfD/M8w=; b=8UzUUME/YlH55KnDDiPY7DoH5eRhIrJtdDWJN+ZdsYZdmJv2TNw+RDEb56gmi96+eB4cGHrvn NcNUmEzIP1QCKmqoa4Ww1l2y7NtSLi/b4E649DTiFNOGaoW5qwoQjrC X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= For the normal path of xiic_smbus_block_read_setup() (rxmsg_len less than IIC_RX_FIFO_DEPTH), RFD was programmed to rxmsg_len - 2, which fires the RX_FULL interrupt while the last payload byte is still in flight. xiic_read_rx()'s bytes_rem =3D=3D 1 branch then sets NACK on that byte still on the wire, truncating the read in the PEC-enabled case. Raise the threshold so RX_FULL fires only once every remaining byte (payload plus optional PEC) is already buffered in the FIFO. That routes the drain through xiic_read_rx()'s bytes_rem =3D=3D 0 path, which reads everything out and emits the stop cleanly. For the non-PEC path the full payload is still read out through the same bytes_rem =3D=3D 0 branch; the only user-visible change is that the controller waits one extra byte-time before servicing the interrupt. The deferred-fire formula is rxmsg_len + pec_len - 1, and the RFD register at XIIC_RFD_REG_OFFSET is a 4-bit field. Widen the chunk-vs-defer guard to (rxmsg_len + pec_len > IIC_RX_FIFO_DEPTH) so the boundary case rxmsg_len =3D=3D IIC_RX_FIFO_DEPTH with PEC enabled cannot write 16 into that 4-bit register; it routes through the chunked drain instead, which already caps RFD at IIC_RX_FIFO_DEPTH - 1. Signed-off-by: Abdurrahman Hussain Acked-by: Michal Simek --- drivers/i2c/busses/i2c-xiic.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index d4308716d461..2bdba6c0931f 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -548,10 +548,11 @@ static void xiic_smbus_block_read_setup(struct xiic_i= 2c *i2c) unsigned int pec_len =3D i2c->rx_msg->len - 1; =20 /* Set Receive fifo depth */ - if (rxmsg_len > IIC_RX_FIFO_DEPTH) { + if (rxmsg_len + pec_len > IIC_RX_FIFO_DEPTH) { /* - * When Rx msg len greater than or equal to Rx fifo capacity - * Receive fifo depth should set to Rx fifo capacity minus 1 + * Trailing payload (data + optional PEC) exceeds Rx FIFO + * capacity; drain in chunks. Fire RX_FULL when the FIFO is + * full and let the ISR re-arm for the remainder. */ rfd_set =3D IIC_RX_FIFO_DEPTH - 1; i2c->rx_msg->len =3D rxmsg_len + 1 + pec_len; @@ -572,11 +573,8 @@ static void xiic_smbus_block_read_setup(struct xiic_i2= c *i2c) i2c->rx_msg->len =3D SMBUS_BLOCK_READ_MIN_LEN; i2c->smbus_actual_len =3D 1 + rxmsg_len + pec_len; } else { - /* - * When Rx msg len less than Rx fifo capacity - * Receive fifo depth should set to Rx msg len minus 2 - */ - rfd_set =3D rxmsg_len - 2; + /* Defer RX_FULL until all trailing bytes are in FIFO. */ + rfd_set =3D rxmsg_len + pec_len - 1; i2c->rx_msg->len =3D rxmsg_len + 1 + pec_len; } xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rfd_set); --=20 2.53.0 From nobody Fri Jun 12 18:35:57 2026 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B72CC394E93 for ; Wed, 13 May 2026 10:09:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666986; cv=none; b=nCfqzXdTE6VCxqiVXSmrPyMPEIPwx4jjvIae5Lp+d8J7GBFojQRaeIMQT/XfoyyNxg2QDUy8fgDkRHhyahBf5W5KGsSiI/kZnUwjiCXTC/FWIm7/Yc1yCuv4MsptJI7895beAJB42+pV0+bTXGjA3FY3QrNvMIGYTauRjH+OkwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666986; c=relaxed/simple; bh=WXSe6TYxSA7cz0PPKHt43EUa98Bkkw8i7qMhYy8i0xs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZyYqeHdI/kehXA6BFfI3CQ+M3xRkbSP8I4yxwIzte9OS9XhMLWu+BWquopSbhliWw1UwuHvGPPGq0dAHXl1RQorTDaAKqktwdGW/s+0i7bV4zhPc92vbjar1y2fq+v+xjo9CuotPBCTaCRHI0i3IgcOW/x40soXr0pIcFRMVF30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=lEfbOyct; arc=none smtp.client-ip=74.125.82.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="lEfbOyct" Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-12db2e415a7so4617255c88.1 for ; Wed, 13 May 2026 03:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1778666968; x=1779271768; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=w8Lg0hsn02D6K83qdccj9lMg9u6Gq5mDY/7w097Ma/I=; b=lEfbOyctJ0RpVtHm7BMAMnR65q/sSl2sURS+aH/dziXNYI6Y1Qxgl4/8MqOvrOzxD4 I+KJWCvINiLvxifkx/uSPvJwGDtHVqKpN6A0u1PM0bQ6wAUvtSsQNQC6eVmncstK+m5Y vQIIYj30C3730Rh7rkU8L+F1HJivfbWMnzg24FKavU6dalljuHAj6hsk2fAMOBuKbDjQ BZ9s2CIbvptXguq1yoZ3ZyVCJRRFozRMaGFJJH/9rDHa5n1wTpvTsKEcLy5zcWsOC234 rPoKsqRqXHy3lWzHfT/bJygStSJTqoo0oeeQ251Ak1Y5DYoPKqrI2kHMm424jPFoPh0/ FeWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778666968; x=1779271768; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=w8Lg0hsn02D6K83qdccj9lMg9u6Gq5mDY/7w097Ma/I=; b=pLfFAax4D3wD4LlJHQLyYs9tXVYarl/HtmQOrofyWGhkEsA8G11Ahm6ZXPKKDqqICm OxGiUYP97jlMuNsgVeplroRKsgoFtkz3GtlN87GRIJjHLgqcZC4Dbr/SYpI9H9jA665G YyfDGWfAF3w70hYTJN7+Uc3WmOmVyMnkWGl6nH0MaC1sjtk7XQh3DsaeHIyCMElMlJTE iotlhGby7vs07oYGzViCCDL3op0V514yfh2B1vO9D8NtrNdA6vGxoeH6zkUIWhIMc7PR f/aLrb4C4l/n/H+4XAiNsI7MvrXhWKVqKVj0BQuUdX/N0icHmYKEiSediKdRxRCK35Si Gxug== X-Forwarded-Encrypted: i=1; AFNElJ97EZLfS/xS9rv+iBcw2Bm7aXwZxN8bO4uwFrHpsn8xU/+VTgMmFXqJRZ9amKDAQ3shxcTZzeQ77bD1pUQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yxc3soct4cVnszp/O91rLiE/tURTr+QH0jPKG5jaXsDXYsmjUoJ w3XCL6j3FGQKZWL9dBGpyw+rZEyCX4qwzOLwuzxjktjQv6Hy028RbpUZa6He+J0OkBISXlA8qFD Btzev80E= X-Gm-Gg: Acq92OHMWEJt7qjENh3lDgujCyr24AXr1GhnFquY5FgQXPyIWiuYFfO10u0N5zc47i9 xND7oEBjDl/3nIxfc5Y/07+Ump7uMAYsM1IaGnFQgfE2N1oRQ20Ieu+VlgPAFWnJLdUTATu4BYN LAyEdeFAaW5Hik0frc2RHW+h8Onzg+HSHyPd9QjRlXW7FrfNh/1v6LTNMNsdtRcsWnXc+2LP0Wa sbrSeQV1B/VGI4FIl+O5uk2HP1K8TCaWCmpeMC8/V9+lunjeNho2uG7F/BAgc0cz277OyxGSM4Z 2ClmsLqkFcoSAF9P8i6CsA7Jztrz09/Hg+5nxJYLAH4zxL6AtRaDcEs0kKV5g3xGfFASRNjuoSs R1/Hrw5CIWRf1buS5yHuHPSVJOA7CN9mLRGpYMOgzzq2hHPiJFrDO2stvd45UlPzujzZvXCNn9c qogqKzBHTQDOb+ziUE2klmchQeEw== X-Received: by 2002:a05:7022:6708:b0:12a:6c4b:9cf0 with SMTP id a92af1059eb24-1349a703b16mr1350615c88.3.1778666967710; Wed, 13 May 2026 03:09:27 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-132787673ffsm29430265c88.15.2026.05.13.03.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 03:09:27 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 13 May 2026 03:09:24 -0700 Subject: [PATCH v3 3/3] i2c: xiic: don't clobber msg->len to signal block-read completion Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260513-i2c-xiic-v3-3-ccb3cf70ba03@nexthop.ai> References: <20260513-i2c-xiic-v3-0-ccb3cf70ba03@nexthop.ai> In-Reply-To: <20260513-i2c-xiic-v3-0-ccb3cf70ba03@nexthop.ai> To: Michal Simek , Andi Shyti Cc: linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778666964; l=2230; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=WXSe6TYxSA7cz0PPKHt43EUa98Bkkw8i7qMhYy8i0xs=; b=WGfE3HlylYu1y1xmIHtQZzvpw9th09pMwA0Y4vyVl8BGkwjAtyUp96PqN67x0uuiupEKbK6oz R0jz1Y0juSGBFyB35Ui/ugENU02Y5ivWGOV0+/Ggo071jjetC7yVmGJ X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= At the end of a SMBus block read the BNB handler force-set tx_msg->len =3D 1 to push xiic_tx_space() to zero so the STATE_DONE branch would fire. Two problems: 1. tx_msg and rx_msg alias the same i2c_msg struct during a receive (see xiic_start_recv), so overwriting tx_msg->len also changes rx_msg->len. The i2c core's i2c_smbus_check_pec() then reads the PEC from the wrong offset -- buf[0] instead of buf[rxmsg_len + 1] -- and either mis-validates or returns -EBADMSG. 2. xiic_start_recv sets tx_pos =3D msg->len (typically 2 when PEC is enabled). xiic_tx_space() is unsigned msg->len - tx_pos, so setting msg->len =3D 1 with tx_pos =3D 2 underflows to 0xFFFFFFFF and xiic_tx_space() never compares equal to 0 -- the STATE_DONE check falls through to STATE_ERROR, giving -EIO. Instead, advance tx_pos up to msg->len. That drives tx_space to 0 without touching msg->len, preserving the buffer length that xiic_smbus_block_read_setup() already grew to cover the length byte, the payload and the optional PEC byte. Also clear smbus_actual_len here so a subsequent non-SMBus transfer does not see a stale trim value from this completed block read. Signed-off-by: Abdurrahman Hussain Acked-by: Michal Simek --- drivers/i2c/busses/i2c-xiic.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index 2bdba6c0931f..8eaa411411c1 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -889,8 +889,17 @@ static irqreturn_t xiic_process(int irq, void *dev_id) =20 if (i2c->tx_msg && i2c->smbus_block_read) { i2c->smbus_block_read =3D false; - /* Set requested message len=3D1 to indicate STATE_DONE */ - i2c->tx_msg->len =3D 1; + /* + * Defensive: reset the per-transfer trim state in case + * the rx phase completed via an error path that + * skipped the trim site in the RX_FULL branch above. + */ + i2c->smbus_actual_len =3D 0; + /* + * Drive xiic_tx_space() to 0 to signal STATE_DONE + * without truncating the rx_msg length. + */ + i2c->tx_pos =3D i2c->tx_msg->len; } =20 if (!i2c->tx_msg) --=20 2.53.0