From patchwork Sat Nov 16 11:17:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Theil X-Patchwork-Id: 11247539 X-Patchwork-Delegate: nbd@nbd.name Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02F3D17EF for ; Sat, 16 Nov 2019 11:18:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E268E20700 for ; Sat, 16 Nov 2019 11:18:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727471AbfKPLSa (ORCPT ); Sat, 16 Nov 2019 06:18:30 -0500 Received: from smail.rz.tu-ilmenau.de ([141.24.186.67]:59114 "EHLO smail.rz.tu-ilmenau.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727331AbfKPLS3 (ORCPT ); Sat, 16 Nov 2019 06:18:29 -0500 Received: from isengard.fritz.box (unknown [87.147.48.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id 57D9458007D; Sat, 16 Nov 2019 12:18:25 +0100 (CET) From: Markus Theil To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, Stanislaw Gruszka , Markus Theil Subject: [PATCH 2/4] mt76: mt76x02: split beaconing Date: Sat, 16 Nov 2019 12:17:07 +0100 Message-Id: <20191116111709.4686-3-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191116111709.4686-1-markus.theil@tu-ilmenau.de> References: <20191116111709.4686-1-markus.theil@tu-ilmenau.de> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Sending beacons to the hardware always happens in batches. In order to speed up beacon processing on usb devices, this patch splits out common code an calls it only once (mt76x02_mac_set_beacon_prepare, mt76x02_mac_set_beacon_finish). Making this split breaks beacon enabling/disabling per vif. This is fixed by adding a call to set the bypass mask, if beaconing should be disabled for a vif. Otherwise the beacon is send after the next beacon interval. The code is also adapted for the mmio part of the driver, but should not have any performance implication there. Signed-off-by: Markus Theil --- .../wireless/mediatek/mt76/mt76x02_beacon.c | 53 +++++++++---------- .../net/wireless/mediatek/mt76/mt76x02_mac.h | 2 + .../net/wireless/mediatek/mt76/mt76x02_mmio.c | 4 ++ .../wireless/mediatek/mt76/mt76x02_usb_core.c | 4 ++ 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_beacon.c b/drivers/net/wireless/mediatek/mt76/mt76x02_beacon.c index 54fe449f01c9..47207b790bf9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_beacon.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_beacon.c @@ -47,10 +47,6 @@ __mt76x02_mac_set_beacon(struct mt76x02_dev *dev, u8 bcn_idx, int beacon_len = dev->beacon_ops->slot_size; int beacon_addr = MT_BEACON_BASE + (beacon_len * bcn_idx); int ret = 0; - int i; - - /* Prevent corrupt transmissions during update */ - mt76_set(dev, MT_BCN_BYPASS_MASK, BIT(bcn_idx)); if (skb) { ret = mt76x02_write_beacon(dev, beacon_addr, skb); @@ -58,41 +54,39 @@ __mt76x02_mac_set_beacon(struct mt76x02_dev *dev, u8 bcn_idx, dev->beacon_data_mask |= BIT(bcn_idx); } - mt76_wr(dev, MT_BCN_BYPASS_MASK, 0xff00 | ~dev->beacon_data_mask); - return ret; } -int mt76x02_mac_set_beacon(struct mt76x02_dev *dev, u8 vif_idx, - struct sk_buff *skb) -{ - bool force_update = false; - int bcn_idx = 0; - int i; +void mt76x02_mac_set_beacon_prepare(struct mt76x02_dev *dev) { + /* Prevent corrupt transmissions during update */ + mt76_set(dev, MT_BCN_BYPASS_MASK, 0xffff); +} +EXPORT_SYMBOL_GPL(mt76x02_mac_set_beacon_prepare); - for (i = 0; i < ARRAY_SIZE(dev->beacons); i++) { - if (vif_idx == i) { - force_update = !!dev->beacons[i] ^ !!skb; - dev_kfree_skb(dev->beacons[i]); - dev->beacons[i] = skb; - __mt76x02_mac_set_beacon(dev, bcn_idx, skb); - } else if (force_update && dev->beacons[i]) { - __mt76x02_mac_set_beacon(dev, bcn_idx, - dev->beacons[i]); - } +void mt76x02_mac_set_beacon_finish(struct mt76x02_dev *dev) { + int i; + int bcn_idx = 0; + int nbeacons = hweight8(dev->mt76.beacon_mask); + for(i = 0; i < nbeacons; ++i) { bcn_idx += !!dev->beacons[i]; } - for (i = bcn_idx; i < ARRAY_SIZE(dev->beacons); i++) { - if (!(dev->beacon_data_mask & BIT(i))) - break; - - __mt76x02_mac_set_beacon(dev, i, NULL); - } - mt76_rmw_field(dev, MT_MAC_BSSID_DW1, MT_MAC_BSSID_DW1_MBEACON_N, bcn_idx - 1); + + mt76_wr(dev, MT_BCN_BYPASS_MASK, 0xff00 | ~dev->beacon_data_mask); +} +EXPORT_SYMBOL_GPL(mt76x02_mac_set_beacon_finish); + +int mt76x02_mac_set_beacon(struct mt76x02_dev *dev, u8 vif_idx, + struct sk_buff *skb) +{ + dev_kfree_skb(dev->beacons[vif_idx]); + dev->beacons[vif_idx] = skb; + __mt76x02_mac_set_beacon(dev, vif_idx, skb); + + return 0; } EXPORT_SYMBOL_GPL(mt76x02_mac_set_beacon); @@ -113,6 +107,7 @@ void mt76x02_mac_set_beacon_enable(struct mt76x02_dev *dev, } else { dev->mt76.beacon_mask &= ~BIT(mvif->idx); mt76x02_mac_set_beacon(dev, mvif->idx, NULL); + mt76_set(dev, MT_BCN_BYPASS_MASK, BIT(mvif->idx)); } if (!!old_mask == !!dev->mt76.beacon_mask) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h index efa4ef945e35..4e717640eef6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h @@ -197,6 +197,8 @@ int mt76x02_mac_set_beacon(struct mt76x02_dev *dev, u8 vif_idx, struct sk_buff *skb); void mt76x02_mac_set_beacon_enable(struct mt76x02_dev *dev, struct ieee80211_vif *vif, bool enable); +void mt76x02_mac_set_beacon_prepare(struct mt76x02_dev *dev); +void mt76x02_mac_set_beacon_finish(struct mt76x02_dev *dev); void mt76x02_edcca_init(struct mt76x02_dev *dev); #endif diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c b/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c index dc773070481d..b8b4c6a67d39 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c @@ -24,10 +24,14 @@ static void mt76x02_pre_tbtt_tasklet(unsigned long arg) mt76x02_resync_beacon_timer(dev); + mt76x02_mac_set_beacon_prepare(dev); + ieee80211_iterate_active_interfaces_atomic(mt76_hw(dev), IEEE80211_IFACE_ITER_RESUME_ALL, mt76x02_update_beacon_iter, dev); + mt76x02_mac_set_beacon_finish(dev); + mt76_csa_check(&dev->mt76); if (dev->mt76.csa_complete) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c index 78dfc1e7f27b..aedab4cc8d40 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c @@ -179,6 +179,8 @@ static void mt76x02u_pre_tbtt_work(struct work_struct *work) mt76x02_resync_beacon_timer(dev); + mt76x02_mac_set_beacon_prepare(dev); + ieee80211_iterate_active_interfaces(mt76_hw(dev), IEEE80211_IFACE_ITER_RESUME_ALL, mt76x02_update_beacon_iter, dev); @@ -191,6 +193,8 @@ static void mt76x02u_pre_tbtt_work(struct work_struct *work) mt76x02_mac_set_beacon(dev, i, skb); } + mt76x02_mac_set_beacon_finish(dev); + mt76x02u_restart_pre_tbtt_timer(dev); } From patchwork Sat Nov 16 11:17:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Theil X-Patchwork-Id: 11247537 X-Patchwork-Delegate: nbd@nbd.name Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA7FE138C for ; Sat, 16 Nov 2019 11:18:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4C5020700 for ; Sat, 16 Nov 2019 11:18:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727440AbfKPLS2 (ORCPT ); Sat, 16 Nov 2019 06:18:28 -0500 Received: from smail.rz.tu-ilmenau.de ([141.24.186.67]:59117 "EHLO smail.rz.tu-ilmenau.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727340AbfKPLS1 (ORCPT ); Sat, 16 Nov 2019 06:18:27 -0500 Received: from isengard.fritz.box (unknown [87.147.48.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id AEFCB58007E; Sat, 16 Nov 2019 12:18:25 +0100 (CET) From: Markus Theil To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, Stanislaw Gruszka , Markus Theil Subject: [PATCH 3/4] mt76: speed up usb bulk copy Date: Sat, 16 Nov 2019 12:17:08 +0100 Message-Id: <20191116111709.4686-4-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191116111709.4686-1-markus.theil@tu-ilmenau.de> References: <20191116111709.4686-1-markus.theil@tu-ilmenau.de> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Use larger batches for usb copy to speed this operation up. Otherwise it would be too slow for copying new beacons or broadcast frames over usb. Signed-off-by: Markus Theil --- drivers/net/wireless/mediatek/mt76/mt76.h | 2 +- .../wireless/mediatek/mt76/mt76x02_beacon.c | 1 - drivers/net/wireless/mediatek/mt76/usb.c | 22 ++++++++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 8aec7ccf2d79..7a6f5d097a3d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -383,7 +383,7 @@ enum mt76u_out_ep { struct mt76_usb { struct mutex usb_ctrl_mtx; union { - u8 data[32]; + u8 data[128]; __le32 reg_val; }; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_beacon.c b/drivers/net/wireless/mediatek/mt76/mt76x02_beacon.c index 47207b790bf9..8b2f7a0d58b5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_beacon.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_beacon.c @@ -86,7 +86,6 @@ int mt76x02_mac_set_beacon(struct mt76x02_dev *dev, u8 vif_idx, dev->beacons[vif_idx] = skb; __mt76x02_mac_set_beacon(dev, vif_idx, skb); - return 0; } EXPORT_SYMBOL_GPL(mt76x02_mac_set_beacon); diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index 20c6fe510e9d..6183105166ec 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -149,18 +149,28 @@ static void mt76u_copy(struct mt76_dev *dev, u32 offset, const void *data, int len) { struct mt76_usb *usb = &dev->usb; - const u32 *val = data; - int i, ret; + const u8 *val = data; + int ret; + const int batch_size_max = sizeof(usb->data); + int current_batch_size; + int i = 0; mutex_lock(&usb->usb_ctrl_mtx); - for (i = 0; i < DIV_ROUND_UP(len, 4); i++) { - put_unaligned(val[i], (u32 *)usb->data); + while (i < len) { + if(len - i > batch_size_max) { + current_batch_size = batch_size_max; + } else { + current_batch_size = len - i; + } + memcpy(usb->data, val + i, current_batch_size); ret = __mt76u_vendor_request(dev, MT_VEND_MULTI_WRITE, USB_DIR_OUT | USB_TYPE_VENDOR, - 0, offset + i * 4, usb->data, - sizeof(u32)); + 0, offset + i, usb->data, + current_batch_size); if (ret < 0) break; + + i += current_batch_size; } mutex_unlock(&usb->usb_ctrl_mtx); } From patchwork Sat Nov 16 11:17:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Theil X-Patchwork-Id: 11247535 X-Patchwork-Delegate: nbd@nbd.name Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCEB017E6 for ; Sat, 16 Nov 2019 11:18:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A75E620700 for ; Sat, 16 Nov 2019 11:18:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727450AbfKPLS2 (ORCPT ); Sat, 16 Nov 2019 06:18:28 -0500 Received: from smail.rz.tu-ilmenau.de ([141.24.186.67]:59122 "EHLO smail.rz.tu-ilmenau.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727388AbfKPLS1 (ORCPT ); Sat, 16 Nov 2019 06:18:27 -0500 Received: from isengard.fritz.box (unknown [87.147.48.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id 1240258007F; Sat, 16 Nov 2019 12:18:26 +0100 (CET) From: Markus Theil To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, Stanislaw Gruszka , Markus Theil Subject: [PATCH 4/4] mt76: mt76x02: add channel switch support for usb interfaces Date: Sat, 16 Nov 2019 12:17:09 +0100 Message-Id: <20191116111709.4686-5-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191116111709.4686-1-markus.theil@tu-ilmenau.de> References: <20191116111709.4686-1-markus.theil@tu-ilmenau.de> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org This patch enables channel switch support on mt76 usb interfaces. Signed-off-by: Markus Theil --- drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c | 7 +++++++ drivers/net/wireless/mediatek/mt76/mt76x02_util.c | 2 +- drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c index aedab4cc8d40..32e6c37aa80d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c @@ -179,6 +179,12 @@ static void mt76x02u_pre_tbtt_work(struct work_struct *work) mt76x02_resync_beacon_timer(dev); + mt76_csa_check(&dev->mt76); + if (dev->mt76.csa_complete) { + mt76_csa_finish(&dev->mt76); + goto out; + } + mt76x02_mac_set_beacon_prepare(dev); ieee80211_iterate_active_interfaces(mt76_hw(dev), @@ -195,6 +201,7 @@ static void mt76x02u_pre_tbtt_work(struct work_struct *work) mt76x02_mac_set_beacon_finish(dev); +out: mt76x02u_restart_pre_tbtt_timer(dev); } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c index 414b22399d93..3f95e5b24e1d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c @@ -174,7 +174,6 @@ void mt76x02_init_device(struct mt76x02_dev *dev) wiphy->reg_notifier = mt76x02_regd_notifier; wiphy->iface_combinations = mt76x02_if_comb; wiphy->n_iface_combinations = ARRAY_SIZE(mt76x02_if_comb); - wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; /* init led callbacks */ if (IS_ENABLED(CONFIG_MT76_LEDS)) { @@ -184,6 +183,7 @@ void mt76x02_init_device(struct mt76x02_dev *dev) } } + wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS); hw->sta_data_size = sizeof(struct mt76x02_sta); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c index eb73cb856c81..2f2c39a6a9e6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c @@ -100,6 +100,10 @@ mt76x2u_config(struct ieee80211_hw *hw, u32 changed) return err; } +void mt76x2u_channel_switch_beacon(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct cfg80211_chan_def *chandef) {} + const struct ieee80211_ops mt76x2u_ops = { .tx = mt76x02_tx, .start = mt76x2u_start, @@ -121,4 +125,5 @@ const struct ieee80211_ops mt76x2u_ops = { .get_survey = mt76_get_survey, .set_tim = mt76_set_tim, .release_buffered_frames = mt76_release_buffered_frames, + .channel_switch_beacon = mt76x2u_channel_switch_beacon, };