Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2887140rwb; Mon, 15 Aug 2022 13:20:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ebZcrTMRAFBmr0+2m3FFqVll+0JfwG0Gg669fSmA+laJ5sKl+3PT9E+bidvrbiaxJKd8Y X-Received: by 2002:a17:907:9606:b0:72f:826d:21b4 with SMTP id gb6-20020a170907960600b0072f826d21b4mr11385540ejc.510.1660594803283; Mon, 15 Aug 2022 13:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594803; cv=none; d=google.com; s=arc-20160816; b=N50K/Jc6g7tOGmGaadHclte0T6fSA+bg7IVPn5ss1OYlezZJlI2Ahzy6odLYjUCE57 YiUwuxsX/954SOv0a4EC/YtJMcT+kfqpFP6SZs/mo0xHmTUGoNivZzQyMvWpFUN3xagn uHkRg8qs49AgsDM8Mhp8WM9AFDquSB9x3HK8Xd7V736UEmbfA3XgiUm1nzECkWqUBgNf 1IaRMKo7dseAwbZpGB+mJBAerYk0CA2I0Ne9kclRmZt8MjDciga7S9F03GJh3wgXFDOX cQk0hZMTXh7eJkzY4D6GKpv56mWPPc+Cs8YFmIR7QNgZDhGxlC7p4apk5JCAEC21kSxv JAfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QQXrGr2x6LoTGzttfUiRCwGZRc7xaXkOTscX7Jc05ik=; b=ytTnDkDVjXoaKg2lDQpTGq325sNPdD8Z5ISC5EZMuVsEvBfAs/gu9e+deNpsnavD5M xPjP4raDWnP5he1pZ9WAU/Yr7ZSLBQiMb6kP21nRfOQyAjyRh7jBW2MvgVURRgKypwCh U/HTtIze+Lgs87jpFrZjLQVaXxHwv8eUnmJUnYitWHrVINrrUcF/fgdLrX8dRaSi76UU VvWy2j67dRdTxVsJLZZUW7cuufnkWXcjg6f1UYPS8k/MjnRmghUdZNRuFVrIM+CjwvLk TrY9yI5cLcLS974DW3G0Do/4MBpe0U+ac8T1YsajBuQ3w1QobYrq1BkS4Y5jPANUJUGl 4O0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TGsnAQCW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ti5-20020a170907c20500b00734b422430bsi6389050ejc.331.2022.08.15.13.19.35; Mon, 15 Aug 2022 13:20:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TGsnAQCW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245512AbiHOTFs (ORCPT + 99 others); Mon, 15 Aug 2022 15:05:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245540AbiHOTCS (ORCPT ); Mon, 15 Aug 2022 15:02:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0B5D4D143; Mon, 15 Aug 2022 11:33:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 403C4B8106E; Mon, 15 Aug 2022 18:33:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 896F8C433C1; Mon, 15 Aug 2022 18:33:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588405; bh=vYKQ+tCX8WDdMfseVHQsF3kvwn3B0p/f7dOk+AcTaPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TGsnAQCWrQUjz3+/1poSwLls6us6OELeZcSbwY0P70YgoAUebtQiOg3MUDWcYEOif zHS465s+Fh75hzUOQqux6qPSkbS3+MkDYFkudECNuHJDhm0q/dQm7J/SFgoKrOPPRU JAP+Fzku8LZJ+IifGAxjv1K6t6rkAzh4tnzrniCI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Shubhrajyoti Datta , Wolfram Sang , Sasha Levin Subject: [PATCH 5.15 362/779] i2c: cadence: Support PEC for SMBus block read Date: Mon, 15 Aug 2022 20:00:06 +0200 Message-Id: <20220815180352.714268192@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lars-Peter Clausen [ Upstream commit 9fdf6d97f03035ad5298e2d1635036c74c2090ed ] SMBus packet error checking (PEC) is implemented by appending one additional byte of checksum data at the end of the message. This provides additional protection and allows to detect data corruption on the I2C bus. SMBus block reads support variable length reads. The first byte in the read message is the number of available data bytes. The combination of PEC and block read is currently not supported by the Cadence I2C driver. * When PEC is enabled the maximum transfer length for block reads increases from 33 to 34 bytes. * The I2C core smbus emulation layer relies on the driver updating the `i2c_msg` `len` field with the number of received bytes. The updated length is used when checking the PEC. Add support to the Cadence I2C driver for handling SMBus block reads with PEC. To determine the maximum transfer length uses the initial `len` value of the `i2c_msg`. When PEC is enabled this will be 2, when it is disabled it will be 1. Once a read transfer is done also increment the `len` field by the amount of received data bytes. This change has been tested with a UCM90320 PMBus power monitor, which requires block reads to access certain data fields, but also has PEC enabled by default. Fixes: df8eb5691c48 ("i2c: Add driver for Cadence I2C controller") Signed-off-by: Lars-Peter Clausen Tested-by: Shubhrajyoti Datta Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-cadence.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index 630cfa4ddd46..33f5588a50c0 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -573,8 +573,13 @@ static void cdns_i2c_mrecv(struct cdns_i2c *id) ctrl_reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); ctrl_reg |= CDNS_I2C_CR_RW | CDNS_I2C_CR_CLR_FIFO; + /* + * Receive up to I2C_SMBUS_BLOCK_MAX data bytes, plus one message length + * byte, plus one checksum byte if PEC is enabled. p_msg->len will be 2 if + * PEC is enabled, otherwise 1. + */ if (id->p_msg->flags & I2C_M_RECV_LEN) - id->recv_count = I2C_SMBUS_BLOCK_MAX + 1; + id->recv_count = I2C_SMBUS_BLOCK_MAX + id->p_msg->len; id->curr_recv_count = id->recv_count; @@ -789,6 +794,9 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg, if (id->err_status & CDNS_I2C_IXR_ARB_LOST) return -EAGAIN; + if (msg->flags & I2C_M_RECV_LEN) + msg->len += min_t(unsigned int, msg->buf[0], I2C_SMBUS_BLOCK_MAX); + return 0; } -- 2.35.1