Skip to content

Commit 91b9f31

Browse files
jmberg-intelMiriam-Rachel
authored andcommitted
wifi: iwlwifi: mvm: remove extra link ID
Since the iwlmvm driver now only supports pre-MLO devices, we no longer need to maintain an extra explicit link ID; valid MAC IDs and link IDs are both in the range 0-3 and the driver always has a 1:1 MAC/link correspondence. Thus, simply use the MAC ID as the link ID as well. This simplifies some further work because on RX the ID is given but there is some confusion about which versions of the firmware report MAC and which report link ID. While at it, clarify iwl_mvm_handle_missed_beacons_notif() code a bit so it doesn't look like an invalid vif pointer is being used. Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: Miri Korenblit <[email protected]> Link: https://patch.msgid.link/20250711183056.005aa5fe34fe.Ib0c1187453f46ce49dc0f9f58907ee21f5b52634@changeid
1 parent 9f9c762 commit 91b9f31

File tree

7 files changed

+34
-138
lines changed

7 files changed

+34
-138
lines changed

drivers/net/wireless/intel/iwlwifi/mvm/fw.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,9 +1462,6 @@ int iwl_mvm_up(struct iwl_mvm *mvm)
14621462
RCU_INIT_POINTER(mvm->fw_id_to_link_sta[i], NULL);
14631463
}
14641464

1465-
for (i = 0; i < IWL_FW_MAX_LINK_ID + 1; i++)
1466-
RCU_INIT_POINTER(mvm->link_id_to_link_conf[i], NULL);
1467-
14681465
mvm->tdls_cs.peer.sta_id = IWL_INVALID_STA;
14691466

14701467
/* reset quota debouncing buffer - 0xff will yield invalid data */

drivers/net/wireless/intel/iwlwifi/mvm/link.c

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,6 @@ static void iwl_mvm_print_esr_state(struct iwl_mvm *mvm, u32 mask)
4949
#undef NAME_PR
5050
}
5151

52-
static u32 iwl_mvm_get_free_fw_link_id(struct iwl_mvm *mvm,
53-
struct iwl_mvm_vif *mvm_vif)
54-
{
55-
u32 i;
56-
57-
lockdep_assert_held(&mvm->mutex);
58-
59-
for (i = 0; i < ARRAY_SIZE(mvm->link_id_to_link_conf); i++)
60-
if (!rcu_access_pointer(mvm->link_id_to_link_conf[i]))
61-
return i;
62-
63-
return IWL_MVM_FW_LINK_ID_INVALID;
64-
}
65-
6652
static int iwl_mvm_link_cmd_send(struct iwl_mvm *mvm,
6753
struct iwl_link_config_cmd *cmd,
6854
enum iwl_ctxt_action action)
@@ -79,25 +65,15 @@ static int iwl_mvm_link_cmd_send(struct iwl_mvm *mvm,
7965
return ret;
8066
}
8167

82-
int iwl_mvm_set_link_mapping(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
83-
struct ieee80211_bss_conf *link_conf)
68+
void iwl_mvm_set_link_fw_id(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
69+
struct ieee80211_bss_conf *link_conf)
8470
{
8571
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8672
struct iwl_mvm_vif_link_info *link_info =
8773
mvmvif->link[link_conf->link_id];
8874

89-
if (link_info->fw_link_id == IWL_MVM_FW_LINK_ID_INVALID) {
90-
link_info->fw_link_id = iwl_mvm_get_free_fw_link_id(mvm,
91-
mvmvif);
92-
if (link_info->fw_link_id >=
93-
ARRAY_SIZE(mvm->link_id_to_link_conf))
94-
return -EINVAL;
95-
96-
rcu_assign_pointer(mvm->link_id_to_link_conf[link_info->fw_link_id],
97-
link_conf);
98-
}
99-
100-
return 0;
75+
if (link_info->fw_link_id == IWL_MVM_FW_LINK_ID_INVALID)
76+
link_info->fw_link_id = mvmvif->id;
10177
}
10278

10379
int iwl_mvm_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
@@ -109,14 +85,11 @@ int iwl_mvm_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
10985
struct iwl_link_config_cmd cmd = {};
11086
unsigned int cmd_id = WIDE_ID(MAC_CONF_GROUP, LINK_CONFIG_CMD);
11187
u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 1);
112-
int ret;
11388

11489
if (WARN_ON_ONCE(!link_info))
11590
return -EINVAL;
11691

117-
ret = iwl_mvm_set_link_mapping(mvm, vif, link_conf);
118-
if (ret)
119-
return ret;
92+
iwl_mvm_set_link_fw_id(mvm, vif, link_conf);
12093

12194
/* Update SF - Disable if needed. if this fails, SF might still be on
12295
* while many macs are bound, which is forbidden - so fail the binding.
@@ -373,24 +346,6 @@ int iwl_mvm_link_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
373346
return ret;
374347
}
375348

376-
int iwl_mvm_unset_link_mapping(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
377-
struct ieee80211_bss_conf *link_conf)
378-
{
379-
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
380-
struct iwl_mvm_vif_link_info *link_info =
381-
mvmvif->link[link_conf->link_id];
382-
383-
/* mac80211 thought we have the link, but it was never configured */
384-
if (WARN_ON(!link_info ||
385-
link_info->fw_link_id >=
386-
ARRAY_SIZE(mvm->link_id_to_link_conf)))
387-
return -EINVAL;
388-
389-
RCU_INIT_POINTER(mvm->link_id_to_link_conf[link_info->fw_link_id],
390-
NULL);
391-
return 0;
392-
}
393-
394349
int iwl_mvm_remove_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
395350
struct ieee80211_bss_conf *link_conf)
396351
{
@@ -400,10 +355,6 @@ int iwl_mvm_remove_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
400355
struct iwl_link_config_cmd cmd = {};
401356
int ret;
402357

403-
ret = iwl_mvm_unset_link_mapping(mvm, vif, link_conf);
404-
if (ret)
405-
return 0;
406-
407358
cmd.link_id = cpu_to_le32(link_info->fw_link_id);
408359
link_info->fw_link_id = IWL_MVM_FW_LINK_ID_INVALID;
409360
cmd.spec_link_id = link_conf->link_id;

drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@ iwl_mvm_handle_missed_beacons_notif(struct iwl_mvm *mvm,
15861586
u32 id = le32_to_cpu(mb->link_id);
15871587
union iwl_dbg_tlv_tp_data tp_data = { .fw_pkt = pkt };
15881588
u32 mac_type;
1589-
int link_id = -1;
1589+
int link_id;
15901590
u8 notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
15911591
MISSED_BEACONS_NOTIFICATION,
15921592
0);
@@ -1602,30 +1602,23 @@ iwl_mvm_handle_missed_beacons_notif(struct iwl_mvm *mvm,
16021602
if (new_notif_ver)
16031603
notif_ver = new_notif_ver;
16041604

1605-
/* before version four the ID in the notification refers to mac ID */
1606-
if (notif_ver < 4) {
1607-
vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, false);
1608-
bss_conf = &vif->bss_conf;
1609-
} else {
1610-
bss_conf = iwl_mvm_rcu_fw_link_id_to_link_conf(mvm, id, false);
1611-
1612-
if (!bss_conf)
1613-
return;
1614-
1615-
vif = bss_conf->vif;
1616-
link_id = bss_conf->link_id;
1617-
}
1618-
16191605
IWL_DEBUG_INFO(mvm,
16201606
"missed bcn %s_id=%u, consecutive=%u (%u)\n",
16211607
notif_ver < 4 ? "mac" : "link",
16221608
id,
16231609
le32_to_cpu(mb->consec_missed_beacons),
16241610
le32_to_cpu(mb->consec_missed_beacons_since_last_rx));
16251611

1612+
/*
1613+
* starting from version 4 the ID is link ID, but driver
1614+
* uses link ID == MAC ID, so always treat as MAC ID
1615+
*/
1616+
vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, false);
16261617
if (!vif)
16271618
return;
16281619

1620+
bss_conf = &vif->bss_conf;
1621+
link_id = bss_conf->link_id;
16291622
mac_type = iwl_mvm_get_mac_type(vif);
16301623

16311624
IWL_DEBUG_INFO(mvm, "missed beacon mac_type=%u,\n", mac_type);
@@ -1875,16 +1868,15 @@ void iwl_mvm_channel_switch_start_notif(struct iwl_mvm *mvm,
18751868
} else {
18761869
struct iwl_channel_switch_start_notif *notif = (void *)pkt->data;
18771870
u32 link_id = le32_to_cpu(notif->link_id);
1878-
struct ieee80211_bss_conf *bss_conf =
1879-
iwl_mvm_rcu_fw_link_id_to_link_conf(mvm, link_id, true);
18801871

1881-
if (!bss_conf)
1872+
/* we use link ID == MAC ID */
1873+
vif = iwl_mvm_rcu_dereference_vif_id(mvm, link_id, true);
1874+
if (!vif)
18821875
goto out_unlock;
18831876

18841877
id = link_id;
1885-
mac_link_id = bss_conf->link_id;
1886-
vif = bss_conf->vif;
1887-
csa_active = bss_conf->csa_active;
1878+
mac_link_id = vif->bss_conf.link_id;
1879+
csa_active = vif->bss_conf.csa_active;
18881880
}
18891881

18901882
mvmvif = iwl_mvm_vif_from_mac80211(vif);

drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,9 +1806,7 @@ static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
18061806

18071807
vif->driver_flags = IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC;
18081808

1809-
ret = iwl_mvm_set_link_mapping(mvm, vif, &vif->bss_conf);
1810-
if (ret)
1811-
goto out;
1809+
iwl_mvm_set_link_fw_id(mvm, vif, &vif->bss_conf);
18121810

18131811
/*
18141812
* Not much to do here. The stack will not allow interface
@@ -2009,7 +2007,6 @@ static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
20092007
mvm->monitor_on = false;
20102008

20112009
out:
2012-
iwl_mvm_unset_link_mapping(mvm, vif, &vif->bss_conf);
20132010
if (vif->type == NL80211_IFTYPE_AP ||
20142011
vif->type == NL80211_IFTYPE_ADHOC) {
20152012
iwl_mvm_dealloc_int_sta(mvm, &mvmvif->deflink.mcast_sta);

drivers/net/wireless/intel/iwlwifi/mvm/mvm.h

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,6 @@ struct iwl_mvm {
11771177

11781178
struct ieee80211_vif __rcu *vif_id_to_mac[NUM_MAC_INDEX_DRIVER];
11791179

1180-
struct ieee80211_bss_conf __rcu *link_id_to_link_conf[IWL_FW_MAX_LINK_ID + 1];
1181-
11821180
u8 *error_recovery_buf;
11831181

11841182
#ifdef CONFIG_IWLWIFI_LEDS
@@ -1485,20 +1483,6 @@ iwl_mvm_rcu_dereference_vif_id(struct iwl_mvm *mvm, u8 vif_id, bool rcu)
14851483
lockdep_is_held(&mvm->mutex));
14861484
}
14871485

1488-
static inline struct ieee80211_bss_conf *
1489-
iwl_mvm_rcu_fw_link_id_to_link_conf(struct iwl_mvm *mvm, u8 link_id, bool rcu)
1490-
{
1491-
if (IWL_FW_CHECK(mvm, link_id >= ARRAY_SIZE(mvm->link_id_to_link_conf),
1492-
"erroneous FW link ID: %d\n", link_id))
1493-
return NULL;
1494-
1495-
if (rcu)
1496-
return rcu_dereference(mvm->link_id_to_link_conf[link_id]);
1497-
1498-
return rcu_dereference_protected(mvm->link_id_to_link_conf[link_id],
1499-
lockdep_is_held(&mvm->mutex));
1500-
}
1501-
15021486
static inline bool iwl_mvm_is_adaptive_dwell_supported(struct iwl_mvm *mvm)
15031487
{
15041488
return fw_has_api(&mvm->fw->ucode_capa,
@@ -2097,15 +2081,13 @@ u32 iwl_mvm_get_lmac_id(struct iwl_mvm *mvm, enum nl80211_band band);
20972081

20982082
/* Links */
20992083
void iwl_mvm_init_link(struct iwl_mvm_vif_link_info *link);
2100-
int iwl_mvm_set_link_mapping(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2101-
struct ieee80211_bss_conf *link_conf);
2084+
void iwl_mvm_set_link_fw_id(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2085+
struct ieee80211_bss_conf *link_conf);
21022086
int iwl_mvm_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
21032087
struct ieee80211_bss_conf *link_conf);
21042088
int iwl_mvm_link_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
21052089
struct ieee80211_bss_conf *link_conf,
21062090
u32 changes, bool active);
2107-
int iwl_mvm_unset_link_mapping(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2108-
struct ieee80211_bss_conf *link_conf);
21092091
int iwl_mvm_remove_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
21102092
struct ieee80211_bss_conf *link_conf);
21112093
int iwl_mvm_disable_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,

drivers/net/wireless/intel/iwlwifi/mvm/rx.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -877,28 +877,28 @@ iwl_mvm_stat_iterator_all_links(struct iwl_mvm *mvm,
877877
u32 rx_bytes[MAC_INDEX_AUX] = {};
878878
int fw_link_id;
879879

880-
for (fw_link_id = 0; fw_link_id < ARRAY_SIZE(mvm->link_id_to_link_conf);
880+
/* driver uses link ID == MAC ID */
881+
for (fw_link_id = 0; fw_link_id < ARRAY_SIZE(mvm->vif_id_to_mac);
881882
fw_link_id++) {
882883
struct iwl_stats_ntfy_per_link *link_stats;
883-
struct ieee80211_bss_conf *bss_conf;
884-
struct iwl_mvm_vif *mvmvif;
885884
struct iwl_mvm_vif_link_info *link_info;
885+
struct iwl_mvm_vif *mvmvif;
886+
struct ieee80211_vif *vif;
886887
int link_id;
887888
int sig;
888889

889-
bss_conf = iwl_mvm_rcu_fw_link_id_to_link_conf(mvm, fw_link_id,
890-
false);
891-
if (!bss_conf)
890+
vif = iwl_mvm_rcu_dereference_vif_id(mvm, fw_link_id, false);
891+
if (!vif)
892892
continue;
893893

894-
if (bss_conf->vif->type != NL80211_IFTYPE_STATION)
894+
if (vif->type != NL80211_IFTYPE_STATION)
895895
continue;
896896

897-
link_id = bss_conf->link_id;
897+
link_id = vif->bss_conf.link_id;
898898
if (link_id >= ARRAY_SIZE(mvmvif->link))
899899
continue;
900900

901-
mvmvif = iwl_mvm_vif_from_mac80211(bss_conf->vif);
901+
mvmvif = iwl_mvm_vif_from_mac80211(vif);
902902
link_info = mvmvif->link[link_id];
903903
if (!link_info)
904904
continue;
@@ -916,8 +916,7 @@ iwl_mvm_stat_iterator_all_links(struct iwl_mvm *mvm,
916916

917917
if (link_info->phy_ctxt &&
918918
link_info->phy_ctxt->channel->band == NL80211_BAND_2GHZ)
919-
iwl_mvm_bt_coex_update_link_esr(mvm, bss_conf->vif,
920-
link_id);
919+
iwl_mvm_bt_coex_update_link_esr(mvm, vif, link_id);
921920

922921
/* make sure that beacon statistics don't go backwards with TCM
923922
* request to clear statistics
@@ -927,8 +926,7 @@ iwl_mvm_stat_iterator_all_links(struct iwl_mvm *mvm,
927926
mvmvif->link[link_id]->beacon_stats.num_beacons;
928927

929928
sig = -le32_to_cpu(link_stats->beacon_filter_average_energy);
930-
iwl_mvm_update_link_sig(bss_conf->vif, sig, link_info,
931-
bss_conf);
929+
iwl_mvm_update_link_sig(vif, sig, link_info, &vif->bss_conf);
932930

933931
if (WARN_ONCE(mvmvif->id >= MAC_INDEX_AUX,
934932
"invalid mvmvif id: %d", mvmvif->id))

drivers/net/wireless/intel/iwlwifi/mvm/time-event.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -958,40 +958,19 @@ void iwl_mvm_rx_session_protect_notif(struct iwl_mvm *mvm,
958958
{
959959
struct iwl_rx_packet *pkt = rxb_addr(rxb);
960960
struct iwl_session_prot_notif *notif = (void *)pkt->data;
961-
unsigned int ver =
962-
iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
963-
SESSION_PROTECTION_NOTIF, 2);
964961
int id = le32_to_cpu(notif->mac_link_id);
965962
struct ieee80211_vif *vif;
966963
struct iwl_mvm_vif *mvmvif;
967-
unsigned int notif_link_id;
968964

969965
rcu_read_lock();
970966

971-
if (ver <= 2) {
972-
vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, true);
973-
} else {
974-
struct ieee80211_bss_conf *link_conf =
975-
iwl_mvm_rcu_fw_link_id_to_link_conf(mvm, id, true);
976-
977-
if (!link_conf)
978-
goto out_unlock;
979-
980-
notif_link_id = link_conf->link_id;
981-
vif = link_conf->vif;
982-
}
983-
967+
/* note we use link ID == MAC ID */
968+
vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, true);
984969
if (!vif)
985970
goto out_unlock;
986971

987972
mvmvif = iwl_mvm_vif_from_mac80211(vif);
988973

989-
if (WARN(ver > 2 && mvmvif->time_event_data.link_id >= 0 &&
990-
mvmvif->time_event_data.link_id != notif_link_id,
991-
"SESSION_PROTECTION_NOTIF was received for link %u, while the current time event is on link %u\n",
992-
notif_link_id, mvmvif->time_event_data.link_id))
993-
goto out_unlock;
994-
995974
/* The vif is not a P2P_DEVICE, maintain its time_event_data */
996975
if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
997976
struct iwl_mvm_time_event_data *te_data =

0 commit comments

Comments
 (0)