Currently, ath12k_mac_op_change_vif_links() derives the links to add and remove from the old_links/new_links arguments: it creates a link vif (arvif) for each link in ~old_links & new_links and frees the arvif of each link in old_links & ~new_links. However, mac80211 invokes drv_change_vif_links() both when the valid links change and when the active links change. In both cases old_links/new_links are only the active links, and for an active-link change vif->valid_links is not modified. A link that is deactivated is therefore reported as removed, although it is still a valid link of the MLD. To fix this, derive the arvif lifetime from vif->valid_links, which mac80211 updates before calling the driver and which an active-link change leaves untouched. Create an arvif for each link in valid_links & ~links_map and remove those in links_map & ~valid_links. A link that is only deactivated keeps its arvif. For a station, a link removed from valid_links keeps its arvif as well: ML reconfiguration deactivates the link first, so the removal is not reported to the driver, and the firmware does not support deleting the vdev of a single link while the ML association is up. On disconnect (valid_links == 0) every remaining arvif is removed. A removed link has no bss_conf anymore, so skip links that are not in vif->valid_links in the change_chanctx iterators. Tested-on: QCC2072 hw1.0 PCI WLAN.COL.1.0.c2-00277-QCACOLSWPL_V1_TO_SILICONZ-1 Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Fixes: 315d80be304a ("wifi: ath12k: allocate new links in change_vif_links()") Signed-off-by: Miaoqing Pan --- drivers/net/wireless/ath/ath12k/mac.c | 35 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index 0411e8a4e309..d454031a231d 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -4390,9 +4390,8 @@ ath12k_mac_op_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_bss_conf *ol[IEEE80211_MLD_MAX_NUM_LINKS]) { struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); - unsigned long to_remove = old_links & ~new_links; - unsigned long to_add = ~old_links & new_links; struct ath12k_hw *ah = ath12k_hw_to_ah(hw); + unsigned long to_remove, to_add; struct ath12k_link_vif *arvif; u8 link_id; @@ -4402,14 +4401,20 @@ ath12k_mac_op_change_vif_links(struct ieee80211_hw *hw, "mac vif link changed for MLD %pM old_links 0x%x new_links 0x%x\n", vif->addr, old_links, new_links); - for_each_set_bit(link_id, &to_add, IEEE80211_MLD_MAX_NUM_LINKS) { - arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); - /* mac80211 wants to add link but driver already has the - * link. This should not happen ideally. - */ - if (WARN_ON(arvif)) - return -EINVAL; + /* + * old_links/new_links only describe the active links, so link vifs + * follow vif->valid_links. A link that leaves valid_links while it is + * inactive (ML reconfiguration deactivates it first) is not reported + * through this callback, and firmware can't delete the vdev/peer of a + * single link of an ML association. So an associated STA MLD keeps + * all link vifs until valid_links becomes 0. + */ + to_add = vif->valid_links & ~ahvif->links_map; + to_remove = ahvif->links_map & ~vif->valid_links; + if (vif->type == NL80211_IFTYPE_STATION && vif->valid_links) + to_remove = 0; + for_each_set_bit(link_id, &to_add, IEEE80211_MLD_MAX_NUM_LINKS) { arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); if (WARN_ON(!arvif)) return -EINVAL; @@ -11601,6 +11606,12 @@ ath12k_mac_change_chanctx_cnt_iter(void *data, u8 *mac, lockdep_assert_wiphy(ahvif->ah->hw->wiphy); links_map = ahvif->links_map; + /* + * skip links removed by the AP but kept until disconnect + */ + if (ieee80211_vif_is_mld(vif)) + links_map &= vif->valid_links; + for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { arvif = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]); if (WARN_ON(!arvif)) @@ -11636,6 +11647,12 @@ ath12k_mac_change_chanctx_fill_iter(void *data, u8 *mac, lockdep_assert_wiphy(ahvif->ah->hw->wiphy); links_map = ahvif->links_map; + /* + * skip links removed by the AP but kept until disconnect + */ + if (ieee80211_vif_is_mld(vif)) + links_map &= vif->valid_links; + for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { arvif = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]); if (WARN_ON(!arvif)) -- 2.34.1