[PATCH v6 1/3] i2c: xiic: preserve PEC byte length in SMBus block read setup

Andi Shyti andi.shyti at kernel.org
Thu Sep 24 13:09:22 PDT 2026


Hi Abdurraham,

there is still another issue here.

...

> @@ -546,23 +552,26 @@ static void xiic_smbus_block_read_setup(struct xiic_i2c *i2c)
>  			 * Receive fifo depth should set to Rx fifo capacity minus 1
>  			 */
>  			rfd_set = IIC_RX_FIFO_DEPTH - 1;
> -			i2c->rx_msg->len = rxmsg_len + 1;
> -		} else if ((rxmsg_len == 1) ||
> -			(rxmsg_len == 0)) {
> +			i2c->rx_msg->len = 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
> +			 * The HW needs SMBUS_BLOCK_READ_MIN_LEN bytes on the
> +			 * bus to exit cleanly: by the time the ISR reads the
> +			 * length byte the second byte is already being clocked
> +			 * in, too late to NACK. Pad the drain target and record
> +			 * the real length, trimmed back on completion so the
> +			 * PEC check sees the right byte.
>  			 */
>  			rfd_set = 0;
>  			i2c->rx_msg->len = SMBUS_BLOCK_READ_MIN_LEN;
> +			i2c->smbus_actual_len = 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 = rxmsg_len - 2;

what if rxmsg is 1? Before this could never happen because we
were checking for rxmsg_len == 0 or 1 and we were ending up here
for values greater than 1.

In patch 2 you fix things, but we don't want to have dependencies
between patches.

Andi

> -			i2c->rx_msg->len = rxmsg_len + 1;
> +			i2c->rx_msg->len = rxmsg_len + 1 + pec_len;
>  		}
>  		xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rfd_set);



More information about the linux-arm-kernel mailing list