1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394
|
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/*
* Copyright (C) 2024 - 2025 Intel Corporation
*/
#include <net/ip.h>
#include "tx.h"
#include "sta.h"
#include "hcmd.h"
#include "iwl-utils.h"
#include "iface.h"
#include "fw/dbg.h"
#include "fw/api/tx.h"
#include "fw/api/rs.h"
#include "fw/api/txq.h"
#include "fw/api/datapath.h"
#include "fw/api/time-event.h"
#define MAX_ANT_NUM 2
/* Toggles between TX antennas. Receives the bitmask of valid TX antennas and
* the *index* used for the last TX, and returns the next valid *index* to use.
* In order to set it in the tx_cmd, must do BIT(idx).
*/
static u8 iwl_mld_next_ant(u8 valid, u8 last_idx)
{
u8 index = last_idx;
for (int i = 0; i < MAX_ANT_NUM; i++) {
index = (index + 1) % MAX_ANT_NUM;
if (valid & BIT(index))
return index;
}
WARN_ONCE(1, "Failed to toggle between antennas 0x%x", valid);
return last_idx;
}
void iwl_mld_toggle_tx_ant(struct iwl_mld *mld, u8 *ant)
{
*ant = iwl_mld_next_ant(iwl_mld_get_valid_tx_ant(mld), *ant);
}
static int
iwl_mld_get_queue_size(struct iwl_mld *mld, struct ieee80211_txq *txq)
{
struct ieee80211_sta *sta = txq->sta;
struct ieee80211_link_sta *link_sta;
unsigned int link_id;
int max_size = IWL_DEFAULT_QUEUE_SIZE;
lockdep_assert_wiphy(mld->wiphy);
for_each_sta_active_link(txq->vif, sta, link_sta, link_id) {
if (link_sta->eht_cap.has_eht) {
max_size = IWL_DEFAULT_QUEUE_SIZE_EHT;
break;
}
if (link_sta->he_cap.has_he)
max_size = IWL_DEFAULT_QUEUE_SIZE_HE;
}
return max_size;
}
static int iwl_mld_allocate_txq(struct iwl_mld *mld, struct ieee80211_txq *txq)
{
u8 tid = txq->tid == IEEE80211_NUM_TIDS ? IWL_MGMT_TID : txq->tid;
u32 fw_sta_mask = iwl_mld_fw_sta_id_mask(mld, txq->sta);
/* We can't know when the station is asleep or awake, so we
* must disable the queue hang detection.
*/
unsigned int watchdog_timeout = txq->vif->type == NL80211_IFTYPE_AP ?
IWL_WATCHDOG_DISABLED :
mld->trans->mac_cfg->base->wd_timeout;
int queue, size;
lockdep_assert_wiphy(mld->wiphy);
if (tid == IWL_MGMT_TID)
size = max_t(u32, IWL_MGMT_QUEUE_SIZE,
mld->trans->mac_cfg->base->min_txq_size);
else
size = iwl_mld_get_queue_size(mld, txq);
queue = iwl_trans_txq_alloc(mld->trans, 0, fw_sta_mask, tid, size,
watchdog_timeout);
if (queue >= 0)
IWL_DEBUG_TX_QUEUES(mld,
"Enabling TXQ #%d for sta mask 0x%x tid %d\n",
queue, fw_sta_mask, tid);
return queue;
}
static int iwl_mld_add_txq(struct iwl_mld *mld, struct ieee80211_txq *txq)
{
struct iwl_mld_txq *mld_txq = iwl_mld_txq_from_mac80211(txq);
int id;
lockdep_assert_wiphy(mld->wiphy);
/* This will alse send the SCD_QUEUE_CONFIG_CMD */
id = iwl_mld_allocate_txq(mld, txq);
if (id < 0)
return id;
mld_txq->fw_id = id;
mld_txq->status.allocated = true;
rcu_assign_pointer(mld->fw_id_to_txq[id], txq);
return 0;
}
void iwl_mld_add_txq_list(struct iwl_mld *mld)
{
lockdep_assert_wiphy(mld->wiphy);
while (!list_empty(&mld->txqs_to_add)) {
struct ieee80211_txq *txq;
struct iwl_mld_txq *mld_txq =
list_first_entry(&mld->txqs_to_add, struct iwl_mld_txq,
list);
int failed;
txq = container_of((void *)mld_txq, struct ieee80211_txq,
drv_priv);
failed = iwl_mld_add_txq(mld, txq);
local_bh_disable();
spin_lock(&mld->add_txqs_lock);
list_del_init(&mld_txq->list);
spin_unlock(&mld->add_txqs_lock);
/* If the queue allocation failed, we can't transmit. Leave the
* frames on the txq, maybe the attempt to allocate the queue
* will succeed.
*/
if (!failed)
iwl_mld_tx_from_txq(mld, txq);
local_bh_enable();
}
}
void iwl_mld_add_txqs_wk(struct wiphy *wiphy, struct wiphy_work *wk)
{
struct iwl_mld *mld = container_of(wk, struct iwl_mld,
add_txqs_wk);
/* will reschedule to run after restart */
if (mld->fw_status.in_hw_restart)
return;
iwl_mld_add_txq_list(mld);
}
void
iwl_mld_free_txq(struct iwl_mld *mld, u32 fw_sta_mask, u32 tid, u32 queue_id)
{
struct iwl_scd_queue_cfg_cmd remove_cmd = {
.operation = cpu_to_le32(IWL_SCD_QUEUE_REMOVE),
.u.remove.tid = cpu_to_le32(tid),
.u.remove.sta_mask = cpu_to_le32(fw_sta_mask),
};
iwl_mld_send_cmd_pdu(mld,
WIDE_ID(DATA_PATH_GROUP, SCD_QUEUE_CONFIG_CMD),
&remove_cmd);
iwl_trans_txq_free(mld->trans, queue_id);
}
void iwl_mld_remove_txq(struct iwl_mld *mld, struct ieee80211_txq *txq)
{
struct iwl_mld_txq *mld_txq = iwl_mld_txq_from_mac80211(txq);
u32 sta_msk, tid;
lockdep_assert_wiphy(mld->wiphy);
spin_lock_bh(&mld->add_txqs_lock);
if (!list_empty(&mld_txq->list))
list_del_init(&mld_txq->list);
spin_unlock_bh(&mld->add_txqs_lock);
if (!mld_txq->status.allocated ||
WARN_ON(mld_txq->fw_id >= ARRAY_SIZE(mld->fw_id_to_txq)))
return;
sta_msk = iwl_mld_fw_sta_id_mask(mld, txq->sta);
tid = txq->tid == IEEE80211_NUM_TIDS ? IWL_MGMT_TID :
txq->tid;
iwl_mld_free_txq(mld, sta_msk, tid, mld_txq->fw_id);
RCU_INIT_POINTER(mld->fw_id_to_txq[mld_txq->fw_id], NULL);
mld_txq->status.allocated = false;
}
#define OPT_HDR(type, skb, off) \
(type *)(skb_network_header(skb) + (off))
static __le32
iwl_mld_get_offload_assist(struct sk_buff *skb, bool amsdu)
{
struct ieee80211_hdr *hdr = (void *)skb->data;
u16 mh_len = ieee80211_hdrlen(hdr->frame_control);
u16 offload_assist = 0;
#if IS_ENABLED(CONFIG_INET)
u8 protocol = 0;
/* Do not compute checksum if already computed */
if (skb->ip_summed != CHECKSUM_PARTIAL)
goto out;
/* We do not expect to be requested to csum stuff we do not support */
/* TBD: do we also need to check
* !(mvm->hw->netdev_features & IWL_TX_CSUM_NETIF_FLAGS) now that all
* the devices we support has this flags?
*/
if (WARN_ONCE(skb->protocol != htons(ETH_P_IP) &&
skb->protocol != htons(ETH_P_IPV6),
"No support for requested checksum\n")) {
skb_checksum_help(skb);
goto out;
}
if (skb->protocol == htons(ETH_P_IP)) {
protocol = ip_hdr(skb)->protocol;
} else {
#if IS_ENABLED(CONFIG_IPV6)
struct ipv6hdr *ipv6h =
(struct ipv6hdr *)skb_network_header(skb);
unsigned int off = sizeof(*ipv6h);
protocol = ipv6h->nexthdr;
while (protocol != NEXTHDR_NONE && ipv6_ext_hdr(protocol)) {
struct ipv6_opt_hdr *hp;
/* only supported extension headers */
if (protocol != NEXTHDR_ROUTING &&
protocol != NEXTHDR_HOP &&
protocol != NEXTHDR_DEST) {
skb_checksum_help(skb);
goto out;
}
hp = OPT_HDR(struct ipv6_opt_hdr, skb, off);
protocol = hp->nexthdr;
off += ipv6_optlen(hp);
}
/* if we get here - protocol now should be TCP/UDP */
#endif
}
if (protocol != IPPROTO_TCP && protocol != IPPROTO_UDP) {
WARN_ON_ONCE(1);
skb_checksum_help(skb);
goto out;
}
/* enable L4 csum */
offload_assist |= BIT(TX_CMD_OFFLD_L4_EN);
/* Set offset to IP header (snap).
* We don't support tunneling so no need to take care of inner header.
* Size is in words.
*/
offload_assist |= (4 << TX_CMD_OFFLD_IP_HDR);
/* Do IPv4 csum for AMSDU only (no IP csum for Ipv6) */
if (skb->protocol == htons(ETH_P_IP) && amsdu) {
ip_hdr(skb)->check = 0;
offload_assist |= BIT(TX_CMD_OFFLD_L3_EN);
}
/* reset UDP/TCP header csum */
if (protocol == IPPROTO_TCP)
tcp_hdr(skb)->check = 0;
else
udp_hdr(skb)->check = 0;
out:
#endif
mh_len /= 2;
offload_assist |= mh_len << TX_CMD_OFFLD_MH_SIZE;
if (amsdu)
offload_assist |= BIT(TX_CMD_OFFLD_AMSDU);
else if (ieee80211_hdrlen(hdr->frame_control) % 4)
/* padding is inserted later in transport */
offload_assist |= BIT(TX_CMD_OFFLD_PAD);
return cpu_to_le32(offload_assist);
}
static void iwl_mld_get_basic_rates_and_band(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_tx_info *info,
unsigned long *basic_rates,
u8 *band)
{
u32 link_id = u32_get_bits(info->control.flags,
IEEE80211_TX_CTRL_MLO_LINK);
*basic_rates = vif->bss_conf.basic_rates;
*band = info->band;
if (link_id == IEEE80211_LINK_UNSPECIFIED &&
ieee80211_vif_is_mld(vif)) {
/* shouldn't do this when >1 link is active */
WARN_ON(hweight16(vif->active_links) != 1);
link_id = __ffs(vif->active_links);
}
if (link_id < IEEE80211_LINK_UNSPECIFIED) {
struct ieee80211_bss_conf *link_conf;
rcu_read_lock();
link_conf = rcu_dereference(vif->link_conf[link_id]);
if (link_conf) {
*basic_rates = link_conf->basic_rates;
if (link_conf->chanreq.oper.chan)
*band = link_conf->chanreq.oper.chan->band;
}
rcu_read_unlock();
}
}
u8 iwl_mld_get_lowest_rate(struct iwl_mld *mld,
struct ieee80211_tx_info *info,
struct ieee80211_vif *vif)
{
struct ieee80211_supported_band *sband;
u16 lowest_cck = IWL_RATE_COUNT, lowest_ofdm = IWL_RATE_COUNT;
unsigned long basic_rates;
u8 band, rate;
u32 i;
iwl_mld_get_basic_rates_and_band(mld, vif, info, &basic_rates, &band);
sband = mld->hw->wiphy->bands[band];
for_each_set_bit(i, &basic_rates, BITS_PER_LONG) {
u16 hw = sband->bitrates[i].hw_value;
if (hw >= IWL_FIRST_OFDM_RATE) {
if (lowest_ofdm > hw)
lowest_ofdm = hw;
} else if (lowest_cck > hw) {
lowest_cck = hw;
}
}
if (band == NL80211_BAND_2GHZ && !vif->p2p &&
vif->type != NL80211_IFTYPE_P2P_DEVICE &&
!(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)) {
if (lowest_cck != IWL_RATE_COUNT)
rate = lowest_cck;
else if (lowest_ofdm != IWL_RATE_COUNT)
rate = lowest_ofdm;
else
rate = IWL_FIRST_CCK_RATE;
} else if (lowest_ofdm != IWL_RATE_COUNT) {
rate = lowest_ofdm;
} else {
rate = IWL_FIRST_OFDM_RATE;
}
return rate;
}
static u32 iwl_mld_mac80211_rate_idx_to_fw(struct iwl_mld *mld,
struct ieee80211_tx_info *info,
int rate_idx)
{
u32 rate_flags = 0;
u8 rate_plcp;
/* if the rate isn't a well known legacy rate, take the lowest one */
if (rate_idx < 0 || rate_idx >= IWL_RATE_COUNT_LEGACY)
rate_idx = iwl_mld_get_lowest_rate(mld, info,
info->control.vif);
WARN_ON_ONCE(rate_idx < 0);
/* Set CCK or OFDM flag */
if (rate_idx <= IWL_LAST_CCK_RATE)
rate_flags |= RATE_MCS_MOD_TYPE_CCK;
else
rate_flags |= RATE_MCS_MOD_TYPE_LEGACY_OFDM;
/* Legacy rates are indexed:
* 0 - 3 for CCK and 0 - 7 for OFDM
*/
rate_plcp = (rate_idx >= IWL_FIRST_OFDM_RATE ?
rate_idx - IWL_FIRST_OFDM_RATE : rate_idx);
return (u32)rate_plcp | rate_flags;
}
static u32 iwl_mld_get_tx_ant(struct iwl_mld *mld,
struct ieee80211_tx_info *info,
struct ieee80211_sta *sta, __le16 fc)
{
if (sta && ieee80211_is_data(fc)) {
struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta);
return BIT(mld_sta->data_tx_ant) << RATE_MCS_ANT_POS;
}
return BIT(mld->mgmt_tx_ant) << RATE_MCS_ANT_POS;
}
static u32 iwl_mld_get_inject_tx_rate(struct iwl_mld *mld,
struct ieee80211_tx_info *info,
struct ieee80211_sta *sta,
__le16 fc)
{
struct ieee80211_tx_rate *rate = &info->control.rates[0];
u32 result;
if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
u8 mcs = ieee80211_rate_get_vht_mcs(rate);
u8 nss = ieee80211_rate_get_vht_nss(rate);
result = RATE_MCS_MOD_TYPE_VHT;
result |= u32_encode_bits(mcs, RATE_MCS_CODE_MSK);
result |= u32_encode_bits(nss, RATE_MCS_NSS_MSK);
if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
result |= RATE_MCS_SGI_MSK;
if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
result |= RATE_MCS_CHAN_WIDTH_40;
else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
result |= RATE_MCS_CHAN_WIDTH_80;
else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
result |= RATE_MCS_CHAN_WIDTH_160;
} else if (rate->flags & IEEE80211_TX_RC_MCS) {
/* only MCS 0-15 are supported */
u8 mcs = rate->idx & 7;
u8 nss = rate->idx > 7;
result = RATE_MCS_MOD_TYPE_HT;
result |= u32_encode_bits(mcs, RATE_MCS_CODE_MSK);
result |= u32_encode_bits(nss, RATE_MCS_NSS_MSK);
if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
result |= RATE_MCS_SGI_MSK;
if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
result |= RATE_MCS_CHAN_WIDTH_40;
if (info->flags & IEEE80211_TX_CTL_LDPC)
result |= RATE_MCS_LDPC_MSK;
if (u32_get_bits(info->flags, IEEE80211_TX_CTL_STBC))
result |= RATE_MCS_STBC_MSK;
} else {
result = iwl_mld_mac80211_rate_idx_to_fw(mld, info, rate->idx);
}
if (info->control.antennas)
result |= u32_encode_bits(info->control.antennas,
RATE_MCS_ANT_AB_MSK);
else
result |= iwl_mld_get_tx_ant(mld, info, sta, fc);
return result;
}
static __le32 iwl_mld_get_tx_rate_n_flags(struct iwl_mld *mld,
struct ieee80211_tx_info *info,
struct ieee80211_sta *sta, __le16 fc)
{
u32 rate;
if (unlikely(info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT))
rate = iwl_mld_get_inject_tx_rate(mld, info, sta, fc);
else
rate = iwl_mld_mac80211_rate_idx_to_fw(mld, info, -1) |
iwl_mld_get_tx_ant(mld, info, sta, fc);
return iwl_v3_rate_to_v2_v3(rate, mld->fw_rates_ver_3);
}
static void
iwl_mld_fill_tx_cmd_hdr(struct iwl_tx_cmd *tx_cmd,
struct sk_buff *skb, bool amsdu)
{
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct ieee80211_hdr *hdr = (void *)skb->data;
struct ieee80211_vif *vif;
/* Copy MAC header from skb into command buffer */
memcpy(tx_cmd->hdr, hdr, ieee80211_hdrlen(hdr->frame_control));
if (!amsdu || !skb_is_gso(skb))
return;
/* As described in IEEE sta 802.11-2020, table 9-30 (Address
* field contents), A-MSDU address 3 should contain the BSSID
* address.
*
* In TSO, the skb header address 3 contains the original address 3 to
* correctly create all the A-MSDU subframes headers from it.
* Override now the address 3 in the command header with the BSSID.
*
* Note: we fill in the MLD address, but the firmware will do the
* necessary translation to link address after encryption.
*/
vif = info->control.vif;
switch (vif->type) {
case NL80211_IFTYPE_STATION:
ether_addr_copy(tx_cmd->hdr->addr3, vif->cfg.ap_addr);
break;
case NL80211_IFTYPE_AP:
ether_addr_copy(tx_cmd->hdr->addr3, vif->addr);
break;
default:
break;
}
}
static void
iwl_mld_fill_tx_cmd(struct iwl_mld *mld, struct sk_buff *skb,
struct iwl_device_tx_cmd *dev_tx_cmd,
struct ieee80211_sta *sta)
{
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct ieee80211_hdr *hdr = (void *)skb->data;
struct iwl_mld_sta *mld_sta = sta ? iwl_mld_sta_from_mac80211(sta) :
NULL;
struct iwl_tx_cmd *tx_cmd;
bool amsdu = ieee80211_is_data_qos(hdr->frame_control) &&
(*ieee80211_get_qos_ctl(hdr) &
IEEE80211_QOS_CTL_A_MSDU_PRESENT);
__le32 rate_n_flags = 0;
u16 flags = 0;
dev_tx_cmd->hdr.cmd = TX_CMD;
if (!info->control.hw_key)
flags |= IWL_TX_FLAGS_ENCRYPT_DIS;
/* For data and mgmt packets rate info comes from the fw.
* Only set rate/antenna for injected frames with fixed rate, or
* when no sta is given.
*/
if (unlikely(!sta ||
info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT)) {
flags |= IWL_TX_FLAGS_CMD_RATE;
rate_n_flags = iwl_mld_get_tx_rate_n_flags(mld, info, sta,
hdr->frame_control);
} else if (!ieee80211_is_data(hdr->frame_control) ||
(mld_sta &&
mld_sta->sta_state < IEEE80211_STA_AUTHORIZED)) {
/* These are important frames */
flags |= IWL_TX_FLAGS_HIGH_PRI;
}
tx_cmd = (void *)dev_tx_cmd->payload;
iwl_mld_fill_tx_cmd_hdr(tx_cmd, skb, amsdu);
tx_cmd->offload_assist = iwl_mld_get_offload_assist(skb, amsdu);
/* Total # bytes to be transmitted */
tx_cmd->len = cpu_to_le16((u16)skb->len);
tx_cmd->flags = cpu_to_le16(flags);
tx_cmd->rate_n_flags = rate_n_flags;
}
/* Caller of this need to check that info->control.vif is not NULL */
static struct iwl_mld_link *
iwl_mld_get_link_from_tx_info(struct ieee80211_tx_info *info)
{
struct iwl_mld_vif *mld_vif =
iwl_mld_vif_from_mac80211(info->control.vif);
u32 link_id = u32_get_bits(info->control.flags,
IEEE80211_TX_CTRL_MLO_LINK);
if (link_id == IEEE80211_LINK_UNSPECIFIED) {
if (info->control.vif->active_links)
link_id = ffs(info->control.vif->active_links) - 1;
else
link_id = 0;
}
return rcu_dereference(mld_vif->link[link_id]);
}
static int
iwl_mld_get_tx_queue_id(struct iwl_mld *mld, struct ieee80211_txq *txq,
struct sk_buff *skb)
{
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct ieee80211_hdr *hdr = (void *)skb->data;
__le16 fc = hdr->frame_control;
struct iwl_mld_vif *mld_vif;
struct iwl_mld_link *link;
if (txq && txq->sta)
return iwl_mld_txq_from_mac80211(txq)->fw_id;
if (!info->control.vif)
return IWL_MLD_INVALID_QUEUE;
switch (info->control.vif->type) {
case NL80211_IFTYPE_AP:
case NL80211_IFTYPE_ADHOC:
link = iwl_mld_get_link_from_tx_info(info);
if (WARN_ON(!link))
break;
/* ucast disassociate/deauth frames without a station might
* happen, especially with reason 7 ("Class 3 frame received
* from nonassociated STA").
*/
if (ieee80211_is_mgmt(fc) &&
(!ieee80211_is_bufferable_mmpdu(skb) ||
ieee80211_is_deauth(fc) || ieee80211_is_disassoc(fc)))
return link->bcast_sta.queue_id;
if (is_multicast_ether_addr(hdr->addr1) &&
!ieee80211_has_order(fc))
return link->mcast_sta.queue_id;
WARN_ONCE(info->control.vif->type != NL80211_IFTYPE_ADHOC,
"Couldn't find a TXQ. fc=0x%02x", le16_to_cpu(fc));
return link->bcast_sta.queue_id;
case NL80211_IFTYPE_P2P_DEVICE:
mld_vif = iwl_mld_vif_from_mac80211(info->control.vif);
if (mld_vif->roc_activity != ROC_ACTIVITY_P2P_DISC &&
mld_vif->roc_activity != ROC_ACTIVITY_P2P_NEG) {
IWL_DEBUG_DROP(mld,
"Drop tx outside ROC with activity %d\n",
mld_vif->roc_activity);
return IWL_MLD_INVALID_DROP_TX;
}
WARN_ON(!ieee80211_is_mgmt(fc));
return mld_vif->aux_sta.queue_id;
case NL80211_IFTYPE_MONITOR:
mld_vif = iwl_mld_vif_from_mac80211(info->control.vif);
return mld_vif->deflink.mon_sta.queue_id;
case NL80211_IFTYPE_STATION:
mld_vif = iwl_mld_vif_from_mac80211(info->control.vif);
if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)) {
IWL_DEBUG_DROP(mld, "Drop tx not off-channel\n");
return IWL_MLD_INVALID_DROP_TX;
}
if (mld_vif->roc_activity != ROC_ACTIVITY_HOTSPOT) {
IWL_DEBUG_DROP(mld, "Drop tx outside ROC\n");
return IWL_MLD_INVALID_DROP_TX;
}
WARN_ON(!ieee80211_is_mgmt(fc));
return mld_vif->aux_sta.queue_id;
default:
WARN_ONCE(1, "Unsupported vif type\n");
break;
}
return IWL_MLD_INVALID_QUEUE;
}
static void iwl_mld_probe_resp_set_noa(struct iwl_mld *mld,
struct sk_buff *skb)
{
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct iwl_mld_link *mld_link =
&iwl_mld_vif_from_mac80211(info->control.vif)->deflink;
struct iwl_probe_resp_data *resp_data;
u8 *pos;
if (!info->control.vif->p2p)
return;
rcu_read_lock();
resp_data = rcu_dereference(mld_link->probe_resp_data);
if (!resp_data)
goto out;
if (!resp_data->notif.noa_active)
goto out;
if (skb_tailroom(skb) < resp_data->noa_len) {
if (pskb_expand_head(skb, 0, resp_data->noa_len, GFP_ATOMIC)) {
IWL_ERR(mld,
"Failed to reallocate probe resp\n");
goto out;
}
}
pos = skb_put(skb, resp_data->noa_len);
*pos++ = WLAN_EID_VENDOR_SPECIFIC;
/* Set length of IE body (not including ID and length itself) */
*pos++ = resp_data->noa_len - 2;
*pos++ = (WLAN_OUI_WFA >> 16) & 0xff;
*pos++ = (WLAN_OUI_WFA >> 8) & 0xff;
*pos++ = WLAN_OUI_WFA & 0xff;
*pos++ = WLAN_OUI_TYPE_WFA_P2P;
memcpy(pos, &resp_data->notif.noa_attr,
resp_data->noa_len - sizeof(struct ieee80211_vendor_ie));
out:
rcu_read_unlock();
}
/* This function must be called with BHs disabled */
static int iwl_mld_tx_mpdu(struct iwl_mld *mld, struct sk_buff *skb,
struct ieee80211_txq *txq)
{
struct ieee80211_hdr *hdr = (void *)skb->data;
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct ieee80211_sta *sta = txq ? txq->sta : NULL;
struct iwl_device_tx_cmd *dev_tx_cmd;
int queue = iwl_mld_get_tx_queue_id(mld, txq, skb);
u8 tid = IWL_MAX_TID_COUNT;
if (WARN_ONCE(queue == IWL_MLD_INVALID_QUEUE, "Invalid TX Queue id") ||
queue == IWL_MLD_INVALID_DROP_TX)
return -1;
if (unlikely(ieee80211_is_any_nullfunc(hdr->frame_control)))
return -1;
dev_tx_cmd = iwl_trans_alloc_tx_cmd(mld->trans);
if (unlikely(!dev_tx_cmd))
return -1;
if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
if (IWL_MLD_NON_TRANSMITTING_AP)
return -1;
iwl_mld_probe_resp_set_noa(mld, skb);
}
iwl_mld_fill_tx_cmd(mld, skb, dev_tx_cmd, sta);
if (ieee80211_is_data(hdr->frame_control)) {
if (ieee80211_is_data_qos(hdr->frame_control))
tid = ieee80211_get_tid(hdr);
else
tid = IWL_TID_NON_QOS;
}
IWL_DEBUG_TX(mld, "TX TID:%d from Q:%d len %d\n",
tid, queue, skb->len);
/* From now on, we cannot access info->control */
memset(&info->status, 0, sizeof(info->status));
memset(info->driver_data, 0, sizeof(info->driver_data));
info->driver_data[1] = dev_tx_cmd;
if (iwl_trans_tx(mld->trans, skb, dev_tx_cmd, queue))
goto err;
/* Update low-latency counter when a packet is queued instead
* of after TX, it makes sense for early low-latency detection
*/
if (sta)
iwl_mld_low_latency_update_counters(mld, hdr, sta, 0);
return 0;
err:
iwl_trans_free_tx_cmd(mld->trans, dev_tx_cmd);
IWL_DEBUG_TX(mld, "TX from Q:%d dropped\n", queue);
return -1;
}
#ifdef CONFIG_INET
/* This function handles the segmentation of a large TSO packet into multiple
* MPDUs, ensuring that the resulting segments conform to AMSDU limits and
* constraints.
*/
static int iwl_mld_tx_tso_segment(struct iwl_mld *mld, struct sk_buff *skb,
struct ieee80211_sta *sta,
struct sk_buff_head *mpdus_skbs)
{
struct ieee80211_hdr *hdr = (void *)skb->data;
netdev_features_t netdev_flags = NETIF_F_CSUM_MASK | NETIF_F_SG;
unsigned int mss = skb_shinfo(skb)->gso_size;
unsigned int num_subframes, tcp_payload_len, subf_len;
u16 snap_ip_tcp, pad, max_tid_amsdu_len;
u8 tid;
snap_ip_tcp = 8 + skb_network_header_len(skb) + tcp_hdrlen(skb);
if (!ieee80211_is_data_qos(hdr->frame_control) ||
!sta->cur->max_rc_amsdu_len)
return iwl_tx_tso_segment(skb, 1, netdev_flags, mpdus_skbs);
/* Do not build AMSDU for IPv6 with extension headers.
* Ask stack to segment and checksum the generated MPDUs for us.
*/
if (skb->protocol == htons(ETH_P_IPV6) &&
((struct ipv6hdr *)skb_network_header(skb))->nexthdr !=
IPPROTO_TCP) {
netdev_flags &= ~NETIF_F_CSUM_MASK;
return iwl_tx_tso_segment(skb, 1, netdev_flags, mpdus_skbs);
}
tid = ieee80211_get_tid(hdr);
if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
return -EINVAL;
max_tid_amsdu_len = sta->cur->max_tid_amsdu_len[tid];
if (!max_tid_amsdu_len)
return iwl_tx_tso_segment(skb, 1, netdev_flags, mpdus_skbs);
/* Sub frame header + SNAP + IP header + TCP header + MSS */
subf_len = sizeof(struct ethhdr) + snap_ip_tcp + mss;
pad = (4 - subf_len) & 0x3;
/* If we have N subframes in the A-MSDU, then the A-MSDU's size is
* N * subf_len + (N - 1) * pad.
*/
num_subframes = (max_tid_amsdu_len + pad) / (subf_len + pad);
if (sta->max_amsdu_subframes &&
num_subframes > sta->max_amsdu_subframes)
num_subframes = sta->max_amsdu_subframes;
tcp_payload_len = skb_tail_pointer(skb) - skb_transport_header(skb) -
tcp_hdrlen(skb) + skb->data_len;
/* Make sure we have enough TBs for the A-MSDU:
* 2 for each subframe
* 1 more for each fragment
* 1 more for the potential data in the header
*/
if ((num_subframes * 2 + skb_shinfo(skb)->nr_frags + 1) >
mld->trans->info.max_skb_frags)
num_subframes = 1;
if (num_subframes > 1)
*ieee80211_get_qos_ctl(hdr) |= IEEE80211_QOS_CTL_A_MSDU_PRESENT;
/* This skb fits in one single A-MSDU */
if (tcp_payload_len <= num_subframes * mss) {
__skb_queue_tail(mpdus_skbs, skb);
return 0;
}
/* Trick the segmentation function to make it create SKBs that can fit
* into one A-MSDU.
*/
return iwl_tx_tso_segment(skb, num_subframes, netdev_flags, mpdus_skbs);
}
/* Manages TSO (TCP Segmentation Offload) packet transmission by segmenting
* large packets when necessary and transmitting each segment as MPDU.
*/
static int iwl_mld_tx_tso(struct iwl_mld *mld, struct sk_buff *skb,
struct ieee80211_txq *txq)
{
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct sk_buff *orig_skb = skb;
struct sk_buff_head mpdus_skbs;
unsigned int payload_len;
int ret;
if (WARN_ON(!txq || !txq->sta))
return -1;
payload_len = skb_tail_pointer(skb) - skb_transport_header(skb) -
tcp_hdrlen(skb) + skb->data_len;
if (payload_len <= skb_shinfo(skb)->gso_size)
return iwl_mld_tx_mpdu(mld, skb, txq);
if (!info->control.vif)
return -1;
__skb_queue_head_init(&mpdus_skbs);
ret = iwl_mld_tx_tso_segment(mld, skb, txq->sta, &mpdus_skbs);
if (ret)
return ret;
WARN_ON(skb_queue_empty(&mpdus_skbs));
while (!skb_queue_empty(&mpdus_skbs)) {
skb = __skb_dequeue(&mpdus_skbs);
ret = iwl_mld_tx_mpdu(mld, skb, txq);
if (!ret)
continue;
/* Free skbs created as part of TSO logic that have not yet
* been dequeued
*/
__skb_queue_purge(&mpdus_skbs);
/* skb here is not necessarily same as skb that entered
* this method, so free it explicitly.
*/
if (skb == orig_skb)
ieee80211_free_txskb(mld->hw, skb);
else
kfree_skb(skb);
/* there was error, but we consumed skb one way or
* another, so return 0
*/
return 0;
}
return 0;
}
#else
static int iwl_mld_tx_tso(struct iwl_mld *mld, struct sk_buff *skb,
struct ieee80211_txq *txq)
{
/* Impossible to get TSO without CONFIG_INET */
WARN_ON(1);
return -1;
}
#endif /* CONFIG_INET */
void iwl_mld_tx_skb(struct iwl_mld *mld, struct sk_buff *skb,
struct ieee80211_txq *txq)
{
if (skb_is_gso(skb)) {
if (!iwl_mld_tx_tso(mld, skb, txq))
return;
goto err;
}
if (likely(!iwl_mld_tx_mpdu(mld, skb, txq)))
return;
err:
ieee80211_free_txskb(mld->hw, skb);
}
void iwl_mld_tx_from_txq(struct iwl_mld *mld, struct ieee80211_txq *txq)
{
struct iwl_mld_txq *mld_txq = iwl_mld_txq_from_mac80211(txq);
struct sk_buff *skb = NULL;
u8 zero_addr[ETH_ALEN] = {};
/*
* No need for threads to be pending here, they can leave the first
* taker all the work.
*
* mld_txq->tx_request logic:
*
* If 0, no one is currently TXing, set to 1 to indicate current thread
* will now start TX and other threads should quit.
*
* If 1, another thread is currently TXing, set to 2 to indicate to
* that thread that there was another request. Since that request may
* have raced with the check whether the queue is empty, the TXing
* thread should check the queue's status one more time before leaving.
* This check is done in order to not leave any TX hanging in the queue
* until the next TX invocation (which may not even happen).
*
* If 2, another thread is currently TXing, and it will already double
* check the queue, so do nothing.
*/
if (atomic_fetch_add_unless(&mld_txq->tx_request, 1, 2))
return;
rcu_read_lock();
do {
while (likely(!mld_txq->status.stop_full) &&
(skb = ieee80211_tx_dequeue(mld->hw, txq)))
iwl_mld_tx_skb(mld, skb, txq);
} while (atomic_dec_return(&mld_txq->tx_request));
IWL_DEBUG_TX(mld, "TXQ of sta %pM tid %d is now empty\n",
txq->sta ? txq->sta->addr : zero_addr, txq->tid);
rcu_read_unlock();
}
static void iwl_mld_hwrate_to_tx_rate(struct iwl_mld *mld,
__le32 rate_n_flags_fw,
struct ieee80211_tx_info *info)
{
enum nl80211_band band = info->band;
struct ieee80211_tx_rate *tx_rate = &info->status.rates[0];
u32 rate_n_flags = iwl_v3_rate_from_v2_v3(rate_n_flags_fw,
mld->fw_rates_ver_3);
u32 sgi = rate_n_flags & RATE_MCS_SGI_MSK;
u32 chan_width = rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK;
u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
if (sgi)
tx_rate->flags |= IEEE80211_TX_RC_SHORT_GI;
switch (chan_width) {
case RATE_MCS_CHAN_WIDTH_20:
break;
case RATE_MCS_CHAN_WIDTH_40:
tx_rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
break;
case RATE_MCS_CHAN_WIDTH_80:
tx_rate->flags |= IEEE80211_TX_RC_80_MHZ_WIDTH;
break;
case RATE_MCS_CHAN_WIDTH_160:
tx_rate->flags |= IEEE80211_TX_RC_160_MHZ_WIDTH;
break;
default:
break;
}
switch (format) {
case RATE_MCS_MOD_TYPE_HT:
tx_rate->flags |= IEEE80211_TX_RC_MCS;
tx_rate->idx = RATE_HT_MCS_INDEX(rate_n_flags);
break;
case RATE_MCS_MOD_TYPE_VHT:
ieee80211_rate_set_vht(tx_rate,
rate_n_flags & RATE_MCS_CODE_MSK,
u32_get_bits(rate_n_flags,
RATE_MCS_NSS_MSK) + 1);
tx_rate->flags |= IEEE80211_TX_RC_VHT_MCS;
break;
case RATE_MCS_MOD_TYPE_HE:
case RATE_MCS_MOD_TYPE_EHT:
/* mac80211 cannot do this without ieee80211_tx_status_ext()
* but it only matters for radiotap
*/
tx_rate->idx = 0;
break;
default:
tx_rate->idx =
iwl_mld_legacy_hw_idx_to_mac80211_idx(rate_n_flags,
band);
break;
}
}
void iwl_mld_handle_tx_resp_notif(struct iwl_mld *mld,
struct iwl_rx_packet *pkt)
{
struct iwl_tx_resp *tx_resp = (void *)pkt->data;
int txq_id = le16_to_cpu(tx_resp->tx_queue);
struct agg_tx_status *agg_status = &tx_resp->status;
u32 status = le16_to_cpu(agg_status->status);
u32 pkt_len = iwl_rx_packet_payload_len(pkt);
size_t notif_size = sizeof(*tx_resp) + sizeof(u32);
int sta_id = IWL_TX_RES_GET_RA(tx_resp->ra_tid);
int tid = IWL_TX_RES_GET_TID(tx_resp->ra_tid);
struct ieee80211_link_sta *link_sta;
struct iwl_mld_sta *mld_sta;
u16 ssn;
struct sk_buff_head skbs;
u8 skb_freed = 0;
bool mgmt = false;
bool tx_failure = (status & TX_STATUS_MSK) != TX_STATUS_SUCCESS;
if (IWL_FW_CHECK(mld, tx_resp->frame_count != 1,
"Invalid tx_resp notif frame_count (%d)\n",
tx_resp->frame_count))
return;
/* validate the size of the variable part of the notif */
if (IWL_FW_CHECK(mld, notif_size != pkt_len,
"Invalid tx_resp notif size (expected=%zu got=%u)\n",
notif_size, pkt_len))
return;
ssn = le32_to_cpup((__le32 *)agg_status +
tx_resp->frame_count) & 0xFFFF;
__skb_queue_head_init(&skbs);
/* we can free until ssn % q.n_bd not inclusive */
iwl_trans_reclaim(mld->trans, txq_id, ssn, &skbs, false);
while (!skb_queue_empty(&skbs)) {
struct sk_buff *skb = __skb_dequeue(&skbs);
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct ieee80211_hdr *hdr = (void *)skb->data;
skb_freed++;
iwl_trans_free_tx_cmd(mld->trans, info->driver_data[1]);
memset(&info->status, 0, sizeof(info->status));
info->flags &= ~(IEEE80211_TX_STAT_ACK | IEEE80211_TX_STAT_TX_FILTERED);
/* inform mac80211 about what happened with the frame */
switch (status & TX_STATUS_MSK) {
case TX_STATUS_SUCCESS:
case TX_STATUS_DIRECT_DONE:
info->flags |= IEEE80211_TX_STAT_ACK;
break;
default:
break;
}
/* If we are freeing multiple frames, mark all the frames
* but the first one as acked, since they were acknowledged
* before
*/
if (skb_freed > 1)
info->flags |= IEEE80211_TX_STAT_ACK;
if (tx_failure) {
enum iwl_fw_ini_time_point tp =
IWL_FW_INI_TIME_POINT_TX_FAILED;
if (ieee80211_is_action(hdr->frame_control))
tp = IWL_FW_INI_TIME_POINT_TX_WFD_ACTION_FRAME_FAILED;
else if (ieee80211_is_mgmt(hdr->frame_control))
mgmt = true;
iwl_dbg_tlv_time_point(&mld->fwrt, tp, NULL);
}
iwl_mld_hwrate_to_tx_rate(mld, tx_resp->initial_rate, info);
if (likely(!iwl_mld_time_sync_frame(mld, skb, hdr->addr1)))
ieee80211_tx_status_skb(mld->hw, skb);
}
IWL_DEBUG_TX_REPLY(mld,
"TXQ %d status 0x%08x ssn=%d initial_rate 0x%x retries %d\n",
txq_id, status, ssn, le32_to_cpu(tx_resp->initial_rate),
tx_resp->failure_frame);
if (tx_failure && mgmt)
iwl_mld_toggle_tx_ant(mld, &mld->mgmt_tx_ant);
if (IWL_FW_CHECK(mld, sta_id >= mld->fw->ucode_capa.num_stations,
"Got invalid sta_id (%d)\n", sta_id))
return;
rcu_read_lock();
link_sta = rcu_dereference(mld->fw_id_to_link_sta[sta_id]);
if (!link_sta) {
/* This can happen if the TX cmd was sent before pre_rcu_remove
* but the TX response was received after
*/
IWL_DEBUG_TX_REPLY(mld,
"Got valid sta_id (%d) but sta is NULL\n",
sta_id);
goto out;
}
if (IS_ERR(link_sta))
goto out;
mld_sta = iwl_mld_sta_from_mac80211(link_sta->sta);
if (tx_failure && mld_sta->sta_state < IEEE80211_STA_AUTHORIZED)
iwl_mld_toggle_tx_ant(mld, &mld_sta->data_tx_ant);
if (tid < IWL_MAX_TID_COUNT)
iwl_mld_count_mpdu_tx(link_sta, 1);
out:
rcu_read_unlock();
}
static void iwl_mld_tx_reclaim_txq(struct iwl_mld *mld, int txq, int index,
bool in_flush)
{
struct sk_buff_head reclaimed_skbs;
__skb_queue_head_init(&reclaimed_skbs);
iwl_trans_reclaim(mld->trans, txq, index, &reclaimed_skbs, in_flush);
while (!skb_queue_empty(&reclaimed_skbs)) {
struct sk_buff *skb = __skb_dequeue(&reclaimed_skbs);
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
iwl_trans_free_tx_cmd(mld->trans, info->driver_data[1]);
memset(&info->status, 0, sizeof(info->status));
/* Packet was transmitted successfully, failures come as single
* frames because before failing a frame the firmware transmits
* it without aggregation at least once.
*/
if (!in_flush)
info->flags |= IEEE80211_TX_STAT_ACK;
else
info->flags &= ~IEEE80211_TX_STAT_ACK;
ieee80211_tx_status_skb(mld->hw, skb);
}
}
int iwl_mld_flush_link_sta_txqs(struct iwl_mld *mld, u32 fw_sta_id)
{
struct iwl_tx_path_flush_cmd_rsp *rsp;
struct iwl_tx_path_flush_cmd flush_cmd = {
.sta_id = cpu_to_le32(fw_sta_id),
.tid_mask = cpu_to_le16(0xffff),
};
struct iwl_host_cmd cmd = {
.id = TXPATH_FLUSH,
.len = { sizeof(flush_cmd), },
.data = { &flush_cmd, },
.flags = CMD_WANT_SKB,
};
int ret, num_flushed_queues;
u32 resp_len;
IWL_DEBUG_TX_QUEUES(mld, "flush for sta id %d tid mask 0x%x\n",
fw_sta_id, 0xffff);
ret = iwl_mld_send_cmd(mld, &cmd);
if (ret) {
IWL_ERR(mld, "Failed to send flush command (%d)\n", ret);
return ret;
}
resp_len = iwl_rx_packet_payload_len(cmd.resp_pkt);
if (IWL_FW_CHECK(mld, resp_len != sizeof(*rsp),
"Invalid TXPATH_FLUSH response len: %d\n",
resp_len)) {
ret = -EIO;
goto free_rsp;
}
rsp = (void *)cmd.resp_pkt->data;
if (IWL_FW_CHECK(mld, le16_to_cpu(rsp->sta_id) != fw_sta_id,
"sta_id %d != rsp_sta_id %d\n", fw_sta_id,
le16_to_cpu(rsp->sta_id))) {
ret = -EIO;
goto free_rsp;
}
num_flushed_queues = le16_to_cpu(rsp->num_flushed_queues);
if (IWL_FW_CHECK(mld, num_flushed_queues > IWL_TX_FLUSH_QUEUE_RSP,
"num_flushed_queues %d\n", num_flushed_queues)) {
ret = -EIO;
goto free_rsp;
}
for (int i = 0; i < num_flushed_queues; i++) {
struct iwl_flush_queue_info *queue_info = &rsp->queues[i];
int read_after = le16_to_cpu(queue_info->read_after_flush);
int txq_id = le16_to_cpu(queue_info->queue_num);
if (IWL_FW_CHECK(mld,
txq_id >= ARRAY_SIZE(mld->fw_id_to_txq),
"Invalid txq id %d\n", txq_id))
continue;
IWL_DEBUG_TX_QUEUES(mld,
"tid %d txq_id %d read-before %d read-after %d\n",
le16_to_cpu(queue_info->tid), txq_id,
le16_to_cpu(queue_info->read_before_flush),
read_after);
iwl_mld_tx_reclaim_txq(mld, txq_id, read_after, true);
}
free_rsp:
iwl_free_resp(&cmd);
return ret;
}
int iwl_mld_ensure_queue(struct iwl_mld *mld, struct ieee80211_txq *txq)
{
struct iwl_mld_txq *mld_txq = iwl_mld_txq_from_mac80211(txq);
int ret;
lockdep_assert_wiphy(mld->wiphy);
if (likely(mld_txq->status.allocated))
return 0;
ret = iwl_mld_add_txq(mld, txq);
spin_lock_bh(&mld->add_txqs_lock);
if (!list_empty(&mld_txq->list))
list_del_init(&mld_txq->list);
spin_unlock_bh(&mld->add_txqs_lock);
return ret;
}
int iwl_mld_update_sta_txqs(struct iwl_mld *mld,
struct ieee80211_sta *sta,
u32 old_sta_mask, u32 new_sta_mask)
{
struct iwl_scd_queue_cfg_cmd cmd = {
.operation = cpu_to_le32(IWL_SCD_QUEUE_MODIFY),
.u.modify.old_sta_mask = cpu_to_le32(old_sta_mask),
.u.modify.new_sta_mask = cpu_to_le32(new_sta_mask),
};
lockdep_assert_wiphy(mld->wiphy);
for (int tid = 0; tid <= IWL_MAX_TID_COUNT; tid++) {
struct ieee80211_txq *txq =
sta->txq[tid != IWL_MAX_TID_COUNT ?
tid : IEEE80211_NUM_TIDS];
struct iwl_mld_txq *mld_txq =
iwl_mld_txq_from_mac80211(txq);
int ret;
if (!mld_txq->status.allocated)
continue;
if (tid == IWL_MAX_TID_COUNT)
cmd.u.modify.tid = cpu_to_le32(IWL_MGMT_TID);
else
cmd.u.modify.tid = cpu_to_le32(tid);
ret = iwl_mld_send_cmd_pdu(mld,
WIDE_ID(DATA_PATH_GROUP,
SCD_QUEUE_CONFIG_CMD),
&cmd);
if (ret)
return ret;
}
return 0;
}
void iwl_mld_handle_compressed_ba_notif(struct iwl_mld *mld,
struct iwl_rx_packet *pkt)
{
struct iwl_compressed_ba_notif *ba_res = (void *)pkt->data;
u32 pkt_len = iwl_rx_packet_payload_len(pkt);
u16 tfd_cnt = le16_to_cpu(ba_res->tfd_cnt);
u8 sta_id = ba_res->sta_id;
struct ieee80211_link_sta *link_sta;
if (!tfd_cnt)
return;
if (IWL_FW_CHECK(mld, struct_size(ba_res, tfd, tfd_cnt) > pkt_len,
"Short BA notif (tfd_cnt=%d, size:0x%x)\n",
tfd_cnt, pkt_len))
return;
IWL_DEBUG_TX_REPLY(mld,
"BA notif received from sta_id=%d, flags=0x%x, sent:%d, acked:%d\n",
sta_id, le32_to_cpu(ba_res->flags),
le16_to_cpu(ba_res->txed),
le16_to_cpu(ba_res->done));
for (int i = 0; i < tfd_cnt; i++) {
struct iwl_compressed_ba_tfd *ba_tfd = &ba_res->tfd[i];
int txq_id = le16_to_cpu(ba_tfd->q_num);
int index = le16_to_cpu(ba_tfd->tfd_index);
if (IWL_FW_CHECK(mld,
txq_id >= ARRAY_SIZE(mld->fw_id_to_txq),
"Invalid txq id %d\n", txq_id))
continue;
iwl_mld_tx_reclaim_txq(mld, txq_id, index, false);
}
if (IWL_FW_CHECK(mld, sta_id >= mld->fw->ucode_capa.num_stations,
"Got invalid sta_id (%d)\n", sta_id))
return;
rcu_read_lock();
link_sta = rcu_dereference(mld->fw_id_to_link_sta[sta_id]);
if (IWL_FW_CHECK(mld, IS_ERR_OR_NULL(link_sta),
"Got valid sta_id (%d) but link_sta is NULL\n",
sta_id))
goto out;
iwl_mld_count_mpdu_tx(link_sta, le16_to_cpu(ba_res->txed));
out:
rcu_read_unlock();
}
|