From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757444AbcEDKBg (ORCPT ); Wed, 4 May 2016 06:01:36 -0400 Received: from mail-am1on0132.outbound.protection.outlook.com ([157.56.112.132]:29664 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757098AbcEDKBb (ORCPT ); Wed, 4 May 2016 06:01:31 -0400 Authentication-Results: lysator.liu.se; dkim=none (message not signed) header.d=none;lysator.liu.se; dmarc=none action=none header.from=axentia.se; Subject: Re: [PATCH v7 16/24] i2c: allow adapter drivers to override the adapter locking To: Wolfram Sang References: <1461165484-2314-1-git-send-email-peda@axentia.se> <1461165484-2314-17-git-send-email-peda@axentia.se> <20160503213807.GA2018@tetsubishi> CC: , Jonathan Corbet , Peter Korsgaard , Guenter Roeck , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald , Antti Palosaari , Mauro Carvalho Chehab , Rob Herring , Frank Rowand , Grant Likely , Andrew Morton , "David S. Miller" , Greg Kroah-Hartman , Kalle Valo , Jiri Slaby , Daniel Baluta , Lucas De Marchi , Adriana Reus , Matt Ranostay , Krzysztof Kozlowski , Hans Verkuil , Terry Heo , Arnd Bergmann , Tommi Rantala , Crestez Dan Leonard , , , , , , Peter Rosin From: Peter Rosin Message-ID: <0b4136b2-e555-9bc0-9003-898d686de7a1@axentia.se> Date: Wed, 4 May 2016 12:01:17 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <20160503213807.GA2018@tetsubishi> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [217.210.101.82] X-ClientProxiedBy: HE1PR09CA0007.eurprd09.prod.outlook.com (10.162.19.17) To AM4PR02MB1300.eurprd02.prod.outlook.com (10.165.241.150) X-MS-Office365-Filtering-Correlation-Id: 24995278-4ae3-43c1-6921-08d374030e8f X-Microsoft-Exchange-Diagnostics: 1;AM4PR02MB1300;2:nLL6PjuRIoIq8tHo4q0TKGlIGJcU0h9YhLV0jMtMINS0gViIjZo6M4z67/l34T46bl4HBhZHwOfQobN3s9q46E6sA/UR1XPullWcJ4FnU5hQEkGJVu44ujlTceMBfYquEgNPQf/O29MVuFOLO9dHC4HzE82Uem8juIJAj41dZGrB0pWxejRoPkAPOwcvznlJ;3:SIBxP1/YGEySeK89mUm+d2niuynU6lWLnHY9BIyO+4B+VFXBxsK8JfA7MVJr1TXuCpRJG6rPnuJIMMmklu5dFHdBU/frFggcD8gDPHjMfqh75XdG02lZ1GpYokrwGK0l X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM4PR02MB1300; X-Microsoft-Exchange-Diagnostics: 1;AM4PR02MB1300;25:dY8ORTzFL1DWfFRFxdc6AxF1zFcDB6/DBpWST8CdY0fsPC4OAwlCLQayc6iz61V+NXaprhjbg3LpizWm3OmAEjHLztZS+EBs+oORf+CV+7AXA/Cnvi6MZFP6Eq/1sMhiB9jmKzA6Agu64dCGSdq9zQoaVPvyetDpMwKMXOmCQl3/XGQRi1f1et9Ih00RZSVLIVbXGfjHADfeFzh5hkLGejh2pm1UlfEnu3bCOwMZ2P2atUre0TAOg/R+BL/sF6Uj3nX/kw0TYMUnLhtXWqjEBf5WzJDkwJKJs27pZ7HLexpy7iM+T5rbnB76k5UhrY39H96ItVvIs1861aJyChG8PStwvDnXfC47PMW4QKY7/t/vX4k2LqDrgY73V6Gf4eU+k/gfKjdJHfbiVK5R6PEtKMgsN/bDvqWG9anyu5sCMBQQ166QwBAdxgNv6VVAr6iBR3FAFUA0nV4zVvdD68TgzW/Is7/i/KYA8DQIT4I0xy9xuF2f4zdV7ZSeXXC+bdulOSQZgHUEGAWh1iM6085QcEBpGW5f6c4FBZlLRLIzz7mCj42M/7Zl4Ydu8vLdenzk9KEz/VWXslFRWuvkFiSJMC731/i17JfIChC0C71wqalo25dyQ50yBtzpAOOhNswxl++xNmP2Z77j7fT3/+t49wBGEWapIyPUC2O49pM+EN7K9Y+eDvGi/bZhB0c72AnawHByoaYMFnewTfqPeVDzowGNp5Ulf4P2rEz3Hx9fKsPFfObpY4u3NUuAopbmIXb/fhZcLhTRvUMnrdCCCu8zwQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521098)(9101528026)(6040130)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041072)(6043046);SRVR:AM4PR02MB1300;BCL:0;PCL:0;RULEID:;SRVR:AM4PR02MB1300; X-Microsoft-Exchange-Diagnostics: 1;AM4PR02MB1300;4:l2zJE+AbIJF3TiK/sBgoHwGhDq7HnsSHn1ZG6OWtRzx3UsChvTyN6OvVQKCvlHb3ejsgIfPXXXU/lC64XaWMutrCu9+jR8q0122CUvQySVtFMFDNDp0PfLZHKTRnu8RK+HBneNptA6SuARox0ppn1lvxevgTI8GJgEIycHKU8cpJ/n0kpAieDa0nBjVRc1FxoVNenY5+XtHzgLtELQKu0a1d1GysmvmQgLvhGFWFMcC8atE6JsxtCrxueTypNqpAhz4X/Y558Nxu1aGJ4TqQP/VX/xQ4hHfgmJyGuPyiiROHy1MUYeMZRtGJHh2ID8IC/cqdG2TfBkJ5Xq/44vAGbjNT/AKsDcWKYP9JptIdej/Q2KkvSVcUcWX/P4i755riQxscKK3Bs+svm8RAuqS5tPnIK/LCEiiY2jJbKbO3XuP2822JTe4kQ+XgQH3mmkbWuVotpmwWGFKvGs6kILl9+nLidloPE4ONdS8ON5drZK0= X-Forefront-PRVS: 093290AD39 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6049001)(6009001)(377424004)(24454002)(83506001)(42186005)(50466002)(19580395003)(31686004)(110136002)(2950100001)(4001350100001)(19580405001)(64126003)(5004730100002)(5008740100001)(2906002)(36756003)(189998001)(77096005)(81166005)(86362001)(31696002)(23746002)(3846002)(4326007)(74482002)(6116002)(54356999)(92566002)(76176999)(66066001)(33646002)(65956001)(586003)(50986999)(117156001)(47776003)(230700001)(65826006)(7059030)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM4PR02MB1300;H:[192.168.0.125];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;AM4PR02MB1300;23:OgJzOANxKbOLR22Jqewmu+ebQ26QWcaYXPt3e?= =?Windows-1252?Q?yxJkj3zG4/ECr1y6dIJO+K6hoXDkWCx2ur/QM0vIGr6yxkeI36FO2yyp?= =?Windows-1252?Q?KEQDknLEhdHYhqFSuBJsef4qJcHBTPHcM1+zS21uDgl3ZXgBhck1jOvB?= =?Windows-1252?Q?+eY18QovaSz67Gv1sLxCbPSiasmcD9nd5uWv+cu/FcsLqb/pHHh3+XhN?= =?Windows-1252?Q?VxGfVKWEVgEDufHRQ/gX/Cx77wxqVZuromQW8mr1LeKcDoKMRwbwqQWQ?= =?Windows-1252?Q?pUfG3UtU65+wW111E2338aDISWeq6C68gPFT7dpEEa22R88ebFqft0hc?= =?Windows-1252?Q?siRrh4MGvHK2Hom5yOGTbFOtj9S85ggi2gEFOSXsv3IaFKJew3xzNK/E?= =?Windows-1252?Q?ucrK9SDZaghxotyhc5nVcem2QJfusRTtWYBqMcxRAunheys4DKPvtney?= =?Windows-1252?Q?x7r+Io5Sl+G3ffWe+PRUfXtVrbZIqC3IkOtLC7/Rhu4XtfkxsSzIAp7c?= =?Windows-1252?Q?c+jKmEO6xvCEg58UjYbnGnnE+lwuv+yGp8qKqaTKYwGynZBVCRRM1iVM?= =?Windows-1252?Q?19r3ZmdSO6VkdS4EXcdQ9hOwNTRBqbsxYSlXTtv7favu0fR7mvk29iyl?= =?Windows-1252?Q?I+B/2Cz8+5e5IKaSdAn2Ys15Vd+SuCbtBhYwGyMj445LAK6OlOdxgldv?= =?Windows-1252?Q?Sd9Q97sS6tru2nEUNjfMWKRsKOD12IZm9EzrImZ8G7VnVXgk26sI4LjS?= =?Windows-1252?Q?DeBiQRAc1d+KG44mEb2/SeZGG0UXbPAJrVP71hvNPlCLaR3U107JJ4SF?= =?Windows-1252?Q?jzA0cPBf/s6tFEb/K3HVb2dHL6f/l5VgoK0YHDvjs3/wEUITyFfU7Mhf?= =?Windows-1252?Q?x5e/rTsdRxG4K/lZ+qbQDYYeA2QYZ2QXuUQeAM8YdXKx28hql5/9oh49?= =?Windows-1252?Q?HiQ8CpmwNLHQ2IGg/nuYYT5nFqblW/z5LuoKiNqofZWjL5La4bL6WuF/?= =?Windows-1252?Q?5QNBFX/S1moqYcDU+e6FHwphROziCcRwDAxzhlwoXuudAgPhU0kY/pR1?= =?Windows-1252?Q?uG6IBYAlMNw9bC+/mYDkTyG/Ia3Z+cwS9UdJBeKOWa+H1nVPpesIbAkS?= =?Windows-1252?Q?+ds/wWrZdaFuBnd9mF+0NU6E5yVXkzMVDN6vrFPhguYXhMwxdqk96GSd?= =?Windows-1252?Q?UlCXyz+AjyXngf+tADJJmmzhOdCK64=3D?= X-Microsoft-Exchange-Diagnostics: 1;AM4PR02MB1300;5:4K6TDJ0xoiSi+WV3+60vYWu9hSipgpVh3ctcB/dw0lP5MZGHqRKt3tvRtJULEtZux+uRPBUFJWhjs6IYA+QQEwNDov/2SRjz3yFFo/e2rRcTHQu22haS/TTvx32iA1yB+Y2BDYKS0w5nUkngufOp3g==;24:cEE4nwYpnQTb1vKNcyjr4Eya2xNbNc+Fm4lkyAw57uCDrB8ZFELd4gh6+5rytBEyEVI8H38xl8T/NSl+BOK4HYJBV32E4VMAYpPEHrsDBZY=;7:rC0alQb+Dapvcc5rVi3Y9hm9pOgjbFY5wvBX/+NUoAPpo/z5C9fcGPpcvyeQ+S6RchPzYe3wOA18PvWtwEOhZCGYRCwYBCN+M88MVPRLYHFvdTHLZUWSKkEHjaXsUt/l4gJq17F5DOFp/7g7ZR+58aikpp/uF7yQWOVcIPbePSI73CWPhFP1bxSKV4n4H/kx SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2016 10:01:21.9873 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR02MB1300 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi! On 2016-05-03 23:38, Wolfram Sang wrote: > On Wed, Apr 20, 2016 at 05:17:56PM +0200, Peter Rosin wrote: >> Add i2c_lock_bus() and i2c_unlock_bus(), which call the new lock_bus and >> unlock_bus ops in the adapter. These funcs/ops take an additional flags >> argument that indicates for what purpose the adapter is locked. >> >> There are two flags, I2C_LOCK_ADAPTER and I2C_LOCK_SEGMENT, but they are >> both implemented the same. For now. Locking the adapter means that the >> whole bus is locked, locking the segment means that only the current bus >> segment is locked (i.e. i2c traffic on the parent side of mux is still >> allowed even if the child side of the mux is locked. >> >> Also support a trylock_bus op (but no function to call it, as it is not >> expected to be needed outside of the i2c core). >> >> Implement i2c_lock_adapter/i2c_unlock_adapter in terms of the new locking >> scheme (i.e. lock with the I2C_LOCK_ADAPTER flag). >> >> Annotate some of the locking with explicit I2C_LOCK_SEGMENT flags. > > Can you explain a little why it is SEGMENT and not ADAPTER here? That > probably makes it easier to get into this patch. > > And to double check my understanding: I was surprised to not see any > i2c_lock_adapter() or I2C_LOCK_ADAPTER in action. This is because muxes > call I2C_LOCK_SEGMENT on their parent which in case of the parent being > the root adapter is essentially the same as I2C_LOCK_ADAPTER. Correct? Correct. Locking the ADAPTER and the SEGMENT is the same thing for the root adapter and for traditional muxes (i.e. not mux-locked). Traditional muxes simply feed the locking request upwards to the root adapter. The new mux-locked muxes behave the same for ADAPTER locking; all locks all the way up to the root adapter are grabbed instantly. If you instead lock SEGMENT on a mux-locked mux, only the new mux lock in the parent adapter is grabbed right away, but when the mux then fires off accesses on its parent adapter, that triggers SEGMENT locks one level up in the tree and the process recurses. So, SEGMENT locking is the normal thing that happens when e.g. normal i2c_transfer calls are made. ADAPTER locking is used for transactions. The patch enables muxes to use more relaxed locking compared to locking the ADAPTER for its transations. The naming can probably be improved. SEGMENT made more sense when it did not lock all mux accesses one level up (that changed in v6, but I didn't change the I2C_LOCK_SEGMENT name at that time), so it is kind of outdated. I2C_LOCK_ROOT_ADAPTER and I2C_LOCK_MUXES instead of I2C_LOCK_ADAPTER and L2C_LOCK_SEGMENT perhaps? But I don't really like I2C_LOCK_MUXES as I find it a bit too specific, and people not thinking about i2c muxes at all (most people I gather, ignorance is bliss) will not think that it is something for them... It is also the case that the two flags are mutually exclusive, and at this point there is no valid uses of using neither flag, nor for using both. It is a binary decision and one flag would technically be enough. So, not setting e.g. I2C_LOCK_ADAPTER could in theory imply I2C_LOCK_SEGMENT. I did it as two separate flags since there might be a third (or fourth even) option in the future (I don't see what it would be though, I have no crystal ball...) So maybe there should be only one flag, e.g. I2C_LOCK_ROOT_ADAPTER? I.e. perhaps leave the future for later? Hmmm, I just now realized that you were not really suggesting any changes other than to the commit message. Oh well, I can perhaps rephrase some of the above in the commit message if you think that we should not unnecessarily touch the code at this point... >> >> Signed-off-by: Peter Rosin >> --- >> drivers/i2c/i2c-core.c | 46 ++++++++++++++++++++++++++++------------------ >> include/linux/i2c.h | 28 ++++++++++++++++++++++++++-- >> 2 files changed, 54 insertions(+), 20 deletions(-) >> >> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c >> index 0f2f8484e8ec..21f46d011c33 100644 >> --- a/drivers/i2c/i2c-core.c >> +++ b/drivers/i2c/i2c-core.c >> @@ -960,10 +960,12 @@ static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) >> } >> >> /** >> - * i2c_lock_adapter - Get exclusive access to an I2C bus segment >> + * i2c_adapter_lock_bus - Get exclusive access to an I2C bus segment >> * @adapter: Target I2C bus segment >> + * @flags: I2C_LOCK_ADAPTER locks the root i2c adapter, I2C_LOCK_SEGMENT >> + * locks only this branch in the adapter tree >> */ > > I think this kerneldoc should be moved to i2c_lock_adapter and/or > i2c_lock_bus() which are now in i2c.h. This is what users will use, not > this static, adapter-specific implementation. I think it is enough to > have a comment here explaining what is special in handling adapters. Yes, I was not really satisfied with having documentation on static functions. But if I move it, there is no natural home for the current i2c_trylock_adapter docs, and I'd hate killing documentation that still applies. Do you have a suggestion? Maybe keep that one doc at the static i2c_trylock_adapter for now and move it to ->trylock_bus when someone decides to write kerneldoc for struct i2c_adapter? Cheers, Peter