aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/cfg.c235
-rw-r--r--net/mac80211/chan.c54
-rw-r--r--net/mac80211/debugfs_key.c10
-rw-r--r--net/mac80211/debugfs_netdev.c33
-rw-r--r--net/mac80211/debugfs_sta.c33
-rw-r--r--net/mac80211/driver-ops.h67
-rw-r--r--net/mac80211/ht.c52
-rw-r--r--net/mac80211/ibss.c175
-rw-r--r--net/mac80211/ieee80211_i.h86
-rw-r--r--net/mac80211/iface.c150
-rw-r--r--net/mac80211/key.c208
-rw-r--r--net/mac80211/key.h18
-rw-r--r--net/mac80211/main.c159
-rw-r--r--net/mac80211/mesh.c70
-rw-r--r--net/mac80211/mesh.h15
-rw-r--r--net/mac80211/mesh_hwmp.c28
-rw-r--r--net/mac80211/mesh_pathtbl.c56
-rw-r--r--net/mac80211/mesh_plink.c43
-rw-r--r--net/mac80211/mlme.c554
-rw-r--r--net/mac80211/offchannel.c16
-rw-r--r--net/mac80211/pm.c132
-rw-r--r--net/mac80211/rate.c324
-rw-r--r--net/mac80211/rc80211_minstrel.c342
-rw-r--r--net/mac80211/rc80211_minstrel.h34
-rw-r--r--net/mac80211/rc80211_minstrel_debugfs.c16
-rw-r--r--net/mac80211/rc80211_minstrel_ht.c273
-rw-r--r--net/mac80211/rc80211_minstrel_ht.h8
-rw-r--r--net/mac80211/rx.c85
-rw-r--r--net/mac80211/scan.c20
-rw-r--r--net/mac80211/sta_info.c56
-rw-r--r--net/mac80211/sta_info.h11
-rw-r--r--net/mac80211/trace.h97
-rw-r--r--net/mac80211/tx.c163
-rw-r--r--net/mac80211/util.c224
-rw-r--r--net/mac80211/vht.c212
35 files changed, 2327 insertions, 1732 deletions
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index a6893602f87a..1a89c80e6407 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -175,7 +175,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
175 * add it to the device after the station. 175 * add it to the device after the station.
176 */ 176 */
177 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) { 177 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
178 ieee80211_key_free(sdata->local, key); 178 ieee80211_key_free_unused(key);
179 err = -ENOENT; 179 err = -ENOENT;
180 goto out_unlock; 180 goto out_unlock;
181 } 181 }
@@ -214,8 +214,6 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
214 } 214 }
215 215
216 err = ieee80211_key_link(key, sdata, sta); 216 err = ieee80211_key_link(key, sdata, sta);
217 if (err)
218 ieee80211_key_free(sdata->local, key);
219 217
220 out_unlock: 218 out_unlock:
221 mutex_unlock(&sdata->local->sta_mtx); 219 mutex_unlock(&sdata->local->sta_mtx);
@@ -254,7 +252,7 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
254 goto out_unlock; 252 goto out_unlock;
255 } 253 }
256 254
257 __ieee80211_key_free(key); 255 ieee80211_key_free(key, true);
258 256
259 ret = 0; 257 ret = 0;
260 out_unlock: 258 out_unlock:
@@ -445,12 +443,14 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
445 struct ieee80211_sub_if_data *sdata = sta->sdata; 443 struct ieee80211_sub_if_data *sdata = sta->sdata;
446 struct ieee80211_local *local = sdata->local; 444 struct ieee80211_local *local = sdata->local;
447 struct timespec uptime; 445 struct timespec uptime;
446 u64 packets = 0;
447 int ac;
448 448
449 sinfo->generation = sdata->local->sta_generation; 449 sinfo->generation = sdata->local->sta_generation;
450 450
451 sinfo->filled = STATION_INFO_INACTIVE_TIME | 451 sinfo->filled = STATION_INFO_INACTIVE_TIME |
452 STATION_INFO_RX_BYTES | 452 STATION_INFO_RX_BYTES64 |
453 STATION_INFO_TX_BYTES | 453 STATION_INFO_TX_BYTES64 |
454 STATION_INFO_RX_PACKETS | 454 STATION_INFO_RX_PACKETS |
455 STATION_INFO_TX_PACKETS | 455 STATION_INFO_TX_PACKETS |
456 STATION_INFO_TX_RETRIES | 456 STATION_INFO_TX_RETRIES |
@@ -467,10 +467,14 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
467 sinfo->connected_time = uptime.tv_sec - sta->last_connected; 467 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
468 468
469 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx); 469 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
470 sinfo->tx_bytes = 0;
471 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
472 sinfo->tx_bytes += sta->tx_bytes[ac];
473 packets += sta->tx_packets[ac];
474 }
475 sinfo->tx_packets = packets;
470 sinfo->rx_bytes = sta->rx_bytes; 476 sinfo->rx_bytes = sta->rx_bytes;
471 sinfo->tx_bytes = sta->tx_bytes;
472 sinfo->rx_packets = sta->rx_packets; 477 sinfo->rx_packets = sta->rx_packets;
473 sinfo->tx_packets = sta->tx_packets;
474 sinfo->tx_retries = sta->tx_retry_count; 478 sinfo->tx_retries = sta->tx_retry_count;
475 sinfo->tx_failed = sta->tx_retry_failed; 479 sinfo->tx_failed = sta->tx_retry_failed;
476 sinfo->rx_dropped_misc = sta->rx_dropped; 480 sinfo->rx_dropped_misc = sta->rx_dropped;
@@ -598,8 +602,8 @@ static void ieee80211_get_et_stats(struct wiphy *wiphy,
598 data[i++] += sta->rx_fragments; \ 602 data[i++] += sta->rx_fragments; \
599 data[i++] += sta->rx_dropped; \ 603 data[i++] += sta->rx_dropped; \
600 \ 604 \
601 data[i++] += sta->tx_packets; \ 605 data[i++] += sinfo.tx_packets; \
602 data[i++] += sta->tx_bytes; \ 606 data[i++] += sinfo.tx_bytes; \
603 data[i++] += sta->tx_fragments; \ 607 data[i++] += sta->tx_fragments; \
604 data[i++] += sta->tx_filtered_count; \ 608 data[i++] += sta->tx_filtered_count; \
605 data[i++] += sta->tx_retry_failed; \ 609 data[i++] += sta->tx_retry_failed; \
@@ -621,13 +625,14 @@ static void ieee80211_get_et_stats(struct wiphy *wiphy,
621 if (!(sta && !WARN_ON(sta->sdata->dev != dev))) 625 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
622 goto do_survey; 626 goto do_survey;
623 627
628 sinfo.filled = 0;
629 sta_set_sinfo(sta, &sinfo);
630
624 i = 0; 631 i = 0;
625 ADD_STA_STATS(sta); 632 ADD_STA_STATS(sta);
626 633
627 data[i++] = sta->sta_state; 634 data[i++] = sta->sta_state;
628 635
629 sinfo.filled = 0;
630 sta_set_sinfo(sta, &sinfo);
631 636
632 if (sinfo.filled & STATION_INFO_TX_BITRATE) 637 if (sinfo.filled & STATION_INFO_TX_BITRATE)
633 data[i] = 100000 * 638 data[i] = 100000 *
@@ -800,8 +805,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
800 IEEE80211_CHANCTX_EXCLUSIVE); 805 IEEE80211_CHANCTX_EXCLUSIVE);
801 } 806 }
802 } else if (local->open_count == local->monitors) { 807 } else if (local->open_count == local->monitors) {
803 local->_oper_channel = chandef->chan; 808 local->_oper_chandef = *chandef;
804 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
805 ieee80211_hw_config(local, 0); 809 ieee80211_hw_config(local, 0);
806 } 810 }
807 811
@@ -960,8 +964,13 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
960 sdata->vif.bss_conf.hidden_ssid = 964 sdata->vif.bss_conf.hidden_ssid =
961 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE); 965 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
962 966
963 sdata->vif.bss_conf.p2p_ctwindow = params->p2p_ctwindow; 967 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
964 sdata->vif.bss_conf.p2p_oppps = params->p2p_opp_ps; 968 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
969 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
970 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
971 if (params->p2p_opp_ps)
972 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
973 IEEE80211_P2P_OPPPS_ENABLE_BIT;
965 974
966 err = ieee80211_assign_beacon(sdata, &params->beacon); 975 err = ieee80211_assign_beacon(sdata, &params->beacon);
967 if (err < 0) 976 if (err < 0)
@@ -1034,12 +1043,17 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1034 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) 1043 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1035 sta_info_flush_defer(vlan); 1044 sta_info_flush_defer(vlan);
1036 sta_info_flush_defer(sdata); 1045 sta_info_flush_defer(sdata);
1046 synchronize_net();
1037 rcu_barrier(); 1047 rcu_barrier();
1038 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) 1048 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1039 sta_info_flush_cleanup(vlan); 1049 sta_info_flush_cleanup(vlan);
1050 ieee80211_free_keys(vlan);
1051 }
1040 sta_info_flush_cleanup(sdata); 1052 sta_info_flush_cleanup(sdata);
1053 ieee80211_free_keys(sdata);
1041 1054
1042 sdata->vif.bss_conf.enable_beacon = false; 1055 sdata->vif.bss_conf.enable_beacon = false;
1056 sdata->vif.bss_conf.ssid_len = 0;
1043 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); 1057 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1044 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); 1058 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1045 1059
@@ -1177,6 +1191,18 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1177 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); 1191 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1178 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) 1192 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1179 set |= BIT(NL80211_STA_FLAG_ASSOCIATED); 1193 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1194 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1195 /*
1196 * TDLS -- everything follows authorized, but
1197 * only becoming authorized is possible, not
1198 * going back
1199 */
1200 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1201 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1202 BIT(NL80211_STA_FLAG_ASSOCIATED);
1203 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1204 BIT(NL80211_STA_FLAG_ASSOCIATED);
1205 }
1180 } 1206 }
1181 1207
1182 ret = sta_apply_auth_flags(local, sta, mask, set); 1208 ret = sta_apply_auth_flags(local, sta, mask, set);
@@ -1261,7 +1287,8 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1261 if (ieee80211_vif_is_mesh(&sdata->vif)) { 1287 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1262#ifdef CONFIG_MAC80211_MESH 1288#ifdef CONFIG_MAC80211_MESH
1263 u32 changed = 0; 1289 u32 changed = 0;
1264 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED) { 1290
1291 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1265 switch (params->plink_state) { 1292 switch (params->plink_state) {
1266 case NL80211_PLINK_ESTAB: 1293 case NL80211_PLINK_ESTAB:
1267 if (sta->plink_state != NL80211_PLINK_ESTAB) 1294 if (sta->plink_state != NL80211_PLINK_ESTAB)
@@ -1292,15 +1319,18 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1292 /* nothing */ 1319 /* nothing */
1293 break; 1320 break;
1294 } 1321 }
1295 } else { 1322 }
1296 switch (params->plink_action) { 1323
1297 case PLINK_ACTION_OPEN: 1324 switch (params->plink_action) {
1298 changed |= mesh_plink_open(sta); 1325 case NL80211_PLINK_ACTION_NO_ACTION:
1299 break; 1326 /* nothing */
1300 case PLINK_ACTION_BLOCK: 1327 break;
1301 changed |= mesh_plink_block(sta); 1328 case NL80211_PLINK_ACTION_OPEN:
1302 break; 1329 changed |= mesh_plink_open(sta);
1303 } 1330 break;
1331 case NL80211_PLINK_ACTION_BLOCK:
1332 changed |= mesh_plink_block(sta);
1333 break;
1304 } 1334 }
1305 1335
1306 if (params->local_pm) 1336 if (params->local_pm)
@@ -1346,8 +1376,10 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1346 * defaults -- if userspace wants something else we'll 1376 * defaults -- if userspace wants something else we'll
1347 * change it accordingly in sta_apply_parameters() 1377 * change it accordingly in sta_apply_parameters()
1348 */ 1378 */
1349 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH); 1379 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1350 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC); 1380 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1381 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1382 }
1351 1383
1352 err = sta_apply_parameters(local, sta, params); 1384 err = sta_apply_parameters(local, sta, params);
1353 if (err) { 1385 if (err) {
@@ -1356,8 +1388,8 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1356 } 1388 }
1357 1389
1358 /* 1390 /*
1359 * for TDLS, rate control should be initialized only when supported 1391 * for TDLS, rate control should be initialized only when
1360 * rates are known. 1392 * rates are known and station is marked authorized
1361 */ 1393 */
1362 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) 1394 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1363 rate_control_rate_init(sta); 1395 rate_control_rate_init(sta);
@@ -1394,50 +1426,67 @@ static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1394} 1426}
1395 1427
1396static int ieee80211_change_station(struct wiphy *wiphy, 1428static int ieee80211_change_station(struct wiphy *wiphy,
1397 struct net_device *dev, 1429 struct net_device *dev, u8 *mac,
1398 u8 *mac,
1399 struct station_parameters *params) 1430 struct station_parameters *params)
1400{ 1431{
1401 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1432 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1402 struct ieee80211_local *local = wiphy_priv(wiphy); 1433 struct ieee80211_local *local = wiphy_priv(wiphy);
1403 struct sta_info *sta; 1434 struct sta_info *sta;
1404 struct ieee80211_sub_if_data *vlansdata; 1435 struct ieee80211_sub_if_data *vlansdata;
1436 enum cfg80211_station_type statype;
1405 int err; 1437 int err;
1406 1438
1407 mutex_lock(&local->sta_mtx); 1439 mutex_lock(&local->sta_mtx);
1408 1440
1409 sta = sta_info_get_bss(sdata, mac); 1441 sta = sta_info_get_bss(sdata, mac);
1410 if (!sta) { 1442 if (!sta) {
1411 mutex_unlock(&local->sta_mtx); 1443 err = -ENOENT;
1412 return -ENOENT; 1444 goto out_err;
1413 } 1445 }
1414 1446
1415 /* in station mode, some updates are only valid with TDLS */ 1447 switch (sdata->vif.type) {
1416 if (sdata->vif.type == NL80211_IFTYPE_STATION && 1448 case NL80211_IFTYPE_MESH_POINT:
1417 (params->supported_rates || params->ht_capa || params->vht_capa || 1449 if (sdata->u.mesh.user_mpm)
1418 params->sta_modify_mask || 1450 statype = CFG80211_STA_MESH_PEER_USER;
1419 (params->sta_flags_mask & BIT(NL80211_STA_FLAG_WME))) && 1451 else
1420 !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { 1452 statype = CFG80211_STA_MESH_PEER_KERNEL;
1421 mutex_unlock(&local->sta_mtx); 1453 break;
1422 return -EINVAL; 1454 case NL80211_IFTYPE_ADHOC:
1455 statype = CFG80211_STA_IBSS;
1456 break;
1457 case NL80211_IFTYPE_STATION:
1458 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1459 statype = CFG80211_STA_AP_STA;
1460 break;
1461 }
1462 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1463 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1464 else
1465 statype = CFG80211_STA_TDLS_PEER_SETUP;
1466 break;
1467 case NL80211_IFTYPE_AP:
1468 case NL80211_IFTYPE_AP_VLAN:
1469 statype = CFG80211_STA_AP_CLIENT;
1470 break;
1471 default:
1472 err = -EOPNOTSUPP;
1473 goto out_err;
1423 } 1474 }
1424 1475
1476 err = cfg80211_check_station_change(wiphy, params, statype);
1477 if (err)
1478 goto out_err;
1479
1425 if (params->vlan && params->vlan != sta->sdata->dev) { 1480 if (params->vlan && params->vlan != sta->sdata->dev) {
1426 bool prev_4addr = false; 1481 bool prev_4addr = false;
1427 bool new_4addr = false; 1482 bool new_4addr = false;
1428 1483
1429 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); 1484 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1430 1485
1431 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1432 vlansdata->vif.type != NL80211_IFTYPE_AP) {
1433 mutex_unlock(&local->sta_mtx);
1434 return -EINVAL;
1435 }
1436
1437 if (params->vlan->ieee80211_ptr->use_4addr) { 1486 if (params->vlan->ieee80211_ptr->use_4addr) {
1438 if (vlansdata->u.vlan.sta) { 1487 if (vlansdata->u.vlan.sta) {
1439 mutex_unlock(&local->sta_mtx); 1488 err = -EBUSY;
1440 return -EBUSY; 1489 goto out_err;
1441 } 1490 }
1442 1491
1443 rcu_assign_pointer(vlansdata->u.vlan.sta, sta); 1492 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
@@ -1464,12 +1513,12 @@ static int ieee80211_change_station(struct wiphy *wiphy,
1464 } 1513 }
1465 1514
1466 err = sta_apply_parameters(local, sta, params); 1515 err = sta_apply_parameters(local, sta, params);
1467 if (err) { 1516 if (err)
1468 mutex_unlock(&local->sta_mtx); 1517 goto out_err;
1469 return err;
1470 }
1471 1518
1472 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates) 1519 /* When peer becomes authorized, init rate control as well */
1520 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1521 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1473 rate_control_rate_init(sta); 1522 rate_control_rate_init(sta);
1474 1523
1475 mutex_unlock(&local->sta_mtx); 1524 mutex_unlock(&local->sta_mtx);
@@ -1479,7 +1528,11 @@ static int ieee80211_change_station(struct wiphy *wiphy,
1479 ieee80211_recalc_ps(local, -1); 1528 ieee80211_recalc_ps(local, -1);
1480 ieee80211_recalc_ps_vif(sdata); 1529 ieee80211_recalc_ps_vif(sdata);
1481 } 1530 }
1531
1482 return 0; 1532 return 0;
1533out_err:
1534 mutex_unlock(&local->sta_mtx);
1535 return err;
1483} 1536}
1484 1537
1485#ifdef CONFIG_MAC80211_MESH 1538#ifdef CONFIG_MAC80211_MESH
@@ -1489,7 +1542,6 @@ static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1489 struct ieee80211_sub_if_data *sdata; 1542 struct ieee80211_sub_if_data *sdata;
1490 struct mesh_path *mpath; 1543 struct mesh_path *mpath;
1491 struct sta_info *sta; 1544 struct sta_info *sta;
1492 int err;
1493 1545
1494 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1546 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1495 1547
@@ -1500,17 +1552,12 @@ static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1500 return -ENOENT; 1552 return -ENOENT;
1501 } 1553 }
1502 1554
1503 err = mesh_path_add(sdata, dst); 1555 mpath = mesh_path_add(sdata, dst);
1504 if (err) { 1556 if (IS_ERR(mpath)) {
1505 rcu_read_unlock(); 1557 rcu_read_unlock();
1506 return err; 1558 return PTR_ERR(mpath);
1507 } 1559 }
1508 1560
1509 mpath = mesh_path_lookup(sdata, dst);
1510 if (!mpath) {
1511 rcu_read_unlock();
1512 return -ENXIO;
1513 }
1514 mesh_path_fix_nexthop(mpath, sta); 1561 mesh_path_fix_nexthop(mpath, sta);
1515 1562
1516 rcu_read_unlock(); 1563 rcu_read_unlock();
@@ -1687,6 +1734,7 @@ static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1687 ifmsh->mesh_sp_id = setup->sync_method; 1734 ifmsh->mesh_sp_id = setup->sync_method;
1688 ifmsh->mesh_pp_id = setup->path_sel_proto; 1735 ifmsh->mesh_pp_id = setup->path_sel_proto;
1689 ifmsh->mesh_pm_id = setup->path_metric; 1736 ifmsh->mesh_pm_id = setup->path_metric;
1737 ifmsh->user_mpm = setup->user_mpm;
1690 ifmsh->security = IEEE80211_MESH_SEC_NONE; 1738 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1691 if (setup->is_authenticated) 1739 if (setup->is_authenticated)
1692 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED; 1740 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
@@ -1730,8 +1778,11 @@ static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1730 conf->dot11MeshTTL = nconf->dot11MeshTTL; 1778 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1731 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask)) 1779 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1732 conf->element_ttl = nconf->element_ttl; 1780 conf->element_ttl = nconf->element_ttl;
1733 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) 1781 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1782 if (ifmsh->user_mpm)
1783 return -EBUSY;
1734 conf->auto_open_plinks = nconf->auto_open_plinks; 1784 conf->auto_open_plinks = nconf->auto_open_plinks;
1785 }
1735 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask)) 1786 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1736 conf->dot11MeshNbrOffsetMaxNeighbor = 1787 conf->dot11MeshNbrOffsetMaxNeighbor =
1737 nconf->dot11MeshNbrOffsetMaxNeighbor; 1788 nconf->dot11MeshNbrOffsetMaxNeighbor;
@@ -1910,12 +1961,20 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
1910 } 1961 }
1911 1962
1912 if (params->p2p_ctwindow >= 0) { 1963 if (params->p2p_ctwindow >= 0) {
1913 sdata->vif.bss_conf.p2p_ctwindow = params->p2p_ctwindow; 1964 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1965 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1966 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1967 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1914 changed |= BSS_CHANGED_P2P_PS; 1968 changed |= BSS_CHANGED_P2P_PS;
1915 } 1969 }
1916 1970
1917 if (params->p2p_opp_ps >= 0) { 1971 if (params->p2p_opp_ps > 0) {
1918 sdata->vif.bss_conf.p2p_oppps = params->p2p_opp_ps; 1972 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1973 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1974 changed |= BSS_CHANGED_P2P_PS;
1975 } else if (params->p2p_opp_ps == 0) {
1976 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1977 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
1919 changed |= BSS_CHANGED_P2P_PS; 1978 changed |= BSS_CHANGED_P2P_PS;
1920 } 1979 }
1921 1980
@@ -2359,9 +2418,22 @@ static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2359 } 2418 }
2360 2419
2361 for (i = 0; i < IEEE80211_NUM_BANDS; i++) { 2420 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
2421 struct ieee80211_supported_band *sband = wiphy->bands[i];
2422 int j;
2423
2362 sdata->rc_rateidx_mask[i] = mask->control[i].legacy; 2424 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
2363 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs, 2425 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2364 sizeof(mask->control[i].mcs)); 2426 sizeof(mask->control[i].mcs));
2427
2428 sdata->rc_has_mcs_mask[i] = false;
2429 if (!sband)
2430 continue;
2431
2432 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2433 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2434 sdata->rc_has_mcs_mask[i] = true;
2435 break;
2436 }
2365 } 2437 }
2366 2438
2367 return 0; 2439 return 0;
@@ -2371,7 +2443,8 @@ static int ieee80211_start_roc_work(struct ieee80211_local *local,
2371 struct ieee80211_sub_if_data *sdata, 2443 struct ieee80211_sub_if_data *sdata,
2372 struct ieee80211_channel *channel, 2444 struct ieee80211_channel *channel,
2373 unsigned int duration, u64 *cookie, 2445 unsigned int duration, u64 *cookie,
2374 struct sk_buff *txskb) 2446 struct sk_buff *txskb,
2447 enum ieee80211_roc_type type)
2375{ 2448{
2376 struct ieee80211_roc_work *roc, *tmp; 2449 struct ieee80211_roc_work *roc, *tmp;
2377 bool queued = false; 2450 bool queued = false;
@@ -2390,6 +2463,7 @@ static int ieee80211_start_roc_work(struct ieee80211_local *local,
2390 roc->duration = duration; 2463 roc->duration = duration;
2391 roc->req_duration = duration; 2464 roc->req_duration = duration;
2392 roc->frame = txskb; 2465 roc->frame = txskb;
2466 roc->type = type;
2393 roc->mgmt_tx_cookie = (unsigned long)txskb; 2467 roc->mgmt_tx_cookie = (unsigned long)txskb;
2394 roc->sdata = sdata; 2468 roc->sdata = sdata;
2395 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work); 2469 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
@@ -2420,7 +2494,7 @@ static int ieee80211_start_roc_work(struct ieee80211_local *local,
2420 if (!duration) 2494 if (!duration)
2421 duration = 10; 2495 duration = 10;
2422 2496
2423 ret = drv_remain_on_channel(local, sdata, channel, duration); 2497 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
2424 if (ret) { 2498 if (ret) {
2425 kfree(roc); 2499 kfree(roc);
2426 return ret; 2500 return ret;
@@ -2439,10 +2513,13 @@ static int ieee80211_start_roc_work(struct ieee80211_local *local,
2439 * 2513 *
2440 * If it hasn't started yet, just increase the duration 2514 * If it hasn't started yet, just increase the duration
2441 * and add the new one to the list of dependents. 2515 * and add the new one to the list of dependents.
2516 * If the type of the new ROC has higher priority, modify the
2517 * type of the previous one to match that of the new one.
2442 */ 2518 */
2443 if (!tmp->started) { 2519 if (!tmp->started) {
2444 list_add_tail(&roc->list, &tmp->dependents); 2520 list_add_tail(&roc->list, &tmp->dependents);
2445 tmp->duration = max(tmp->duration, roc->duration); 2521 tmp->duration = max(tmp->duration, roc->duration);
2522 tmp->type = max(tmp->type, roc->type);
2446 queued = true; 2523 queued = true;
2447 break; 2524 break;
2448 } 2525 }
@@ -2454,16 +2531,18 @@ static int ieee80211_start_roc_work(struct ieee80211_local *local,
2454 /* 2531 /*
2455 * In the offloaded ROC case, if it hasn't begun, add 2532 * In the offloaded ROC case, if it hasn't begun, add
2456 * this new one to the dependent list to be handled 2533 * this new one to the dependent list to be handled
2457 * when the the master one begins. If it has begun, 2534 * when the master one begins. If it has begun,
2458 * check that there's still a minimum time left and 2535 * check that there's still a minimum time left and
2459 * if so, start this one, transmitting the frame, but 2536 * if so, start this one, transmitting the frame, but
2460 * add it to the list directly after this one with a 2537 * add it to the list directly after this one with
2461 * a reduced time so we'll ask the driver to execute 2538 * a reduced time so we'll ask the driver to execute
2462 * it right after finishing the previous one, in the 2539 * it right after finishing the previous one, in the
2463 * hope that it'll also be executed right afterwards, 2540 * hope that it'll also be executed right afterwards,
2464 * effectively extending the old one. 2541 * effectively extending the old one.
2465 * If there's no minimum time left, just add it to the 2542 * If there's no minimum time left, just add it to the
2466 * normal list. 2543 * normal list.
2544 * TODO: the ROC type is ignored here, assuming that it
2545 * is better to immediately use the current ROC.
2467 */ 2546 */
2468 if (!tmp->hw_begun) { 2547 if (!tmp->hw_begun) {
2469 list_add_tail(&roc->list, &tmp->dependents); 2548 list_add_tail(&roc->list, &tmp->dependents);
@@ -2557,7 +2636,8 @@ static int ieee80211_remain_on_channel(struct wiphy *wiphy,
2557 2636
2558 mutex_lock(&local->mtx); 2637 mutex_lock(&local->mtx);
2559 ret = ieee80211_start_roc_work(local, sdata, chan, 2638 ret = ieee80211_start_roc_work(local, sdata, chan,
2560 duration, cookie, NULL); 2639 duration, cookie, NULL,
2640 IEEE80211_ROC_TYPE_NORMAL);
2561 mutex_unlock(&local->mtx); 2641 mutex_unlock(&local->mtx);
2562 2642
2563 return ret; 2643 return ret;
@@ -2792,7 +2872,8 @@ static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
2792 2872
2793 /* This will handle all kinds of coalescing and immediate TX */ 2873 /* This will handle all kinds of coalescing and immediate TX */
2794 ret = ieee80211_start_roc_work(local, sdata, chan, 2874 ret = ieee80211_start_roc_work(local, sdata, chan,
2795 wait, cookie, skb); 2875 wait, cookie, skb,
2876 IEEE80211_ROC_TYPE_MGMT_TX);
2796 if (ret) 2877 if (ret)
2797 kfree_skb(skb); 2878 kfree_skb(skb);
2798 out_unlock: 2879 out_unlock:
@@ -3302,9 +3383,7 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3302 if (local->use_chanctx) 3383 if (local->use_chanctx)
3303 *chandef = local->monitor_chandef; 3384 *chandef = local->monitor_chandef;
3304 else 3385 else
3305 cfg80211_chandef_create(chandef, 3386 *chandef = local->_oper_chandef;
3306 local->_oper_channel,
3307 local->_oper_channel_type);
3308 ret = 0; 3387 ret = 0;
3309 } 3388 }
3310 rcu_read_unlock(); 3389 rcu_read_unlock();
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index 931be419ab5a..03e8d2e3270e 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -22,7 +22,7 @@ static void ieee80211_change_chanctx(struct ieee80211_local *local,
22 drv_change_chanctx(local, ctx, IEEE80211_CHANCTX_CHANGE_WIDTH); 22 drv_change_chanctx(local, ctx, IEEE80211_CHANCTX_CHANGE_WIDTH);
23 23
24 if (!local->use_chanctx) { 24 if (!local->use_chanctx) {
25 local->_oper_channel_type = cfg80211_get_chandef_type(chandef); 25 local->_oper_chandef = *chandef;
26 ieee80211_hw_config(local, 0); 26 ieee80211_hw_config(local, 0);
27 } 27 }
28} 28}
@@ -57,6 +57,22 @@ ieee80211_find_chanctx(struct ieee80211_local *local,
57 return NULL; 57 return NULL;
58} 58}
59 59
60static bool ieee80211_is_radar_required(struct ieee80211_local *local)
61{
62 struct ieee80211_sub_if_data *sdata;
63
64 rcu_read_lock();
65 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
66 if (sdata->radar_required) {
67 rcu_read_unlock();
68 return true;
69 }
70 }
71 rcu_read_unlock();
72
73 return false;
74}
75
60static struct ieee80211_chanctx * 76static struct ieee80211_chanctx *
61ieee80211_new_chanctx(struct ieee80211_local *local, 77ieee80211_new_chanctx(struct ieee80211_local *local,
62 const struct cfg80211_chan_def *chandef, 78 const struct cfg80211_chan_def *chandef,
@@ -76,6 +92,9 @@ ieee80211_new_chanctx(struct ieee80211_local *local,
76 ctx->conf.rx_chains_static = 1; 92 ctx->conf.rx_chains_static = 1;
77 ctx->conf.rx_chains_dynamic = 1; 93 ctx->conf.rx_chains_dynamic = 1;
78 ctx->mode = mode; 94 ctx->mode = mode;
95 ctx->conf.radar_enabled = ieee80211_is_radar_required(local);
96 if (!local->use_chanctx)
97 local->hw.conf.radar_enabled = ctx->conf.radar_enabled;
79 98
80 /* acquire mutex to prevent idle from changing */ 99 /* acquire mutex to prevent idle from changing */
81 mutex_lock(&local->mtx); 100 mutex_lock(&local->mtx);
@@ -85,9 +104,7 @@ ieee80211_new_chanctx(struct ieee80211_local *local,
85 ieee80211_hw_config(local, changed); 104 ieee80211_hw_config(local, changed);
86 105
87 if (!local->use_chanctx) { 106 if (!local->use_chanctx) {
88 local->_oper_channel_type = 107 local->_oper_chandef = *chandef;
89 cfg80211_get_chandef_type(chandef);
90 local->_oper_channel = chandef->chan;
91 ieee80211_hw_config(local, 0); 108 ieee80211_hw_config(local, 0);
92 } else { 109 } else {
93 err = drv_add_chanctx(local, ctx); 110 err = drv_add_chanctx(local, ctx);
@@ -112,12 +129,24 @@ ieee80211_new_chanctx(struct ieee80211_local *local,
112static void ieee80211_free_chanctx(struct ieee80211_local *local, 129static void ieee80211_free_chanctx(struct ieee80211_local *local,
113 struct ieee80211_chanctx *ctx) 130 struct ieee80211_chanctx *ctx)
114{ 131{
132 bool check_single_channel = false;
115 lockdep_assert_held(&local->chanctx_mtx); 133 lockdep_assert_held(&local->chanctx_mtx);
116 134
117 WARN_ON_ONCE(ctx->refcount != 0); 135 WARN_ON_ONCE(ctx->refcount != 0);
118 136
119 if (!local->use_chanctx) { 137 if (!local->use_chanctx) {
120 local->_oper_channel_type = NL80211_CHAN_NO_HT; 138 struct cfg80211_chan_def *chandef = &local->_oper_chandef;
139 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
140 chandef->center_freq1 = chandef->chan->center_freq;
141 chandef->center_freq2 = 0;
142
143 /* NOTE: Disabling radar is only valid here for
144 * single channel context. To be sure, check it ...
145 */
146 if (local->hw.conf.radar_enabled)
147 check_single_channel = true;
148 local->hw.conf.radar_enabled = false;
149
121 ieee80211_hw_config(local, 0); 150 ieee80211_hw_config(local, 0);
122 } else { 151 } else {
123 drv_remove_chanctx(local, ctx); 152 drv_remove_chanctx(local, ctx);
@@ -126,6 +155,9 @@ static void ieee80211_free_chanctx(struct ieee80211_local *local,
126 list_del_rcu(&ctx->list); 155 list_del_rcu(&ctx->list);
127 kfree_rcu(ctx, rcu_head); 156 kfree_rcu(ctx, rcu_head);
128 157
158 /* throw a warning if this wasn't the only channel context. */
159 WARN_ON(check_single_channel && !list_empty(&local->chanctx_list));
160
129 mutex_lock(&local->mtx); 161 mutex_lock(&local->mtx);
130 ieee80211_recalc_idle(local); 162 ieee80211_recalc_idle(local);
131 mutex_unlock(&local->mtx); 163 mutex_unlock(&local->mtx);
@@ -237,19 +269,11 @@ static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata)
237void ieee80211_recalc_radar_chanctx(struct ieee80211_local *local, 269void ieee80211_recalc_radar_chanctx(struct ieee80211_local *local,
238 struct ieee80211_chanctx *chanctx) 270 struct ieee80211_chanctx *chanctx)
239{ 271{
240 struct ieee80211_sub_if_data *sdata; 272 bool radar_enabled;
241 bool radar_enabled = false;
242 273
243 lockdep_assert_held(&local->chanctx_mtx); 274 lockdep_assert_held(&local->chanctx_mtx);
244 275
245 rcu_read_lock(); 276 radar_enabled = ieee80211_is_radar_required(local);
246 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
247 if (sdata->radar_required) {
248 radar_enabled = true;
249 break;
250 }
251 }
252 rcu_read_unlock();
253 277
254 if (radar_enabled == chanctx->conf.radar_enabled) 278 if (radar_enabled == chanctx->conf.radar_enabled)
255 return; 279 return;
diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
index c3a3082b72e5..1521cabad3d6 100644
--- a/net/mac80211/debugfs_key.c
+++ b/net/mac80211/debugfs_key.c
@@ -295,7 +295,7 @@ void ieee80211_debugfs_key_update_default(struct ieee80211_sub_if_data *sdata)
295 char buf[50]; 295 char buf[50];
296 struct ieee80211_key *key; 296 struct ieee80211_key *key;
297 297
298 if (!sdata->debugfs.dir) 298 if (!sdata->vif.debugfs_dir)
299 return; 299 return;
300 300
301 lockdep_assert_held(&sdata->local->key_mtx); 301 lockdep_assert_held(&sdata->local->key_mtx);
@@ -311,7 +311,7 @@ void ieee80211_debugfs_key_update_default(struct ieee80211_sub_if_data *sdata)
311 sprintf(buf, "../keys/%d", key->debugfs.cnt); 311 sprintf(buf, "../keys/%d", key->debugfs.cnt);
312 sdata->debugfs.default_unicast_key = 312 sdata->debugfs.default_unicast_key =
313 debugfs_create_symlink("default_unicast_key", 313 debugfs_create_symlink("default_unicast_key",
314 sdata->debugfs.dir, buf); 314 sdata->vif.debugfs_dir, buf);
315 } 315 }
316 316
317 if (sdata->debugfs.default_multicast_key) { 317 if (sdata->debugfs.default_multicast_key) {
@@ -325,7 +325,7 @@ void ieee80211_debugfs_key_update_default(struct ieee80211_sub_if_data *sdata)
325 sprintf(buf, "../keys/%d", key->debugfs.cnt); 325 sprintf(buf, "../keys/%d", key->debugfs.cnt);
326 sdata->debugfs.default_multicast_key = 326 sdata->debugfs.default_multicast_key =
327 debugfs_create_symlink("default_multicast_key", 327 debugfs_create_symlink("default_multicast_key",
328 sdata->debugfs.dir, buf); 328 sdata->vif.debugfs_dir, buf);
329 } 329 }
330} 330}
331 331
@@ -334,7 +334,7 @@ void ieee80211_debugfs_key_add_mgmt_default(struct ieee80211_sub_if_data *sdata)
334 char buf[50]; 334 char buf[50];
335 struct ieee80211_key *key; 335 struct ieee80211_key *key;
336 336
337 if (!sdata->debugfs.dir) 337 if (!sdata->vif.debugfs_dir)
338 return; 338 return;
339 339
340 key = key_mtx_dereference(sdata->local, 340 key = key_mtx_dereference(sdata->local,
@@ -343,7 +343,7 @@ void ieee80211_debugfs_key_add_mgmt_default(struct ieee80211_sub_if_data *sdata)
343 sprintf(buf, "../keys/%d", key->debugfs.cnt); 343 sprintf(buf, "../keys/%d", key->debugfs.cnt);
344 sdata->debugfs.default_mgmt_key = 344 sdata->debugfs.default_mgmt_key =
345 debugfs_create_symlink("default_mgmt_key", 345 debugfs_create_symlink("default_mgmt_key",
346 sdata->debugfs.dir, buf); 346 sdata->vif.debugfs_dir, buf);
347 } else 347 } else
348 ieee80211_debugfs_key_remove_mgmt_default(sdata); 348 ieee80211_debugfs_key_remove_mgmt_default(sdata);
349} 349}
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 059bbb82e84f..14abcf44f974 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -124,6 +124,15 @@ static ssize_t ieee80211_if_fmt_##name( \
124 return scnprintf(buf, buflen, "%d\n", sdata->field / 16); \ 124 return scnprintf(buf, buflen, "%d\n", sdata->field / 16); \
125} 125}
126 126
127#define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, field) \
128static ssize_t ieee80211_if_fmt_##name( \
129 const struct ieee80211_sub_if_data *sdata, \
130 char *buf, int buflen) \
131{ \
132 return scnprintf(buf, buflen, "%d\n", \
133 jiffies_to_msecs(sdata->field)); \
134}
135
127#define __IEEE80211_IF_FILE(name, _write) \ 136#define __IEEE80211_IF_FILE(name, _write) \
128static ssize_t ieee80211_if_read_##name(struct file *file, \ 137static ssize_t ieee80211_if_read_##name(struct file *file, \
129 char __user *userbuf, \ 138 char __user *userbuf, \
@@ -197,6 +206,7 @@ IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
197IEEE80211_IF_FILE(aid, u.mgd.aid, DEC); 206IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
198IEEE80211_IF_FILE(last_beacon, u.mgd.last_beacon_signal, DEC); 207IEEE80211_IF_FILE(last_beacon, u.mgd.last_beacon_signal, DEC);
199IEEE80211_IF_FILE(ave_beacon, u.mgd.ave_beacon_signal, DEC_DIV_16); 208IEEE80211_IF_FILE(ave_beacon, u.mgd.ave_beacon_signal, DEC_DIV_16);
209IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS);
200 210
201static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata, 211static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
202 enum ieee80211_smps_mode smps_mode) 212 enum ieee80211_smps_mode smps_mode)
@@ -521,7 +531,7 @@ IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
521#endif 531#endif
522 532
523#define DEBUGFS_ADD_MODE(name, mode) \ 533#define DEBUGFS_ADD_MODE(name, mode) \
524 debugfs_create_file(#name, mode, sdata->debugfs.dir, \ 534 debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
525 sdata, &name##_ops); 535 sdata, &name##_ops);
526 536
527#define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400) 537#define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
@@ -542,6 +552,7 @@ static void add_sta_files(struct ieee80211_sub_if_data *sdata)
542 DEBUGFS_ADD(aid); 552 DEBUGFS_ADD(aid);
543 DEBUGFS_ADD(last_beacon); 553 DEBUGFS_ADD(last_beacon);
544 DEBUGFS_ADD(ave_beacon); 554 DEBUGFS_ADD(ave_beacon);
555 DEBUGFS_ADD(beacon_timeout);
545 DEBUGFS_ADD_MODE(smps, 0600); 556 DEBUGFS_ADD_MODE(smps, 0600);
546 DEBUGFS_ADD_MODE(tkip_mic_test, 0200); 557 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
547 DEBUGFS_ADD_MODE(uapsd_queues, 0600); 558 DEBUGFS_ADD_MODE(uapsd_queues, 0600);
@@ -577,7 +588,7 @@ static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
577static void add_mesh_stats(struct ieee80211_sub_if_data *sdata) 588static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
578{ 589{
579 struct dentry *dir = debugfs_create_dir("mesh_stats", 590 struct dentry *dir = debugfs_create_dir("mesh_stats",
580 sdata->debugfs.dir); 591 sdata->vif.debugfs_dir);
581#define MESHSTATS_ADD(name)\ 592#define MESHSTATS_ADD(name)\
582 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops); 593 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
583 594
@@ -594,7 +605,7 @@ static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
594static void add_mesh_config(struct ieee80211_sub_if_data *sdata) 605static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
595{ 606{
596 struct dentry *dir = debugfs_create_dir("mesh_config", 607 struct dentry *dir = debugfs_create_dir("mesh_config",
597 sdata->debugfs.dir); 608 sdata->vif.debugfs_dir);
598 609
599#define MESHPARAMS_ADD(name) \ 610#define MESHPARAMS_ADD(name) \
600 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops); 611 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
@@ -631,7 +642,7 @@ static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
631 642
632static void add_files(struct ieee80211_sub_if_data *sdata) 643static void add_files(struct ieee80211_sub_if_data *sdata)
633{ 644{
634 if (!sdata->debugfs.dir) 645 if (!sdata->vif.debugfs_dir)
635 return; 646 return;
636 647
637 DEBUGFS_ADD(flags); 648 DEBUGFS_ADD(flags);
@@ -673,21 +684,21 @@ void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
673 char buf[10+IFNAMSIZ]; 684 char buf[10+IFNAMSIZ];
674 685
675 sprintf(buf, "netdev:%s", sdata->name); 686 sprintf(buf, "netdev:%s", sdata->name);
676 sdata->debugfs.dir = debugfs_create_dir(buf, 687 sdata->vif.debugfs_dir = debugfs_create_dir(buf,
677 sdata->local->hw.wiphy->debugfsdir); 688 sdata->local->hw.wiphy->debugfsdir);
678 if (sdata->debugfs.dir) 689 if (sdata->vif.debugfs_dir)
679 sdata->debugfs.subdir_stations = debugfs_create_dir("stations", 690 sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
680 sdata->debugfs.dir); 691 sdata->vif.debugfs_dir);
681 add_files(sdata); 692 add_files(sdata);
682} 693}
683 694
684void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata) 695void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
685{ 696{
686 if (!sdata->debugfs.dir) 697 if (!sdata->vif.debugfs_dir)
687 return; 698 return;
688 699
689 debugfs_remove_recursive(sdata->debugfs.dir); 700 debugfs_remove_recursive(sdata->vif.debugfs_dir);
690 sdata->debugfs.dir = NULL; 701 sdata->vif.debugfs_dir = NULL;
691} 702}
692 703
693void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata) 704void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
@@ -695,7 +706,7 @@ void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
695 struct dentry *dir; 706 struct dentry *dir;
696 char buf[10 + IFNAMSIZ]; 707 char buf[10 + IFNAMSIZ];
697 708
698 dir = sdata->debugfs.dir; 709 dir = sdata->vif.debugfs_dir;
699 710
700 if (!dir) 711 if (!dir)
701 return; 712 return;
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
index c7591f73dbc3..44e201d60a13 100644
--- a/net/mac80211/debugfs_sta.c
+++ b/net/mac80211/debugfs_sta.c
@@ -54,6 +54,7 @@ STA_FILE(aid, sta.aid, D);
54STA_FILE(dev, sdata->name, S); 54STA_FILE(dev, sdata->name, S);
55STA_FILE(last_signal, last_signal, D); 55STA_FILE(last_signal, last_signal, D);
56STA_FILE(last_ack_signal, last_ack_signal, D); 56STA_FILE(last_ack_signal, last_ack_signal, D);
57STA_FILE(beacon_loss_count, beacon_loss_count, D);
57 58
58static ssize_t sta_flags_read(struct file *file, char __user *userbuf, 59static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
59 size_t count, loff_t *ppos) 60 size_t count, loff_t *ppos)
@@ -325,6 +326,36 @@ static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
325} 326}
326STA_OPS(ht_capa); 327STA_OPS(ht_capa);
327 328
329static ssize_t sta_vht_capa_read(struct file *file, char __user *userbuf,
330 size_t count, loff_t *ppos)
331{
332 char buf[128], *p = buf;
333 struct sta_info *sta = file->private_data;
334 struct ieee80211_sta_vht_cap *vhtc = &sta->sta.vht_cap;
335
336 p += scnprintf(p, sizeof(buf) + buf - p, "VHT %ssupported\n",
337 vhtc->vht_supported ? "" : "not ");
338 if (vhtc->vht_supported) {
339 p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.8x\n", vhtc->cap);
340
341 p += scnprintf(p, sizeof(buf)+buf-p, "RX MCS: %.4x\n",
342 le16_to_cpu(vhtc->vht_mcs.rx_mcs_map));
343 if (vhtc->vht_mcs.rx_highest)
344 p += scnprintf(p, sizeof(buf)+buf-p,
345 "MCS RX highest: %d Mbps\n",
346 le16_to_cpu(vhtc->vht_mcs.rx_highest));
347 p += scnprintf(p, sizeof(buf)+buf-p, "TX MCS: %.4x\n",
348 le16_to_cpu(vhtc->vht_mcs.tx_mcs_map));
349 if (vhtc->vht_mcs.tx_highest)
350 p += scnprintf(p, sizeof(buf)+buf-p,
351 "MCS TX highest: %d Mbps\n",
352 le16_to_cpu(vhtc->vht_mcs.tx_highest));
353 }
354
355 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
356}
357STA_OPS(vht_capa);
358
328static ssize_t sta_current_tx_rate_read(struct file *file, char __user *userbuf, 359static ssize_t sta_current_tx_rate_read(struct file *file, char __user *userbuf,
329 size_t count, loff_t *ppos) 360 size_t count, loff_t *ppos)
330{ 361{
@@ -404,7 +435,9 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta)
404 DEBUGFS_ADD(agg_status); 435 DEBUGFS_ADD(agg_status);
405 DEBUGFS_ADD(dev); 436 DEBUGFS_ADD(dev);
406 DEBUGFS_ADD(last_signal); 437 DEBUGFS_ADD(last_signal);
438 DEBUGFS_ADD(beacon_loss_count);
407 DEBUGFS_ADD(ht_capa); 439 DEBUGFS_ADD(ht_capa);
440 DEBUGFS_ADD(vht_capa);
408 DEBUGFS_ADD(last_ack_signal); 441 DEBUGFS_ADD(last_ack_signal);
409 DEBUGFS_ADD(current_tx_rate); 442 DEBUGFS_ADD(current_tx_rate);
410 DEBUGFS_ADD(last_rx_rate); 443 DEBUGFS_ADD(last_rx_rate);
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index ee56d0779d8b..169664c122e2 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -241,6 +241,22 @@ static inline u64 drv_prepare_multicast(struct ieee80211_local *local,
241 return ret; 241 return ret;
242} 242}
243 243
244static inline void drv_set_multicast_list(struct ieee80211_local *local,
245 struct ieee80211_sub_if_data *sdata,
246 struct netdev_hw_addr_list *mc_list)
247{
248 bool allmulti = sdata->flags & IEEE80211_SDATA_ALLMULTI;
249
250 trace_drv_set_multicast_list(local, sdata, mc_list->count);
251
252 check_sdata_in_driver(sdata);
253
254 if (local->ops->set_multicast_list)
255 local->ops->set_multicast_list(&local->hw, &sdata->vif,
256 allmulti, mc_list);
257 trace_drv_return_void(local);
258}
259
244static inline void drv_configure_filter(struct ieee80211_local *local, 260static inline void drv_configure_filter(struct ieee80211_local *local,
245 unsigned int changed_flags, 261 unsigned int changed_flags,
246 unsigned int *total_flags, 262 unsigned int *total_flags,
@@ -531,43 +547,6 @@ static inline void drv_sta_remove_debugfs(struct ieee80211_local *local,
531 local->ops->sta_remove_debugfs(&local->hw, &sdata->vif, 547 local->ops->sta_remove_debugfs(&local->hw, &sdata->vif,
532 sta, dir); 548 sta, dir);
533} 549}
534
535static inline
536void drv_add_interface_debugfs(struct ieee80211_local *local,
537 struct ieee80211_sub_if_data *sdata)
538{
539 might_sleep();
540
541 check_sdata_in_driver(sdata);
542
543 if (!local->ops->add_interface_debugfs)
544 return;
545
546 local->ops->add_interface_debugfs(&local->hw, &sdata->vif,
547 sdata->debugfs.dir);
548}
549
550static inline
551void drv_remove_interface_debugfs(struct ieee80211_local *local,
552 struct ieee80211_sub_if_data *sdata)
553{
554 might_sleep();
555
556 check_sdata_in_driver(sdata);
557
558 if (!local->ops->remove_interface_debugfs)
559 return;
560
561 local->ops->remove_interface_debugfs(&local->hw, &sdata->vif,
562 sdata->debugfs.dir);
563}
564#else
565static inline
566void drv_add_interface_debugfs(struct ieee80211_local *local,
567 struct ieee80211_sub_if_data *sdata) {}
568static inline
569void drv_remove_interface_debugfs(struct ieee80211_local *local,
570 struct ieee80211_sub_if_data *sdata) {}
571#endif 550#endif
572 551
573static inline __must_check 552static inline __must_check
@@ -741,13 +720,14 @@ static inline void drv_rfkill_poll(struct ieee80211_local *local)
741 local->ops->rfkill_poll(&local->hw); 720 local->ops->rfkill_poll(&local->hw);
742} 721}
743 722
744static inline void drv_flush(struct ieee80211_local *local, bool drop) 723static inline void drv_flush(struct ieee80211_local *local,
724 u32 queues, bool drop)
745{ 725{
746 might_sleep(); 726 might_sleep();
747 727
748 trace_drv_flush(local, drop); 728 trace_drv_flush(local, queues, drop);
749 if (local->ops->flush) 729 if (local->ops->flush)
750 local->ops->flush(&local->hw, drop); 730 local->ops->flush(&local->hw, queues, drop);
751 trace_drv_return_void(local); 731 trace_drv_return_void(local);
752} 732}
753 733
@@ -787,15 +767,16 @@ static inline int drv_get_antenna(struct ieee80211_local *local,
787static inline int drv_remain_on_channel(struct ieee80211_local *local, 767static inline int drv_remain_on_channel(struct ieee80211_local *local,
788 struct ieee80211_sub_if_data *sdata, 768 struct ieee80211_sub_if_data *sdata,
789 struct ieee80211_channel *chan, 769 struct ieee80211_channel *chan,
790 unsigned int duration) 770 unsigned int duration,
771 enum ieee80211_roc_type type)
791{ 772{
792 int ret; 773 int ret;
793 774
794 might_sleep(); 775 might_sleep();
795 776
796 trace_drv_remain_on_channel(local, sdata, chan, duration); 777 trace_drv_remain_on_channel(local, sdata, chan, duration, type);
797 ret = local->ops->remain_on_channel(&local->hw, &sdata->vif, 778 ret = local->ops->remain_on_channel(&local->hw, &sdata->vif,
798 chan, duration); 779 chan, duration, type);
799 trace_drv_return_int(local, ret); 780 trace_drv_return_int(local, ret);
800 781
801 return ret; 782 return ret;
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index 0db25d4bb223..af8cee06e4f3 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -40,13 +40,6 @@ void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
40 if (!ht_cap->ht_supported) 40 if (!ht_cap->ht_supported)
41 return; 41 return;
42 42
43 if (sdata->vif.type != NL80211_IFTYPE_STATION) {
44 /* AP interfaces call this code when adding new stations,
45 * so just silently ignore non station interfaces.
46 */
47 return;
48 }
49
50 /* NOTE: If you add more over-rides here, update register_hw 43 /* NOTE: If you add more over-rides here, update register_hw
51 * ht_capa_mod_msk logic in main.c as well. 44 * ht_capa_mod_msk logic in main.c as well.
52 * And, if this method can ever change ht_cap.ht_supported, fix 45 * And, if this method can ever change ht_cap.ht_supported, fix
@@ -97,7 +90,7 @@ bool ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
97 const struct ieee80211_ht_cap *ht_cap_ie, 90 const struct ieee80211_ht_cap *ht_cap_ie,
98 struct sta_info *sta) 91 struct sta_info *sta)
99{ 92{
100 struct ieee80211_sta_ht_cap ht_cap; 93 struct ieee80211_sta_ht_cap ht_cap, own_cap;
101 u8 ampdu_info, tx_mcs_set_cap; 94 u8 ampdu_info, tx_mcs_set_cap;
102 int i, max_tx_streams; 95 int i, max_tx_streams;
103 bool changed; 96 bool changed;
@@ -111,6 +104,18 @@ bool ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
111 104
112 ht_cap.ht_supported = true; 105 ht_cap.ht_supported = true;
113 106
107 own_cap = sband->ht_cap;
108
109 /*
110 * If user has specified capability over-rides, take care
111 * of that if the station we're setting up is the AP that
112 * we advertised a restricted capability set to. Override
113 * our own capabilities and then use those below.
114 */
115 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
116 !test_sta_flag(sta, WLAN_STA_TDLS_PEER))
117 ieee80211_apply_htcap_overrides(sdata, &own_cap);
118
114 /* 119 /*
115 * The bits listed in this expression should be 120 * The bits listed in this expression should be
116 * the same for the peer and us, if the station 121 * the same for the peer and us, if the station
@@ -118,21 +123,20 @@ bool ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
118 * we mask them out. 123 * we mask them out.
119 */ 124 */
120 ht_cap.cap = le16_to_cpu(ht_cap_ie->cap_info) & 125 ht_cap.cap = le16_to_cpu(ht_cap_ie->cap_info) &
121 (sband->ht_cap.cap | 126 (own_cap.cap | ~(IEEE80211_HT_CAP_LDPC_CODING |
122 ~(IEEE80211_HT_CAP_LDPC_CODING | 127 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
123 IEEE80211_HT_CAP_SUP_WIDTH_20_40 | 128 IEEE80211_HT_CAP_GRN_FLD |
124 IEEE80211_HT_CAP_GRN_FLD | 129 IEEE80211_HT_CAP_SGI_20 |
125 IEEE80211_HT_CAP_SGI_20 | 130 IEEE80211_HT_CAP_SGI_40 |
126 IEEE80211_HT_CAP_SGI_40 | 131 IEEE80211_HT_CAP_DSSSCCK40));
127 IEEE80211_HT_CAP_DSSSCCK40));
128 132
129 /* 133 /*
130 * The STBC bits are asymmetric -- if we don't have 134 * The STBC bits are asymmetric -- if we don't have
131 * TX then mask out the peer's RX and vice versa. 135 * TX then mask out the peer's RX and vice versa.
132 */ 136 */
133 if (!(sband->ht_cap.cap & IEEE80211_HT_CAP_TX_STBC)) 137 if (!(own_cap.cap & IEEE80211_HT_CAP_TX_STBC))
134 ht_cap.cap &= ~IEEE80211_HT_CAP_RX_STBC; 138 ht_cap.cap &= ~IEEE80211_HT_CAP_RX_STBC;
135 if (!(sband->ht_cap.cap & IEEE80211_HT_CAP_RX_STBC)) 139 if (!(own_cap.cap & IEEE80211_HT_CAP_RX_STBC))
136 ht_cap.cap &= ~IEEE80211_HT_CAP_TX_STBC; 140 ht_cap.cap &= ~IEEE80211_HT_CAP_TX_STBC;
137 141
138 ampdu_info = ht_cap_ie->ampdu_params_info; 142 ampdu_info = ht_cap_ie->ampdu_params_info;
@@ -142,7 +146,7 @@ bool ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
142 (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2; 146 (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
143 147
144 /* own MCS TX capabilities */ 148 /* own MCS TX capabilities */
145 tx_mcs_set_cap = sband->ht_cap.mcs.tx_params; 149 tx_mcs_set_cap = own_cap.mcs.tx_params;
146 150
147 /* Copy peer MCS TX capabilities, the driver might need them. */ 151 /* Copy peer MCS TX capabilities, the driver might need them. */
148 ht_cap.mcs.tx_params = ht_cap_ie->mcs.tx_params; 152 ht_cap.mcs.tx_params = ht_cap_ie->mcs.tx_params;
@@ -168,26 +172,20 @@ bool ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
168 */ 172 */
169 for (i = 0; i < max_tx_streams; i++) 173 for (i = 0; i < max_tx_streams; i++)
170 ht_cap.mcs.rx_mask[i] = 174 ht_cap.mcs.rx_mask[i] =
171 sband->ht_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i]; 175 own_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i];
172 176
173 if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION) 177 if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION)
174 for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE; 178 for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE;
175 i < IEEE80211_HT_MCS_MASK_LEN; i++) 179 i < IEEE80211_HT_MCS_MASK_LEN; i++)
176 ht_cap.mcs.rx_mask[i] = 180 ht_cap.mcs.rx_mask[i] =
177 sband->ht_cap.mcs.rx_mask[i] & 181 own_cap.mcs.rx_mask[i] &
178 ht_cap_ie->mcs.rx_mask[i]; 182 ht_cap_ie->mcs.rx_mask[i];
179 183
180 /* handle MCS rate 32 too */ 184 /* handle MCS rate 32 too */
181 if (sband->ht_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1) 185 if (own_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1)
182 ht_cap.mcs.rx_mask[32/8] |= 1; 186 ht_cap.mcs.rx_mask[32/8] |= 1;
183 187
184 apply: 188 apply:
185 /*
186 * If user has specified capability over-rides, take care
187 * of that here.
188 */
189 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
190
191 changed = memcmp(&sta->sta.ht_cap, &ht_cap, sizeof(ht_cap)); 189 changed = memcmp(&sta->sta.ht_cap, &ht_cap, sizeof(ht_cap));
192 190
193 memcpy(&sta->sta.ht_cap, &ht_cap, sizeof(ht_cap)); 191 memcpy(&sta->sta.ht_cap, &ht_cap, sizeof(ht_cap));
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 40b71dfcc79d..170f9a7fa319 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -44,7 +44,6 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
44 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 44 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
45 struct ieee80211_local *local = sdata->local; 45 struct ieee80211_local *local = sdata->local;
46 int rates, i; 46 int rates, i;
47 struct sk_buff *skb;
48 struct ieee80211_mgmt *mgmt; 47 struct ieee80211_mgmt *mgmt;
49 u8 *pos; 48 u8 *pos;
50 struct ieee80211_supported_band *sband; 49 struct ieee80211_supported_band *sband;
@@ -52,20 +51,14 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
52 u32 bss_change; 51 u32 bss_change;
53 u8 supp_rates[IEEE80211_MAX_SUPP_RATES]; 52 u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
54 struct cfg80211_chan_def chandef; 53 struct cfg80211_chan_def chandef;
54 struct beacon_data *presp;
55 int frame_len;
55 56
56 lockdep_assert_held(&ifibss->mtx); 57 lockdep_assert_held(&ifibss->mtx);
57 58
58 /* Reset own TSF to allow time synchronization work. */ 59 /* Reset own TSF to allow time synchronization work. */
59 drv_reset_tsf(local, sdata); 60 drv_reset_tsf(local, sdata);
60 61
61 skb = ifibss->skb;
62 RCU_INIT_POINTER(ifibss->presp, NULL);
63 synchronize_rcu();
64 skb->data = skb->head;
65 skb->len = 0;
66 skb_reset_tail_pointer(skb);
67 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
68
69 if (!ether_addr_equal(ifibss->bssid, bssid)) 62 if (!ether_addr_equal(ifibss->bssid, bssid))
70 sta_info_flush(sdata); 63 sta_info_flush(sdata);
71 64
@@ -73,10 +66,19 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
73 if (sdata->vif.bss_conf.ibss_joined) { 66 if (sdata->vif.bss_conf.ibss_joined) {
74 sdata->vif.bss_conf.ibss_joined = false; 67 sdata->vif.bss_conf.ibss_joined = false;
75 sdata->vif.bss_conf.ibss_creator = false; 68 sdata->vif.bss_conf.ibss_creator = false;
69 sdata->vif.bss_conf.enable_beacon = false;
76 netif_carrier_off(sdata->dev); 70 netif_carrier_off(sdata->dev);
77 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IBSS); 71 ieee80211_bss_info_change_notify(sdata,
72 BSS_CHANGED_IBSS |
73 BSS_CHANGED_BEACON_ENABLED);
78 } 74 }
79 75
76 presp = rcu_dereference_protected(ifibss->presp,
77 lockdep_is_held(&ifibss->mtx));
78 rcu_assign_pointer(ifibss->presp, NULL);
79 if (presp)
80 kfree_rcu(presp, rcu_head);
81
80 sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0; 82 sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
81 83
82 cfg80211_chandef_create(&chandef, chan, ifibss->channel_type); 84 cfg80211_chandef_create(&chandef, chan, ifibss->channel_type);
@@ -98,19 +100,24 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
98 100
99 sband = local->hw.wiphy->bands[chan->band]; 101 sband = local->hw.wiphy->bands[chan->band];
100 102
101 /* build supported rates array */
102 pos = supp_rates;
103 for (i = 0; i < sband->n_bitrates; i++) {
104 int rate = sband->bitrates[i].bitrate;
105 u8 basic = 0;
106 if (basic_rates & BIT(i))
107 basic = 0x80;
108 *pos++ = basic | (u8) (rate / 5);
109 }
110
111 /* Build IBSS probe response */ 103 /* Build IBSS probe response */
112 mgmt = (void *) skb_put(skb, 24 + sizeof(mgmt->u.beacon)); 104 frame_len = sizeof(struct ieee80211_hdr_3addr) +
113 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); 105 12 /* struct ieee80211_mgmt.u.beacon */ +
106 2 + IEEE80211_MAX_SSID_LEN /* max SSID */ +
107 2 + 8 /* max Supported Rates */ +
108 3 /* max DS params */ +
109 4 /* IBSS params */ +
110 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
111 2 + sizeof(struct ieee80211_ht_cap) +
112 2 + sizeof(struct ieee80211_ht_operation) +
113 ifibss->ie_len;
114 presp = kzalloc(sizeof(*presp) + frame_len, GFP_KERNEL);
115 if (!presp)
116 return;
117
118 presp->head = (void *)(presp + 1);
119
120 mgmt = (void *) presp->head;
114 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 121 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
115 IEEE80211_STYPE_PROBE_RESP); 122 IEEE80211_STYPE_PROBE_RESP);
116 eth_broadcast_addr(mgmt->da); 123 eth_broadcast_addr(mgmt->da);
@@ -120,27 +127,30 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
120 mgmt->u.beacon.timestamp = cpu_to_le64(tsf); 127 mgmt->u.beacon.timestamp = cpu_to_le64(tsf);
121 mgmt->u.beacon.capab_info = cpu_to_le16(capability); 128 mgmt->u.beacon.capab_info = cpu_to_le16(capability);
122 129
123 pos = skb_put(skb, 2 + ifibss->ssid_len); 130 pos = (u8 *)mgmt + offsetof(struct ieee80211_mgmt, u.beacon.variable);
131
124 *pos++ = WLAN_EID_SSID; 132 *pos++ = WLAN_EID_SSID;
125 *pos++ = ifibss->ssid_len; 133 *pos++ = ifibss->ssid_len;
126 memcpy(pos, ifibss->ssid, ifibss->ssid_len); 134 memcpy(pos, ifibss->ssid, ifibss->ssid_len);
135 pos += ifibss->ssid_len;
127 136
128 rates = sband->n_bitrates; 137 rates = min_t(int, 8, sband->n_bitrates);
129 if (rates > 8)
130 rates = 8;
131 pos = skb_put(skb, 2 + rates);
132 *pos++ = WLAN_EID_SUPP_RATES; 138 *pos++ = WLAN_EID_SUPP_RATES;
133 *pos++ = rates; 139 *pos++ = rates;
134 memcpy(pos, supp_rates, rates); 140 for (i = 0; i < rates; i++) {
141 int rate = sband->bitrates[i].bitrate;
142 u8 basic = 0;
143 if (basic_rates & BIT(i))
144 basic = 0x80;
145 *pos++ = basic | (u8) (rate / 5);
146 }
135 147
136 if (sband->band == IEEE80211_BAND_2GHZ) { 148 if (sband->band == IEEE80211_BAND_2GHZ) {
137 pos = skb_put(skb, 2 + 1);
138 *pos++ = WLAN_EID_DS_PARAMS; 149 *pos++ = WLAN_EID_DS_PARAMS;
139 *pos++ = 1; 150 *pos++ = 1;
140 *pos++ = ieee80211_frequency_to_channel(chan->center_freq); 151 *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
141 } 152 }
142 153
143 pos = skb_put(skb, 2 + 2);
144 *pos++ = WLAN_EID_IBSS_PARAMS; 154 *pos++ = WLAN_EID_IBSS_PARAMS;
145 *pos++ = 2; 155 *pos++ = 2;
146 /* FIX: set ATIM window based on scan results */ 156 /* FIX: set ATIM window based on scan results */
@@ -148,23 +158,25 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
148 *pos++ = 0; 158 *pos++ = 0;
149 159
150 if (sband->n_bitrates > 8) { 160 if (sband->n_bitrates > 8) {
151 rates = sband->n_bitrates - 8;
152 pos = skb_put(skb, 2 + rates);
153 *pos++ = WLAN_EID_EXT_SUPP_RATES; 161 *pos++ = WLAN_EID_EXT_SUPP_RATES;
154 *pos++ = rates; 162 *pos++ = sband->n_bitrates - 8;
155 memcpy(pos, &supp_rates[8], rates); 163 for (i = 8; i < sband->n_bitrates; i++) {
164 int rate = sband->bitrates[i].bitrate;
165 u8 basic = 0;
166 if (basic_rates & BIT(i))
167 basic = 0x80;
168 *pos++ = basic | (u8) (rate / 5);
169 }
156 } 170 }
157 171
158 if (ifibss->ie_len) 172 if (ifibss->ie_len) {
159 memcpy(skb_put(skb, ifibss->ie_len), 173 memcpy(pos, ifibss->ie, ifibss->ie_len);
160 ifibss->ie, ifibss->ie_len); 174 pos += ifibss->ie_len;
175 }
161 176
162 /* add HT capability and information IEs */ 177 /* add HT capability and information IEs */
163 if (chandef.width != NL80211_CHAN_WIDTH_20_NOHT && 178 if (chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
164 sband->ht_cap.ht_supported) { 179 sband->ht_cap.ht_supported) {
165 pos = skb_put(skb, 4 +
166 sizeof(struct ieee80211_ht_cap) +
167 sizeof(struct ieee80211_ht_operation));
168 pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, 180 pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap,
169 sband->ht_cap.cap); 181 sband->ht_cap.cap);
170 /* 182 /*
@@ -177,7 +189,6 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
177 } 189 }
178 190
179 if (local->hw.queues >= IEEE80211_NUM_ACS) { 191 if (local->hw.queues >= IEEE80211_NUM_ACS) {
180 pos = skb_put(skb, 9);
181 *pos++ = WLAN_EID_VENDOR_SPECIFIC; 192 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
182 *pos++ = 7; /* len */ 193 *pos++ = 7; /* len */
183 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ 194 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
@@ -189,11 +200,17 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
189 *pos++ = 0; /* U-APSD no in use */ 200 *pos++ = 0; /* U-APSD no in use */
190 } 201 }
191 202
192 rcu_assign_pointer(ifibss->presp, skb); 203 presp->head_len = pos - presp->head;
204 if (WARN_ON(presp->head_len > frame_len))
205 return;
206
207 rcu_assign_pointer(ifibss->presp, presp);
193 208
194 sdata->vif.bss_conf.enable_beacon = true; 209 sdata->vif.bss_conf.enable_beacon = true;
195 sdata->vif.bss_conf.beacon_int = beacon_int; 210 sdata->vif.bss_conf.beacon_int = beacon_int;
196 sdata->vif.bss_conf.basic_rates = basic_rates; 211 sdata->vif.bss_conf.basic_rates = basic_rates;
212 sdata->vif.bss_conf.ssid_len = ifibss->ssid_len;
213 memcpy(sdata->vif.bss_conf.ssid, ifibss->ssid, ifibss->ssid_len);
197 bss_change = BSS_CHANGED_BEACON_INT; 214 bss_change = BSS_CHANGED_BEACON_INT;
198 bss_change |= ieee80211_reset_erp_info(sdata); 215 bss_change |= ieee80211_reset_erp_info(sdata);
199 bss_change |= BSS_CHANGED_BSSID; 216 bss_change |= BSS_CHANGED_BSSID;
@@ -202,6 +219,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
202 bss_change |= BSS_CHANGED_BASIC_RATES; 219 bss_change |= BSS_CHANGED_BASIC_RATES;
203 bss_change |= BSS_CHANGED_HT; 220 bss_change |= BSS_CHANGED_HT;
204 bss_change |= BSS_CHANGED_IBSS; 221 bss_change |= BSS_CHANGED_IBSS;
222 bss_change |= BSS_CHANGED_SSID;
205 223
206 /* 224 /*
207 * In 5 GHz/802.11a, we can always use short slot time. 225 * In 5 GHz/802.11a, we can always use short slot time.
@@ -227,7 +245,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
227 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); 245 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
228 246
229 bss = cfg80211_inform_bss_frame(local->hw.wiphy, chan, 247 bss = cfg80211_inform_bss_frame(local->hw.wiphy, chan,
230 mgmt, skb->len, 0, GFP_KERNEL); 248 mgmt, presp->head_len, 0, GFP_KERNEL);
231 cfg80211_put_bss(local->hw.wiphy, bss); 249 cfg80211_put_bss(local->hw.wiphy, bss);
232 netif_carrier_on(sdata->dev); 250 netif_carrier_on(sdata->dev);
233 cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL); 251 cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL);
@@ -448,7 +466,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
448 struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band]; 466 struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
449 bool rates_updated = false; 467 bool rates_updated = false;
450 468
451 if (elems->ds_params && elems->ds_params_len == 1) 469 if (elems->ds_params)
452 freq = ieee80211_channel_to_frequency(elems->ds_params[0], 470 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
453 band); 471 band);
454 else 472 else
@@ -822,8 +840,7 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
822 struct ieee80211_local *local = sdata->local; 840 struct ieee80211_local *local = sdata->local;
823 int tx_last_beacon, len = req->len; 841 int tx_last_beacon, len = req->len;
824 struct sk_buff *skb; 842 struct sk_buff *skb;
825 struct ieee80211_mgmt *resp; 843 struct beacon_data *presp;
826 struct sk_buff *presp;
827 u8 *pos, *end; 844 u8 *pos, *end;
828 845
829 lockdep_assert_held(&ifibss->mtx); 846 lockdep_assert_held(&ifibss->mtx);
@@ -864,13 +881,15 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
864 } 881 }
865 882
866 /* Reply with ProbeResp */ 883 /* Reply with ProbeResp */
867 skb = skb_copy(presp, GFP_KERNEL); 884 skb = dev_alloc_skb(local->tx_headroom + presp->head_len);
868 if (!skb) 885 if (!skb)
869 return; 886 return;
870 887
871 resp = (struct ieee80211_mgmt *) skb->data; 888 skb_reserve(skb, local->tx_headroom);
872 memcpy(resp->da, mgmt->sa, ETH_ALEN); 889 memcpy(skb_put(skb, presp->head_len), presp->head, presp->head_len);
873 ibss_dbg(sdata, "Sending ProbeResp to %pM\n", resp->da); 890
891 memcpy(((struct ieee80211_mgmt *) skb->data)->da, mgmt->sa, ETH_ALEN);
892 ibss_dbg(sdata, "Sending ProbeResp to %pM\n", mgmt->sa);
874 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 893 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
875 ieee80211_tx_skb(sdata, skb); 894 ieee80211_tx_skb(sdata, skb);
876} 895}
@@ -895,7 +914,7 @@ void ieee80211_rx_mgmt_probe_beacon(struct ieee80211_sub_if_data *sdata,
895 return; 914 return;
896 915
897 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, 916 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
898 &elems); 917 false, &elems);
899 918
900 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems); 919 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
901} 920}
@@ -985,36 +1004,9 @@ static void ieee80211_ibss_timer(unsigned long data)
985{ 1004{
986 struct ieee80211_sub_if_data *sdata = 1005 struct ieee80211_sub_if_data *sdata =
987 (struct ieee80211_sub_if_data *) data; 1006 (struct ieee80211_sub_if_data *) data;
988 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
989 struct ieee80211_local *local = sdata->local;
990
991 if (local->quiescing) {
992 ifibss->timer_running = true;
993 return;
994 }
995
996 ieee80211_queue_work(&local->hw, &sdata->work);
997}
998
999#ifdef CONFIG_PM
1000void ieee80211_ibss_quiesce(struct ieee80211_sub_if_data *sdata)
1001{
1002 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
1003 1007
1004 if (del_timer_sync(&ifibss->timer)) 1008 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
1005 ifibss->timer_running = true;
1006}
1007
1008void ieee80211_ibss_restart(struct ieee80211_sub_if_data *sdata)
1009{
1010 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
1011
1012 if (ifibss->timer_running) {
1013 add_timer(&ifibss->timer);
1014 ifibss->timer_running = false;
1015 }
1016} 1009}
1017#endif
1018 1010
1019void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata) 1011void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata)
1020{ 1012{
@@ -1047,23 +1039,8 @@ void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local)
1047int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata, 1039int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1048 struct cfg80211_ibss_params *params) 1040 struct cfg80211_ibss_params *params)
1049{ 1041{
1050 struct sk_buff *skb;
1051 u32 changed = 0; 1042 u32 changed = 0;
1052 1043
1053 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom +
1054 sizeof(struct ieee80211_hdr_3addr) +
1055 12 /* struct ieee80211_mgmt.u.beacon */ +
1056 2 + IEEE80211_MAX_SSID_LEN /* max SSID */ +
1057 2 + 8 /* max Supported Rates */ +
1058 3 /* max DS params */ +
1059 4 /* IBSS params */ +
1060 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
1061 2 + sizeof(struct ieee80211_ht_cap) +
1062 2 + sizeof(struct ieee80211_ht_operation) +
1063 params->ie_len);
1064 if (!skb)
1065 return -ENOMEM;
1066
1067 mutex_lock(&sdata->u.ibss.mtx); 1044 mutex_lock(&sdata->u.ibss.mtx);
1068 1045
1069 if (params->bssid) { 1046 if (params->bssid) {
@@ -1092,7 +1069,6 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1092 sdata->u.ibss.ie_len = params->ie_len; 1069 sdata->u.ibss.ie_len = params->ie_len;
1093 } 1070 }
1094 1071
1095 sdata->u.ibss.skb = skb;
1096 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH; 1072 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
1097 sdata->u.ibss.ibss_join_req = jiffies; 1073 sdata->u.ibss.ibss_join_req = jiffies;
1098 1074
@@ -1128,13 +1104,13 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1128 1104
1129int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata) 1105int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
1130{ 1106{
1131 struct sk_buff *skb;
1132 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 1107 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
1133 struct ieee80211_local *local = sdata->local; 1108 struct ieee80211_local *local = sdata->local;
1134 struct cfg80211_bss *cbss; 1109 struct cfg80211_bss *cbss;
1135 u16 capability; 1110 u16 capability;
1136 int active_ibss; 1111 int active_ibss;
1137 struct sta_info *sta; 1112 struct sta_info *sta;
1113 struct beacon_data *presp;
1138 1114
1139 mutex_lock(&sdata->u.ibss.mtx); 1115 mutex_lock(&sdata->u.ibss.mtx);
1140 1116
@@ -1180,17 +1156,18 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
1180 1156
1181 /* remove beacon */ 1157 /* remove beacon */
1182 kfree(sdata->u.ibss.ie); 1158 kfree(sdata->u.ibss.ie);
1183 skb = rcu_dereference_protected(sdata->u.ibss.presp, 1159 presp = rcu_dereference_protected(ifibss->presp,
1184 lockdep_is_held(&sdata->u.ibss.mtx)); 1160 lockdep_is_held(&sdata->u.ibss.mtx));
1185 RCU_INIT_POINTER(sdata->u.ibss.presp, NULL); 1161 RCU_INIT_POINTER(sdata->u.ibss.presp, NULL);
1186 sdata->vif.bss_conf.ibss_joined = false; 1162 sdata->vif.bss_conf.ibss_joined = false;
1187 sdata->vif.bss_conf.ibss_creator = false; 1163 sdata->vif.bss_conf.ibss_creator = false;
1188 sdata->vif.bss_conf.enable_beacon = false; 1164 sdata->vif.bss_conf.enable_beacon = false;
1165 sdata->vif.bss_conf.ssid_len = 0;
1189 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); 1166 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1190 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED | 1167 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
1191 BSS_CHANGED_IBSS); 1168 BSS_CHANGED_IBSS);
1192 synchronize_rcu(); 1169 synchronize_rcu();
1193 kfree_skb(skb); 1170 kfree(presp);
1194 1171
1195 skb_queue_purge(&sdata->skb_queue); 1172 skb_queue_purge(&sdata->skb_queue);
1196 1173
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 5672533a0832..158e6eb188d3 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -156,6 +156,7 @@ struct ieee80211_tx_data {
156 struct ieee80211_sub_if_data *sdata; 156 struct ieee80211_sub_if_data *sdata;
157 struct sta_info *sta; 157 struct sta_info *sta;
158 struct ieee80211_key *key; 158 struct ieee80211_key *key;
159 struct ieee80211_tx_rate rate;
159 160
160 unsigned int flags; 161 unsigned int flags;
161}; 162};
@@ -316,6 +317,7 @@ struct ieee80211_roc_work {
316 u32 duration, req_duration; 317 u32 duration, req_duration;
317 struct sk_buff *frame; 318 struct sk_buff *frame;
318 u64 cookie, mgmt_tx_cookie; 319 u64 cookie, mgmt_tx_cookie;
320 enum ieee80211_roc_type type;
319}; 321};
320 322
321/* flags used in struct ieee80211_if_managed.flags */ 323/* flags used in struct ieee80211_if_managed.flags */
@@ -401,7 +403,6 @@ struct ieee80211_if_managed {
401 403
402 u16 aid; 404 u16 aid;
403 405
404 unsigned long timers_running; /* used for quiesce/restart */
405 bool powersave; /* powersave requested for this iface */ 406 bool powersave; /* powersave requested for this iface */
406 bool broken_ap; /* AP is broken -- turn off powersave */ 407 bool broken_ap; /* AP is broken -- turn off powersave */
407 u8 dtim_period; 408 u8 dtim_period;
@@ -443,7 +444,7 @@ struct ieee80211_if_managed {
443 444
444 u8 use_4addr; 445 u8 use_4addr;
445 446
446 u8 p2p_noa_index; 447 s16 p2p_noa_index;
447 448
448 /* Signal strength from the last Beacon frame in the current BSS. */ 449 /* Signal strength from the last Beacon frame in the current BSS. */
449 int last_beacon_signal; 450 int last_beacon_signal;
@@ -480,6 +481,8 @@ struct ieee80211_if_managed {
480 481
481 struct ieee80211_ht_cap ht_capa; /* configured ht-cap over-rides */ 482 struct ieee80211_ht_cap ht_capa; /* configured ht-cap over-rides */
482 struct ieee80211_ht_cap ht_capa_mask; /* Valid parts of ht_capa */ 483 struct ieee80211_ht_cap ht_capa_mask; /* Valid parts of ht_capa */
484 struct ieee80211_vht_cap vht_capa; /* configured VHT overrides */
485 struct ieee80211_vht_cap vht_capa_mask; /* Valid parts of vht_capa */
483}; 486};
484 487
485struct ieee80211_if_ibss { 488struct ieee80211_if_ibss {
@@ -491,8 +494,6 @@ struct ieee80211_if_ibss {
491 494
492 u32 basic_rates; 495 u32 basic_rates;
493 496
494 bool timer_running;
495
496 bool fixed_bssid; 497 bool fixed_bssid;
497 bool fixed_channel; 498 bool fixed_channel;
498 bool privacy; 499 bool privacy;
@@ -509,8 +510,7 @@ struct ieee80211_if_ibss {
509 510
510 unsigned long ibss_join_req; 511 unsigned long ibss_join_req;
511 /* probe response/beacon for IBSS */ 512 /* probe response/beacon for IBSS */
512 struct sk_buff __rcu *presp; 513 struct beacon_data __rcu *presp;
513 struct sk_buff *skb;
514 514
515 spinlock_t incomplete_lock; 515 spinlock_t incomplete_lock;
516 struct list_head incomplete_stations; 516 struct list_head incomplete_stations;
@@ -544,8 +544,6 @@ struct ieee80211_if_mesh {
544 struct timer_list mesh_path_timer; 544 struct timer_list mesh_path_timer;
545 struct timer_list mesh_path_root_timer; 545 struct timer_list mesh_path_root_timer;
546 546
547 unsigned long timers_running;
548
549 unsigned long wrkq_flags; 547 unsigned long wrkq_flags;
550 548
551 u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN]; 549 u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN];
@@ -591,6 +589,7 @@ struct ieee80211_if_mesh {
591 IEEE80211_MESH_SEC_AUTHED = 0x1, 589 IEEE80211_MESH_SEC_AUTHED = 0x1,
592 IEEE80211_MESH_SEC_SECURED = 0x2, 590 IEEE80211_MESH_SEC_SECURED = 0x2,
593 } security; 591 } security;
592 bool user_mpm;
594 /* Extensible Synchronization Framework */ 593 /* Extensible Synchronization Framework */
595 const struct ieee80211_mesh_sync_ops *sync_ops; 594 const struct ieee80211_mesh_sync_ops *sync_ops;
596 s64 sync_offset_clockdrift_max; 595 s64 sync_offset_clockdrift_max;
@@ -683,6 +682,8 @@ struct ieee80211_sub_if_data {
683 682
684 /* count for keys needing tailroom space allocation */ 683 /* count for keys needing tailroom space allocation */
685 int crypto_tx_tailroom_needed_cnt; 684 int crypto_tx_tailroom_needed_cnt;
685 int crypto_tx_tailroom_pending_dec;
686 struct delayed_work dec_tailroom_needed_wk;
686 687
687 struct net_device *dev; 688 struct net_device *dev;
688 struct ieee80211_local *local; 689 struct ieee80211_local *local;
@@ -740,6 +741,8 @@ struct ieee80211_sub_if_data {
740 741
741 /* bitmap of allowed (non-MCS) rate indexes for rate control */ 742 /* bitmap of allowed (non-MCS) rate indexes for rate control */
742 u32 rc_rateidx_mask[IEEE80211_NUM_BANDS]; 743 u32 rc_rateidx_mask[IEEE80211_NUM_BANDS];
744
745 bool rc_has_mcs_mask[IEEE80211_NUM_BANDS];
743 u8 rc_rateidx_mcs_mask[IEEE80211_NUM_BANDS][IEEE80211_HT_MCS_MASK_LEN]; 746 u8 rc_rateidx_mcs_mask[IEEE80211_NUM_BANDS][IEEE80211_HT_MCS_MASK_LEN];
744 747
745 union { 748 union {
@@ -758,7 +761,6 @@ struct ieee80211_sub_if_data {
758 761
759#ifdef CONFIG_MAC80211_DEBUGFS 762#ifdef CONFIG_MAC80211_DEBUGFS
760 struct { 763 struct {
761 struct dentry *dir;
762 struct dentry *subdir_stations; 764 struct dentry *subdir_stations;
763 struct dentry *default_unicast_key; 765 struct dentry *default_unicast_key;
764 struct dentry *default_multicast_key; 766 struct dentry *default_multicast_key;
@@ -766,10 +768,6 @@ struct ieee80211_sub_if_data {
766 } debugfs; 768 } debugfs;
767#endif 769#endif
768 770
769#ifdef CONFIG_PM
770 struct ieee80211_bss_conf suspend_bss_conf;
771#endif
772
773 /* must be last, dynamically sized area in this! */ 771 /* must be last, dynamically sized area in this! */
774 struct ieee80211_vif vif; 772 struct ieee80211_vif vif;
775}; 773};
@@ -804,11 +802,6 @@ enum sdata_queue_type {
804enum { 802enum {
805 IEEE80211_RX_MSG = 1, 803 IEEE80211_RX_MSG = 1,
806 IEEE80211_TX_STATUS_MSG = 2, 804 IEEE80211_TX_STATUS_MSG = 2,
807 IEEE80211_EOSP_MSG = 3,
808};
809
810struct skb_eosp_msg_data {
811 u8 sta[ETH_ALEN], iface[ETH_ALEN];
812}; 805};
813 806
814enum queue_stop_reason { 807enum queue_stop_reason {
@@ -819,6 +812,7 @@ enum queue_stop_reason {
819 IEEE80211_QUEUE_STOP_REASON_SUSPEND, 812 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
820 IEEE80211_QUEUE_STOP_REASON_SKB_ADD, 813 IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
821 IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL, 814 IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL,
815 IEEE80211_QUEUE_STOP_REASON_FLUSH,
822}; 816};
823 817
824#ifdef CONFIG_MAC80211_LEDS 818#ifdef CONFIG_MAC80211_LEDS
@@ -1029,10 +1023,9 @@ struct ieee80211_local {
1029 enum mac80211_scan_state next_scan_state; 1023 enum mac80211_scan_state next_scan_state;
1030 struct delayed_work scan_work; 1024 struct delayed_work scan_work;
1031 struct ieee80211_sub_if_data __rcu *scan_sdata; 1025 struct ieee80211_sub_if_data __rcu *scan_sdata;
1032 struct ieee80211_channel *csa_channel; 1026 struct cfg80211_chan_def csa_chandef;
1033 /* For backward compatibility only -- do not use */ 1027 /* For backward compatibility only -- do not use */
1034 struct ieee80211_channel *_oper_channel; 1028 struct cfg80211_chan_def _oper_chandef;
1035 enum nl80211_channel_type _oper_channel_type;
1036 1029
1037 /* Temporary remain-on-channel for off-channel operations */ 1030 /* Temporary remain-on-channel for off-channel operations */
1038 struct ieee80211_channel *tmp_channel; 1031 struct ieee80211_channel *tmp_channel;
@@ -1137,11 +1130,6 @@ struct ieee80211_local {
1137 1130
1138 struct ieee80211_sub_if_data __rcu *p2p_sdata; 1131 struct ieee80211_sub_if_data __rcu *p2p_sdata;
1139 1132
1140 /* dummy netdev for use w/ NAPI */
1141 struct net_device napi_dev;
1142
1143 struct napi_struct napi;
1144
1145 /* virtual monitor interface */ 1133 /* virtual monitor interface */
1146 struct ieee80211_sub_if_data __rcu *monitor_sdata; 1134 struct ieee80211_sub_if_data __rcu *monitor_sdata;
1147 struct cfg80211_chan_def monitor_chandef; 1135 struct cfg80211_chan_def monitor_chandef;
@@ -1173,11 +1161,8 @@ struct ieee802_11_elems {
1173 /* pointers to IEs */ 1161 /* pointers to IEs */
1174 const u8 *ssid; 1162 const u8 *ssid;
1175 const u8 *supp_rates; 1163 const u8 *supp_rates;
1176 const u8 *fh_params;
1177 const u8 *ds_params; 1164 const u8 *ds_params;
1178 const u8 *cf_params;
1179 const struct ieee80211_tim_ie *tim; 1165 const struct ieee80211_tim_ie *tim;
1180 const u8 *ibss_params;
1181 const u8 *challenge; 1166 const u8 *challenge;
1182 const u8 *rsn; 1167 const u8 *rsn;
1183 const u8 *erp_info; 1168 const u8 *erp_info;
@@ -1197,23 +1182,20 @@ struct ieee802_11_elems {
1197 const u8 *perr; 1182 const u8 *perr;
1198 const struct ieee80211_rann_ie *rann; 1183 const struct ieee80211_rann_ie *rann;
1199 const struct ieee80211_channel_sw_ie *ch_switch_ie; 1184 const struct ieee80211_channel_sw_ie *ch_switch_ie;
1185 const struct ieee80211_ext_chansw_ie *ext_chansw_ie;
1186 const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
1200 const u8 *country_elem; 1187 const u8 *country_elem;
1201 const u8 *pwr_constr_elem; 1188 const u8 *pwr_constr_elem;
1202 const u8 *quiet_elem; /* first quite element */ 1189 const struct ieee80211_timeout_interval_ie *timeout_int;
1203 const u8 *timeout_int;
1204 const u8 *opmode_notif; 1190 const u8 *opmode_notif;
1191 const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1205 1192
1206 /* length of them, respectively */ 1193 /* length of them, respectively */
1207 u8 ssid_len; 1194 u8 ssid_len;
1208 u8 supp_rates_len; 1195 u8 supp_rates_len;
1209 u8 fh_params_len;
1210 u8 ds_params_len;
1211 u8 cf_params_len;
1212 u8 tim_len; 1196 u8 tim_len;
1213 u8 ibss_params_len;
1214 u8 challenge_len; 1197 u8 challenge_len;
1215 u8 rsn_len; 1198 u8 rsn_len;
1216 u8 erp_info_len;
1217 u8 ext_supp_rates_len; 1199 u8 ext_supp_rates_len;
1218 u8 wmm_info_len; 1200 u8 wmm_info_len;
1219 u8 wmm_param_len; 1201 u8 wmm_param_len;
@@ -1223,9 +1205,6 @@ struct ieee802_11_elems {
1223 u8 prep_len; 1205 u8 prep_len;
1224 u8 perr_len; 1206 u8 perr_len;
1225 u8 country_elem_len; 1207 u8 country_elem_len;
1226 u8 quiet_elem_len;
1227 u8 num_of_quiet_elem; /* can be more the one */
1228 u8 timeout_int_len;
1229 1208
1230 /* whether a parse error occurred while retrieving these elements */ 1209 /* whether a parse error occurred while retrieving these elements */
1231 bool parse_error; 1210 bool parse_error;
@@ -1280,12 +1259,6 @@ void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata);
1280int ieee80211_max_network_latency(struct notifier_block *nb, 1259int ieee80211_max_network_latency(struct notifier_block *nb,
1281 unsigned long data, void *dummy); 1260 unsigned long data, void *dummy);
1282int ieee80211_set_arp_filter(struct ieee80211_sub_if_data *sdata); 1261int ieee80211_set_arp_filter(struct ieee80211_sub_if_data *sdata);
1283void
1284ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1285 const struct ieee80211_channel_sw_ie *sw_elem,
1286 struct ieee80211_bss *bss, u64 timestamp);
1287void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata);
1288void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata);
1289void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata); 1262void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata);
1290void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, 1263void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1291 struct sk_buff *skb); 1264 struct sk_buff *skb);
@@ -1303,8 +1276,6 @@ void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata,
1303int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata, 1276int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1304 struct cfg80211_ibss_params *params); 1277 struct cfg80211_ibss_params *params);
1305int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata); 1278int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata);
1306void ieee80211_ibss_quiesce(struct ieee80211_sub_if_data *sdata);
1307void ieee80211_ibss_restart(struct ieee80211_sub_if_data *sdata);
1308void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata); 1279void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata);
1309void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, 1280void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1310 struct sk_buff *skb); 1281 struct sk_buff *skb);
@@ -1347,7 +1318,8 @@ void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local);
1347void ieee80211_offchannel_return(struct ieee80211_local *local); 1318void ieee80211_offchannel_return(struct ieee80211_local *local);
1348void ieee80211_roc_setup(struct ieee80211_local *local); 1319void ieee80211_roc_setup(struct ieee80211_local *local);
1349void ieee80211_start_next_roc(struct ieee80211_local *local); 1320void ieee80211_start_next_roc(struct ieee80211_local *local);
1350void ieee80211_roc_purge(struct ieee80211_sub_if_data *sdata); 1321void ieee80211_roc_purge(struct ieee80211_local *local,
1322 struct ieee80211_sub_if_data *sdata);
1351void ieee80211_roc_notify_destroy(struct ieee80211_roc_work *roc, bool free); 1323void ieee80211_roc_notify_destroy(struct ieee80211_roc_work *roc, bool free);
1352void ieee80211_sw_roc_work(struct work_struct *work); 1324void ieee80211_sw_roc_work(struct work_struct *work);
1353void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc); 1325void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc);
@@ -1368,6 +1340,8 @@ void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata,
1368 const int offset); 1340 const int offset);
1369int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up); 1341int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up);
1370void ieee80211_sdata_stop(struct ieee80211_sub_if_data *sdata); 1342void ieee80211_sdata_stop(struct ieee80211_sub_if_data *sdata);
1343int ieee80211_add_virtual_monitor(struct ieee80211_local *local);
1344void ieee80211_del_virtual_monitor(struct ieee80211_local *local);
1371 1345
1372bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata); 1346bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata);
1373void ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata); 1347void ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata);
@@ -1443,6 +1417,8 @@ void ieee80211_sta_set_rx_nss(struct sta_info *sta);
1443void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata, 1417void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
1444 struct sta_info *sta, u8 opmode, 1418 struct sta_info *sta, u8 opmode,
1445 enum ieee80211_band band, bool nss_only); 1419 enum ieee80211_band band, bool nss_only);
1420void ieee80211_apply_vhtcap_overrides(struct ieee80211_sub_if_data *sdata,
1421 struct ieee80211_sta_vht_cap *vht_cap);
1446 1422
1447/* Spectrum management */ 1423/* Spectrum management */
1448void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata, 1424void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata,
@@ -1520,11 +1496,15 @@ static inline void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata,
1520 ieee80211_tx_skb_tid(sdata, skb, 7); 1496 ieee80211_tx_skb_tid(sdata, skb, 7);
1521} 1497}
1522 1498
1523void ieee802_11_parse_elems(u8 *start, size_t len, 1499u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, bool action,
1524 struct ieee802_11_elems *elems);
1525u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
1526 struct ieee802_11_elems *elems, 1500 struct ieee802_11_elems *elems,
1527 u64 filter, u32 crc); 1501 u64 filter, u32 crc);
1502static inline void ieee802_11_parse_elems(u8 *start, size_t len, bool action,
1503 struct ieee802_11_elems *elems)
1504{
1505 ieee802_11_parse_elems_crc(start, len, action, elems, 0, 0);
1506}
1507
1528u32 ieee80211_mandatory_rates(struct ieee80211_local *local, 1508u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
1529 enum ieee80211_band band); 1509 enum ieee80211_band band);
1530 1510
@@ -1540,8 +1520,10 @@ void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
1540 struct ieee80211_hdr *hdr, bool ack); 1520 struct ieee80211_hdr *hdr, bool ack);
1541 1521
1542void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw, 1522void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
1523 unsigned long queues,
1543 enum queue_stop_reason reason); 1524 enum queue_stop_reason reason);
1544void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw, 1525void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
1526 unsigned long queues,
1545 enum queue_stop_reason reason); 1527 enum queue_stop_reason reason);
1546void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue, 1528void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
1547 enum queue_stop_reason reason); 1529 enum queue_stop_reason reason);
@@ -1558,6 +1540,8 @@ static inline void ieee80211_add_pending_skbs(struct ieee80211_local *local,
1558{ 1540{
1559 ieee80211_add_pending_skbs_fn(local, skbs, NULL, NULL); 1541 ieee80211_add_pending_skbs_fn(local, skbs, NULL, NULL);
1560} 1542}
1543void ieee80211_flush_queues(struct ieee80211_local *local,
1544 struct ieee80211_sub_if_data *sdata);
1561 1545
1562void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, 1546void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
1563 u16 transaction, u16 auth_alg, u16 status, 1547 u16 transaction, u16 auth_alg, u16 status,
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 9ed49ad0380f..60f1ce5e5e52 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Interface handling (except master interface) 2 * Interface handling
3 * 3 *
4 * Copyright 2002-2005, Instant802 Networks, Inc. 4 * Copyright 2002-2005, Instant802 Networks, Inc.
5 * Copyright 2005-2006, Devicescape Software, Inc. 5 * Copyright 2005-2006, Devicescape Software, Inc.
@@ -92,7 +92,7 @@ static u32 __ieee80211_idle_on(struct ieee80211_local *local)
92 if (local->hw.conf.flags & IEEE80211_CONF_IDLE) 92 if (local->hw.conf.flags & IEEE80211_CONF_IDLE)
93 return 0; 93 return 0;
94 94
95 drv_flush(local, false); 95 ieee80211_flush_queues(local, NULL);
96 96
97 local->hw.conf.flags |= IEEE80211_CONF_IDLE; 97 local->hw.conf.flags |= IEEE80211_CONF_IDLE;
98 return IEEE80211_CONF_CHANGE_IDLE; 98 return IEEE80211_CONF_CHANGE_IDLE;
@@ -357,7 +357,7 @@ static void ieee80211_set_default_queues(struct ieee80211_sub_if_data *sdata)
357 sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE; 357 sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE;
358} 358}
359 359
360static int ieee80211_add_virtual_monitor(struct ieee80211_local *local) 360int ieee80211_add_virtual_monitor(struct ieee80211_local *local)
361{ 361{
362 struct ieee80211_sub_if_data *sdata; 362 struct ieee80211_sub_if_data *sdata;
363 int ret; 363 int ret;
@@ -410,7 +410,7 @@ static int ieee80211_add_virtual_monitor(struct ieee80211_local *local)
410 return 0; 410 return 0;
411} 411}
412 412
413static void ieee80211_del_virtual_monitor(struct ieee80211_local *local) 413void ieee80211_del_virtual_monitor(struct ieee80211_local *local)
414{ 414{
415 struct ieee80211_sub_if_data *sdata; 415 struct ieee80211_sub_if_data *sdata;
416 416
@@ -499,8 +499,6 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
499 res = drv_start(local); 499 res = drv_start(local);
500 if (res) 500 if (res)
501 goto err_del_bss; 501 goto err_del_bss;
502 if (local->ops->napi_poll)
503 napi_enable(&local->napi);
504 /* we're brought up, everything changes */ 502 /* we're brought up, everything changes */
505 hw_reconf_flags = ~0; 503 hw_reconf_flags = ~0;
506 ieee80211_led_radio(local, true); 504 ieee80211_led_radio(local, true);
@@ -573,8 +571,6 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
573 goto err_del_interface; 571 goto err_del_interface;
574 } 572 }
575 573
576 drv_add_interface_debugfs(local, sdata);
577
578 if (sdata->vif.type == NL80211_IFTYPE_AP) { 574 if (sdata->vif.type == NL80211_IFTYPE_AP) {
579 local->fif_pspoll++; 575 local->fif_pspoll++;
580 local->fif_probe_req++; 576 local->fif_probe_req++;
@@ -599,7 +595,8 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
599 case NL80211_IFTYPE_P2P_DEVICE: 595 case NL80211_IFTYPE_P2P_DEVICE:
600 break; 596 break;
601 default: 597 default:
602 netif_carrier_on(dev); 598 /* not reached */
599 WARN_ON(1);
603 } 600 }
604 601
605 /* 602 /*
@@ -656,8 +653,28 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
656 653
657 ieee80211_recalc_ps(local, -1); 654 ieee80211_recalc_ps(local, -1);
658 655
659 if (dev) 656 if (dev) {
660 netif_tx_start_all_queues(dev); 657 unsigned long flags;
658 int n_acs = IEEE80211_NUM_ACS;
659 int ac;
660
661 if (local->hw.queues < IEEE80211_NUM_ACS)
662 n_acs = 1;
663
664 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
665 if (sdata->vif.cab_queue == IEEE80211_INVAL_HW_QUEUE ||
666 (local->queue_stop_reasons[sdata->vif.cab_queue] == 0 &&
667 skb_queue_empty(&local->pending[sdata->vif.cab_queue]))) {
668 for (ac = 0; ac < n_acs; ac++) {
669 int ac_queue = sdata->vif.hw_queue[ac];
670
671 if (local->queue_stop_reasons[ac_queue] == 0 &&
672 skb_queue_empty(&local->pending[ac_queue]))
673 netif_start_subqueue(dev, ac);
674 }
675 }
676 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
677 }
661 678
662 return 0; 679 return 0;
663 err_del_interface: 680 err_del_interface:
@@ -711,7 +728,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
711 if (sdata->dev) 728 if (sdata->dev)
712 netif_tx_stop_all_queues(sdata->dev); 729 netif_tx_stop_all_queues(sdata->dev);
713 730
714 ieee80211_roc_purge(sdata); 731 ieee80211_roc_purge(local, sdata);
715 732
716 if (sdata->vif.type == NL80211_IFTYPE_STATION) 733 if (sdata->vif.type == NL80211_IFTYPE_STATION)
717 ieee80211_mgd_stop(sdata); 734 ieee80211_mgd_stop(sdata);
@@ -736,12 +753,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
736 WARN_ON_ONCE((sdata->vif.type != NL80211_IFTYPE_WDS && flushed > 0) || 753 WARN_ON_ONCE((sdata->vif.type != NL80211_IFTYPE_WDS && flushed > 0) ||
737 (sdata->vif.type == NL80211_IFTYPE_WDS && flushed != 1)); 754 (sdata->vif.type == NL80211_IFTYPE_WDS && flushed != 1));
738 755
739 /* 756 /* don't count this interface for promisc/allmulti while it is down */
740 * Don't count this interface for promisc/allmulti while it
741 * is down. dev_mc_unsync() will invoke set_multicast_list
742 * on the master interface which will sync these down to the
743 * hardware as filter flags.
744 */
745 if (sdata->flags & IEEE80211_SDATA_ALLMULTI) 757 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
746 atomic_dec(&local->iff_allmultis); 758 atomic_dec(&local->iff_allmultis);
747 759
@@ -762,8 +774,6 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
762 sdata->dev->addr_len); 774 sdata->dev->addr_len);
763 spin_unlock_bh(&local->filter_lock); 775 spin_unlock_bh(&local->filter_lock);
764 netif_addr_unlock_bh(sdata->dev); 776 netif_addr_unlock_bh(sdata->dev);
765
766 ieee80211_configure_filter(local);
767 } 777 }
768 778
769 del_timer_sync(&local->dynamic_ps_timer); 779 del_timer_sync(&local->dynamic_ps_timer);
@@ -774,6 +784,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
774 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work); 784 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
775 785
776 if (sdata->wdev.cac_started) { 786 if (sdata->wdev.cac_started) {
787 WARN_ON(local->suspended);
777 mutex_lock(&local->iflist_mtx); 788 mutex_lock(&local->iflist_mtx);
778 ieee80211_vif_release_channel(sdata); 789 ieee80211_vif_release_channel(sdata);
779 mutex_unlock(&local->iflist_mtx); 790 mutex_unlock(&local->iflist_mtx);
@@ -824,14 +835,9 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
824 if (local->monitors == 0) { 835 if (local->monitors == 0) {
825 local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR; 836 local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
826 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; 837 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
827 ieee80211_del_virtual_monitor(local);
828 } 838 }
829 839
830 ieee80211_adjust_monitor_flags(sdata, -1); 840 ieee80211_adjust_monitor_flags(sdata, -1);
831 ieee80211_configure_filter(local);
832 mutex_lock(&local->mtx);
833 ieee80211_recalc_idle(local);
834 mutex_unlock(&local->mtx);
835 break; 841 break;
836 case NL80211_IFTYPE_P2P_DEVICE: 842 case NL80211_IFTYPE_P2P_DEVICE:
837 /* relies on synchronize_rcu() below */ 843 /* relies on synchronize_rcu() below */
@@ -844,46 +850,28 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
844 * 850 *
845 * sta_info_flush_cleanup() requires rcu_barrier() 851 * sta_info_flush_cleanup() requires rcu_barrier()
846 * first to wait for the station call_rcu() calls 852 * first to wait for the station call_rcu() calls
847 * to complete, here we need at least sychronize_rcu() 853 * to complete, and we also need synchronize_rcu()
848 * it to wait for the RX path in case it is using the 854 * to wait for the RX path in case it is using the
849 * interface and enqueuing frames at this very time on 855 * interface and enqueuing frames at this very time on
850 * another CPU. 856 * another CPU.
851 */ 857 */
858 synchronize_rcu();
852 rcu_barrier(); 859 rcu_barrier();
853 sta_info_flush_cleanup(sdata); 860 sta_info_flush_cleanup(sdata);
854 861
855 skb_queue_purge(&sdata->skb_queue);
856
857 /* 862 /*
858 * Free all remaining keys, there shouldn't be any, 863 * Free all remaining keys, there shouldn't be any,
859 * except maybe group keys in AP more or WDS? 864 * except maybe in WDS mode?
860 */ 865 */
861 ieee80211_free_keys(sdata); 866 ieee80211_free_keys(sdata);
862 867
863 drv_remove_interface_debugfs(local, sdata); 868 /* fall through */
864 869 case NL80211_IFTYPE_AP:
865 if (going_down) 870 skb_queue_purge(&sdata->skb_queue);
866 drv_remove_interface(local, sdata);
867 } 871 }
868 872
869 sdata->bss = NULL; 873 sdata->bss = NULL;
870 874
871 ieee80211_recalc_ps(local, -1);
872
873 if (local->open_count == 0) {
874 if (local->ops->napi_poll)
875 napi_disable(&local->napi);
876 ieee80211_clear_tx_pending(local);
877 ieee80211_stop_device(local);
878
879 /* no reconfiguring after stop! */
880 hw_reconf_flags = 0;
881 }
882
883 /* do after stop to avoid reconfiguring when we stop anyway */
884 if (hw_reconf_flags)
885 ieee80211_hw_config(local, hw_reconf_flags);
886
887 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 875 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
888 for (i = 0; i < IEEE80211_MAX_QUEUES; i++) { 876 for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
889 skb_queue_walk_safe(&local->pending[i], skb, tmp) { 877 skb_queue_walk_safe(&local->pending[i], skb, tmp) {
@@ -896,7 +884,54 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
896 } 884 }
897 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 885 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
898 886
899 if (local->monitors == local->open_count && local->monitors > 0) 887 if (local->open_count == 0)
888 ieee80211_clear_tx_pending(local);
889
890 /*
891 * If the interface goes down while suspended, presumably because
892 * the device was unplugged and that happens before our resume,
893 * then the driver is already unconfigured and the remainder of
894 * this function isn't needed.
895 * XXX: what about WoWLAN? If the device has software state, e.g.
896 * memory allocated, it might expect teardown commands from
897 * mac80211 here?
898 */
899 if (local->suspended) {
900 WARN_ON(local->wowlan);
901 WARN_ON(rtnl_dereference(local->monitor_sdata));
902 return;
903 }
904
905 switch (sdata->vif.type) {
906 case NL80211_IFTYPE_AP_VLAN:
907 break;
908 case NL80211_IFTYPE_MONITOR:
909 if (local->monitors == 0)
910 ieee80211_del_virtual_monitor(local);
911
912 mutex_lock(&local->mtx);
913 ieee80211_recalc_idle(local);
914 mutex_unlock(&local->mtx);
915 break;
916 default:
917 if (going_down)
918 drv_remove_interface(local, sdata);
919 }
920
921 ieee80211_recalc_ps(local, -1);
922
923 if (local->open_count == 0) {
924 ieee80211_stop_device(local);
925
926 /* no reconfiguring after stop! */
927 return;
928 }
929
930 /* do after stop to avoid reconfiguring when we stop anyway */
931 ieee80211_configure_filter(local);
932 ieee80211_hw_config(local, hw_reconf_flags);
933
934 if (local->monitors == local->open_count)
900 ieee80211_add_virtual_monitor(local); 935 ieee80211_add_virtual_monitor(local);
901} 936}
902 937
@@ -935,6 +970,17 @@ static void ieee80211_set_multicast_list(struct net_device *dev)
935 atomic_dec(&local->iff_promiscs); 970 atomic_dec(&local->iff_promiscs);
936 sdata->flags ^= IEEE80211_SDATA_PROMISC; 971 sdata->flags ^= IEEE80211_SDATA_PROMISC;
937 } 972 }
973
974 /*
975 * TODO: If somebody needs this on AP interfaces,
976 * it can be enabled easily but multicast
977 * addresses from VLANs need to be synced.
978 */
979 if (sdata->vif.type != NL80211_IFTYPE_MONITOR &&
980 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
981 sdata->vif.type != NL80211_IFTYPE_AP)
982 drv_set_multicast_list(local, sdata, &dev->mc);
983
938 spin_lock_bh(&local->filter_lock); 984 spin_lock_bh(&local->filter_lock);
939 __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len); 985 __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len);
940 spin_unlock_bh(&local->filter_lock); 986 spin_unlock_bh(&local->filter_lock);
@@ -1561,6 +1607,8 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
1561 INIT_WORK(&sdata->cleanup_stations_wk, ieee80211_cleanup_sdata_stas_wk); 1607 INIT_WORK(&sdata->cleanup_stations_wk, ieee80211_cleanup_sdata_stas_wk);
1562 INIT_DELAYED_WORK(&sdata->dfs_cac_timer_work, 1608 INIT_DELAYED_WORK(&sdata->dfs_cac_timer_work,
1563 ieee80211_dfs_cac_timer_work); 1609 ieee80211_dfs_cac_timer_work);
1610 INIT_DELAYED_WORK(&sdata->dec_tailroom_needed_wk,
1611 ieee80211_delayed_tailroom_dec);
1564 1612
1565 for (i = 0; i < IEEE80211_NUM_BANDS; i++) { 1613 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
1566 struct ieee80211_supported_band *sband; 1614 struct ieee80211_supported_band *sband;
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index ef252eb58c36..67059b88fea5 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -248,11 +248,11 @@ void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata,
248} 248}
249 249
250 250
251static void __ieee80211_key_replace(struct ieee80211_sub_if_data *sdata, 251static void ieee80211_key_replace(struct ieee80211_sub_if_data *sdata,
252 struct sta_info *sta, 252 struct sta_info *sta,
253 bool pairwise, 253 bool pairwise,
254 struct ieee80211_key *old, 254 struct ieee80211_key *old,
255 struct ieee80211_key *new) 255 struct ieee80211_key *new)
256{ 256{
257 int idx; 257 int idx;
258 bool defunikey, defmultikey, defmgmtkey; 258 bool defunikey, defmultikey, defmgmtkey;
@@ -397,7 +397,41 @@ struct ieee80211_key *ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
397 return key; 397 return key;
398} 398}
399 399
400static void __ieee80211_key_destroy(struct ieee80211_key *key) 400static void ieee80211_key_free_common(struct ieee80211_key *key)
401{
402 if (key->conf.cipher == WLAN_CIPHER_SUITE_CCMP)
403 ieee80211_aes_key_free(key->u.ccmp.tfm);
404 if (key->conf.cipher == WLAN_CIPHER_SUITE_AES_CMAC)
405 ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm);
406 kfree(key);
407}
408
409static void __ieee80211_key_destroy(struct ieee80211_key *key,
410 bool delay_tailroom)
411{
412 if (key->local)
413 ieee80211_key_disable_hw_accel(key);
414
415 if (key->local) {
416 struct ieee80211_sub_if_data *sdata = key->sdata;
417
418 ieee80211_debugfs_key_remove(key);
419
420 if (delay_tailroom) {
421 /* see ieee80211_delayed_tailroom_dec */
422 sdata->crypto_tx_tailroom_pending_dec++;
423 schedule_delayed_work(&sdata->dec_tailroom_needed_wk,
424 HZ/2);
425 } else {
426 sdata->crypto_tx_tailroom_needed_cnt--;
427 }
428 }
429
430 ieee80211_key_free_common(key);
431}
432
433static void ieee80211_key_destroy(struct ieee80211_key *key,
434 bool delay_tailroom)
401{ 435{
402 if (!key) 436 if (!key)
403 return; 437 return;
@@ -408,19 +442,13 @@ static void __ieee80211_key_destroy(struct ieee80211_key *key)
408 */ 442 */
409 synchronize_net(); 443 synchronize_net();
410 444
411 if (key->local) 445 __ieee80211_key_destroy(key, delay_tailroom);
412 ieee80211_key_disable_hw_accel(key); 446}
413
414 if (key->conf.cipher == WLAN_CIPHER_SUITE_CCMP)
415 ieee80211_aes_key_free(key->u.ccmp.tfm);
416 if (key->conf.cipher == WLAN_CIPHER_SUITE_AES_CMAC)
417 ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm);
418 if (key->local) {
419 ieee80211_debugfs_key_remove(key);
420 key->sdata->crypto_tx_tailroom_needed_cnt--;
421 }
422 447
423 kfree(key); 448void ieee80211_key_free_unused(struct ieee80211_key *key)
449{
450 WARN_ON(key->sdata || key->local);
451 ieee80211_key_free_common(key);
424} 452}
425 453
426int ieee80211_key_link(struct ieee80211_key *key, 454int ieee80211_key_link(struct ieee80211_key *key,
@@ -440,32 +468,6 @@ int ieee80211_key_link(struct ieee80211_key *key,
440 key->sdata = sdata; 468 key->sdata = sdata;
441 key->sta = sta; 469 key->sta = sta;
442 470
443 if (sta) {
444 /*
445 * some hardware cannot handle TKIP with QoS, so
446 * we indicate whether QoS could be in use.
447 */
448 if (test_sta_flag(sta, WLAN_STA_WME))
449 key->conf.flags |= IEEE80211_KEY_FLAG_WMM_STA;
450 } else {
451 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
452 struct sta_info *ap;
453
454 /*
455 * We're getting a sta pointer in, so must be under
456 * appropriate locking for sta_info_get().
457 */
458
459 /* same here, the AP could be using QoS */
460 ap = sta_info_get(key->sdata, key->sdata->u.mgd.bssid);
461 if (ap) {
462 if (test_sta_flag(ap, WLAN_STA_WME))
463 key->conf.flags |=
464 IEEE80211_KEY_FLAG_WMM_STA;
465 }
466 }
467 }
468
469 mutex_lock(&sdata->local->key_mtx); 471 mutex_lock(&sdata->local->key_mtx);
470 472
471 if (sta && pairwise) 473 if (sta && pairwise)
@@ -477,19 +479,22 @@ int ieee80211_key_link(struct ieee80211_key *key,
477 479
478 increment_tailroom_need_count(sdata); 480 increment_tailroom_need_count(sdata);
479 481
480 __ieee80211_key_replace(sdata, sta, pairwise, old_key, key); 482 ieee80211_key_replace(sdata, sta, pairwise, old_key, key);
481 __ieee80211_key_destroy(old_key); 483 ieee80211_key_destroy(old_key, true);
482 484
483 ieee80211_debugfs_key_add(key); 485 ieee80211_debugfs_key_add(key);
484 486
485 ret = ieee80211_key_enable_hw_accel(key); 487 ret = ieee80211_key_enable_hw_accel(key);
486 488
489 if (ret)
490 ieee80211_key_free(key, true);
491
487 mutex_unlock(&sdata->local->key_mtx); 492 mutex_unlock(&sdata->local->key_mtx);
488 493
489 return ret; 494 return ret;
490} 495}
491 496
492void __ieee80211_key_free(struct ieee80211_key *key) 497void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom)
493{ 498{
494 if (!key) 499 if (!key)
495 return; 500 return;
@@ -498,18 +503,10 @@ void __ieee80211_key_free(struct ieee80211_key *key)
498 * Replace key with nothingness if it was ever used. 503 * Replace key with nothingness if it was ever used.
499 */ 504 */
500 if (key->sdata) 505 if (key->sdata)
501 __ieee80211_key_replace(key->sdata, key->sta, 506 ieee80211_key_replace(key->sdata, key->sta,
502 key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE, 507 key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
503 key, NULL); 508 key, NULL);
504 __ieee80211_key_destroy(key); 509 ieee80211_key_destroy(key, delay_tailroom);
505}
506
507void ieee80211_key_free(struct ieee80211_local *local,
508 struct ieee80211_key *key)
509{
510 mutex_lock(&local->key_mtx);
511 __ieee80211_key_free(key);
512 mutex_unlock(&local->key_mtx);
513} 510}
514 511
515void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata) 512void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
@@ -566,36 +563,109 @@ void ieee80211_iter_keys(struct ieee80211_hw *hw,
566} 563}
567EXPORT_SYMBOL(ieee80211_iter_keys); 564EXPORT_SYMBOL(ieee80211_iter_keys);
568 565
569void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata) 566void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata)
570{ 567{
571 struct ieee80211_key *key; 568 struct ieee80211_key *key, *tmp;
569 LIST_HEAD(keys);
572 570
573 ASSERT_RTNL(); 571 cancel_delayed_work_sync(&sdata->dec_tailroom_needed_wk);
574 572
575 mutex_lock(&sdata->local->key_mtx); 573 mutex_lock(&sdata->local->key_mtx);
576 574
577 list_for_each_entry(key, &sdata->key_list, list) 575 sdata->crypto_tx_tailroom_needed_cnt -=
578 ieee80211_key_disable_hw_accel(key); 576 sdata->crypto_tx_tailroom_pending_dec;
577 sdata->crypto_tx_tailroom_pending_dec = 0;
578
579 ieee80211_debugfs_key_remove_mgmt_default(sdata);
580
581 list_for_each_entry_safe(key, tmp, &sdata->key_list, list) {
582 ieee80211_key_replace(key->sdata, key->sta,
583 key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
584 key, NULL);
585 list_add_tail(&key->list, &keys);
586 }
587
588 ieee80211_debugfs_key_update_default(sdata);
589
590 if (!list_empty(&keys)) {
591 synchronize_net();
592 list_for_each_entry_safe(key, tmp, &keys, list)
593 __ieee80211_key_destroy(key, false);
594 }
595
596 WARN_ON_ONCE(sdata->crypto_tx_tailroom_needed_cnt ||
597 sdata->crypto_tx_tailroom_pending_dec);
579 598
580 mutex_unlock(&sdata->local->key_mtx); 599 mutex_unlock(&sdata->local->key_mtx);
581} 600}
582 601
583void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata) 602void ieee80211_free_sta_keys(struct ieee80211_local *local,
603 struct sta_info *sta)
584{ 604{
585 struct ieee80211_key *key, *tmp; 605 struct ieee80211_key *key, *tmp;
606 LIST_HEAD(keys);
607 int i;
586 608
587 mutex_lock(&sdata->local->key_mtx); 609 mutex_lock(&local->key_mtx);
610 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
611 key = key_mtx_dereference(local, sta->gtk[i]);
612 if (!key)
613 continue;
614 ieee80211_key_replace(key->sdata, key->sta,
615 key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
616 key, NULL);
617 list_add(&key->list, &keys);
618 }
588 619
589 ieee80211_debugfs_key_remove_mgmt_default(sdata); 620 key = key_mtx_dereference(local, sta->ptk);
621 if (key) {
622 ieee80211_key_replace(key->sdata, key->sta,
623 key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
624 key, NULL);
625 list_add(&key->list, &keys);
626 }
590 627
591 list_for_each_entry_safe(key, tmp, &sdata->key_list, list) 628 /*
592 __ieee80211_key_free(key); 629 * NB: the station code relies on this being
630 * done even if there aren't any keys
631 */
632 synchronize_net();
593 633
594 ieee80211_debugfs_key_update_default(sdata); 634 list_for_each_entry_safe(key, tmp, &keys, list)
635 __ieee80211_key_destroy(key, true);
595 636
596 mutex_unlock(&sdata->local->key_mtx); 637 mutex_unlock(&local->key_mtx);
597} 638}
598 639
640void ieee80211_delayed_tailroom_dec(struct work_struct *wk)
641{
642 struct ieee80211_sub_if_data *sdata;
643
644 sdata = container_of(wk, struct ieee80211_sub_if_data,
645 dec_tailroom_needed_wk.work);
646
647 /*
648 * The reason for the delayed tailroom needed decrementing is to
649 * make roaming faster: during roaming, all keys are first deleted
650 * and then new keys are installed. The first new key causes the
651 * crypto_tx_tailroom_needed_cnt to go from 0 to 1, which invokes
652 * the cost of synchronize_net() (which can be slow). Avoid this
653 * by deferring the crypto_tx_tailroom_needed_cnt decrementing on
654 * key removal for a while, so if we roam the value is larger than
655 * zero and no 0->1 transition happens.
656 *
657 * The cost is that if the AP switching was from an AP with keys
658 * to one without, we still allocate tailroom while it would no
659 * longer be needed. However, in the typical (fast) roaming case
660 * within an ESS this usually won't happen.
661 */
662
663 mutex_lock(&sdata->local->key_mtx);
664 sdata->crypto_tx_tailroom_needed_cnt -=
665 sdata->crypto_tx_tailroom_pending_dec;
666 sdata->crypto_tx_tailroom_pending_dec = 0;
667 mutex_unlock(&sdata->local->key_mtx);
668}
599 669
600void ieee80211_gtk_rekey_notify(struct ieee80211_vif *vif, const u8 *bssid, 670void ieee80211_gtk_rekey_notify(struct ieee80211_vif *vif, const u8 *bssid,
601 const u8 *replay_ctr, gfp_t gfp) 671 const u8 *replay_ctr, gfp_t gfp)
diff --git a/net/mac80211/key.h b/net/mac80211/key.h
index 382dc44ed330..e8de3e6d7804 100644
--- a/net/mac80211/key.h
+++ b/net/mac80211/key.h
@@ -129,23 +129,25 @@ struct ieee80211_key *ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
129 size_t seq_len, const u8 *seq); 129 size_t seq_len, const u8 *seq);
130/* 130/*
131 * Insert a key into data structures (sdata, sta if necessary) 131 * Insert a key into data structures (sdata, sta if necessary)
132 * to make it used, free old key. 132 * to make it used, free old key. On failure, also free the new key.
133 */ 133 */
134int __must_check ieee80211_key_link(struct ieee80211_key *key, 134int ieee80211_key_link(struct ieee80211_key *key,
135 struct ieee80211_sub_if_data *sdata, 135 struct ieee80211_sub_if_data *sdata,
136 struct sta_info *sta); 136 struct sta_info *sta);
137void __ieee80211_key_free(struct ieee80211_key *key); 137void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom);
138void ieee80211_key_free(struct ieee80211_local *local, 138void ieee80211_key_free_unused(struct ieee80211_key *key);
139 struct ieee80211_key *key);
140void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx, 139void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx,
141 bool uni, bool multi); 140 bool uni, bool multi);
142void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata, 141void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata,
143 int idx); 142 int idx);
144void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata); 143void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata);
144void ieee80211_free_sta_keys(struct ieee80211_local *local,
145 struct sta_info *sta);
145void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata); 146void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata);
146void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata);
147 147
148#define key_mtx_dereference(local, ref) \ 148#define key_mtx_dereference(local, ref) \
149 rcu_dereference_protected(ref, lockdep_is_held(&((local)->key_mtx))) 149 rcu_dereference_protected(ref, lockdep_is_held(&((local)->key_mtx)))
150 150
151void ieee80211_delayed_tailroom_dec(struct work_struct *wk);
152
151#endif /* IEEE80211_KEY_H */ 153#endif /* IEEE80211_KEY_H */
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 1a8591b77a13..8a7bfc47d577 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -95,43 +95,47 @@ static void ieee80211_reconfig_filter(struct work_struct *work)
95static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local) 95static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
96{ 96{
97 struct ieee80211_sub_if_data *sdata; 97 struct ieee80211_sub_if_data *sdata;
98 struct ieee80211_channel *chan; 98 struct cfg80211_chan_def chandef = {};
99 u32 changed = 0; 99 u32 changed = 0;
100 int power; 100 int power;
101 enum nl80211_channel_type channel_type;
102 u32 offchannel_flag; 101 u32 offchannel_flag;
103 bool scanning = false;
104 102
105 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL; 103 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
104
106 if (local->scan_channel) { 105 if (local->scan_channel) {
107 chan = local->scan_channel; 106 chandef.chan = local->scan_channel;
108 /* If scanning on oper channel, use whatever channel-type 107 /* If scanning on oper channel, use whatever channel-type
109 * is currently in use. 108 * is currently in use.
110 */ 109 */
111 if (chan == local->_oper_channel) 110 if (chandef.chan == local->_oper_chandef.chan) {
112 channel_type = local->_oper_channel_type; 111 chandef = local->_oper_chandef;
113 else 112 } else {
114 channel_type = NL80211_CHAN_NO_HT; 113 chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
114 chandef.center_freq1 = chandef.chan->center_freq;
115 }
115 } else if (local->tmp_channel) { 116 } else if (local->tmp_channel) {
116 chan = local->tmp_channel; 117 chandef.chan = local->tmp_channel;
117 channel_type = NL80211_CHAN_NO_HT; 118 chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
118 } else { 119 chandef.center_freq1 = chandef.chan->center_freq;
119 chan = local->_oper_channel; 120 } else
120 channel_type = local->_oper_channel_type; 121 chandef = local->_oper_chandef;
121 } 122
122 123 WARN(!cfg80211_chandef_valid(&chandef),
123 if (chan != local->_oper_channel || 124 "control:%d MHz width:%d center: %d/%d MHz",
124 channel_type != local->_oper_channel_type) 125 chandef.chan->center_freq, chandef.width,
126 chandef.center_freq1, chandef.center_freq2);
127
128 if (!cfg80211_chandef_identical(&chandef, &local->_oper_chandef))
125 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL; 129 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
126 else 130 else
127 local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL; 131 local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
128 132
129 offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL; 133 offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
130 134
131 if (offchannel_flag || chan != local->hw.conf.channel || 135 if (offchannel_flag ||
132 channel_type != local->hw.conf.channel_type) { 136 !cfg80211_chandef_identical(&local->hw.conf.chandef,
133 local->hw.conf.channel = chan; 137 &local->_oper_chandef)) {
134 local->hw.conf.channel_type = channel_type; 138 local->hw.conf.chandef = chandef;
135 changed |= IEEE80211_CONF_CHANGE_CHANNEL; 139 changed |= IEEE80211_CONF_CHANGE_CHANNEL;
136 } 140 }
137 141
@@ -147,10 +151,7 @@ static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
147 changed |= IEEE80211_CONF_CHANGE_SMPS; 151 changed |= IEEE80211_CONF_CHANGE_SMPS;
148 } 152 }
149 153
150 scanning = test_bit(SCAN_SW_SCANNING, &local->scanning) || 154 power = chandef.chan->max_power;
151 test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning) ||
152 test_bit(SCAN_HW_SCANNING, &local->scanning);
153 power = chan->max_power;
154 155
155 rcu_read_lock(); 156 rcu_read_lock();
156 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 157 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
@@ -226,8 +227,6 @@ u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
226static void ieee80211_tasklet_handler(unsigned long data) 227static void ieee80211_tasklet_handler(unsigned long data)
227{ 228{
228 struct ieee80211_local *local = (struct ieee80211_local *) data; 229 struct ieee80211_local *local = (struct ieee80211_local *) data;
229 struct sta_info *sta, *tmp;
230 struct skb_eosp_msg_data *eosp_data;
231 struct sk_buff *skb; 230 struct sk_buff *skb;
232 231
233 while ((skb = skb_dequeue(&local->skb_queue)) || 232 while ((skb = skb_dequeue(&local->skb_queue)) ||
@@ -243,18 +242,6 @@ static void ieee80211_tasklet_handler(unsigned long data)
243 skb->pkt_type = 0; 242 skb->pkt_type = 0;
244 ieee80211_tx_status(&local->hw, skb); 243 ieee80211_tx_status(&local->hw, skb);
245 break; 244 break;
246 case IEEE80211_EOSP_MSG:
247 eosp_data = (void *)skb->cb;
248 for_each_sta_info(local, eosp_data->sta, sta, tmp) {
249 /* skip wrong virtual interface */
250 if (memcmp(eosp_data->iface,
251 sta->sdata->vif.addr, ETH_ALEN))
252 continue;
253 clear_sta_flag(sta, WLAN_STA_SP);
254 break;
255 }
256 dev_kfree_skb(skb);
257 break;
258 default: 245 default:
259 WARN(1, "mac80211: Packet is of unknown type %d\n", 246 WARN(1, "mac80211: Packet is of unknown type %d\n",
260 skb->pkt_type); 247 skb->pkt_type);
@@ -295,8 +282,8 @@ void ieee80211_restart_hw(struct ieee80211_hw *hw)
295 "Hardware restart was requested\n"); 282 "Hardware restart was requested\n");
296 283
297 /* use this reason, ieee80211_reconfig will unblock it */ 284 /* use this reason, ieee80211_reconfig will unblock it */
298 ieee80211_stop_queues_by_reason(hw, 285 ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
299 IEEE80211_QUEUE_STOP_REASON_SUSPEND); 286 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
300 287
301 /* 288 /*
302 * Stop all Rx during the reconfig. We don't want state changes 289 * Stop all Rx during the reconfig. We don't want state changes
@@ -399,30 +386,6 @@ static int ieee80211_ifa6_changed(struct notifier_block *nb,
399} 386}
400#endif 387#endif
401 388
402static int ieee80211_napi_poll(struct napi_struct *napi, int budget)
403{
404 struct ieee80211_local *local =
405 container_of(napi, struct ieee80211_local, napi);
406
407 return local->ops->napi_poll(&local->hw, budget);
408}
409
410void ieee80211_napi_schedule(struct ieee80211_hw *hw)
411{
412 struct ieee80211_local *local = hw_to_local(hw);
413
414 napi_schedule(&local->napi);
415}
416EXPORT_SYMBOL(ieee80211_napi_schedule);
417
418void ieee80211_napi_complete(struct ieee80211_hw *hw)
419{
420 struct ieee80211_local *local = hw_to_local(hw);
421
422 napi_complete(&local->napi);
423}
424EXPORT_SYMBOL(ieee80211_napi_complete);
425
426/* There isn't a lot of sense in it, but you can transmit anything you like */ 389/* There isn't a lot of sense in it, but you can transmit anything you like */
427static const struct ieee80211_txrx_stypes 390static const struct ieee80211_txrx_stypes
428ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = { 391ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
@@ -501,6 +464,27 @@ static const struct ieee80211_ht_cap mac80211_ht_capa_mod_mask = {
501 }, 464 },
502}; 465};
503 466
467static const struct ieee80211_vht_cap mac80211_vht_capa_mod_mask = {
468 .vht_cap_info =
469 cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC |
470 IEEE80211_VHT_CAP_SHORT_GI_80 |
471 IEEE80211_VHT_CAP_SHORT_GI_160 |
472 IEEE80211_VHT_CAP_RXSTBC_1 |
473 IEEE80211_VHT_CAP_RXSTBC_2 |
474 IEEE80211_VHT_CAP_RXSTBC_3 |
475 IEEE80211_VHT_CAP_RXSTBC_4 |
476 IEEE80211_VHT_CAP_TXSTBC |
477 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
478 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
479 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
480 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
481 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK),
482 .supp_mcs = {
483 .rx_mcs_map = cpu_to_le16(~0),
484 .tx_mcs_map = cpu_to_le16(~0),
485 },
486};
487
504static const u8 extended_capabilities[] = { 488static const u8 extended_capabilities[] = {
505 0, 0, 0, 0, 0, 0, 0, 489 0, 0, 0, 0, 0, 0, 0,
506 WLAN_EXT_CAPA8_OPMODE_NOTIF, 490 WLAN_EXT_CAPA8_OPMODE_NOTIF,
@@ -572,7 +556,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
572 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS | 556 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
573 NL80211_FEATURE_SAE | 557 NL80211_FEATURE_SAE |
574 NL80211_FEATURE_HT_IBSS | 558 NL80211_FEATURE_HT_IBSS |
575 NL80211_FEATURE_VIF_TXPOWER; 559 NL80211_FEATURE_VIF_TXPOWER |
560 NL80211_FEATURE_USERSPACE_MPM;
576 561
577 if (!ops->hw_scan) 562 if (!ops->hw_scan)
578 wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN | 563 wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
@@ -607,8 +592,11 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
607 IEEE80211_RADIOTAP_MCS_HAVE_BW; 592 IEEE80211_RADIOTAP_MCS_HAVE_BW;
608 local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI | 593 local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
609 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH; 594 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
595 local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
596 local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
610 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL; 597 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
611 wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask; 598 wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
599 wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
612 600
613 INIT_LIST_HEAD(&local->interfaces); 601 INIT_LIST_HEAD(&local->interfaces);
614 602
@@ -664,9 +652,6 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
664 skb_queue_head_init(&local->skb_queue); 652 skb_queue_head_init(&local->skb_queue);
665 skb_queue_head_init(&local->skb_queue_unreliable); 653 skb_queue_head_init(&local->skb_queue_unreliable);
666 654
667 /* init dummy netdev for use w/ NAPI */
668 init_dummy_netdev(&local->napi_dev);
669
670 ieee80211_led_names(local); 655 ieee80211_led_names(local);
671 656
672 ieee80211_roc_setup(local); 657 ieee80211_roc_setup(local);
@@ -683,6 +668,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
683 int channels, max_bitrates; 668 int channels, max_bitrates;
684 bool supp_ht, supp_vht; 669 bool supp_ht, supp_vht;
685 netdev_features_t feature_whitelist; 670 netdev_features_t feature_whitelist;
671 struct cfg80211_chan_def dflt_chandef = {};
686 static const u32 cipher_suites[] = { 672 static const u32 cipher_suites[] = {
687 /* keep WEP first, it may be removed below */ 673 /* keep WEP first, it may be removed below */
688 WLAN_CIPHER_SUITE_WEP40, 674 WLAN_CIPHER_SUITE_WEP40,
@@ -760,15 +746,19 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
760 sband = local->hw.wiphy->bands[band]; 746 sband = local->hw.wiphy->bands[band];
761 if (!sband) 747 if (!sband)
762 continue; 748 continue;
763 if (!local->use_chanctx && !local->_oper_channel) { 749
750 if (!dflt_chandef.chan) {
751 cfg80211_chandef_create(&dflt_chandef,
752 &sband->channels[0],
753 NL80211_CHAN_NO_HT);
764 /* init channel we're on */ 754 /* init channel we're on */
765 local->hw.conf.channel = 755 if (!local->use_chanctx && !local->_oper_chandef.chan) {
766 local->_oper_channel = &sband->channels[0]; 756 local->hw.conf.chandef = dflt_chandef;
767 local->hw.conf.channel_type = NL80211_CHAN_NO_HT; 757 local->_oper_chandef = dflt_chandef;
758 }
759 local->monitor_chandef = dflt_chandef;
768 } 760 }
769 cfg80211_chandef_create(&local->monitor_chandef, 761
770 &sband->channels[0],
771 NL80211_CHAN_NO_HT);
772 channels += sband->n_channels; 762 channels += sband->n_channels;
773 763
774 if (max_bitrates < sband->n_bitrates) 764 if (max_bitrates < sband->n_bitrates)
@@ -851,22 +841,10 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
851 if (supp_ht) 841 if (supp_ht)
852 local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap); 842 local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
853 843
854 if (supp_vht) { 844 if (supp_vht)
855 local->scan_ies_len += 845 local->scan_ies_len +=
856 2 + sizeof(struct ieee80211_vht_cap); 846 2 + sizeof(struct ieee80211_vht_cap);
857 847
858 /*
859 * (for now at least), drivers wanting to use VHT must
860 * support channel contexts, as they contain all the
861 * necessary VHT information and the global hw config
862 * doesn't (yet)
863 */
864 if (WARN_ON(!local->use_chanctx)) {
865 result = -EINVAL;
866 goto fail_wiphy_register;
867 }
868 }
869
870 if (!local->ops->hw_scan) { 848 if (!local->ops->hw_scan) {
871 /* For hw_scan, driver needs to set these up. */ 849 /* For hw_scan, driver needs to set these up. */
872 local->hw.wiphy->max_scan_ssids = 4; 850 local->hw.wiphy->max_scan_ssids = 4;
@@ -1021,9 +999,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
1021 goto fail_ifa6; 999 goto fail_ifa6;
1022#endif 1000#endif
1023 1001
1024 netif_napi_add(&local->napi_dev, &local->napi, ieee80211_napi_poll,
1025 local->hw.napi_weight);
1026
1027 return 0; 1002 return 0;
1028 1003
1029#if IS_ENABLED(CONFIG_IPV6) 1004#if IS_ENABLED(CONFIG_IPV6)
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 4749b3858695..6952760881c8 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -13,10 +13,6 @@
13#include "ieee80211_i.h" 13#include "ieee80211_i.h"
14#include "mesh.h" 14#include "mesh.h"
15 15
16#define TMR_RUNNING_HK 0
17#define TMR_RUNNING_MP 1
18#define TMR_RUNNING_MPR 2
19
20static int mesh_allocated; 16static int mesh_allocated;
21static struct kmem_cache *rm_cache; 17static struct kmem_cache *rm_cache;
22 18
@@ -50,11 +46,6 @@ static void ieee80211_mesh_housekeeping_timer(unsigned long data)
50 46
51 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags); 47 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
52 48
53 if (local->quiescing) {
54 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
55 return;
56 }
57
58 ieee80211_queue_work(&local->hw, &sdata->work); 49 ieee80211_queue_work(&local->hw, &sdata->work);
59} 50}
60 51
@@ -165,7 +156,7 @@ void mesh_sta_cleanup(struct sta_info *sta)
165 * an update. 156 * an update.
166 */ 157 */
167 changed = mesh_accept_plinks_update(sdata); 158 changed = mesh_accept_plinks_update(sdata);
168 if (sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) { 159 if (!sdata->u.mesh.user_mpm) {
169 changed |= mesh_plink_deactivate(sta); 160 changed |= mesh_plink_deactivate(sta);
170 del_timer_sync(&sta->plink_timer); 161 del_timer_sync(&sta->plink_timer);
171 } 162 }
@@ -479,15 +470,8 @@ static void ieee80211_mesh_path_timer(unsigned long data)
479{ 470{
480 struct ieee80211_sub_if_data *sdata = 471 struct ieee80211_sub_if_data *sdata =
481 (struct ieee80211_sub_if_data *) data; 472 (struct ieee80211_sub_if_data *) data;
482 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
483 struct ieee80211_local *local = sdata->local;
484
485 if (local->quiescing) {
486 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
487 return;
488 }
489 473
490 ieee80211_queue_work(&local->hw, &sdata->work); 474 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
491} 475}
492 476
493static void ieee80211_mesh_path_root_timer(unsigned long data) 477static void ieee80211_mesh_path_root_timer(unsigned long data)
@@ -495,16 +479,10 @@ static void ieee80211_mesh_path_root_timer(unsigned long data)
495 struct ieee80211_sub_if_data *sdata = 479 struct ieee80211_sub_if_data *sdata =
496 (struct ieee80211_sub_if_data *) data; 480 (struct ieee80211_sub_if_data *) data;
497 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 481 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
498 struct ieee80211_local *local = sdata->local;
499 482
500 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); 483 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
501 484
502 if (local->quiescing) { 485 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
503 set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
504 return;
505 }
506
507 ieee80211_queue_work(&local->hw, &sdata->work);
508} 486}
509 487
510void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh) 488void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
@@ -622,35 +600,6 @@ static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
622 round_jiffies(TU_TO_EXP_TIME(interval))); 600 round_jiffies(TU_TO_EXP_TIME(interval)));
623} 601}
624 602
625#ifdef CONFIG_PM
626void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
627{
628 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
629
630 /* use atomic bitops in case all timers fire at the same time */
631
632 if (del_timer_sync(&ifmsh->housekeeping_timer))
633 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
634 if (del_timer_sync(&ifmsh->mesh_path_timer))
635 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
636 if (del_timer_sync(&ifmsh->mesh_path_root_timer))
637 set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
638}
639
640void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
641{
642 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
643
644 if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running))
645 add_timer(&ifmsh->housekeeping_timer);
646 if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
647 add_timer(&ifmsh->mesh_path_timer);
648 if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running))
649 add_timer(&ifmsh->mesh_path_root_timer);
650 ieee80211_mesh_root_setup(ifmsh);
651}
652#endif
653
654static int 603static int
655ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh) 604ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
656{ 605{
@@ -750,10 +699,8 @@ out_free:
750static int 699static int
751ieee80211_mesh_rebuild_beacon(struct ieee80211_if_mesh *ifmsh) 700ieee80211_mesh_rebuild_beacon(struct ieee80211_if_mesh *ifmsh)
752{ 701{
753 struct ieee80211_sub_if_data *sdata;
754 struct beacon_data *old_bcn; 702 struct beacon_data *old_bcn;
755 int ret; 703 int ret;
756 sdata = container_of(ifmsh, struct ieee80211_sub_if_data, u.mesh);
757 704
758 mutex_lock(&ifmsh->mtx); 705 mutex_lock(&ifmsh->mtx);
759 706
@@ -871,8 +818,6 @@ void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
871 local->fif_other_bss--; 818 local->fif_other_bss--;
872 atomic_dec(&local->iff_allmultis); 819 atomic_dec(&local->iff_allmultis);
873 ieee80211_configure_filter(local); 820 ieee80211_configure_filter(local);
874
875 sdata->u.mesh.timers_running = 0;
876} 821}
877 822
878static void 823static void
@@ -886,15 +831,14 @@ ieee80211_mesh_rx_probe_req(struct ieee80211_sub_if_data *sdata,
886 struct ieee80211_mgmt *hdr; 831 struct ieee80211_mgmt *hdr;
887 struct ieee802_11_elems elems; 832 struct ieee802_11_elems elems;
888 size_t baselen; 833 size_t baselen;
889 u8 *pos, *end; 834 u8 *pos;
890 835
891 end = ((u8 *) mgmt) + len;
892 pos = mgmt->u.probe_req.variable; 836 pos = mgmt->u.probe_req.variable;
893 baselen = (u8 *) pos - (u8 *) mgmt; 837 baselen = (u8 *) pos - (u8 *) mgmt;
894 if (baselen > len) 838 if (baselen > len)
895 return; 839 return;
896 840
897 ieee802_11_parse_elems(pos, len - baselen, &elems); 841 ieee802_11_parse_elems(pos, len - baselen, false, &elems);
898 842
899 /* 802.11-2012 10.1.4.3.2 */ 843 /* 802.11-2012 10.1.4.3.2 */
900 if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) && 844 if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
@@ -955,7 +899,7 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
955 return; 899 return;
956 900
957 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, 901 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
958 &elems); 902 false, &elems);
959 903
960 /* ignore non-mesh or secure / unsecure mismatch */ 904 /* ignore non-mesh or secure / unsecure mismatch */
961 if ((!elems.mesh_id || !elems.mesh_config) || 905 if ((!elems.mesh_id || !elems.mesh_config) ||
@@ -963,7 +907,7 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
963 (!elems.rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)) 907 (!elems.rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE))
964 return; 908 return;
965 909
966 if (elems.ds_params && elems.ds_params_len == 1) 910 if (elems.ds_params)
967 freq = ieee80211_channel_to_frequency(elems.ds_params[0], band); 911 freq = ieee80211_channel_to_frequency(elems.ds_params[0], band);
968 else 912 else
969 freq = rx_status->freq; 913 freq = rx_status->freq;
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index 336c88a16687..da158774eebb 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -275,7 +275,8 @@ void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop);
275void mesh_path_expire(struct ieee80211_sub_if_data *sdata); 275void mesh_path_expire(struct ieee80211_sub_if_data *sdata);
276void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata, 276void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
277 struct ieee80211_mgmt *mgmt, size_t len); 277 struct ieee80211_mgmt *mgmt, size_t len);
278int mesh_path_add(struct ieee80211_sub_if_data *sdata, const u8 *dst); 278struct mesh_path *
279mesh_path_add(struct ieee80211_sub_if_data *sdata, const u8 *dst);
279 280
280int mesh_path_add_gate(struct mesh_path *mpath); 281int mesh_path_add_gate(struct mesh_path *mpath);
281int mesh_path_send_to_gates(struct mesh_path *mpath); 282int mesh_path_send_to_gates(struct mesh_path *mpath);
@@ -313,8 +314,6 @@ void mesh_path_timer(unsigned long data);
313void mesh_path_flush_by_nexthop(struct sta_info *sta); 314void mesh_path_flush_by_nexthop(struct sta_info *sta);
314void mesh_path_discard_frame(struct ieee80211_sub_if_data *sdata, 315void mesh_path_discard_frame(struct ieee80211_sub_if_data *sdata,
315 struct sk_buff *skb); 316 struct sk_buff *skb);
316void mesh_path_quiesce(struct ieee80211_sub_if_data *sdata);
317void mesh_path_restart(struct ieee80211_sub_if_data *sdata);
318void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata); 317void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata);
319 318
320bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt); 319bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt);
@@ -359,22 +358,12 @@ static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata)
359 358
360void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local); 359void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local);
361 360
362void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata);
363void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata);
364void mesh_plink_quiesce(struct sta_info *sta);
365void mesh_plink_restart(struct sta_info *sta);
366void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata); 361void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata);
367void mesh_sync_adjust_tbtt(struct ieee80211_sub_if_data *sdata); 362void mesh_sync_adjust_tbtt(struct ieee80211_sub_if_data *sdata);
368void ieee80211s_stop(void); 363void ieee80211s_stop(void);
369#else 364#else
370static inline void 365static inline void
371ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) {} 366ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) {}
372static inline void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
373{}
374static inline void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
375{}
376static inline void mesh_plink_quiesce(struct sta_info *sta) {}
377static inline void mesh_plink_restart(struct sta_info *sta) {}
378static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata) 367static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata)
379{ return false; } 368{ return false; }
380static inline void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata) 369static inline void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata)
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
index bdb8d3b14587..486819cd02cd 100644
--- a/net/mac80211/mesh_hwmp.c
+++ b/net/mac80211/mesh_hwmp.c
@@ -144,7 +144,7 @@ static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags,
144 *pos++ = WLAN_EID_PREQ; 144 *pos++ = WLAN_EID_PREQ;
145 break; 145 break;
146 case MPATH_PREP: 146 case MPATH_PREP:
147 mhwmp_dbg(sdata, "sending PREP to %pM\n", target); 147 mhwmp_dbg(sdata, "sending PREP to %pM\n", orig_addr);
148 ie_len = 31; 148 ie_len = 31;
149 pos = skb_put(skb, 2 + ie_len); 149 pos = skb_put(skb, 2 + ie_len);
150 *pos++ = WLAN_EID_PREP; 150 *pos++ = WLAN_EID_PREP;
@@ -445,9 +445,8 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
445 } 445 }
446 } 446 }
447 } else { 447 } else {
448 mesh_path_add(sdata, orig_addr); 448 mpath = mesh_path_add(sdata, orig_addr);
449 mpath = mesh_path_lookup(sdata, orig_addr); 449 if (IS_ERR(mpath)) {
450 if (!mpath) {
451 rcu_read_unlock(); 450 rcu_read_unlock();
452 return 0; 451 return 0;
453 } 452 }
@@ -486,9 +485,8 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
486 (last_hop_metric > mpath->metric))) 485 (last_hop_metric > mpath->metric)))
487 fresh_info = false; 486 fresh_info = false;
488 } else { 487 } else {
489 mesh_path_add(sdata, ta); 488 mpath = mesh_path_add(sdata, ta);
490 mpath = mesh_path_lookup(sdata, ta); 489 if (IS_ERR(mpath)) {
491 if (!mpath) {
492 rcu_read_unlock(); 490 rcu_read_unlock();
493 return 0; 491 return 0;
494 } 492 }
@@ -661,7 +659,7 @@ static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
661 u32 target_sn, orig_sn, lifetime; 659 u32 target_sn, orig_sn, lifetime;
662 660
663 mhwmp_dbg(sdata, "received PREP from %pM\n", 661 mhwmp_dbg(sdata, "received PREP from %pM\n",
664 PREP_IE_ORIG_ADDR(prep_elem)); 662 PREP_IE_TARGET_ADDR(prep_elem));
665 663
666 orig_addr = PREP_IE_ORIG_ADDR(prep_elem); 664 orig_addr = PREP_IE_ORIG_ADDR(prep_elem);
667 if (ether_addr_equal(orig_addr, sdata->vif.addr)) 665 if (ether_addr_equal(orig_addr, sdata->vif.addr))
@@ -804,9 +802,8 @@ static void hwmp_rann_frame_process(struct ieee80211_sub_if_data *sdata,
804 802
805 mpath = mesh_path_lookup(sdata, orig_addr); 803 mpath = mesh_path_lookup(sdata, orig_addr);
806 if (!mpath) { 804 if (!mpath) {
807 mesh_path_add(sdata, orig_addr); 805 mpath = mesh_path_add(sdata, orig_addr);
808 mpath = mesh_path_lookup(sdata, orig_addr); 806 if (IS_ERR(mpath)) {
809 if (!mpath) {
810 rcu_read_unlock(); 807 rcu_read_unlock();
811 sdata->u.mesh.mshstats.dropped_frames_no_route++; 808 sdata->u.mesh.mshstats.dropped_frames_no_route++;
812 return; 809 return;
@@ -883,7 +880,7 @@ void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
883 880
884 baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt; 881 baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt;
885 ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable, 882 ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
886 len - baselen, &elems); 883 len - baselen, false, &elems);
887 884
888 if (elems.preq) { 885 if (elems.preq) {
889 if (elems.preq_len != 37) 886 if (elems.preq_len != 37)
@@ -1098,11 +1095,10 @@ int mesh_nexthop_resolve(struct ieee80211_sub_if_data *sdata,
1098 /* no nexthop found, start resolving */ 1095 /* no nexthop found, start resolving */
1099 mpath = mesh_path_lookup(sdata, target_addr); 1096 mpath = mesh_path_lookup(sdata, target_addr);
1100 if (!mpath) { 1097 if (!mpath) {
1101 mesh_path_add(sdata, target_addr); 1098 mpath = mesh_path_add(sdata, target_addr);
1102 mpath = mesh_path_lookup(sdata, target_addr); 1099 if (IS_ERR(mpath)) {
1103 if (!mpath) {
1104 mesh_path_discard_frame(sdata, skb); 1100 mesh_path_discard_frame(sdata, skb);
1105 err = -ENOSPC; 1101 err = PTR_ERR(mpath);
1106 goto endlookup; 1102 goto endlookup;
1107 } 1103 }
1108 } 1104 }
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index dc7c8df40c2c..89aacfd2756d 100644
--- a/net/mac80211/mesh_pathtbl.c
+++ b/net/mac80211/mesh_pathtbl.c
@@ -493,7 +493,8 @@ int mesh_gate_num(struct ieee80211_sub_if_data *sdata)
493 * 493 *
494 * State: the initial state of the new path is set to 0 494 * State: the initial state of the new path is set to 0
495 */ 495 */
496int mesh_path_add(struct ieee80211_sub_if_data *sdata, const u8 *dst) 496struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata,
497 const u8 *dst)
497{ 498{
498 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 499 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
499 struct ieee80211_local *local = sdata->local; 500 struct ieee80211_local *local = sdata->local;
@@ -502,18 +503,33 @@ int mesh_path_add(struct ieee80211_sub_if_data *sdata, const u8 *dst)
502 struct mpath_node *node, *new_node; 503 struct mpath_node *node, *new_node;
503 struct hlist_head *bucket; 504 struct hlist_head *bucket;
504 int grow = 0; 505 int grow = 0;
505 int err = 0; 506 int err;
506 u32 hash_idx; 507 u32 hash_idx;
507 508
508 if (ether_addr_equal(dst, sdata->vif.addr)) 509 if (ether_addr_equal(dst, sdata->vif.addr))
509 /* never add ourselves as neighbours */ 510 /* never add ourselves as neighbours */
510 return -ENOTSUPP; 511 return ERR_PTR(-ENOTSUPP);
511 512
512 if (is_multicast_ether_addr(dst)) 513 if (is_multicast_ether_addr(dst))
513 return -ENOTSUPP; 514 return ERR_PTR(-ENOTSUPP);
514 515
515 if (atomic_add_unless(&sdata->u.mesh.mpaths, 1, MESH_MAX_MPATHS) == 0) 516 if (atomic_add_unless(&sdata->u.mesh.mpaths, 1, MESH_MAX_MPATHS) == 0)
516 return -ENOSPC; 517 return ERR_PTR(-ENOSPC);
518
519 read_lock_bh(&pathtbl_resize_lock);
520 tbl = resize_dereference_mesh_paths();
521
522 hash_idx = mesh_table_hash(dst, sdata, tbl);
523 bucket = &tbl->hash_buckets[hash_idx];
524
525 spin_lock(&tbl->hashwlock[hash_idx]);
526
527 hlist_for_each_entry(node, bucket, list) {
528 mpath = node->mpath;
529 if (mpath->sdata == sdata &&
530 ether_addr_equal(dst, mpath->dst))
531 goto found;
532 }
517 533
518 err = -ENOMEM; 534 err = -ENOMEM;
519 new_mpath = kzalloc(sizeof(struct mesh_path), GFP_ATOMIC); 535 new_mpath = kzalloc(sizeof(struct mesh_path), GFP_ATOMIC);
@@ -524,7 +540,6 @@ int mesh_path_add(struct ieee80211_sub_if_data *sdata, const u8 *dst)
524 if (!new_node) 540 if (!new_node)
525 goto err_node_alloc; 541 goto err_node_alloc;
526 542
527 read_lock_bh(&pathtbl_resize_lock);
528 memcpy(new_mpath->dst, dst, ETH_ALEN); 543 memcpy(new_mpath->dst, dst, ETH_ALEN);
529 eth_broadcast_addr(new_mpath->rann_snd_addr); 544 eth_broadcast_addr(new_mpath->rann_snd_addr);
530 new_mpath->is_root = false; 545 new_mpath->is_root = false;
@@ -538,21 +553,6 @@ int mesh_path_add(struct ieee80211_sub_if_data *sdata, const u8 *dst)
538 spin_lock_init(&new_mpath->state_lock); 553 spin_lock_init(&new_mpath->state_lock);
539 init_timer(&new_mpath->timer); 554 init_timer(&new_mpath->timer);
540 555
541 tbl = resize_dereference_mesh_paths();
542
543 hash_idx = mesh_table_hash(dst, sdata, tbl);
544 bucket = &tbl->hash_buckets[hash_idx];
545
546 spin_lock(&tbl->hashwlock[hash_idx]);
547
548 err = -EEXIST;
549 hlist_for_each_entry(node, bucket, list) {
550 mpath = node->mpath;
551 if (mpath->sdata == sdata &&
552 ether_addr_equal(dst, mpath->dst))
553 goto err_exists;
554 }
555
556 hlist_add_head_rcu(&new_node->list, bucket); 556 hlist_add_head_rcu(&new_node->list, bucket);
557 if (atomic_inc_return(&tbl->entries) >= 557 if (atomic_inc_return(&tbl->entries) >=
558 tbl->mean_chain_len * (tbl->hash_mask + 1)) 558 tbl->mean_chain_len * (tbl->hash_mask + 1))
@@ -560,23 +560,23 @@ int mesh_path_add(struct ieee80211_sub_if_data *sdata, const u8 *dst)
560 560
561 mesh_paths_generation++; 561 mesh_paths_generation++;
562 562
563 spin_unlock(&tbl->hashwlock[hash_idx]);
564 read_unlock_bh(&pathtbl_resize_lock);
565 if (grow) { 563 if (grow) {
566 set_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags); 564 set_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags);
567 ieee80211_queue_work(&local->hw, &sdata->work); 565 ieee80211_queue_work(&local->hw, &sdata->work);
568 } 566 }
569 return 0; 567 mpath = new_mpath;
570 568found:
571err_exists:
572 spin_unlock(&tbl->hashwlock[hash_idx]); 569 spin_unlock(&tbl->hashwlock[hash_idx]);
573 read_unlock_bh(&pathtbl_resize_lock); 570 read_unlock_bh(&pathtbl_resize_lock);
574 kfree(new_node); 571 return mpath;
572
575err_node_alloc: 573err_node_alloc:
576 kfree(new_mpath); 574 kfree(new_mpath);
577err_path_alloc: 575err_path_alloc:
578 atomic_dec(&sdata->u.mesh.mpaths); 576 atomic_dec(&sdata->u.mesh.mpaths);
579 return err; 577 spin_unlock(&tbl->hashwlock[hash_idx]);
578 read_unlock_bh(&pathtbl_resize_lock);
579 return ERR_PTR(err);
580} 580}
581 581
582static void mesh_table_free_rcu(struct rcu_head *rcu) 582static void mesh_table_free_rcu(struct rcu_head *rcu)
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index 07d396d57079..09bebed99416 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -420,7 +420,6 @@ __mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *hw_addr)
420 return NULL; 420 return NULL;
421 421
422 sta->plink_state = NL80211_PLINK_LISTEN; 422 sta->plink_state = NL80211_PLINK_LISTEN;
423 init_timer(&sta->plink_timer);
424 423
425 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH); 424 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
426 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC); 425 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
@@ -437,8 +436,9 @@ mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *addr,
437{ 436{
438 struct sta_info *sta = NULL; 437 struct sta_info *sta = NULL;
439 438
440 /* Userspace handles peer allocation when security is enabled */ 439 /* Userspace handles station allocation */
441 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED) 440 if (sdata->u.mesh.user_mpm ||
441 sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
442 cfg80211_notify_new_peer_candidate(sdata->dev, addr, 442 cfg80211_notify_new_peer_candidate(sdata->dev, addr,
443 elems->ie_start, 443 elems->ie_start,
444 elems->total_len, 444 elems->total_len,
@@ -534,10 +534,8 @@ static void mesh_plink_timer(unsigned long data)
534 */ 534 */
535 sta = (struct sta_info *) data; 535 sta = (struct sta_info *) data;
536 536
537 if (sta->sdata->local->quiescing) { 537 if (sta->sdata->local->quiescing)
538 sta->plink_timer_was_running = true;
539 return; 538 return;
540 }
541 539
542 spin_lock_bh(&sta->lock); 540 spin_lock_bh(&sta->lock);
543 if (sta->ignore_plink_timer) { 541 if (sta->ignore_plink_timer) {
@@ -546,8 +544,8 @@ static void mesh_plink_timer(unsigned long data)
546 return; 544 return;
547 } 545 }
548 mpl_dbg(sta->sdata, 546 mpl_dbg(sta->sdata,
549 "Mesh plink timer for %pM fired on state %d\n", 547 "Mesh plink timer for %pM fired on state %s\n",
550 sta->sta.addr, sta->plink_state); 548 sta->sta.addr, mplstates[sta->plink_state]);
551 reason = 0; 549 reason = 0;
552 llid = sta->llid; 550 llid = sta->llid;
553 plid = sta->plid; 551 plid = sta->plid;
@@ -598,29 +596,6 @@ static void mesh_plink_timer(unsigned long data)
598 } 596 }
599} 597}
600 598
601#ifdef CONFIG_PM
602void mesh_plink_quiesce(struct sta_info *sta)
603{
604 if (!ieee80211_vif_is_mesh(&sta->sdata->vif))
605 return;
606
607 /* no kernel mesh sta timers have been initialized */
608 if (sta->sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
609 return;
610
611 if (del_timer_sync(&sta->plink_timer))
612 sta->plink_timer_was_running = true;
613}
614
615void mesh_plink_restart(struct sta_info *sta)
616{
617 if (sta->plink_timer_was_running) {
618 add_timer(&sta->plink_timer);
619 sta->plink_timer_was_running = false;
620 }
621}
622#endif
623
624static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout) 599static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
625{ 600{
626 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000); 601 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
@@ -695,6 +670,10 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
695 if (len < IEEE80211_MIN_ACTION_SIZE + 3) 670 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
696 return; 671 return;
697 672
673 if (sdata->u.mesh.user_mpm)
674 /* userspace must register for these */
675 return;
676
698 if (is_multicast_ether_addr(mgmt->da)) { 677 if (is_multicast_ether_addr(mgmt->da)) {
699 mpl_dbg(sdata, 678 mpl_dbg(sdata,
700 "Mesh plink: ignore frame from multicast address\n"); 679 "Mesh plink: ignore frame from multicast address\n");
@@ -708,7 +687,7 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
708 baseaddr += 4; 687 baseaddr += 4;
709 baselen += 4; 688 baselen += 4;
710 } 689 }
711 ieee802_11_parse_elems(baseaddr, len - baselen, &elems); 690 ieee802_11_parse_elems(baseaddr, len - baselen, true, &elems);
712 691
713 if (!elems.peering) { 692 if (!elems.peering) {
714 mpl_dbg(sdata, 693 mpl_dbg(sdata,
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 346ad4cfb013..29620bfc7a69 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -56,7 +56,10 @@ MODULE_PARM_DESC(max_probe_tries,
56 * probe on beacon miss before declaring the connection lost 56 * probe on beacon miss before declaring the connection lost
57 * default to what we want. 57 * default to what we want.
58 */ 58 */
59#define IEEE80211_BEACON_LOSS_COUNT 7 59static int beacon_loss_count = 7;
60module_param(beacon_loss_count, int, 0644);
61MODULE_PARM_DESC(beacon_loss_count,
62 "Number of beacon intervals before we decide beacon was lost.");
60 63
61/* 64/*
62 * Time the connection can be idle before we probe 65 * Time the connection can be idle before we probe
@@ -87,9 +90,6 @@ MODULE_PARM_DESC(probe_wait_ms,
87 */ 90 */
88#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4 91#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
89 92
90#define TMR_RUNNING_TIMER 0
91#define TMR_RUNNING_CHANSW 1
92
93/* 93/*
94 * All cfg80211 functions have to be called outside a locked 94 * All cfg80211 functions have to be called outside a locked
95 * section so that they can acquire a lock themselves... This 95 * section so that they can acquire a lock themselves... This
@@ -289,6 +289,8 @@ ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
289 } else { 289 } else {
290 /* 40 MHz (and 80 MHz) must be supported for VHT */ 290 /* 40 MHz (and 80 MHz) must be supported for VHT */
291 ret = IEEE80211_STA_DISABLE_VHT; 291 ret = IEEE80211_STA_DISABLE_VHT;
292 /* also mark 40 MHz disabled */
293 ret |= IEEE80211_STA_DISABLE_40MHZ;
292 goto out; 294 goto out;
293 } 295 }
294 296
@@ -303,12 +305,6 @@ ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
303 channel->band); 305 channel->band);
304 vht_chandef.center_freq2 = 0; 306 vht_chandef.center_freq2 = 0;
305 307
306 if (vht_oper->center_freq_seg2_idx)
307 vht_chandef.center_freq2 =
308 ieee80211_channel_to_frequency(
309 vht_oper->center_freq_seg2_idx,
310 channel->band);
311
312 switch (vht_oper->chan_width) { 308 switch (vht_oper->chan_width) {
313 case IEEE80211_VHT_CHANWIDTH_USE_HT: 309 case IEEE80211_VHT_CHANWIDTH_USE_HT:
314 vht_chandef.width = chandef->width; 310 vht_chandef.width = chandef->width;
@@ -321,6 +317,10 @@ ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
321 break; 317 break;
322 case IEEE80211_VHT_CHANWIDTH_80P80MHZ: 318 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
323 vht_chandef.width = NL80211_CHAN_WIDTH_80P80; 319 vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
320 vht_chandef.center_freq2 =
321 ieee80211_channel_to_frequency(
322 vht_oper->center_freq_seg2_idx,
323 channel->band);
324 break; 324 break;
325 default: 325 default:
326 if (verbose) 326 if (verbose)
@@ -604,11 +604,11 @@ static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
604 u8 *pos; 604 u8 *pos;
605 u32 cap; 605 u32 cap;
606 struct ieee80211_sta_vht_cap vht_cap; 606 struct ieee80211_sta_vht_cap vht_cap;
607 int i;
608 607
609 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap)); 608 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
610 609
611 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); 610 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
611 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
612 612
613 /* determine capability flags */ 613 /* determine capability flags */
614 cap = vht_cap.cap; 614 cap = vht_cap.cap;
@@ -631,37 +631,6 @@ static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
631 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE))) 631 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
632 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE; 632 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
633 633
634 if (!(ap_vht_cap->vht_cap_info &
635 cpu_to_le32(IEEE80211_VHT_CAP_TXSTBC)))
636 cap &= ~(IEEE80211_VHT_CAP_RXSTBC_1 |
637 IEEE80211_VHT_CAP_RXSTBC_3 |
638 IEEE80211_VHT_CAP_RXSTBC_4);
639
640 for (i = 0; i < 8; i++) {
641 int shift = i * 2;
642 u16 mask = IEEE80211_VHT_MCS_NOT_SUPPORTED << shift;
643 u16 ap_mcs, our_mcs;
644
645 ap_mcs = (le16_to_cpu(ap_vht_cap->supp_mcs.tx_mcs_map) &
646 mask) >> shift;
647 our_mcs = (le16_to_cpu(vht_cap.vht_mcs.rx_mcs_map) &
648 mask) >> shift;
649
650 if (our_mcs == IEEE80211_VHT_MCS_NOT_SUPPORTED)
651 continue;
652
653 switch (ap_mcs) {
654 default:
655 if (our_mcs <= ap_mcs)
656 break;
657 /* fall through */
658 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
659 vht_cap.vht_mcs.rx_mcs_map &= cpu_to_le16(~mask);
660 vht_cap.vht_mcs.rx_mcs_map |=
661 cpu_to_le16(ap_mcs << shift);
662 }
663 }
664
665 /* reserve and fill IE */ 634 /* reserve and fill IE */
666 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); 635 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
667 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); 636 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
@@ -987,6 +956,7 @@ static void ieee80211_chswitch_work(struct work_struct *work)
987{ 956{
988 struct ieee80211_sub_if_data *sdata = 957 struct ieee80211_sub_if_data *sdata =
989 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); 958 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
959 struct ieee80211_local *local = sdata->local;
990 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 960 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
991 961
992 if (!ieee80211_sdata_running(sdata)) 962 if (!ieee80211_sdata_running(sdata))
@@ -996,21 +966,22 @@ static void ieee80211_chswitch_work(struct work_struct *work)
996 if (!ifmgd->associated) 966 if (!ifmgd->associated)
997 goto out; 967 goto out;
998 968
999 sdata->local->_oper_channel = sdata->local->csa_channel; 969 local->_oper_chandef = local->csa_chandef;
1000 if (!sdata->local->ops->channel_switch) { 970
971 if (!local->ops->channel_switch) {
1001 /* call "hw_config" only if doing sw channel switch */ 972 /* call "hw_config" only if doing sw channel switch */
1002 ieee80211_hw_config(sdata->local, 973 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1003 IEEE80211_CONF_CHANGE_CHANNEL);
1004 } else { 974 } else {
1005 /* update the device channel directly */ 975 /* update the device channel directly */
1006 sdata->local->hw.conf.channel = sdata->local->_oper_channel; 976 local->hw.conf.chandef = local->_oper_chandef;
1007 } 977 }
1008 978
1009 /* XXX: shouldn't really modify cfg80211-owned data! */ 979 /* XXX: shouldn't really modify cfg80211-owned data! */
1010 ifmgd->associated->channel = sdata->local->_oper_channel; 980 ifmgd->associated->channel = local->_oper_chandef.chan;
1011 981
1012 /* XXX: wait for a beacon first? */ 982 /* XXX: wait for a beacon first? */
1013 ieee80211_wake_queues_by_reason(&sdata->local->hw, 983 ieee80211_wake_queues_by_reason(&local->hw,
984 IEEE80211_MAX_QUEUE_MAP,
1014 IEEE80211_QUEUE_STOP_REASON_CSA); 985 IEEE80211_QUEUE_STOP_REASON_CSA);
1015 out: 986 out:
1016 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; 987 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
@@ -1038,66 +1009,197 @@ static void ieee80211_chswitch_timer(unsigned long data)
1038{ 1009{
1039 struct ieee80211_sub_if_data *sdata = 1010 struct ieee80211_sub_if_data *sdata =
1040 (struct ieee80211_sub_if_data *) data; 1011 (struct ieee80211_sub_if_data *) data;
1041 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1042
1043 if (sdata->local->quiescing) {
1044 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
1045 return;
1046 }
1047 1012
1048 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); 1013 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1049} 1014}
1050 1015
1051void 1016static void
1052ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, 1017ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1053 const struct ieee80211_channel_sw_ie *sw_elem, 1018 u64 timestamp, struct ieee802_11_elems *elems)
1054 struct ieee80211_bss *bss, u64 timestamp)
1055{ 1019{
1056 struct cfg80211_bss *cbss = 1020 struct ieee80211_local *local = sdata->local;
1057 container_of((void *)bss, struct cfg80211_bss, priv);
1058 struct ieee80211_channel *new_ch;
1059 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1021 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1060 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num, 1022 struct cfg80211_bss *cbss = ifmgd->associated;
1061 cbss->channel->band); 1023 struct ieee80211_bss *bss;
1062 struct ieee80211_chanctx *chanctx; 1024 struct ieee80211_chanctx *chanctx;
1025 enum ieee80211_band new_band;
1026 int new_freq;
1027 u8 new_chan_no;
1028 u8 count;
1029 u8 mode;
1030 struct ieee80211_channel *new_chan;
1031 struct cfg80211_chan_def new_chandef = {};
1032 struct cfg80211_chan_def new_vht_chandef = {};
1033 const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1034 const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
1035 int secondary_channel_offset = -1;
1063 1036
1064 ASSERT_MGD_MTX(ifmgd); 1037 ASSERT_MGD_MTX(ifmgd);
1065 1038
1066 if (!ifmgd->associated) 1039 if (!cbss)
1067 return; 1040 return;
1068 1041
1069 if (sdata->local->scanning) 1042 if (local->scanning)
1070 return; 1043 return;
1071 1044
1072 /* Disregard subsequent beacons if we are already running a timer 1045 /* disregard subsequent announcements if we are already processing */
1073 processing a CSA */
1074
1075 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED) 1046 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1076 return; 1047 return;
1077 1048
1078 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq); 1049 sec_chan_offs = elems->sec_chan_offs;
1079 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) { 1050 wide_bw_chansw_ie = elems->wide_bw_chansw_ie;
1051
1052 if (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
1053 IEEE80211_STA_DISABLE_40MHZ)) {
1054 sec_chan_offs = NULL;
1055 wide_bw_chansw_ie = NULL;
1056 }
1057
1058 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
1059 wide_bw_chansw_ie = NULL;
1060
1061 if (elems->ext_chansw_ie) {
1062 if (!ieee80211_operating_class_to_band(
1063 elems->ext_chansw_ie->new_operating_class,
1064 &new_band)) {
1065 sdata_info(sdata,
1066 "cannot understand ECSA IE operating class %d, disconnecting\n",
1067 elems->ext_chansw_ie->new_operating_class);
1068 ieee80211_queue_work(&local->hw,
1069 &ifmgd->csa_connection_drop_work);
1070 }
1071 new_chan_no = elems->ext_chansw_ie->new_ch_num;
1072 count = elems->ext_chansw_ie->count;
1073 mode = elems->ext_chansw_ie->mode;
1074 } else if (elems->ch_switch_ie) {
1075 new_band = cbss->channel->band;
1076 new_chan_no = elems->ch_switch_ie->new_ch_num;
1077 count = elems->ch_switch_ie->count;
1078 mode = elems->ch_switch_ie->mode;
1079 } else {
1080 /* nothing here we understand */
1081 return;
1082 }
1083
1084 bss = (void *)cbss->priv;
1085
1086 new_freq = ieee80211_channel_to_frequency(new_chan_no, new_band);
1087 new_chan = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1088 if (!new_chan || new_chan->flags & IEEE80211_CHAN_DISABLED) {
1080 sdata_info(sdata, 1089 sdata_info(sdata,
1081 "AP %pM switches to unsupported channel (%d MHz), disconnecting\n", 1090 "AP %pM switches to unsupported channel (%d MHz), disconnecting\n",
1082 ifmgd->associated->bssid, new_freq); 1091 ifmgd->associated->bssid, new_freq);
1083 ieee80211_queue_work(&sdata->local->hw, 1092 ieee80211_queue_work(&local->hw,
1093 &ifmgd->csa_connection_drop_work);
1094 return;
1095 }
1096
1097 if (sec_chan_offs) {
1098 secondary_channel_offset = sec_chan_offs->sec_chan_offs;
1099 } else if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
1100 /* if HT is enabled and the IE not present, it's still HT */
1101 secondary_channel_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1102 }
1103
1104 switch (secondary_channel_offset) {
1105 default:
1106 /* secondary_channel_offset was present but is invalid */
1107 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
1108 cfg80211_chandef_create(&new_chandef, new_chan,
1109 NL80211_CHAN_HT20);
1110 break;
1111 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
1112 cfg80211_chandef_create(&new_chandef, new_chan,
1113 NL80211_CHAN_HT40PLUS);
1114 break;
1115 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
1116 cfg80211_chandef_create(&new_chandef, new_chan,
1117 NL80211_CHAN_HT40MINUS);
1118 break;
1119 case -1:
1120 cfg80211_chandef_create(&new_chandef, new_chan,
1121 NL80211_CHAN_NO_HT);
1122 break;
1123 }
1124
1125 if (wide_bw_chansw_ie) {
1126 new_vht_chandef.chan = new_chan;
1127 new_vht_chandef.center_freq1 =
1128 ieee80211_channel_to_frequency(
1129 wide_bw_chansw_ie->new_center_freq_seg0,
1130 new_band);
1131
1132 switch (wide_bw_chansw_ie->new_channel_width) {
1133 default:
1134 /* hmmm, ignore VHT and use HT if present */
1135 case IEEE80211_VHT_CHANWIDTH_USE_HT:
1136 new_vht_chandef.chan = NULL;
1137 break;
1138 case IEEE80211_VHT_CHANWIDTH_80MHZ:
1139 new_vht_chandef.width = NL80211_CHAN_WIDTH_80;
1140 break;
1141 case IEEE80211_VHT_CHANWIDTH_160MHZ:
1142 new_vht_chandef.width = NL80211_CHAN_WIDTH_160;
1143 break;
1144 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1145 /* field is otherwise reserved */
1146 new_vht_chandef.center_freq2 =
1147 ieee80211_channel_to_frequency(
1148 wide_bw_chansw_ie->new_center_freq_seg1,
1149 new_band);
1150 new_vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1151 break;
1152 }
1153 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
1154 new_vht_chandef.width == NL80211_CHAN_WIDTH_80P80)
1155 chandef_downgrade(&new_vht_chandef);
1156 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
1157 new_vht_chandef.width == NL80211_CHAN_WIDTH_160)
1158 chandef_downgrade(&new_vht_chandef);
1159 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
1160 new_vht_chandef.width > NL80211_CHAN_WIDTH_20)
1161 chandef_downgrade(&new_vht_chandef);
1162 }
1163
1164 /* if VHT data is there validate & use it */
1165 if (new_vht_chandef.chan) {
1166 if (!cfg80211_chandef_compatible(&new_vht_chandef,
1167 &new_chandef)) {
1168 sdata_info(sdata,
1169 "AP %pM CSA has inconsistent channel data, disconnecting\n",
1170 ifmgd->associated->bssid);
1171 ieee80211_queue_work(&local->hw,
1172 &ifmgd->csa_connection_drop_work);
1173 return;
1174 }
1175 new_chandef = new_vht_chandef;
1176 }
1177
1178 if (!cfg80211_chandef_usable(local->hw.wiphy, &new_chandef,
1179 IEEE80211_CHAN_DISABLED)) {
1180 sdata_info(sdata,
1181 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1182 ifmgd->associated->bssid, new_freq,
1183 new_chandef.width, new_chandef.center_freq1,
1184 new_chandef.center_freq2);
1185 ieee80211_queue_work(&local->hw,
1084 &ifmgd->csa_connection_drop_work); 1186 &ifmgd->csa_connection_drop_work);
1085 return; 1187 return;
1086 } 1188 }
1087 1189
1088 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED; 1190 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
1089 1191
1090 if (sdata->local->use_chanctx) { 1192 if (local->use_chanctx) {
1091 sdata_info(sdata, 1193 sdata_info(sdata,
1092 "not handling channel switch with channel contexts\n"); 1194 "not handling channel switch with channel contexts\n");
1093 ieee80211_queue_work(&sdata->local->hw, 1195 ieee80211_queue_work(&local->hw,
1094 &ifmgd->csa_connection_drop_work); 1196 &ifmgd->csa_connection_drop_work);
1095 return; 1197 return;
1096 } 1198 }
1097 1199
1098 mutex_lock(&sdata->local->chanctx_mtx); 1200 mutex_lock(&local->chanctx_mtx);
1099 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) { 1201 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
1100 mutex_unlock(&sdata->local->chanctx_mtx); 1202 mutex_unlock(&local->chanctx_mtx);
1101 return; 1203 return;
1102 } 1204 }
1103 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf), 1205 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
@@ -1105,39 +1207,39 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1105 if (chanctx->refcount > 1) { 1207 if (chanctx->refcount > 1) {
1106 sdata_info(sdata, 1208 sdata_info(sdata,
1107 "channel switch with multiple interfaces on the same channel, disconnecting\n"); 1209 "channel switch with multiple interfaces on the same channel, disconnecting\n");
1108 ieee80211_queue_work(&sdata->local->hw, 1210 ieee80211_queue_work(&local->hw,
1109 &ifmgd->csa_connection_drop_work); 1211 &ifmgd->csa_connection_drop_work);
1110 mutex_unlock(&sdata->local->chanctx_mtx); 1212 mutex_unlock(&local->chanctx_mtx);
1111 return; 1213 return;
1112 } 1214 }
1113 mutex_unlock(&sdata->local->chanctx_mtx); 1215 mutex_unlock(&local->chanctx_mtx);
1114 1216
1115 sdata->local->csa_channel = new_ch; 1217 local->csa_chandef = new_chandef;
1116 1218
1117 if (sw_elem->mode) 1219 if (mode)
1118 ieee80211_stop_queues_by_reason(&sdata->local->hw, 1220 ieee80211_stop_queues_by_reason(&local->hw,
1221 IEEE80211_MAX_QUEUE_MAP,
1119 IEEE80211_QUEUE_STOP_REASON_CSA); 1222 IEEE80211_QUEUE_STOP_REASON_CSA);
1120 1223
1121 if (sdata->local->ops->channel_switch) { 1224 if (local->ops->channel_switch) {
1122 /* use driver's channel switch callback */ 1225 /* use driver's channel switch callback */
1123 struct ieee80211_channel_switch ch_switch = { 1226 struct ieee80211_channel_switch ch_switch = {
1124 .timestamp = timestamp, 1227 .timestamp = timestamp,
1125 .block_tx = sw_elem->mode, 1228 .block_tx = mode,
1126 .channel = new_ch, 1229 .chandef = new_chandef,
1127 .count = sw_elem->count, 1230 .count = count,
1128 }; 1231 };
1129 1232
1130 drv_channel_switch(sdata->local, &ch_switch); 1233 drv_channel_switch(local, &ch_switch);
1131 return; 1234 return;
1132 } 1235 }
1133 1236
1134 /* channel switch handled in software */ 1237 /* channel switch handled in software */
1135 if (sw_elem->count <= 1) 1238 if (count <= 1)
1136 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); 1239 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1137 else 1240 else
1138 mod_timer(&ifmgd->chswitch_timer, 1241 mod_timer(&ifmgd->chswitch_timer,
1139 TU_TO_EXP_TIME(sw_elem->count * 1242 TU_TO_EXP_TIME(count * cbss->beacon_interval));
1140 cbss->beacon_interval));
1141} 1243}
1142 1244
1143static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, 1245static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
@@ -1383,6 +1485,7 @@ void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1383 } 1485 }
1384 1486
1385 ieee80211_wake_queues_by_reason(&local->hw, 1487 ieee80211_wake_queues_by_reason(&local->hw,
1488 IEEE80211_MAX_QUEUE_MAP,
1386 IEEE80211_QUEUE_STOP_REASON_PS); 1489 IEEE80211_QUEUE_STOP_REASON_PS);
1387} 1490}
1388 1491
@@ -1435,16 +1538,14 @@ void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1435 1538
1436 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && 1539 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
1437 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { 1540 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1438 netif_tx_stop_all_queues(sdata->dev); 1541 if (drv_tx_frames_pending(local)) {
1439
1440 if (drv_tx_frames_pending(local))
1441 mod_timer(&local->dynamic_ps_timer, jiffies + 1542 mod_timer(&local->dynamic_ps_timer, jiffies +
1442 msecs_to_jiffies( 1543 msecs_to_jiffies(
1443 local->hw.conf.dynamic_ps_timeout)); 1544 local->hw.conf.dynamic_ps_timeout));
1444 else { 1545 } else {
1445 ieee80211_send_nullfunc(local, sdata, 1); 1546 ieee80211_send_nullfunc(local, sdata, 1);
1446 /* Flush to get the tx status of nullfunc frame */ 1547 /* Flush to get the tx status of nullfunc frame */
1447 drv_flush(local, false); 1548 ieee80211_flush_queues(local, sdata);
1448 } 1549 }
1449 } 1550 }
1450 1551
@@ -1455,9 +1556,6 @@ void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1455 local->hw.conf.flags |= IEEE80211_CONF_PS; 1556 local->hw.conf.flags |= IEEE80211_CONF_PS;
1456 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 1557 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1457 } 1558 }
1458
1459 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1460 netif_tx_wake_all_queues(sdata->dev);
1461} 1559}
1462 1560
1463void ieee80211_dynamic_ps_timer(unsigned long data) 1561void ieee80211_dynamic_ps_timer(unsigned long data)
@@ -1563,6 +1661,7 @@ static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
1563 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); 1661 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1564 params.cw_min = ecw2cw(pos[1] & 0x0f); 1662 params.cw_min = ecw2cw(pos[1] & 0x0f);
1565 params.txop = get_unaligned_le16(pos + 2); 1663 params.txop = get_unaligned_le16(pos + 2);
1664 params.acm = acm;
1566 params.uapsd = uapsd; 1665 params.uapsd = uapsd;
1567 1666
1568 mlme_dbg(sdata, 1667 mlme_dbg(sdata,
@@ -1650,7 +1749,7 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
1650 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value); 1749 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
1651 1750
1652 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec( 1751 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
1653 IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int)); 1752 beacon_loss_count * bss_conf->beacon_int));
1654 1753
1655 sdata->u.mgd.associated = cbss; 1754 sdata->u.mgd.associated = cbss;
1656 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN); 1755 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
@@ -1663,18 +1762,17 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
1663 rcu_read_lock(); 1762 rcu_read_lock();
1664 ies = rcu_dereference(cbss->ies); 1763 ies = rcu_dereference(cbss->ies);
1665 if (ies) { 1764 if (ies) {
1666 u8 noa[2];
1667 int ret; 1765 int ret;
1668 1766
1669 ret = cfg80211_get_p2p_attr( 1767 ret = cfg80211_get_p2p_attr(
1670 ies->data, ies->len, 1768 ies->data, ies->len,
1671 IEEE80211_P2P_ATTR_ABSENCE_NOTICE, 1769 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
1672 noa, sizeof(noa)); 1770 (u8 *) &bss_conf->p2p_noa_attr,
1771 sizeof(bss_conf->p2p_noa_attr));
1673 if (ret >= 2) { 1772 if (ret >= 2) {
1674 bss_conf->p2p_oppps = noa[1] & 0x80; 1773 sdata->u.mgd.p2p_noa_index =
1675 bss_conf->p2p_ctwindow = noa[1] & 0x7f; 1774 bss_conf->p2p_noa_attr.index;
1676 bss_info_changed |= BSS_CHANGED_P2P_PS; 1775 bss_info_changed |= BSS_CHANGED_P2P_PS;
1677 sdata->u.mgd.p2p_noa_index = noa[0];
1678 } 1776 }
1679 } 1777 }
1680 rcu_read_unlock(); 1778 rcu_read_unlock();
@@ -1718,7 +1816,6 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
1718 ieee80211_recalc_smps(sdata); 1816 ieee80211_recalc_smps(sdata);
1719 ieee80211_recalc_ps_vif(sdata); 1817 ieee80211_recalc_ps_vif(sdata);
1720 1818
1721 netif_tx_start_all_queues(sdata->dev);
1722 netif_carrier_on(sdata->dev); 1819 netif_carrier_on(sdata->dev);
1723} 1820}
1724 1821
@@ -1741,22 +1838,6 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1741 ieee80211_stop_poll(sdata); 1838 ieee80211_stop_poll(sdata);
1742 1839
1743 ifmgd->associated = NULL; 1840 ifmgd->associated = NULL;
1744
1745 /*
1746 * we need to commit the associated = NULL change because the
1747 * scan code uses that to determine whether this iface should
1748 * go to/wake up from powersave or not -- and could otherwise
1749 * wake the queues erroneously.
1750 */
1751 smp_mb();
1752
1753 /*
1754 * Thus, we can only afterwards stop the queues -- to account
1755 * for the case where another CPU is finishing a scan at this
1756 * time -- we don't want the scan code to enable queues.
1757 */
1758
1759 netif_tx_stop_all_queues(sdata->dev);
1760 netif_carrier_off(sdata->dev); 1841 netif_carrier_off(sdata->dev);
1761 1842
1762 /* 1843 /*
@@ -1775,7 +1856,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1775 1856
1776 /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */ 1857 /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */
1777 if (tx) 1858 if (tx)
1778 drv_flush(local, false); 1859 ieee80211_flush_queues(local, sdata);
1779 1860
1780 /* deauthenticate/disassociate now */ 1861 /* deauthenticate/disassociate now */
1781 if (tx || frame_buf) 1862 if (tx || frame_buf)
@@ -1784,7 +1865,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1784 1865
1785 /* flush out frame */ 1866 /* flush out frame */
1786 if (tx) 1867 if (tx)
1787 drv_flush(local, false); 1868 ieee80211_flush_queues(local, sdata);
1788 1869
1789 /* clear bssid only after building the needed mgmt frames */ 1870 /* clear bssid only after building the needed mgmt frames */
1790 memset(ifmgd->bssid, 0, ETH_ALEN); 1871 memset(ifmgd->bssid, 0, ETH_ALEN);
@@ -1799,12 +1880,15 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1799 changed |= BSS_CHANGED_ASSOC; 1880 changed |= BSS_CHANGED_ASSOC;
1800 sdata->vif.bss_conf.assoc = false; 1881 sdata->vif.bss_conf.assoc = false;
1801 1882
1802 sdata->vif.bss_conf.p2p_ctwindow = 0; 1883 ifmgd->p2p_noa_index = -1;
1803 sdata->vif.bss_conf.p2p_oppps = false; 1884 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1885 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
1804 1886
1805 /* on the next assoc, re-program HT parameters */ 1887 /* on the next assoc, re-program HT/VHT parameters */
1806 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa)); 1888 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
1807 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask)); 1889 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
1890 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
1891 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
1808 1892
1809 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL; 1893 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
1810 1894
@@ -1830,8 +1914,6 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1830 del_timer_sync(&sdata->u.mgd.timer); 1914 del_timer_sync(&sdata->u.mgd.timer);
1831 del_timer_sync(&sdata->u.mgd.chswitch_timer); 1915 del_timer_sync(&sdata->u.mgd.chswitch_timer);
1832 1916
1833 sdata->u.mgd.timers_running = 0;
1834
1835 sdata->vif.bss_conf.dtim_period = 0; 1917 sdata->vif.bss_conf.dtim_period = 0;
1836 1918
1837 ifmgd->flags = 0; 1919 ifmgd->flags = 0;
@@ -1956,7 +2038,7 @@ static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1956 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); 2038 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
1957 run_again(ifmgd, ifmgd->probe_timeout); 2039 run_again(ifmgd, ifmgd->probe_timeout);
1958 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) 2040 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
1959 drv_flush(sdata->local, false); 2041 ieee80211_flush_queues(sdata->local, sdata);
1960} 2042}
1961 2043
1962static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, 2044static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
@@ -1980,12 +2062,15 @@ static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1980 goto out; 2062 goto out;
1981 } 2063 }
1982 2064
1983 if (beacon) 2065 if (beacon) {
1984 mlme_dbg_ratelimited(sdata, 2066 mlme_dbg_ratelimited(sdata,
1985 "detected beacon loss from AP - probing\n"); 2067 "detected beacon loss from AP (missed %d beacons) - probing\n",
2068 beacon_loss_count);
1986 2069
1987 ieee80211_cqm_rssi_notify(&sdata->vif, 2070 ieee80211_cqm_rssi_notify(&sdata->vif,
1988 NL80211_CQM_RSSI_BEACON_LOSS_EVENT, GFP_KERNEL); 2071 NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
2072 GFP_KERNEL);
2073 }
1989 2074
1990 /* 2075 /*
1991 * The driver/our work has already reported this event or the 2076 * The driver/our work has already reported this event or the
@@ -2079,6 +2164,7 @@ static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2079 true, frame_buf); 2164 true, frame_buf);
2080 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; 2165 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
2081 ieee80211_wake_queues_by_reason(&sdata->local->hw, 2166 ieee80211_wake_queues_by_reason(&sdata->local->hw,
2167 IEEE80211_MAX_QUEUE_MAP,
2082 IEEE80211_QUEUE_STOP_REASON_CSA); 2168 IEEE80211_QUEUE_STOP_REASON_CSA);
2083 mutex_unlock(&ifmgd->mtx); 2169 mutex_unlock(&ifmgd->mtx);
2084 2170
@@ -2130,7 +2216,6 @@ void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2130 2216
2131 trace_api_beacon_loss(sdata); 2217 trace_api_beacon_loss(sdata);
2132 2218
2133 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
2134 sdata->u.mgd.connection_loss = false; 2219 sdata->u.mgd.connection_loss = false;
2135 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); 2220 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2136} 2221}
@@ -2180,7 +2265,7 @@ static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2180 u32 tx_flags = 0; 2265 u32 tx_flags = 0;
2181 2266
2182 pos = mgmt->u.auth.variable; 2267 pos = mgmt->u.auth.variable;
2183 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); 2268 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2184 if (!elems.challenge) 2269 if (!elems.challenge)
2185 return; 2270 return;
2186 auth_data->expected_transaction = 4; 2271 auth_data->expected_transaction = 4;
@@ -2445,7 +2530,7 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2445 } 2530 }
2446 2531
2447 pos = mgmt->u.assoc_resp.variable; 2532 pos = mgmt->u.assoc_resp.variable;
2448 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); 2533 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2449 2534
2450 if (!elems.supp_rates) { 2535 if (!elems.supp_rates) {
2451 sdata_info(sdata, "no SuppRates element in AssocResp\n"); 2536 sdata_info(sdata, "no SuppRates element in AssocResp\n");
@@ -2614,13 +2699,13 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2614 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); 2699 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
2615 2700
2616 pos = mgmt->u.assoc_resp.variable; 2701 pos = mgmt->u.assoc_resp.variable;
2617 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); 2702 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2618 2703
2619 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && 2704 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
2620 elems.timeout_int && elems.timeout_int_len == 5 && 2705 elems.timeout_int &&
2621 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) { 2706 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
2622 u32 tu, ms; 2707 u32 tu, ms;
2623 tu = get_unaligned_le32(elems.timeout_int + 1); 2708 tu = le32_to_cpu(elems.timeout_int->value);
2624 ms = tu * 1024 / 1000; 2709 ms = tu * 1024 / 1000;
2625 sdata_info(sdata, 2710 sdata_info(sdata,
2626 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n", 2711 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
@@ -2669,6 +2754,8 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
2669 struct ieee80211_channel *channel; 2754 struct ieee80211_channel *channel;
2670 bool need_ps = false; 2755 bool need_ps = false;
2671 2756
2757 lockdep_assert_held(&sdata->u.mgd.mtx);
2758
2672 if ((sdata->u.mgd.associated && 2759 if ((sdata->u.mgd.associated &&
2673 ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) || 2760 ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) ||
2674 (sdata->u.mgd.assoc_data && 2761 (sdata->u.mgd.assoc_data &&
@@ -2683,7 +2770,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
2683 } 2770 }
2684 } 2771 }
2685 2772
2686 if (elems->ds_params && elems->ds_params_len == 1) 2773 if (elems->ds_params)
2687 freq = ieee80211_channel_to_frequency(elems->ds_params[0], 2774 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
2688 rx_status->band); 2775 rx_status->band);
2689 else 2776 else
@@ -2699,7 +2786,8 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
2699 if (bss) 2786 if (bss)
2700 ieee80211_rx_bss_put(local, bss); 2787 ieee80211_rx_bss_put(local, bss);
2701 2788
2702 if (!sdata->u.mgd.associated) 2789 if (!sdata->u.mgd.associated ||
2790 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid))
2703 return; 2791 return;
2704 2792
2705 if (need_ps) { 2793 if (need_ps) {
@@ -2708,10 +2796,8 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
2708 mutex_unlock(&local->iflist_mtx); 2796 mutex_unlock(&local->iflist_mtx);
2709 } 2797 }
2710 2798
2711 if (elems->ch_switch_ie && 2799 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime, elems);
2712 memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, ETH_ALEN) == 0) 2800
2713 ieee80211_sta_process_chanswitch(sdata, elems->ch_switch_ie,
2714 bss, rx_status->mactime);
2715} 2801}
2716 2802
2717 2803
@@ -2736,7 +2822,7 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
2736 return; 2822 return;
2737 2823
2738 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, 2824 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
2739 &elems); 2825 false, &elems);
2740 2826
2741 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems); 2827 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2742 2828
@@ -2819,7 +2905,7 @@ ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2819 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon && 2905 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
2820 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) { 2906 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2821 ieee802_11_parse_elems(mgmt->u.beacon.variable, 2907 ieee802_11_parse_elems(mgmt->u.beacon.variable,
2822 len - baselen, &elems); 2908 len - baselen, false, &elems);
2823 2909
2824 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems); 2910 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2825 ifmgd->assoc_data->have_beacon = true; 2911 ifmgd->assoc_data->have_beacon = true;
@@ -2929,7 +3015,7 @@ ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2929 3015
2930 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); 3016 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
2931 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable, 3017 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
2932 len - baselen, &elems, 3018 len - baselen, false, &elems,
2933 care_about_ies, ncrc); 3019 care_about_ies, ncrc);
2934 3020
2935 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { 3021 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
@@ -2961,22 +3047,30 @@ ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2961 } 3047 }
2962 3048
2963 if (sdata->vif.p2p) { 3049 if (sdata->vif.p2p) {
2964 u8 noa[2]; 3050 struct ieee80211_p2p_noa_attr noa = {};
2965 int ret; 3051 int ret;
2966 3052
2967 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable, 3053 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
2968 len - baselen, 3054 len - baselen,
2969 IEEE80211_P2P_ATTR_ABSENCE_NOTICE, 3055 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2970 noa, sizeof(noa)); 3056 (u8 *) &noa, sizeof(noa));
2971 if (ret >= 2 && sdata->u.mgd.p2p_noa_index != noa[0]) { 3057 if (ret >= 2) {
2972 bss_conf->p2p_oppps = noa[1] & 0x80; 3058 if (sdata->u.mgd.p2p_noa_index != noa.index) {
2973 bss_conf->p2p_ctwindow = noa[1] & 0x7f; 3059 /* valid noa_attr and index changed */
3060 sdata->u.mgd.p2p_noa_index = noa.index;
3061 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3062 changed |= BSS_CHANGED_P2P_PS;
3063 /*
3064 * make sure we update all information, the CRC
3065 * mechanism doesn't look at P2P attributes.
3066 */
3067 ifmgd->beacon_crc_valid = false;
3068 }
3069 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3070 /* noa_attr not found and we had valid noa_attr before */
3071 sdata->u.mgd.p2p_noa_index = -1;
3072 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
2974 changed |= BSS_CHANGED_P2P_PS; 3073 changed |= BSS_CHANGED_P2P_PS;
2975 sdata->u.mgd.p2p_noa_index = noa[0];
2976 /*
2977 * make sure we update all information, the CRC
2978 * mechanism doesn't look at P2P attributes.
2979 */
2980 ifmgd->beacon_crc_valid = false; 3074 ifmgd->beacon_crc_valid = false;
2981 } 3075 }
2982 } 3076 }
@@ -3018,7 +3112,7 @@ ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3018 changed |= BSS_CHANGED_DTIM_PERIOD; 3112 changed |= BSS_CHANGED_DTIM_PERIOD;
3019 } 3113 }
3020 3114
3021 if (elems.erp_info && elems.erp_info_len >= 1) { 3115 if (elems.erp_info) {
3022 erp_valid = true; 3116 erp_valid = true;
3023 erp_value = elems.erp_info[0]; 3117 erp_value = elems.erp_info[0];
3024 } else { 3118 } else {
@@ -3068,6 +3162,8 @@ void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3068 enum rx_mgmt_action rma = RX_MGMT_NONE; 3162 enum rx_mgmt_action rma = RX_MGMT_NONE;
3069 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN]; 3163 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3070 u16 fc; 3164 u16 fc;
3165 struct ieee802_11_elems elems;
3166 int ies_len;
3071 3167
3072 rx_status = (struct ieee80211_rx_status *) skb->cb; 3168 rx_status = (struct ieee80211_rx_status *) skb->cb;
3073 mgmt = (struct ieee80211_mgmt *) skb->data; 3169 mgmt = (struct ieee80211_mgmt *) skb->data;
@@ -3097,14 +3193,48 @@ void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3097 rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss); 3193 rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss);
3098 break; 3194 break;
3099 case IEEE80211_STYPE_ACTION: 3195 case IEEE80211_STYPE_ACTION:
3100 switch (mgmt->u.action.category) { 3196 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
3101 case WLAN_CATEGORY_SPECTRUM_MGMT: 3197 ies_len = skb->len -
3198 offsetof(struct ieee80211_mgmt,
3199 u.action.u.chan_switch.variable);
3200
3201 if (ies_len < 0)
3202 break;
3203
3204 ieee802_11_parse_elems(
3205 mgmt->u.action.u.chan_switch.variable,
3206 ies_len, true, &elems);
3207
3208 if (elems.parse_error)
3209 break;
3210
3102 ieee80211_sta_process_chanswitch(sdata, 3211 ieee80211_sta_process_chanswitch(sdata,
3103 &mgmt->u.action.u.chan_switch.sw_elem, 3212 rx_status->mactime,
3104 (void *)ifmgd->associated->priv, 3213 &elems);
3105 rx_status->mactime); 3214 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3106 break; 3215 ies_len = skb->len -
3216 offsetof(struct ieee80211_mgmt,
3217 u.action.u.ext_chan_switch.variable);
3218
3219 if (ies_len < 0)
3220 break;
3221
3222 ieee802_11_parse_elems(
3223 mgmt->u.action.u.ext_chan_switch.variable,
3224 ies_len, true, &elems);
3225
3226 if (elems.parse_error)
3227 break;
3228
3229 /* for the handling code pretend this was also an IE */
3230 elems.ext_chansw_ie =
3231 &mgmt->u.action.u.ext_chan_switch.data;
3232
3233 ieee80211_sta_process_chanswitch(sdata,
3234 rx_status->mactime,
3235 &elems);
3107 } 3236 }
3237 break;
3108 } 3238 }
3109 mutex_unlock(&ifmgd->mtx); 3239 mutex_unlock(&ifmgd->mtx);
3110 3240
@@ -3140,15 +3270,8 @@ static void ieee80211_sta_timer(unsigned long data)
3140{ 3270{
3141 struct ieee80211_sub_if_data *sdata = 3271 struct ieee80211_sub_if_data *sdata =
3142 (struct ieee80211_sub_if_data *) data; 3272 (struct ieee80211_sub_if_data *) data;
3143 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3144 struct ieee80211_local *local = sdata->local;
3145 3273
3146 if (local->quiescing) { 3274 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
3147 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
3148 return;
3149 }
3150
3151 ieee80211_queue_work(&local->hw, &sdata->work);
3152} 3275}
3153 3276
3154static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, 3277static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
@@ -3500,72 +3623,6 @@ static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3500 } 3623 }
3501} 3624}
3502 3625
3503#ifdef CONFIG_PM
3504void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
3505{
3506 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3507
3508 /*
3509 * Stop timers before deleting work items, as timers
3510 * could race and re-add the work-items. They will be
3511 * re-established on connection.
3512 */
3513 del_timer_sync(&ifmgd->conn_mon_timer);
3514 del_timer_sync(&ifmgd->bcn_mon_timer);
3515
3516 /*
3517 * we need to use atomic bitops for the running bits
3518 * only because both timers might fire at the same
3519 * time -- the code here is properly synchronised.
3520 */
3521
3522 cancel_work_sync(&ifmgd->request_smps_work);
3523
3524 cancel_work_sync(&ifmgd->monitor_work);
3525 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
3526 cancel_work_sync(&ifmgd->csa_connection_drop_work);
3527 if (del_timer_sync(&ifmgd->timer))
3528 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
3529
3530 if (del_timer_sync(&ifmgd->chswitch_timer))
3531 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
3532 cancel_work_sync(&ifmgd->chswitch_work);
3533}
3534
3535void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
3536{
3537 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3538
3539 mutex_lock(&ifmgd->mtx);
3540 if (!ifmgd->associated) {
3541 mutex_unlock(&ifmgd->mtx);
3542 return;
3543 }
3544
3545 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
3546 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
3547 mlme_dbg(sdata, "driver requested disconnect after resume\n");
3548 ieee80211_sta_connection_lost(sdata,
3549 ifmgd->associated->bssid,
3550 WLAN_REASON_UNSPECIFIED,
3551 true);
3552 mutex_unlock(&ifmgd->mtx);
3553 return;
3554 }
3555 mutex_unlock(&ifmgd->mtx);
3556
3557 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
3558 add_timer(&ifmgd->timer);
3559 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
3560 add_timer(&ifmgd->chswitch_timer);
3561 ieee80211_sta_reset_beacon_monitor(sdata);
3562
3563 mutex_lock(&sdata->local->mtx);
3564 ieee80211_restart_sta_timer(sdata);
3565 mutex_unlock(&sdata->local->mtx);
3566}
3567#endif
3568
3569/* interface setup */ 3626/* interface setup */
3570void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) 3627void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
3571{ 3628{
@@ -3590,8 +3647,9 @@ void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
3590 3647
3591 ifmgd->flags = 0; 3648 ifmgd->flags = 0;
3592 ifmgd->powersave = sdata->wdev.ps; 3649 ifmgd->powersave = sdata->wdev.ps;
3593 ifmgd->uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES; 3650 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
3594 ifmgd->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN; 3651 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
3652 ifmgd->p2p_noa_index = -1;
3595 3653
3596 mutex_init(&ifmgd->mtx); 3654 mutex_init(&ifmgd->mtx);
3597 3655
@@ -4089,6 +4147,9 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
4089 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; 4147 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4090 } 4148 }
4091 4149
4150 if (req->flags & ASSOC_REQ_DISABLE_VHT)
4151 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4152
4092 /* Also disable HT if we don't support it or the AP doesn't use WMM */ 4153 /* Also disable HT if we don't support it or the AP doesn't use WMM */
4093 sband = local->hw.wiphy->bands[req->bss->channel->band]; 4154 sband = local->hw.wiphy->bands[req->bss->channel->band];
4094 if (!sband->ht_cap.ht_supported || 4155 if (!sband->ht_cap.ht_supported ||
@@ -4112,6 +4173,10 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
4112 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask, 4173 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
4113 sizeof(ifmgd->ht_capa_mask)); 4174 sizeof(ifmgd->ht_capa_mask));
4114 4175
4176 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
4177 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
4178 sizeof(ifmgd->vht_capa_mask));
4179
4115 if (req->ie && req->ie_len) { 4180 if (req->ie && req->ie_len) {
4116 memcpy(assoc_data->ie, req->ie, req->ie_len); 4181 memcpy(assoc_data->ie, req->ie, req->ie_len);
4117 assoc_data->ie_len = req->ie_len; 4182 assoc_data->ie_len = req->ie_len;
@@ -4149,7 +4214,8 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
4149 rcu_read_unlock(); 4214 rcu_read_unlock();
4150 4215
4151 if (bss->wmm_used && bss->uapsd_supported && 4216 if (bss->wmm_used && bss->uapsd_supported &&
4152 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) { 4217 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD) &&
4218 sdata->wmm_acm != 0xff) {
4153 assoc_data->uapsd = true; 4219 assoc_data->uapsd = true;
4154 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; 4220 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
4155 } else { 4221 } else {
diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c
index 430bd254e496..acd1f71adc03 100644
--- a/net/mac80211/offchannel.c
+++ b/net/mac80211/offchannel.c
@@ -118,9 +118,9 @@ void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local)
118 * Stop queues and transmit all frames queued by the driver 118 * Stop queues and transmit all frames queued by the driver
119 * before sending nullfunc to enable powersave at the AP. 119 * before sending nullfunc to enable powersave at the AP.
120 */ 120 */
121 ieee80211_stop_queues_by_reason(&local->hw, 121 ieee80211_stop_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
122 IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL); 122 IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL);
123 drv_flush(local, false); 123 ieee80211_flush_queues(local, NULL);
124 124
125 mutex_lock(&local->iflist_mtx); 125 mutex_lock(&local->iflist_mtx);
126 list_for_each_entry(sdata, &local->interfaces, list) { 126 list_for_each_entry(sdata, &local->interfaces, list) {
@@ -181,7 +181,7 @@ void ieee80211_offchannel_return(struct ieee80211_local *local)
181 } 181 }
182 mutex_unlock(&local->iflist_mtx); 182 mutex_unlock(&local->iflist_mtx);
183 183
184 ieee80211_wake_queues_by_reason(&local->hw, 184 ieee80211_wake_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
185 IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL); 185 IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL);
186} 186}
187 187
@@ -277,7 +277,7 @@ void ieee80211_start_next_roc(struct ieee80211_local *local)
277 duration = 10; 277 duration = 10;
278 278
279 ret = drv_remain_on_channel(local, roc->sdata, roc->chan, 279 ret = drv_remain_on_channel(local, roc->sdata, roc->chan,
280 duration); 280 duration, roc->type);
281 281
282 roc->started = true; 282 roc->started = true;
283 283
@@ -382,7 +382,7 @@ void ieee80211_sw_roc_work(struct work_struct *work)
382 ieee80211_roc_notify_destroy(roc, !roc->abort); 382 ieee80211_roc_notify_destroy(roc, !roc->abort);
383 383
384 if (started) { 384 if (started) {
385 drv_flush(local, false); 385 ieee80211_flush_queues(local, NULL);
386 386
387 local->tmp_channel = NULL; 387 local->tmp_channel = NULL;
388 ieee80211_hw_config(local, 0); 388 ieee80211_hw_config(local, 0);
@@ -445,15 +445,15 @@ void ieee80211_roc_setup(struct ieee80211_local *local)
445 INIT_LIST_HEAD(&local->roc_list); 445 INIT_LIST_HEAD(&local->roc_list);
446} 446}
447 447
448void ieee80211_roc_purge(struct ieee80211_sub_if_data *sdata) 448void ieee80211_roc_purge(struct ieee80211_local *local,
449 struct ieee80211_sub_if_data *sdata)
449{ 450{
450 struct ieee80211_local *local = sdata->local;
451 struct ieee80211_roc_work *roc, *tmp; 451 struct ieee80211_roc_work *roc, *tmp;
452 LIST_HEAD(tmp_list); 452 LIST_HEAD(tmp_list);
453 453
454 mutex_lock(&local->mtx); 454 mutex_lock(&local->mtx);
455 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) { 455 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
456 if (roc->sdata != sdata) 456 if (sdata && roc->sdata != sdata)
457 continue; 457 continue;
458 458
459 if (roc->started && local->ops->remain_on_channel) { 459 if (roc->started && local->ops->remain_on_channel) {
diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
index d0275f34bf70..7fc5d0d8149a 100644
--- a/net/mac80211/pm.c
+++ b/net/mac80211/pm.c
@@ -6,32 +6,11 @@
6#include "driver-ops.h" 6#include "driver-ops.h"
7#include "led.h" 7#include "led.h"
8 8
9/* return value indicates whether the driver should be further notified */
10static void ieee80211_quiesce(struct ieee80211_sub_if_data *sdata)
11{
12 switch (sdata->vif.type) {
13 case NL80211_IFTYPE_STATION:
14 ieee80211_sta_quiesce(sdata);
15 break;
16 case NL80211_IFTYPE_ADHOC:
17 ieee80211_ibss_quiesce(sdata);
18 break;
19 case NL80211_IFTYPE_MESH_POINT:
20 ieee80211_mesh_quiesce(sdata);
21 break;
22 default:
23 break;
24 }
25
26 cancel_work_sync(&sdata->work);
27}
28
29int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) 9int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
30{ 10{
31 struct ieee80211_local *local = hw_to_local(hw); 11 struct ieee80211_local *local = hw_to_local(hw);
32 struct ieee80211_sub_if_data *sdata; 12 struct ieee80211_sub_if_data *sdata;
33 struct sta_info *sta; 13 struct sta_info *sta;
34 struct ieee80211_chanctx *ctx;
35 14
36 if (!local->open_count) 15 if (!local->open_count)
37 goto suspend; 16 goto suspend;
@@ -40,6 +19,10 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
40 19
41 ieee80211_dfs_cac_cancel(local); 20 ieee80211_dfs_cac_cancel(local);
42 21
22 ieee80211_roc_purge(local, NULL);
23
24 ieee80211_del_virtual_monitor(local);
25
43 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { 26 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
44 mutex_lock(&local->sta_mtx); 27 mutex_lock(&local->sta_mtx);
45 list_for_each_entry(sta, &local->sta_list, list) { 28 list_for_each_entry(sta, &local->sta_list, list) {
@@ -51,12 +34,14 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
51 } 34 }
52 35
53 ieee80211_stop_queues_by_reason(hw, 36 ieee80211_stop_queues_by_reason(hw,
54 IEEE80211_QUEUE_STOP_REASON_SUSPEND); 37 IEEE80211_MAX_QUEUE_MAP,
38 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
55 39
56 /* flush out all packets */ 40 /* flush out all packets and station cleanup call_rcu()s */
57 synchronize_net(); 41 synchronize_net();
42 rcu_barrier();
58 43
59 drv_flush(local, false); 44 ieee80211_flush_queues(local, NULL);
60 45
61 local->quiescing = true; 46 local->quiescing = true;
62 /* make quiescing visible to timers everywhere */ 47 /* make quiescing visible to timers everywhere */
@@ -89,23 +74,17 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89 mutex_unlock(&local->sta_mtx); 74 mutex_unlock(&local->sta_mtx);
90 } 75 }
91 ieee80211_wake_queues_by_reason(hw, 76 ieee80211_wake_queues_by_reason(hw,
77 IEEE80211_MAX_QUEUE_MAP,
92 IEEE80211_QUEUE_STOP_REASON_SUSPEND); 78 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
93 return err; 79 return err;
94 } else if (err > 0) { 80 } else if (err > 0) {
95 WARN_ON(err != 1); 81 WARN_ON(err != 1);
96 local->wowlan = false; 82 return err;
97 } else { 83 } else {
98 list_for_each_entry(sdata, &local->interfaces, list)
99 if (ieee80211_sdata_running(sdata))
100 ieee80211_quiesce(sdata);
101 goto suspend; 84 goto suspend;
102 } 85 }
103 } 86 }
104 87
105 /* disable keys */
106 list_for_each_entry(sdata, &local->interfaces, list)
107 ieee80211_disable_keys(sdata);
108
109 /* tear down aggregation sessions and remove STAs */ 88 /* tear down aggregation sessions and remove STAs */
110 mutex_lock(&local->sta_mtx); 89 mutex_lock(&local->sta_mtx);
111 list_for_each_entry(sta, &local->sta_list, list) { 90 list_for_each_entry(sta, &local->sta_list, list) {
@@ -117,100 +96,21 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
117 WARN_ON(drv_sta_state(local, sta->sdata, sta, 96 WARN_ON(drv_sta_state(local, sta->sdata, sta,
118 state, state - 1)); 97 state, state - 1));
119 } 98 }
120
121 mesh_plink_quiesce(sta);
122 } 99 }
123 mutex_unlock(&local->sta_mtx); 100 mutex_unlock(&local->sta_mtx);
124 101
125 /* remove all interfaces */ 102 /* remove all interfaces */
126 list_for_each_entry(sdata, &local->interfaces, list) { 103 list_for_each_entry(sdata, &local->interfaces, list) {
127 static u8 zero_addr[ETH_ALEN] = {};
128 u32 changed = 0;
129
130 if (!ieee80211_sdata_running(sdata)) 104 if (!ieee80211_sdata_running(sdata))
131 continue; 105 continue;
132
133 switch (sdata->vif.type) {
134 case NL80211_IFTYPE_AP_VLAN:
135 case NL80211_IFTYPE_MONITOR:
136 /* skip these */
137 continue;
138 case NL80211_IFTYPE_STATION:
139 if (sdata->vif.bss_conf.assoc)
140 changed = BSS_CHANGED_ASSOC |
141 BSS_CHANGED_BSSID |
142 BSS_CHANGED_IDLE;
143 break;
144 case NL80211_IFTYPE_AP:
145 case NL80211_IFTYPE_ADHOC:
146 case NL80211_IFTYPE_MESH_POINT:
147 if (sdata->vif.bss_conf.enable_beacon)
148 changed = BSS_CHANGED_BEACON_ENABLED;
149 break;
150 default:
151 break;
152 }
153
154 ieee80211_quiesce(sdata);
155
156 sdata->suspend_bss_conf = sdata->vif.bss_conf;
157 memset(&sdata->vif.bss_conf, 0, sizeof(sdata->vif.bss_conf));
158 sdata->vif.bss_conf.idle = true;
159 if (sdata->suspend_bss_conf.bssid)
160 sdata->vif.bss_conf.bssid = zero_addr;
161
162 /* disable beaconing or remove association */
163 ieee80211_bss_info_change_notify(sdata, changed);
164
165 if (sdata->vif.type == NL80211_IFTYPE_AP &&
166 rcu_access_pointer(sdata->u.ap.beacon))
167 drv_stop_ap(local, sdata);
168
169 if (local->use_chanctx) {
170 struct ieee80211_chanctx_conf *conf;
171
172 mutex_lock(&local->chanctx_mtx);
173 conf = rcu_dereference_protected(
174 sdata->vif.chanctx_conf,
175 lockdep_is_held(&local->chanctx_mtx));
176 if (conf) {
177 ctx = container_of(conf,
178 struct ieee80211_chanctx,
179 conf);
180 drv_unassign_vif_chanctx(local, sdata, ctx);
181 }
182
183 mutex_unlock(&local->chanctx_mtx);
184 }
185 drv_remove_interface(local, sdata);
186 }
187
188 sdata = rtnl_dereference(local->monitor_sdata);
189 if (sdata) {
190 if (local->use_chanctx) {
191 struct ieee80211_chanctx_conf *conf;
192
193 mutex_lock(&local->chanctx_mtx);
194 conf = rcu_dereference_protected(
195 sdata->vif.chanctx_conf,
196 lockdep_is_held(&local->chanctx_mtx));
197 if (conf) {
198 ctx = container_of(conf,
199 struct ieee80211_chanctx,
200 conf);
201 drv_unassign_vif_chanctx(local, sdata, ctx);
202 }
203
204 mutex_unlock(&local->chanctx_mtx);
205 }
206
207 drv_remove_interface(local, sdata); 106 drv_remove_interface(local, sdata);
208 } 107 }
209 108
210 mutex_lock(&local->chanctx_mtx); 109 /*
211 list_for_each_entry(ctx, &local->chanctx_list, list) 110 * We disconnected on all interfaces before suspend, all channel
212 drv_remove_chanctx(local, ctx); 111 * contexts should be released.
213 mutex_unlock(&local->chanctx_mtx); 112 */
113 WARN_ON(!list_empty(&local->chanctx_list));
214 114
215 /* stop hardware - this must stop RX */ 115 /* stop hardware - this must stop RX */
216 if (local->open_count) 116 if (local->open_count)
diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
index dd88381c53b7..0d51877efdb7 100644
--- a/net/mac80211/rate.c
+++ b/net/mac80211/rate.c
@@ -252,6 +252,25 @@ rate_lowest_non_cck_index(struct ieee80211_supported_band *sband,
252 return 0; 252 return 0;
253} 253}
254 254
255static void __rate_control_send_low(struct ieee80211_hw *hw,
256 struct ieee80211_supported_band *sband,
257 struct ieee80211_sta *sta,
258 struct ieee80211_tx_info *info)
259{
260 if ((sband->band != IEEE80211_BAND_2GHZ) ||
261 !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
262 info->control.rates[0].idx = rate_lowest_index(sband, sta);
263 else
264 info->control.rates[0].idx =
265 rate_lowest_non_cck_index(sband, sta);
266
267 info->control.rates[0].count =
268 (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
269 1 : hw->max_rate_tries;
270
271 info->control.skip_table = 1;
272}
273
255 274
256bool rate_control_send_low(struct ieee80211_sta *sta, 275bool rate_control_send_low(struct ieee80211_sta *sta,
257 void *priv_sta, 276 void *priv_sta,
@@ -262,16 +281,8 @@ bool rate_control_send_low(struct ieee80211_sta *sta,
262 int mcast_rate; 281 int mcast_rate;
263 282
264 if (!sta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) { 283 if (!sta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) {
265 if ((sband->band != IEEE80211_BAND_2GHZ) || 284 __rate_control_send_low(txrc->hw, sband, sta, info);
266 !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)) 285
267 info->control.rates[0].idx =
268 rate_lowest_index(txrc->sband, sta);
269 else
270 info->control.rates[0].idx =
271 rate_lowest_non_cck_index(txrc->sband, sta);
272 info->control.rates[0].count =
273 (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
274 1 : txrc->hw->max_rate_tries;
275 if (!sta && txrc->bss) { 286 if (!sta && txrc->bss) {
276 mcast_rate = txrc->bss_conf->mcast_rate[sband->band]; 287 mcast_rate = txrc->bss_conf->mcast_rate[sband->band];
277 if (mcast_rate > 0) { 288 if (mcast_rate > 0) {
@@ -355,7 +366,8 @@ static bool rate_idx_match_mcs_mask(struct ieee80211_tx_rate *rate,
355 366
356 367
357static void rate_idx_match_mask(struct ieee80211_tx_rate *rate, 368static void rate_idx_match_mask(struct ieee80211_tx_rate *rate,
358 struct ieee80211_tx_rate_control *txrc, 369 struct ieee80211_supported_band *sband,
370 enum nl80211_chan_width chan_width,
359 u32 mask, 371 u32 mask,
360 u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) 372 u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
361{ 373{
@@ -375,27 +387,17 @@ static void rate_idx_match_mask(struct ieee80211_tx_rate *rate,
375 IEEE80211_TX_RC_USE_SHORT_PREAMBLE); 387 IEEE80211_TX_RC_USE_SHORT_PREAMBLE);
376 alt_rate.count = rate->count; 388 alt_rate.count = rate->count;
377 if (rate_idx_match_legacy_mask(&alt_rate, 389 if (rate_idx_match_legacy_mask(&alt_rate,
378 txrc->sband->n_bitrates, 390 sband->n_bitrates, mask)) {
379 mask)) {
380 *rate = alt_rate; 391 *rate = alt_rate;
381 return; 392 return;
382 } 393 }
383 } else { 394 } else {
384 struct sk_buff *skb = txrc->skb;
385 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
386 __le16 fc;
387
388 /* handle legacy rates */ 395 /* handle legacy rates */
389 if (rate_idx_match_legacy_mask(rate, txrc->sband->n_bitrates, 396 if (rate_idx_match_legacy_mask(rate, sband->n_bitrates, mask))
390 mask))
391 return; 397 return;
392 398
393 /* if HT BSS, and we handle a data frame, also try HT rates */ 399 /* if HT BSS, and we handle a data frame, also try HT rates */
394 if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT) 400 if (chan_width == NL80211_CHAN_WIDTH_20_NOHT)
395 return;
396
397 fc = hdr->frame_control;
398 if (!ieee80211_is_data(fc))
399 return; 401 return;
400 402
401 alt_rate.idx = 0; 403 alt_rate.idx = 0;
@@ -408,7 +410,7 @@ static void rate_idx_match_mask(struct ieee80211_tx_rate *rate,
408 410
409 alt_rate.flags |= IEEE80211_TX_RC_MCS; 411 alt_rate.flags |= IEEE80211_TX_RC_MCS;
410 412
411 if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_40) 413 if (chan_width == NL80211_CHAN_WIDTH_40)
412 alt_rate.flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; 414 alt_rate.flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
413 415
414 if (rate_idx_match_mcs_mask(&alt_rate, mcs_mask)) { 416 if (rate_idx_match_mcs_mask(&alt_rate, mcs_mask)) {
@@ -426,6 +428,228 @@ static void rate_idx_match_mask(struct ieee80211_tx_rate *rate,
426 */ 428 */
427} 429}
428 430
431static void rate_fixup_ratelist(struct ieee80211_vif *vif,
432 struct ieee80211_supported_band *sband,
433 struct ieee80211_tx_info *info,
434 struct ieee80211_tx_rate *rates,
435 int max_rates)
436{
437 struct ieee80211_rate *rate;
438 bool inval = false;
439 int i;
440
441 /*
442 * Set up the RTS/CTS rate as the fastest basic rate
443 * that is not faster than the data rate unless there
444 * is no basic rate slower than the data rate, in which
445 * case we pick the slowest basic rate
446 *
447 * XXX: Should this check all retry rates?
448 */
449 if (!(rates[0].flags & IEEE80211_TX_RC_MCS)) {
450 u32 basic_rates = vif->bss_conf.basic_rates;
451 s8 baserate = basic_rates ? ffs(basic_rates - 1) : 0;
452
453 rate = &sband->bitrates[rates[0].idx];
454
455 for (i = 0; i < sband->n_bitrates; i++) {
456 /* must be a basic rate */
457 if (!(basic_rates & BIT(i)))
458 continue;
459 /* must not be faster than the data rate */
460 if (sband->bitrates[i].bitrate > rate->bitrate)
461 continue;
462 /* maximum */
463 if (sband->bitrates[baserate].bitrate <
464 sband->bitrates[i].bitrate)
465 baserate = i;
466 }
467
468 info->control.rts_cts_rate_idx = baserate;
469 }
470
471 for (i = 0; i < max_rates; i++) {
472 /*
473 * make sure there's no valid rate following
474 * an invalid one, just in case drivers don't
475 * take the API seriously to stop at -1.
476 */
477 if (inval) {
478 rates[i].idx = -1;
479 continue;
480 }
481 if (rates[i].idx < 0) {
482 inval = true;
483 continue;
484 }
485
486 /*
487 * For now assume MCS is already set up correctly, this
488 * needs to be fixed.
489 */
490 if (rates[i].flags & IEEE80211_TX_RC_MCS) {
491 WARN_ON(rates[i].idx > 76);
492
493 if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) &&
494 info->control.use_cts_prot)
495 rates[i].flags |=
496 IEEE80211_TX_RC_USE_CTS_PROTECT;
497 continue;
498 }
499
500 if (rates[i].flags & IEEE80211_TX_RC_VHT_MCS) {
501 WARN_ON(ieee80211_rate_get_vht_mcs(&rates[i]) > 9);
502 continue;
503 }
504
505 /* set up RTS protection if desired */
506 if (info->control.use_rts) {
507 rates[i].flags |= IEEE80211_TX_RC_USE_RTS_CTS;
508 info->control.use_cts_prot = false;
509 }
510
511 /* RC is busted */
512 if (WARN_ON_ONCE(rates[i].idx >= sband->n_bitrates)) {
513 rates[i].idx = -1;
514 continue;
515 }
516
517 rate = &sband->bitrates[rates[i].idx];
518
519 /* set up short preamble */
520 if (info->control.short_preamble &&
521 rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
522 rates[i].flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
523
524 /* set up G protection */
525 if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) &&
526 info->control.use_cts_prot &&
527 rate->flags & IEEE80211_RATE_ERP_G)
528 rates[i].flags |= IEEE80211_TX_RC_USE_CTS_PROTECT;
529 }
530}
531
532
533static void rate_control_fill_sta_table(struct ieee80211_sta *sta,
534 struct ieee80211_tx_info *info,
535 struct ieee80211_tx_rate *rates,
536 int max_rates)
537{
538 struct ieee80211_sta_rates *ratetbl = NULL;
539 int i;
540
541 if (sta && !info->control.skip_table)
542 ratetbl = rcu_dereference(sta->rates);
543
544 /* Fill remaining rate slots with data from the sta rate table. */
545 max_rates = min_t(int, max_rates, IEEE80211_TX_RATE_TABLE_SIZE);
546 for (i = 0; i < max_rates; i++) {
547 if (i < ARRAY_SIZE(info->control.rates) &&
548 info->control.rates[i].idx >= 0 &&
549 info->control.rates[i].count) {
550 if (rates != info->control.rates)
551 rates[i] = info->control.rates[i];
552 } else if (ratetbl) {
553 rates[i].idx = ratetbl->rate[i].idx;
554 rates[i].flags = ratetbl->rate[i].flags;
555 if (info->control.use_rts)
556 rates[i].count = ratetbl->rate[i].count_rts;
557 else if (info->control.use_cts_prot)
558 rates[i].count = ratetbl->rate[i].count_cts;
559 else
560 rates[i].count = ratetbl->rate[i].count;
561 } else {
562 rates[i].idx = -1;
563 rates[i].count = 0;
564 }
565
566 if (rates[i].idx < 0 || !rates[i].count)
567 break;
568 }
569}
570
571static void rate_control_apply_mask(struct ieee80211_sub_if_data *sdata,
572 struct ieee80211_sta *sta,
573 struct ieee80211_supported_band *sband,
574 struct ieee80211_tx_info *info,
575 struct ieee80211_tx_rate *rates,
576 int max_rates)
577{
578 enum nl80211_chan_width chan_width;
579 u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
580 bool has_mcs_mask;
581 u32 mask;
582 int i;
583
584 /*
585 * Try to enforce the rateidx mask the user wanted. skip this if the
586 * default mask (allow all rates) is used to save some processing for
587 * the common case.
588 */
589 mask = sdata->rc_rateidx_mask[info->band];
590 has_mcs_mask = sdata->rc_has_mcs_mask[info->band];
591 if (mask == (1 << sband->n_bitrates) - 1 && !has_mcs_mask)
592 return;
593
594 if (has_mcs_mask)
595 memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band],
596 sizeof(mcs_mask));
597 else
598 memset(mcs_mask, 0xff, sizeof(mcs_mask));
599
600 if (sta) {
601 /* Filter out rates that the STA does not support */
602 mask &= sta->supp_rates[info->band];
603 for (i = 0; i < sizeof(mcs_mask); i++)
604 mcs_mask[i] &= sta->ht_cap.mcs.rx_mask[i];
605 }
606
607 /*
608 * Make sure the rate index selected for each TX rate is
609 * included in the configured mask and change the rate indexes
610 * if needed.
611 */
612 chan_width = sdata->vif.bss_conf.chandef.width;
613 for (i = 0; i < max_rates; i++) {
614 /* Skip invalid rates */
615 if (rates[i].idx < 0)
616 break;
617
618 rate_idx_match_mask(&rates[i], sband, mask, chan_width,
619 mcs_mask);
620 }
621}
622
623void ieee80211_get_tx_rates(struct ieee80211_vif *vif,
624 struct ieee80211_sta *sta,
625 struct sk_buff *skb,
626 struct ieee80211_tx_rate *dest,
627 int max_rates)
628{
629 struct ieee80211_sub_if_data *sdata;
630 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
631 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
632 struct ieee80211_supported_band *sband;
633
634 rate_control_fill_sta_table(sta, info, dest, max_rates);
635
636 if (!vif)
637 return;
638
639 sdata = vif_to_sdata(vif);
640 sband = sdata->local->hw.wiphy->bands[info->band];
641
642 if (ieee80211_is_data(hdr->frame_control))
643 rate_control_apply_mask(sdata, sta, sband, info, dest, max_rates);
644
645 if (dest[0].idx < 0)
646 __rate_control_send_low(&sdata->local->hw, sband, sta, info);
647
648 if (sta)
649 rate_fixup_ratelist(vif, sband, info, dest, max_rates);
650}
651EXPORT_SYMBOL(ieee80211_get_tx_rates);
652
429void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, 653void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
430 struct sta_info *sta, 654 struct sta_info *sta,
431 struct ieee80211_tx_rate_control *txrc) 655 struct ieee80211_tx_rate_control *txrc)
@@ -435,8 +659,6 @@ void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
435 struct ieee80211_sta *ista = NULL; 659 struct ieee80211_sta *ista = NULL;
436 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb); 660 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
437 int i; 661 int i;
438 u32 mask;
439 u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
440 662
441 if (sta && test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) { 663 if (sta && test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) {
442 ista = &sta->sta; 664 ista = &sta->sta;
@@ -454,37 +676,27 @@ void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
454 676
455 ref->ops->get_rate(ref->priv, ista, priv_sta, txrc); 677 ref->ops->get_rate(ref->priv, ista, priv_sta, txrc);
456 678
457 /* 679 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_RC_TABLE)
458 * Try to enforce the rateidx mask the user wanted. skip this if the 680 return;
459 * default mask (allow all rates) is used to save some processing for 681
460 * the common case. 682 ieee80211_get_tx_rates(&sdata->vif, ista, txrc->skb,
461 */ 683 info->control.rates,
462 mask = sdata->rc_rateidx_mask[info->band]; 684 ARRAY_SIZE(info->control.rates));
463 memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band], 685}
464 sizeof(mcs_mask));
465 if (mask != (1 << txrc->sband->n_bitrates) - 1) {
466 if (sta) {
467 /* Filter out rates that the STA does not support */
468 mask &= sta->sta.supp_rates[info->band];
469 for (i = 0; i < sizeof(mcs_mask); i++)
470 mcs_mask[i] &= sta->sta.ht_cap.mcs.rx_mask[i];
471 }
472 /*
473 * Make sure the rate index selected for each TX rate is
474 * included in the configured mask and change the rate indexes
475 * if needed.
476 */
477 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
478 /* Skip invalid rates */
479 if (info->control.rates[i].idx < 0)
480 break;
481 rate_idx_match_mask(&info->control.rates[i], txrc,
482 mask, mcs_mask);
483 }
484 }
485 686
486 BUG_ON(info->control.rates[0].idx < 0); 687int rate_control_set_rates(struct ieee80211_hw *hw,
688 struct ieee80211_sta *pubsta,
689 struct ieee80211_sta_rates *rates)
690{
691 struct ieee80211_sta_rates *old = rcu_dereference(pubsta->rates);
692
693 rcu_assign_pointer(pubsta->rates, rates);
694 if (old)
695 kfree_rcu(old, rcu_head);
696
697 return 0;
487} 698}
699EXPORT_SYMBOL(rate_control_set_rates);
488 700
489int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local, 701int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
490 const char *name) 702 const char *name)
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index eea45a2c7c35..ac7ef5414bde 100644
--- a/net/mac80211/rc80211_minstrel.c
+++ b/net/mac80211/rc80211_minstrel.c
@@ -55,7 +55,6 @@
55#include "rate.h" 55#include "rate.h"
56#include "rc80211_minstrel.h" 56#include "rc80211_minstrel.h"
57 57
58#define SAMPLE_COLUMNS 10
59#define SAMPLE_TBL(_mi, _idx, _col) \ 58#define SAMPLE_TBL(_mi, _idx, _col) \
60 _mi->sample_table[(_idx * SAMPLE_COLUMNS) + _col] 59 _mi->sample_table[(_idx * SAMPLE_COLUMNS) + _col]
61 60
@@ -70,16 +69,75 @@ rix_to_ndx(struct minstrel_sta_info *mi, int rix)
70 return i; 69 return i;
71} 70}
72 71
72/* find & sort topmost throughput rates */
73static inline void
74minstrel_sort_best_tp_rates(struct minstrel_sta_info *mi, int i, u8 *tp_list)
75{
76 int j = MAX_THR_RATES;
77
78 while (j > 0 && mi->r[i].cur_tp > mi->r[tp_list[j - 1]].cur_tp)
79 j--;
80 if (j < MAX_THR_RATES - 1)
81 memmove(&tp_list[j + 1], &tp_list[j], MAX_THR_RATES - (j + 1));
82 if (j < MAX_THR_RATES)
83 tp_list[j] = i;
84}
85
86static void
87minstrel_set_rate(struct minstrel_sta_info *mi, struct ieee80211_sta_rates *ratetbl,
88 int offset, int idx)
89{
90 struct minstrel_rate *r = &mi->r[idx];
91
92 ratetbl->rate[offset].idx = r->rix;
93 ratetbl->rate[offset].count = r->adjusted_retry_count;
94 ratetbl->rate[offset].count_cts = r->retry_count_cts;
95 ratetbl->rate[offset].count_rts = r->retry_count_rtscts;
96}
97
98static void
99minstrel_update_rates(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
100{
101 struct ieee80211_sta_rates *ratetbl;
102 int i = 0;
103
104 ratetbl = kzalloc(sizeof(*ratetbl), GFP_ATOMIC);
105 if (!ratetbl)
106 return;
107
108 /* Start with max_tp_rate */
109 minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[0]);
110
111 if (mp->hw->max_rates >= 3) {
112 /* At least 3 tx rates supported, use max_tp_rate2 next */
113 minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[1]);
114 }
115
116 if (mp->hw->max_rates >= 2) {
117 /* At least 2 tx rates supported, use max_prob_rate next */
118 minstrel_set_rate(mi, ratetbl, i++, mi->max_prob_rate);
119 }
120
121 /* Use lowest rate last */
122 ratetbl->rate[i].idx = mi->lowest_rix;
123 ratetbl->rate[i].count = mp->max_retry;
124 ratetbl->rate[i].count_cts = mp->max_retry;
125 ratetbl->rate[i].count_rts = mp->max_retry;
126
127 rate_control_set_rates(mp->hw, mi->sta, ratetbl);
128}
129
73static void 130static void
74minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi) 131minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
75{ 132{
76 u32 max_tp = 0, index_max_tp = 0, index_max_tp2 = 0; 133 u8 tmp_tp_rate[MAX_THR_RATES];
77 u32 max_prob = 0, index_max_prob = 0; 134 u8 tmp_prob_rate = 0;
78 u32 usecs; 135 u32 usecs;
79 u32 p;
80 int i; 136 int i;
81 137
82 mi->stats_update = jiffies; 138 for (i=0; i < MAX_THR_RATES; i++)
139 tmp_tp_rate[i] = 0;
140
83 for (i = 0; i < mi->n_rates; i++) { 141 for (i = 0; i < mi->n_rates; i++) {
84 struct minstrel_rate *mr = &mi->r[i]; 142 struct minstrel_rate *mr = &mi->r[i];
85 143
@@ -87,27 +145,32 @@ minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
87 if (!usecs) 145 if (!usecs)
88 usecs = 1000000; 146 usecs = 1000000;
89 147
90 /* To avoid rounding issues, probabilities scale from 0 (0%) 148 if (unlikely(mr->attempts > 0)) {
91 * to 18000 (100%) */ 149 mr->sample_skipped = 0;
92 if (mr->attempts) { 150 mr->cur_prob = MINSTREL_FRAC(mr->success, mr->attempts);
93 p = (mr->success * 18000) / mr->attempts;
94 mr->succ_hist += mr->success; 151 mr->succ_hist += mr->success;
95 mr->att_hist += mr->attempts; 152 mr->att_hist += mr->attempts;
96 mr->cur_prob = p; 153 mr->probability = minstrel_ewma(mr->probability,
97 p = ((p * (100 - mp->ewma_level)) + (mr->probability * 154 mr->cur_prob,
98 mp->ewma_level)) / 100; 155 EWMA_LEVEL);
99 mr->probability = p; 156 } else
100 mr->cur_tp = p * (1000000 / usecs); 157 mr->sample_skipped++;
101 }
102 158
103 mr->last_success = mr->success; 159 mr->last_success = mr->success;
104 mr->last_attempts = mr->attempts; 160 mr->last_attempts = mr->attempts;
105 mr->success = 0; 161 mr->success = 0;
106 mr->attempts = 0; 162 mr->attempts = 0;
107 163
164 /* Update throughput per rate, reset thr. below 10% success */
165 if (mr->probability < MINSTREL_FRAC(10, 100))
166 mr->cur_tp = 0;
167 else
168 mr->cur_tp = mr->probability * (1000000 / usecs);
169
108 /* Sample less often below the 10% chance of success. 170 /* Sample less often below the 10% chance of success.
109 * Sample less often above the 95% chance of success. */ 171 * Sample less often above the 95% chance of success. */
110 if ((mr->probability > 17100) || (mr->probability < 1800)) { 172 if (mr->probability > MINSTREL_FRAC(95, 100) ||
173 mr->probability < MINSTREL_FRAC(10, 100)) {
111 mr->adjusted_retry_count = mr->retry_count >> 1; 174 mr->adjusted_retry_count = mr->retry_count >> 1;
112 if (mr->adjusted_retry_count > 2) 175 if (mr->adjusted_retry_count > 2)
113 mr->adjusted_retry_count = 2; 176 mr->adjusted_retry_count = 2;
@@ -118,35 +181,32 @@ minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
118 } 181 }
119 if (!mr->adjusted_retry_count) 182 if (!mr->adjusted_retry_count)
120 mr->adjusted_retry_count = 2; 183 mr->adjusted_retry_count = 2;
121 }
122 184
123 for (i = 0; i < mi->n_rates; i++) { 185 minstrel_sort_best_tp_rates(mi, i, tmp_tp_rate);
124 struct minstrel_rate *mr = &mi->r[i]; 186
125 if (max_tp < mr->cur_tp) { 187 /* To determine the most robust rate (max_prob_rate) used at
126 index_max_tp = i; 188 * 3rd mmr stage we distinct between two cases:
127 max_tp = mr->cur_tp; 189 * (1) if any success probabilitiy >= 95%, out of those rates
128 } 190 * choose the maximum throughput rate as max_prob_rate
129 if (max_prob < mr->probability) { 191 * (2) if all success probabilities < 95%, the rate with
130 index_max_prob = i; 192 * highest success probability is choosen as max_prob_rate */
131 max_prob = mr->probability; 193 if (mr->probability >= MINSTREL_FRAC(95,100)) {
194 if (mr->cur_tp >= mi->r[tmp_prob_rate].cur_tp)
195 tmp_prob_rate = i;
196 } else {
197 if (mr->probability >= mi->r[tmp_prob_rate].probability)
198 tmp_prob_rate = i;
132 } 199 }
133 } 200 }
134 201
135 max_tp = 0; 202 /* Assign the new rate set */
136 for (i = 0; i < mi->n_rates; i++) { 203 memcpy(mi->max_tp_rate, tmp_tp_rate, sizeof(mi->max_tp_rate));
137 struct minstrel_rate *mr = &mi->r[i]; 204 mi->max_prob_rate = tmp_prob_rate;
138 205
139 if (i == index_max_tp) 206 /* Reset update timer */
140 continue; 207 mi->stats_update = jiffies;
141 208
142 if (max_tp < mr->cur_tp) { 209 minstrel_update_rates(mp, mi);
143 index_max_tp2 = i;
144 max_tp = mr->cur_tp;
145 }
146 }
147 mi->max_tp_rate = index_max_tp;
148 mi->max_tp_rate2 = index_max_tp2;
149 mi->max_prob_rate = index_max_prob;
150} 210}
151 211
152static void 212static void
@@ -195,9 +255,9 @@ minstrel_get_retry_count(struct minstrel_rate *mr,
195{ 255{
196 unsigned int retry = mr->adjusted_retry_count; 256 unsigned int retry = mr->adjusted_retry_count;
197 257
198 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) 258 if (info->control.use_rts)
199 retry = max(2U, min(mr->retry_count_rtscts, retry)); 259 retry = max(2U, min(mr->retry_count_rtscts, retry));
200 else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) 260 else if (info->control.use_cts_prot)
201 retry = max(2U, min(mr->retry_count_cts, retry)); 261 retry = max(2U, min(mr->retry_count_cts, retry));
202 return retry; 262 return retry;
203} 263}
@@ -207,10 +267,10 @@ static int
207minstrel_get_next_sample(struct minstrel_sta_info *mi) 267minstrel_get_next_sample(struct minstrel_sta_info *mi)
208{ 268{
209 unsigned int sample_ndx; 269 unsigned int sample_ndx;
210 sample_ndx = SAMPLE_TBL(mi, mi->sample_idx, mi->sample_column); 270 sample_ndx = SAMPLE_TBL(mi, mi->sample_row, mi->sample_column);
211 mi->sample_idx++; 271 mi->sample_row++;
212 if ((int) mi->sample_idx > (mi->n_rates - 2)) { 272 if ((int) mi->sample_row >= mi->n_rates) {
213 mi->sample_idx = 0; 273 mi->sample_row = 0;
214 mi->sample_column++; 274 mi->sample_column++;
215 if (mi->sample_column >= SAMPLE_COLUMNS) 275 if (mi->sample_column >= SAMPLE_COLUMNS)
216 mi->sample_column = 0; 276 mi->sample_column = 0;
@@ -226,111 +286,96 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
226 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 286 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
227 struct minstrel_sta_info *mi = priv_sta; 287 struct minstrel_sta_info *mi = priv_sta;
228 struct minstrel_priv *mp = priv; 288 struct minstrel_priv *mp = priv;
229 struct ieee80211_tx_rate *ar = info->control.rates; 289 struct ieee80211_tx_rate *rate = &info->control.rates[0];
230 unsigned int ndx, sample_ndx = 0; 290 struct minstrel_rate *msr, *mr;
231 bool mrr; 291 unsigned int ndx;
232 bool sample_slower = false; 292 bool mrr_capable;
233 bool sample = false; 293 bool prev_sample = mi->prev_sample;
234 int i, delta; 294 int delta;
235 int mrr_ndx[3]; 295 int sampling_ratio;
236 int sample_rate; 296
237 297 /* management/no-ack frames do not use rate control */
238 if (rate_control_send_low(sta, priv_sta, txrc)) 298 if (rate_control_send_low(sta, priv_sta, txrc))
239 return; 299 return;
240 300
241 mrr = mp->has_mrr && !txrc->rts && !txrc->bss_conf->use_cts_prot; 301 /* check multi-rate-retry capabilities & adjust lookaround_rate */
242 302 mrr_capable = mp->has_mrr &&
243 ndx = mi->max_tp_rate; 303 !txrc->rts &&
244 304 !txrc->bss_conf->use_cts_prot;
245 if (mrr) 305 if (mrr_capable)
246 sample_rate = mp->lookaround_rate_mrr; 306 sampling_ratio = mp->lookaround_rate_mrr;
247 else 307 else
248 sample_rate = mp->lookaround_rate; 308 sampling_ratio = mp->lookaround_rate;
249 309
310 /* increase sum packet counter */
250 mi->packet_count++; 311 mi->packet_count++;
251 delta = (mi->packet_count * sample_rate / 100) - 312
313 delta = (mi->packet_count * sampling_ratio / 100) -
252 (mi->sample_count + mi->sample_deferred / 2); 314 (mi->sample_count + mi->sample_deferred / 2);
253 315
254 /* delta > 0: sampling required */ 316 /* delta < 0: no sampling required */
255 if ((delta > 0) && (mrr || !mi->prev_sample)) { 317 mi->prev_sample = false;
256 struct minstrel_rate *msr; 318 if (delta < 0 || (!mrr_capable && prev_sample))
257 if (mi->packet_count >= 10000) { 319 return;
258 mi->sample_deferred = 0;
259 mi->sample_count = 0;
260 mi->packet_count = 0;
261 } else if (delta > mi->n_rates * 2) {
262 /* With multi-rate retry, not every planned sample
263 * attempt actually gets used, due to the way the retry
264 * chain is set up - [max_tp,sample,prob,lowest] for
265 * sample_rate < max_tp.
266 *
267 * If there's too much sampling backlog and the link
268 * starts getting worse, minstrel would start bursting
269 * out lots of sampling frames, which would result
270 * in a large throughput loss. */
271 mi->sample_count += (delta - mi->n_rates * 2);
272 }
273 320
274 sample_ndx = minstrel_get_next_sample(mi); 321 if (mi->packet_count >= 10000) {
275 msr = &mi->r[sample_ndx]; 322 mi->sample_deferred = 0;
276 sample = true; 323 mi->sample_count = 0;
277 sample_slower = mrr && (msr->perfect_tx_time > 324 mi->packet_count = 0;
278 mi->r[ndx].perfect_tx_time); 325 } else if (delta > mi->n_rates * 2) {
279 326 /* With multi-rate retry, not every planned sample
280 if (!sample_slower) { 327 * attempt actually gets used, due to the way the retry
281 if (msr->sample_limit != 0) { 328 * chain is set up - [max_tp,sample,prob,lowest] for
282 ndx = sample_ndx; 329 * sample_rate < max_tp.
283 mi->sample_count++; 330 *
284 if (msr->sample_limit > 0) 331 * If there's too much sampling backlog and the link
285 msr->sample_limit--; 332 * starts getting worse, minstrel would start bursting
286 } else { 333 * out lots of sampling frames, which would result
287 sample = false; 334 * in a large throughput loss. */
288 } 335 mi->sample_count += (delta - mi->n_rates * 2);
289 } else { 336 }
290 /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark 337
291 * packets that have the sampling rate deferred to the 338 /* get next random rate sample */
292 * second MRR stage. Increase the sample counter only 339 ndx = minstrel_get_next_sample(mi);
293 * if the deferred sample rate was actually used. 340 msr = &mi->r[ndx];
294 * Use the sample_deferred counter to make sure that 341 mr = &mi->r[mi->max_tp_rate[0]];
295 * the sampling is not done in large bursts */ 342
296 info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE; 343 /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
297 mi->sample_deferred++; 344 * rate sampling method should be used.
298 } 345 * Respect such rates that are not sampled for 20 interations.
346 */
347 if (mrr_capable &&
348 msr->perfect_tx_time > mr->perfect_tx_time &&
349 msr->sample_skipped < 20) {
350 /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
351 * packets that have the sampling rate deferred to the
352 * second MRR stage. Increase the sample counter only
353 * if the deferred sample rate was actually used.
354 * Use the sample_deferred counter to make sure that
355 * the sampling is not done in large bursts */
356 info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
357 rate++;
358 mi->sample_deferred++;
359 } else {
360 if (!msr->sample_limit != 0)
361 return;
362
363 mi->sample_count++;
364 if (msr->sample_limit > 0)
365 msr->sample_limit--;
299 } 366 }
300 mi->prev_sample = sample;
301 367
302 /* If we're not using MRR and the sampling rate already 368 /* If we're not using MRR and the sampling rate already
303 * has a probability of >95%, we shouldn't be attempting 369 * has a probability of >95%, we shouldn't be attempting
304 * to use it, as this only wastes precious airtime */ 370 * to use it, as this only wastes precious airtime */
305 if (!mrr && sample && (mi->r[ndx].probability > 17100)) 371 if (!mrr_capable &&
306 ndx = mi->max_tp_rate; 372 (mi->r[ndx].probability > MINSTREL_FRAC(95, 100)))
307
308 ar[0].idx = mi->r[ndx].rix;
309 ar[0].count = minstrel_get_retry_count(&mi->r[ndx], info);
310
311 if (!mrr) {
312 if (!sample)
313 ar[0].count = mp->max_retry;
314 ar[1].idx = mi->lowest_rix;
315 ar[1].count = mp->max_retry;
316 return; 373 return;
317 }
318 374
319 /* MRR setup */ 375 mi->prev_sample = true;
320 if (sample) { 376
321 if (sample_slower) 377 rate->idx = mi->r[ndx].rix;
322 mrr_ndx[0] = sample_ndx; 378 rate->count = minstrel_get_retry_count(&mi->r[ndx], info);
323 else
324 mrr_ndx[0] = mi->max_tp_rate;
325 } else {
326 mrr_ndx[0] = mi->max_tp_rate2;
327 }
328 mrr_ndx[1] = mi->max_prob_rate;
329 mrr_ndx[2] = 0;
330 for (i = 1; i < 4; i++) {
331 ar[i].idx = mi->r[mrr_ndx[i - 1]].rix;
332 ar[i].count = mi->r[mrr_ndx[i - 1]].adjusted_retry_count;
333 }
334} 379}
335 380
336 381
@@ -351,26 +396,21 @@ static void
351init_sample_table(struct minstrel_sta_info *mi) 396init_sample_table(struct minstrel_sta_info *mi)
352{ 397{
353 unsigned int i, col, new_idx; 398 unsigned int i, col, new_idx;
354 unsigned int n_srates = mi->n_rates - 1;
355 u8 rnd[8]; 399 u8 rnd[8];
356 400
357 mi->sample_column = 0; 401 mi->sample_column = 0;
358 mi->sample_idx = 0; 402 mi->sample_row = 0;
359 memset(mi->sample_table, 0, SAMPLE_COLUMNS * mi->n_rates); 403 memset(mi->sample_table, 0xff, SAMPLE_COLUMNS * mi->n_rates);
360 404
361 for (col = 0; col < SAMPLE_COLUMNS; col++) { 405 for (col = 0; col < SAMPLE_COLUMNS; col++) {
362 for (i = 0; i < n_srates; i++) { 406 for (i = 0; i < mi->n_rates; i++) {
363 get_random_bytes(rnd, sizeof(rnd)); 407 get_random_bytes(rnd, sizeof(rnd));
364 new_idx = (i + rnd[i & 7]) % n_srates; 408 new_idx = (i + rnd[i & 7]) % mi->n_rates;
365 409
366 while (SAMPLE_TBL(mi, new_idx, col) != 0) 410 while (SAMPLE_TBL(mi, new_idx, col) != 0xff)
367 new_idx = (new_idx + 1) % n_srates; 411 new_idx = (new_idx + 1) % mi->n_rates;
368 412
369 /* Don't sample the slowest rate (i.e. slowest base 413 SAMPLE_TBL(mi, new_idx, col) = i;
370 * rate). We must presume that the slowest rate works
371 * fine, or else other management frames will also be
372 * failing and the link will break */
373 SAMPLE_TBL(mi, new_idx, col) = i + 1;
374 } 414 }
375 } 415 }
376} 416}
@@ -385,12 +425,16 @@ minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
385 unsigned int i, n = 0; 425 unsigned int i, n = 0;
386 unsigned int t_slot = 9; /* FIXME: get real slot time */ 426 unsigned int t_slot = 9; /* FIXME: get real slot time */
387 427
428 mi->sta = sta;
388 mi->lowest_rix = rate_lowest_index(sband, sta); 429 mi->lowest_rix = rate_lowest_index(sband, sta);
389 ctl_rate = &sband->bitrates[mi->lowest_rix]; 430 ctl_rate = &sband->bitrates[mi->lowest_rix];
390 mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10, 431 mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10,
391 ctl_rate->bitrate, 432 ctl_rate->bitrate,
392 !!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1); 433 !!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1);
393 434
435 memset(mi->max_tp_rate, 0, sizeof(mi->max_tp_rate));
436 mi->max_prob_rate = 0;
437
394 for (i = 0; i < sband->n_bitrates; i++) { 438 for (i = 0; i < sband->n_bitrates; i++) {
395 struct minstrel_rate *mr = &mi->r[n]; 439 struct minstrel_rate *mr = &mi->r[n];
396 unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0; 440 unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0;
@@ -433,6 +477,8 @@ minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
433 } while ((tx_time < mp->segment_size) && 477 } while ((tx_time < mp->segment_size) &&
434 (++mr->retry_count < mp->max_retry)); 478 (++mr->retry_count < mp->max_retry));
435 mr->adjusted_retry_count = mr->retry_count; 479 mr->adjusted_retry_count = mr->retry_count;
480 if (!(sband->bitrates[i].flags & IEEE80211_RATE_ERP_G))
481 mr->retry_count_cts = mr->retry_count;
436 } 482 }
437 483
438 for (i = n; i < sband->n_bitrates; i++) { 484 for (i = n; i < sband->n_bitrates; i++) {
@@ -444,6 +490,7 @@ minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
444 mi->stats_update = jiffies; 490 mi->stats_update = jiffies;
445 491
446 init_sample_table(mi); 492 init_sample_table(mi);
493 minstrel_update_rates(mp, mi);
447} 494}
448 495
449static void * 496static void *
@@ -542,9 +589,6 @@ minstrel_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
542 mp->lookaround_rate = 5; 589 mp->lookaround_rate = 5;
543 mp->lookaround_rate_mrr = 10; 590 mp->lookaround_rate_mrr = 10;
544 591
545 /* moving average weight for EWMA */
546 mp->ewma_level = 75;
547
548 /* maximum time that the hw is allowed to stay in one MRR segment */ 592 /* maximum time that the hw is allowed to stay in one MRR segment */
549 mp->segment_size = 6000; 593 mp->segment_size = 6000;
550 594
diff --git a/net/mac80211/rc80211_minstrel.h b/net/mac80211/rc80211_minstrel.h
index 5ecf757817f2..f4301f4b2e41 100644
--- a/net/mac80211/rc80211_minstrel.h
+++ b/net/mac80211/rc80211_minstrel.h
@@ -9,6 +9,29 @@
9#ifndef __RC_MINSTREL_H 9#ifndef __RC_MINSTREL_H
10#define __RC_MINSTREL_H 10#define __RC_MINSTREL_H
11 11
12#define EWMA_LEVEL 96 /* ewma weighting factor [/EWMA_DIV] */
13#define EWMA_DIV 128
14#define SAMPLE_COLUMNS 10 /* number of columns in sample table */
15
16
17/* scaled fraction values */
18#define MINSTREL_SCALE 16
19#define MINSTREL_FRAC(val, div) (((val) << MINSTREL_SCALE) / div)
20#define MINSTREL_TRUNC(val) ((val) >> MINSTREL_SCALE)
21
22/* number of highest throughput rates to consider*/
23#define MAX_THR_RATES 4
24
25/*
26 * Perform EWMA (Exponentially Weighted Moving Average) calculation
27 */
28static inline int
29minstrel_ewma(int old, int new, int weight)
30{
31 return (new * (EWMA_DIV - weight) + old * weight) / EWMA_DIV;
32}
33
34
12struct minstrel_rate { 35struct minstrel_rate {
13 int bitrate; 36 int bitrate;
14 int rix; 37 int rix;
@@ -26,6 +49,7 @@ struct minstrel_rate {
26 u32 attempts; 49 u32 attempts;
27 u32 last_attempts; 50 u32 last_attempts;
28 u32 last_success; 51 u32 last_success;
52 u8 sample_skipped;
29 53
30 /* parts per thousand */ 54 /* parts per thousand */
31 u32 cur_prob; 55 u32 cur_prob;
@@ -39,20 +63,21 @@ struct minstrel_rate {
39}; 63};
40 64
41struct minstrel_sta_info { 65struct minstrel_sta_info {
66 struct ieee80211_sta *sta;
67
42 unsigned long stats_update; 68 unsigned long stats_update;
43 unsigned int sp_ack_dur; 69 unsigned int sp_ack_dur;
44 unsigned int rate_avg; 70 unsigned int rate_avg;
45 71
46 unsigned int lowest_rix; 72 unsigned int lowest_rix;
47 73
48 unsigned int max_tp_rate; 74 u8 max_tp_rate[MAX_THR_RATES];
49 unsigned int max_tp_rate2; 75 u8 max_prob_rate;
50 unsigned int max_prob_rate;
51 unsigned int packet_count; 76 unsigned int packet_count;
52 unsigned int sample_count; 77 unsigned int sample_count;
53 int sample_deferred; 78 int sample_deferred;
54 79
55 unsigned int sample_idx; 80 unsigned int sample_row;
56 unsigned int sample_column; 81 unsigned int sample_column;
57 82
58 int n_rates; 83 int n_rates;
@@ -73,7 +98,6 @@ struct minstrel_priv {
73 unsigned int cw_min; 98 unsigned int cw_min;
74 unsigned int cw_max; 99 unsigned int cw_max;
75 unsigned int max_retry; 100 unsigned int max_retry;
76 unsigned int ewma_level;
77 unsigned int segment_size; 101 unsigned int segment_size;
78 unsigned int update_interval; 102 unsigned int update_interval;
79 unsigned int lookaround_rate; 103 unsigned int lookaround_rate;
diff --git a/net/mac80211/rc80211_minstrel_debugfs.c b/net/mac80211/rc80211_minstrel_debugfs.c
index d5a56226e675..fd0b9ca1570e 100644
--- a/net/mac80211/rc80211_minstrel_debugfs.c
+++ b/net/mac80211/rc80211_minstrel_debugfs.c
@@ -68,23 +68,25 @@ minstrel_stats_open(struct inode *inode, struct file *file)
68 68
69 file->private_data = ms; 69 file->private_data = ms;
70 p = ms->buf; 70 p = ms->buf;
71 p += sprintf(p, "rate throughput ewma prob this prob " 71 p += sprintf(p, "rate throughput ewma prob this prob "
72 "this succ/attempt success attempts\n"); 72 "this succ/attempt success attempts\n");
73 for (i = 0; i < mi->n_rates; i++) { 73 for (i = 0; i < mi->n_rates; i++) {
74 struct minstrel_rate *mr = &mi->r[i]; 74 struct minstrel_rate *mr = &mi->r[i];
75 75
76 *(p++) = (i == mi->max_tp_rate) ? 'T' : ' '; 76 *(p++) = (i == mi->max_tp_rate[0]) ? 'A' : ' ';
77 *(p++) = (i == mi->max_tp_rate2) ? 't' : ' '; 77 *(p++) = (i == mi->max_tp_rate[1]) ? 'B' : ' ';
78 *(p++) = (i == mi->max_tp_rate[2]) ? 'C' : ' ';
79 *(p++) = (i == mi->max_tp_rate[3]) ? 'D' : ' ';
78 *(p++) = (i == mi->max_prob_rate) ? 'P' : ' '; 80 *(p++) = (i == mi->max_prob_rate) ? 'P' : ' ';
79 p += sprintf(p, "%3u%s", mr->bitrate / 2, 81 p += sprintf(p, "%3u%s", mr->bitrate / 2,
80 (mr->bitrate & 1 ? ".5" : " ")); 82 (mr->bitrate & 1 ? ".5" : " "));
81 83
82 tp = mr->cur_tp / ((18000 << 10) / 96); 84 tp = MINSTREL_TRUNC(mr->cur_tp / 10);
83 prob = mr->cur_prob / 18; 85 prob = MINSTREL_TRUNC(mr->cur_prob * 1000);
84 eprob = mr->probability / 18; 86 eprob = MINSTREL_TRUNC(mr->probability * 1000);
85 87
86 p += sprintf(p, " %6u.%1u %6u.%1u %6u.%1u " 88 p += sprintf(p, " %6u.%1u %6u.%1u %6u.%1u "
87 "%3u(%3u) %8llu %8llu\n", 89 " %3u(%3u) %8llu %8llu\n",
88 tp / 10, tp % 10, 90 tp / 10, tp % 10,
89 eprob / 10, eprob % 10, 91 eprob / 10, eprob % 10,
90 prob / 10, prob % 10, 92 prob / 10, prob % 10,
diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c
index 3af141c69712..5b2d3012b983 100644
--- a/net/mac80211/rc80211_minstrel_ht.c
+++ b/net/mac80211/rc80211_minstrel_ht.c
@@ -17,8 +17,6 @@
17#include "rc80211_minstrel_ht.h" 17#include "rc80211_minstrel_ht.h"
18 18
19#define AVG_PKT_SIZE 1200 19#define AVG_PKT_SIZE 1200
20#define SAMPLE_COLUMNS 10
21#define EWMA_LEVEL 75
22 20
23/* Number of bits for an average sized packet */ 21/* Number of bits for an average sized packet */
24#define MCS_NBITS (AVG_PKT_SIZE << 3) 22#define MCS_NBITS (AVG_PKT_SIZE << 3)
@@ -26,11 +24,11 @@
26/* Number of symbols for a packet with (bps) bits per symbol */ 24/* Number of symbols for a packet with (bps) bits per symbol */
27#define MCS_NSYMS(bps) ((MCS_NBITS + (bps) - 1) / (bps)) 25#define MCS_NSYMS(bps) ((MCS_NBITS + (bps) - 1) / (bps))
28 26
29/* Transmission time for a packet containing (syms) symbols */ 27/* Transmission time (nanoseconds) for a packet containing (syms) symbols */
30#define MCS_SYMBOL_TIME(sgi, syms) \ 28#define MCS_SYMBOL_TIME(sgi, syms) \
31 (sgi ? \ 29 (sgi ? \
32 ((syms) * 18 + 4) / 5 : /* syms * 3.6 us */ \ 30 ((syms) * 18000 + 4000) / 5 : /* syms * 3.6 us */ \
33 (syms) << 2 /* syms * 4 us */ \ 31 ((syms) * 1000) << 2 /* syms * 4 us */ \
34 ) 32 )
35 33
36/* Transmit duration for the raw data part of an average sized packet */ 34/* Transmit duration for the raw data part of an average sized packet */
@@ -64,9 +62,9 @@
64} 62}
65 63
66#define CCK_DURATION(_bitrate, _short, _len) \ 64#define CCK_DURATION(_bitrate, _short, _len) \
67 (10 /* SIFS */ + \ 65 (1000 * (10 /* SIFS */ + \
68 (_short ? 72 + 24 : 144 + 48 ) + \ 66 (_short ? 72 + 24 : 144 + 48 ) + \
69 (8 * (_len + 4) * 10) / (_bitrate)) 67 (8 * (_len + 4) * 10) / (_bitrate)))
70 68
71#define CCK_ACK_DURATION(_bitrate, _short) \ 69#define CCK_ACK_DURATION(_bitrate, _short) \
72 (CCK_DURATION((_bitrate > 10 ? 20 : 10), false, 60) + \ 70 (CCK_DURATION((_bitrate > 10 ? 20 : 10), false, 60) + \
@@ -128,14 +126,8 @@ const struct mcs_group minstrel_mcs_groups[] = {
128 126
129static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES]; 127static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES];
130 128
131/* 129static void
132 * Perform EWMA (Exponentially Weighted Moving Average) calculation 130minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi);
133 */
134static int
135minstrel_ewma(int old, int new, int weight)
136{
137 return (new * (100 - weight) + old * weight) / 100;
138}
139 131
140/* 132/*
141 * Look up an MCS group index based on mac80211 rate information 133 * Look up an MCS group index based on mac80211 rate information
@@ -211,20 +203,32 @@ static void
211minstrel_ht_calc_tp(struct minstrel_ht_sta *mi, int group, int rate) 203minstrel_ht_calc_tp(struct minstrel_ht_sta *mi, int group, int rate)
212{ 204{
213 struct minstrel_rate_stats *mr; 205 struct minstrel_rate_stats *mr;
214 unsigned int usecs = 0; 206 unsigned int nsecs = 0;
207 unsigned int tp;
208 unsigned int prob;
215 209
216 mr = &mi->groups[group].rates[rate]; 210 mr = &mi->groups[group].rates[rate];
211 prob = mr->probability;
217 212
218 if (mr->probability < MINSTREL_FRAC(1, 10)) { 213 if (prob < MINSTREL_FRAC(1, 10)) {
219 mr->cur_tp = 0; 214 mr->cur_tp = 0;
220 return; 215 return;
221 } 216 }
222 217
218 /*
219 * For the throughput calculation, limit the probability value to 90% to
220 * account for collision related packet error rate fluctuation
221 */
222 if (prob > MINSTREL_FRAC(9, 10))
223 prob = MINSTREL_FRAC(9, 10);
224
223 if (group != MINSTREL_CCK_GROUP) 225 if (group != MINSTREL_CCK_GROUP)
224 usecs = mi->overhead / MINSTREL_TRUNC(mi->avg_ampdu_len); 226 nsecs = 1000 * mi->overhead / MINSTREL_TRUNC(mi->avg_ampdu_len);
225 227
226 usecs += minstrel_mcs_groups[group].duration[rate]; 228 nsecs += minstrel_mcs_groups[group].duration[rate];
227 mr->cur_tp = MINSTREL_TRUNC((1000000 / usecs) * mr->probability); 229 tp = 1000000 * ((mr->probability * 1000) / nsecs);
230
231 mr->cur_tp = MINSTREL_TRUNC(tp);
228} 232}
229 233
230/* 234/*
@@ -243,6 +247,7 @@ minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
243 struct minstrel_rate_stats *mr; 247 struct minstrel_rate_stats *mr;
244 int cur_prob, cur_prob_tp, cur_tp, cur_tp2; 248 int cur_prob, cur_prob_tp, cur_tp, cur_tp2;
245 int group, i, index; 249 int group, i, index;
250 bool mi_rates_valid = false;
246 251
247 if (mi->ampdu_packets > 0) { 252 if (mi->ampdu_packets > 0) {
248 mi->avg_ampdu_len = minstrel_ewma(mi->avg_ampdu_len, 253 mi->avg_ampdu_len = minstrel_ewma(mi->avg_ampdu_len,
@@ -253,11 +258,10 @@ minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
253 258
254 mi->sample_slow = 0; 259 mi->sample_slow = 0;
255 mi->sample_count = 0; 260 mi->sample_count = 0;
256 mi->max_tp_rate = 0;
257 mi->max_tp_rate2 = 0;
258 mi->max_prob_rate = 0;
259 261
260 for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) { 262 for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) {
263 bool mg_rates_valid = false;
264
261 cur_prob = 0; 265 cur_prob = 0;
262 cur_prob_tp = 0; 266 cur_prob_tp = 0;
263 cur_tp = 0; 267 cur_tp = 0;
@@ -267,15 +271,24 @@ minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
267 if (!mg->supported) 271 if (!mg->supported)
268 continue; 272 continue;
269 273
270 mg->max_tp_rate = 0;
271 mg->max_tp_rate2 = 0;
272 mg->max_prob_rate = 0;
273 mi->sample_count++; 274 mi->sample_count++;
274 275
275 for (i = 0; i < MCS_GROUP_RATES; i++) { 276 for (i = 0; i < MCS_GROUP_RATES; i++) {
276 if (!(mg->supported & BIT(i))) 277 if (!(mg->supported & BIT(i)))
277 continue; 278 continue;
278 279
280 /* initialize rates selections starting indexes */
281 if (!mg_rates_valid) {
282 mg->max_tp_rate = mg->max_tp_rate2 =
283 mg->max_prob_rate = i;
284 if (!mi_rates_valid) {
285 mi->max_tp_rate = mi->max_tp_rate2 =
286 mi->max_prob_rate = i;
287 mi_rates_valid = true;
288 }
289 mg_rates_valid = true;
290 }
291
279 mr = &mg->rates[i]; 292 mr = &mg->rates[i];
280 mr->retry_updated = false; 293 mr->retry_updated = false;
281 index = MCS_GROUP_RATES * group + i; 294 index = MCS_GROUP_RATES * group + i;
@@ -308,8 +321,8 @@ minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
308 } 321 }
309 } 322 }
310 323
311 /* try to sample up to half of the available rates during each interval */ 324 /* try to sample all available rates during each interval */
312 mi->sample_count *= 4; 325 mi->sample_count *= 8;
313 326
314 cur_prob = 0; 327 cur_prob = 0;
315 cur_prob_tp = 0; 328 cur_prob_tp = 0;
@@ -320,20 +333,13 @@ minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
320 if (!mg->supported) 333 if (!mg->supported)
321 continue; 334 continue;
322 335
323 mr = minstrel_get_ratestats(mi, mg->max_prob_rate);
324 if (cur_prob_tp < mr->cur_tp &&
325 minstrel_mcs_groups[group].streams == 1) {
326 mi->max_prob_rate = mg->max_prob_rate;
327 cur_prob = mr->cur_prob;
328 cur_prob_tp = mr->cur_tp;
329 }
330
331 mr = minstrel_get_ratestats(mi, mg->max_tp_rate); 336 mr = minstrel_get_ratestats(mi, mg->max_tp_rate);
332 if (cur_tp < mr->cur_tp) { 337 if (cur_tp < mr->cur_tp) {
333 mi->max_tp_rate2 = mi->max_tp_rate; 338 mi->max_tp_rate2 = mi->max_tp_rate;
334 cur_tp2 = cur_tp; 339 cur_tp2 = cur_tp;
335 mi->max_tp_rate = mg->max_tp_rate; 340 mi->max_tp_rate = mg->max_tp_rate;
336 cur_tp = mr->cur_tp; 341 cur_tp = mr->cur_tp;
342 mi->max_prob_streams = minstrel_mcs_groups[group].streams - 1;
337 } 343 }
338 344
339 mr = minstrel_get_ratestats(mi, mg->max_tp_rate2); 345 mr = minstrel_get_ratestats(mi, mg->max_tp_rate2);
@@ -343,6 +349,23 @@ minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
343 } 349 }
344 } 350 }
345 351
352 if (mi->max_prob_streams < 1)
353 mi->max_prob_streams = 1;
354
355 for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) {
356 mg = &mi->groups[group];
357 if (!mg->supported)
358 continue;
359 mr = minstrel_get_ratestats(mi, mg->max_prob_rate);
360 if (cur_prob_tp < mr->cur_tp &&
361 minstrel_mcs_groups[group].streams <= mi->max_prob_streams) {
362 mi->max_prob_rate = mg->max_prob_rate;
363 cur_prob = mr->cur_prob;
364 cur_prob_tp = mr->cur_tp;
365 }
366 }
367
368
346 mi->stats_update = jiffies; 369 mi->stats_update = jiffies;
347} 370}
348 371
@@ -445,7 +468,7 @@ minstrel_ht_tx_status(void *priv, struct ieee80211_supported_band *sband,
445 struct ieee80211_tx_rate *ar = info->status.rates; 468 struct ieee80211_tx_rate *ar = info->status.rates;
446 struct minstrel_rate_stats *rate, *rate2; 469 struct minstrel_rate_stats *rate, *rate2;
447 struct minstrel_priv *mp = priv; 470 struct minstrel_priv *mp = priv;
448 bool last; 471 bool last, update = false;
449 int i; 472 int i;
450 473
451 if (!msp->is_ht) 474 if (!msp->is_ht)
@@ -467,7 +490,7 @@ minstrel_ht_tx_status(void *priv, struct ieee80211_supported_band *sband,
467 490
468 if (!mi->sample_wait && !mi->sample_tries && mi->sample_count > 0) { 491 if (!mi->sample_wait && !mi->sample_tries && mi->sample_count > 0) {
469 mi->sample_wait = 16 + 2 * MINSTREL_TRUNC(mi->avg_ampdu_len); 492 mi->sample_wait = 16 + 2 * MINSTREL_TRUNC(mi->avg_ampdu_len);
470 mi->sample_tries = 2; 493 mi->sample_tries = 1;
471 mi->sample_count--; 494 mi->sample_count--;
472 } 495 }
473 496
@@ -494,21 +517,29 @@ minstrel_ht_tx_status(void *priv, struct ieee80211_supported_band *sband,
494 rate = minstrel_get_ratestats(mi, mi->max_tp_rate); 517 rate = minstrel_get_ratestats(mi, mi->max_tp_rate);
495 if (rate->attempts > 30 && 518 if (rate->attempts > 30 &&
496 MINSTREL_FRAC(rate->success, rate->attempts) < 519 MINSTREL_FRAC(rate->success, rate->attempts) <
497 MINSTREL_FRAC(20, 100)) 520 MINSTREL_FRAC(20, 100)) {
498 minstrel_downgrade_rate(mi, &mi->max_tp_rate, true); 521 minstrel_downgrade_rate(mi, &mi->max_tp_rate, true);
522 update = true;
523 }
499 524
500 rate2 = minstrel_get_ratestats(mi, mi->max_tp_rate2); 525 rate2 = minstrel_get_ratestats(mi, mi->max_tp_rate2);
501 if (rate2->attempts > 30 && 526 if (rate2->attempts > 30 &&
502 MINSTREL_FRAC(rate2->success, rate2->attempts) < 527 MINSTREL_FRAC(rate2->success, rate2->attempts) <
503 MINSTREL_FRAC(20, 100)) 528 MINSTREL_FRAC(20, 100)) {
504 minstrel_downgrade_rate(mi, &mi->max_tp_rate2, false); 529 minstrel_downgrade_rate(mi, &mi->max_tp_rate2, false);
530 update = true;
531 }
505 532
506 if (time_after(jiffies, mi->stats_update + (mp->update_interval / 2 * HZ) / 1000)) { 533 if (time_after(jiffies, mi->stats_update + (mp->update_interval / 2 * HZ) / 1000)) {
534 update = true;
507 minstrel_ht_update_stats(mp, mi); 535 minstrel_ht_update_stats(mp, mi);
508 if (!(info->flags & IEEE80211_TX_CTL_AMPDU) && 536 if (!(info->flags & IEEE80211_TX_CTL_AMPDU) &&
509 mi->max_prob_rate / MCS_GROUP_RATES != MINSTREL_CCK_GROUP) 537 mi->max_prob_rate / MCS_GROUP_RATES != MINSTREL_CCK_GROUP)
510 minstrel_aggr_check(sta, skb); 538 minstrel_aggr_check(sta, skb);
511 } 539 }
540
541 if (update)
542 minstrel_ht_update_rates(mp, mi);
512} 543}
513 544
514static void 545static void
@@ -536,7 +567,7 @@ minstrel_calc_retransmit(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
536 mr->retry_updated = true; 567 mr->retry_updated = true;
537 568
538 group = &minstrel_mcs_groups[index / MCS_GROUP_RATES]; 569 group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
539 tx_time_data = group->duration[index % MCS_GROUP_RATES] * ampdu_len; 570 tx_time_data = group->duration[index % MCS_GROUP_RATES] * ampdu_len / 1000;
540 571
541 /* Contention time for first 2 tries */ 572 /* Contention time for first 2 tries */
542 ctime = (t_slot * cw) >> 1; 573 ctime = (t_slot * cw) >> 1;
@@ -572,36 +603,71 @@ minstrel_calc_retransmit(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
572 603
573static void 604static void
574minstrel_ht_set_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi, 605minstrel_ht_set_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
575 struct ieee80211_tx_rate *rate, int index, 606 struct ieee80211_sta_rates *ratetbl, int offset, int index)
576 bool sample, bool rtscts)
577{ 607{
578 const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES]; 608 const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
579 struct minstrel_rate_stats *mr; 609 struct minstrel_rate_stats *mr;
610 u8 idx;
611 u16 flags;
580 612
581 mr = minstrel_get_ratestats(mi, index); 613 mr = minstrel_get_ratestats(mi, index);
582 if (!mr->retry_updated) 614 if (!mr->retry_updated)
583 minstrel_calc_retransmit(mp, mi, index); 615 minstrel_calc_retransmit(mp, mi, index);
584 616
585 if (sample) 617 if (mr->probability < MINSTREL_FRAC(20, 100) || !mr->retry_count) {
586 rate->count = 1; 618 ratetbl->rate[offset].count = 2;
587 else if (mr->probability < MINSTREL_FRAC(20, 100)) 619 ratetbl->rate[offset].count_rts = 2;
588 rate->count = 2; 620 ratetbl->rate[offset].count_cts = 2;
589 else if (rtscts) 621 } else {
590 rate->count = mr->retry_count_rtscts; 622 ratetbl->rate[offset].count = mr->retry_count;
591 else 623 ratetbl->rate[offset].count_cts = mr->retry_count;
592 rate->count = mr->retry_count; 624 ratetbl->rate[offset].count_rts = mr->retry_count_rtscts;
593 625 }
594 rate->flags = 0;
595 if (rtscts)
596 rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
597 626
598 if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) { 627 if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) {
599 rate->idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)]; 628 idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
629 flags = 0;
630 } else {
631 idx = index % MCS_GROUP_RATES +
632 (group->streams - 1) * MCS_GROUP_RATES;
633 flags = IEEE80211_TX_RC_MCS | group->flags;
634 }
635
636 if (offset > 0) {
637 ratetbl->rate[offset].count = ratetbl->rate[offset].count_rts;
638 flags |= IEEE80211_TX_RC_USE_RTS_CTS;
639 }
640
641 ratetbl->rate[offset].idx = idx;
642 ratetbl->rate[offset].flags = flags;
643}
644
645static void
646minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
647{
648 struct ieee80211_sta_rates *rates;
649 int i = 0;
650
651 rates = kzalloc(sizeof(*rates), GFP_ATOMIC);
652 if (!rates)
600 return; 653 return;
654
655 /* Start with max_tp_rate */
656 minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate);
657
658 if (mp->hw->max_rates >= 3) {
659 /* At least 3 tx rates supported, use max_tp_rate2 next */
660 minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate2);
601 } 661 }
602 662
603 rate->flags |= IEEE80211_TX_RC_MCS | group->flags; 663 if (mp->hw->max_rates >= 2) {
604 rate->idx = index % MCS_GROUP_RATES + (group->streams - 1) * MCS_GROUP_RATES; 664 /*
665 * At least 2 tx rates supported, use max_prob_rate next */
666 minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_prob_rate);
667 }
668
669 rates->rate[i].idx = -1;
670 rate_control_set_rates(mp->hw, mi->sta, rates);
605} 671}
606 672
607static inline int 673static inline int
@@ -616,6 +682,7 @@ minstrel_get_sample_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
616{ 682{
617 struct minstrel_rate_stats *mr; 683 struct minstrel_rate_stats *mr;
618 struct minstrel_mcs_group_data *mg; 684 struct minstrel_mcs_group_data *mg;
685 unsigned int sample_dur, sample_group;
619 int sample_idx = 0; 686 int sample_idx = 0;
620 687
621 if (mi->sample_wait > 0) { 688 if (mi->sample_wait > 0) {
@@ -626,39 +693,46 @@ minstrel_get_sample_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
626 if (!mi->sample_tries) 693 if (!mi->sample_tries)
627 return -1; 694 return -1;
628 695
629 mi->sample_tries--;
630 mg = &mi->groups[mi->sample_group]; 696 mg = &mi->groups[mi->sample_group];
631 sample_idx = sample_table[mg->column][mg->index]; 697 sample_idx = sample_table[mg->column][mg->index];
632 mr = &mg->rates[sample_idx]; 698 mr = &mg->rates[sample_idx];
633 sample_idx += mi->sample_group * MCS_GROUP_RATES; 699 sample_group = mi->sample_group;
700 sample_idx += sample_group * MCS_GROUP_RATES;
634 minstrel_next_sample_idx(mi); 701 minstrel_next_sample_idx(mi);
635 702
636 /* 703 /*
637 * Sampling might add some overhead (RTS, no aggregation) 704 * Sampling might add some overhead (RTS, no aggregation)
638 * to the frame. Hence, don't use sampling for the currently 705 * to the frame. Hence, don't use sampling for the currently
639 * used max TP rate. 706 * used rates.
640 */ 707 */
641 if (sample_idx == mi->max_tp_rate) 708 if (sample_idx == mi->max_tp_rate ||
709 sample_idx == mi->max_tp_rate2 ||
710 sample_idx == mi->max_prob_rate)
642 return -1; 711 return -1;
712
643 /* 713 /*
644 * When not using MRR, do not sample if the probability is already 714 * Do not sample if the probability is already higher than 95%
645 * higher than 95% to avoid wasting airtime 715 * to avoid wasting airtime.
646 */ 716 */
647 if (!mp->has_mrr && (mr->probability > MINSTREL_FRAC(95, 100))) 717 if (mr->probability > MINSTREL_FRAC(95, 100))
648 return -1; 718 return -1;
649 719
650 /* 720 /*
651 * Make sure that lower rates get sampled only occasionally, 721 * Make sure that lower rates get sampled only occasionally,
652 * if the link is working perfectly. 722 * if the link is working perfectly.
653 */ 723 */
654 if (minstrel_get_duration(sample_idx) > 724 sample_dur = minstrel_get_duration(sample_idx);
655 minstrel_get_duration(mi->max_tp_rate)) { 725 if (sample_dur >= minstrel_get_duration(mi->max_tp_rate2) &&
726 (mi->max_prob_streams <
727 minstrel_mcs_groups[sample_group].streams ||
728 sample_dur >= minstrel_get_duration(mi->max_prob_rate))) {
656 if (mr->sample_skipped < 20) 729 if (mr->sample_skipped < 20)
657 return -1; 730 return -1;
658 731
659 if (mi->sample_slow++ > 2) 732 if (mi->sample_slow++ > 2)
660 return -1; 733 return -1;
661 } 734 }
735 mi->sample_tries--;
662 736
663 return sample_idx; 737 return sample_idx;
664} 738}
@@ -683,13 +757,13 @@ static void
683minstrel_ht_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta, 757minstrel_ht_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
684 struct ieee80211_tx_rate_control *txrc) 758 struct ieee80211_tx_rate_control *txrc)
685{ 759{
760 const struct mcs_group *sample_group;
686 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb); 761 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
687 struct ieee80211_tx_rate *ar = info->status.rates; 762 struct ieee80211_tx_rate *rate = &info->status.rates[0];
688 struct minstrel_ht_sta_priv *msp = priv_sta; 763 struct minstrel_ht_sta_priv *msp = priv_sta;
689 struct minstrel_ht_sta *mi = &msp->ht; 764 struct minstrel_ht_sta *mi = &msp->ht;
690 struct minstrel_priv *mp = priv; 765 struct minstrel_priv *mp = priv;
691 int sample_idx; 766 int sample_idx;
692 bool sample = false;
693 767
694 if (rate_control_send_low(sta, priv_sta, txrc)) 768 if (rate_control_send_low(sta, priv_sta, txrc))
695 return; 769 return;
@@ -717,51 +791,6 @@ minstrel_ht_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
717 } 791 }
718#endif 792#endif
719 793
720 if (sample_idx >= 0) {
721 sample = true;
722 minstrel_ht_set_rate(mp, mi, &ar[0], sample_idx,
723 true, false);
724 info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
725 } else {
726 minstrel_ht_set_rate(mp, mi, &ar[0], mi->max_tp_rate,
727 false, false);
728 }
729
730 if (mp->hw->max_rates >= 3) {
731 /*
732 * At least 3 tx rates supported, use
733 * sample_rate -> max_tp_rate -> max_prob_rate for sampling and
734 * max_tp_rate -> max_tp_rate2 -> max_prob_rate by default.
735 */
736 if (sample_idx >= 0)
737 minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_tp_rate,
738 false, false);
739 else
740 minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_tp_rate2,
741 false, true);
742
743 minstrel_ht_set_rate(mp, mi, &ar[2], mi->max_prob_rate,
744 false, !sample);
745
746 ar[3].count = 0;
747 ar[3].idx = -1;
748 } else if (mp->hw->max_rates == 2) {
749 /*
750 * Only 2 tx rates supported, use
751 * sample_rate -> max_prob_rate for sampling and
752 * max_tp_rate -> max_prob_rate by default.
753 */
754 minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_prob_rate,
755 false, !sample);
756
757 ar[2].count = 0;
758 ar[2].idx = -1;
759 } else {
760 /* Not using MRR, only use the first rate */
761 ar[1].count = 0;
762 ar[1].idx = -1;
763 }
764
765 mi->total_packets++; 794 mi->total_packets++;
766 795
767 /* wraparound */ 796 /* wraparound */
@@ -769,6 +798,16 @@ minstrel_ht_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
769 mi->total_packets = 0; 798 mi->total_packets = 0;
770 mi->sample_packets = 0; 799 mi->sample_packets = 0;
771 } 800 }
801
802 if (sample_idx < 0)
803 return;
804
805 sample_group = &minstrel_mcs_groups[sample_idx / MCS_GROUP_RATES];
806 info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
807 rate->idx = sample_idx % MCS_GROUP_RATES +
808 (sample_group->streams - 1) * MCS_GROUP_RATES;
809 rate->flags = IEEE80211_TX_RC_MCS | sample_group->flags;
810 rate->count = 1;
772} 811}
773 812
774static void 813static void
@@ -818,6 +857,8 @@ minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
818 857
819 msp->is_ht = true; 858 msp->is_ht = true;
820 memset(mi, 0, sizeof(*mi)); 859 memset(mi, 0, sizeof(*mi));
860
861 mi->sta = sta;
821 mi->stats_update = jiffies; 862 mi->stats_update = jiffies;
822 863
823 ack_dur = ieee80211_frame_duration(sband->band, 10, 60, 1, 1); 864 ack_dur = ieee80211_frame_duration(sband->band, 10, 60, 1, 1);
@@ -879,6 +920,10 @@ minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
879 if (!n_supported) 920 if (!n_supported)
880 goto use_legacy; 921 goto use_legacy;
881 922
923 /* create an initial rate table with the lowest supported rates */
924 minstrel_ht_update_stats(mp, mi);
925 minstrel_ht_update_rates(mp, mi);
926
882 return; 927 return;
883 928
884use_legacy: 929use_legacy:
diff --git a/net/mac80211/rc80211_minstrel_ht.h b/net/mac80211/rc80211_minstrel_ht.h
index 302dbd52180d..d655586773ac 100644
--- a/net/mac80211/rc80211_minstrel_ht.h
+++ b/net/mac80211/rc80211_minstrel_ht.h
@@ -16,11 +16,6 @@
16#define MINSTREL_MAX_STREAMS 3 16#define MINSTREL_MAX_STREAMS 3
17#define MINSTREL_STREAM_GROUPS 4 17#define MINSTREL_STREAM_GROUPS 4
18 18
19/* scaled fraction values */
20#define MINSTREL_SCALE 16
21#define MINSTREL_FRAC(val, div) (((val) << MINSTREL_SCALE) / div)
22#define MINSTREL_TRUNC(val) ((val) >> MINSTREL_SCALE)
23
24#define MCS_GROUP_RATES 8 19#define MCS_GROUP_RATES 8
25 20
26struct mcs_group { 21struct mcs_group {
@@ -70,6 +65,8 @@ struct minstrel_mcs_group_data {
70}; 65};
71 66
72struct minstrel_ht_sta { 67struct minstrel_ht_sta {
68 struct ieee80211_sta *sta;
69
73 /* ampdu length (average, per sampling interval) */ 70 /* ampdu length (average, per sampling interval) */
74 unsigned int ampdu_len; 71 unsigned int ampdu_len;
75 unsigned int ampdu_packets; 72 unsigned int ampdu_packets;
@@ -85,6 +82,7 @@ struct minstrel_ht_sta {
85 82
86 /* best probability rate */ 83 /* best probability rate */
87 unsigned int max_prob_rate; 84 unsigned int max_prob_rate;
85 unsigned int max_prob_streams;
88 86
89 /* time of last status update */ 87 /* time of last status update */
90 unsigned long stats_update; 88 unsigned long stats_update;
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index c6844ad080be..c8447af76ead 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -648,24 +648,6 @@ static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
648 return RX_CONTINUE; 648 return RX_CONTINUE;
649} 649}
650 650
651#define SEQ_MODULO 0x1000
652#define SEQ_MASK 0xfff
653
654static inline int seq_less(u16 sq1, u16 sq2)
655{
656 return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1);
657}
658
659static inline u16 seq_inc(u16 sq)
660{
661 return (sq + 1) & SEQ_MASK;
662}
663
664static inline u16 seq_sub(u16 sq1, u16 sq2)
665{
666 return (sq1 - sq2) & SEQ_MASK;
667}
668
669static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata, 651static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
670 struct tid_ampdu_rx *tid_agg_rx, 652 struct tid_ampdu_rx *tid_agg_rx,
671 int index, 653 int index,
@@ -687,7 +669,7 @@ static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
687 __skb_queue_tail(frames, skb); 669 __skb_queue_tail(frames, skb);
688 670
689no_frame: 671no_frame:
690 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); 672 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
691} 673}
692 674
693static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata, 675static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
@@ -699,8 +681,9 @@ static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata
699 681
700 lockdep_assert_held(&tid_agg_rx->reorder_lock); 682 lockdep_assert_held(&tid_agg_rx->reorder_lock);
701 683
702 while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) { 684 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
703 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) % 685 index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
686 tid_agg_rx->ssn) %
704 tid_agg_rx->buf_size; 687 tid_agg_rx->buf_size;
705 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index, 688 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
706 frames); 689 frames);
@@ -727,8 +710,8 @@ static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
727 lockdep_assert_held(&tid_agg_rx->reorder_lock); 710 lockdep_assert_held(&tid_agg_rx->reorder_lock);
728 711
729 /* release the buffer until next missing frame */ 712 /* release the buffer until next missing frame */
730 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) % 713 index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
731 tid_agg_rx->buf_size; 714 tid_agg_rx->ssn) % tid_agg_rx->buf_size;
732 if (!tid_agg_rx->reorder_buf[index] && 715 if (!tid_agg_rx->reorder_buf[index] &&
733 tid_agg_rx->stored_mpdu_num) { 716 tid_agg_rx->stored_mpdu_num) {
734 /* 717 /*
@@ -756,19 +739,22 @@ static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
756 * Increment the head seq# also for the skipped slots. 739 * Increment the head seq# also for the skipped slots.
757 */ 740 */
758 tid_agg_rx->head_seq_num = 741 tid_agg_rx->head_seq_num =
759 (tid_agg_rx->head_seq_num + skipped) & SEQ_MASK; 742 (tid_agg_rx->head_seq_num +
743 skipped) & IEEE80211_SN_MASK;
760 skipped = 0; 744 skipped = 0;
761 } 745 }
762 } else while (tid_agg_rx->reorder_buf[index]) { 746 } else while (tid_agg_rx->reorder_buf[index]) {
763 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index, 747 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
764 frames); 748 frames);
765 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) % 749 index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
750 tid_agg_rx->ssn) %
766 tid_agg_rx->buf_size; 751 tid_agg_rx->buf_size;
767 } 752 }
768 753
769 if (tid_agg_rx->stored_mpdu_num) { 754 if (tid_agg_rx->stored_mpdu_num) {
770 j = index = seq_sub(tid_agg_rx->head_seq_num, 755 j = index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
771 tid_agg_rx->ssn) % tid_agg_rx->buf_size; 756 tid_agg_rx->ssn) %
757 tid_agg_rx->buf_size;
772 758
773 for (; j != (index - 1) % tid_agg_rx->buf_size; 759 for (; j != (index - 1) % tid_agg_rx->buf_size;
774 j = (j + 1) % tid_agg_rx->buf_size) { 760 j = (j + 1) % tid_agg_rx->buf_size) {
@@ -809,7 +795,7 @@ static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata
809 head_seq_num = tid_agg_rx->head_seq_num; 795 head_seq_num = tid_agg_rx->head_seq_num;
810 796
811 /* frame with out of date sequence number */ 797 /* frame with out of date sequence number */
812 if (seq_less(mpdu_seq_num, head_seq_num)) { 798 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
813 dev_kfree_skb(skb); 799 dev_kfree_skb(skb);
814 goto out; 800 goto out;
815 } 801 }
@@ -818,8 +804,9 @@ static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata
818 * If frame the sequence number exceeds our buffering window 804 * If frame the sequence number exceeds our buffering window
819 * size release some previous frames to make room for this one. 805 * size release some previous frames to make room for this one.
820 */ 806 */
821 if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) { 807 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
822 head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size)); 808 head_seq_num = ieee80211_sn_inc(
809 ieee80211_sn_sub(mpdu_seq_num, buf_size));
823 /* release stored frames up to new head to stack */ 810 /* release stored frames up to new head to stack */
824 ieee80211_release_reorder_frames(sdata, tid_agg_rx, 811 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
825 head_seq_num, frames); 812 head_seq_num, frames);
@@ -827,7 +814,8 @@ static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata
827 814
828 /* Now the new frame is always in the range of the reordering buffer */ 815 /* Now the new frame is always in the range of the reordering buffer */
829 816
830 index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) % tid_agg_rx->buf_size; 817 index = ieee80211_sn_sub(mpdu_seq_num,
818 tid_agg_rx->ssn) % tid_agg_rx->buf_size;
831 819
832 /* check if we already stored this frame */ 820 /* check if we already stored this frame */
833 if (tid_agg_rx->reorder_buf[index]) { 821 if (tid_agg_rx->reorder_buf[index]) {
@@ -843,7 +831,8 @@ static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata
843 */ 831 */
844 if (mpdu_seq_num == tid_agg_rx->head_seq_num && 832 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
845 tid_agg_rx->stored_mpdu_num == 0) { 833 tid_agg_rx->stored_mpdu_num == 0) {
846 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); 834 tid_agg_rx->head_seq_num =
835 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
847 ret = false; 836 ret = false;
848 goto out; 837 goto out;
849 } 838 }
@@ -1894,8 +1883,10 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1894 * 'align' will only take the values 0 or 2 here 1883 * 'align' will only take the values 0 or 2 here
1895 * since all frames are required to be aligned 1884 * since all frames are required to be aligned
1896 * to 2-byte boundaries when being passed to 1885 * to 2-byte boundaries when being passed to
1897 * mac80211. That also explains the __skb_push() 1886 * mac80211; the code here works just as well if
1898 * below. 1887 * that isn't true, but mac80211 assumes it can
1888 * access fields as 2-byte aligned (e.g. for
1889 * compare_ether_addr)
1899 */ 1890 */
1900 align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3; 1891 align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3;
1901 if (align) { 1892 if (align) {
@@ -2094,6 +2085,7 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2094 } 2085 }
2095 2086
2096 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data; 2087 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2088 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2097 info = IEEE80211_SKB_CB(fwd_skb); 2089 info = IEEE80211_SKB_CB(fwd_skb);
2098 memset(info, 0, sizeof(*info)); 2090 memset(info, 0, sizeof(*info));
2099 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; 2091 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
@@ -2432,6 +2424,22 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2432 } 2424 }
2433 2425
2434 break; 2426 break;
2427 case WLAN_CATEGORY_PUBLIC:
2428 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2429 goto invalid;
2430 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2431 break;
2432 if (!rx->sta)
2433 break;
2434 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
2435 break;
2436 if (mgmt->u.action.u.ext_chan_switch.action_code !=
2437 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
2438 break;
2439 if (len < offsetof(struct ieee80211_mgmt,
2440 u.action.u.ext_chan_switch.variable))
2441 goto invalid;
2442 goto queue;
2435 case WLAN_CATEGORY_VHT: 2443 case WLAN_CATEGORY_VHT:
2436 if (sdata->vif.type != NL80211_IFTYPE_STATION && 2444 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2437 sdata->vif.type != NL80211_IFTYPE_MESH_POINT && 2445 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
@@ -2515,10 +2523,6 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2515 ieee80211_process_measurement_req(sdata, mgmt, len); 2523 ieee80211_process_measurement_req(sdata, mgmt, len);
2516 goto handled; 2524 goto handled;
2517 case WLAN_ACTION_SPCT_CHL_SWITCH: 2525 case WLAN_ACTION_SPCT_CHL_SWITCH:
2518 if (len < (IEEE80211_MIN_ACTION_SIZE +
2519 sizeof(mgmt->u.action.u.chan_switch)))
2520 break;
2521
2522 if (sdata->vif.type != NL80211_IFTYPE_STATION) 2526 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2523 break; 2527 break;
2524 2528
@@ -2552,7 +2556,7 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2552 case WLAN_SP_MESH_PEERING_CONFIRM: 2556 case WLAN_SP_MESH_PEERING_CONFIRM:
2553 if (!ieee80211_vif_is_mesh(&sdata->vif)) 2557 if (!ieee80211_vif_is_mesh(&sdata->vif))
2554 goto invalid; 2558 goto invalid;
2555 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE) 2559 if (sdata->u.mesh.user_mpm)
2556 /* userspace handles this frame */ 2560 /* userspace handles this frame */
2557 break; 2561 break;
2558 goto queue; 2562 goto queue;
@@ -3051,7 +3055,8 @@ static int prepare_for_handlers(struct ieee80211_rx_data *rx,
3051 !ieee80211_is_probe_resp(hdr->frame_control) && 3055 !ieee80211_is_probe_resp(hdr->frame_control) &&
3052 !ieee80211_is_beacon(hdr->frame_control)) 3056 !ieee80211_is_beacon(hdr->frame_control))
3053 return 0; 3057 return 0;
3054 if (!ether_addr_equal(sdata->vif.addr, hdr->addr1)) 3058 if (!ether_addr_equal(sdata->vif.addr, hdr->addr1) &&
3059 !multicast)
3055 status->rx_flags &= ~IEEE80211_RX_RA_MATCH; 3060 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
3056 break; 3061 break;
3057 default: 3062 default:
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 43a45cf00e06..99b103921a4b 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -98,9 +98,8 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
98 } 98 }
99 99
100 /* save the ERP value so that it is available at association time */ 100 /* save the ERP value so that it is available at association time */
101 if (elems->erp_info && elems->erp_info_len >= 1 && 101 if (elems->erp_info && (!elems->parse_error ||
102 (!elems->parse_error || 102 !(bss->valid_data & IEEE80211_BSS_VALID_ERP))) {
103 !(bss->valid_data & IEEE80211_BSS_VALID_ERP))) {
104 bss->erp_value = elems->erp_info[0]; 103 bss->erp_value = elems->erp_info[0];
105 bss->has_erp_value = true; 104 bss->has_erp_value = true;
106 if (!elems->parse_error) 105 if (!elems->parse_error)
@@ -153,7 +152,6 @@ void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb)
153 u8 *elements; 152 u8 *elements;
154 struct ieee80211_channel *channel; 153 struct ieee80211_channel *channel;
155 size_t baselen; 154 size_t baselen;
156 bool beacon;
157 struct ieee802_11_elems elems; 155 struct ieee802_11_elems elems;
158 156
159 if (skb->len < 24 || 157 if (skb->len < 24 ||
@@ -175,17 +173,15 @@ void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb)
175 173
176 elements = mgmt->u.probe_resp.variable; 174 elements = mgmt->u.probe_resp.variable;
177 baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); 175 baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
178 beacon = false;
179 } else { 176 } else {
180 baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable); 177 baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable);
181 elements = mgmt->u.beacon.variable; 178 elements = mgmt->u.beacon.variable;
182 beacon = true;
183 } 179 }
184 180
185 if (baselen > skb->len) 181 if (baselen > skb->len)
186 return; 182 return;
187 183
188 ieee802_11_parse_elems(elements, skb->len - baselen, &elems); 184 ieee802_11_parse_elems(elements, skb->len - baselen, false, &elems);
189 185
190 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq); 186 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
191 187
@@ -335,7 +331,7 @@ static int ieee80211_start_sw_scan(struct ieee80211_local *local)
335 ieee80211_offchannel_stop_vifs(local); 331 ieee80211_offchannel_stop_vifs(local);
336 332
337 /* ensure nullfunc is transmitted before leaving operating channel */ 333 /* ensure nullfunc is transmitted before leaving operating channel */
338 drv_flush(local, false); 334 ieee80211_flush_queues(local, NULL);
339 335
340 ieee80211_configure_filter(local); 336 ieee80211_configure_filter(local);
341 337
@@ -387,7 +383,7 @@ static void ieee80211_scan_state_send_probe(struct ieee80211_local *local,
387{ 383{
388 int i; 384 int i;
389 struct ieee80211_sub_if_data *sdata; 385 struct ieee80211_sub_if_data *sdata;
390 enum ieee80211_band band = local->hw.conf.channel->band; 386 enum ieee80211_band band = local->hw.conf.chandef.chan->band;
391 u32 tx_flags; 387 u32 tx_flags;
392 388
393 tx_flags = IEEE80211_TX_INTFL_OFFCHAN_TX_OK; 389 tx_flags = IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
@@ -404,7 +400,7 @@ static void ieee80211_scan_state_send_probe(struct ieee80211_local *local,
404 local->scan_req->ssids[i].ssid_len, 400 local->scan_req->ssids[i].ssid_len,
405 local->scan_req->ie, local->scan_req->ie_len, 401 local->scan_req->ie, local->scan_req->ie_len,
406 local->scan_req->rates[band], false, 402 local->scan_req->rates[band], false,
407 tx_flags, local->hw.conf.channel, true); 403 tx_flags, local->hw.conf.chandef.chan, true);
408 404
409 /* 405 /*
410 * After sending probe requests, wait for probe responses 406 * After sending probe requests, wait for probe responses
@@ -470,7 +466,7 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
470 if (local->ops->hw_scan) { 466 if (local->ops->hw_scan) {
471 __set_bit(SCAN_HW_SCANNING, &local->scanning); 467 __set_bit(SCAN_HW_SCANNING, &local->scanning);
472 } else if ((req->n_channels == 1) && 468 } else if ((req->n_channels == 1) &&
473 (req->channels[0] == local->_oper_channel)) { 469 (req->channels[0] == local->_oper_chandef.chan)) {
474 /* 470 /*
475 * If we are scanning only on the operating channel 471 * If we are scanning only on the operating channel
476 * then we do not need to stop normal activities 472 * then we do not need to stop normal activities
@@ -671,7 +667,7 @@ static void ieee80211_scan_state_resume(struct ieee80211_local *local,
671 ieee80211_offchannel_stop_vifs(local); 667 ieee80211_offchannel_stop_vifs(local);
672 668
673 if (local->ops->flush) { 669 if (local->ops->flush) {
674 drv_flush(local, false); 670 ieee80211_flush_queues(local, NULL);
675 *next_delay = 0; 671 *next_delay = 0;
676 } else 672 } else
677 *next_delay = HZ / 10; 673 *next_delay = HZ / 10;
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 238a0cca320e..11216bc13b27 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -342,6 +342,11 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
342 INIT_WORK(&sta->drv_unblock_wk, sta_unblock); 342 INIT_WORK(&sta->drv_unblock_wk, sta_unblock);
343 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work); 343 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
344 mutex_init(&sta->ampdu_mlme.mtx); 344 mutex_init(&sta->ampdu_mlme.mtx);
345#ifdef CONFIG_MAC80211_MESH
346 if (ieee80211_vif_is_mesh(&sdata->vif) &&
347 !sdata->u.mesh.user_mpm)
348 init_timer(&sta->plink_timer);
349#endif
345 350
346 memcpy(sta->sta.addr, addr, ETH_ALEN); 351 memcpy(sta->sta.addr, addr, ETH_ALEN);
347 sta->local = local; 352 sta->local = local;
@@ -551,6 +556,15 @@ static inline void __bss_tim_clear(u8 *tim, u16 id)
551 tim[id / 8] &= ~(1 << (id % 8)); 556 tim[id / 8] &= ~(1 << (id % 8));
552} 557}
553 558
559static inline bool __bss_tim_get(u8 *tim, u16 id)
560{
561 /*
562 * This format has been mandated by the IEEE specifications,
563 * so this line may not be changed to use the test_bit() format.
564 */
565 return tim[id / 8] & (1 << (id % 8));
566}
567
554static unsigned long ieee80211_tids_for_ac(int ac) 568static unsigned long ieee80211_tids_for_ac(int ac)
555{ 569{
556 /* If we ever support TIDs > 7, this obviously needs to be adjusted */ 570 /* If we ever support TIDs > 7, this obviously needs to be adjusted */
@@ -631,6 +645,9 @@ void sta_info_recalc_tim(struct sta_info *sta)
631 done: 645 done:
632 spin_lock_bh(&local->tim_lock); 646 spin_lock_bh(&local->tim_lock);
633 647
648 if (indicate_tim == __bss_tim_get(ps->tim, id))
649 goto out_unlock;
650
634 if (indicate_tim) 651 if (indicate_tim)
635 __bss_tim_set(ps->tim, id); 652 __bss_tim_set(ps->tim, id);
636 else 653 else
@@ -642,6 +659,7 @@ void sta_info_recalc_tim(struct sta_info *sta)
642 local->tim_in_locked_section = false; 659 local->tim_in_locked_section = false;
643 } 660 }
644 661
662out_unlock:
645 spin_unlock_bh(&local->tim_lock); 663 spin_unlock_bh(&local->tim_lock);
646} 664}
647 665
@@ -765,8 +783,7 @@ int __must_check __sta_info_destroy(struct sta_info *sta)
765{ 783{
766 struct ieee80211_local *local; 784 struct ieee80211_local *local;
767 struct ieee80211_sub_if_data *sdata; 785 struct ieee80211_sub_if_data *sdata;
768 int ret, i; 786 int ret;
769 bool have_key = false;
770 787
771 might_sleep(); 788 might_sleep();
772 789
@@ -793,19 +810,8 @@ int __must_check __sta_info_destroy(struct sta_info *sta)
793 810
794 list_del_rcu(&sta->list); 811 list_del_rcu(&sta->list);
795 812
796 mutex_lock(&local->key_mtx); 813 /* this always calls synchronize_net() */
797 for (i = 0; i < NUM_DEFAULT_KEYS; i++) { 814 ieee80211_free_sta_keys(local, sta);
798 __ieee80211_key_free(key_mtx_dereference(local, sta->gtk[i]));
799 have_key = true;
800 }
801 if (sta->ptk) {
802 __ieee80211_key_free(key_mtx_dereference(local, sta->ptk));
803 have_key = true;
804 }
805 mutex_unlock(&local->key_mtx);
806
807 if (!have_key)
808 synchronize_net();
809 815
810 sta->dead = true; 816 sta->dead = true;
811 817
@@ -1391,30 +1397,16 @@ void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
1391} 1397}
1392EXPORT_SYMBOL(ieee80211_sta_block_awake); 1398EXPORT_SYMBOL(ieee80211_sta_block_awake);
1393 1399
1394void ieee80211_sta_eosp_irqsafe(struct ieee80211_sta *pubsta) 1400void ieee80211_sta_eosp(struct ieee80211_sta *pubsta)
1395{ 1401{
1396 struct sta_info *sta = container_of(pubsta, struct sta_info, sta); 1402 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1397 struct ieee80211_local *local = sta->local; 1403 struct ieee80211_local *local = sta->local;
1398 struct sk_buff *skb;
1399 struct skb_eosp_msg_data *data;
1400 1404
1401 trace_api_eosp(local, pubsta); 1405 trace_api_eosp(local, pubsta);
1402 1406
1403 skb = alloc_skb(0, GFP_ATOMIC); 1407 clear_sta_flag(sta, WLAN_STA_SP);
1404 if (!skb) {
1405 /* too bad ... but race is better than loss */
1406 clear_sta_flag(sta, WLAN_STA_SP);
1407 return;
1408 }
1409
1410 data = (void *)skb->cb;
1411 memcpy(data->sta, pubsta->addr, ETH_ALEN);
1412 memcpy(data->iface, sta->sdata->vif.addr, ETH_ALEN);
1413 skb->pkt_type = IEEE80211_EOSP_MSG;
1414 skb_queue_tail(&local->skb_queue, skb);
1415 tasklet_schedule(&local->tasklet);
1416} 1408}
1417EXPORT_SYMBOL(ieee80211_sta_eosp_irqsafe); 1409EXPORT_SYMBOL(ieee80211_sta_eosp);
1418 1410
1419void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta, 1411void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
1420 u8 tid, bool buffered) 1412 u8 tid, bool buffered)
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 4947341a2a82..adc30045f99e 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -281,7 +281,6 @@ struct sta_ampdu_mlme {
281 * @plink_state: peer link state 281 * @plink_state: peer link state
282 * @plink_timeout: timeout of peer link 282 * @plink_timeout: timeout of peer link
283 * @plink_timer: peer link watch timer 283 * @plink_timer: peer link watch timer
284 * @plink_timer_was_running: used by suspend/resume to restore timers
285 * @t_offset: timing offset relative to this host 284 * @t_offset: timing offset relative to this host
286 * @t_offset_setpoint: reference timing offset of this sta to be used when 285 * @t_offset_setpoint: reference timing offset of this sta to be used when
287 * calculating clockdrift 286 * calculating clockdrift
@@ -334,7 +333,8 @@ struct sta_info {
334 unsigned long driver_buffered_tids; 333 unsigned long driver_buffered_tids;
335 334
336 /* Updated from RX path only, no locking requirements */ 335 /* Updated from RX path only, no locking requirements */
337 unsigned long rx_packets, rx_bytes; 336 unsigned long rx_packets;
337 u64 rx_bytes;
338 unsigned long wep_weak_iv_count; 338 unsigned long wep_weak_iv_count;
339 unsigned long last_rx; 339 unsigned long last_rx;
340 long last_connected; 340 long last_connected;
@@ -354,9 +354,9 @@ struct sta_info {
354 unsigned int fail_avg; 354 unsigned int fail_avg;
355 355
356 /* Updated from TX path only, no locking requirements */ 356 /* Updated from TX path only, no locking requirements */
357 unsigned long tx_packets; 357 u32 tx_fragments;
358 unsigned long tx_bytes; 358 u64 tx_packets[IEEE80211_NUM_ACS];
359 unsigned long tx_fragments; 359 u64 tx_bytes[IEEE80211_NUM_ACS];
360 struct ieee80211_tx_rate last_tx_rate; 360 struct ieee80211_tx_rate last_tx_rate;
361 int last_rx_rate_idx; 361 int last_rx_rate_idx;
362 u32 last_rx_rate_flag; 362 u32 last_rx_rate_flag;
@@ -379,7 +379,6 @@ struct sta_info {
379 __le16 reason; 379 __le16 reason;
380 u8 plink_retries; 380 u8 plink_retries;
381 bool ignore_plink_timer; 381 bool ignore_plink_timer;
382 bool plink_timer_was_running;
383 enum nl80211_plink_state plink_state; 382 enum nl80211_plink_state plink_state;
384 u32 plink_timeout; 383 u32 plink_timeout;
385 struct timer_list plink_timer; 384 struct timer_list plink_timer;
diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h
index 3d7cd2a0582f..c215fafd7a2f 100644
--- a/net/mac80211/trace.h
+++ b/net/mac80211/trace.h
@@ -28,27 +28,27 @@
28#define VIF_PR_FMT " vif:%s(%d%s)" 28#define VIF_PR_FMT " vif:%s(%d%s)"
29#define VIF_PR_ARG __get_str(vif_name), __entry->vif_type, __entry->p2p ? "/p2p" : "" 29#define VIF_PR_ARG __get_str(vif_name), __entry->vif_type, __entry->p2p ? "/p2p" : ""
30 30
31#define CHANDEF_ENTRY __field(u32, control_freq) \ 31#define CHANDEF_ENTRY __field(u32, control_freq) \
32 __field(u32, chan_width) \ 32 __field(u32, chan_width) \
33 __field(u32, center_freq1) \ 33 __field(u32, center_freq1) \
34 __field(u32, center_freq2) 34 __field(u32, center_freq2)
35#define CHANDEF_ASSIGN(c) \ 35#define CHANDEF_ASSIGN(c) \
36 __entry->control_freq = (c)->chan->center_freq; \ 36 __entry->control_freq = (c)->chan ? (c)->chan->center_freq : 0; \
37 __entry->chan_width = (c)->width; \ 37 __entry->chan_width = (c)->width; \
38 __entry->center_freq1 = (c)->center_freq1; \ 38 __entry->center_freq1 = (c)->center_freq1; \
39 __entry->center_freq2 = (c)->center_freq2; 39 __entry->center_freq2 = (c)->center_freq2;
40#define CHANDEF_PR_FMT " control:%d MHz width:%d center: %d/%d MHz" 40#define CHANDEF_PR_FMT " control:%d MHz width:%d center: %d/%d MHz"
41#define CHANDEF_PR_ARG __entry->control_freq, __entry->chan_width, \ 41#define CHANDEF_PR_ARG __entry->control_freq, __entry->chan_width, \
42 __entry->center_freq1, __entry->center_freq2 42 __entry->center_freq1, __entry->center_freq2
43 43
44#define CHANCTX_ENTRY CHANDEF_ENTRY \ 44#define CHANCTX_ENTRY CHANDEF_ENTRY \
45 __field(u8, rx_chains_static) \ 45 __field(u8, rx_chains_static) \
46 __field(u8, rx_chains_dynamic) 46 __field(u8, rx_chains_dynamic)
47#define CHANCTX_ASSIGN CHANDEF_ASSIGN(&ctx->conf.def) \ 47#define CHANCTX_ASSIGN CHANDEF_ASSIGN(&ctx->conf.def) \
48 __entry->rx_chains_static = ctx->conf.rx_chains_static; \ 48 __entry->rx_chains_static = ctx->conf.rx_chains_static; \
49 __entry->rx_chains_dynamic = ctx->conf.rx_chains_dynamic 49 __entry->rx_chains_dynamic = ctx->conf.rx_chains_dynamic
50#define CHANCTX_PR_FMT CHANDEF_PR_FMT " chains:%d/%d" 50#define CHANCTX_PR_FMT CHANDEF_PR_FMT " chains:%d/%d"
51#define CHANCTX_PR_ARG CHANDEF_PR_ARG, \ 51#define CHANCTX_PR_ARG CHANDEF_PR_ARG, \
52 __entry->rx_chains_static, __entry->rx_chains_dynamic 52 __entry->rx_chains_static, __entry->rx_chains_dynamic
53 53
54 54
@@ -286,8 +286,7 @@ TRACE_EVENT(drv_config,
286 __field(u16, listen_interval) 286 __field(u16, listen_interval)
287 __field(u8, long_frame_max_tx_count) 287 __field(u8, long_frame_max_tx_count)
288 __field(u8, short_frame_max_tx_count) 288 __field(u8, short_frame_max_tx_count)
289 __field(int, center_freq) 289 CHANDEF_ENTRY
290 __field(int, channel_type)
291 __field(int, smps) 290 __field(int, smps)
292 ), 291 ),
293 292
@@ -303,15 +302,13 @@ TRACE_EVENT(drv_config,
303 local->hw.conf.long_frame_max_tx_count; 302 local->hw.conf.long_frame_max_tx_count;
304 __entry->short_frame_max_tx_count = 303 __entry->short_frame_max_tx_count =
305 local->hw.conf.short_frame_max_tx_count; 304 local->hw.conf.short_frame_max_tx_count;
306 __entry->center_freq = local->hw.conf.channel ? 305 CHANDEF_ASSIGN(&local->hw.conf.chandef)
307 local->hw.conf.channel->center_freq : 0;
308 __entry->channel_type = local->hw.conf.channel_type;
309 __entry->smps = local->hw.conf.smps_mode; 306 __entry->smps = local->hw.conf.smps_mode;
310 ), 307 ),
311 308
312 TP_printk( 309 TP_printk(
313 LOCAL_PR_FMT " ch:%#x freq:%d", 310 LOCAL_PR_FMT " ch:%#x" CHANDEF_PR_FMT,
314 LOCAL_PR_ARG, __entry->changed, __entry->center_freq 311 LOCAL_PR_ARG, __entry->changed, CHANDEF_PR_ARG
315 ) 312 )
316); 313);
317 314
@@ -359,8 +356,7 @@ TRACE_EVENT(drv_bss_info_changed,
359 __dynamic_array(u8, ssid, info->ssid_len); 356 __dynamic_array(u8, ssid, info->ssid_len);
360 __field(bool, hidden_ssid); 357 __field(bool, hidden_ssid);
361 __field(int, txpower) 358 __field(int, txpower)
362 __field(u8, p2p_ctwindow) 359 __field(u8, p2p_oppps_ctwindow)
363 __field(bool, p2p_oppps)
364 ), 360 ),
365 361
366 TP_fast_assign( 362 TP_fast_assign(
@@ -400,8 +396,7 @@ TRACE_EVENT(drv_bss_info_changed,
400 memcpy(__get_dynamic_array(ssid), info->ssid, info->ssid_len); 396 memcpy(__get_dynamic_array(ssid), info->ssid, info->ssid_len);
401 __entry->hidden_ssid = info->hidden_ssid; 397 __entry->hidden_ssid = info->hidden_ssid;
402 __entry->txpower = info->txpower; 398 __entry->txpower = info->txpower;
403 __entry->p2p_ctwindow = info->p2p_ctwindow; 399 __entry->p2p_oppps_ctwindow = info->p2p_noa_attr.oppps_ctwindow;
404 __entry->p2p_oppps = info->p2p_oppps;
405 ), 400 ),
406 401
407 TP_printk( 402 TP_printk(
@@ -431,6 +426,30 @@ TRACE_EVENT(drv_prepare_multicast,
431 ) 426 )
432); 427);
433 428
429TRACE_EVENT(drv_set_multicast_list,
430 TP_PROTO(struct ieee80211_local *local,
431 struct ieee80211_sub_if_data *sdata, int mc_count),
432
433 TP_ARGS(local, sdata, mc_count),
434
435 TP_STRUCT__entry(
436 LOCAL_ENTRY
437 __field(bool, allmulti)
438 __field(int, mc_count)
439 ),
440
441 TP_fast_assign(
442 LOCAL_ASSIGN;
443 __entry->allmulti = sdata->flags & IEEE80211_SDATA_ALLMULTI;
444 __entry->mc_count = mc_count;
445 ),
446
447 TP_printk(
448 LOCAL_PR_FMT " configure mc filter, count=%d, allmulti=%d",
449 LOCAL_PR_ARG, __entry->mc_count, __entry->allmulti
450 )
451);
452
434TRACE_EVENT(drv_configure_filter, 453TRACE_EVENT(drv_configure_filter,
435 TP_PROTO(struct ieee80211_local *local, 454 TP_PROTO(struct ieee80211_local *local,
436 unsigned int changed_flags, 455 unsigned int changed_flags,
@@ -940,23 +959,26 @@ TRACE_EVENT(drv_get_survey,
940); 959);
941 960
942TRACE_EVENT(drv_flush, 961TRACE_EVENT(drv_flush,
943 TP_PROTO(struct ieee80211_local *local, bool drop), 962 TP_PROTO(struct ieee80211_local *local,
963 u32 queues, bool drop),
944 964
945 TP_ARGS(local, drop), 965 TP_ARGS(local, queues, drop),
946 966
947 TP_STRUCT__entry( 967 TP_STRUCT__entry(
948 LOCAL_ENTRY 968 LOCAL_ENTRY
949 __field(bool, drop) 969 __field(bool, drop)
970 __field(u32, queues)
950 ), 971 ),
951 972
952 TP_fast_assign( 973 TP_fast_assign(
953 LOCAL_ASSIGN; 974 LOCAL_ASSIGN;
954 __entry->drop = drop; 975 __entry->drop = drop;
976 __entry->queues = queues;
955 ), 977 ),
956 978
957 TP_printk( 979 TP_printk(
958 LOCAL_PR_FMT " drop:%d", 980 LOCAL_PR_FMT " queues:0x%x drop:%d",
959 LOCAL_PR_ARG, __entry->drop 981 LOCAL_PR_ARG, __entry->queues, __entry->drop
960 ) 982 )
961); 983);
962 984
@@ -968,23 +990,23 @@ TRACE_EVENT(drv_channel_switch,
968 990
969 TP_STRUCT__entry( 991 TP_STRUCT__entry(
970 LOCAL_ENTRY 992 LOCAL_ENTRY
993 CHANDEF_ENTRY
971 __field(u64, timestamp) 994 __field(u64, timestamp)
972 __field(bool, block_tx) 995 __field(bool, block_tx)
973 __field(u16, freq)
974 __field(u8, count) 996 __field(u8, count)
975 ), 997 ),
976 998
977 TP_fast_assign( 999 TP_fast_assign(
978 LOCAL_ASSIGN; 1000 LOCAL_ASSIGN;
1001 CHANDEF_ASSIGN(&ch_switch->chandef)
979 __entry->timestamp = ch_switch->timestamp; 1002 __entry->timestamp = ch_switch->timestamp;
980 __entry->block_tx = ch_switch->block_tx; 1003 __entry->block_tx = ch_switch->block_tx;
981 __entry->freq = ch_switch->channel->center_freq;
982 __entry->count = ch_switch->count; 1004 __entry->count = ch_switch->count;
983 ), 1005 ),
984 1006
985 TP_printk( 1007 TP_printk(
986 LOCAL_PR_FMT " new freq:%u count:%d", 1008 LOCAL_PR_FMT " new " CHANDEF_PR_FMT " count:%d",
987 LOCAL_PR_ARG, __entry->freq, __entry->count 1009 LOCAL_PR_ARG, CHANDEF_PR_ARG, __entry->count
988 ) 1010 )
989); 1011);
990 1012
@@ -1042,15 +1064,17 @@ TRACE_EVENT(drv_remain_on_channel,
1042 TP_PROTO(struct ieee80211_local *local, 1064 TP_PROTO(struct ieee80211_local *local,
1043 struct ieee80211_sub_if_data *sdata, 1065 struct ieee80211_sub_if_data *sdata,
1044 struct ieee80211_channel *chan, 1066 struct ieee80211_channel *chan,
1045 unsigned int duration), 1067 unsigned int duration,
1068 enum ieee80211_roc_type type),
1046 1069
1047 TP_ARGS(local, sdata, chan, duration), 1070 TP_ARGS(local, sdata, chan, duration, type),
1048 1071
1049 TP_STRUCT__entry( 1072 TP_STRUCT__entry(
1050 LOCAL_ENTRY 1073 LOCAL_ENTRY
1051 VIF_ENTRY 1074 VIF_ENTRY
1052 __field(int, center_freq) 1075 __field(int, center_freq)
1053 __field(unsigned int, duration) 1076 __field(unsigned int, duration)
1077 __field(u32, type)
1054 ), 1078 ),
1055 1079
1056 TP_fast_assign( 1080 TP_fast_assign(
@@ -1058,12 +1082,13 @@ TRACE_EVENT(drv_remain_on_channel,
1058 VIF_ASSIGN; 1082 VIF_ASSIGN;
1059 __entry->center_freq = chan->center_freq; 1083 __entry->center_freq = chan->center_freq;
1060 __entry->duration = duration; 1084 __entry->duration = duration;
1085 __entry->type = type;
1061 ), 1086 ),
1062 1087
1063 TP_printk( 1088 TP_printk(
1064 LOCAL_PR_FMT VIF_PR_FMT " freq:%dMHz duration:%dms", 1089 LOCAL_PR_FMT VIF_PR_FMT " freq:%dMHz duration:%dms type=%d",
1065 LOCAL_PR_ARG, VIF_PR_ARG, 1090 LOCAL_PR_ARG, VIF_PR_ARG,
1066 __entry->center_freq, __entry->duration 1091 __entry->center_freq, __entry->duration, __entry->type
1067 ) 1092 )
1068); 1093);
1069 1094
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 8914d2d2881a..9972e07a2f96 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -48,15 +48,15 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
48 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 48 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
49 49
50 /* assume HW handles this */ 50 /* assume HW handles this */
51 if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS) 51 if (tx->rate.flags & IEEE80211_TX_RC_MCS)
52 return 0; 52 return 0;
53 53
54 /* uh huh? */ 54 /* uh huh? */
55 if (WARN_ON_ONCE(info->control.rates[0].idx < 0)) 55 if (WARN_ON_ONCE(tx->rate.idx < 0))
56 return 0; 56 return 0;
57 57
58 sband = local->hw.wiphy->bands[info->band]; 58 sband = local->hw.wiphy->bands[info->band];
59 txrate = &sband->bitrates[info->control.rates[0].idx]; 59 txrate = &sband->bitrates[tx->rate.idx];
60 60
61 erp = txrate->flags & IEEE80211_RATE_ERP_G; 61 erp = txrate->flags & IEEE80211_RATE_ERP_G;
62 62
@@ -233,6 +233,7 @@ ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx)
233 233
234 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 234 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
235 ieee80211_stop_queues_by_reason(&local->hw, 235 ieee80211_stop_queues_by_reason(&local->hw,
236 IEEE80211_MAX_QUEUE_MAP,
236 IEEE80211_QUEUE_STOP_REASON_PS); 237 IEEE80211_QUEUE_STOP_REASON_PS);
237 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; 238 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
238 ieee80211_queue_work(&local->hw, 239 ieee80211_queue_work(&local->hw,
@@ -616,11 +617,9 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
616 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 617 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
617 struct ieee80211_hdr *hdr = (void *)tx->skb->data; 618 struct ieee80211_hdr *hdr = (void *)tx->skb->data;
618 struct ieee80211_supported_band *sband; 619 struct ieee80211_supported_band *sband;
619 struct ieee80211_rate *rate;
620 int i;
621 u32 len; 620 u32 len;
622 bool inval = false, rts = false, short_preamble = false;
623 struct ieee80211_tx_rate_control txrc; 621 struct ieee80211_tx_rate_control txrc;
622 struct ieee80211_sta_rates *ratetbl = NULL;
624 bool assoc = false; 623 bool assoc = false;
625 624
626 memset(&txrc, 0, sizeof(txrc)); 625 memset(&txrc, 0, sizeof(txrc));
@@ -641,18 +640,23 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
641 txrc.max_rate_idx = -1; 640 txrc.max_rate_idx = -1;
642 else 641 else
643 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1; 642 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
644 memcpy(txrc.rate_idx_mcs_mask, 643
645 tx->sdata->rc_rateidx_mcs_mask[info->band], 644 if (tx->sdata->rc_has_mcs_mask[info->band])
646 sizeof(txrc.rate_idx_mcs_mask)); 645 txrc.rate_idx_mcs_mask =
646 tx->sdata->rc_rateidx_mcs_mask[info->band];
647
647 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP || 648 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
648 tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT || 649 tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
649 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC); 650 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC);
650 651
651 /* set up RTS protection if desired */ 652 /* set up RTS protection if desired */
652 if (len > tx->local->hw.wiphy->rts_threshold) { 653 if (len > tx->local->hw.wiphy->rts_threshold) {
653 txrc.rts = rts = true; 654 txrc.rts = true;
654 } 655 }
655 656
657 info->control.use_rts = txrc.rts;
658 info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot;
659
656 /* 660 /*
657 * Use short preamble if the BSS can handle it, but not for 661 * Use short preamble if the BSS can handle it, but not for
658 * management frames unless we know the receiver can handle 662 * management frames unless we know the receiver can handle
@@ -662,7 +666,9 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
662 if (tx->sdata->vif.bss_conf.use_short_preamble && 666 if (tx->sdata->vif.bss_conf.use_short_preamble &&
663 (ieee80211_is_data(hdr->frame_control) || 667 (ieee80211_is_data(hdr->frame_control) ||
664 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE)))) 668 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
665 txrc.short_preamble = short_preamble = true; 669 txrc.short_preamble = true;
670
671 info->control.short_preamble = txrc.short_preamble;
666 672
667 if (tx->sta) 673 if (tx->sta)
668 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC); 674 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
@@ -686,16 +692,38 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
686 */ 692 */
687 rate_control_get_rate(tx->sdata, tx->sta, &txrc); 693 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
688 694
689 if (unlikely(info->control.rates[0].idx < 0)) 695 if (tx->sta && !info->control.skip_table)
690 return TX_DROP; 696 ratetbl = rcu_dereference(tx->sta->sta.rates);
697
698 if (unlikely(info->control.rates[0].idx < 0)) {
699 if (ratetbl) {
700 struct ieee80211_tx_rate rate = {
701 .idx = ratetbl->rate[0].idx,
702 .flags = ratetbl->rate[0].flags,
703 .count = ratetbl->rate[0].count
704 };
705
706 if (ratetbl->rate[0].idx < 0)
707 return TX_DROP;
708
709 tx->rate = rate;
710 } else {
711 return TX_DROP;
712 }
713 } else {
714 tx->rate = info->control.rates[0];
715 }
691 716
692 if (txrc.reported_rate.idx < 0) { 717 if (txrc.reported_rate.idx < 0) {
693 txrc.reported_rate = info->control.rates[0]; 718 txrc.reported_rate = tx->rate;
694 if (tx->sta && ieee80211_is_data(hdr->frame_control)) 719 if (tx->sta && ieee80211_is_data(hdr->frame_control))
695 tx->sta->last_tx_rate = txrc.reported_rate; 720 tx->sta->last_tx_rate = txrc.reported_rate;
696 } else if (tx->sta) 721 } else if (tx->sta)
697 tx->sta->last_tx_rate = txrc.reported_rate; 722 tx->sta->last_tx_rate = txrc.reported_rate;
698 723
724 if (ratetbl)
725 return TX_CONTINUE;
726
699 if (unlikely(!info->control.rates[0].count)) 727 if (unlikely(!info->control.rates[0].count))
700 info->control.rates[0].count = 1; 728 info->control.rates[0].count = 1;
701 729
@@ -703,91 +731,6 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
703 (info->flags & IEEE80211_TX_CTL_NO_ACK))) 731 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
704 info->control.rates[0].count = 1; 732 info->control.rates[0].count = 1;
705 733
706 if (is_multicast_ether_addr(hdr->addr1)) {
707 /*
708 * XXX: verify the rate is in the basic rateset
709 */
710 return TX_CONTINUE;
711 }
712
713 /*
714 * set up the RTS/CTS rate as the fastest basic rate
715 * that is not faster than the data rate
716 *
717 * XXX: Should this check all retry rates?
718 */
719 if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
720 s8 baserate = 0;
721
722 rate = &sband->bitrates[info->control.rates[0].idx];
723
724 for (i = 0; i < sband->n_bitrates; i++) {
725 /* must be a basic rate */
726 if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
727 continue;
728 /* must not be faster than the data rate */
729 if (sband->bitrates[i].bitrate > rate->bitrate)
730 continue;
731 /* maximum */
732 if (sband->bitrates[baserate].bitrate <
733 sband->bitrates[i].bitrate)
734 baserate = i;
735 }
736
737 info->control.rts_cts_rate_idx = baserate;
738 }
739
740 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
741 /*
742 * make sure there's no valid rate following
743 * an invalid one, just in case drivers don't
744 * take the API seriously to stop at -1.
745 */
746 if (inval) {
747 info->control.rates[i].idx = -1;
748 continue;
749 }
750 if (info->control.rates[i].idx < 0) {
751 inval = true;
752 continue;
753 }
754
755 /*
756 * For now assume MCS is already set up correctly, this
757 * needs to be fixed.
758 */
759 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
760 WARN_ON(info->control.rates[i].idx > 76);
761 continue;
762 }
763
764 /* set up RTS protection if desired */
765 if (rts)
766 info->control.rates[i].flags |=
767 IEEE80211_TX_RC_USE_RTS_CTS;
768
769 /* RC is busted */
770 if (WARN_ON_ONCE(info->control.rates[i].idx >=
771 sband->n_bitrates)) {
772 info->control.rates[i].idx = -1;
773 continue;
774 }
775
776 rate = &sband->bitrates[info->control.rates[i].idx];
777
778 /* set up short preamble */
779 if (short_preamble &&
780 rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
781 info->control.rates[i].flags |=
782 IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
783
784 /* set up G protection */
785 if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
786 rate->flags & IEEE80211_RATE_ERP_G)
787 info->control.rates[i].flags |=
788 IEEE80211_TX_RC_USE_CTS_PROTECT;
789 }
790
791 return TX_CONTINUE; 734 return TX_CONTINUE;
792} 735}
793 736
@@ -991,15 +934,18 @@ static ieee80211_tx_result debug_noinline
991ieee80211_tx_h_stats(struct ieee80211_tx_data *tx) 934ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
992{ 935{
993 struct sk_buff *skb; 936 struct sk_buff *skb;
937 int ac = -1;
994 938
995 if (!tx->sta) 939 if (!tx->sta)
996 return TX_CONTINUE; 940 return TX_CONTINUE;
997 941
998 tx->sta->tx_packets++;
999 skb_queue_walk(&tx->skbs, skb) { 942 skb_queue_walk(&tx->skbs, skb) {
943 ac = skb_get_queue_mapping(skb);
1000 tx->sta->tx_fragments++; 944 tx->sta->tx_fragments++;
1001 tx->sta->tx_bytes += skb->len; 945 tx->sta->tx_bytes[ac] += skb->len;
1002 } 946 }
947 if (ac >= 0)
948 tx->sta->tx_packets[ac]++;
1003 949
1004 return TX_CONTINUE; 950 return TX_CONTINUE;
1005} 951}
@@ -1705,7 +1651,7 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1705 if (chanctx_conf) 1651 if (chanctx_conf)
1706 chan = chanctx_conf->def.chan; 1652 chan = chanctx_conf->def.chan;
1707 else if (!local->use_chanctx) 1653 else if (!local->use_chanctx)
1708 chan = local->_oper_channel; 1654 chan = local->_oper_chandef.chan;
1709 else 1655 else
1710 goto fail_rcu; 1656 goto fail_rcu;
1711 1657
@@ -1839,7 +1785,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1839 * This is the exception! WDS style interfaces are prohibited 1785 * This is the exception! WDS style interfaces are prohibited
1840 * when channel contexts are in used so this must be valid 1786 * when channel contexts are in used so this must be valid
1841 */ 1787 */
1842 band = local->hw.conf.channel->band; 1788 band = local->hw.conf.chandef.chan->band;
1843 break; 1789 break;
1844#ifdef CONFIG_MAC80211_MESH 1790#ifdef CONFIG_MAC80211_MESH
1845 case NL80211_IFTYPE_MESH_POINT: 1791 case NL80211_IFTYPE_MESH_POINT:
@@ -2085,7 +2031,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
2085 encaps_data = bridge_tunnel_header; 2031 encaps_data = bridge_tunnel_header;
2086 encaps_len = sizeof(bridge_tunnel_header); 2032 encaps_len = sizeof(bridge_tunnel_header);
2087 skip_header_bytes -= 2; 2033 skip_header_bytes -= 2;
2088 } else if (ethertype >= 0x600) { 2034 } else if (ethertype >= ETH_P_802_3_MIN) {
2089 encaps_data = rfc1042_header; 2035 encaps_data = rfc1042_header;
2090 encaps_len = sizeof(rfc1042_header); 2036 encaps_len = sizeof(rfc1042_header);
2091 skip_header_bytes -= 2; 2037 skip_header_bytes -= 2;
@@ -2438,14 +2384,17 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2438 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 2384 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2439 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 2385 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
2440 struct ieee80211_hdr *hdr; 2386 struct ieee80211_hdr *hdr;
2441 struct sk_buff *presp = rcu_dereference(ifibss->presp); 2387 struct beacon_data *presp = rcu_dereference(ifibss->presp);
2442 2388
2443 if (!presp) 2389 if (!presp)
2444 goto out; 2390 goto out;
2445 2391
2446 skb = skb_copy(presp, GFP_ATOMIC); 2392 skb = dev_alloc_skb(local->tx_headroom + presp->head_len);
2447 if (!skb) 2393 if (!skb)
2448 goto out; 2394 goto out;
2395 skb_reserve(skb, local->tx_headroom);
2396 memcpy(skb_put(skb, presp->head_len), presp->head,
2397 presp->head_len);
2449 2398
2450 hdr = (struct ieee80211_hdr *) skb->data; 2399 hdr = (struct ieee80211_hdr *) skb->data;
2451 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2400 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
@@ -2495,8 +2444,6 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2495 txrc.max_rate_idx = -1; 2444 txrc.max_rate_idx = -1;
2496 else 2445 else
2497 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1; 2446 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
2498 memcpy(txrc.rate_idx_mcs_mask, sdata->rc_rateidx_mcs_mask[band],
2499 sizeof(txrc.rate_idx_mcs_mask));
2500 txrc.bss = true; 2447 txrc.bss = true;
2501 rate_control_get_rate(sdata, NULL, &txrc); 2448 rate_control_get_rate(sdata, NULL, &txrc);
2502 2449
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 0f38f43ac62e..3f87fa468b1f 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -453,7 +453,8 @@ void ieee80211_add_pending_skbs_fn(struct ieee80211_local *local,
453} 453}
454 454
455void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw, 455void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
456 enum queue_stop_reason reason) 456 unsigned long queues,
457 enum queue_stop_reason reason)
457{ 458{
458 struct ieee80211_local *local = hw_to_local(hw); 459 struct ieee80211_local *local = hw_to_local(hw);
459 unsigned long flags; 460 unsigned long flags;
@@ -461,7 +462,7 @@ void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
461 462
462 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 463 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
463 464
464 for (i = 0; i < hw->queues; i++) 465 for_each_set_bit(i, &queues, hw->queues)
465 __ieee80211_stop_queue(hw, i, reason); 466 __ieee80211_stop_queue(hw, i, reason);
466 467
467 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 468 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
@@ -469,7 +470,7 @@ void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
469 470
470void ieee80211_stop_queues(struct ieee80211_hw *hw) 471void ieee80211_stop_queues(struct ieee80211_hw *hw)
471{ 472{
472 ieee80211_stop_queues_by_reason(hw, 473 ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
473 IEEE80211_QUEUE_STOP_REASON_DRIVER); 474 IEEE80211_QUEUE_STOP_REASON_DRIVER);
474} 475}
475EXPORT_SYMBOL(ieee80211_stop_queues); 476EXPORT_SYMBOL(ieee80211_stop_queues);
@@ -484,13 +485,15 @@ int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
484 return true; 485 return true;
485 486
486 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 487 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
487 ret = !!local->queue_stop_reasons[queue]; 488 ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER,
489 &local->queue_stop_reasons[queue]);
488 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 490 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
489 return ret; 491 return ret;
490} 492}
491EXPORT_SYMBOL(ieee80211_queue_stopped); 493EXPORT_SYMBOL(ieee80211_queue_stopped);
492 494
493void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw, 495void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
496 unsigned long queues,
494 enum queue_stop_reason reason) 497 enum queue_stop_reason reason)
495{ 498{
496 struct ieee80211_local *local = hw_to_local(hw); 499 struct ieee80211_local *local = hw_to_local(hw);
@@ -499,7 +502,7 @@ void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
499 502
500 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 503 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
501 504
502 for (i = 0; i < hw->queues; i++) 505 for_each_set_bit(i, &queues, hw->queues)
503 __ieee80211_wake_queue(hw, i, reason); 506 __ieee80211_wake_queue(hw, i, reason);
504 507
505 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 508 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
@@ -507,10 +510,42 @@ void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
507 510
508void ieee80211_wake_queues(struct ieee80211_hw *hw) 511void ieee80211_wake_queues(struct ieee80211_hw *hw)
509{ 512{
510 ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER); 513 ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
514 IEEE80211_QUEUE_STOP_REASON_DRIVER);
511} 515}
512EXPORT_SYMBOL(ieee80211_wake_queues); 516EXPORT_SYMBOL(ieee80211_wake_queues);
513 517
518void ieee80211_flush_queues(struct ieee80211_local *local,
519 struct ieee80211_sub_if_data *sdata)
520{
521 u32 queues;
522
523 if (!local->ops->flush)
524 return;
525
526 if (sdata && local->hw.flags & IEEE80211_HW_QUEUE_CONTROL) {
527 int ac;
528
529 queues = 0;
530
531 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
532 queues |= BIT(sdata->vif.hw_queue[ac]);
533 if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE)
534 queues |= BIT(sdata->vif.cab_queue);
535 } else {
536 /* all queues */
537 queues = BIT(local->hw.queues) - 1;
538 }
539
540 ieee80211_stop_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
541 IEEE80211_QUEUE_STOP_REASON_FLUSH);
542
543 drv_flush(local, queues, false);
544
545 ieee80211_wake_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
546 IEEE80211_QUEUE_STOP_REASON_FLUSH);
547}
548
514void ieee80211_iterate_active_interfaces( 549void ieee80211_iterate_active_interfaces(
515 struct ieee80211_hw *hw, u32 iter_flags, 550 struct ieee80211_hw *hw, u32 iter_flags,
516 void (*iterator)(void *data, u8 *mac, 551 void (*iterator)(void *data, u8 *mac,
@@ -626,7 +661,7 @@ void ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
626} 661}
627EXPORT_SYMBOL(ieee80211_queue_delayed_work); 662EXPORT_SYMBOL(ieee80211_queue_delayed_work);
628 663
629u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, 664u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, bool action,
630 struct ieee802_11_elems *elems, 665 struct ieee802_11_elems *elems,
631 u64 filter, u32 crc) 666 u64 filter, u32 crc)
632{ 667{
@@ -634,6 +669,7 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
634 u8 *pos = start; 669 u8 *pos = start;
635 bool calc_crc = filter != 0; 670 bool calc_crc = filter != 0;
636 DECLARE_BITMAP(seen_elems, 256); 671 DECLARE_BITMAP(seen_elems, 256);
672 const u8 *ie;
637 673
638 bitmap_zero(seen_elems, 256); 674 bitmap_zero(seen_elems, 256);
639 memset(elems, 0, sizeof(*elems)); 675 memset(elems, 0, sizeof(*elems));
@@ -681,6 +717,12 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
681 case WLAN_EID_COUNTRY: 717 case WLAN_EID_COUNTRY:
682 case WLAN_EID_PWR_CONSTRAINT: 718 case WLAN_EID_PWR_CONSTRAINT:
683 case WLAN_EID_TIMEOUT_INTERVAL: 719 case WLAN_EID_TIMEOUT_INTERVAL:
720 case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
721 case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
722 /*
723 * not listing WLAN_EID_CHANNEL_SWITCH_WRAPPER -- it seems possible
724 * that if the content gets bigger it might be needed more than once
725 */
684 if (test_bit(id, seen_elems)) { 726 if (test_bit(id, seen_elems)) {
685 elems->parse_error = true; 727 elems->parse_error = true;
686 left -= elen; 728 left -= elen;
@@ -704,17 +746,11 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
704 elems->supp_rates = pos; 746 elems->supp_rates = pos;
705 elems->supp_rates_len = elen; 747 elems->supp_rates_len = elen;
706 break; 748 break;
707 case WLAN_EID_FH_PARAMS:
708 elems->fh_params = pos;
709 elems->fh_params_len = elen;
710 break;
711 case WLAN_EID_DS_PARAMS: 749 case WLAN_EID_DS_PARAMS:
712 elems->ds_params = pos; 750 if (elen >= 1)
713 elems->ds_params_len = elen; 751 elems->ds_params = pos;
714 break; 752 else
715 case WLAN_EID_CF_PARAMS: 753 elem_parse_failed = true;
716 elems->cf_params = pos;
717 elems->cf_params_len = elen;
718 break; 754 break;
719 case WLAN_EID_TIM: 755 case WLAN_EID_TIM:
720 if (elen >= sizeof(struct ieee80211_tim_ie)) { 756 if (elen >= sizeof(struct ieee80211_tim_ie)) {
@@ -723,10 +759,6 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
723 } else 759 } else
724 elem_parse_failed = true; 760 elem_parse_failed = true;
725 break; 761 break;
726 case WLAN_EID_IBSS_PARAMS:
727 elems->ibss_params = pos;
728 elems->ibss_params_len = elen;
729 break;
730 case WLAN_EID_CHALLENGE: 762 case WLAN_EID_CHALLENGE:
731 elems->challenge = pos; 763 elems->challenge = pos;
732 elems->challenge_len = elen; 764 elems->challenge_len = elen;
@@ -756,8 +788,10 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
756 elems->rsn_len = elen; 788 elems->rsn_len = elen;
757 break; 789 break;
758 case WLAN_EID_ERP_INFO: 790 case WLAN_EID_ERP_INFO:
759 elems->erp_info = pos; 791 if (elen >= 1)
760 elems->erp_info_len = elen; 792 elems->erp_info = pos;
793 else
794 elem_parse_failed = true;
761 break; 795 break;
762 case WLAN_EID_EXT_SUPP_RATES: 796 case WLAN_EID_EXT_SUPP_RATES:
763 elems->ext_supp_rates = pos; 797 elems->ext_supp_rates = pos;
@@ -836,12 +870,47 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
836 } 870 }
837 elems->ch_switch_ie = (void *)pos; 871 elems->ch_switch_ie = (void *)pos;
838 break; 872 break;
839 case WLAN_EID_QUIET: 873 case WLAN_EID_EXT_CHANSWITCH_ANN:
840 if (!elems->quiet_elem) { 874 if (elen != sizeof(struct ieee80211_ext_chansw_ie)) {
841 elems->quiet_elem = pos; 875 elem_parse_failed = true;
842 elems->quiet_elem_len = elen; 876 break;
877 }
878 elems->ext_chansw_ie = (void *)pos;
879 break;
880 case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
881 if (elen != sizeof(struct ieee80211_sec_chan_offs_ie)) {
882 elem_parse_failed = true;
883 break;
884 }
885 elems->sec_chan_offs = (void *)pos;
886 break;
887 case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
888 if (!action ||
889 elen != sizeof(*elems->wide_bw_chansw_ie)) {
890 elem_parse_failed = true;
891 break;
892 }
893 elems->wide_bw_chansw_ie = (void *)pos;
894 break;
895 case WLAN_EID_CHANNEL_SWITCH_WRAPPER:
896 if (action) {
897 elem_parse_failed = true;
898 break;
899 }
900 /*
901 * This is a bit tricky, but as we only care about
902 * the wide bandwidth channel switch element, so
903 * just parse it out manually.
904 */
905 ie = cfg80211_find_ie(WLAN_EID_WIDE_BW_CHANNEL_SWITCH,
906 pos, elen);
907 if (ie) {
908 if (ie[1] == sizeof(*elems->wide_bw_chansw_ie))
909 elems->wide_bw_chansw_ie =
910 (void *)(ie + 2);
911 else
912 elem_parse_failed = true;
843 } 913 }
844 elems->num_of_quiet_elem++;
845 break; 914 break;
846 case WLAN_EID_COUNTRY: 915 case WLAN_EID_COUNTRY:
847 elems->country_elem = pos; 916 elems->country_elem = pos;
@@ -855,8 +924,10 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
855 elems->pwr_constr_elem = pos; 924 elems->pwr_constr_elem = pos;
856 break; 925 break;
857 case WLAN_EID_TIMEOUT_INTERVAL: 926 case WLAN_EID_TIMEOUT_INTERVAL:
858 elems->timeout_int = pos; 927 if (elen >= sizeof(struct ieee80211_timeout_interval_ie))
859 elems->timeout_int_len = elen; 928 elems->timeout_int = (void *)pos;
929 else
930 elem_parse_failed = true;
860 break; 931 break;
861 default: 932 default:
862 break; 933 break;
@@ -877,12 +948,6 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
877 return crc; 948 return crc;
878} 949}
879 950
880void ieee802_11_parse_elems(u8 *start, size_t len,
881 struct ieee802_11_elems *elems)
882{
883 ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
884}
885
886void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata, 951void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
887 bool bss_notify) 952 bool bss_notify)
888{ 953{
@@ -1357,6 +1422,25 @@ void ieee80211_stop_device(struct ieee80211_local *local)
1357 drv_stop(local); 1422 drv_stop(local);
1358} 1423}
1359 1424
1425static void ieee80211_assign_chanctx(struct ieee80211_local *local,
1426 struct ieee80211_sub_if_data *sdata)
1427{
1428 struct ieee80211_chanctx_conf *conf;
1429 struct ieee80211_chanctx *ctx;
1430
1431 if (!local->use_chanctx)
1432 return;
1433
1434 mutex_lock(&local->chanctx_mtx);
1435 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1436 lockdep_is_held(&local->chanctx_mtx));
1437 if (conf) {
1438 ctx = container_of(conf, struct ieee80211_chanctx, conf);
1439 drv_assign_vif_chanctx(local, sdata, ctx);
1440 }
1441 mutex_unlock(&local->chanctx_mtx);
1442}
1443
1360int ieee80211_reconfig(struct ieee80211_local *local) 1444int ieee80211_reconfig(struct ieee80211_local *local)
1361{ 1445{
1362 struct ieee80211_hw *hw = &local->hw; 1446 struct ieee80211_hw *hw = &local->hw;
@@ -1421,6 +1505,8 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1421 /* add interfaces */ 1505 /* add interfaces */
1422 sdata = rtnl_dereference(local->monitor_sdata); 1506 sdata = rtnl_dereference(local->monitor_sdata);
1423 if (sdata) { 1507 if (sdata) {
1508 /* in HW restart it exists already */
1509 WARN_ON(local->resuming);
1424 res = drv_add_interface(local, sdata); 1510 res = drv_add_interface(local, sdata);
1425 if (WARN_ON(res)) { 1511 if (WARN_ON(res)) {
1426 rcu_assign_pointer(local->monitor_sdata, NULL); 1512 rcu_assign_pointer(local->monitor_sdata, NULL);
@@ -1445,36 +1531,14 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1445 } 1531 }
1446 1532
1447 list_for_each_entry(sdata, &local->interfaces, list) { 1533 list_for_each_entry(sdata, &local->interfaces, list) {
1448 struct ieee80211_chanctx_conf *ctx_conf;
1449
1450 if (!ieee80211_sdata_running(sdata)) 1534 if (!ieee80211_sdata_running(sdata))
1451 continue; 1535 continue;
1452 1536 ieee80211_assign_chanctx(local, sdata);
1453 mutex_lock(&local->chanctx_mtx);
1454 ctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1455 lockdep_is_held(&local->chanctx_mtx));
1456 if (ctx_conf) {
1457 ctx = container_of(ctx_conf, struct ieee80211_chanctx,
1458 conf);
1459 drv_assign_vif_chanctx(local, sdata, ctx);
1460 }
1461 mutex_unlock(&local->chanctx_mtx);
1462 } 1537 }
1463 1538
1464 sdata = rtnl_dereference(local->monitor_sdata); 1539 sdata = rtnl_dereference(local->monitor_sdata);
1465 if (sdata && local->use_chanctx && ieee80211_sdata_running(sdata)) { 1540 if (sdata && ieee80211_sdata_running(sdata))
1466 struct ieee80211_chanctx_conf *ctx_conf; 1541 ieee80211_assign_chanctx(local, sdata);
1467
1468 mutex_lock(&local->chanctx_mtx);
1469 ctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1470 lockdep_is_held(&local->chanctx_mtx));
1471 if (ctx_conf) {
1472 ctx = container_of(ctx_conf, struct ieee80211_chanctx,
1473 conf);
1474 drv_assign_vif_chanctx(local, sdata, ctx);
1475 }
1476 mutex_unlock(&local->chanctx_mtx);
1477 }
1478 1542
1479 /* add STAs back */ 1543 /* add STAs back */
1480 mutex_lock(&local->sta_mtx); 1544 mutex_lock(&local->sta_mtx);
@@ -1534,11 +1598,6 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1534 BSS_CHANGED_IDLE | 1598 BSS_CHANGED_IDLE |
1535 BSS_CHANGED_TXPOWER; 1599 BSS_CHANGED_TXPOWER;
1536 1600
1537#ifdef CONFIG_PM
1538 if (local->resuming && !reconfig_due_to_wowlan)
1539 sdata->vif.bss_conf = sdata->suspend_bss_conf;
1540#endif
1541
1542 switch (sdata->vif.type) { 1601 switch (sdata->vif.type) {
1543 case NL80211_IFTYPE_STATION: 1602 case NL80211_IFTYPE_STATION:
1544 changed |= BSS_CHANGED_ASSOC | 1603 changed |= BSS_CHANGED_ASSOC |
@@ -1637,6 +1696,9 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1637 local->in_reconfig = false; 1696 local->in_reconfig = false;
1638 barrier(); 1697 barrier();
1639 1698
1699 if (local->monitors == local->open_count && local->monitors > 0)
1700 ieee80211_add_virtual_monitor(local);
1701
1640 /* 1702 /*
1641 * Clear the WLAN_STA_BLOCK_BA flag so new aggregation 1703 * Clear the WLAN_STA_BLOCK_BA flag so new aggregation
1642 * sessions can be established after a resume. 1704 * sessions can be established after a resume.
@@ -1659,8 +1721,8 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1659 mutex_unlock(&local->sta_mtx); 1721 mutex_unlock(&local->sta_mtx);
1660 } 1722 }
1661 1723
1662 ieee80211_wake_queues_by_reason(hw, 1724 ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
1663 IEEE80211_QUEUE_STOP_REASON_SUSPEND); 1725 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
1664 1726
1665 /* 1727 /*
1666 * If this is for hw restart things are still running. 1728 * If this is for hw restart things are still running.
@@ -1678,28 +1740,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1678 mb(); 1740 mb();
1679 local->resuming = false; 1741 local->resuming = false;
1680 1742
1681 list_for_each_entry(sdata, &local->interfaces, list) {
1682 switch(sdata->vif.type) {
1683 case NL80211_IFTYPE_STATION:
1684 ieee80211_sta_restart(sdata);
1685 break;
1686 case NL80211_IFTYPE_ADHOC:
1687 ieee80211_ibss_restart(sdata);
1688 break;
1689 case NL80211_IFTYPE_MESH_POINT:
1690 ieee80211_mesh_restart(sdata);
1691 break;
1692 default:
1693 break;
1694 }
1695 }
1696
1697 mod_timer(&local->sta_cleanup, jiffies + 1); 1743 mod_timer(&local->sta_cleanup, jiffies + 1);
1698
1699 mutex_lock(&local->sta_mtx);
1700 list_for_each_entry(sta, &local->sta_list, list)
1701 mesh_plink_restart(sta);
1702 mutex_unlock(&local->sta_mtx);
1703#else 1744#else
1704 WARN_ON(1); 1745 WARN_ON(1);
1705#endif 1746#endif
@@ -2051,7 +2092,7 @@ int ieee80211_ave_rssi(struct ieee80211_vif *vif)
2051 /* non-managed type inferfaces */ 2092 /* non-managed type inferfaces */
2052 return 0; 2093 return 0;
2053 } 2094 }
2054 return ifmgd->ave_beacon_signal; 2095 return ifmgd->ave_beacon_signal / 16;
2055} 2096}
2056EXPORT_SYMBOL_GPL(ieee80211_ave_rssi); 2097EXPORT_SYMBOL_GPL(ieee80211_ave_rssi);
2057 2098
@@ -2166,8 +2207,7 @@ void ieee80211_dfs_radar_detected_work(struct work_struct *work)
2166 /* currently not handled */ 2207 /* currently not handled */
2167 WARN_ON(1); 2208 WARN_ON(1);
2168 else { 2209 else {
2169 cfg80211_chandef_create(&chandef, local->hw.conf.channel, 2210 chandef = local->hw.conf.chandef;
2170 local->hw.conf.channel_type);
2171 cfg80211_radar_event(local->hw.wiphy, &chandef, GFP_KERNEL); 2211 cfg80211_radar_event(local->hw.wiphy, &chandef, GFP_KERNEL);
2172 } 2212 }
2173} 2213}
diff --git a/net/mac80211/vht.c b/net/mac80211/vht.c
index a2c2258bc84e..171344d4eb7c 100644
--- a/net/mac80211/vht.c
+++ b/net/mac80211/vht.c
@@ -13,6 +13,104 @@
13#include "rate.h" 13#include "rate.h"
14 14
15 15
16static void __check_vhtcap_disable(struct ieee80211_sub_if_data *sdata,
17 struct ieee80211_sta_vht_cap *vht_cap,
18 u32 flag)
19{
20 __le32 le_flag = cpu_to_le32(flag);
21
22 if (sdata->u.mgd.vht_capa_mask.vht_cap_info & le_flag &&
23 !(sdata->u.mgd.vht_capa.vht_cap_info & le_flag))
24 vht_cap->cap &= ~flag;
25}
26
27void ieee80211_apply_vhtcap_overrides(struct ieee80211_sub_if_data *sdata,
28 struct ieee80211_sta_vht_cap *vht_cap)
29{
30 int i;
31 u16 rxmcs_mask, rxmcs_cap, rxmcs_n, txmcs_mask, txmcs_cap, txmcs_n;
32
33 if (!vht_cap->vht_supported)
34 return;
35
36 if (sdata->vif.type != NL80211_IFTYPE_STATION)
37 return;
38
39 __check_vhtcap_disable(sdata, vht_cap,
40 IEEE80211_VHT_CAP_RXLDPC);
41 __check_vhtcap_disable(sdata, vht_cap,
42 IEEE80211_VHT_CAP_SHORT_GI_80);
43 __check_vhtcap_disable(sdata, vht_cap,
44 IEEE80211_VHT_CAP_SHORT_GI_160);
45 __check_vhtcap_disable(sdata, vht_cap,
46 IEEE80211_VHT_CAP_TXSTBC);
47 __check_vhtcap_disable(sdata, vht_cap,
48 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
49 __check_vhtcap_disable(sdata, vht_cap,
50 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE);
51 __check_vhtcap_disable(sdata, vht_cap,
52 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN);
53 __check_vhtcap_disable(sdata, vht_cap,
54 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN);
55
56 /* Allow user to decrease AMPDU length exponent */
57 if (sdata->u.mgd.vht_capa_mask.vht_cap_info &
58 cpu_to_le32(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK)) {
59 u32 cap, n;
60
61 n = le32_to_cpu(sdata->u.mgd.vht_capa.vht_cap_info) &
62 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
63 n >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
64 cap = vht_cap->cap & IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
65 cap >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
66
67 if (n < cap) {
68 vht_cap->cap &=
69 ~IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
70 vht_cap->cap |=
71 n << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
72 }
73 }
74
75 /* Allow the user to decrease MCSes */
76 rxmcs_mask =
77 le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.rx_mcs_map);
78 rxmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.rx_mcs_map);
79 rxmcs_n &= rxmcs_mask;
80 rxmcs_cap = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
81
82 txmcs_mask =
83 le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.tx_mcs_map);
84 txmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.tx_mcs_map);
85 txmcs_n &= txmcs_mask;
86 txmcs_cap = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
87 for (i = 0; i < 8; i++) {
88 u8 m, n, c;
89
90 m = (rxmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
91 n = (rxmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
92 c = (rxmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
93
94 if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) ||
95 n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) {
96 rxmcs_cap &= ~(3 << 2*i);
97 rxmcs_cap |= (rxmcs_n & (3 << 2*i));
98 }
99
100 m = (txmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
101 n = (txmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
102 c = (txmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
103
104 if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) ||
105 n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) {
106 txmcs_cap &= ~(3 << 2*i);
107 txmcs_cap |= (txmcs_n & (3 << 2*i));
108 }
109 }
110 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_cap);
111 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_cap);
112}
113
16void 114void
17ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata, 115ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
18 struct ieee80211_supported_band *sband, 116 struct ieee80211_supported_band *sband,
@@ -20,6 +118,8 @@ ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
20 struct sta_info *sta) 118 struct sta_info *sta)
21{ 119{
22 struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap; 120 struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
121 struct ieee80211_sta_vht_cap own_cap;
122 u32 cap_info, i;
23 123
24 memset(vht_cap, 0, sizeof(*vht_cap)); 124 memset(vht_cap, 0, sizeof(*vht_cap));
25 125
@@ -35,12 +135,122 @@ ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
35 135
36 vht_cap->vht_supported = true; 136 vht_cap->vht_supported = true;
37 137
38 vht_cap->cap = le32_to_cpu(vht_cap_ie->vht_cap_info); 138 own_cap = sband->vht_cap;
139 /*
140 * If user has specified capability overrides, take care
141 * of that if the station we're setting up is the AP that
142 * we advertised a restricted capability set to. Override
143 * our own capabilities and then use those below.
144 */
145 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
146 !test_sta_flag(sta, WLAN_STA_TDLS_PEER))
147 ieee80211_apply_vhtcap_overrides(sdata, &own_cap);
148
149 /* take some capabilities as-is */
150 cap_info = le32_to_cpu(vht_cap_ie->vht_cap_info);
151 vht_cap->cap = cap_info;
152 vht_cap->cap &= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
153 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
154 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
155 IEEE80211_VHT_CAP_RXLDPC |
156 IEEE80211_VHT_CAP_VHT_TXOP_PS |
157 IEEE80211_VHT_CAP_HTC_VHT |
158 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
159 IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB |
160 IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB |
161 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
162 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
163
164 /* and some based on our own capabilities */
165 switch (own_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
166 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
167 vht_cap->cap |= cap_info &
168 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
169 break;
170 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
171 vht_cap->cap |= cap_info &
172 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
173 break;
174 default:
175 /* nothing */
176 break;
177 }
178
179 /* symmetric capabilities */
180 vht_cap->cap |= cap_info & own_cap.cap &
181 (IEEE80211_VHT_CAP_SHORT_GI_80 |
182 IEEE80211_VHT_CAP_SHORT_GI_160);
183
184 /* remaining ones */
185 if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) {
186 vht_cap->cap |= cap_info &
187 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
188 IEEE80211_VHT_CAP_BEAMFORMER_ANTENNAS_MAX |
189 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MAX);
190 }
191
192 if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
193 vht_cap->cap |= cap_info &
194 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
195
196 if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
197 vht_cap->cap |= cap_info &
198 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
199
200 if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
201 vht_cap->cap |= cap_info &
202 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
203
204 if (own_cap.cap & IEEE80211_VHT_CAP_TXSTBC)
205 vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_RXSTBC_MASK;
206
207 if (own_cap.cap & IEEE80211_VHT_CAP_RXSTBC_MASK)
208 vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_TXSTBC;
39 209
40 /* Copy peer MCS info, the driver might need them. */ 210 /* Copy peer MCS info, the driver might need them. */
41 memcpy(&vht_cap->vht_mcs, &vht_cap_ie->supp_mcs, 211 memcpy(&vht_cap->vht_mcs, &vht_cap_ie->supp_mcs,
42 sizeof(struct ieee80211_vht_mcs_info)); 212 sizeof(struct ieee80211_vht_mcs_info));
43 213
214 /* but also restrict MCSes */
215 for (i = 0; i < 8; i++) {
216 u16 own_rx, own_tx, peer_rx, peer_tx;
217
218 own_rx = le16_to_cpu(own_cap.vht_mcs.rx_mcs_map);
219 own_rx = (own_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
220
221 own_tx = le16_to_cpu(own_cap.vht_mcs.tx_mcs_map);
222 own_tx = (own_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
223
224 peer_rx = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
225 peer_rx = (peer_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
226
227 peer_tx = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
228 peer_tx = (peer_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
229
230 if (peer_tx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
231 if (own_rx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
232 peer_tx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
233 else if (own_rx < peer_tx)
234 peer_tx = own_rx;
235 }
236
237 if (peer_rx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
238 if (own_tx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
239 peer_rx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
240 else if (own_tx < peer_rx)
241 peer_rx = own_tx;
242 }
243
244 vht_cap->vht_mcs.rx_mcs_map &=
245 ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
246 vht_cap->vht_mcs.rx_mcs_map |= cpu_to_le16(peer_rx << i * 2);
247
248 vht_cap->vht_mcs.tx_mcs_map &=
249 ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
250 vht_cap->vht_mcs.tx_mcs_map |= cpu_to_le16(peer_tx << i * 2);
251 }
252
253 /* finally set up the bandwidth */
44 switch (vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) { 254 switch (vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
45 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ: 255 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
46 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ: 256 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ: