Received: by 10.223.148.5 with SMTP id 5csp6917929wrq; Wed, 17 Jan 2018 21:42:02 -0800 (PST) X-Google-Smtp-Source: ACJfBossfEuI2GuWlbNKbB8vIzFJwBgguJFfgLM3Bw+3//7YeahJVbfCbbyU2ea/PSjWrsrvBseZ X-Received: by 10.98.204.75 with SMTP id a72mr32257039pfg.211.1516254121898; Wed, 17 Jan 2018 21:42:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516254121; cv=none; d=google.com; s=arc-20160816; b=AhZUPuTOgw1IKDhqNWl0Km8zI/BWo2HNqIzkJ8AKw9GaeQSMMzStxRMTMkvC7GDE6y 1FgAi2rO4xxUCF5E/69E1sB0LRmdTx7AmwxmyhOpzhzLXrn9GlbV3pekZo+QJUwwI9f1 aTOUFjqwF+Sosvrd6YBlD/Uw9gsvmcUMgTOXsD+ZhZbEHHKY3n04fdbxSJubB4dOOoTu 41DKrYvdOysnLBloLNBul1WfPQI37CAIdltQhpuWIOG9Fc/9D80k3Ca6tIsCG4b/DfOk qPgsWc+Sm9GvzQs8TwisIxl/pEh4NYVgOzaZ1/+zqqICCSIgtBINW8TVb+Sd8vFicHU3 ZhEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:arc-authentication-results; bh=BKkmC96OKb0xsLWEREPa5BRKHjWlZAxlAa55pCpooHw=; b=NTz3Z7bUCVeKfL1V2CRkkv4fGdIhpHM0BX36vBfEPVT9wgpOf59Ij0gwZLsA+ZA/r1 oVBiKQyXpuShEcMveW6wzPd1dr4qs6VtJKnbM/M7o6TuPdCj7v3Kk8xOH+yEum/sgHV/ NLqmxkiEVXNNxWykDQ8TI2amZCmycMUYdfQiEtJhKDMj0jZ2yoYB/pmUmhESxCYnE6dm s8/y2xpB3D5Grd6jnTrxjmLopEe5mL9sciOrB3SU9Z5aNUm/ge842h1wzQFfaGIkZ8OW Q0IRoIHXVjcVZNTorlGGXHn+cWxkT/Xvwo14KTZWPlPMCBBGV8nm1FXWhMqaeJbuvO58 nOzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=NMf9SZmg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si5318108pgc.108.2018.01.17.21.41.48; Wed, 17 Jan 2018 21:42:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=NMf9SZmg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754688AbeARFkm (ORCPT + 99 others); Thu, 18 Jan 2018 00:40:42 -0500 Received: from mail-by2nam03on0078.outbound.protection.outlook.com ([104.47.42.78]:53632 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753433AbeARFj6 (ORCPT ); Thu, 18 Jan 2018 00:39:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=BKkmC96OKb0xsLWEREPa5BRKHjWlZAxlAa55pCpooHw=; b=NMf9SZmgwx9sWmFvDcyWHMKX0DKpEyRvMZuHb9u0pd1q8c/LRZ2MFPKqh4OAzVhUNUdL216rC/WQ+zeRrefjbBRiI7ce3TghR94zT6QJ0xqFfkQpewlY9ZoKgy5R2eWP0mxrclGwP/F7u2sfCQWYDwdhJhN3N+lE9CYyrQkuE7s= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=George.Cherian@cavium.com; Received: from ubuntu.caveonetworks.com (111.93.218.67) by BN3PR0701MB1703.namprd07.prod.outlook.com (10.163.39.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Thu, 18 Jan 2018 05:39:54 +0000 From: George Cherian To: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org Cc: wsa@the-dreams.de, George Cherian Subject: [PATCH 2/4] i2c: xlp9xx: Handle transactions with I2C_M_RECV_LEN properly Date: Thu, 18 Jan 2018 05:39:22 +0000 Message-Id: <1516253964-4615-2-git-send-email-george.cherian@cavium.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1516253964-4615-1-git-send-email-george.cherian@cavium.com> References: <1516253964-4615-1-git-send-email-george.cherian@cavium.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BM1PR0101CA0047.INDPRD01.PROD.OUTLOOK.COM (10.174.221.33) To BN3PR0701MB1703.namprd07.prod.outlook.com (10.163.39.157) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 05f0dddc-30ab-4166-e2c2-08d55e35e7db X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(4534125)(4602075)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060)(7193020);SRVR:BN3PR0701MB1703; X-Microsoft-Exchange-Diagnostics: 1;BN3PR0701MB1703;3:4c4cERybDZ3kf/LFpBIwfqoVwaXjZwXfSMD2KN1UQZCwYhoK5tgQJQQ1Q50EVGEQW8SJLMw4vJ6kNETCr4aNGjM8woZ2F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rQ3vy1xjUfB6svXm4S0HjT2X2orZNIG5DAcI01DPlQjYgbQh2xUp+BF9jhDUhHdRkui9xCldJYJJWZNv1OXKyvrgWREFzBr2gYOATJWcx4ngdk6at4JJYVG26E1iveeRaQ79E1Epto/o7xc4YvbWCBtKeydzQhtlP+vgH7S6aDO+crlR7e09pIIxGxMiZt92fINihsgXKpKFElYiwJP/RyAch0T1DKmgWp5VWfv8wBjnGACnLn53;4:nyN5B/LNh/jrT161AuwAb8ZQq0EY39OTuY+I/yJ59R/H5kzrpS0Ot7KWNXolM0JpGDF0aUt/9BDEaec2mK+d0/IF0Fr7k1Wu56W4DIruQxdNcbfQ8/z+CPqBDN3yoPJBXPm5k8WcNh65hF+wAeLN4rj4POSOeeijHCpTbcepSuT2zOlRZ3UA6rmxOOzOK9BC1Q42FnYrbKhMybOwv1jXmNWHykDrf9q6SpwsjZrPnx97a0xAAHBJk6rVGOLgL5Rp7N5gHvnmYqmrRnn/CfTPwQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231023)(2400056)(944501161)(10201501046)(6041268)(20161123558120)(20161123562045)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:BN3PR0701MB1703;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:BN3PR0701MB1703; X-Forefront-PRVS: 05568D1FF7 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(39380400002)(396003)(346002)(376002)(39860400002)(199004)(189003)(107886003)(6512007)(316002)(48376002)(53936002)(97736004)(69596002)(25786009)(86362001)(26005)(7736002)(478600001)(16586007)(6486002)(72206003)(6666003)(2950100002)(106356001)(3846002)(53416004)(8676002)(81156014)(81166006)(105586002)(5660300001)(305945005)(36756003)(6116002)(51416003)(59450400001)(50226002)(6506007)(386003)(47776003)(52116002)(68736007)(50466002)(5009440100003)(66066001)(8936002)(4326008)(2906002)(16526018)(76176011)(551934003);DIR:OUT;SFP:1101;SCL:1;SRVR:BN3PR0701MB1703;H:ubuntu.caveonetworks.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BN3PR0701MB1703;23:VtgzV3k/XoNap1Tsmxia9V0lCrxNygpjBINLsb0?= =?us-ascii?Q?ue5UWyOaLzEr8VoBYcwJz4Lh85ViYp5CCyVF3dOvmI1XsmrAKbrUmNStmxA4?= =?us-ascii?Q?Dvh7Ff8eac4L8gu2LCuGHTz5zdFwj2exy+O+2cyWrVfLYXcUeERXhu/Kunjk?= =?us-ascii?Q?0Fgwxu3PstK848ygBQL0Z+AXd0sjYuFPgi5pRElIznecpmeVKL8cGmTkSnuU?= =?us-ascii?Q?R0uSZ4ix79bLw0HQRpN1C/6nIHYqdcFYcg1Glg7/ZHe+mUG6KeqRvv3ilIbN?= =?us-ascii?Q?V/wiFQmbkLZAfWmNI7tI2jhAzqcVuUQXpYO4STQigEhxGrAnDx2Oxnk/mhHA?= =?us-ascii?Q?vlFmLNfAVmQ7/JmR6MwF8wLWxWDl6z9CrXyZS7t+WRQtryilHqhxD058H9hD?= =?us-ascii?Q?EnqFEUcFKiBupsD9uSTV4Sf056kEPR0vOsc+ohBxT8PjFmrj73OOe8t0xUi4?= =?us-ascii?Q?d5t6NqolBZDKelzd4YoNeyWgSODIjUKKkF/+2MZX5RW6/H96kx+3kUgD3xFU?= =?us-ascii?Q?R8Y1H/mJBnhtvTop9Ll1CgNbCbW18peUUCQw//N6icTNncHfV4f9m7iPiZBV?= =?us-ascii?Q?Ldq9ou7P2WzDIzB94ffY9Bn7ppCa2zs8Ycf6pjXptVhniBpTUzePSi/TANYy?= =?us-ascii?Q?y0DNyME83WiP930cGkfL5W27OWbztp1CYdqG8mwCSfijHlzJ5rgqRbSb+NjW?= =?us-ascii?Q?8rlMbm3/rtUPCu3hhguB3dPeDH13tySqJx/Wekk/b65t4/e4kXok6uCN52dx?= =?us-ascii?Q?edLutAo6fR+jA3rlpff7jH4Yu78owdnisrO9Pt91+i1N1NVXnncTQMFaDpFS?= =?us-ascii?Q?KIP4JN832J5vprRQtI0M6ZvIX2lCqI+48oKhrxU6vm/lRL35G8yern4IUwM7?= =?us-ascii?Q?BwdmcHBPPx2DfBRWq24XendpgUontfHwFFGK/zDooeMYhZaJa5sw7bIInA3B?= =?us-ascii?Q?FARmnGNUymcDVDDfWBufXqRWlpjlVy4njXs7rQ1+FKCe2DonkaJbaD5c9fxG?= =?us-ascii?Q?4KRF3NETHGxWC1rCiQC33xlKtAivmtZCN8/2Rp+kRFPAxpTYnd4KFbKcZxC/?= =?us-ascii?Q?UbWs2y8eXXL4PXX+16GRhVJAYOJrUVqvAJCQhzP/P4QDFb4RRGTQjNwNniI0?= =?us-ascii?Q?EOiHu5MeF70Qfnvit2l0Akmw08v+8aAuf91/TmqYflSnihdR0wQaufNLa33u?= =?us-ascii?Q?tQ42voZBOcFP+q9T6fTq0oNmJqn4V5Vh3iax00mSb7tsAznMjGZsahD9cGA?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;BN3PR0701MB1703;6:+WXaacATF0GpVBErEQtVlY54aMhm02gHI5iWjfnu/xwTMiDfCYCEb4HrbEprkATJAuSl4omYJ28Bo0DR3P/sSXYfkSEYDRSEq7aRi7H00sSlK38VWLGigGxZ4M4EKfvKZZVmoCIMSwpR4HOBy1e/gQVzXTCOuDzhqlTYnOH+ev/b3XS1nRGv2K0BzFGfSYUcPP8n0eZb57KDE9xBYx/Eqr8/ftmmzA7Rh3Di4IcJWZjQ7U2SPxNZ+F7woDHbWnvVswicFPFq658KL7q8AUToZZQwqnYDxYpBhwx6bYW0kz5yfUQLnT7hF9i6Rh8yBORVanhA8t8qXyX7eNwAX5s4U1GKH6Yc3dYbBxgm0jvoZQ8=;5:XAwFi2mZ+2soSbriB1K0+0zfIEaxmPSaQbsg8CoKlBfxrh6eKjFuSmMcSX5hxzhgswqUFj0chytXic9sspEwqp+RsRkGDvMehaPHZJJWS3J0X2rAmP7fXzOnDekjqxizz05QwuyKa9turECIv4ARtY/T2o5wLm3OSlM/GDJ8L5w=;24:g+Z8oXHEFg2VzS8GUb6uZryebXpRdBXPi/Dgr2UoG3uSpuC7asjpAx9Yg5+uCSia2m8j6LAWLjKCL2x8L9D8yZIRrN+FbB5sc2WcGOYAs6A=;7:wQQyK4FAb/YZ3GRdRLf1WunMv4G83NjMbnVouQulv4NP6Hvgc73ph4bwxierxRcYbH3FWSBVm3TVrsG3GMUhNxgPRvtnQjn8id+Yell338qTDCchVN++TxK5FJUE8eZLWSE5qg9qkaR422RfOIzqm+v6YBnFqVbKujte9kY7ra57ZLH03FIoduXluxMPT87Hc3B23OSVr9VF+lCc5sGzFr7E2Bc7Y+HPfEpQ0bSLdfI+wIzQJt2AiXx87c2DjA8q SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 05:39:54.5423 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05f0dddc-30ab-4166-e2c2-08d55e35e7db X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR0701MB1703 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case of transaction with I2C_M_RECV_LEN set, make sure the driver reads the first byte and then updates the RX fifo with the expected length. Set threshold to 1 byte so that driver gets an interrupt on receiving the first byte. After which the transfer length is updated depending on the received length. Signed-off-by: George Cherian --- drivers/i2c/busses/i2c-xlp9xx.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c index 6d78cdc..b5b224e 100644 --- a/drivers/i2c/busses/i2c-xlp9xx.c +++ b/drivers/i2c/busses/i2c-xlp9xx.c @@ -125,7 +125,16 @@ static void xlp9xx_i2c_update_rx_fifo_thres(struct xlp9xx_i2c_dev *priv) { u32 thres; - thres = min(priv->msg_buf_remaining, XLP9XX_I2C_FIFO_SIZE); + if (priv->len_recv) + /* interrupt after the first read to examine + * the length byte before proceeding further + */ + thres = 1; + else if (priv->msg_buf_remaining > XLP9XX_I2C_FIFO_SIZE) + thres = XLP9XX_I2C_FIFO_SIZE; + else + thres = priv->msg_buf_remaining; + xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_MFIFOCTRL, thres << XLP9XX_I2C_MFIFOCTRL_HITH_SHIFT); } @@ -144,7 +153,7 @@ static void xlp9xx_i2c_fill_tx_fifo(struct xlp9xx_i2c_dev *priv) static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv) { - u32 len, i; + u32 len, i, val; u8 rlen, *buf = priv->msg_buf; len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) & @@ -156,19 +165,27 @@ static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv) rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO); *buf++ = rlen; len--; + if (priv->client_pec) ++rlen; /* update remaining bytes and message length */ priv->msg_buf_remaining = rlen; priv->msg_len = rlen + 1; priv->len_recv = false; - } - len = min(priv->msg_buf_remaining, len); - for (i = 0; i < len; i++, buf++) - *buf = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO); + /* Update transfer length to read only actual data */ + val = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_CTRL); + val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) | + ((rlen + 1) << XLP9XX_I2C_CTRL_MCTLEN_SHIFT); + xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val); + } else { + len = min(priv->msg_buf_remaining, len); + for (i = 0; i < len; i++, buf++) + *buf = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO); + + priv->msg_buf_remaining -= len; + } - priv->msg_buf_remaining -= len; priv->msg_buf = buf; if (priv->msg_buf_remaining) -- 2.1.4