/* 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 */ if (WARN_ONCE(!(mvm->hw->netdev_features & IWL_TX_CSUM_NETIF_FLAGS) ||
(skb->protocol != htons(ETH_P_IP) &&
skb->protocol != htons(ETH_P_IPV6)), "No support for requested checksum\n")) {
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
}
/* * 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);
}
out: #endif /* * mac header len should include IV, size is in words unless * the IV is added by the firmware like in WEP. * In new Tx API, the IV is always added by the firmware.
*/ if (!iwl_mvm_has_new_tx_api(mvm) && info->control.hw_key &&
info->control.hw_key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
info->control.hw_key->cipher != WLAN_CIPHER_SUITE_WEP104)
mh_len += info->control.hw_key->iv_len;
mh_len /= 2;
offload_assist |= mh_len << TX_CMD_OFFLD_MH_SIZE;
if (amsdu)
offload_assist |= BIT(TX_CMD_OFFLD_AMSDU); elseif (ieee80211_hdrlen(hdr->frame_control) % 4) /* padding is inserted later in transport */
offload_assist |= BIT(TX_CMD_OFFLD_PAD);
/* Default to 0 (BE) when tid_spec is set to IWL_MAX_TID_COUNT */ if (tx_cmd_params->tid_tspec < IWL_MAX_TID_COUNT)
ac = tid_to_mac80211_ac[tx_cmd_params->tid_tspec]; else
ac = tid_to_mac80211_ac[0];
/* 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_mvm_mac_ctxt_get_lowest_rate(mvm,
info,
info->control.vif);
/* Get PLCP rate for tx_cmd->rate_n_flags */
rate_plcp = iwl_mvm_mac80211_idx_to_hwrate(mvm->fw, rate_idx);
is_cck = (rate_idx >= IWL_FIRST_CCK_RATE) &&
(rate_idx <= IWL_LAST_CCK_RATE);
/* Set CCK or OFDM flag */ if (!is_cck)
rate_flags |= RATE_MCS_MOD_TYPE_LEGACY_OFDM; else
rate_flags |= RATE_MCS_MOD_TYPE_CCK;
result = RATE_MCS_MOD_TYPE_VHT;
result |= u32_encode_bits(mcs, RATE_VHT_MCS_RATE_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; elseif (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
result |= RATE_MCS_CHAN_WIDTH_80; elseif (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
result |= RATE_MCS_CHAN_WIDTH_160;
} elseif (rate->flags & IEEE80211_TX_RC_MCS) {
result = RATE_MCS_MOD_TYPE_HT;
result |= u32_encode_bits(rate->idx & 0x7,
RATE_HT_MCS_CODE_MSK);
result |= u32_encode_bits(rate->idx >> 3,
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 { int rate_idx = info->control.rates[0].idx;
result = iwl_mvm_convert_rate_idx(mvm, info, rate_idx);
}
if (info->control.antennas)
result |= u32_encode_bits(info->control.antennas,
RATE_MCS_ANT_AB_MSK); else
result |= iwl_mvm_get_tx_ant(mvm, info, sta, fc);
if (!ieee80211_hw_check(mvm->hw, HAS_RATE_CONTROL)) { /* info->control is only relevant for non HW rate control */
/* HT rate doesn't make sense for a non data frame */
WARN_ONCE(info->control.rates[0].flags & IEEE80211_TX_RC_MCS &&
!ieee80211_is_data(fc), "Got a HT rate (flags:0x%x/mcs:%d/fc:0x%x/state:%d) for a non data frame\n",
info->control.rates[0].flags,
info->control.rates[0].idx,
le16_to_cpu(fc),
sta ? iwl_mvm_sta_from_mac80211(sta)->sta_state : -1);
rate_idx = info->control.rates[0].idx;
/* For non 2 GHZ band, remap mac80211 rate indices into driver * indices.
*/ if (info->band != NL80211_BAND_2GHZ ||
(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
rate_idx += IWL_FIRST_OFDM_RATE;
/* For 2.4 GHZ band, check that there is no need to remap */
BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
}
case WLAN_CIPHER_SUITE_WEP104:
tx_cmd_params->sec_ctl |= TX_CMD_SEC_KEY128;
fallthrough; case WLAN_CIPHER_SUITE_WEP40:
tx_cmd_params->sec_ctl |= TX_CMD_SEC_WEP |
((keyconf->keyidx << TX_CMD_SEC_WEP_KEY_IDX_POS) &
TX_CMD_SEC_WEP_KEY_IDX_MSK);
memcpy(&tx_cmd_params->key[3], keyconf->key, keyconf->keylen); break; case WLAN_CIPHER_SUITE_GCMP: case WLAN_CIPHER_SUITE_GCMP_256:
type = TX_CMD_SEC_GCMP;
fallthrough; case WLAN_CIPHER_SUITE_CCMP_256: /* TODO: Taking the key from the table might introduce a race * when PTK rekeying is done, having an old packets with a PN * based on the old key but the message encrypted with a new * one. * Need to handle this.
*/
tx_cmd_params->sec_ctl |= type | TX_CMD_SEC_KEY_FROM_TABLE;
tx_cmd_params->key[0] = keyconf->hw_key_idx;
iwl_mvm_set_tx_cmd_pn(info, crypto_hdr); break; default:
tx_cmd_params->sec_ctl |= TX_CMD_SEC_EXT;
}
}
if (unlikely(info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT)) returntrue;
if (likely(ieee80211_is_data(hdr->frame_control) &&
mvmsta->sta_state >= IEEE80211_STA_AUTHORIZED)) returnfalse;
/* * Not a data frame, use host rate if on an old device that * can't possibly be doing MLO (firmware may be selecting a * bad rate), if we might be doing MLO we need to let FW pick * (since we don't necesarily know the link), but FW rate * selection was fixed.
*/ return mvm->trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_BZ;
}
if (ieee80211_is_data_qos(hdr->frame_control)) {
u8 *qc = ieee80211_get_qos_ctl(hdr);
amsdu = *qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT;
}
if (!info->control.hw_key)
flags |= IWL_TX_FLAGS_ENCRYPT_DIS;
/* * For data and mgmt packets rate info comes from the fw (for * new devices, older FW is somewhat broken for this). Only * set rate/antenna for injected frames with fixed rate, or * when no sta is given, or with older firmware.
*/ if (unlikely(iwl_mvm_use_host_rate(mvm, mvmsta, hdr, info))) {
flags |= IWL_TX_FLAGS_CMD_RATE;
rate_n_flags =
iwl_mvm_get_tx_rate_n_flags(mvm, info, sta,
hdr->frame_control);
} elseif (!ieee80211_is_data(hdr->frame_control) ||
mvmsta->sta_state < IEEE80211_STA_AUTHORIZED) { /* These are important frames */
flags |= IWL_TX_FLAGS_HIGH_PRI;
}
switch (info->control.vif->type) { case NL80211_IFTYPE_AP: case NL80211_IFTYPE_ADHOC: /* * Non-bufferable frames use the broadcast station, thus they * use the probe queue. * Also take care of the case where we send a deauth to a * station that we don't have, or similarly an association * response (with non-success status) for a station we can't * accept. * Also, disassociate frames might happen, particular 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->mgmt_queue;
if (!ieee80211_has_order(fc) && !ieee80211_is_probe_req(fc) &&
is_multicast_ether_addr(hdr->addr1)) return link->cab_queue;
WARN_ONCE(info->control.vif->type != NL80211_IFTYPE_ADHOC, "fc=0x%02x", le16_to_cpu(fc)); return link->mgmt_queue; case NL80211_IFTYPE_P2P_DEVICE: if (ieee80211_is_mgmt(fc)) return mvm->p2p_dev_queue;
WARN_ON_ONCE(1); return mvm->p2p_dev_queue; default:
WARN_ONCE(1, "Not a ctrl vif, no available queue\n"); return -1;
}
}
if ((info.control.vif->type == NL80211_IFTYPE_P2P_DEVICE &&
p2p_aux) ||
(info.control.vif->type == NL80211_IFTYPE_STATION &&
offchannel)) { /* * IWL_MVM_OFFCHANNEL_QUEUE is used for ROC packets * that can be used in 2 different types of vifs, P2P * Device and STATION. * P2P Device uses the offchannel queue. * STATION (HS2.0) uses the auxiliary context of the FW, * and hence needs to be sent on the aux queue. * If P2P_DEV_OVER_AUX is supported (p2p_aux = true) * also P2P Device uses the aux queue.
*/
sta_id = mvm->aux_sta.sta_id;
queue = mvm->aux_queue; if (WARN_ON(queue == IWL_MVM_INVALID_QUEUE)) return -1;
} elseif (info.control.vif->type ==
NL80211_IFTYPE_P2P_DEVICE ||
info.control.vif->type == NL80211_IFTYPE_AP ||
info.control.vif->type == NL80211_IFTYPE_ADHOC) {
u32 link_id = u32_get_bits(info.control.flags,
IEEE80211_TX_CTRL_MLO_LINK); struct iwl_mvm_vif_link_info *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;
}
link = mvmvif->link[link_id]; if (WARN_ON(!link)) return -1;
if (!ieee80211_is_data(hdr->frame_control))
sta_id = link->bcast_sta.sta_id; else
sta_id = link->mcast_sta.sta_id;
/* For HE redirect to trigger based fifos */ if (sta->deflink.he_cap.has_he && !WARN_ON(!iwl_mvm_has_new_tx_api(mvm)))
ac += 4;
txf = iwl_mvm_mac_ac_to_tx_fifo(mvm, ac);
/* * Don't send an AMSDU that will be longer than the TXF. * Add a security margin of 256 for the TX command + headers. * We also want to have the start of the next packet inside the * fifo to be able to send bursts.
*/
val = mvmsta->max_amsdu_len;
if (hweight16(sta->valid_links) <= 1) { if (sta->valid_links) { struct ieee80211_bss_conf *link_conf; unsignedint link = ffs(sta->valid_links) - 1;
rcu_read_lock();
link_conf = rcu_dereference(mvmsta->vif->link_conf[link]); if (WARN_ON(!link_conf))
band = NL80211_BAND_2GHZ; else
band = link_conf->chanreq.oper.chan->band;
rcu_read_unlock();
} else {
band = mvmsta->vif->bss_conf.chanreq.oper.chan->band;
}
lmac = iwl_mvm_get_lmac_id(mvm, band);
} elseif (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_CDB_SUPPORT)) { /* for real MLO restrict to both LMACs if they exist */
lmac = IWL_LMAC_5G_INDEX;
val = min_t(unsignedint, val,
mvm->fwrt.smem_cfg.lmac[lmac].txfifo_size[txf] - 256);
lmac = IWL_LMAC_24G_INDEX;
} else {
lmac = IWL_LMAC_24G_INDEX;
}
/* * Do not build AMSDU for IPv6 with extension headers. * ask stack to segment and checkum 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_skb);
}
tid = ieee80211_get_tid(hdr); if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) return -EINVAL;
/* * No need to lock amsdu_in_ampdu_allowed since it can't be modified * during an BA session.
*/ if ((info->flags & IEEE80211_TX_CTL_AMPDU &&
!mvmsta->tid_data[tid].amsdu_in_ampdu_allowed) ||
!(mvmsta->amsdu_enabled & BIT(tid))) return iwl_tx_tso_segment(skb, 1, netdev_flags, mpdus_skb);
/* * Take the min of ieee80211 station and mvm station
*/
max_amsdu_len =
min_t(unsignedint, sta->cur->max_amsdu_len,
iwl_mvm_max_amsdu_size(mvm, sta, tid));
/* * Limit A-MSDU in A-MPDU to 4095 bytes when VHT is not * supported. This is a spec requirement (IEEE 802.11-2015 * section 8.7.3 NOTE 3).
*/ if (info->flags & IEEE80211_TX_CTL_AMPDU &&
!sta->deflink.vht_cap.vht_supported)
max_amsdu_len = min_t(unsignedint, max_amsdu_len, 4095);
/* 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_amsdu_len + pad) / (subf_len + pad);
if (sta->max_amsdu_subframes &&
num_subframes > sta->max_amsdu_subframes)
num_subframes = sta->max_amsdu_subframes;
/* * 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) >
mvm->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 (num_subframes * mss >= tcp_payload_len) {
__skb_queue_tail(mpdus_skb, 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_skb);
} #else/* CONFIG_INET */ staticint iwl_mvm_tx_tso(struct iwl_mvm *mvm, struct sk_buff *skb, struct ieee80211_tx_info *info, struct ieee80211_sta *sta, struct sk_buff_head *mpdus_skb)
{ /* Impossible to get TSO with CONFIG_INET */
WARN_ON(1);
return -1;
} #endif
/* Check if there are any timed-out TIDs on a given shared TXQ */ staticbool iwl_mvm_txq_should_update(struct iwl_mvm *mvm, int txq_id)
{ unsignedlong queue_tid_bitmap = mvm->queue_info[txq_id].tid_bitmap; unsignedlong now = jiffies; int tid;
if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) returnfalse;
/* * we handle that entirely ourselves -- for uAPSD the firmware * will always send a notification, and for PS-Poll responses * we'll notify mac80211 when getting frame status
*/
info->flags &= ~IEEE80211_TX_STATUS_EOSP;
spin_lock(&mvmsta->lock);
/* nullfunc frames should go to the MGMT queue regardless of QOS, * the conditions of !ieee80211_is_qos_nullfunc(fc) and * !ieee80211_is_data_qos(fc) keep the default assignment of MGMT TID
*/ if (ieee80211_is_data_qos(fc) && !ieee80211_is_qos_nullfunc(fc)) {
tid = ieee80211_get_tid(hdr); if (WARN_ONCE(tid >= IWL_MAX_TID_COUNT, "Invalid TID %d", tid)) goto drop_unlock_sta;
is_ampdu = info->flags & IEEE80211_TX_CTL_AMPDU; if (WARN_ONCE(is_ampdu &&
mvmsta->tid_data[tid].state != IWL_AGG_ON, "Invalid internal agg state %d for TID %d",
mvmsta->tid_data[tid].state, tid)) goto drop_unlock_sta;
if (!iwl_mvm_has_new_tx_api(mvm)) { /* Keep track of the time of the last frame for this RA/TID */
mvm->queue_info[txq_id].last_frame_time[tid] = jiffies;
/* * If we have timed-out TIDs - schedule the worker that will * reconfig the queues and update them * * Note that the no lock is taken here in order to not serialize * the TX flow. This isn't dangerous because scheduling * mvm->add_stream_wk can't ruin the state, and if we DON'T * schedule it due to some race condition then next TX we get * here we will.
*/ if (unlikely(mvm->queue_info[txq_id].status ==
IWL_MVM_QUEUE_SHARED &&
iwl_mvm_txq_should_update(mvm, txq_id)))
schedule_work(&mvm->add_stream_wk);
}
IWL_DEBUG_TX(mvm, "TX to [%d|%d] Q:%d - seq: 0x%x len %d\n",
mvmsta->deflink.sta_id, tid, txq_id,
IEEE80211_SEQ_TO_SN(seq_number), skb->len);
/* From now on, we cannot access info->control */
iwl_mvm_skb_prepare_status(skb, dev_cmd);
/* * The IV is introduced by the HW for new tx api, and it is not present * in the skb, hence, don't tell iwl_mvm_mei_tx_copy_to_csme about the * IV for those devices.
*/ if (ieee80211_is_data(fc))
iwl_mvm_mei_tx_copy_to_csme(mvm, skb,
info->control.hw_key &&
!iwl_mvm_has_new_tx_api(mvm) ?
info->control.hw_key->iv_len : 0);
if (iwl_trans_tx(mvm->trans, skb, dev_cmd, txq_id)) goto drop_unlock_sta;
if (payload_len <= skb_shinfo(skb)->gso_size) return iwl_mvm_tx_mpdu(mvm, skb, &info, sta, NULL);
__skb_queue_head_init(&mpdus_skbs);
vif = info.control.vif; if (!vif) return -1;
ret = iwl_mvm_tx_tso(mvm, skb, &info, sta, &mpdus_skbs); if (ret) return ret;
WARN_ON(skb_queue_empty(&mpdus_skbs));
/* * As described in IEEE sta 802.11-2020, table 9-30 (Address * field contents), A-MSDU address 3 should contain the BSSID * address. * Pass address 3 down to iwl_mvm_tx_mpdu() and further to set it * in the command header. We need to preserve the original * address 3 in the skb header to correctly create all the * A-MSDU subframe headers from it.
*/ switch (vif->type) { case NL80211_IFTYPE_STATION:
addr3 = vif->cfg.ap_addr; break; case NL80211_IFTYPE_AP:
addr3 = vif->addr; break; default:
addr3 = NULL; break;
}
while (!skb_queue_empty(&mpdus_skbs)) { struct ieee80211_hdr *hdr; bool amsdu;
ret = iwl_mvm_tx_mpdu(mvm, skb, &info, sta,
amsdu ? addr3 : NULL); if (ret) { /* 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(mvm->hw, skb); else
kfree_skb(skb); /* there was error, but we consumed skb one way or another, so return 0 */ return 0;
}
}
if (tid_data->state == IWL_AGG_ON &&
iwl_mvm_tid_queued(mvm, tid_data) == 0) { /* * Now that this aggregation or DQA queue is empty tell * mac80211 so it knows we no longer have frames buffered for * the station on this TID (for the TIM bitmap calculation.)
*/
ieee80211_sta_set_buffered(sta, tid, false);
}
/* * In 22000 HW, the next_reclaimed index is only 8 bit, so we'll need * to align the wrap around of ssn so we compare relevant values.
*/
normalized_ssn = tid_data->ssn; if (mvm->trans->mac_cfg->gen2)
normalized_ssn &= 0xff;
if (normalized_ssn != tid_data->next_reclaimed) return;
if (rate_n_flags & RATE_MCS_SGI_MSK)
r->flags |= IEEE80211_TX_RC_SHORT_GI; switch (format) { case RATE_MCS_MOD_TYPE_HT:
r->flags |= IEEE80211_TX_RC_MCS;
r->idx = rate; break; case RATE_MCS_MOD_TYPE_VHT:
ieee80211_rate_set_vht(r, rate,
FIELD_GET(RATE_MCS_NSS_MSK,
rate_n_flags) + 1);
r->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 */
r->idx = 0; break; default:
r->idx = iwl_mvm_legacy_hw_idx_to_mac80211_idx(rate_n_flags,
band);
}
}
/* * translate ucode response to mac80211 tx status control values
*/ staticvoid iwl_mvm_hwrate_to_tx_status(struct iwl_mvm *mvm,
__le32 rate_n_flags, struct ieee80211_tx_info *info)
{ struct ieee80211_tx_rate *r = &info->status.rates[0];
u32 rate;
/* * Technically this conversion is incorrect for BA status, however: * - we only use the BA notif data for older firmware that have * host rate scaling and don't use newer rate formats * - the firmware API changed together for BA notif and TX CMD * as well
*/
rate = iwl_mvm_v3_rate_from_fw(rate_n_flags, mvm->fw_rates_ver);
trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, NULL,
FW_DBG_TRIGGER_TX_STATUS); if (!trig) return;
status_trig = (void *)trig->data;
for (i = 0; i < ARRAY_SIZE(status_trig->statuses); i++) { /* don't collect on status 0 */ if (!status_trig->statuses[i].status) break;
if (status_trig->statuses[i].status != (status & TX_STATUS_MSK)) continue;
iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, "Tx status %d was received",
status & TX_STATUS_MSK); break;
}
}
/* * iwl_mvm_get_scd_ssn - returns the SSN of the SCD * @tx_resp: the Tx response from the fw (agg or non-agg) * * When the fw sends an AMPDU, it fetches the MPDUs one after the other. Since * it can't know that everything will go well until the end of the AMPDU, it * can't know in advance the number of MPDUs that will be sent in the current * batch. This is why it writes the agg Tx response while it fetches the MPDUs. * Hence, it can't know in advance what the SSN of the SCD will be at the end * of the batch. This is why the SSN of the SCD is written at the end of the * whole struct at a variable offset. This function knows how to cope with the * variable offset and returns the SSN of the SCD. * * For 22000-series and lower, this is just 12 bits. For later, 16 bits.
*/ staticinline u32 iwl_mvm_get_scd_ssn(struct iwl_mvm *mvm, struct iwl_tx_resp *tx_resp)
{
u32 val = le32_to_cpup((__le32 *)iwl_mvm_get_agg_status(mvm, tx_resp) +
tx_resp->frame_count);
if (mvm->trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) return val & 0xFFFF; return val & 0xFFF;
}
staticvoid iwl_mvm_rx_tx_cmd_single(struct iwl_mvm *mvm, struct iwl_rx_packet *pkt)
{ struct ieee80211_sta *sta;
u16 sequence = le16_to_cpu(pkt->hdr.sequence); int txq_id = SEQ_TO_QUEUE(sequence); /* struct iwl_tx_resp_v3 is almost the same */ struct iwl_tx_resp *tx_resp = (void *)pkt->data; int sta_id = IWL_TX_RES_GET_RA(tx_resp->ra_tid); int tid = IWL_TX_RES_GET_TID(tx_resp->ra_tid); struct agg_tx_status *agg_status =
iwl_mvm_get_agg_status(mvm, tx_resp);
u32 status = le16_to_cpu(agg_status->status);
u16 ssn = iwl_mvm_get_scd_ssn(mvm, tx_resp); struct sk_buff_head skbs;
u8 skb_freed = 0;
u8 lq_color;
u16 next_reclaimed, seq_ctl; bool is_ndp = false;
__skb_queue_head_init(&skbs);
if (iwl_mvm_has_new_tx_api(mvm))
txq_id = le16_to_cpu(tx_resp->tx_queue);
seq_ctl = le16_to_cpu(tx_resp->seq_ctl);
/* we can free until ssn % q.n_bd not inclusive */
iwl_trans_reclaim(mvm->trans, txq_id, ssn, &skbs, false);
/* 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; case TX_STATUS_FAIL_FIFO_FLUSHED: case TX_STATUS_FAIL_DRAIN_FLOW:
flushed = true; break; case TX_STATUS_FAIL_DEST_PS: /* the FW should have stopped the queue and not * return this status
*/
IWL_ERR_LIMIT(mvm, "FW reported TX filtered, status=0x%x, FC=0x%x\n",
status, le16_to_cpu(hdr->frame_control));
info->flags |= IEEE80211_TX_STAT_TX_FILTERED; break; default: break;
}
if ((status & TX_STATUS_MSK) != TX_STATUS_SUCCESS &&
ieee80211_is_mgmt(hdr->frame_control))
iwl_mvm_toggle_tx_ant(mvm, &mvm->mgmt_last_antenna_idx);
/* * 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;
/* Don't assign the converted initial_rate, because driver * TLC uses this and doesn't support the new FW rate
*/
info->status.status_driver_data[1] =
(void *)(uintptr_t)le32_to_cpu(tx_resp->initial_rate);
/* Single frame failure in an AMPDU queue => send BAR */ if (info->flags & IEEE80211_TX_CTL_AMPDU &&
!(info->flags & IEEE80211_TX_STAT_ACK) &&
!(info->flags & IEEE80211_TX_STAT_TX_FILTERED) && !flushed)
info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
info->flags &= ~IEEE80211_TX_CTL_AMPDU;
/* W/A FW bug: seq_ctl is wrong upon failure / BAR frame */ if (ieee80211_is_back_req(hdr->frame_control))
seq_ctl = 0; elseif (status != TX_STATUS_SUCCESS)
seq_ctl = le16_to_cpu(hdr->seq_ctrl);
if (unlikely(!seq_ctl)) { /* * If it is an NDP, we can't update next_reclaim since * its sequence control is 0. Note that for that same * reason, NDPs are never sent to A-MPDU'able queues * so that we can never have more than one freed frame * for a single Tx resonse (see WARN_ON below).
*/ if (ieee80211_is_qos_nullfunc(hdr->frame_control))
is_ndp = true;
}
/* * TODO: this is not accurate if we are freeing more than one * packet.
*/
info->status.tx_time =
le16_to_cpu(tx_resp->wireless_media_time);
BUILD_BUG_ON(ARRAY_SIZE(info->status.status_driver_data) < 1);
lq_color = TX_RES_RATE_TABLE_COL_GET(tx_resp->tlc_info);
info->status.status_driver_data[0] =
RS_DRV_DATA_PACK(lq_color, tx_resp->reduced_tpc);
if (likely(!iwl_mvm_time_sync_frame(mvm, skb, hdr->addr1)))
ieee80211_tx_status_skb(mvm->hw, skb);
}
/* This is an aggregation queue or might become one, so we use * the ssn since: ssn = wifi seq_num % 256. * The seq_ctl is the sequence control of the packet to which * this Tx response relates. But if there is a hole in the * bitmap of the BA we received, this Tx response may allow to * reclaim the hole and all the subsequent packets that were * already acked. In that case, seq_ctl != ssn, and the next * packet to be reclaimed will be ssn and not seq_ctl. In that * case, several packets will be reclaimed even if * frame_count = 1. * * The ssn is the index (% 256) of the latest packet that has * treated (acked / dropped) + 1.
*/
next_reclaimed = ssn;
IWL_DEBUG_TX_REPLY(mvm, "TXQ %d status %s (0x%08x)\n",
txq_id, iwl_mvm_get_tx_fail_reason(status), status);
sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); /* * sta can't be NULL otherwise it'd mean that the sta has been freed in * the firmware while we still have packets for it in the Tx queues.
*/ if (WARN_ON_ONCE(!sta)) goto out;
if (!IS_ERR(sta)) { struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
if (mvmsta->sleep_tx_count) {
mvmsta->sleep_tx_count--; if (mvmsta->sleep_tx_count &&
!iwl_mvm_tid_queued(mvm, tid_data)) { /* * The number of frames in the queue * dropped to 0 even if we sent less * frames than we thought we had on the * Tx queue. * This means we had holes in the BA * window that we just filled, ask * mac80211 to send EOSP since the * firmware won't know how to do that. * Send NDP and the firmware will send * EOSP notification that will trigger * a call to ieee80211_sta_eosp().
*/
send_eosp_ndp = true;
}
}
if (tx_resp->frame_count == 1)
iwl_mvm_rx_tx_cmd_single(mvm, pkt); else
iwl_mvm_rx_tx_cmd_agg(mvm, pkt);
}
staticvoid iwl_mvm_tx_reclaim(struct iwl_mvm *mvm, int sta_id, int tid, int txq, int index, struct ieee80211_tx_info *tx_info, __le32 rate, bool is_flush)
{ struct sk_buff_head reclaimed_skbs; struct iwl_mvm_tid_data *tid_data = NULL; struct ieee80211_sta *sta; struct iwl_mvm_sta *mvmsta = NULL; struct sk_buff *skb; int freed;
if (WARN_ONCE(sta_id >= mvm->fw->ucode_capa.num_stations ||
tid > IWL_MAX_TID_COUNT, "sta_id %d tid %d", sta_id, tid)) return;
rcu_read_lock();
sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
/* Reclaiming frames for a station that has been deleted ? */ if (WARN_ON_ONCE(!sta)) {
rcu_read_unlock(); return;
}
__skb_queue_head_init(&reclaimed_skbs);
/* * Release all TFDs before the SSN, i.e. all TFDs in front of * block-ack window (we assume that they've been successfully * transmitted ... if not, it's too late anyway).
*/
iwl_trans_reclaim(mvm->trans, txq, index, &reclaimed_skbs, is_flush);
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 (!is_flush)
info->flags |= IEEE80211_TX_STAT_ACK; else
info->flags &= ~IEEE80211_TX_STAT_ACK;
}
/* * It's possible to get a BA response after invalidating the rcu (rcu is * invalidated in order to prevent new Tx from being sent, but there may * be some frames already in-flight). * In this case we just want to reclaim, and could skip all the * sta-dependent stuff since it's in the middle of being removed * anyways.
*/ if (IS_ERR(sta)) goto out;
if (tid_data->txq_id != txq) {
IWL_ERR(mvm, "invalid reclaim request: Q %d, tid %d\n",
tid_data->txq_id, tid);
rcu_read_unlock(); return;
}
spin_lock_bh(&mvmsta->lock);
tid_data->next_reclaimed = index;
iwl_mvm_check_ratid_empty(mvm, sta, tid);
freed = 0;
/* pack lq color from tid_data along the reduced txp */
tx_info->status.status_driver_data[0] =
RS_DRV_DATA_PACK(tid_data->lq_color,
tx_info->status.status_driver_data[0]); /* the value is only consumed for old FW that has v1 rates anyway */
tx_info->status.status_driver_data[1] =
(void *)(uintptr_t)le32_to_cpu(rate);
if (!is_flush) { if (ieee80211_is_data_qos(hdr->frame_control))
freed++; else
WARN_ON_ONCE(tid != IWL_MAX_TID_COUNT);
}
/* this is the first skb we deliver in this batch */ /* put the rate scaling data there */ if (freed == 1) {
info->flags |= IEEE80211_TX_STAT_AMPDU;
memcpy(&info->status, &tx_info->status, sizeof(tx_info->status));
iwl_mvm_hwrate_to_tx_status(mvm, rate, info);
}
}
spin_unlock_bh(&mvmsta->lock);
/* We got a BA notif with 0 acked or scd_ssn didn't progress which is * possible (i.e. first MPDU in the aggregation wasn't acked) * Still it's important to update RS about sent vs. acked.
*/ if (!is_flush && skb_queue_empty(&reclaimed_skbs) &&
!iwl_mvm_has_tlc_offload(mvm)) { struct ieee80211_chanctx_conf *chanctx_conf = NULL;
/* no TLC offload, so non-MLD mode */ if (mvmsta->vif)
chanctx_conf =
rcu_dereference(mvmsta->vif->bss_conf.chanctx_conf);
tfd_cnt = le16_to_cpu(ba_res->tfd_cnt); if (!tfd_cnt) return;
if (IWL_FW_CHECK(mvm,
struct_size(ba_res, tfd, tfd_cnt) > pkt_len, "short BA notification (tfds:%d, size:%d)\n",
tfd_cnt, pkt_len)) return;
IWL_DEBUG_TX_REPLY(mvm, "BA_NOTIFICATION Received from sta_id = %d, flags %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));
rcu_read_lock();
mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, sta_id); /* * It's possible to get a BA response after invalidating the rcu * (rcu is invalidated in order to prevent new Tx from being * sent, but there may be some frames already in-flight). * In this case we just want to reclaim, and could skip all the * sta-dependent stuff since it's in the middle of being removed * anyways.
*/
/* Free per TID */ for (i = 0; i < tfd_cnt; i++) { struct iwl_compressed_ba_tfd *ba_tfd = &ba_res->tfd[i];
tid = ba_tfd->tid; if (tid == IWL_MGMT_TID)
tid = IWL_MAX_TID_COUNT;
if (mvmsta)
mvmsta->tid_data[i].lq_color = lq_color;
ba_notif = (void *)pkt->data;
sta_id = ba_notif->sta_id;
tid = ba_notif->tid; /* "flow" corresponds to Tx queue */
txq = le16_to_cpu(ba_notif->scd_flow); /* "ssn" is start of block-ack Tx window, corresponds to index
* (in Tx queue's circular buffer) of first TFD/frame in window */
index = le16_to_cpu(ba_notif->scd_ssn);
rcu_read_lock();
mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, sta_id); if (IWL_FW_CHECK(mvm, !mvmsta, "invalid STA ID %d in BA notif\n",
sta_id)) {
rcu_read_unlock(); return;
}
/* * Note that there are transports that buffer frames before they reach * the firmware. This means that after flush_tx_path is called, the * queue might not be empty. The race-free way to handle this is to: * 1) set the station as draining * 2) flush the Tx path * 3) wait for the transport queues to be empty
*/ int iwl_mvm_flush_tx_path(struct iwl_mvm *mvm, u32 tfd_msk)
{ int ret; struct iwl_tx_path_flush_cmd_v1 flush_cmd = {
.queues_ctl = cpu_to_le32(tfd_msk),
.flush_ctl = cpu_to_le16(DUMP_TX_FIFO_FLUSH),
};
WARN_ON(iwl_mvm_has_new_tx_api(mvm));
ret = iwl_mvm_send_cmd_pdu(mvm, TXPATH_FLUSH, 0, sizeof(flush_cmd), &flush_cmd); if (ret)
IWL_ERR(mvm, "Failed to send flush command (%d)\n", ret); return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.