From patchwork Mon Nov 14 01:57:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 19509 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1915828wru; Sun, 13 Nov 2022 18:00:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf4WJqCrxyQf+y2UKWlENIILO+Dxe25cmCCrlNk9zFdwiYsxWV9FexMRqiZY5TrmfcxOdCPk X-Received: by 2002:aa7:d553:0:b0:458:f012:bacb with SMTP id u19-20020aa7d553000000b00458f012bacbmr9657513edr.345.1668391208628; Sun, 13 Nov 2022 18:00:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668391208; cv=none; d=google.com; s=arc-20160816; b=sPDpwOwFsfxi03DCfjDympfgWby7x7S0XKBdWpWzw8km0LbykwIGdaob4QazkyaWzY zmgnHrZ/YavOOPZ98RpB1gmDXvfvRlGs/WBcVPn3mnXGvxmLCIcmjmPue0lzQBG2dBxe v/g/mQ396wBWtfh21jV6N5wjVZcgHJHilV9dd5GgulIkKObySD1YDC6zQ9qcZct2AqWN MOt0ysWI/vjlEGwbHTe2rHS5TZDWnce9MI/NY9ZBRS9yahZWT6yJf9mSzRR+zsTfZ5Wl 9bx5DVDqJNE3uaLuDLdJKdoEjE/sMvNePGqQU4imXlu6HgYsEWtvGBgjvEVN791Isxay b9Cw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=8v64se4ndLgqbFDAHIerqamapO8xDSwZD3YbrOF2gwU=; b=uc4Nhly/4SwmFuWOgz7PVqqJVWJc8pSFtJ2hLVnePVrOK9sAc/rEeGnu97h13LFoFU Bh2++TYZa9rNOqIAXf9lUEkLr+cjP+ftqoaxCdv74CFh36f+ntwpQcymXUQeKd4j7QNc q3ml3JwiYOM8n4pInnNV88ROIcCmjWTBsqz1JPx2nwWc8+Df7d1EdrLnLbtr7GMEV625 EsPdrqnHLS1q3fxebfirm+hMXjjRNe3P2x80Y/ExtXCTdJXHfjJk8MNoUvxNUL3hWmGu hdx7YHLQ1pnl+iD6fLeq0vAfJD11T5Sx9GrWDGZFPb85JU1InkZpxUX/KWwASX2iIrer HH2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm2 header.b="nW/Za3Em"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=LR4qa+zq; 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=sholland.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j11-20020a05640211cb00b004615c5728e8si9089564edw.494.2022.11.13.17.59.44; Sun, 13 Nov 2022 18:00:08 -0800 (PST) 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=@sholland.org header.s=fm2 header.b="nW/Za3Em"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=LR4qa+zq; 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=sholland.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235485AbiKNB6M (ORCPT + 99 others); Sun, 13 Nov 2022 20:58:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235753AbiKNB57 (ORCPT ); Sun, 13 Nov 2022 20:57:59 -0500 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A79256385 for ; Sun, 13 Nov 2022 17:57:56 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id AB4C13200918; Sun, 13 Nov 2022 20:57:55 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 13 Nov 2022 20:57:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1668391075; x=1668477475; bh=8v 64se4ndLgqbFDAHIerqamapO8xDSwZD3YbrOF2gwU=; b=nW/Za3EmB97fE3xQuz U6IjghrHUwvxKsNRYAo8tZ4gfTFvimat3kKsyL+VLjfRGPJ5zYlnB51PnMgHErdz Jgsdcq2Blkkn1IGrQ82ih1dfhaC3wX8rTcSjWHtrAmflQ14Al8CyaK/4PZytH8ub FBmKyvt74izhN6/cVv7dkRKszHISqk01Zi7jtxnpKCN5SATtcwEjjce6u+28HZFt Q9pbVdOKS/MaA/JD1aZpbebRw38r8Q2+hxewAkQM2X5XqSh/xEFK5b5DuJONAlJw CJ80JOXmUQ+u18v1BmERKTU8nryl8s1u1aOlM40aMHH6FOslFE2THipsR2BtZbA4 fiDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1668391075; x=1668477475; bh=8v64se4ndLgqb FDAHIerqamapO8xDSwZD3YbrOF2gwU=; b=LR4qa+zqLoevQmTaWy4UOL7sr85kK PxsH3h3OkgY4sJXhswK2jBoXG+CxNsvMXsSgTeccvtLW2lKqADVrSHbT5vuo6uMA 0IMUXs8TF0t/T2ikJGGH3MDM9PnOEDUu8eEhsmkDIb2zcD5NqIebFIhOJu2hpj14 UhI0aMo73HNIoz4IDdwM+T4IKhyceGKvKFM/Ax5PpiqPgKAkURqdZHnN+4EfnvZL Hn9efLrK/Xr01xHE5KuMC4k3JY/n3ebtLoQfPElN3YqdIPDjozErKP28Wlrn/KpQ mmRL/JEYSgyLUYAdUzrG1D9y2yPCxX6tPd0BoPR7EeyJ93dsKSlWkS49A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrgedugdegtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpedukeetueduhedtleetvefguddvvdejhfefudelgfduveeggeehgfdu feeitdevteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 13 Nov 2022 20:57:54 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Jernej Skrabec Cc: Ivaylo Dimitrov , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, Andre Przywara , Samuel Holland Subject: [PATCH v3 2/3] bus: sunxi-rsb: Support atomic transfers Date: Sun, 13 Nov 2022 19:57:48 -0600 Message-Id: <20221114015749.28490-3-samuel@sholland.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221114015749.28490-1-samuel@sholland.org> References: <20221114015749.28490-1-samuel@sholland.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749434979912795301?= X-GMAIL-MSGID: =?utf-8?q?1749434979912795301?= When communicating with a PMIC during system poweroff (pm_power_off()), IRQs are disabled and we are in a RCU read-side critical section, so we cannot use wait_for_completion_io_timeout(). Instead, poll the status register for transfer completion. Fixes: d787dcdb9c8f ("bus: sunxi-rsb: Add driver for Allwinner Reduced Serial Bus") Signed-off-by: Samuel Holland Reviewed-by: Jernej Skrabec --- Changes in v3: - Clear the interrupt status register after polling Changes in v2: - Add Fixes tag to patch 2 - Only check for specific status bits when polling drivers/bus/sunxi-rsb.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/bus/sunxi-rsb.c b/drivers/bus/sunxi-rsb.c index 17343cd75338..3aa91aed3bf7 100644 --- a/drivers/bus/sunxi-rsb.c +++ b/drivers/bus/sunxi-rsb.c @@ -267,6 +267,9 @@ EXPORT_SYMBOL_GPL(sunxi_rsb_driver_register); /* common code that starts a transfer */ static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb) { + u32 int_mask, status; + bool timeout; + if (readl(rsb->regs + RSB_CTRL) & RSB_CTRL_START_TRANS) { dev_dbg(rsb->dev, "RSB transfer still in progress\n"); return -EBUSY; @@ -274,13 +277,23 @@ static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb) reinit_completion(&rsb->complete); - writel(RSB_INTS_LOAD_BSY | RSB_INTS_TRANS_ERR | RSB_INTS_TRANS_OVER, - rsb->regs + RSB_INTE); + int_mask = RSB_INTS_LOAD_BSY | RSB_INTS_TRANS_ERR | RSB_INTS_TRANS_OVER; + writel(int_mask, rsb->regs + RSB_INTE); writel(RSB_CTRL_START_TRANS | RSB_CTRL_GLOBAL_INT_ENB, rsb->regs + RSB_CTRL); - if (!wait_for_completion_io_timeout(&rsb->complete, - msecs_to_jiffies(100))) { + if (irqs_disabled()) { + timeout = readl_poll_timeout_atomic(rsb->regs + RSB_INTS, + status, (status & int_mask), + 10, 100000); + writel(status, rsb->regs + RSB_INTS); + } else { + timeout = !wait_for_completion_io_timeout(&rsb->complete, + msecs_to_jiffies(100)); + status = rsb->status; + } + + if (timeout) { dev_dbg(rsb->dev, "RSB timeout\n"); /* abort the transfer */ @@ -292,18 +305,18 @@ static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb) return -ETIMEDOUT; } - if (rsb->status & RSB_INTS_LOAD_BSY) { + if (status & RSB_INTS_LOAD_BSY) { dev_dbg(rsb->dev, "RSB busy\n"); return -EBUSY; } - if (rsb->status & RSB_INTS_TRANS_ERR) { - if (rsb->status & RSB_INTS_TRANS_ERR_ACK) { + if (status & RSB_INTS_TRANS_ERR) { + if (status & RSB_INTS_TRANS_ERR_ACK) { dev_dbg(rsb->dev, "RSB slave nack\n"); return -EINVAL; } - if (rsb->status & RSB_INTS_TRANS_ERR_DATA) { + if (status & RSB_INTS_TRANS_ERR_DATA) { dev_dbg(rsb->dev, "RSB transfer data error\n"); return -EIO; }