wifi: mt76: mt7996: hold the wiphy lock in the L1 SER reset work
Subsystems (3)
Felix Fietkau
maintainerPATCH 1/20 wifi: mt76: mt7996: hold the wiphy lock in the L1 SER reset work
Since the beacon restore after an L1 SER walks the links of each interface, it reads vif->link_conf. mt7996_mac_reset_work() holds only dev->mt76.mutex there, and ieee80211_iterate_active_interfaces() takes only iflist_mtx. An L1 SER with a beaconing interface thus gives a suspicious RCU usage report under CONFIG_PROVE_RCU.
Hold the wiphy lock across the locked section of the L1 SER path. Take it before dev->mt76.mutex, as the mac80211 ops do; no caller flushes the mt76 workqueue under the wiphy lock. The full reset path reads no link_conf. An RCU read-side section cannot cover the walk, since the template upload waits for the answer of the firmware.
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +2 -0
@@ -2711,6 +2711,7 @@ void mt7996_mac_reset_work(struct work_struct *work)cancel_delayed_work_sync (&phy->mt76->mac_work); } +wiphy_lock (hw->wiphy);mutex_lock (&dev->mt76.mutex);mt76_worker_disable (&dev->mt76.tx_worker);
@@ -2810,6 +2811,7 @@ void mt7996_mac_reset_work(struct work_struct *work)mt7996_update_beacons (dev, bcn_restored);mutex_unlock (&dev->mt76.mutex); +wiphy_unlock (hw->wiphy);mt7996_for_each_phy (dev, phy) ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 2/20 wifi: mt76: mt7996: report the TX statistics of each link of a station
The TXD of QoS data of an MLD peer names the wcid of one of two links. Even TIDs take the default link, and odd TIDs take the secondary link. The TX free and the TX status count on the wcid of the TXD. With WED, the firmware also reports the byte and packet counts per link wcid. mt7996_sta_statistics() and mt7996_ethtool_worker() read the counters of the default link alone, so the counts of the other links are lost.
Report the sum over the link wcids of the station, in the station info and in the ethtool statistics.
--- .../net/wireless/mediatek/mt76/mt7996/main.c | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +29 -11
@@ -2575,10 +2575,13 @@ static void mt7996_sta_statistics(struct ieee80211_hw *hw,struct ieee80211_sta *sta, struct station_info *sinfo) { + u32 tx_packets = 0, rx_packets = 0, tx_failed = 0, tx_retries = 0;struct mt7996_dev *dev =mt7996_hw_dev (hw);struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;struct mt7996_sta_link *msta_link; +u64 tx_bytes =0 , rx_bytes =0 ;struct rate_info *txrate; +unsigned int link_id;rcu_read_lock ();
@@ -2603,10 +2606,24 @@ static void mt7996_sta_statistics(struct ieee80211_hw *hw, sinfo->filled |=BIT_ULL (NL80211_STA_INFO_TX_BITRATE ); } - sinfo->tx_failed = msta_link->wcid.stats.tx_failed; +for (link_id =0 ; link_id <ARRAY_SIZE (msta->link); link_id++) { +struct mt7996_sta_link *iter =mt7996_sta_link (msta, link_id); + +if (!iter) +continue ; + + tx_failed += iter->wcid.stats.tx_failed; + tx_retries += iter->wcid.stats.tx_retries; + tx_bytes += iter->wcid.stats.tx_bytes; + rx_bytes += iter->wcid.stats.rx_bytes; + tx_packets += iter->wcid.stats.tx_packets; + rx_packets += iter->wcid.stats.rx_packets; + } + + sinfo->tx_failed = tx_failed; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_TX_FAILED ); - sinfo->tx_retries = msta_link->wcid.stats.tx_retries; + sinfo->tx_retries = tx_retries; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_TX_RETRIES ); sinfo->ack_signal = (s8 )msta_link->ack_signal;
@@ -2617,16 +2634,16 @@ static void mt7996_sta_statistics(struct ieee80211_hw *hw, sinfo->filled |=BIT_ULL (NL80211_STA_INFO_ACK_SIGNAL_AVG );if (mtk_wed_device_active (&dev->mt76.mmio.wed)) { - sinfo->tx_bytes = msta_link->wcid.stats.tx_bytes; + sinfo->tx_bytes = tx_bytes; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_TX_BYTES64 ); - sinfo->rx_bytes = msta_link->wcid.stats.rx_bytes; + sinfo->rx_bytes = rx_bytes; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_RX_BYTES64 ); - sinfo->tx_packets = msta_link->wcid.stats.tx_packets; + sinfo->tx_packets = tx_packets; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_TX_PACKETS ); - sinfo->rx_packets = msta_link->wcid.stats.rx_packets; + sinfo->rx_packets = rx_packets; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_RX_PACKETS ); }
@@ -2919,15 +2936,16 @@ static void mt7996_ethtool_worker(void *wi_data, struct ieee80211_sta *sta)struct mt76_ethtool_worker_info *wi = wi_data;struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;struct mt7996_sta_link *msta_link; +unsigned int link_id;if (msta->vif->deflink.mt76.idx != wi->idx)return ; - msta_link =mt7996_sta_link (msta, msta->deflink_id); -if (!msta_link) -return ; - -mt76_ethtool_worker (wi, &msta_link->wcid.stats, true); +for (link_id =0 ; link_id <ARRAY_SIZE (msta->link); link_id++) { + msta_link =mt7996_sta_link (msta, link_id); +if (msta_link) +mt76_ethtool_worker (wi, &msta_link->wcid.stats, true); + } } static
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 02/20] wifi: mt76: mt7996: report the TX statistics of each link of a station
Quoted 7 lines
The TXD of QoS data of an MLD peer names the wcid of one of two links. Even TIDs take the default link, and odd TIDs take the secondary link. The TX free and the TX status count on the wcid of the TXD. With WED, the firmware also reports the byte and packet counts per link wcid.
mt7996_sta_statistics()andmt7996_ethtool_worker()read the counters of the default link alone, so the counts of the other links are lost.
Quoted 5 lines
Report the sum over the link wcids of the station, in the station info and in the ethtool statistics.
Fixes 85cd5534a3f2 ("wifi: mt76: mt7996: use correct link_id when filling TXD and TXP")Signed-off-by Felix Fietkau <[email protected]>
Quoted 96 lines
--- .../net/wireless/mediatek/mt76/mt7996/main.c | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-)drivers/net/wireless/mediatek/mt76/mt7996/main.c +29
-11@@ -2575,10 +2575,13 @@ static void mt7996_sta_statistics(struct ieee80211_hw *hw,struct ieee80211_sta *sta, struct station_info *sinfo) { + u32 tx_packets = 0, rx_packets = 0, tx_failed = 0, tx_retries = 0;struct mt7996_dev *dev =mt7996_hw_dev (hw);struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;struct mt7996_sta_link *msta_link; +u64 tx_bytes =0 , rx_bytes =0 ;struct rate_info *txrate; +unsigned int link_id;rcu_read_lock ();@@ -2603,10 +2606,24 @@ static void mt7996_sta_statistics(struct ieee80211_hw *hw, sinfo->filled |=BIT_ULL (NL80211_STA_INFO_TX_BITRATE ); } - sinfo->tx_failed = msta_link->wcid.stats.tx_failed; +for (link_id =0 ; link_id <ARRAY_SIZE (msta->link); link_id++) { +struct mt7996_sta_link *iter =mt7996_sta_link (msta, link_id); + +if (!iter) +continue ; + + tx_failed += iter->wcid.stats.tx_failed; + tx_retries += iter->wcid.stats.tx_retries; + tx_bytes += iter->wcid.stats.tx_bytes; + rx_bytes += iter->wcid.stats.rx_bytes; + tx_packets += iter->wcid.stats.tx_packets; + rx_packets += iter->wcid.stats.rx_packets; + } + + sinfo->tx_failed = tx_failed; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_TX_FAILED ); - sinfo->tx_retries = msta_link->wcid.stats.tx_retries; + sinfo->tx_retries = tx_retries; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_TX_RETRIES ); sinfo->ack_signal = (s8 )msta_link->ack_signal;@@ -2617,16 +2634,16 @@ static void mt7996_sta_statistics(struct ieee80211_hw *hw, sinfo->filled |=BIT_ULL (NL80211_STA_INFO_ACK_SIGNAL_AVG );if (mtk_wed_device_active (&dev->mt76.mmio.wed)) { - sinfo->tx_bytes = msta_link->wcid.stats.tx_bytes; + sinfo->tx_bytes = tx_bytes; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_TX_BYTES64 ); - sinfo->rx_bytes = msta_link->wcid.stats.rx_bytes; + sinfo->rx_bytes = rx_bytes; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_RX_BYTES64 ); - sinfo->tx_packets = msta_link->wcid.stats.tx_packets; + sinfo->tx_packets = tx_packets; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_TX_PACKETS ); - sinfo->rx_packets = msta_link->wcid.stats.rx_packets; + sinfo->rx_packets = rx_packets; sinfo->filled |=BIT_ULL (NL80211_STA_INFO_RX_PACKETS ); }@@ -2919,15 +2936,16 @@ static void mt7996_ethtool_worker(void *wi_data, struct ieee80211_sta *sta)struct mt76_ethtool_worker_info *wi = wi_data;struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;struct mt7996_sta_link *msta_link; +unsigned int link_id;if (msta->vif->deflink.mt76.idx != wi->idx)return ; - msta_link =mt7996_sta_link (msta, msta->deflink_id); -if (!msta_link) -return ; - -mt76_ethtool_worker (wi, &msta_link->wcid.stats, true); +for (link_id =0 ; link_id <ARRAY_SIZE (msta->link); link_id++) { + msta_link =mt7996_sta_link (msta, link_id); +if (msta_link) +mt76_ethtool_worker (wi, &msta_link->wcid.stats, true); + } } staticSignature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 3/20 wifi: mt76: mt7996: stop the hardware when the probe fails
In reply to Felix Fietkaumt7996_register_device() returns every error after mt7996_dma_init() with no teardown, and the probe then frees the device. A missing firmware or default EEPROM file is enough. The RX NAPIs stay enabled and thus stay in the global NAPI hash inside the freed memory. Each later napi_enable() whose id falls into one of their buckets then reads and writes freed memory. The DMA, the firmware and the NAPI threads are left running. An error of mt7996_coredump_register() also frees a registered hw.
Stop the hardware on these errors as the remove path does. Where the hw was registered, unregister it first, like mt7915. Clear hw_init_done before that, so that no reset or dump work is queued during the teardown.
Initialise the RRO MSDU page lists before the DMA init, since the teardown walks them also after a failed firmware load. Free the RRO buffers in the teardown after the DMA stop. With WED or NPU they are devres memory of that device, which the release of the PCI device does not free.
The remove path shares the teardown. It thus frees the RRO buffers after the DMA stop, no longer before the NAPI disable. It also cancels reset_work and dump_work once more after the hw is unregistered.
--- .../net/wireless/mediatek/mt76/mt7996/init.c | 85 ++++++++++++------- 1 file changed, 54 insertions(+), 31 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/init.c +54 -31
@@ -878,10 +878,6 @@ void mt7996_rro_hw_init(struct mt7996_dev *dev)if (!mt7996_has_hwrro (dev))return ; -INIT_LIST_HEAD (&dev->wed_rro.page_cache); -for (i =0 ; i <ARRAY_SIZE (dev->wed_rro.page_map); i++) -INIT_LIST_HEAD (&dev->wed_rro.page_map[i]); -if (!is_mt7996 (&dev->mt76)) { reg =MT_RRO_MSDU_PG_SEG_ADDR0 ;
@@ -1274,9 +1270,29 @@ int mt7996_global_wcid_init(struct mt7996_dev *dev)return 0 ; } +static void mt7996_stop_hardware (struct mt7996_dev *dev) +{ +int i; + +cancel_work_sync (&dev->dump_work); +cancel_work_sync (&dev->reset_work); +for (i =0 ; i <ARRAY_SIZE (dev->mt76.napi); i++) { +if (dev->mt76.napi[i].dev) +napi_disable (&dev->mt76.napi[i]); + } +mt7996_mcu_exit (dev); +mt7996_tx_token_put (dev); +mt7996_dma_cleanup (dev); +if (mt7996_has_hwrro (dev) && + !mtk_wed_device_active (&dev->mt76.mmio.wed)) +mt7996_rro_msdu_page_map_free (dev); +tasklet_disable (&dev->mt76.irq_tasklet); +mt7996_wed_rro_free (dev); +} +static int mt7996_init_hardware (struct mt7996_dev *dev) { -int ret; +int i, ret;mt76_wr (dev,MT_INT_SOURCE_CSR , ~0 );if (is_mt7992 (&dev->mt76)) {
@@ -1287,6 +1303,9 @@ static int mt7996_init_hardware(struct mt7996_dev *dev)INIT_WORK (&dev->init_work, mt7996_init_work);INIT_WORK (&dev->wed_rro.work, mt7996_wed_rro_work);INIT_LIST_HEAD (&dev->wed_rro.poll_list); +INIT_LIST_HEAD (&dev->wed_rro.page_cache); +for (i =0 ; i <ARRAY_SIZE (dev->wed_rro.page_map); i++) +INIT_LIST_HEAD (&dev->wed_rro.page_map[i]);spin_lock_init (&dev->wed_rro.lock); ret =mt7996_variant_type_init (dev);
@@ -1301,21 +1320,30 @@ static int mt7996_init_hardware(struct mt7996_dev *dev) ret =mt7996_mcu_init (dev);if (ret) -return ret; + goto error; ret =mt7996_wed_rro_init (dev);if (ret) -return ret; + goto error; ret =mt7996_variant_fem_init (dev);if (ret) -return ret; + goto error; ret =mt7996_eeprom_init (dev);if (ret <0 ) -return ret; + goto error; -return mt7996_global_wcid_init (dev); + ret =mt7996_global_wcid_init (dev); +if (ret) + goto error; + +return 0 ; + +error: +mt7996_stop_hardware (dev); + +return ret; }void mt7996_set_stream_vht_txbf_caps (struct mt7996_phy *phy)
@@ -1777,22 +1805,22 @@ int mt7996_register_device(struct mt7996_dev *dev) ret =mt7996_register_phy (dev,MT_BAND1 );if (ret) -return ret; + goto stop_hw; ret =mt7996_register_phy (dev,MT_BAND2 );if (ret) -return ret; + goto stop_hw; ret =mt7996_npu_hw_init (dev);if (ret) -return ret; + goto stop_hw;mt7996_dma_rro_start (dev); ret =mt76_register_device (&dev->mt76, true, mt76_rates,ARRAY_SIZE (mt76_rates));if (ret) -return ret; + goto stop_hw;mt7996_for_each_phy (dev, phy)mt7996_thermal_init (phy);
@@ -1803,24 +1831,30 @@ int mt7996_register_device(struct mt7996_dev *dev) ret =mt7996_init_debugfs (dev);if (ret) - goto error; + goto unregister; ret =mt7996_coredump_register (dev);if (ret) - goto error; + goto unregister;return 0 ; -error: +unregister: +mt7996_set_hw_init_done (dev, false);cancel_work_sync (&dev->init_work); +cancel_work_sync (&dev->dump_work); +cancel_work_sync (&dev->reset_work); +mt7996_for_each_phy (dev, phy) +mt7996_unregister_thermal (phy); +mt76_unregister_device (&dev->mt76); +stop_hw: +mt7996_stop_hardware (dev);return ret; }void mt7996_unregister_device (struct mt7996_dev *dev) { -int i; -mt7996_set_hw_init_done (dev, false);cancel_work_sync (&dev->dump_work);cancel_work_sync (&dev->wed_rro.work);
@@ -1831,18 +1865,7 @@ void mt7996_unregister_device(struct mt7996_dev *dev)mt7996_unregister_thermal (&dev->phy);mt7996_coredump_unregister (dev);mt76_unregister_device (&dev->mt76); -mt7996_wed_rro_free (dev); -for (i =0 ; i <ARRAY_SIZE (dev->mt76.napi); i++) { -if (dev->mt76.napi[i].dev) -napi_disable (&dev->mt76.napi[i]); - } -mt7996_mcu_exit (dev); -mt7996_tx_token_put (dev); -mt7996_dma_cleanup (dev); -if (mt7996_has_hwrro (dev) && - !mtk_wed_device_active (&dev->mt76.mmio.wed)) -mt7996_rro_msdu_page_map_free (dev); -tasklet_disable (&dev->mt76.irq_tasklet); +mt7996_stop_hardware (dev);mt76_free_device (&dev->mt76); }
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 03/20] wifi: mt76: mt7996: stop the hardware when the probe fails
Quoted 20 lines
mt7996_register_device()returns every error aftermt7996_dma_init()with no teardown, and the probe then frees the device. A missing firmware or default EEPROM file is enough. The RX NAPIs stay enabled and thus stay in the global NAPI hash inside the freed memory. Each laternapi_enable()whose id falls into one of their buckets then reads and writes freed memory. The DMA, the firmware and the NAPI threads are left running. An error ofmt7996_coredump_register()also frees a registered hw.Stop the hardware on these errors as the remove path does. Where the hw was registered, unregister it first, like mt7915. Clear
hw_init_donebefore that, so that no reset or dump work is queued during the teardown.Initialise the RRO MSDU page lists before the DMA init, since the teardown walks them also after a failed firmware load. Free the RRO buffers in the teardown after the DMA stop. With WED or NPU they are devres memory of that device, which the release of the PCI device does not free.
Quoted 6 lines
The remove path shares the teardown. It thus frees the RRO buffers after the DMA stop, no longer before the NAPI disable. It also cancels
reset_workanddump_workonce more after the hw is unregistered.Fixes 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")Signed-off-by Felix Fietkau <[email protected]>
Quoted 183 lines
--- .../net/wireless/mediatek/mt76/mt7996/init.c | 85 ++++++++++++------- 1 file changed, 54 insertions(+), 31 deletions(-)drivers/net/wireless/mediatek/mt76/mt7996/init.c +54
-31@@ -878,10 +878,6 @@ void mt7996_rro_hw_init(struct mt7996_dev *dev)if (!mt7996_has_hwrro (dev))return ; -INIT_LIST_HEAD (&dev->wed_rro.page_cache); -for (i =0 ; i <ARRAY_SIZE (dev->wed_rro.page_map); i++) -INIT_LIST_HEAD (&dev->wed_rro.page_map[i]); -if (!is_mt7996 (&dev->mt76)) { reg =MT_RRO_MSDU_PG_SEG_ADDR0 ;@@ -1274,9 +1270,29 @@ int mt7996_global_wcid_init(struct mt7996_dev *dev)return 0 ; } +static void mt7996_stop_hardware (struct mt7996_dev *dev) +{ +int i; + +cancel_work_sync (&dev->dump_work); +cancel_work_sync (&dev->reset_work); +for (i =0 ; i <ARRAY_SIZE (dev->mt76.napi); i++) { +if (dev->mt76.napi[i].dev) +napi_disable (&dev->mt76.napi[i]); + } +mt7996_mcu_exit (dev); +mt7996_tx_token_put (dev); +mt7996_dma_cleanup (dev); +if (mt7996_has_hwrro (dev) && + !mtk_wed_device_active (&dev->mt76.mmio.wed)) +mt7996_rro_msdu_page_map_free (dev); +tasklet_disable (&dev->mt76.irq_tasklet); +mt7996_wed_rro_free (dev); +} +static int mt7996_init_hardware (struct mt7996_dev *dev) { -int ret; +int i, ret;mt76_wr (dev,MT_INT_SOURCE_CSR , ~0 );if (is_mt7992 (&dev->mt76)) {@@ -1287,6 +1303,9 @@ static int mt7996_init_hardware(struct mt7996_dev *dev)INIT_WORK (&dev->init_work, mt7996_init_work);INIT_WORK (&dev->wed_rro.work, mt7996_wed_rro_work);INIT_LIST_HEAD (&dev->wed_rro.poll_list); +INIT_LIST_HEAD (&dev->wed_rro.page_cache); +for (i =0 ; i <ARRAY_SIZE (dev->wed_rro.page_map); i++) +INIT_LIST_HEAD (&dev->wed_rro.page_map[i]);spin_lock_init (&dev->wed_rro.lock); ret =mt7996_variant_type_init (dev);@@ -1301,21 +1320,30 @@ static int mt7996_init_hardware(struct mt7996_dev *dev) ret =mt7996_mcu_init (dev);if (ret) -return ret; + goto error; ret =mt7996_wed_rro_init (dev);if (ret) -return ret; + goto error; ret =mt7996_variant_fem_init (dev);if (ret) -return ret; + goto error; ret =mt7996_eeprom_init (dev);if (ret <0 ) -return ret; + goto error; -return mt7996_global_wcid_init (dev); + ret =mt7996_global_wcid_init (dev); +if (ret) + goto error; + +return 0 ; + +error: +mt7996_stop_hardware (dev); + +return ret; }void mt7996_set_stream_vht_txbf_caps (struct mt7996_phy *phy)@@ -1777,22 +1805,22 @@ int mt7996_register_device(struct mt7996_dev *dev) ret =mt7996_register_phy (dev,MT_BAND1 );if (ret) -return ret; + goto stop_hw; ret =mt7996_register_phy (dev,MT_BAND2 );if (ret) -return ret; + goto stop_hw; ret =mt7996_npu_hw_init (dev);if (ret) -return ret; + goto stop_hw;mt7996_dma_rro_start (dev); ret =mt76_register_device (&dev->mt76, true, mt76_rates,ARRAY_SIZE (mt76_rates));if (ret) -return ret; + goto stop_hw;mt7996_for_each_phy (dev, phy)mt7996_thermal_init (phy);@@ -1803,24 +1831,30 @@ int mt7996_register_device(struct mt7996_dev *dev) ret =mt7996_init_debugfs (dev);if (ret) - goto error; + goto unregister; ret =mt7996_coredump_register (dev);if (ret) - goto error; + goto unregister;return 0 ; -error: +unregister: +mt7996_set_hw_init_done (dev, false);cancel_work_sync (&dev->init_work); +cancel_work_sync (&dev->dump_work); +cancel_work_sync (&dev->reset_work); +mt7996_for_each_phy (dev, phy) +mt7996_unregister_thermal (phy); +mt76_unregister_device (&dev->mt76); +stop_hw: +mt7996_stop_hardware (dev);return ret; }void mt7996_unregister_device (struct mt7996_dev *dev) { -int i; -mt7996_set_hw_init_done (dev, false);cancel_work_sync (&dev->dump_work);cancel_work_sync (&dev->wed_rro.work);@@ -1831,18 +1865,7 @@ void mt7996_unregister_device(struct mt7996_dev *dev)mt7996_unregister_thermal (&dev->phy);mt7996_coredump_unregister (dev);mt76_unregister_device (&dev->mt76); -mt7996_wed_rro_free (dev); -for (i =0 ; i <ARRAY_SIZE (dev->mt76.napi); i++) { -if (dev->mt76.napi[i].dev) -napi_disable (&dev->mt76.napi[i]); - } -mt7996_mcu_exit (dev); -mt7996_tx_token_put (dev); -mt7996_dma_cleanup (dev); -if (mt7996_has_hwrro (dev) && - !mtk_wed_device_active (&dev->mt76.mmio.wed)) -mt7996_rro_msdu_page_map_free (dev); -tasklet_disable (&dev->mt76.irq_tasklet); +mt7996_stop_hardware (dev);mt76_free_device (&dev->mt76); }Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 4/20 wifi: mt76: mt7996: clean up the DMA when the NPU RX queue init fails
In reply to Felix Fietkaumt7996_dma_init() returns an error of mt7996_npu_rx_queues_init() after mt76_init_queues() enabled the RX NAPIs, and the probe then frees the device. The RX NAPIs stay in the global NAPI hash inside the freed memory, and their threads, page pools and dummy netdevs leak.
On this error, disable the RX NAPIs and clean up the DMA, as the stop of the hardware does. Set up the TX NAPI before the NPU RX queues, since mt76_dma_cleanup() needs it.
--- .../net/wireless/mediatek/mt76/mt7996/dma.c | 21 +++++++++++++++---- .../net/wireless/mediatek/mt76/mt7996/init.c | 7 +------ .../wireless/mediatek/mt76/mt7996/mt7996.h | 1 + 3 files changed, 19 insertions(+), 10 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/dma.c +17 -4
@@ -945,14 +945,17 @@ int mt7996_dma_init(struct mt7996_dev *dev)if (ret <0 )return ret; - ret =mt7996_npu_rx_queues_init (dev); -if (ret) -return ret; -netif_napi_add_tx (dev->mt76.tx_napi_dev, &dev->mt76.tx_napi, mt7996_poll_tx);napi_enable (&dev->mt76.tx_napi); + ret =mt7996_npu_rx_queues_init (dev); +if (ret) { +mt7996_dma_rx_napi_disable (dev); +mt7996_dma_cleanup (dev); +return ret; + } +mt7996_dma_enable (dev, false);return 0 ;
@@ -1072,6 +1075,16 @@ void mt7996_dma_reset(struct mt7996_dev *dev, bool force)mt7996_dma_enable (dev, !force); } +void mt7996_dma_rx_napi_disable (struct mt7996_dev *dev) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (dev->mt76.napi); i++) { +if (dev->mt76.napi[i].dev) +napi_disable (&dev->mt76.napi[i]); + } +} +void mt7996_dma_cleanup (struct mt7996_dev *dev) {mt7996_dma_disable (dev, true);
drivers/net/wireless/mediatek/mt76/mt7996/init.c +1 -6
@@ -1272,14 +1272,9 @@ int mt7996_global_wcid_init(struct mt7996_dev *dev)static void mt7996_stop_hardware (struct mt7996_dev *dev) { -int i; -cancel_work_sync (&dev->dump_work);cancel_work_sync (&dev->reset_work); -for (i =0 ; i <ARRAY_SIZE (dev->mt76.napi); i++) { -if (dev->mt76.napi[i].dev) -napi_disable (&dev->mt76.napi[i]); - } +mt7996_dma_rx_napi_disable (dev);mt7996_mcu_exit (dev);mt7996_tx_token_put (dev);mt7996_dma_cleanup (dev);
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +1 -0
@@ -732,6 +732,7 @@ bool mt7996_eeprom_has_background_radar(struct mt7996_dev *dev);int mt7996_dma_init (struct mt7996_dev *dev);void mt7996_dma_reset (struct mt7996_dev *dev,bool force);void mt7996_dma_prefetch (struct mt7996_dev *dev); +void mt7996_dma_rx_napi_disable (struct mt7996_dev *dev);void mt7996_dma_cleanup (struct mt7996_dev *dev);void mt7996_dma_start (struct mt7996_dev *dev,bool reset,bool wed_reset); int mt7996_init_tx_queues(struct mt7996_phy *phy, int idx,
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 04/20] wifi: mt76: mt7996: clean up the DMA when the NPU RX queue init fails
Quoted 11 lines
mt7996_dma_init()returns an error ofmt7996_npu_rx_queues_init()aftermt76_init_queues()enabled the RX NAPIs, and the probe then frees the device. The RX NAPIs stay in the global NAPI hash inside the freed memory, and their threads, page pools and dummy netdevs leak.On this error, disable the RX NAPIs and clean up the DMA, as the stop of the hardware does. Set up the TX NAPI before the NPU RX queues, since
mt76_dma_cleanup()needs it.Fixes 377aa17d2aed ("wifi: mt76: mt7996: Add NPU offload support to MT7996 driver")Signed-off-by Felix Fietkau <[email protected]>
Quoted 85 lines
--- .../net/wireless/mediatek/mt76/mt7996/dma.c | 21 +++++++++++++++---- .../net/wireless/mediatek/mt76/mt7996/init.c | 7 +------ .../wireless/mediatek/mt76/mt7996/mt7996.h | 1 + 3 files changed, 19 insertions(+), 10 deletions(-)drivers/net/wireless/mediatek/mt76/mt7996/dma.c +17
-4@@ -945,14 +945,17 @@ int mt7996_dma_init(struct mt7996_dev *dev)if (ret <0 )return ret; - ret =mt7996_npu_rx_queues_init (dev); -if (ret) -return ret; -netif_napi_add_tx (dev->mt76.tx_napi_dev, &dev->mt76.tx_napi, mt7996_poll_tx);napi_enable (&dev->mt76.tx_napi); + ret =mt7996_npu_rx_queues_init (dev); +if (ret) { +mt7996_dma_rx_napi_disable (dev); +mt7996_dma_cleanup (dev); +return ret; + } +mt7996_dma_enable (dev, false);return 0 ;@@ -1072,6 +1075,16 @@ void mt7996_dma_reset(struct mt7996_dev *dev, bool force)mt7996_dma_enable (dev, !force); } +void mt7996_dma_rx_napi_disable (struct mt7996_dev *dev) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (dev->mt76.napi); i++) { +if (dev->mt76.napi[i].dev) +napi_disable (&dev->mt76.napi[i]); + } +} +void mt7996_dma_cleanup (struct mt7996_dev *dev) {mt7996_dma_disable (dev, true);drivers/net/wireless/mediatek/mt76/mt7996/init.c +1
-6@@ -1272,14 +1272,9 @@ int mt7996_global_wcid_init(struct mt7996_dev *dev)static void mt7996_stop_hardware (struct mt7996_dev *dev) { -int i; -cancel_work_sync (&dev->dump_work);cancel_work_sync (&dev->reset_work); -for (i =0 ; i <ARRAY_SIZE (dev->mt76.napi); i++) { -if (dev->mt76.napi[i].dev) -napi_disable (&dev->mt76.napi[i]); - } +mt7996_dma_rx_napi_disable (dev);mt7996_mcu_exit (dev);mt7996_tx_token_put (dev);mt7996_dma_cleanup (dev);drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +1
-0@@ -732,6 +732,7 @@ bool mt7996_eeprom_has_background_radar(struct mt7996_dev *dev);int mt7996_dma_init (struct mt7996_dev *dev);void mt7996_dma_reset (struct mt7996_dev *dev,bool force);void mt7996_dma_prefetch (struct mt7996_dev *dev); +void mt7996_dma_rx_napi_disable (struct mt7996_dev *dev);void mt7996_dma_cleanup (struct mt7996_dev *dev);void mt7996_dma_start (struct mt7996_dev *dev,bool reset,bool wed_reset); int mt7996_init_tx_queues(struct mt7996_phy *phy, int idx,Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 5/20 wifi: mt76: mt7996: name the link and the error of a failed key install
In reply to Felix Fietkaumt7996_key_iter() installs the keys of an interface or a station on a link that is added. If an install fails, it warns without the key, the link or the error. mac80211 still holds the key as uploaded, so it does not encrypt frames for that link in software.
Print the key index, the link and the error in the warning.
--- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +4 -1
@@ -295,6 +295,7 @@ mt7996_key_iter(struct ieee80211_hw *hw, struct ieee80211_vif *vif, void *data) {struct mt7996_key_iter_data *it = data; +int err;if (sta != it->sta)return ;
@@ -302,7 +303,9 @@ mt7996_key_iter(struct ieee80211_hw *hw, struct ieee80211_vif *vif,if (key->link_id >=0 && key->link_id != it->link_id)return ; -WARN_ON (mt7996_set_hw_key (hw, it->cmd, vif, sta, it->link_id, key)); + err =mt7996_set_hw_key (hw, it->cmd, vif, sta, it->link_id, key); +WARN (err,"key %d not installed on link %u: %d\n" , key->keyidx, + it->link_id, err); } static void mt7996_vif_link_teardown(struct mt7996_phy *phy,
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 05/20] wifi: mt76: mt7996: name the link and the error of a failed key install
Quoted 8 lines
mt7996_key_iter()installs the keys of an interface or a station on a link that is added. If an install fails, it warns without the key, the link or the error. mac80211 still holds the key as uploaded, so it does not encrypt frames for that link in software.Print the key index, the link and the error in the warning.
Signed-off-by Felix Fietkau <[email protected]>
Quoted 31 lines
--- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/net/wireless/mediatek/mt76/mt7996/main.c +4
-1@@ -295,6 +295,7 @@ mt7996_key_iter(struct ieee80211_hw *hw, struct ieee80211_vif *vif, void *data) {struct mt7996_key_iter_data *it = data; +int err;if (sta != it->sta)return ;@@ -302,7 +303,9 @@ mt7996_key_iter(struct ieee80211_hw *hw, struct ieee80211_vif *vif,if (key->link_id >=0 && key->link_id != it->link_id)return ; -WARN_ON (mt7996_set_hw_key (hw, it->cmd, vif, sta, it->link_id, key)); + err =mt7996_set_hw_key (hw, it->cmd, vif, sta, it->link_id, key); +WARN (err,"key %d not installed on link %u: %d\n" , key->keyidx, + it->link_id, err); } static void mt7996_vif_link_teardown(struct mt7996_phy *phy,Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 6/20 wifi: mt76: mt7925: send the HE capabilities of each link of a peer
In reply to Felix Fietkaumt7925_mcu_sta_he_tlv() passes the station to mt76_connac_mcu_sta_he_tlv_v2(), which reads the HE capabilities and the bandwidth of sta->deflink, the association link. mac80211 fills the capabilities of each link of an MLD peer from the elements of that link. STA_REC_HE_V2 of every other link thus carries the HE capabilities, MCS maps and bandwidth of the association link. A 5 GHz link of a peer that associated on 2.4 GHz, for example, gets no 160 MHz map.
Take the HE capabilities and the bandwidth of the link station, like the other STA_REC TLVs of mt7925. mt7921 has one link per station and passes its deflink.
--- drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 9 +++++---- drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h | 3 ++- drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +5 -4
@@ -822,9 +822,10 @@ mt76_connac_mcu_sta_he_tlv(struct sk_buff *skb, struct ieee80211_sta *sta) }void -mt76_connac_mcu_sta_he_tlv_v2 (struct sk_buff *skb,struct ieee80211_sta *sta) +mt76_connac_mcu_sta_he_tlv_v2 (struct sk_buff *skb, +struct ieee80211_link_sta *link_sta) { -struct ieee80211_sta_he_cap *he_cap = &sta->deflink.he_cap; +struct ieee80211_sta_he_cap *he_cap = &link_sta->he_cap;struct ieee80211_he_cap_elem *elem = &he_cap->he_cap_elem;struct sta_rec_he_v2 *he;struct tlv *tlv;
@@ -835,7 +836,7 @@ mt76_connac_mcu_sta_he_tlv_v2(struct sk_buff *skb, struct ieee80211_sta *sta)memcpy (he->he_phy_cap, elem->phy_cap_info,sizeof (he->he_phy_cap));memcpy (he->he_mac_cap, elem->mac_cap_info,sizeof (he->he_mac_cap)); -switch (sta->deflink.bandwidth) { +switch (link_sta->bandwidth) {case IEEE80211_STA_RX_BW_160 :if (elem->phy_cap_info[0 ] &IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G )
@@ -962,7 +963,7 @@ void mt76_connac_mcu_sta_tlv(struct mt76_phy *mphy, struct sk_buff *skb,/* starec he */ if (sta->deflink.he_cap.has_he) {mt76_connac_mcu_sta_he_tlv (skb, sta); -mt76_connac_mcu_sta_he_tlv_v2 (skb, sta); +mt76_connac_mcu_sta_he_tlv_v2 (skb, &sta->deflink);if (band ==NL80211_BAND_6GHZ && sta_state ==MT76_STA_INFO_STATE_ASSOC ) {struct sta_rec_he_6g_capa *he_6g_capa;
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +2 -1
@@ -2092,7 +2092,8 @@ void mt76_connac_mcu_wtbl_hdr_trans_tlv(struct sk_buff *skb,int mt76_connac_mcu_sta_update_hdr_trans (struct mt76_dev *dev,struct ieee80211_vif *vif,struct mt76_wcid *wcid,int cmd); -void mt76_connac_mcu_sta_he_tlv_v2 (struct sk_buff *skb,struct ieee80211_sta *sta); +void mt76_connac_mcu_sta_he_tlv_v2 (struct sk_buff *skb, +struct ieee80211_link_sta *link_sta);u8 mt76_connac_get_phy_mode_v2 (struct mt76_phy *mphy,struct ieee80211_vif *vif,enum nl80211_band band,struct ieee80211_link_sta *link_sta);
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +1 -1
@@ -1926,7 +1926,7 @@ mt7925_mcu_sta_he_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta)if (!link_sta->he_cap.has_he)return ; -mt76_connac_mcu_sta_he_tlv_v2 (skb, link_sta->sta); +mt76_connac_mcu_sta_he_tlv_v2 (skb, link_sta); } static void
Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 7/20 wifi: mt76: connac: mask the LDPC capabilities of an AP peer
In reply to Felix Fietkaumt76_connac_mcu_sta_tlv() copies the HT, VHT and HE capabilities of the peer into the STA_REC TLVs unchanged. On mt7615, mt7663 and mt7921, both callers of mt76_connac_mcu_wtbl_ht_tlv() enable WTBL LDPC for any LDPC peer. mac80211 keeps the AP's own setting in ht_ldpc, vht_ldpc and he_ldpc of the link conf alone. An AP configured without LDPC can thus send LDPC frames to an LDPC peer.
On an AP, clear each LDPC bit of these TLVs where the link conf has no LDPC for that mode. Clear the WTBL LDPC fields under that condition, like mt7915 does for the WTBL and mt7996 for its STA_REC TLVs. Other interface types keep the peer's bits, since mac80211 sets these link conf fields for an AP alone.
--- .../net/wireless/mediatek/mt76/mt7615/mcu.c | 4 ++- .../wireless/mediatek/mt76/mt76_connac_mcu.c | 31 ++++++++++++++----- .../wireless/mediatek/mt76/mt76_connac_mcu.h | 21 ++++++++++++- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 2 +- 4 files changed, 47 insertions(+), 11 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/mcu.c +3 -1
@@ -898,7 +898,9 @@ mt7615_mcu_wtbl_sta_add(struct mt7615_phy *phy, struct ieee80211_vif *vif, NULL, wtbl_hdr);if (sta)mt76_connac_mcu_wtbl_ht_tlv (&dev->mt76, wskb, sta, -NULL , wtbl_hdr, true, true); +NULL , wtbl_hdr, +mt76_connac_mcu_ht_ldpc (&vif->bss_conf), +mt76_connac_mcu_vht_ldpc (&vif->bss_conf));mt76_connac_mcu_wtbl_hdr_trans_tlv (wskb, vif, &msta->wcid,NULL , wtbl_hdr); }
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +23 -8
@@ -689,7 +689,8 @@ mt76_connac_mcu_sta_amsdu_tlv(struct sk_buff *skb, struct ieee80211_sta *sta,#define HE_PHY (p, c) u8_get_bits(c, IEEE80211_HE_PHY_##p)#define HE_MAC (m, c) u8_get_bits(c, IEEE80211_HE_MAC_##m)static void -mt76_connac_mcu_sta_he_tlv (struct sk_buff *skb,struct ieee80211_sta *sta) +mt76_connac_mcu_sta_he_tlv (struct sk_buff *skb,struct ieee80211_sta *sta, +bool ldpc) {struct ieee80211_sta_he_cap *he_cap = &sta->deflink.he_cap;struct ieee80211_he_cap_elem *elem = &he_cap->he_cap_elem;
@@ -721,7 +722,7 @@ mt76_connac_mcu_sta_he_tlv(struct sk_buff *skb, struct ieee80211_sta *sta) IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G)) cap |= STA_REC_HE_CAP_BW20_RU242_SUPPORT; -if (elem->phy_cap_info[1 ] & +if (ldpc && elem->phy_cap_info[1 ] &IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD ) cap |=STA_REC_HE_CAP_LDPC ;
@@ -823,7 +824,7 @@ mt76_connac_mcu_sta_he_tlv(struct sk_buff *skb, struct ieee80211_sta *sta)void mt76_connac_mcu_sta_he_tlv_v2 (struct sk_buff *skb, -struct ieee80211_link_sta *link_sta) +struct ieee80211_link_sta *link_sta,bool ldpc) {struct ieee80211_sta_he_cap *he_cap = &link_sta->he_cap;struct ieee80211_he_cap_elem *elem = &he_cap->he_cap_elem;
@@ -836,6 +837,9 @@ mt76_connac_mcu_sta_he_tlv_v2(struct sk_buff *skb,memcpy (he->he_phy_cap, elem->phy_cap_info,sizeof (he->he_phy_cap));memcpy (he->he_mac_cap, elem->mac_cap_info,sizeof (he->he_mac_cap)); +if (!ldpc) + he->he_phy_cap[1 ] &= ~IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD ; +switch (link_sta->bandwidth) {case IEEE80211_STA_RX_BW_160 : if (elem->phy_cap_info[0] &
@@ -931,22 +935,30 @@ void mt76_connac_mcu_sta_tlv(struct mt76_phy *mphy, struct sk_buff *skb,/* starec ht */ if (sta->deflink.ht_cap.ht_supported) { +u16 cap = sta->deflink.ht_cap.cap;struct sta_rec_ht *ht; +if (!mt76_connac_mcu_ht_ldpc (&vif->bss_conf)) + cap &= ~IEEE80211_HT_CAP_LDPC_CODING ; + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_HT ,sizeof (*ht)); ht = (struct sta_rec_ht *)tlv; - ht->ht_cap =cpu_to_le16 (sta->deflink.ht_cap.cap); + ht->ht_cap =cpu_to_le16 (cap); }/* starec vht */ if (sta->deflink.vht_cap.vht_supported) { +u32 cap = sta->deflink.vht_cap.cap;struct sta_rec_vht *vht;int len; +if (!mt76_connac_mcu_vht_ldpc (&vif->bss_conf)) + cap &= ~IEEE80211_VHT_CAP_RXLDPC ; + len =is_connac2 (dev) ?sizeof (*vht) :sizeof (*vht) -4 ; tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_VHT , len); vht = (struct sta_rec_vht *)tlv; - vht->vht_cap =cpu_to_le32 (sta->deflink.vht_cap.cap); + vht->vht_cap =cpu_to_le32 (cap); vht->vht_rx_mcs_map = sta->deflink.vht_cap.vht_mcs.rx_mcs_map; vht->vht_tx_mcs_map = sta->deflink.vht_cap.vht_mcs.tx_mcs_map; }
@@ -962,8 +974,10 @@ void mt76_connac_mcu_sta_tlv(struct mt76_phy *mphy, struct sk_buff *skb,/* starec he */ if (sta->deflink.he_cap.has_he) { -mt76_connac_mcu_sta_he_tlv (skb, sta); -mt76_connac_mcu_sta_he_tlv_v2 (skb, &sta->deflink); +bool ldpc =mt76_connac_mcu_he_ldpc (&vif->bss_conf); + +mt76_connac_mcu_sta_he_tlv (skb, sta, ldpc); +mt76_connac_mcu_sta_he_tlv_v2 (skb, &sta->deflink, ldpc);if (band ==NL80211_BAND_6GHZ && sta_state ==MT76_STA_INFO_STATE_ASSOC ) {struct sta_rec_he_6g_capa *he_6g_capa;
@@ -1155,7 +1169,8 @@ int mt76_connac_mcu_sta_cmd(struct mt76_phy *phy,if (info->sta)mt76_connac_mcu_wtbl_ht_tlv (dev, skb, info->sta, sta_wtbl, wtbl_hdr, - true, true); +mt76_connac_mcu_ht_ldpc (info->link_conf), +mt76_connac_mcu_vht_ldpc (info->link_conf)); }return mt76_mcu_skb_send_msg (dev, skb, info->cmd, true);
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +20 -1
@@ -2075,6 +2075,24 @@ mt76_connac_mcu_add_tlv(struct sk_buff *skb, int tag, int len)return mt76_connac_mcu_add_nested_tlv (skb, tag, len, skb->data,NULL ); } +static inline bool +mt76_connac_mcu_ht_ldpc (struct ieee80211_bss_conf *link_conf) +{ +return link_conf->vif->type !=NL80211_IFTYPE_AP || link_conf->ht_ldpc; +} + +static inline bool +mt76_connac_mcu_vht_ldpc (struct ieee80211_bss_conf *link_conf) +{ +return link_conf->vif->type !=NL80211_IFTYPE_AP || link_conf->vht_ldpc; +} + +static inline bool +mt76_connac_mcu_he_ldpc (struct ieee80211_bss_conf *link_conf) +{ +return link_conf->vif->type !=NL80211_IFTYPE_AP || link_conf->he_ldpc; +} +int mt76_connac_mcu_set_channel_domain (struct mt76_phy *phy);int mt76_connac_mcu_set_vif_ps (struct mt76_dev *dev,struct ieee80211_vif *vif); void mt76_connac_mcu_sta_basic_tlv(struct mt76_dev *dev, struct sk_buff *skb,
@@ -2093,7 +2111,8 @@ int mt76_connac_mcu_sta_update_hdr_trans(struct mt76_dev *dev,struct ieee80211_vif *vif, struct mt76_wcid *wcid, int cmd);void mt76_connac_mcu_sta_he_tlv_v2 (struct sk_buff *skb, -struct ieee80211_link_sta *link_sta); +struct ieee80211_link_sta *link_sta, +bool ldpc);u8 mt76_connac_get_phy_mode_v2 (struct mt76_phy *mphy,struct ieee80211_vif *vif,enum nl80211_band band,struct ieee80211_link_sta *link_sta);
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +1 -1
@@ -1926,7 +1926,7 @@ mt7925_mcu_sta_he_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta)if (!link_sta->he_cap.has_he)return ; -mt76_connac_mcu_sta_he_tlv_v2 (skb, link_sta); +mt76_connac_mcu_sta_he_tlv_v2 (skb, link_sta, true); } static void
Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 8/20 wifi: mt76: mt7925: mask the LDPC capabilities of an AP peer
In reply to Felix Fietkaumt7925_mcu_sta_ht_tlv(), mt7925_mcu_sta_vht_tlv() and mt7925_mcu_sta_he_tlv() send the capabilities of the peer link unchanged. mac80211 keeps the AP's own setting in ht_ldpc, vht_ldpc and he_ldpc of the link conf alone. An AP configured without LDPC can thus send LDPC frames to an LDPC peer.
On an AP, clear each LDPC bit where the conf of the peer's link has no LDPC for that mode. mt7996 does the same. Other interface types keep the peer's bits, since mac80211 sets these link conf fields for an AP alone.
--- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +25 -9
@@ -1921,12 +1921,14 @@ mt7925_mcu_set_bss_pm(struct mt792x_dev *dev, }static void -mt7925_mcu_sta_he_tlv (struct sk_buff *skb,struct ieee80211_link_sta *link_sta) +mt7925_mcu_sta_he_tlv (struct sk_buff *skb,struct ieee80211_bss_conf *link_conf, +struct ieee80211_link_sta *link_sta) {if (!link_sta->he_cap.has_he)return ; -mt76_connac_mcu_sta_he_tlv_v2 (skb, link_sta, true); +mt76_connac_mcu_sta_he_tlv_v2 (skb, link_sta, +mt76_connac_mcu_he_ldpc (link_conf)); } static void
@@ -1975,23 +1977,30 @@ mt7925_mcu_sta_eht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta) }static void -mt7925_mcu_sta_ht_tlv (struct sk_buff *skb,struct ieee80211_link_sta *link_sta) +mt7925_mcu_sta_ht_tlv (struct sk_buff *skb,struct ieee80211_bss_conf *link_conf, +struct ieee80211_link_sta *link_sta) { +u16 cap = link_sta->ht_cap.cap;struct sta_rec_ht *ht;struct tlv *tlv;if (!link_sta->ht_cap.ht_supported)return ; +if (!mt76_connac_mcu_ht_ldpc (link_conf)) + cap &= ~IEEE80211_HT_CAP_LDPC_CODING ; + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_HT ,sizeof (*ht)); ht = (struct sta_rec_ht *)tlv; - ht->ht_cap =cpu_to_le16 (link_sta->ht_cap.cap); + ht->ht_cap =cpu_to_le16 (cap); }static void -mt7925_mcu_sta_vht_tlv (struct sk_buff *skb,struct ieee80211_link_sta *link_sta) +mt7925_mcu_sta_vht_tlv (struct sk_buff *skb,struct ieee80211_bss_conf *link_conf, +struct ieee80211_link_sta *link_sta) { +u32 cap = link_sta->vht_cap.cap;struct sta_rec_vht *vht;struct tlv *tlv;
@@ -1999,10 +2008,13 @@ mt7925_mcu_sta_vht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta)if (!link_sta->he_6ghz_capa.capa && !link_sta->vht_cap.vht_supported)return ; +if (!mt76_connac_mcu_vht_ldpc (link_conf)) + cap &= ~IEEE80211_VHT_CAP_RXLDPC ; + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_VHT ,sizeof (*vht)); vht = (struct sta_rec_vht *)tlv; - vht->vht_cap =cpu_to_le32 (link_sta->vht_cap.cap); + vht->vht_cap =cpu_to_le32 (cap); vht->vht_rx_mcs_map = link_sta->vht_cap.vht_mcs.rx_mcs_map; vht->vht_tx_mcs_map = link_sta->vht_cap.vht_mcs.tx_mcs_map; }
@@ -2310,6 +2322,7 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy, struct mt792x_link_sta *pending) {struct mt792x_vif *mvif = (struct mt792x_vif *)info->vif->drv_priv; +struct ieee80211_bss_conf *link_conf;struct mt76_dev *dev = phy->dev;struct mt792x_bss_conf *mconf;struct mt792x_link_sta *mlink;
@@ -2328,15 +2341,18 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy,CONN_STATE_DISCONNECT ;if (info->enable && info->link_sta) { + link_conf =mt792x_vif_to_bss_conf (info->vif, + info->link_sta->link_id); +mt76_connac_mcu_sta_basic_tlv (dev, skb, info->link_conf, info->link_sta, conn_state, info->newly);mt7925_mcu_sta_phy_tlv (skb, info->vif, info->link_sta); -mt7925_mcu_sta_ht_tlv (skb, info->link_sta); -mt7925_mcu_sta_vht_tlv (skb, info->link_sta); +mt7925_mcu_sta_ht_tlv (skb, link_conf, info->link_sta); +mt7925_mcu_sta_vht_tlv (skb, link_conf, info->link_sta);mt76_connac_mcu_sta_uapsd (skb, info->vif, info->link_sta->sta);mt7925_mcu_sta_amsdu_tlv (skb, info->vif, info->link_sta, mlink); -mt7925_mcu_sta_he_tlv (skb, info->link_sta); +mt7925_mcu_sta_he_tlv (skb, link_conf, info->link_sta);mt7925_mcu_sta_he_6g_tlv (skb, info->link_sta);mt7925_mcu_sta_eht_tlv (skb, info->link_sta); mt7925_mcu_sta_rate_ctrl_tlv(skb, info->vif,
Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 9/20 wifi: mt76: mt7996: read the EHT capabilities of a station as LE
In reply to Felix Fietkaumt7996_mcu_sta_eht_tlv() reads the EHT MAC and PHY capability bytes as host integers. On a big-endian host the firmware thus gets these bytes in reverse order. The casts also assume an alignment that the u8 arrays do not guarantee.
Read both fields with the unaligned little-endian helpers.
--- drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +2 -2
@@ -1753,8 +1753,8 @@ mt7996_mcu_sta_eht_tlv(struct sk_buff *skb, eht = (struct sta_rec_eht *)tlv; eht->tid_bitmap =0xff ; - eht->mac_cap =cpu_to_le16 (*(u16 *)elem->mac_cap_info); - eht->phy_cap =cpu_to_le64 (*(u64 *)elem->phy_cap_info); + eht->mac_cap =cpu_to_le16 (get_unaligned_le16 (elem->mac_cap_info)); + eht->phy_cap =cpu_to_le64 (get_unaligned_le64 (elem->phy_cap_info)); eht->phy_cap_ext =cpu_to_le64 (elem->phy_cap_info[8 ]); if (vif->type != NL80211_IFTYPE_STATION &&
Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 10/20 wifi: mt76: mt7925: read the EHT capabilities of a station as LE
In reply to Felix Fietkaumt7925_mcu_sta_eht_tlv() reads the EHT MAC and PHY capability bytes as host integers. On a big-endian host the firmware thus gets these bytes in reverse order. The casts also assume an alignment that the u8 arrays do not guarantee.
Read both fields with the unaligned little-endian helpers.
--- drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +2 -2
@@ -1965,8 +1965,8 @@ mt7925_mcu_sta_eht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta) eht = (struct sta_rec_eht *)tlv; eht->tid_bitmap =0xff ; - eht->mac_cap =cpu_to_le16 (*(u16 *)elem->mac_cap_info); - eht->phy_cap =cpu_to_le64 (*(u64 *)elem->phy_cap_info); + eht->mac_cap =cpu_to_le16 (get_unaligned_le16 (elem->mac_cap_info)); + eht->phy_cap =cpu_to_le64 (get_unaligned_le64 (elem->phy_cap_info)); eht->phy_cap_ext =cpu_to_le64 (elem->phy_cap_info[8 ]);if (link_sta->bandwidth ==IEEE80211_STA_RX_BW_20 )
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 10/20] wifi: mt76: mt7925: read the EHT capabilities of a station as LE
Quoted 9 lines
mt7925_mcu_sta_eht_tlv()reads the EHT MAC and PHY capability bytes as host integers. On a big-endian host the firmware thus gets these bytes in reverse order. The casts also assume an alignment that the u8 arrays do not guarantee.Read both fields with the unaligned little-endian helpers.
Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")Signed-off-by Felix Fietkau <[email protected]>
Quoted 23 lines
--- drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +2
-2@@ -1965,8 +1965,8 @@ mt7925_mcu_sta_eht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta) eht = (struct sta_rec_eht *)tlv; eht->tid_bitmap =0xff ; - eht->mac_cap =cpu_to_le16 (*(u16 *)elem->mac_cap_info); - eht->phy_cap =cpu_to_le64 (*(u64 *)elem->phy_cap_info); + eht->mac_cap =cpu_to_le16 (get_unaligned_le16 (elem->mac_cap_info)); + eht->phy_cap =cpu_to_le64 (get_unaligned_le64 (elem->phy_cap_info)); eht->phy_cap_ext =cpu_to_le64 (elem->phy_cap_info[8 ]);if (link_sta->bandwidth ==IEEE80211_STA_RX_BW_20 )Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 11/20 wifi: mt76: mt7615: drop RX frame with a header gap past its end
In reply to Felix Fietkaumt7615_mac_fill_rx() does not check hdr_gap against the linear data of the skb. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. If hdr_gap is too large, skb_pull() hits the BUG() in __skb_pull(), or fails and leaves no headroom, so the __skb_push() in mt76_insert_ccmp_hdr() writes before skb->head. For a first fragment, mt7615_reverse_frag0_hdr_trans() reads an Ethernet header after hdr_gap, and a frame too short for it makes the skb_push() of the LLC header hit skb_under_panic().
Drop the frame if hdr_gap is not within the linear data, or if a first fragment holds no full Ethernet header there.
--- drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +6 -0
@@ -257,6 +257,9 @@ static int mt7615_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)struct ieee80211_hdr hdr;u16 frame_control; +if (skb_headlen (skb) < hdr_gap +sizeof (*eth_hdr)) +return -EINVAL ; +if (le32_get_bits (rxd[1 ],MT_RXD1_NORMAL_ADDR_TYPE ) !=MT_RXD1_NORMAL_U2M )return -EINVAL ;
@@ -594,6 +597,9 @@ static int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb) } hdr_gap = (u8 *)rxd - skb->data +2 * remove_pad; +if (hdr_gap >=skb_headlen (skb)) +return -EINVAL ; +if (hdr_trans &&ieee80211_has_morefrags (fc)) {if (mt7615_reverse_frag0_hdr_trans (skb, hdr_gap))return -EINVAL ;
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 11/20] wifi: mt76: mt7615: drop RX frame with a header gap past its end
Quoted 9 lines · Felix Fietkau
mt7615_mac_fill_rx()does not checkhdr_gapagainst the linear data of the skb. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. Ifhdr_gapis too large,skb_pull()hits theBUG()in__skb_pull(), or fails and leaves no headroom, so the__skb_push()inmt76_insert_ccmp_hdr()writes beforeskb->head. For a first fragment,mt7615_reverse_frag0_hdr_trans()reads an Ethernet header afterhdr_gap, and a frame too short for it makes theskb_push()of the LLC header hitskb_under_panic().
Quoted 7 lines
Drop the frame if
hdr_gapis not within the linear data, or if a first fragment holds no full Ethernet header there.Fixes 04b8e65922f6 ("mt76: add mac80211 driver for MT7615 PCIe-based chipsets")Fixes dc5399a50b45 ("mt76: reverse the first fragmented frame to 802.11")Signed-off-by Felix Fietkau <[email protected]>
Quoted 32 lines
--- drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/wireless/mediatek/mt76/mt7615/mac.c +6
-0@@ -257,6 +257,9 @@ static int mt7615_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)struct ieee80211_hdr hdr;u16 frame_control; +if (skb_headlen (skb) < hdr_gap +sizeof (*eth_hdr)) +return -EINVAL ; +if (le32_get_bits (rxd[1 ],MT_RXD1_NORMAL_ADDR_TYPE ) !=MT_RXD1_NORMAL_U2M )return -EINVAL ;@@ -594,6 +597,9 @@ static int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb) } hdr_gap = (u8 *)rxd - skb->data +2 * remove_pad; +if (hdr_gap >=skb_headlen (skb)) +return -EINVAL ; +if (hdr_trans &&ieee80211_has_morefrags (fc)) {if (mt7615_reverse_frag0_hdr_trans (skb, hdr_gap))return -EINVAL ;Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 12/20 wifi: mt76: connac: drop a first fragment without an Ethernet header
In reply to Felix Fietkaumt76_connac2_reverse_frag0_hdr_trans() reads an Ethernet header after hdr_offset, but does not check that the linear data of the skb holds one. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. For a shorter first buffer, skb_pull() hits the BUG() in __skb_pull(), or fails and leaves no headroom, so the skb_push() of the LLC header hits skb_under_panic().
Drop a first fragment whose linear data holds no full Ethernet header after the header gap.
--- drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c +3 -0
@@ -976,6 +976,9 @@ int mt76_connac2_reverse_frag0_hdr_trans(struct ieee80211_vif *vif,struct ieee80211_hdr hdr;u16 frame_control; +if (skb_headlen (skb) < hdr_offset +sizeof (*eth_hdr)) +return -EINVAL ; +if (le32_get_bits (rxd[3 ],MT_RXD3_NORMAL_ADDR_TYPE ) !=MT_RXD3_NORMAL_U2M )return -EINVAL ;
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 12/20] wifi: mt76: connac: drop a first fragment without an Ethernet header
Quoted 7 lines
mt76_connac2_reverse_frag0_hdr_trans()reads an Ethernet header afterhdr_offset, but does not check that the linear data of the skb holds one. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. For a shorter first buffer,skb_pull()hits theBUG()in__skb_pull(), or fails and leaves no headroom, so theskb_push()of the LLC header hitsskb_under_panic().
Quoted 6 lines
Drop a first fragment whose linear data holds no full Ethernet header after the header gap.
Fixes dc5399a50b45 ("mt76: reverse the first fragmented frame to 802.11")Signed-off-by Felix Fietkau <[email protected]>
Quoted 22 lines
--- drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c +3
-0@@ -976,6 +976,9 @@ int mt76_connac2_reverse_frag0_hdr_trans(struct ieee80211_vif *vif,struct ieee80211_hdr hdr;u16 frame_control; +if (skb_headlen (skb) < hdr_offset +sizeof (*eth_hdr)) +return -EINVAL ; +if (le32_get_bits (rxd[3 ],MT_RXD3_NORMAL_ADDR_TYPE ) !=MT_RXD3_NORMAL_U2M )return -EINVAL ;Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 13/20 wifi: mt76: mt7915: drop RX frame with a header gap past its end
In reply to Felix Fietkaumt7915_mac_fill_rx() does not check hdr_gap against the linear data of the skb. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. If hdr_gap is too large, skb_pull() hits the BUG() in __skb_pull(), or fails and leaves no headroom, so the __skb_push() in mt76_insert_ccmp_hdr() writes before skb->head.
Drop the frame if hdr_gap is not within the linear data.
--- drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +3 -0
@@ -471,6 +471,9 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb, } hdr_gap = (u8 *)rxd - skb->data +2 * remove_pad; +if (hdr_gap >=skb_headlen (skb)) +return -EINVAL ; +if (hdr_trans &&ieee80211_has_morefrags (fc)) {struct ieee80211_vif *vif;int err;
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 13/20] wifi: mt76: mt7915: drop RX frame with a header gap past its end
Quoted 11 lines
mt7915_mac_fill_rx()does not checkhdr_gapagainst the linear data of the skb. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. Ifhdr_gapis too large,skb_pull()hits theBUG()in__skb_pull(), or fails and leaves no headroom, so the__skb_push()inmt76_insert_ccmp_hdr()writes beforeskb->head.Drop the frame if
hdr_gapis not within the linear data.Fixes e57b7901469f ("mt76: add mac80211 driver for MT7915 PCIe-based chipsets")Signed-off-by Felix Fietkau <[email protected]>
Quoted 22 lines
--- drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/wireless/mediatek/mt76/mt7915/mac.c +3
-0@@ -471,6 +471,9 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb, } hdr_gap = (u8 *)rxd - skb->data +2 * remove_pad; +if (hdr_gap >=skb_headlen (skb)) +return -EINVAL ; +if (hdr_trans &&ieee80211_has_morefrags (fc)) {struct ieee80211_vif *vif;int err;Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 14/20 wifi: mt76: mt7921: drop RX frame with a header gap past its end
In reply to Felix Fietkaumt7921_mac_fill_rx() does not check hdr_gap against the linear data of the skb. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. If hdr_gap is too large, skb_pull() hits the BUG() in __skb_pull(), or fails and leaves no headroom, so the __skb_push() in mt76_insert_ccmp_hdr() writes before skb->head.
Drop the frame if hdr_gap is not within the linear data.
--- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7921/mac.c +3 -0
@@ -383,6 +383,9 @@ mt7921_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb) } hdr_gap = (u8 *)rxd - skb->data +2 * remove_pad; +if (hdr_gap >=skb_headlen (skb)) +return -EINVAL ; +if (hdr_trans &&ieee80211_has_morefrags (fc)) {struct ieee80211_vif *vif;int err;
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 14/20] wifi: mt76: mt7921: drop RX frame with a header gap past its end
Quoted 11 lines · Felix Fietkau
mt7921_mac_fill_rx()does not checkhdr_gapagainst the linear data of the skb. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. Ifhdr_gapis too large,skb_pull()hits theBUG()in__skb_pull(), or fails and leaves no headroom, so the__skb_push()inmt76_insert_ccmp_hdr()writes beforeskb->head.Drop the frame if
hdr_gapis not within the linear data.Fixes 163f4d22c118 ("mt76: mt7921: add MAC support")Signed-off-by Felix Fietkau <[email protected]>
Quoted 22 lines
--- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/wireless/mediatek/mt76/mt7921/mac.c +3
-0@@ -383,6 +383,9 @@ mt7921_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb) } hdr_gap = (u8 *)rxd - skb->data +2 * remove_pad; +if (hdr_gap >=skb_headlen (skb)) +return -EINVAL ; +if (hdr_trans &&ieee80211_has_morefrags (fc)) {struct ieee80211_vif *vif;int err;Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 15/20 wifi: mt76: mt7996: drop RX frame with a header gap past its end
In reply to Felix Fietkaumt7996_mac_fill_rx() does not check hdr_gap against the linear data of the skb. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. If hdr_gap is too large, skb_pull() hits the BUG() in __skb_pull(), or fails and leaves no headroom, so the __skb_push() in mt76_insert_ccmp_hdr() writes before skb->head. For a first fragment, mt7996_reverse_frag0_hdr_trans() reads an Ethernet header after hdr_gap, and a frame too short for it makes the skb_push() of the LLC header hit skb_under_panic().
Drop the frame if hdr_gap is not within the linear data, or if a first fragment holds no full Ethernet header there.
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +6 -0
@@ -203,6 +203,9 @@ static int mt7996_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)struct mt7996_sta *msta;u16 frame_control; +if (skb_headlen (skb) < hdr_gap +sizeof (*eth_hdr)) +return -EINVAL ; +if (le32_get_bits (rxd[3 ],MT_RXD3_NORMAL_ADDR_TYPE ) !=MT_RXD3_NORMAL_U2M )return -EINVAL ;
@@ -642,6 +645,9 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q,return -EINVAL ; hdr_gap = (u8 *)rxd - skb->data +2 * remove_pad; +if (hdr_gap >=skb_headlen (skb)) +return -EINVAL ; +if (hdr_trans &&ieee80211_has_morefrags (fc)) {if (mt7996_reverse_frag0_hdr_trans (skb, hdr_gap))return -EINVAL ;
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 15/20] wifi: mt76: mt7996: drop RX frame with a header gap past its end
Quoted 9 lines
mt7996_mac_fill_rx()does not checkhdr_gapagainst the linear data of the skb. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. Ifhdr_gapis too large,skb_pull()hits theBUG()in__skb_pull(), or fails and leaves no headroom, so the__skb_push()inmt76_insert_ccmp_hdr()writes beforeskb->head. For a first fragment,mt7996_reverse_frag0_hdr_trans()reads an Ethernet header afterhdr_gap, and a frame too short for it makes theskb_push()of the LLC header hitskb_under_panic().
Quoted 6 lines
Drop the frame if
hdr_gapis not within the linear data, or if a first fragment holds no full Ethernet header there.Fixes 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")Signed-off-by Felix Fietkau <[email protected]>
Quoted 32 lines
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/wireless/mediatek/mt76/mt7996/mac.c +6
-0@@ -203,6 +203,9 @@ static int mt7996_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)struct mt7996_sta *msta;u16 frame_control; +if (skb_headlen (skb) < hdr_gap +sizeof (*eth_hdr)) +return -EINVAL ; +if (le32_get_bits (rxd[3 ],MT_RXD3_NORMAL_ADDR_TYPE ) !=MT_RXD3_NORMAL_U2M )return -EINVAL ;@@ -642,6 +645,9 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q,return -EINVAL ; hdr_gap = (u8 *)rxd - skb->data +2 * remove_pad; +if (hdr_gap >=skb_headlen (skb)) +return -EINVAL ; +if (hdr_trans &&ieee80211_has_morefrags (fc)) {if (mt7996_reverse_frag0_hdr_trans (skb, hdr_gap))return -EINVAL ;Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 16/20 wifi: mt76: mt7925: bound the header gap by the linear data of a frame
In reply to Felix Fietkaumt7925_mac_fill_rx() and mt7925_reverse_frag0_hdr_trans() check hdr_gap against skb->len. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. A hdr_gap past the linear data thus still hits the BUG() in __skb_pull(), and the Ethernet header of a first fragment is read past the linear data.
Check hdr_gap against the linear data of the skb.
--- drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +2 -2
@@ -215,7 +215,7 @@ static int mt7925_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)struct ieee80211_hdr hdr;u16 frame_control; -if (skb->len < hdr_gap +sizeof (*eth_hdr)) +if (skb_headlen (skb) < hdr_gap +sizeof (*eth_hdr))return -EINVAL ; if (le32_get_bits(rxd[3], MT_RXD3_NORMAL_ADDR_TYPE) !=
@@ -604,7 +604,7 @@ mt7925_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb) } hdr_gap = (u8 *)rxd - skb->data +2 * remove_pad; -if (hdr_gap >= skb->len) +if (hdr_gap >=skb_headlen (skb))return -EINVAL ;if (hdr_trans &&ieee80211_has_morefrags (fc)) {
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 16/20] wifi: mt76: mt7925: bound the header gap by the linear data of a frame
Quoted 11 lines · Felix Fietkau
mt7925_mac_fill_rx()andmt7925_reverse_frag0_hdr_trans()checkhdr_gapagainstskb->len. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. Ahdr_gappast the linear data thus still hits theBUG()in__skb_pull(), and the Ethernet header of a first fragment is read past the linear data.Check
hdr_gapagainst the linear data of the skb.Fixes 211a71c64347 ("wifi: mt76: mt7925: drop RX frame with a header gap past its end")Signed-off-by Felix Fietkau <[email protected]>
Quoted 30 lines
--- drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/mediatek/mt76/mt7925/mac.c +2
-2@@ -215,7 +215,7 @@ static int mt7925_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)struct ieee80211_hdr hdr;u16 frame_control; -if (skb->len < hdr_gap +sizeof (*eth_hdr)) +if (skb_headlen (skb) < hdr_gap +sizeof (*eth_hdr))return -EINVAL ; if (le32_get_bits(rxd[3], MT_RXD3_NORMAL_ADDR_TYPE) !=@@ -604,7 +604,7 @@ mt7925_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb) } hdr_gap = (u8 *)rxd - skb->data +2 * remove_pad; -if (hdr_gap >= skb->len) +if (hdr_gap >=skb_headlen (skb))return -EINVAL ;if (hdr_trans &&ieee80211_has_morefrags (fc)) {Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 17/20 wifi: mt76: mt7921: fix out-of-bounds read in mt7921_mac_add_txs
In reply to Felix Fietkaumt7921_queue_rx_skb() walks the TXS entries up to skb->len. An skb from the USB scatter-gather RX path in mt76u_process_rx_entry() is not linear, so skb->data only covers skb_headlen(skb) bytes, and the loop reads past the head buffer of the skb.
Bound the walk by skb_headlen(skb). For a linear skb both lengths are equal.
--- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7921/mac.c +1 -1
@@ -588,7 +588,7 @@ void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, { struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);__le32 *rxd = (__le32 *)skb->data; -__le32 *end = (__le32 *)&skb->data[skb->len]; +__le32 *end = (__le32 *)&skb->data[skb_headlen (skb)];enum rx_pkt_type type;u16 flag;
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 17/20] wifi: mt76: mt7921: fix out-of-bounds read in mt7921_mac_add_txs
Quoted 11 lines · Felix Fietkau
mt7921_queue_rx_skb()walks the TXS entries up toskb->len. An skb from the USB scatter-gather RX path inmt76u_process_rx_entry()is not linear, soskb->dataonly coversskb_headlen(skb)bytes, and the loop reads past the head buffer of the skb.Bound the walk by
skb_headlen(skb). For a linear skb both lengths are equal.Fixes 0d2afe09fad5 ("mt76: mt7921: add mt7921u driver")Signed-off-by Felix Fietkau <[email protected]>
Quoted 21 lines
--- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/wireless/mediatek/mt76/mt7921/mac.c +1
-1@@ -588,7 +588,7 @@ void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, { struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);__le32 *rxd = (__le32 *)skb->data; -__le32 *end = (__le32 *)&skb->data[skb->len]; +__le32 *end = (__le32 *)&skb->data[skb_headlen (skb)];enum rx_pkt_type type;u16 flag;Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 18/20 wifi: mt76: mt7925: fix out-of-bounds read in mt7925_mac_add_txs
In reply to Felix Fietkaumt7925_queue_rx_skb() walks the TXS entries up to skb->len. An skb from the USB scatter-gather RX path in mt76u_process_rx_entry() is not linear, so skb->data only covers skb_headlen(skb) bytes, and the loop reads past the head buffer of the skb.
Bound the walk by skb_headlen(skb). For a linear skb both lengths are equal.
--- drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +1 -1
@@ -1501,7 +1501,7 @@ void mt7925_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, { struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);__le32 *rxd = (__le32 *)skb->data; -__le32 *end = (__le32 *)&skb->data[skb->len]; +__le32 *end = (__le32 *)&skb->data[skb_headlen (skb)];enum rx_pkt_type type;u16 flag;
Signature · 1 line
2.47.3
Re: [PATCH mt76-next 18/20] wifi: mt76: mt7925: fix out-of-bounds read in mt7925_mac_add_txs
Quoted 11 lines
mt7925_queue_rx_skb()walks the TXS entries up toskb->len. An skb from the USB scatter-gather RX path inmt76u_process_rx_entry()is not linear, soskb->dataonly coversskb_headlen(skb)bytes, and the loop reads past the head buffer of the skb.Bound the walk by
skb_headlen(skb). For a linear skb both lengths are equal.Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")Signed-off-by Felix Fietkau <[email protected]>
Quoted 21 lines
--- drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/wireless/mediatek/mt76/mt7925/mac.c +1
-1@@ -1501,7 +1501,7 @@ void mt7925_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, { struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);__le32 *rxd = (__le32 *)skb->data; -__le32 *end = (__le32 *)&skb->data[skb->len]; +__le32 *end = (__le32 *)&skb->data[skb_headlen (skb)];enum rx_pkt_type type;u16 flag;Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 19/20 wifi: mt76: mt7925: apply the dwell time of a scan request
In reply to Felix Fietkaumt792x_init_wiphy() advertises NL80211_EXT_FEATURE_SET_SCAN_DWELL, but mt7925_mcu_hw_scan() ignores the duration of the scan request. Since commit efeaabc5680c ("wifi: mt76: mt7925: config the dwell time by firmware") it leaves the dwell fields of the scan command at 0, so the firmware uses its default dwell time on every channel. That default is shorter than a beacon interval. A scan for a beacon report with a duration of 150 TU thus misses APs whose beacon does not fall into the dwell and whose probe response comes late.
Pass the duration of the request, converted to ms, as the minimum and the maximum dwell time. The firmware sends its probe requests only within the minimum dwell time, so both carry the same value. A request without a duration keeps the firmware default, which that commit chose for a shorter scan.
--- drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h | 8 ++++++++ drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 3 +++ 2 files changed, 11 insertions(+)
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +8 -0
@@ -2093,6 +2093,14 @@ mt76_connac_mcu_he_ldpc(struct ieee80211_bss_conf *link_conf)return link_conf->vif->type !=NL80211_IFTYPE_AP || link_conf->he_ldpc; } +static inline u16 +mt76_connac_mcu_scan_dwell (struct cfg80211_scan_request *sreq) +{ + return min_t(unsigned long, +ieee80211_tu_to_usec (sreq->duration) /USEC_PER_MSEC , +U16_MAX ); +} +int mt76_connac_mcu_set_channel_domain (struct mt76_phy *phy);int mt76_connac_mcu_set_vif_ps (struct mt76_dev *dev,struct ieee80211_vif *vif); void mt76_connac_mcu_sta_basic_tlv(struct mt76_dev *dev, struct sk_buff *skb,
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +3 -0
@@ -3459,6 +3459,9 @@ int mt7925_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif, req = (struct scan_req_tlv *)tlv; req->scan_type = sreq->n_ssids ?1 :0 ; req->probe_req_num = sreq->n_ssids ?2 :0 ; + req->channel_min_dwell_time = +cpu_to_le16 (mt76_connac_mcu_scan_dwell (sreq)); + req->channel_dwell_time = req->channel_min_dwell_time; tlv =mt76_connac_mcu_add_tlv (skb,UNI_SCAN_SSID ,sizeof (*ssid)); ssid = (struct scan_ssid_tlv *)tlv;
Signature · 1 line
2.47.3
Felix Fietkau
maintainerPATCH 20/20 wifi: mt76: connac: apply the dwell time of a scan request on mt7663
In reply to Felix Fietkaumt7615_init_wiphy() advertises NL80211_EXT_FEATURE_SET_SCAN_DWELL, but mt76_connac_mcu_hw_scan() ignores the duration of the scan request. On mt7663 the dwell time per channel is a fixed value, whatever duration the request asks for.
Pass the duration of the request, converted to ms, as the minimum and the maximum dwell time, and size the scan timeout from it. A request without a duration keeps the fixed value. The connac2 chips keep the firmware dwell time, since their firmware does not take one from the driver, see commit 9db419f0cb39 ("mt76: mt7921: fix the dwell time control").
--- drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +4 -1
@@ -1891,7 +1891,10 @@ int mt76_connac_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif,/* increase channel time for passive scan */ if (!sreq->n_ssids) duration *=2 ; - req->timeout_value =cpu_to_le16 (sreq->n_channels * duration); +if (sreq->duration && !is_connac2 (phy->dev)) + duration =mt76_connac_mcu_scan_dwell (sreq); + req->timeout_value =cpu_to_le16 (min_t (u32, sreq->n_channels * duration, +U16_MAX )); req->channel_min_dwell_time =cpu_to_le16 (duration); req->channel_dwell_time =cpu_to_le16 (duration);
Signature · 1 line
2.47.3