From patchwork Sat Mar 2 13:47:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 10836637 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DA0C14DE for ; Sat, 2 Mar 2019 13:49:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75E9E2B4A3 for ; Sat, 2 Mar 2019 13:49:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 663892B4A5; Sat, 2 Mar 2019 13:49:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DE4692B4A3 for ; Sat, 2 Mar 2019 13:49:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=zgpYUpqpWdFBticcVfr2+6tyUEFlV/QGdqzo6W2Vrus=; b=tDb A63s032RTcEY2z+dtryI3BTxNdWi6df2N33GrCK9UsEQDwXjvp3qHfiNmQraQqdwlWhrqC3Ut4JTd grrNZUNPKOvRLcifaawhQesArMXL5oNwqC92utJRAOQGeDfCzFeL7WrSOo2lw5xu1YbBhPuaNoaAC LCPlb1njw8ltBKuYB91QQiItgcw7obCcsDstqJdyqKtLqkkq17YUsOOgHBPrENFSpJaXWis3ZGV0f ZEcXI0+4wo6yynNfZni1wqBM5PbSVyoiNxsd5CdefUoMl2/qN1B55CZS5FDrjQvSx86F9KBYpbB45 04wRM2J0xQMdOrUvDa9lYbPc7fsT/mg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h050g-0002on-53; Sat, 02 Mar 2019 13:49:02 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h04zh-0001Eq-EL for linux-arm-kernel@bombadil.infradead.org; Sat, 02 Mar 2019 13:48:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=f7T9Am8ZM3a9H9qMAkP4xLarkHRgqjHuLtU86EfC7vc=; b=kqNiPvieIcQpOWWszCzq3lq8q xNiWm22r+lOvURUaktBX+AHJSZGBL7b0IgWqwEULSP7DDxR1tfAmhPfsJRbao+q9wJ2UF0sKllSBD cnpRHkqaBhglEDzsrK/NcmXKfStm0Y+5bm14TPjxX5fHXFEWmwZmcuQCFrRFxNAGrEJkNMAqewRVi TcQoXjJiHawhIZl/u0+AuTXcY+pNsMJ5hojrpHGh9cJA10MiEtorb87w2fGCgRZyRAnJkL5KRBcHB GK1bc+82trTVM+9k5suVCBALSaXbJdYccyIJhwvIEqqAl923mYoymaQCnnZ+XVkSB3v/a0UURmjhc 31ldoAYKg==; Received: from sauhun.de ([88.99.104.3] helo=pokefinder.org) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h04zd-0000T0-8Q for linux-arm-kernel@lists.infradead.org; Sat, 02 Mar 2019 13:47:59 +0000 Received: from localhost (p54B33179.dip0.t-ipconnect.de [84.179.49.121]) by pokefinder.org (Postfix) with ESMTPSA id 2F45D4A1772; Sat, 2 Mar 2019 14:47:43 +0100 (CET) From: Wolfram Sang To: linux-i2c@vger.kernel.org Subject: [RFC PATCH v2 0/7] i2c: core: introduce atomic transfers Date: Sat, 2 Mar 2019 14:47:28 +0100 Message-Id: <20190302134735.4393-1-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190302_084757_513682_8D020A7A X-CRM114-Status: GOOD ( 23.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tero Kristo , Phil Reid , Tony Lindgren , Keerthy , linux-kernel@vger.kernel.org, Russell King , linux-renesas-soc@vger.kernel.org, Wolfram Sang , linux-omap@vger.kernel.org, linux-tegra@vger.kernel.org, Stefan Lengfeld , Andy Shevchenko , Peter Rosin , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP So, finally, here is the second RFC for supporting I2C transfers in atomic contexts (i.e. very late). This will need some text because I tried some things on the way but had to discard them. However, I think it is important to have that documented. One thing I really wanted to have is a kind of whitelist for devices which are allowed to use atomic transfers. So we could identify the "unauthorized" ones as buggy. To be useful, this should not add new API calls for transfers, otherwise things would have become way more complicated for I2C users like regmap. So, I tried e.g. to flag clients and provide that information throughout the i2c tree (think muxes here). In the end, I concluded that this is not an I2C specific problem, so it can't have an I2C specifc solution. Imagine a GPIO which is needed to reboot (drivers/power/reset/gpio-restart.c). This is the device which needs to whitelisted but the driver doesn't even know if the GPIO is behind I2C or not. So, if we want this, it should probably be handled on 'struct device' level. Including all the hierarchy. Postponed. So, this RFC v2 is much more similar to v1 than I expected. Main changes: * cleaned up 'struct i2c_adapter' a bit before adding the new stuff * added an atomic callback for SMBus, too. Only build-tested so far. But spent a few braincells of getting the SMBus logic readable because we could have an I2C fallback just for the atomic case * add a WARN for atomic transfers with no atomic transfer handler * added support for the i2c-demuxer, so I could test the series. Support for I2C muxes is missing because of the locking issue (see later) which may mean a redesign anyhow * imported the omap support into this series to have another user. I didn't pick up the patch for imx from Stefan because it is bigger and probably needs seperate review first * I converted the tegra-bpmp driver which already had handling for the atomic case*. I did not convert the pxa driver which has a polling-only mode, too. This also seems like a bigger task and its current behaviour shouldn't be affected by this series. *only build tested * added a HACK to allow the i2c-gpio driver atomic transfers. This will only work if accessing the GPIO can be done in atomic contexts, too, so this is for testing only For the regular cases this series works well on my Renesas Lager board* which needs an I2C access to the PMIC to reboot the board. *if I use the i2c-gpio driver, the i2c-sh_mobile is not converted yet. However, during the last review, Russell King brought up an interesting corner case. What if we want to reboot because of a panic and the bus is not in a consistent state? To create this situation, I recently created the 'inject-panic' fault injector [1] which is merged into i2c/for-next meanwhile. With this fault injector and 'reboot after panic' settings, I can create the problem Russell described: a) the bus is in an inconsistent state because the driver was interrupted (SCL/SDA both low) and b) the lock for this driver is taken, so trylock fails. I think b) is an interesting question: shall we give atomic transfers priority and ignore the lock? Do we need a seperate one then (SMP is turned off already, or?)? If so, that would probably mean way more complicated mux-locking code (Peter?)? And what if some mux in the path needs interrupts? And how academic is all that? Because someone putting the reboot functionality behind muxed I2C is kind of asking for problems :) That being said: this is an issue I think it is worth tackling. However, this issue is not introduced by this series. It is already there. It might just become more visible. Sidenote: I think problem a) is easier once we solved b). E.g. if we decide on a higher priority, we can postulate that IP cores should be reset first and bus recovery can also be applied. This will not help all cases but IMO is all we can do. Another topic where I'd like input from other people is the use of 'in_atomic' in this series. It was already there, so I kept it to avoid regressions. I am aware that 'in_atomic' should not be used in drivers. So, if someone has expertise to say if it can be removed or replaced with something else, I am all ears. A branch (based on i2c/for-next) can be found here: git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git renesas/i2c/atomic_xfer Sorry, no TLDR; text here - I think this topic deserves a few words ;) Looking forward to comments, thanks! Wolfram [1] http://patchwork.ozlabs.org/patch/1044789/ Tero Kristo (1): i2c: busses: omap: Add the master_xfer_irqless hook Wolfram Sang (6): i2c: apply coding style for struct i2c_adapter i2c: core: use I2C locking behaviour also for SMBUS i2c: core: introduce callbacks for atomic transfers i2c: demux: WIP: handle the new atomic callbacks i2c: tegra-bpmp: convert to use new atomic callbacks i2c: algo: bit: HACK! add atomic callback drivers/i2c/algos/i2c-algo-bit.c | 5 ++- drivers/i2c/busses/i2c-omap.c | 79 +++++++++++++++++++++++++++++------ drivers/i2c/busses/i2c-tegra-bpmp.c | 27 +++++++++--- drivers/i2c/i2c-core-base.c | 17 ++++---- drivers/i2c/i2c-core-smbus.c | 25 ++++++++--- drivers/i2c/i2c-core.h | 15 +++++++ drivers/i2c/muxes/i2c-demux-pinctrl.c | 3 ++ include/linux/i2c.h | 38 +++++++++++------ 8 files changed, 162 insertions(+), 47 deletions(-) Reviewed-by: Andy Shevchenko