Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3503043ybi; Tue, 18 Jun 2019 01:44:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRRrxgSqlYtQfoLUrNaJ6Z42Jzb0rUF1nwQzRVAF7gSfzQlz/KiS2QyK6rGS7DRiP0CMTe X-Received: by 2002:aa7:92d2:: with SMTP id k18mr19778391pfa.153.1560847471848; Tue, 18 Jun 2019 01:44:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560847471; cv=none; d=google.com; s=arc-20160816; b=l+qbt1zJxF2meo8e17IZxwZa2QlN0IuPH2+nqDY7mb2ILRtO88VNyusxf6eeSFAmsZ heXZ3ehwO3CpkcCRYFPQFuw2XL7D3OlKqbldVuzlmMDt+hHlf/1X8n8PTaKkv7oMoiPb tpf9buq7CFmWUEyNRNem7imIFUb9MMc6MUQ12c0/vb71L10UMwYLpDTAZuwsewDxNUGT CR3l7NO6QOQZnixJq2vy6qBZBWegdrbqCXwkTRh1cCxJ8s9WEpkrmbJzRDTLVE1amXlR y7ZV9GaCF3EZy1EGz3sMdKtbBoAzcZEYVPBSAQj66p1Ce4paCJryLbJNJTnKGEJd0nu8 bLpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:mime-version:message-id :date:subject:cc:to:from; bh=HqDxJokKgFe1kNELmIXIfg1rSInkOt34jaRIIaxFV6c=; b=vvG+Lk2KGlhe029shiJXwxCqpfSJOAprASioXLgB+9YC/dxu8TdoIfmwqkWbp5mjOK JmenyFdB7sMzNS4SGzrTPyzIbi7DwACKElwnTipXFbbdrHQyWSpBIA2Xcz7CWqOq0OWH M0famgB5UkGgBZn5XqUJcgaY2maZfPZ8PuaoXjz6ffal45oJHhPAZc6vCnAKXamcJ4BD kopkLOltegqPMe31a66kh4iE2iT+WNJhBsowRXSVg0mE3FQrmPUgHOaAmZ7b185+0YgO 6amLNVwwTOGpJxUKR/Yt0hjyJijfVqVVCX4fNdoeqFetU0VfQ0qCWzN6Spbey6B4zx0E W24A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=o4hxEGOB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b41si12430896pla.409.2019.06.18.01.44.15; Tue, 18 Jun 2019 01:44:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=o4hxEGOB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729207AbfFRIm4 (ORCPT + 99 others); Tue, 18 Jun 2019 04:42:56 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:3615 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728818AbfFRIm4 (ORCPT ); Tue, 18 Jun 2019 04:42:56 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 18 Jun 2019 01:42:55 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 18 Jun 2019 01:42:54 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 18 Jun 2019 01:42:54 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 18 Jun 2019 08:42:54 +0000 Received: from hqnvemgw02.nvidia.com (172.16.227.111) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 18 Jun 2019 08:42:54 +0000 Received: from dhcp-10-19-65-14.client.nvidia.com (Not Verified[10.19.65.14]) by hqnvemgw02.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Tue, 18 Jun 2019 01:42:54 -0700 From: Bitan Biswas To: Laxman Dewangan , Thierry Reding , Jonathan Hunter , , , , Peter Rosin , Wolfram Sang , Dmitry Osipenko CC: Shardar Mohammed , Sowjanya Komatineni , Mantravadi Karthik , Bitan Biswas Subject: [PATCH V2] i2c: tegra: disable irq in tegra_i2c_xfer_msg Date: Tue, 18 Jun 2019 01:42:48 -0700 Message-ID: <1560847368-16069-1-git-send-email-bbiswas@nvidia.com> X-Mailer: git-send-email 2.7.4 X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1560847375; bh=HqDxJokKgFe1kNELmIXIfg1rSInkOt34jaRIIaxFV6c=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: X-NVConfidentiality:MIME-Version:Content-Type; b=o4hxEGOBt4jHW3AFM4uPmORRpOmNjwGP8oUU8ZQbkzc5+fZLQ8K0vW2m4yxcTdL2o NMVJuIi4dwqn84EqY1B+FcKwYnHX1V19S4s2qwYN6O1zBEISZgxmwXO02OulJZOo2T wrsGLliKsvC0jfdv7DIRAAWKVrL77VAXbFEnEhtPjePR0e0jdXNM3RWuY/Cv3KWH+8 C4V4AHpBboog2tr0U3IlQfkMLpnFwWINn/eVbKCAjiYgusTdShVgpBcZzH1UGESC5d 40RCE7Me3Y1grrVGY/BuslqMIDDf3oqjg60CW18AlFR3s8GaUyfc/lrW+z5YmeqrGk /booCGUDRst8w== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org tegra_i2c_xfer_msg initiates the I2C transfer in DMA or PIO mode. It involves steps that need FIFO register access, DMA API calls like dma_sync_single_for_device, etc. Tegra I2C ISR has calls to tegra_i2c_empty_rx_fifo in PIO mode and in DMA/PIO mode writes different I2C registers including I2C interrupt status. ISR cannot start processing before the preparation step at tegra_i2c_xfer_msg is complete. Hence, a synchronization between ISR and tegra_i2c_xfer_msg is in place today using spinlock. Spinlock busy waits and can add avoidable delays. In this patch needed synchronization is achieved by disabling I2C interrupt during preparation step and enabling interrupt once preparation is over and spinlock is no longer needed. Signed-off-by: Bitan Biswas --- drivers/i2c/busses/i2c-tegra.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 6fb545e..ccc7fae 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -240,7 +240,6 @@ struct tegra_i2c_hw_feature { * @bus_clk_rate: current I2C bus clock rate * @clk_divisor_non_hs_mode: clock divider for non-high-speed modes * @is_multimaster_mode: track if I2C controller is in multi-master mode - * @xfer_lock: lock to serialize transfer submission and processing * @tx_dma_chan: DMA transmit channel * @rx_dma_chan: DMA receive channel * @dma_phys: handle to DMA resources @@ -270,8 +269,6 @@ struct tegra_i2c_dev { u32 bus_clk_rate; u16 clk_divisor_non_hs_mode; bool is_multimaster_mode; - /* xfer_lock: lock to serialize transfer submission and processing */ - spinlock_t xfer_lock; struct dma_chan *tx_dma_chan; struct dma_chan *rx_dma_chan; dma_addr_t dma_phys; @@ -835,7 +832,6 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) status = i2c_readl(i2c_dev, I2C_INT_STATUS); - spin_lock(&i2c_dev->xfer_lock); if (status == 0) { dev_warn(i2c_dev->dev, "irq status 0 %08x %08x %08x\n", i2c_readl(i2c_dev, I2C_PACKET_TRANSFER_STATUS), @@ -935,7 +931,6 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) complete(&i2c_dev->msg_complete); done: - spin_unlock(&i2c_dev->xfer_lock); return IRQ_HANDLED; } @@ -1054,7 +1049,6 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, u32 packet_header; u32 int_mask; unsigned long time_left; - unsigned long flags; size_t xfer_size; u32 *buffer = NULL; int err = 0; @@ -1085,7 +1079,10 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, */ xfer_time += DIV_ROUND_CLOSEST(((xfer_size * 9) + 2) * MSEC_PER_SEC, i2c_dev->bus_clk_rate); - spin_lock_irqsave(&i2c_dev->xfer_lock, flags); + if (!i2c_dev->irq_disabled) { + disable_irq_nosync(i2c_dev->irq); + i2c_dev->irq_disabled = true; + } int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; tegra_i2c_unmask_irq(i2c_dev, int_mask); @@ -1180,7 +1177,10 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_readl(i2c_dev, I2C_INT_MASK)); unlock: - spin_unlock_irqrestore(&i2c_dev->xfer_lock, flags); + if (i2c_dev->irq_disabled) { + i2c_dev->irq_disabled = false; + enable_irq(i2c_dev->irq); + } if (dma) { if (err) @@ -1576,7 +1576,6 @@ static int tegra_i2c_probe(struct platform_device *pdev) I2C_PACKET_HEADER_SIZE; init_completion(&i2c_dev->msg_complete); init_completion(&i2c_dev->dma_complete); - spin_lock_init(&i2c_dev->xfer_lock); if (!i2c_dev->hw->has_single_clk_source) { fast_clk = devm_clk_get(&pdev->dev, "fast-clk"); -- 2.7.4