Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752073AbdLAKGt (ORCPT ); Fri, 1 Dec 2017 05:06:49 -0500 Received: from mail-by2nam01on0089.outbound.protection.outlook.com ([104.47.34.89]:6400 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750994AbdLAKGm (ORCPT ); Fri, 1 Dec 2017 05:06:42 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jan.Glauber@cavium.com; Date: Fri, 1 Dec 2017 11:06:30 +0100 From: Jan Glauber To: "Zhang, Sean C. (NSB - CN/Hangzhou)" Cc: "david.daney@cavium.com" , "wsa@the-dreams.de" , "linux-i2c@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [Bug fix] octeon-i2c driver updates Message-ID: <20171201100630.GA3632@hc> References: <20171124131026.GA30811@hc> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [46.5.204.125] X-ClientProxiedBy: LNXP265CA0014.GBRP265.PROD.OUTLOOK.COM (10.166.227.154) To CY1PR07MB2588.namprd07.prod.outlook.com (10.167.16.138) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 17d81cec-fa18-48d1-3020-08d538a33779 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603286);SRVR:CY1PR07MB2588; X-Microsoft-Exchange-Diagnostics: 1;CY1PR07MB2588;3:cl2mI/64yH6UXlnU17/Py3Wu/8xcrYYlHSqYSU699FO3FtOaTxshBg1mfMQ/up58r/i+8X3EopWpfe+2Cu/q4ay1/8wn8DYANytJ8b9gNS7k+1c6nNtV1rWKPfVPxkPE9ddPS56KtQUkMacCyZQs6hm7PweGKwBckzB0BLPh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RZlBgSLnVo1B86QQsj0mhdYJ6XUQsA3P4wKndn1Tnro8+V57dkiBsdfdSXKGtnfdoR1uxZJ/4varvssttddel+ou6Rqhy5QAXQi8p0rFzG9vdH9JInkL8oqnCnM45esYdZccZ5n8Pm0sgJ7wTH5z/OjUsumFG/dYl6CtuwT/OcA82TyZQNeHNLOwZUEsO2V/0G4rPsnxrARXTXgPM6g/yczwdk7viPT4k3cmp5/he9unLK9ib+JhuwRflWYRNBMHkR7WtOylo9o2qITrCmNmKUEqo= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(82608151540597); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(5005006)(8121501046)(3231022)(10201501046)(3002001)(93006095)(6041248)(20161123562025)(20161123560025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123555025)(6072148)(201708071742011);SRVR:CY1PR07MB2588;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CY1PR07MB2588; X-Microsoft-Exchange-Diagnostics: 1;CY1PR07MB2588;4:pCStcHqD/qqPxXjldRgBmjBC6t++qicLxPqR9yBycpnDisSsBLKmXoq0g8FuZCU3W7gkBDGWJ3Q8iMMNmDrsr8+lIF7weqcJtnk3SyeYXGYB6TapexLCSiqS/wXnkuDFzG/Pp7i6bmfU2Lqzp6kIGtf3Y0oAPVBr5ldIKixFlAx4iLvsQ/7ActZ+mDDsEQh1+CHY5oXuq3DTbrtcOeBelWsf/986O9oV7Tgfwi6PLRxEvOfNUiRsz3o18nFLLixnd69t0c8KXOHBg8nd/aUg5VuRDlCiLz8ub2IdnVVjIGkbtVgcyEY1YP7/BaNI1J0mrnxMya7jy5EOOVUMFAXEqtsELslaGnLmeABNdd/Ug/k= X-Forefront-PRVS: 05087F0C24 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(346002)(376002)(366004)(189002)(31014005)(13464003)(24454002)(51874003)(54094003)(199003)(575784001)(53936002)(52146003)(93886005)(1076002)(9686003)(2950100002)(6666003)(6116002)(6916009)(3846002)(305945005)(2870700001)(25786009)(68736007)(33716001)(2906002)(229853002)(23676004)(52116002)(47776003)(15650500001)(2486003)(42882006)(5660300001)(53546010)(66066001)(478600001)(81166006)(105586002)(189998001)(16526018)(316002)(97736004)(58126008)(106356001)(81156014)(8676002)(5890100001)(8936002)(101416001)(83506002)(55016002)(54906003)(6246003)(6496006)(33656002)(4326008)(72206003)(54356011)(50466002)(7736002)(76176011)(18370500001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR07MB2588;H:hc;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTFQUjA3TUIyNTg4OzIzOm5PNnV4ZTFXNTVEVjM3cERyYWRrQXJ0SEhq?= =?utf-8?B?Q1h0akUxcXBvNlRSUUJzM1VYd0FadXNjWjFFVlFybmdsR3lzRTZSWFpIU0Yx?= =?utf-8?B?ak02TXBFU3NvMVR4cDJPbnJtL1J1UTR6M1BkMlJIUXN4SHJnbitPbFBCVEkw?= =?utf-8?B?aHFSVllwUlZoS0tkNnJMakUyK2VLVmJ4TDljRW9lb2JjWms5dUZ6Zng4OHlH?= =?utf-8?B?cThMTVdVamM1YzVGUjlMMEVoU2hxMlp6bWFWTmRsdVVjTi9sZmNqMGxXM2Nw?= =?utf-8?B?RWRnTlh0aW1OUFBhbHZtUU10c1BCZXdmU0RnYitaMVdaYkRrdDNOMC9EN2FS?= =?utf-8?B?VGhtNmdaWk1OT0JPVUZRMndFenJxSXY3ZHQyUVM2aWJ1UURib2xMSW0wSkZD?= =?utf-8?B?UDU1eWdmamJBVXpNdGxML3hNNi9aWHVDSmthS1k4VDJVTEM5TjIzcXJGSFJT?= =?utf-8?B?dkluK1IvMlVxRWJ4c0h4WWlmTjhwaTA3Ujl4SFBRcmNIc2t2UXlENEIzM3Zq?= =?utf-8?B?bEx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lQfw/xK4oKWTiyf9q644FpDf7UblNhEmE2RX8peeAkYFWSPtCo=;5:oUqYYZbdVbSYRR0VhsFmqNlfRyorCJTiVtwjw2LgN1Pl1hrb+wMzF/VLWgWujyg9Q57wess6D3xh/SPvNlkJivTizWco8X99D/L1+nBbq1SzWyz+brEXimk+yR1ebo5oaNxErVRoUVWYhq3qt5ImQGm7ZU8ViG9Jme59mBcw3aM=;24:U2Ndps4N//mWfJ4D7Oc/DiP3UUhA/1KZqh9l4hpUA03WqF93HAglr/BDNINljMkrF19kmKFEmVNR2RWWRECP4cCCLoDxubbJJAPe7wHAbd0=;7:VdegwK3u/mdIY7Z8jfLGfUnK3bJI3tqQpCS38o3S2wuJdolpg+GMYe8OMaQZb6lhIk57jjUuekVd09jq4KoyK2RxJ4SRKpPFyX5XotvxyYIEC1Uw6Eob0VhjMWlf/PBusmQAWyK2orBYDF1ZTg5rN/40+6yrRDEdUSbq8Wl3ehxiVFa4ahyajOjXy5xA3J6oKbFMBKWRGHLhY3V96fQMS9K+kgaBajeEhmPn9K1n8O4S0+ocLr2fnFCBMcop6WQ3 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2017 10:06:39.2947 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 17d81cec-fa18-48d1-3020-08d538a33779 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2588 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7275 Lines: 197 Hi Sean, as you try to solve two different issues I suggest that you create one patch per issue. For the second point (retry of START after recovery) I would still like to hear Wolfram's opinion. I would assume that any i2c user should be well aware of -EAGAIN, so I wonder if it is worth the additional complexity of the retry logic. Also, the first issue changes Octeon MIPS which I'm not able to test, so David needs to be involved here. thanks, Jan On Thu, Nov 30, 2017 at 01:56:09AM +0000, Zhang, Sean C. (NSB - CN/Hangzhou) wrote: > Hi Jan, > > Any other comments for this patch? > > BR, > Sean Zhang > > -----Original Message----- > From: Zhang, Sean C. (NSB - CN/Hangzhou) > Sent: Monday, November 27, 2017 4:38 PM > To: 'Jan Glauber' > Cc: david.daney@cavium.com; wsa@the-dreams.de; linux-i2c@vger.kernel.org; linux-kernel@vger.kernel.org > Subject: RE: [Bug fix] octeon-i2c driver updates > > Hi Jan, > > There are two points in this patch. > > Point 1. As you see, replaced octeon_i2c_init_lowlevel() by recover bus status if TWSI controller is not IDLE. > Please take a scenario like this: when system soft reset without I2C slave reset, maybe make this I2C bus > dead lock occurred (I2C slave device stuck low SCL) in chance. Then during system goes up and I2C slave > device creating process, if this I2C slave device has a register with less than 8 bytes to read, but I2C bus was > still stuck low SCL by last system reset, then the read will failed and this I2C slave device cannot be created. > If bus recovered before the reading process, this failure can be fixed. > > Function flow explanation shown as below: > > a. System reset without I2C slave device reset > --make SCL stuck low by I2C slave device > ...... > b. octeon_i2c_probe() > -- octeon_i2c_init_lowlevel //reset TWSI core, but SCL still stuck low by. > ...... > > c. Another I2C slave device creating process > octeon_i2c_xfer() > -- octeon_i2c_hlc_comp_read() //failed due to SCL stuck low. > > If full recovery executed in octeon_i2c_probe(), above failure can be avoided. > > > Point 2. octeon_i2c_recovery() is used in octeon_i2c_start() error branch, in the case of octeon_i2c_recovery() > successful, octeon_i2c_start() will return -EAGAIN, and then octeon_i2c_xfer() return with error. I understand this like > this: if octeon_i2c_recovery() successful, then i2c START signal can be sent again, and all following step can be continue, > octeon_i2c_xfer() should not return error from this condition. > > BR, > Sean Zhang > > -----Original Message----- > From: Jan Glauber [mailto:jan.glauber@caviumnetworks.com] > Sent: Friday, November 24, 2017 9:10 PM > To: Zhang, Sean C. (NSB - CN/Hangzhou) > Cc: david.daney@cavium.com; wsa@the-dreams.de; linux-i2c@vger.kernel.org; linux-kernel@vger.kernel.org > Subject: Re: [Bug fix] octeon-i2c driver updates > > On Thu, Nov 23, 2017 at 11:42:36AM +0000, Zhang, Sean C. (NSB - CN/Hangzhou) wrote: > > Dear Maintainer, > > > > For octeon TWSI controller, I found below two cases, maybe can be improved. > > Hi Sean, > > form the description below this looks like you're fixing a bug. Can you > elaborate on when the I2C bus dead lock occurs. Is it always happening? > > What I don't like about the patch is that you're removing > octeon_i2c_init_lowlevel() from the probe and replacing it by _always_ > going through a full recovery. Why is this neccessary? > > Regards, > Jan > > > > > >From 09d9f0ce658d7f6a50d1af352dde619c29bc8bcf Mon Sep 17 00:00:00 2001 > > From: hgt463 > > Date: Thu, 23 Nov 2017 18:46:09 +0800 > > Subject: [PATCH] Driver updates: > > - In the case of I2C bus dead lock occurred during driver probing, > > it is better try to recovery it. so added bus recovery step in > > octeon_i2c_probe(); > > - The purpose of function octeon_i2c_start() is to send START, so after > > bus recovery, also need try to send START again. > > > > Signed-off-by: hgt463 > > --- > > drivers/i2c/busses/i2c-octeon-core.c | 31 ++++++++++++++++++++++++++++++- > > drivers/i2c/busses/i2c-octeon-platdrv.c | 15 +++++++++------ > > 2 files changed, 39 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/i2c/busses/i2c-octeon-core.c b/drivers/i2c/busses/i2c-octeon-core.c > > index 1d87757..3ae1e03 100644 > > --- a/drivers/i2c/busses/i2c-octeon-core.c > > +++ b/drivers/i2c/busses/i2c-octeon-core.c > > @@ -255,6 +255,35 @@ static int octeon_i2c_recovery(struct octeon_i2c *i2c) > > return ret; > > } > > > > +/* > > + * octeon_i2c_start_retry - send START to the bus after bus recovery. > > + * @i2c: The struct octeon_i2c > > + * > > + * Returns 0 on success, otherwise a negative errno. > > + */ > > +static int octeon_i2c_start_retry(struct octeon_i2c *i2c) > > +{ > > + int ret; > > + u8 stat; > > + > > + ret = octeon_i2c_recovery(i2c); > > + if (ret) > > + goto error; > > + > > + octeon_i2c_ctl_write(i2c, TWSI_CTL_ENAB | TWSI_CTL_STA); > > + ret = octeon_i2c_wait(i2c); > > + if (ret) > > + goto error; > > + > > + stat = octeon_i2c_stat_read(i2c); > > + if (stat == STAT_START || stat == STAT_REP_START) > > + /* START successful, bail out */ > > + return 0; > > + > > +error: > > + return (ret) ? ret : -EAGAIN; > > +} > > + > > /** > > * octeon_i2c_start - send START to the bus > > * @i2c: The struct octeon_i2c > > @@ -280,7 +309,7 @@ static int octeon_i2c_start(struct octeon_i2c *i2c) > > > > error: > > /* START failed, try to recover */ > > - ret = octeon_i2c_recovery(i2c); > > + ret = octeon_i2c_start_retry(i2c); > > return (ret) ? ret : -EAGAIN; > > } > > > > diff --git a/drivers/i2c/busses/i2c-octeon-platdrv.c b/drivers/i2c/busses/i2c-octeon-platdrv.c > > index 64bda83..98063af 100644 > > --- a/drivers/i2c/busses/i2c-octeon-platdrv.c > > +++ b/drivers/i2c/busses/i2c-octeon-platdrv.c > > @@ -228,12 +228,6 @@ static int octeon_i2c_probe(struct platform_device *pdev) > > if (OCTEON_IS_MODEL(OCTEON_CN38XX)) > > i2c->broken_irq_check = true; > > > > - result = octeon_i2c_init_lowlevel(i2c); > > - if (result) { > > - dev_err(i2c->dev, "init low level failed\n"); > > - goto out; > > - } > > - > > octeon_i2c_set_clock(i2c); > > > > i2c->adap = octeon_i2c_ops; > > @@ -245,6 +239,15 @@ static int octeon_i2c_probe(struct platform_device *pdev) > > i2c_set_adapdata(&i2c->adap, i2c); > > platform_set_drvdata(pdev, i2c); > > > > + stat = octeon_i2c_stat_read(i2c); > > + if (stat != STAT_IDLE) { > > + result = octeon_i2c_recovery(i2c); > > + if (result) { > > + dev_err(i2c->dev, "octeon i2c recovery failed\n"); > > + goto out; > > + } > > + } > > + > > result = i2c_add_adapter(&i2c->adap); > > if (result < 0) > > goto out; > > > > > > Attached patch for you review. Thanks in advance. > > > > BR, > > Sean Zhang > >