Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3522062pxf; Mon, 15 Mar 2021 11:25:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygdefWJiovsDkpdSmMsLk8F80cuItgRoXjtetJo3r/Gy6mOKUA9ktj8Qf249nbYT95EP+2 X-Received: by 2002:a17:907:1693:: with SMTP id hc19mr24808144ejc.28.1615832726147; Mon, 15 Mar 2021 11:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832726; cv=none; d=google.com; s=arc-20160816; b=r2urRUlGuqbaH6bvpLOgI14J8GJGcMtwSlZup4fyL2jKPKbF/e7lqfVe6+fkGr3Lcw gCWfpjZc4dqP9ZTji8k/NX5VkYg0EDYyhkemY47wOGlAxs+TQZceJRTBIpzkcMClkCai xAqM7GStHO3DR4vAp+QLZfMJlLmKU/I4a04toNIMdTxSOlBGTgZlMXQCQ93grdzvpj5z ORC0d/Xf8NTl+N0e/AuYkhAJUYFloAZVPyLI9ZyoBWHxc9zu08RfYR4zp0yCXeXiCvHN WiiK3oowHKxLRdm6u5gbrKsuyJPn9PkIq/IE1HOsokfWZOZ5nWxnyKbkVRmAScAGQMnM Rq6g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=av1EIH5Dh3r8ExArGXSKgSspH5ipnoFub0Iucif3ZvQ=; b=PLj2qJ9Ob1T4jpKne0qQY+PsndgLEVu6bNKoARIH9K8kSLPNBhRSO+C8Tiyc0UJJpc JV7TTu2qDiGjxFseE25/3dgW5Ti55hYb0IEIawl791aNx5ZCwsDfMWCGGbLaothbs6k5 XbetmSniLWmUwTEuBpeFN7iOhNjZN2MUxDH9fLwFoVCjhMieufieJ6C+lniifsVR1Cqm vJ0bNdWmpqspXPC8UAV1J110jDF7fZJ8RG1QIrzXNqTQGetvSRS/hdgtQMqswFl3Yjp2 nB9IPwL7krvL7syi2y/kt2wt6CuIysfsKz71BhAuRhrj6R4QzRP1+Bq0omHRRgT6nktc hEdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OGQfnsbN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si11887635edx.470.2021.03.15.11.25.03; Mon, 15 Mar 2021 11:25:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OGQfnsbN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238454AbhCOOXP (ORCPT + 99 others); Mon, 15 Mar 2021 10:23:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:37540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232055AbhCOOAP (ORCPT ); Mon, 15 Mar 2021 10:00:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 89C8A64F07; Mon, 15 Mar 2021 13:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816786; bh=3dHF4xPZBkdJCHhLjFFJ+oVg5bdDf4otkPiATNSJy9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OGQfnsbN7jXWzzPQolcSArXTTC4gh2hGE/+mtrO124dGWAYRHAullA7yj9fkVayjc WtAxSi2t2ESdwXl+K9dXyra8DB9FfhlYbKxBvakY2ioG21QYOIb5Tz37bKHdLeNCDV SocqM3ysmUnw1W1bqurjwefD9OD/YJVpOVC5BumE= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wolfram Sang , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Wolfram Sang , Sasha Levin Subject: [PATCH 5.11 124/306] i2c: rcar: faster irq code to minimize HW race condition Date: Mon, 15 Mar 2021 14:53:07 +0100 Message-Id: <20210315135511.861679238@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Wolfram Sang [ Upstream commit c7b514ec979e23a08c411f3d8ed39c7922751422 ] To avoid the HW race condition on R-Car Gen2 and earlier, we need to write to ICMCR as soon as possible in the interrupt handler. We can improve this by writing a static value instead of masking out bits. Signed-off-by: Wolfram Sang Reviewed-by: Niklas Söderlund Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-rcar.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 217def2d7cb4..824586d7ee56 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -91,7 +91,6 @@ #define RCAR_BUS_PHASE_START (MDBS | MIE | ESG) #define RCAR_BUS_PHASE_DATA (MDBS | MIE) -#define RCAR_BUS_MASK_DATA (~(ESG | FSB) & 0xFF) #define RCAR_BUS_PHASE_STOP (MDBS | MIE | FSB) #define RCAR_IRQ_SEND (MNR | MAL | MST | MAT | MDE) @@ -621,7 +620,7 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv) /* * This driver has a lock-free design because there are IP cores (at least * R-Car Gen2) which have an inherent race condition in their hardware design. - * There, we need to clear RCAR_BUS_MASK_DATA bits as soon as possible after + * There, we need to switch to RCAR_BUS_PHASE_DATA as soon as possible after * the interrupt was generated, otherwise an unwanted repeated message gets * generated. It turned out that taking a spinlock at the beginning of the ISR * was already causing repeated messages. Thus, this driver was converted to @@ -630,13 +629,11 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv) static irqreturn_t rcar_i2c_irq(int irq, void *ptr) { struct rcar_i2c_priv *priv = ptr; - u32 msr, val; + u32 msr; /* Clear START or STOP immediately, except for REPSTART after read */ - if (likely(!(priv->flags & ID_P_REP_AFTER_RD))) { - val = rcar_i2c_read(priv, ICMCR); - rcar_i2c_write(priv, ICMCR, val & RCAR_BUS_MASK_DATA); - } + if (likely(!(priv->flags & ID_P_REP_AFTER_RD))) + rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_DATA); msr = rcar_i2c_read(priv, ICMSR); -- 2.30.1