Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1784194ybb; Thu, 9 Apr 2020 08:59:24 -0700 (PDT) X-Google-Smtp-Source: APiQypIRf98x6XkJO8aKA1wqTbNggSQt4ymp8ONbKG4LvH6Cv5vgVwtHA64R1SzWy63l8bH80Mu+ X-Received: by 2002:aed:2fc5:: with SMTP id m63mr24565qtd.126.1586447964603; Thu, 09 Apr 2020 08:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586447964; cv=none; d=google.com; s=arc-20160816; b=o3wCOfrWF3vZM4jNLGEtWISRPTehWnlV95GCOve3uQoCFyJntjVljJdZcPsRTOP0OZ kr8BcywVY8HNxK/zcEzb2e1mEMOeyHrKmuO3k5s6q4is8IhZTcBmK44Tw1kT5VtQ6ey4 5dlWw60eond7Ovb6hY9/EXyIYta6jPBC2kmx7PRbcSckHPSbIcKUj/MJj4nKvcKKgxDl pQdf8YaVgaNrz8ryVl2X6q/AR6VJPqyEIlGKE4k0SM3yWf6EVUInpHqzeW4ksyJyZFhX a2psgaMf8FdGRBIjlE2qWrdlsx7CiXtU2BRPul6oY/PhLStk7qM9PtDPhA7MmQv4YK7q iAUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zQj3NkQdEmz1XJI2N1VYZtyJ3wNhfxRrJ5okzYfZiLM=; b=Bu56Eb0I7pQER5OiAXz+8rLhNLx0mU99Uap1XmvN4Joed4l/QzGhsBHUebVSwSr3OJ p1VqlZlNXSDsPq+VSCYQxyjX4iYVgACKWKV9MIARTAzM2v56T1Xr0vbvtqcVh1orKZQL 0PVcj68BOAQz59cPJw/rVajttzL1bl+gCsVsaQSQ8rOEcyO8igScry+cjQ1dbknHuNva gyThc28f0rQWjOWwJeOXyjR27s+U7GyWpVaYFhzdtqdxzSEcMX9vCcrnM2Ooheg2F+ET 1S3WeFbtgcE4ludQXXRWsEd+YPze5Sitmyvr7objFPyvu7Dnk5Yu2mYpIfxL8ahAQ0Ya srtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=K7B+s05O; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si6260549qva.213.2020.04.09.08.59.10; Thu, 09 Apr 2020 08:59:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=K7B+s05O; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728343AbgDIP7H (ORCPT + 99 others); Thu, 9 Apr 2020 11:59:07 -0400 Received: from nbd.name ([46.4.11.11]:52322 "EHLO nbd.name" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727865AbgDIP7H (ORCPT ); Thu, 9 Apr 2020 11:59:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject :Cc:To:From:Sender:Reply-To:Content-Type: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=zQj3NkQdEmz1XJI2N1VYZtyJ3wNhfxRrJ5okzYfZiLM=; b=K7B+s05OMxW5UiYTxcKB4UEhmJ 7ucrRc3pN0cPQenQv7JNr9yt+kjVRbIRF+QJLkJM9JU9Tf2j3rKkoGlixy0em1jhRDjh2HHIgP2/+ Ow45BMLi/ZBVlO5C9sgZ/NEhuEry2iLemzfCWpFP4Q1RijrpR5E5iDo55Nq0ymfDx7eg=; Received: from p54ae91d1.dip0.t-ipconnect.de ([84.174.145.209] helo=maeck.lan) by ds12 with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jMZa3-0000MM-Sp; Thu, 09 Apr 2020 17:59:04 +0200 Received: by maeck.lan (Postfix, from userid 501) id 4EAA4829A4CC; Thu, 9 Apr 2020 17:59:03 +0200 (CEST) From: Felix Fietkau To: linux-wireless@vger.kernel.org Cc: Soul Huang Subject: [PATCH] mt76: mt7615: rework IRQ handling to prepare for MSI support Date: Thu, 9 Apr 2020 17:59:02 +0200 Message-Id: <20200409155902.58185-1-nbd@nbd.name> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org With MSI interrupts, IRQs must not be enabled from within the IRQ handler, because that can lead to lost events. Defer IRQ processing to a tasklet, which is also responsible for enabling IRQs (to avoid race conditions against the handler) Co-developed-by: Soul Huang Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mmio.c | 3 +- .../net/wireless/mediatek/mt76/mt7615/init.c | 2 ++ .../net/wireless/mediatek/mt76/mt7615/mmio.c | 30 +++++++++++++------ .../wireless/mediatek/mt76/mt7615/mt7615.h | 9 +++--- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mmio.c b/drivers/net/wireless/mediatek/mt76/mmio.c index 7ead6620bb8b..26353b6bce97 100644 --- a/drivers/net/wireless/mediatek/mt76/mmio.c +++ b/drivers/net/wireless/mediatek/mt76/mmio.c @@ -73,7 +73,8 @@ void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr, spin_lock_irqsave(&dev->mmio.irq_lock, flags); dev->mmio.irqmask &= ~clear; dev->mmio.irqmask |= set; - mt76_mmio_wr(dev, addr, dev->mmio.irqmask); + if (addr) + mt76_mmio_wr(dev, addr, dev->mmio.irqmask); spin_unlock_irqrestore(&dev->mmio.irq_lock, flags); } EXPORT_SYMBOL_GPL(mt76_set_irq_mask); diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/init.c b/drivers/net/wireless/mediatek/mt76/mt7615/init.c index 96b7c6284833..cb626a2d9197 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/init.c @@ -561,5 +561,7 @@ void mt7615_unregister_device(struct mt7615_dev *dev) spin_unlock_bh(&dev->token_lock); idr_destroy(&dev->token); + tasklet_disable(&dev->irq_tasklet); + mt76_free_device(&dev->mt76); } diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mmio.c b/drivers/net/wireless/mediatek/mt76/mt7615/mmio.c index 3849bb6b49d0..58506dc423ab 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mmio.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mmio.c @@ -80,30 +80,41 @@ mt7615_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q) static irqreturn_t mt7615_irq_handler(int irq, void *dev_instance) { struct mt7615_dev *dev = dev_instance; - u32 intr; - - intr = mt76_rr(dev, MT_INT_SOURCE_CSR); - mt76_wr(dev, MT_INT_SOURCE_CSR, intr); if (!test_bit(MT76_STATE_INITIALIZED, &dev->mphy.state)) return IRQ_NONE; - trace_dev_irq(&dev->mt76, intr, dev->mt76.mmio.irqmask); + mt76_wr(dev, MT_INT_MASK_CSR, 0); + tasklet_schedule(&dev->irq_tasklet); + return IRQ_HANDLED; +} + +static void mt7615_irq_tasklet(unsigned long data) +{ + struct mt7615_dev *dev = (struct mt7615_dev *)data; + u32 intr, mask = 0; + + mt76_wr(dev, MT_INT_MASK_CSR, 0); + + intr = mt76_rr(dev, MT_INT_SOURCE_CSR); + mt76_wr(dev, MT_INT_SOURCE_CSR, intr); + + trace_dev_irq(&dev->mt76, intr, dev->mt76.mmio.irqmask); intr &= dev->mt76.mmio.irqmask; if (intr & MT_INT_TX_DONE_ALL) { - mt7615_irq_disable(dev, MT_INT_TX_DONE_ALL); + mask |= MT_INT_TX_DONE_ALL; napi_schedule(&dev->mt76.tx_napi); } if (intr & MT_INT_RX_DONE(0)) { - mt7615_irq_disable(dev, MT_INT_RX_DONE(0)); + mask |= MT_INT_RX_DONE(0); napi_schedule(&dev->mt76.napi[0]); } if (intr & MT_INT_RX_DONE(1)) { - mt7615_irq_disable(dev, MT_INT_RX_DONE(1)); + mask |= MT_INT_RX_DONE(1); napi_schedule(&dev->mt76.napi[1]); } @@ -117,7 +128,7 @@ static irqreturn_t mt7615_irq_handler(int irq, void *dev_instance) } } - return IRQ_HANDLED; + mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0); } int mt7615_mmio_probe(struct device *pdev, void __iomem *mem_base, @@ -154,6 +165,7 @@ int mt7615_mmio_probe(struct device *pdev, void __iomem *mem_base, dev = container_of(mdev, struct mt7615_dev, mt76); mt76_mmio_init(&dev->mt76, mem_base); + tasklet_init(&dev->irq_tasklet, mt7615_irq_tasklet, (unsigned long)dev); dev->reg_map = map; dev->ops = ops; diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h index 4f0d29e5e595..10a98d38f77e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h @@ -229,6 +229,8 @@ struct mt7615_dev { struct mt76_phy mphy; }; + struct tasklet_struct irq_tasklet; + struct mt7615_phy phy; u32 vif_mask; u32 omac_mask; @@ -404,12 +406,9 @@ static inline bool is_mt7663(struct mt76_dev *dev) static inline void mt7615_irq_enable(struct mt7615_dev *dev, u32 mask) { - mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask); -} + mt76_set_irq_mask(&dev->mt76, 0, 0, mask); -static inline void mt7615_irq_disable(struct mt7615_dev *dev, u32 mask) -{ - mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0); + tasklet_schedule(&dev->irq_tasklet); } static inline bool mt7615_firmware_offload(struct mt7615_dev *dev) -- 2.24.0