From patchwork Fri Jun 26 21:25:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 215228 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B8C1C433E1 for ; Fri, 26 Jun 2020 21:25:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB4FA212CC for ; Fri, 26 Jun 2020 21:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206737; bh=CxpFfMpM2Kch9ViP8mk2zlgAoNMNqzZ7GfJbgeo/4kc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=tgb0BQ3B7/zoYnOTM+lNvVMAcmqCY09kIcvM5pSEsorqIJx1zZGfuVWC7c3D6/5J2 UL1eoZJKlhSzIr9O3QpF4n8mC9YUTb3vXm0XHG3LDQT6dW1hV4SjL1zSrIlBNjuIl2 bOILB9FccCtK0/5TWQ7cXaQVVml4g9AiGNmWonm0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726315AbgFZVZh (ORCPT ); Fri, 26 Jun 2020 17:25:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:33648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725793AbgFZVZg (ORCPT ); Fri, 26 Jun 2020 17:25:36 -0400 Received: from localhost.localdomain.com (unknown [151.48.138.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8104D20C09; Fri, 26 Jun 2020 21:25:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206735; bh=CxpFfMpM2Kch9ViP8mk2zlgAoNMNqzZ7GfJbgeo/4kc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rLprkZ186WZemqO50MoinHZaoN87k1PdzIherGNO+CF5h6GFMDhu4tk/phpGFkA5V qtAbw/RlihQ7c8tu12BJemodr5GjoUVD9jXGFl8cfbfZOEAiJXX9g0RSdpX0MpCCHG 8zoeGb3HgBKSTFkeFBxPQpyescmUwJIv8CefqaQg= From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com, ryder.lee@mediatek.com, linux-mediatek@lists.infradead.org Subject: [PATCH 02/17] mt76: move mt76 worqueue in common code Date: Fri, 26 Jun 2020 23:25:02 +0200 Message-Id: <648c2d720e030bdd1206bb46dddd0cce1038c078.1593204577.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Move mt76 worqueue from usb to common code in order to be reused adding low-power support for mt7663 chipset Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mac80211.c | 11 +++++++++- drivers/net/wireless/mediatek/mt76/mt76.h | 4 ++-- .../net/wireless/mediatek/mt76/mt7615/mac.c | 2 +- .../net/wireless/mediatek/mt76/mt7615/main.c | 2 +- .../net/wireless/mediatek/mt76/mt7615/usb.c | 6 ++---- .../net/wireless/mediatek/mt76/mt76x0/usb.c | 6 ++---- .../net/wireless/mediatek/mt76/mt76x2/usb.c | 7 ++----- drivers/net/wireless/mediatek/mt76/usb.c | 20 ++++--------------- 8 files changed, 24 insertions(+), 34 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index 10e6dbb64996..a15862920f19 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -437,6 +437,12 @@ mt76_alloc_device(struct device *pdev, unsigned int size, tasklet_init(&dev->tx_tasklet, mt76_tx_tasklet, (unsigned long)dev); + dev->wq = alloc_ordered_workqueue("mt76", 0); + if (!dev->wq) { + ieee80211_free_hw(hw); + return NULL; + } + return dev; } EXPORT_SYMBOL_GPL(mt76_alloc_device); @@ -490,7 +496,10 @@ EXPORT_SYMBOL_GPL(mt76_unregister_device); void mt76_free_device(struct mt76_dev *dev) { - mt76_tx_free(dev); + if (dev->wq) + destroy_workqueue(dev->wq); + if (mt76_is_mmio(dev)) + mt76_tx_free(dev); ieee80211_free_hw(dev->hw); } EXPORT_SYMBOL_GPL(mt76_free_device); diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 0dc43e474976..f7be1d5f71a0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -424,7 +424,6 @@ struct mt76_usb { u16 data_len; struct tasklet_struct rx_tasklet; - struct workqueue_struct *wq; struct work_struct stat_work; u8 out_ep[__MT_EP_OUT_MAX]; @@ -623,6 +622,8 @@ struct mt76_dev { struct mt76_testmode_data test; #endif + struct workqueue_struct *wq; + union { struct mt76_mmio mmio; struct mt76_usb usb; @@ -1027,7 +1028,6 @@ int mt76u_vendor_request(struct mt76_dev *dev, u8 req, void *buf, size_t len); void mt76u_single_wr(struct mt76_dev *dev, const u8 req, const u16 offset, const u32 val); -void mt76u_deinit(struct mt76_dev *dev); int mt76u_init(struct mt76_dev *dev, struct usb_interface *intf, bool ext); int mt76u_alloc_mcu_queue(struct mt76_dev *dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index 9d74a6550cf0..c1a802366172 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -927,7 +927,7 @@ mt7615_mac_queue_rate_update(struct mt7615_phy *phy, struct mt7615_sta *sta, mt7615_mac_update_rate_desc(phy, sta, probe_rate, rates, &wd->rate); list_add_tail(&wd->node, &dev->wd_head); - queue_work(dev->mt76.usb.wq, &dev->wtbl_work); + queue_work(dev->mt76.wq, &dev->wtbl_work); return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/main.c b/drivers/net/wireless/mediatek/mt76/mt7615/main.c index 3abb33ddab7d..3bcbd13c26d7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/main.c @@ -319,7 +319,7 @@ mt7615_queue_key_update(struct mt7615_dev *dev, enum set_key_cmd cmd, wd->key.cmd = cmd; list_add_tail(&wd->node, &dev->wd_head); - queue_work(dev->mt76.usb.wq, &dev->wtbl_work); + queue_work(dev->mt76.wq, &dev->wtbl_work); return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c index 0ba28d37c414..f70a7d9d65e2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c @@ -349,11 +349,10 @@ static int mt7663u_probe(struct usb_interface *usb_intf, error_freeq: mt76u_queues_deinit(&dev->mt76); error: - mt76u_deinit(&dev->mt76); usb_set_intfdata(usb_intf, NULL); usb_put_dev(interface_to_usbdev(usb_intf)); - ieee80211_free_hw(mdev->hw); + mt76_free_device(&dev->mt76); return ret; } @@ -371,8 +370,7 @@ static void mt7663u_disconnect(struct usb_interface *usb_intf) usb_set_intfdata(usb_intf, NULL); usb_put_dev(interface_to_usbdev(usb_intf)); - mt76u_deinit(&dev->mt76); - ieee80211_free_hw(dev->mt76.hw); + mt76_free_device(&dev->mt76); } #ifdef CONFIG_PM diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c index 5535b9c0632f..ce6b286a8152 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c @@ -277,9 +277,8 @@ static int mt76x0u_probe(struct usb_interface *usb_intf, err: usb_set_intfdata(usb_intf, NULL); usb_put_dev(interface_to_usbdev(usb_intf)); - mt76u_deinit(&dev->mt76); + mt76_free_device(&dev->mt76); - ieee80211_free_hw(mdev->hw); return ret; } @@ -297,8 +296,7 @@ static void mt76x0_disconnect(struct usb_interface *usb_intf) usb_set_intfdata(usb_intf, NULL); usb_put_dev(interface_to_usbdev(usb_intf)); - mt76u_deinit(&dev->mt76); - ieee80211_free_hw(dev->mt76.hw); + mt76_free_device(&dev->mt76); } static int __maybe_unused mt76x0_suspend(struct usb_interface *usb_intf, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c index 3a4e41724af1..0be4afef5e6f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c @@ -74,8 +74,7 @@ static int mt76x2u_probe(struct usb_interface *intf, return 0; err: - ieee80211_free_hw(mt76_hw(dev)); - mt76u_deinit(&dev->mt76); + mt76_free_device(&dev->mt76); usb_set_intfdata(intf, NULL); usb_put_dev(udev); @@ -91,9 +90,7 @@ static void mt76x2u_disconnect(struct usb_interface *intf) set_bit(MT76_REMOVED, &dev->mphy.state); ieee80211_unregister_hw(hw); mt76x2u_cleanup(dev); - mt76u_deinit(&dev->mt76); - - ieee80211_free_hw(hw); + mt76_free_device(&dev->mt76); usb_set_intfdata(intf, NULL); usb_put_dev(udev); } diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index 0ff3096f7455..84e2fd0a4fc1 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -842,7 +842,7 @@ static void mt76u_tx_tasklet(unsigned long data) if (dev->drv->tx_status_data && !test_and_set_bit(MT76_READING_STATS, &dev->phy.state)) - queue_work(dev->usb.wq, &dev->usb.stat_work); + queue_work(dev->wq, &dev->usb.stat_work); if (wake) ieee80211_wake_queue(dev->hw, i); } @@ -868,7 +868,7 @@ static void mt76u_tx_status_data(struct work_struct *work) } if (count && test_bit(MT76_STATE_RUNNING, &dev->phy.state)) - queue_work(usb->wq, &usb->stat_work); + queue_work(dev->wq, &usb->stat_work); else clear_bit(MT76_READING_STATS, &dev->phy.state); } @@ -1132,15 +1132,6 @@ static const struct mt76_queue_ops usb_queue_ops = { .kick = mt76u_tx_kick, }; -void mt76u_deinit(struct mt76_dev *dev) -{ - if (dev->usb.wq) { - destroy_workqueue(dev->usb.wq); - dev->usb.wq = NULL; - } -} -EXPORT_SYMBOL_GPL(mt76u_deinit); - int mt76u_init(struct mt76_dev *dev, struct usb_interface *intf, bool ext) { @@ -1163,10 +1154,6 @@ int mt76u_init(struct mt76_dev *dev, tasklet_init(&dev->tx_tasklet, mt76u_tx_tasklet, (unsigned long)dev); INIT_WORK(&usb->stat_work, mt76u_tx_status_data); - usb->wq = alloc_workqueue("mt76u", WQ_UNBOUND, 0); - if (!usb->wq) - return -ENOMEM; - usb->data_len = usb_maxpacket(udev, usb_sndctrlpipe(udev, 0), 1); if (usb->data_len < 32) usb->data_len = 32; @@ -1190,7 +1177,8 @@ int mt76u_init(struct mt76_dev *dev, return 0; error: - mt76u_deinit(dev); + destroy_workqueue(dev->wq); + return err; } EXPORT_SYMBOL_GPL(mt76u_init); From patchwork Fri Jun 26 21:25:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 215227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7AA0C433E0 for ; Fri, 26 Jun 2020 21:25:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB0E720C09 for ; Fri, 26 Jun 2020 21:25:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206741; bh=iyIePkMiM9mLtY9jRWUeJSht04YE6OWXCxHNJb6+clE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=It/Ug7OfuoPj2vRRVe+AbIPK5aq7hqqxud/37Q9ay4GWJRd6uxiNEPEw3Ty6XfGH0 M++KAC/AbfqDrjvw2a1xoPv0XJS21kmObn0Cr6s/O8uftYj7+wEznELKpIOnG5zLCZ qTvzZPr/vPrkuep7qwxVM82T5NRLveIqpDEUEKcc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726342AbgFZVZl (ORCPT ); Fri, 26 Jun 2020 17:25:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:33730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725793AbgFZVZk (ORCPT ); Fri, 26 Jun 2020 17:25:40 -0400 Received: from localhost.localdomain.com (unknown [151.48.138.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 176CB2100A; Fri, 26 Jun 2020 21:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206739; bh=iyIePkMiM9mLtY9jRWUeJSht04YE6OWXCxHNJb6+clE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O8tsnUshw5AvSyctmW2e+F91j2Fyh9lcPj3J/aIn275mfXLYalwEMvYxmeLwF98wb tpXrJQKLFwLr0N/V2Xuij720+OTKB8AGIrIGrZW8wwkEkbCbda9JvU7Dl+xFWYf1QQ 1HIdTUwZMqnbyP7c+Z6IREfRSih9h9GUiNEOTPqc= From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com, ryder.lee@mediatek.com, linux-mediatek@lists.infradead.org Subject: [PATCH 04/17] mt76: mt7615: introduce mt7615_mutex_{acquire, release} utilities Date: Fri, 26 Jun 2020 23:25:04 +0200 Message-Id: <6a99ada6c2ef43c741bf2c0847e7b11c1d0c68eb.1593204577.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Introduce mt7615_mutex_{acquire,release} utility routines in order to switch in full-power/low-power before/after accessing device register-map Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt7615/mac.c | 12 +-- .../net/wireless/mediatek/mt76/mt7615/main.c | 83 ++++++++++--------- .../net/wireless/mediatek/mt76/mt7615/mcu.c | 5 +- .../wireless/mediatek/mt76/mt7615/mt7615.h | 18 ++++ .../net/wireless/mediatek/mt76/mt7615/usb.c | 11 +-- .../wireless/mediatek/mt76/mt7615/usb_mcu.c | 4 +- 6 files changed, 79 insertions(+), 54 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index 4d8cd88473dd..8910604719b1 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -1530,7 +1530,7 @@ void mt7615_mac_set_scs(struct mt7615_phy *phy, bool enable) bool ext_phy = phy != &dev->phy; u32 reg, mask; - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); if (phy->scs_en == enable) goto out; @@ -1557,7 +1557,7 @@ void mt7615_mac_set_scs(struct mt7615_phy *phy, bool enable) phy->scs_en = enable; out: - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); } void mt7615_mac_enable_nf(struct mt7615_dev *dev, bool ext_phy) @@ -1859,7 +1859,7 @@ void mt7615_mac_work(struct work_struct *work) mac_work.work); mdev = &phy->dev->mt76; - mutex_lock(&mdev->mutex); + mt7615_mutex_acquire(phy->dev, &mdev->mutex); mt76_update_survey(mdev); if (++phy->mac_work_count == 5) { @@ -1869,7 +1869,7 @@ void mt7615_mac_work(struct work_struct *work) mt7615_mac_scs_check(phy); } - mutex_unlock(&mdev->mutex); + mt7615_mutex_release(phy->dev, &mdev->mutex); mt76_tx_status_check(mdev, NULL, false); ieee80211_queue_delayed_work(phy->mt76->hw, &phy->mac_work, @@ -1973,7 +1973,7 @@ void mt7615_mac_reset_work(struct work_struct *work) napi_disable(&dev->mt76.napi[1]); napi_disable(&dev->mt76.tx_napi); - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); mt76_wr(dev, MT_MCU_INT_EVENT, MT_MCU_INT_EVENT_PDMA_STOPPED); @@ -2006,7 +2006,7 @@ void mt7615_mac_reset_work(struct work_struct *work) mt76_wr(dev, MT_MCU_INT_EVENT, MT_MCU_INT_EVENT_RESET_DONE); mt7615_wait_reset_state(dev, MT_MCU_CMD_NORMAL_STATE); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); mt7615_update_beacons(dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/main.c b/drivers/net/wireless/mediatek/mt76/mt7615/main.c index 1e7f7b9b1388..b63dc12a0342 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/main.c @@ -33,7 +33,7 @@ static int mt7615_start(struct ieee80211_hw *hw) if (!mt7615_wait_for_mcu_init(dev)) return -EIO; - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); running = mt7615_dev_running(dev); @@ -60,7 +60,7 @@ static int mt7615_start(struct ieee80211_hw *hw) if (!running) mt7615_mac_reset_counters(dev); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); return 0; } @@ -76,7 +76,7 @@ static void mt7615_stop(struct ieee80211_hw *hw) cancel_work_sync(&dev->pm.wake_work); - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); mt76_testmode_reset(&dev->mt76, true); @@ -93,7 +93,7 @@ static void mt7615_stop(struct ieee80211_hw *hw) mt7615_mcu_set_mac_enable(dev, 0, false); } - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); } static int get_omac_idx(enum nl80211_iftype type, u32 mask) @@ -139,7 +139,7 @@ static int mt7615_add_interface(struct ieee80211_hw *hw, bool ext_phy = phy != &dev->phy; int idx, ret = 0; - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); mt76_testmode_reset(&dev->mt76, true); @@ -191,7 +191,7 @@ static int mt7615_add_interface(struct ieee80211_hw *hw, ret = mt7615_mcu_add_dev_info(dev, vif, true); out: - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); return ret; } @@ -207,9 +207,9 @@ static void mt7615_remove_interface(struct ieee80211_hw *hw, /* TODO: disable beacon for the bss */ - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); mt76_testmode_reset(&dev->mt76, true); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); if (vif == phy->monitor_vif) phy->monitor_vif = NULL; @@ -220,11 +220,13 @@ static void mt7615_remove_interface(struct ieee80211_hw *hw, if (vif->txq) mt76_txq_remove(&dev->mt76, vif->txq); - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); + dev->mphy.vif_mask &= ~BIT(mvif->idx); dev->omac_mask &= ~BIT(mvif->omac_idx); phy->omac_mask &= ~BIT(mvif->omac_idx); - mutex_unlock(&dev->mt76.mutex); + + mt7615_mutex_release(dev, &dev->mt76.mutex); spin_lock_bh(&dev->sta_poll_lock); if (!list_empty(&msta->poll_list)) @@ -259,7 +261,8 @@ int mt7615_set_channel(struct mt7615_phy *phy) cancel_delayed_work_sync(&phy->mac_work); - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); + set_bit(MT76_RESET, &phy->mt76->state); mt7615_init_dfs_state(phy); @@ -285,7 +288,8 @@ int mt7615_set_channel(struct mt7615_phy *phy) out: clear_bit(MT76_RESET, &phy->mt76->state); - mutex_unlock(&dev->mt76.mutex); + + mt7615_mutex_release(dev, &dev->mt76.mutex); mt76_txq_schedule_all(phy->mt76); @@ -391,9 +395,9 @@ static int mt7615_config(struct ieee80211_hw *hw, u32 changed) IEEE80211_CONF_CHANGE_POWER)) { #ifdef CONFIG_NL80211_TESTMODE if (dev->mt76.test.state != MT76_TM_STATE_OFF) { - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); mt76_testmode_reset(&dev->mt76, false); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); } #endif ieee80211_stop_queues(hw); @@ -401,7 +405,7 @@ static int mt7615_config(struct ieee80211_hw *hw, u32 changed) ieee80211_wake_queues(hw); } - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); if (changed & IEEE80211_CONF_CHANGE_MONITOR) { mt76_testmode_reset(&dev->mt76, true); @@ -414,7 +418,7 @@ static int mt7615_config(struct ieee80211_hw *hw, u32 changed) mt76_wr(dev, MT_WF_RFCR(band), phy->rxfilter); } - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); return ret; } @@ -448,7 +452,7 @@ static void mt7615_configure_filter(struct ieee80211_hw *hw, MT_WF_RFCR1_DROP_CFACK; u32 flags = 0; - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); #define MT76_FILTER(_flag, _hw) do { \ flags |= *total_flags & FIF_##_flag; \ @@ -488,7 +492,7 @@ static void mt7615_configure_filter(struct ieee80211_hw *hw, else mt76_set(dev, MT_WF_RFCR1(band), ctl_flags); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); } static void mt7615_bss_info_changed(struct ieee80211_hw *hw, @@ -499,7 +503,7 @@ static void mt7615_bss_info_changed(struct ieee80211_hw *hw, struct mt7615_dev *dev = mt7615_hw_dev(hw); struct mt7615_phy *phy = mt7615_hw_phy(hw); - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); if (changed & BSS_CHANGED_ERP_SLOT) { int slottime = info->use_short_slot ? 9 : 20; @@ -528,7 +532,7 @@ static void mt7615_bss_info_changed(struct ieee80211_hw *hw, if (changed & BSS_CHANGED_ARP_FILTER) mt7615_mcu_update_arp_filter(hw, vif, info); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); } static void @@ -538,9 +542,9 @@ mt7615_channel_switch_beacon(struct ieee80211_hw *hw, { struct mt7615_dev *dev = mt7615_hw_dev(hw); - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); mt7615_mcu_add_beacon(dev, hw, vif, true); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); } int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, @@ -656,9 +660,9 @@ static int mt7615_set_rts_threshold(struct ieee80211_hw *hw, u32 val) struct mt7615_dev *dev = mt7615_hw_dev(hw); struct mt7615_phy *phy = mt7615_hw_phy(hw); - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); mt7615_mcu_set_rts_thresh(phy, val); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); return 0; } @@ -682,7 +686,8 @@ mt7615_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mtxq = (struct mt76_txq *)txq->drv_priv; - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); + switch (action) { case IEEE80211_AMPDU_RX_START: mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn, @@ -718,7 +723,7 @@ mt7615_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); break; } - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); return ret; } @@ -763,13 +768,13 @@ mt7615_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) u32 t32[2]; } tsf; - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); mt76_set(dev, MT_LPON_T0CR, MT_LPON_T0CR_MODE); /* TSF read */ tsf.t32[0] = mt76_rr(dev, MT_LPON_UTTR0); tsf.t32[1] = mt76_rr(dev, MT_LPON_UTTR1); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); return tsf.t64; } @@ -784,14 +789,14 @@ mt7615_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u32 t32[2]; } tsf = { .t64 = timestamp, }; - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); mt76_wr(dev, MT_LPON_UTTR0, tsf.t32[0]); mt76_wr(dev, MT_LPON_UTTR1, tsf.t32[1]); /* TSF software overwrite */ mt76_set(dev, MT_LPON_T0CR, MT_LPON_T0CR_WRITE); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); } static void @@ -800,10 +805,10 @@ mt7615_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class) struct mt7615_phy *phy = mt7615_hw_phy(hw); struct mt7615_dev *dev = phy->dev; - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); phy->coverage_class = max_t(s16, coverage_class, 0); mt7615_mac_set_timing(phy); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); } static int @@ -820,7 +825,7 @@ mt7615_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) if ((BIT(hweight8(tx_ant)) - 1) != tx_ant) tx_ant = BIT(ffs(tx_ant) - 1) - 1; - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); phy->mt76->antenna_mask = tx_ant; if (ext_phy) { @@ -833,7 +838,7 @@ mt7615_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) mt76_set_stream_caps(phy->mt76, true); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); return 0; } @@ -995,7 +1000,7 @@ static int mt7615_suspend(struct ieee80211_hw *hw, bool ext_phy = phy != &dev->phy; int err = 0; - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); cancel_delayed_work_sync(&phy->scan_work); @@ -1011,7 +1016,7 @@ static int mt7615_suspend(struct ieee80211_hw *hw, if (!mt7615_dev_running(dev)) err = mt7615_mcu_set_hif_suspend(dev, true); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); return err; } @@ -1022,7 +1027,7 @@ static int mt7615_resume(struct ieee80211_hw *hw) struct mt7615_phy *phy = mt7615_hw_phy(hw); bool running, ext_phy = phy != &dev->phy; - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); running = mt7615_dev_running(dev); set_bit(MT76_STATE_RUNNING, &phy->mt76->state); @@ -1032,7 +1037,7 @@ static int mt7615_resume(struct ieee80211_hw *hw) err = mt7615_mcu_set_hif_suspend(dev, false); if (err < 0) { - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); return err; } } @@ -1046,7 +1051,7 @@ static int mt7615_resume(struct ieee80211_hw *hw) MT7615_WATCHDOG_TIME); mt76_clear(dev, MT_WF_RFCR(ext_phy), MT_WF_RFCR_DROP_OTHER_BEACON); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c index b72c824e5c15..3c356a08e71e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c @@ -250,7 +250,7 @@ mt7615_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb, struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76); int ret, seq; - mutex_lock(&mdev->mcu.mutex); + mt7615_mutex_acquire(dev, &mdev->mcu.mutex); ret = __mt7615_mcu_msg_send(dev, skb, cmd, &seq); if (ret) @@ -260,7 +260,7 @@ mt7615_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb, ret = mt7615_mcu_wait_response(dev, cmd, seq); out: - mutex_unlock(&mdev->mcu.mutex); + mt7615_mutex_release(dev, &mdev->mcu.mutex); return ret; } @@ -1937,6 +1937,7 @@ int mt7615_driver_own(struct mt7615_dev *dev) out: mt7622_trigger_hif_int(dev, false); + dev->pm.last_activity = jiffies; return err; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h index 194ae43091d6..8e473bb41a5d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h @@ -301,6 +301,8 @@ struct mt7615_dev { struct { struct work_struct wake_work; struct completion wake_cmpl; + + unsigned long last_activity; } pm; }; @@ -487,6 +489,22 @@ static inline u16 mt7615_wtbl_size(struct mt7615_dev *dev) return MT7615_WTBL_SIZE; } +static inline void +mt7615_mutex_acquire(struct mt7615_dev *dev, struct mutex *mutex) + __acquires(mutex) +{ + mutex_lock(mutex); + mt7615_pm_wake(dev); +} + +static inline void +mt7615_mutex_release(struct mt7615_dev *dev, struct mutex *mutex) + __releases(mutex) +{ + dev->pm.last_activity = jiffies; + mutex_unlock(mutex); +} + static inline u8 mt7615_lmac_mapping(struct mt7615_dev *dev, u8 ac) { static const u8 lmac_queue_map[] = { diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c index f70a7d9d65e2..4b7b835c3d0f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c @@ -201,12 +201,13 @@ void mt7663u_wtbl_work(struct work_struct *work) dev = (struct mt7615_dev *)container_of(work, struct mt7615_dev, wtbl_work); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); + list_for_each_entry_safe(wd, wd_next, &dev->wd_head, node) { spin_lock_bh(&dev->mt76.lock); list_del(&wd->node); spin_unlock_bh(&dev->mt76.lock); - mutex_lock(&dev->mt76.mutex); switch (wd->type) { case MT7615_WTBL_RATE_DESC: __mt7663u_mac_set_rates(dev, wd); @@ -215,10 +216,10 @@ void mt7663u_wtbl_work(struct work_struct *work) __mt7663u_mac_set_key(dev, wd); break; } - mutex_unlock(&dev->mt76.mutex); - kfree(wd); } + + mt7615_mutex_release(dev, &dev->mt76.mutex); } static void @@ -257,9 +258,9 @@ static bool mt7663u_tx_status_data(struct mt76_dev *mdev, u8 *update) { struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76); - mutex_lock(&dev->mt76.mutex); + mt7615_mutex_acquire(dev, &dev->mt76.mutex); mt7615_mac_sta_poll(dev); - mutex_unlock(&dev->mt76.mutex); + mt7615_mutex_release(dev, &dev->mt76.mutex); return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/usb_mcu.c b/drivers/net/wireless/mediatek/mt76/mt7615/usb_mcu.c index cd709fd617db..dab1df8975ff 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/usb_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/usb_mcu.c @@ -20,7 +20,7 @@ mt7663u_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb, struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76); int ret, seq, ep; - mutex_lock(&mdev->mcu.mutex); + mt7615_mutex_acquire(dev, &mdev->mcu.mutex); mt7615_mcu_fill_msg(dev, skb, cmd, &seq); if (cmd != MCU_CMD_FW_SCATTER) @@ -42,7 +42,7 @@ mt7663u_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb, ret = mt7615_mcu_wait_response(dev, cmd, seq); out: - mutex_unlock(&mdev->mcu.mutex); + mt7615_mutex_release(dev, &mdev->mcu.mutex); return ret; } From patchwork Fri Jun 26 21:25:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 215226 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AE74C433DF for ; Fri, 26 Jun 2020 21:25:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F01952100A for ; Fri, 26 Jun 2020 21:25:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206745; bh=pPcCbVgcEboVVAYAy++sxqhrZnM4Fe9FZuWUms+LUgg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=i3TRSmA2xyODYTRecfYiMb4os3n4qRKokbqMfpV2iDjwG509hK0PbGf1uyYaSOyaB XQfINrrPsnUaKQGT5c3XdDO6Tgqes8z5zlMSsKu77jhOcPsL042GD7J2PEWYKJRwH9 4aWTYWUDviwTFOQVCyXq5sJEqnVLy3uDCpOgKK/I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726196AbgFZVZo (ORCPT ); Fri, 26 Jun 2020 17:25:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:33778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725793AbgFZVZn (ORCPT ); Fri, 26 Jun 2020 17:25:43 -0400 Received: from localhost.localdomain.com (unknown [151.48.138.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 15B2320B80; Fri, 26 Jun 2020 21:25:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206743; bh=pPcCbVgcEboVVAYAy++sxqhrZnM4Fe9FZuWUms+LUgg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rQP3kyCkAB2lMx3iSm2r/fynLQIO/I2M8DkFhv2miI8rI+zBSOd3NpiupR4m5yFMU Om/NvacGc6P0YdDeW4zYXP9KiDObky2liv+lP9Qn4l8bYiVBu+nHOD7ylV29wAl15W n4q3z9UOYOkGt9KkhmPrTzklHRTnItqb26sHkkWQ= From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com, ryder.lee@mediatek.com, linux-mediatek@lists.infradead.org Subject: [PATCH 06/17] mt76: mt7615: wake device before configuring hw keys Date: Fri, 26 Jun 2020 23:25:06 +0200 Message-Id: <0bc5bc1f94fa2bcaa0abc51a5bada9f921135471.1593204577.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Make sure the device is in full-power before uploading keys to the hw Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt7615/main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/main.c b/drivers/net/wireless/mediatek/mt76/mt7615/main.c index b63dc12a0342..8ac63ea7cbb8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/main.c @@ -339,7 +339,7 @@ static int mt7615_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, struct mt7615_sta *msta = sta ? (struct mt7615_sta *)sta->drv_priv : &mvif->sta; struct mt76_wcid *wcid = &msta->wcid; - int idx = key->keyidx; + int idx = key->keyidx, err; /* The hardware does not support per-STA RX GTK, fallback * to software mode for these. @@ -369,6 +369,8 @@ static int mt7615_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, return -EOPNOTSUPP; } + mt7615_mutex_acquire(dev, &dev->mt76.mutex); + if (cmd == SET_KEY) { key->hw_key_idx = wcid->idx; wcid->hw_key_idx = idx; @@ -379,9 +381,13 @@ static int mt7615_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, cmd == SET_KEY ? key : NULL); if (mt76_is_usb(&dev->mt76)) - return mt7615_queue_key_update(dev, cmd, msta, key); + err = mt7615_queue_key_update(dev, cmd, msta, key); + else + err = mt7615_mac_wtbl_set_key(dev, wcid, key, cmd); - return mt7615_mac_wtbl_set_key(dev, wcid, key, cmd); + mt7615_mutex_release(dev, &dev->mt76.mutex); + + return err; } static int mt7615_config(struct ieee80211_hw *hw, u32 changed) From patchwork Fri Jun 26 21:25:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 215225 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D45C6C433E0 for ; Fri, 26 Jun 2020 21:25:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B592220C09 for ; Fri, 26 Jun 2020 21:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206748; bh=yXAfdIvDyV/FPxignSW9Iry1OtUEOEJLOKVKITh448o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Aj/5HCJowWAVajkWqRKw+YPI9Tw4Scs1MqtWodwKwzRearbKeZRsfuvYfqEFhVQsZ 9XYt1bO9YX3mAIPNKQyEZRXZ6n1y53ba5DKayiG7Wv/H62yN2lTyq/DzURTe3CZn70 j83XzXmzKSyNR3Gs5Ds0h2NXza0wE5Bm0Ac5Ig5c= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726364AbgFZVZs (ORCPT ); Fri, 26 Jun 2020 17:25:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:33848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725793AbgFZVZr (ORCPT ); Fri, 26 Jun 2020 17:25:47 -0400 Received: from localhost.localdomain.com (unknown [151.48.138.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9D04120B1F; Fri, 26 Jun 2020 21:25:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206747; bh=yXAfdIvDyV/FPxignSW9Iry1OtUEOEJLOKVKITh448o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nJzsRCreUYgg+ZMt8fU77fTaG3K9hjFM2z7NmHi+S+QVA4tNchelAl0dMN94wnHmM 0SU7G8H6iZvL8wNuySJqmkxPih7YVxE6u+1wbn8bYLY76z2FT7QhZiugFc7Xl4Yq/r Vf2YUqZ2x7t6WqTGL2b4j+0AIxsdxIEc8X9LHG7Q= From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com, ryder.lee@mediatek.com, linux-mediatek@lists.infradead.org Subject: [PATCH 08/17] mt76: mt7615: wake device in mt7615_update_channel before access regmap Date: Fri, 26 Jun 2020 23:25:08 +0200 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Introduce mt7615_update_survey utility routine in order to compute survey stats without waking up the device since it runs holding mt76 lock. Run mt7615_pm_wake directly in mt7615_update_channel since it can run with mt76.mutex held if called by mac80211 Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mac80211.c | 4 +-- drivers/net/wireless/mediatek/mt76/mt76.h | 1 + .../net/wireless/mediatek/mt76/mt7615/mac.c | 30 +++++++++++++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index a15862920f19..fecdd91cdf5f 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -558,8 +558,7 @@ mt76_channel_state(struct mt76_phy *phy, struct ieee80211_channel *c) return &msband->chan[idx]; } -static void -mt76_update_survey_active_time(struct mt76_phy *phy, ktime_t time) +void mt76_update_survey_active_time(struct mt76_phy *phy, ktime_t time) { struct mt76_channel_state *state = phy->chan_state; @@ -567,6 +566,7 @@ mt76_update_survey_active_time(struct mt76_phy *phy, ktime_t time) phy->survey_time)); phy->survey_time = time; } +EXPORT_SYMBOL_GPL(mt76_update_survey_active_time); void mt76_update_survey(struct mt76_dev *dev) { diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 265ee55d22f1..c6e44283bd5f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -893,6 +893,7 @@ void mt76_release_buffered_frames(struct ieee80211_hw *hw, bool mt76_has_tx_pending(struct mt76_phy *phy); void mt76_set_channel(struct mt76_phy *phy); void mt76_update_survey(struct mt76_dev *dev); +void mt76_update_survey_active_time(struct mt76_phy *phy, ktime_t time); int mt76_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey); void mt76_set_stream_caps(struct mt76_phy *phy, bool vht); diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index 7804928f54d8..acefcc2e571a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -1747,9 +1747,9 @@ mt7615_phy_update_channel(struct mt76_phy *mphy, int idx) state->noise = -(phy->noise >> 4); } -void mt7615_update_channel(struct mt76_dev *mdev) +static void __mt7615_update_channel(struct mt7615_dev *dev) { - struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76); + struct mt76_dev *mdev = &dev->mt76; mt7615_phy_update_channel(&mdev->phy, 0); if (mdev->phy2) @@ -1758,8 +1758,32 @@ void mt7615_update_channel(struct mt76_dev *mdev) /* reset obss airtime */ mt76_set(dev, MT_WF_RMAC_MIB_TIME0, MT_WF_RMAC_MIB_RXTIME_CLR); } + +void mt7615_update_channel(struct mt76_dev *mdev) +{ + struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76); + + if (mt7615_pm_wake(dev)) + return; + + __mt7615_update_channel(dev); + mt7615_pm_power_save_sched(dev); +} EXPORT_SYMBOL_GPL(mt7615_update_channel); +static void mt7615_update_survey(struct mt7615_dev *dev) +{ + struct mt76_dev *mdev = &dev->mt76; + ktime_t cur_time; + + __mt7615_update_channel(dev); + cur_time = ktime_get_boottime(); + + mt76_update_survey_active_time(&mdev->phy, cur_time); + if (mdev->phy2) + mt76_update_survey_active_time(mdev->phy2, cur_time); +} + static void mt7615_mac_update_mib_stats(struct mt7615_phy *phy) { @@ -1888,7 +1912,7 @@ void mt7615_mac_work(struct work_struct *work) mt7615_mutex_acquire(phy->dev, &mdev->mutex); - mt76_update_survey(mdev); + mt7615_update_survey(phy->dev); if (++phy->mac_work_count == 5) { phy->mac_work_count = 0; From patchwork Fri Jun 26 21:25:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 215224 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21305C433E0 for ; Fri, 26 Jun 2020 21:25:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF48D20B80 for ; Fri, 26 Jun 2020 21:25:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206754; bh=B4urpNBnbqrJc3aTZLtJhAEvtRQLx1H/USypH4b6B04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=qzbkpTy4y+oEgHTmQOAaR86ujH3f3Wu7Fbc3UBi7KOTye0hV5Vb0bf+9R5ZTSWFuQ kxs8qxevdOOvkC+sqd5aQTjE8iRRjkA6VJxF4Lk/OJRvQzi5Ga1tlOT7kffHoKwlvt QuGbqCn/hYP7dbUpCA7MxUIj+4FUFcGp4q5TkzzQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726373AbgFZVZw (ORCPT ); Fri, 26 Jun 2020 17:25:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:33934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbgFZVZu (ORCPT ); Fri, 26 Jun 2020 17:25:50 -0400 Received: from localhost.localdomain.com (unknown [151.48.138.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3739E20B1F; Fri, 26 Jun 2020 21:25:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206750; bh=B4urpNBnbqrJc3aTZLtJhAEvtRQLx1H/USypH4b6B04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R4lKw8JWMBLkj3cef0GODGfmG5aMA50icbMAPWk38f9JeK6rBT9bW9LoxfT6QK5+x 4Bk7ajyds0wyB8V0J7AuyuspFQb9Ek7puINRAJdZrgk52K87/cneHjF4KzSYCbn5Xd DsypIGHCkC1tEnFS/9jsrZ3/cnxNSBlfOXtThukk= From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com, ryder.lee@mediatek.com, linux-mediatek@lists.infradead.org Subject: [PATCH 10/17] mt76: mt7615: wake device before pulling packets from mac80211 queues Date: Fri, 26 Jun 2020 23:25:10 +0200 Message-Id: <5bd9536f6518a3b21ee0029777b4d9a84c0b44e7.1593204577.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Make sure the device is in full-power before pulling frames from mac80211 queues Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt7615/mac.c | 6 +++++- .../net/wireless/mediatek/mt76/mt7615/main.c | 20 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index acefcc2e571a..0a16acf40cf8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -1841,9 +1841,13 @@ void mt7615_pm_wake_work(struct work_struct *work) pm.wake_work); mphy = dev->phy.mt76; - if (mt7615_driver_own(dev)) + if (mt7615_driver_own(dev)) { dev_err(mphy->dev->dev, "failed to wake device\n"); + goto out; + } + tasklet_schedule(&dev->mt76.tx_tasklet); +out: complete_all(&dev->pm.wake_cmpl); } diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/main.c b/drivers/net/wireless/mediatek/mt76/mt7615/main.c index e63c2584b326..9c17026c541d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/main.c @@ -635,6 +635,24 @@ static void mt7615_sta_rate_tbl_update(struct ieee80211_hw *hw, spin_unlock_bh(&dev->mt76.lock); } +static void +mt7615_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq) +{ + struct mt7615_dev *dev = mt7615_hw_dev(hw); + struct mt7615_phy *phy = mt7615_hw_phy(hw); + struct mt76_phy *mphy = phy->mt76; + + if (!test_bit(MT76_STATE_RUNNING, &mphy->state)) + return; + + if (test_bit(MT76_STATE_PM, &mphy->state)) { + queue_work(dev->mt76.wq, &dev->pm.wake_work); + return; + } + + tasklet_schedule(&dev->mt76.tx_tasklet); +} + static void mt7615_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, struct sk_buff *skb) @@ -1097,7 +1115,7 @@ const struct ieee80211_ops mt7615_ops = { .set_key = mt7615_set_key, .ampdu_action = mt7615_ampdu_action, .set_rts_threshold = mt7615_set_rts_threshold, - .wake_tx_queue = mt76_wake_tx_queue, + .wake_tx_queue = mt7615_wake_tx_queue, .sta_rate_tbl_update = mt7615_sta_rate_tbl_update, .sw_scan_start = mt76_sw_scan, .sw_scan_complete = mt76_sw_scan_complete, From patchwork Fri Jun 26 21:25:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 215223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C307DC433E2 for ; Fri, 26 Jun 2020 21:25:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1D212100A for ; Fri, 26 Jun 2020 21:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206756; bh=cNm4vevn52MHqQhVmtkazDdt9Txp0Mki2vNXGAapXMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=f4uYB0xQIyS/3/1OkqpxBNH8yKrbcQbMnCspgQD/Mgg3GvvsruFS+b1y0uhy6rJEo UcNuuMMoSffLLJqaX4T3Zx085uJGEDdvJShRRlVaXZT8yrfkgL4To50clKvQm65KjS W/61vIv0BvwXaKFlEMiQC8GefH1SJuFevK1GfpWA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726402AbgFZVZz (ORCPT ); Fri, 26 Jun 2020 17:25:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:34010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726399AbgFZVZy (ORCPT ); Fri, 26 Jun 2020 17:25:54 -0400 Received: from localhost.localdomain.com (unknown [151.48.138.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C358B20B1F; Fri, 26 Jun 2020 21:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206754; bh=cNm4vevn52MHqQhVmtkazDdt9Txp0Mki2vNXGAapXMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SjENw/Te39bMyb1oB0Ze08+Jvd2GghjzIv2bwr8GIlLEkswEMCUSbTbXn1Qs5ODsj eAFaIvbx6KhaFIqaCcTfC4735b72L4EjYahmW82DDD2IXkOPwJKLePxeRV1YG+QLzv 0dTIehGDO97HzHbrT9xF7fD+Nq9loCTlb+t+A36M= From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com, ryder.lee@mediatek.com, linux-mediatek@lists.infradead.org Subject: [PATCH 12/17] mt76: mt7615: check MT76_STATE_PM flag before accessing the device Date: Fri, 26 Jun 2020 23:25:12 +0200 Message-Id: <1aeb01ddefdd112ffbabca0f488ca3cd0c4ccd3e.1593204577.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Double-check if the device is in low-power state before accessing registermap in mt7615_sta_rate_tbl_update() and in mt7615_led_set_config() Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt7615/main.c | 3 ++- drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/main.c b/drivers/net/wireless/mediatek/mt76/mt7615/main.c index 32f060014bb7..3ab8e7e9be44 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/main.c @@ -652,7 +652,8 @@ static void mt7615_sta_rate_tbl_update(struct ieee80211_hw *hw, break; } msta->n_rates = i; - mt7615_mac_set_rates(phy, msta, NULL, msta->rates); + if (!test_bit(MT76_STATE_PM, &phy->mt76->state)) + mt7615_mac_set_rates(phy, msta, NULL, msta->rates); msta->rate_probe = false; spin_unlock_bh(&dev->mt76.lock); } diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c b/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c index 69cba8609edf..7224a0078211 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c @@ -70,6 +70,10 @@ mt7615_led_set_config(struct led_classdev *led_cdev, mt76 = container_of(led_cdev, struct mt76_dev, led_cdev); dev = container_of(mt76, struct mt7615_dev, mt76); + + if (test_bit(MT76_STATE_PM, &mt76->phy.state)) + return; + val = FIELD_PREP(MT_LED_STATUS_DURATION, 0xffff) | FIELD_PREP(MT_LED_STATUS_OFF, delay_off) | FIELD_PREP(MT_LED_STATUS_ON, delay_on); From patchwork Fri Jun 26 21:25:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 215222 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1722C433E2 for ; Fri, 26 Jun 2020 21:25:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A467D20B1F for ; Fri, 26 Jun 2020 21:25:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206759; bh=2Hmhq3wzP1gA0bSghnIl/mgLX+Tpgs8h4BrhEVV7eTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=OjEAWQULf22tmlXTSZi7DM68lR/rp0Uf9beOEcqQMsICZrarp492BBmLfSube+k4f 2j86FUpceebou49JeCaRuebdADjwpd6dHKx64SOr5fGe4VQ4SZoz1HelX0FEbPZ/MV xK8IUtRq0ANKrbMLy8FZWPAOnDLZjvTCCAtjMkDM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726408AbgFZVZ7 (ORCPT ); Fri, 26 Jun 2020 17:25:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:34066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725916AbgFZVZ6 (ORCPT ); Fri, 26 Jun 2020 17:25:58 -0400 Received: from localhost.localdomain.com (unknown [151.48.138.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C07D20B80; Fri, 26 Jun 2020 21:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206757; bh=2Hmhq3wzP1gA0bSghnIl/mgLX+Tpgs8h4BrhEVV7eTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SilLbHrOdlYEw93QlkKcZmgpGXW5I0Mdkgy5N+AOzV6nl8d09K9EtLdxHQ+MZQaW1 j1sGHCxpWhiUrKNL51SYNHzk92cNFNvBymKz7HTLwMu6KOc+ZTiXO6HZx/EhM40GMd RuK58r/afABlBHDDWSj5Z6MtoPcjeA4uhrgT9QdM= From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com, ryder.lee@mediatek.com, linux-mediatek@lists.infradead.org Subject: [PATCH 14/17] mt76: mt7615: add runtime-pm knob in mt7615 debugfs Date: Fri, 26 Jun 2020 23:25:14 +0200 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Introduce runtime-pm knob in mt7615 debugfs in order to enable/disable runtime pm available in offload firmware Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt7615/debugfs.c | 24 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7615/mac.c | 22 ++++++++++++++++- .../wireless/mediatek/mt76/mt7615/mt7615.h | 3 +++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c index b4c196005ebf..357b3c2fc3f9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c @@ -46,6 +46,29 @@ mt7615_scs_get(void *data, u64 *val) DEFINE_DEBUGFS_ATTRIBUTE(fops_scs, mt7615_scs_get, mt7615_scs_set, "%lld\n"); +static int +mt7615_pm_set(void *data, u64 val) +{ + struct mt7615_dev *dev = data; + + if (!mt7615_wait_for_mcu_init(dev)) + return 0; + + return mt7615_pm_set_enable(dev, val); +} + +static int +mt7615_pm_get(void *data, u64 *val) +{ + struct mt7615_dev *dev = data; + + *val = dev->pm.enable; + + return 0; +} + +DEFINE_DEBUGFS_ATTRIBUTE(fops_pm, mt7615_pm_get, mt7615_pm_set, "%lld\n"); + static int mt7615_dbdc_set(void *data, u64 val) { @@ -336,6 +359,7 @@ int mt7615_init_debugfs(struct mt7615_dev *dev) debugfs_create_file("scs", 0600, dir, dev, &fops_scs); debugfs_create_file("dbdc", 0600, dir, dev, &fops_dbdc); debugfs_create_file("fw_debug", 0600, dir, dev, &fops_fw_debug); + debugfs_create_file("runtime-pm", 0600, dir, dev, &fops_pm); debugfs_create_devm_seqfile(dev->mt76.dev, "radio", dir, mt7615_radio_read); debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern); diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index 8616bac97963..d3e3112359e8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -1905,7 +1905,8 @@ void mt7615_pm_power_save_sched(struct mt7615_dev *dev) { struct mt76_phy *mphy = dev->phy.mt76; - if (!mt7615_firmware_offload(dev) || !mt76_is_mmio(mphy->dev) || + if (!mt7615_firmware_offload(dev) || + !dev->pm.enable || !mt76_is_mmio(mphy->dev) || !test_bit(MT76_STATE_RUNNING, &mphy->state)) return; @@ -1928,6 +1929,25 @@ void mt7615_pm_power_save_work(struct work_struct *work) MT7615_PM_TIMEOUT); } +int mt7615_pm_set_enable(struct mt7615_dev *dev, bool enable) +{ + if (!mt7615_firmware_offload(dev) || !mt76_is_mmio(&dev->mt76)) + return -EOPNOTSUPP; + + mutex_lock(&dev->mt76.mutex); + + if (dev->pm.enable == enable) + goto out; + + dev->pm.enable = enable; + if (!enable) + cancel_delayed_work_sync(&dev->pm.ps_work); +out: + mutex_unlock(&dev->mt76.mutex); + + return 0; +} + void mt7615_mac_work(struct work_struct *work) { struct mt7615_phy *phy; diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h index 6da0af628c8d..02282b1a00b0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h @@ -300,6 +300,8 @@ struct mt7615_dev { #endif struct { + bool enable; + spinlock_t txq_lock; struct { struct mt7615_sta *msta; @@ -441,6 +443,7 @@ bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev); void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta, struct ieee80211_tx_rate *probe_rate, struct ieee80211_tx_rate *rates); +int mt7615_pm_set_enable(struct mt7615_dev *dev, bool enable); void mt7615_pm_wake_work(struct work_struct *work); int mt7615_pm_wake(struct mt7615_dev *dev); void mt7615_pm_power_save_sched(struct mt7615_dev *dev); From patchwork Fri Jun 26 21:25:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 215221 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A61DC433E2 for ; Fri, 26 Jun 2020 21:26:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA70B20C09 for ; Fri, 26 Jun 2020 21:26:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206763; bh=rs/tThQUT0zyXGwo/wQ1egLkcyTxG+blDV3R49QluiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Dezb3R3QLI6+fGiVLHGtYeIGr/Pdee5qGDvWtJbUssULRKZaH4yhRrpJiv0wwgTGf FTbO9IHsSCRiqO+bL+HM65lyH4Vl7PYSySOvu0UQxpahtVQ4NLavneU6FOIhmr57jx upJOEi5x8oxuGbFZ5BCYdTL/r0kEDaBsjgIUUiH0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726413AbgFZV0C (ORCPT ); Fri, 26 Jun 2020 17:26:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:34130 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725916AbgFZV0C (ORCPT ); Fri, 26 Jun 2020 17:26:02 -0400 Received: from localhost.localdomain.com (unknown [151.48.138.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EF32520B1F; Fri, 26 Jun 2020 21:25:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593206761; bh=rs/tThQUT0zyXGwo/wQ1egLkcyTxG+blDV3R49QluiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rZUMEIVDc2FmBIokQo+jjsSViDOYhTS5QY0LXVaS/3tLr/MBWUzNp8RzJuz0McGC4 nvTTOPHB291WstMT4WdQPZFbpiUCw9mKiQvhEk/TfqXGjDGCMY/vAMDwk/SbRHzz9w j2QK7k6OlNnJSuD+sIDPSSxxmpNiNPmRHSfb3K74= From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com, ryder.lee@mediatek.com, linux-mediatek@lists.infradead.org Subject: [PATCH 16/17] mt76: mt7615: add idle-timeout knob in mt7615 debugfs Date: Fri, 26 Jun 2020 23:25:16 +0200 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Introduce idle-timeout knob in mt7615 debugfs in order to configure the idle time to switch to low-power state Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt7615/debugfs.c | 25 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7615/init.c | 1 + .../net/wireless/mediatek/mt76/mt7615/mac.c | 4 +-- .../wireless/mediatek/mt76/mt7615/mt7615.h | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c index 357b3c2fc3f9..9d58ddae0338 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c @@ -69,6 +69,29 @@ mt7615_pm_get(void *data, u64 *val) DEFINE_DEBUGFS_ATTRIBUTE(fops_pm, mt7615_pm_get, mt7615_pm_set, "%lld\n"); +static int +mt7615_pm_idle_timeout_set(void *data, u64 val) +{ + struct mt7615_dev *dev = data; + + dev->pm.idle_timeout = msecs_to_jiffies(val); + + return 0; +} + +static int +mt7615_pm_idle_timeout_get(void *data, u64 *val) +{ + struct mt7615_dev *dev = data; + + *val = jiffies_to_msecs(dev->pm.idle_timeout); + + return 0; +} + +DEFINE_DEBUGFS_ATTRIBUTE(fops_pm_idle_timeout, mt7615_pm_idle_timeout_get, + mt7615_pm_idle_timeout_set, "%lld\n"); + static int mt7615_dbdc_set(void *data, u64 val) { @@ -360,6 +383,8 @@ int mt7615_init_debugfs(struct mt7615_dev *dev) debugfs_create_file("dbdc", 0600, dir, dev, &fops_dbdc); debugfs_create_file("fw_debug", 0600, dir, dev, &fops_fw_debug); debugfs_create_file("runtime-pm", 0600, dir, dev, &fops_pm); + debugfs_create_file("idle-timeout", 0600, dir, dev, + &fops_pm_idle_timeout); debugfs_create_devm_seqfile(dev->mt76.dev, "radio", dir, mt7615_radio_read); debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern); diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/init.c b/drivers/net/wireless/mediatek/mt76/mt7615/init.c index e799f93be510..e26cf762e416 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/init.c @@ -463,6 +463,7 @@ void mt7615_init_device(struct mt7615_dev *dev) timer_setup(&dev->phy.roc_timer, mt7615_roc_timer, 0); mt7615_init_wiphy(hw); + dev->pm.idle_timeout = MT7615_PM_TIMEOUT; dev->mphy.sband_2g.sband.ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; dev->mphy.sband_5g.sband.ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; dev->mphy.sband_5g.sband.vht_cap.cap |= diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index e93d229a7887..cb61a19bc7ce 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -1913,7 +1913,7 @@ void mt7615_pm_power_save_sched(struct mt7615_dev *dev) dev->pm.last_activity = jiffies; if (!test_bit(MT76_STATE_PM, &mphy->state)) queue_delayed_work(dev->mt76.wq, &dev->pm.ps_work, - MT7615_PM_TIMEOUT); + dev->pm.idle_timeout); } EXPORT_SYMBOL_GPL(mt7615_pm_power_save_sched); @@ -1926,7 +1926,7 @@ void mt7615_pm_power_save_work(struct work_struct *work) if (mt7615_firmware_own(dev)) queue_delayed_work(dev->mt76.wq, &dev->pm.ps_work, - MT7615_PM_TIMEOUT); + dev->pm.idle_timeout); } static void diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h index 9591dedee416..d3360196c76a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h @@ -313,6 +313,7 @@ struct mt7615_dev { struct delayed_work ps_work; unsigned long last_activity; + unsigned long idle_timeout; } pm; };