Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3523497pxf; Mon, 15 Mar 2021 11:27:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCT3P/J57/IF+2TP5PdHNMil2SRneTRb/KE6TwttLP0jkb0b+14H6Q6XTfMXdo3FIl3LBU X-Received: by 2002:a05:6402:354d:: with SMTP id f13mr31749974edd.228.1615832852636; Mon, 15 Mar 2021 11:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832852; cv=none; d=google.com; s=arc-20160816; b=eWiReSKVCu+tpgpfpRcurdvFTfAg7CWsJAV6SoIRf04b06S/zuIrxW8tyK/O6+B6w9 /6wn1rMpXSWuiruX+IBzLyqOuiMU3ZI0yDUsVGfJOpgrBqgnqOVe6vwsKVbsAsgp9qyw VtmslcXKcQMhPynawfu0l+9ZkXYG8ObArxukMGladJLzSUqgyN6HPN3th5Z4oK0LiA9L ohTfoYKt1QiXaJSBA6pWPQoI+aMa14LEYp8JGIWoxOFgaSR+Lqyc0AQWh5yQnTrEImhH WwjIXcGiCq37KOsp9wLyGXEC3UHatoJk4vNxHTa2kkWTd1wKR5eb6NJ2pUiKJsGfCK7v gLng== 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=J+UIjJKCIHbZODu1otl5jd+StcNWy+2Mu+SS6hLdJiwwLEqc7h2+a4IpE7z4xhnGi/ xCo4tI/xwEyObIOl8fBo+3ao4JcAO8gaNs6G0qUkS17qA+ThBLC7sLlMrhZXaYuGM5G3 jFzlAYFQKfcHfzqR4QP7HRxwKHFt73olVX30JPKt5jpAuId2vUmsXp/LUnIPSArP+heq qQqdrI1gacRloD+R2Gi64cBKHEMjhbVPDi3lpJP0xMXdrJDxvdPzNgsRiNV4/r/tyMQe NKkJlOOQ8qDtLs+0cT7toGaS1PvSEYiWqk3CJtAdkaIbkGR3WwK2KOHG8/NOJCow5Th2 NUxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="jgsy/sxE"; 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 r25si11355025ejs.195.2021.03.15.11.27.03; Mon, 15 Mar 2021 11:27:32 -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="jgsy/sxE"; 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 S231573AbhCOO0y (ORCPT + 99 others); Mon, 15 Mar 2021 10:26:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:35186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233052AbhCOOAf (ORCPT ); Mon, 15 Mar 2021 10:00:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3865664EEE; Mon, 15 Mar 2021 14:00:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816818; bh=3dHF4xPZBkdJCHhLjFFJ+oVg5bdDf4otkPiATNSJy9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jgsy/sxE4Exsho3jfgIhmb8r2FqTdRyb0vmRdyAOKlD1bZkuhHnRTk1BiOdUNiSWU NQ6qxDgE5DfuAVvuuyUlKfz5BzCcZFOGF814yC/q8fDyvEu7/K+F6fMvtPGNqW/eSC be5N8DeS9LgUnqFtra++skFUF7N9ApRY+KMh6ZCc= 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.10 131/290] i2c: rcar: faster irq code to minimize HW race condition Date: Mon, 15 Mar 2021 14:53:44 +0100 Message-Id: <20210315135546.327084320@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@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