30 #include <linux/kernel.h>
31 #include <linux/module.h>
33 #include <linux/sched.h>
41 static const u8 tid_to_ac[] = {
52 static void iwlagn_tx_cmd_protection(
struct iwl_priv *
priv,
65 static void iwlagn_tx_cmd_build_basic(
struct iwl_priv *priv,
81 if (ieee80211_is_probe_resp(fc))
83 else if (ieee80211_is_back_req(fc))
86 priv->
cfg->bt_params &&
87 priv->
cfg->bt_params->advanced_bt_coexist &&
88 (ieee80211_is_auth(fc) || ieee80211_is_assoc_req(fc) ||
89 ieee80211_is_reassoc_req(fc) ||
95 if (ieee80211_has_morefrags(fc))
98 if (ieee80211_is_data_qos(fc)) {
99 u8 *qc = ieee80211_get_qos_ctl(hdr);
110 iwlagn_tx_cmd_protection(priv, info, fc, &tx_flags);
113 if (ieee80211_is_mgmt(fc)) {
114 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
127 static void iwlagn_tx_cmd_build_rate(
struct iwl_priv *priv,
147 if (ieee80211_is_probe_resp(fc)) {
150 min(data_retry_limit, rts_retry_limit);
151 }
else if (ieee80211_is_back_req(fc))
162 if (ieee80211_is_data(fc)) {
165 #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
166 if (priv->tm_fixed_rate) {
178 }
else if (ieee80211_is_back_req(fc))
187 rate_idx = info->
control.rates[0].idx;
190 rate_idx = rate_lowest_index(
205 if (priv->
cfg->bt_params &&
206 priv->
cfg->bt_params->advanced_bt_coexist &&
215 rate_flags |= iwl_ant_idx_to_flags(priv->
mgmt_tx_ant);
218 tx_cmd->
rate_n_flags = iwl_hw_set_rate_n_flags(rate_plcp, rate_flags);
221 static void iwlagn_tx_cmd_build_hwcrypto(
struct iwl_priv *priv,
228 switch (keyconf->
cipher) {
252 IWL_DEBUG_TX(priv,
"Configuring packet for WEP encryption "
253 "with key %d\n", keyconf->
keyidx);
257 IWL_ERR(priv,
"Unknown encode cipher %x\n", keyconf->
cipher);
280 sta_id = iwl_sta_id(sta);
312 ctx = iwl_rxon_ctx_from_vif(info->
control.vif);
314 if (iwl_is_rfkill(priv)) {
316 goto drop_unlock_priv;
321 #ifdef CONFIG_IWLWIFI_DEBUG
322 if (ieee80211_is_auth(fc))
324 else if (ieee80211_is_assoc_req(fc))
326 else if (ieee80211_is_reassoc_req(fc))
330 if (
unlikely(ieee80211_is_probe_resp(fc))) {
346 if (!ieee80211_is_data(fc))
350 sta_id = iwl_sta_id_or_broadcast(ctx, sta);
354 goto drop_unlock_priv;
361 sta_priv = (
void *)sta->drv_priv;
384 dev_cmd = iwl_trans_alloc_tx_cmd(priv->
trans);
387 goto drop_unlock_priv;
389 memset(dev_cmd, 0,
sizeof(*dev_cmd));
397 iwlagn_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb);
400 iwlagn_tx_cmd_build_basic(priv, skb, tx_cmd, info, hdr, sta_id);
402 iwlagn_tx_cmd_build_rate(priv, tx_cmd, info, sta, fc);
412 if (ieee80211_is_data_qos(fc) && !ieee80211_is_qos_nullfunc(fc)) {
415 qc = ieee80211_get_qos_ctl(hdr);
418 goto drop_unlock_sta;
419 tid_data = &priv->
tid_data[sta_id][tid];
424 IWL_ERR(priv,
"TX_CTL_AMPDU while not in AGG:"
425 " Tx flags = 0x%08x, agg.state = %d",
427 IWL_ERR(priv,
"sta_id = %d, tid = %d seq_num = %d",
429 goto drop_unlock_sta;
437 "Tx while agg.state = %d", tid_data->
agg.state))
438 goto drop_unlock_sta;
451 txq_id = priv->
tid_data[sta_id][tid].agg.txq_id;
468 txq_id = ctx->
ac_to_queue[skb_get_queue_mapping(skb)];
474 if (iwl_trans_tx(priv->
trans, skb, dev_cmd, txq_id))
475 goto drop_unlock_sta;
477 if (ieee80211_is_data_qos(fc) && !ieee80211_is_qos_nullfunc(fc) &&
478 !ieee80211_has_morefrags(fc))
490 if (sta_priv && sta_priv->
client && !is_agg)
500 iwl_trans_free_tx_cmd(priv->
trans, dev_cmd);
506 static int iwlagn_alloc_agg_txq(
struct iwl_priv *priv,
int mq)
511 q < priv->
cfg->base_params->num_of_queues; q++) {
521 static void iwlagn_dealloc_agg_txq(
struct iwl_priv *priv,
int q)
534 sta_id = iwl_sta_id(sta);
537 IWL_ERR(priv,
"Invalid station for AGG tid %d\n", tid);
543 tid_data = &priv->
tid_data[sta_id][tid];
544 txq_id = priv->
tid_data[sta_id][tid].agg.txq_id;
546 switch (priv->
tid_data[sta_id][tid].agg.state) {
561 IWL_DEBUG_HT(priv,
"AGG stop before AGG became operational\n");
566 IWL_WARN(priv,
"Stopping AGG while state not ON "
567 "or starting for %d on %d (%d)\n", sta_id, tid,
568 priv->
tid_data[sta_id][tid].agg.state);
578 "stopping AGG on STA/TID %d/%d but hwq %d not used\n",
579 sta_id, tid, txq_id);
585 priv->
tid_data[sta_id][tid].agg.state =
594 agg_state = priv->
tid_data[sta_id][tid].agg.state;
607 iwl_trans_txq_disable(priv->
trans, txq_id);
611 iwlagn_dealloc_agg_txq(priv, txq_id);
624 int sta_id, txq_id,
ret;
626 IWL_DEBUG_HT(priv,
"TX AGG request on ra = %pM tid = %d\n",
629 sta_id = iwl_sta_id(sta);
631 IWL_ERR(priv,
"Start AGG on invalid station\n");
638 IWL_ERR(priv,
"Start AGG when state is not IWL_AGG_OFF !\n");
642 txq_id = iwlagn_alloc_agg_txq(priv, ctx->
ac_to_queue[tid_to_ac[tid]]);
645 "No free aggregation queue for %pM/%d\n",
655 tid_data = &priv->
tid_data[sta_id][tid];
657 tid_data->
agg.txq_id = txq_id;
659 *ssn = tid_data->
agg.ssn;
668 "next_reclaimed = %d\n",
694 fifo =
ctx->ac_to_fifo[tid_to_ac[tid]];
696 iwl_trans_txq_enable(priv->
trans, q, fifo, sta_priv->
sta_id, tid,
719 if (priv->
hw_params.use_rts_for_aggregation) {
725 sta_priv->
lq_sta.lq.general_params.flags |=
732 sta_priv->
lq_sta.lq.agg_params.agg_frame_cnt_limit =
735 IWL_DEBUG_HT(priv,
"Tx aggregation enabled on ra = %pM tid = %d\n",
742 static void iwlagn_check_ratid_empty(
struct iwl_priv *priv,
int sta_id,
u8 tid)
751 addr = priv->
stations[sta_id].sta.sta.addr;
755 switch (priv->
tid_data[sta_id][tid].agg.state) {
760 "Can continue DELBA flow ssn = next_recl ="
762 iwl_trans_txq_disable(priv->
trans,
763 tid_data->
agg.txq_id);
764 iwlagn_dealloc_agg_txq(priv, tid_data->
agg.txq_id);
773 "Can continue ADDBA flow ssn = next_recl ="
784 static void iwlagn_non_agg_tx_status(
struct iwl_priv *priv,
794 sta_priv = (
void *)sta->drv_priv;
806 static void iwlagn_hwrate_to_tx_control(
struct iwl_priv *priv,
u32 rate_n_flags,
826 #ifdef CONFIG_IWLWIFI_DEBUG
827 const char *iwl_get_tx_fail_reason(
u32 status)
829 #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x
830 #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x
835 TX_STATUS_POSTPONE(
DELAY);
836 TX_STATUS_POSTPONE(FEW_BYTES);
837 TX_STATUS_POSTPONE(BT_PRIO);
838 TX_STATUS_POSTPONE(QUIET_PERIOD);
839 TX_STATUS_POSTPONE(CALC_TTAK);
840 TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY);
841 TX_STATUS_FAIL(SHORT_LIMIT);
842 TX_STATUS_FAIL(LONG_LIMIT);
843 TX_STATUS_FAIL(FIFO_UNDERRUN);
844 TX_STATUS_FAIL(DRAIN_FLOW);
845 TX_STATUS_FAIL(RFKILL_FLUSH);
846 TX_STATUS_FAIL(LIFE_EXPIRE);
847 TX_STATUS_FAIL(DEST_PS);
849 TX_STATUS_FAIL(BT_RETRY);
850 TX_STATUS_FAIL(STA_INVALID);
851 TX_STATUS_FAIL(FRAG_DROPPED);
852 TX_STATUS_FAIL(TID_DISABLE);
853 TX_STATUS_FAIL(FIFO_FLUSHED);
854 TX_STATUS_FAIL(INSUFFICIENT_CF_POLL);
855 TX_STATUS_FAIL(PASSIVE_NO_RX);
856 TX_STATUS_FAIL(NO_BEACON_ON_RADAR);
861 #undef TX_STATUS_FAIL
862 #undef TX_STATUS_POSTPONE
866 static void iwlagn_count_agg_tx_err_status(
struct iwl_priv *priv,
u16 status)
913 static void iwl_rx_reply_tx_agg(
struct iwl_priv *priv,
929 "got tx response w/o block-ack\n");
939 priv->
cfg->bt_params &&
940 priv->
cfg->bt_params->advanced_bt_coexist) {
952 iwlagn_count_agg_tx_err_status(priv, fstatus);
959 "try-count (0x%08x)\n",
960 iwl_get_agg_tx_fail_reason(fstatus),
961 fstatus & AGG_TX_STATUS_MSK,
966 #ifdef CONFIG_IWLWIFI_DEBUG
967 #define AGG_TX_STATE_FAIL(x) case AGG_TX_STATE_ ## x: return #x
969 const char *iwl_get_agg_tx_fail_reason(
u16 status)
975 AGG_TX_STATE_FAIL(UNDERRUN_MSK);
976 AGG_TX_STATE_FAIL(BT_PRIO_MSK);
977 AGG_TX_STATE_FAIL(FEW_BYTES_MSK);
978 AGG_TX_STATE_FAIL(ABORT_MSK);
979 AGG_TX_STATE_FAIL(LAST_SENT_TTL_MSK);
980 AGG_TX_STATE_FAIL(LAST_SENT_TRY_CNT_MSK);
981 AGG_TX_STATE_FAIL(LAST_SENT_BT_KILL_MSK);
982 AGG_TX_STATE_FAIL(SCD_QUERY_MSK);
983 AGG_TX_STATE_FAIL(TEST_BAD_CRC32_MSK);
984 AGG_TX_STATE_FAIL(RESPONSE_MSK);
985 AGG_TX_STATE_FAIL(DUMP_TX_MSK);
986 AGG_TX_STATE_FAIL(DELAY_TX_MSK);
999 static void iwlagn_count_tx_err_status(
struct iwl_priv *priv,
u16 status)
1076 static void iwlagn_set_tx_status(
struct iwl_priv *priv,
1086 info->
flags |= iwl_tx_status_to_mac80211(status);
1089 if (!iwl_is_tx_success(status))
1090 iwlagn_count_tx_err_status(priv, status);
1093 static void iwl_check_abort_status(
struct iwl_priv *priv,
1097 IWL_ERR(priv,
"Tx flush command to flush out all frames\n");
1103 static int iwl_reclaim(
struct iwl_priv *priv,
int sta_id,
int tid,
1108 txq_id != priv->
tid_data[sta_id][tid].agg.txq_id)) {
1116 "Bad queue mapping txq_id=%d, agg_txq[sta:%d,tid:%d]=%d\n",
1117 txq_id, sta_id, tid,
1118 priv->
tid_data[sta_id][tid].agg.txq_id);
1122 iwl_trans_reclaim(priv->
trans, txq_id, ssn, skbs);
1136 u16 ssn = iwlagn_get_scd_ssn(tx_resp);
1145 bool is_offchannel_skb;
1155 iwl_rx_reply_tx_agg(priv, tx_resp);
1157 __skb_queue_head_init(&skbs);
1159 is_offchannel_skb =
false;
1163 next_reclaimed =
SEQ_TO_SN(next_reclaimed + 0x10);
1177 next_reclaimed =
ssn;
1181 priv->
tid_data[sta_id][tid].next_reclaimed =
1189 txq_id, ssn, &skbs));
1190 iwlagn_check_ratid_empty(priv, sta_id, tid);
1194 skb_queue_walk(&skbs, skb) {
1200 info = IEEE80211_SKB_CB(skb);
1202 iwl_trans_free_tx_cmd(priv->
trans,
1208 iwl_is_associated_ctx(ctx) && ctx->
vif &&
1217 "TXQ %d status %s (0x%08x) "
1218 "rate_n_flags 0x%x retries %d\n",
1220 iwl_get_tx_fail_reason(status),
1226 "FrameCnt = %d, idx=%d\n",
1231 if (is_agg && !iwl_is_tx_success(status))
1233 iwlagn_set_tx_status(priv, IEEE80211_SKB_CB(skb),
1236 iwlagn_non_agg_tx_status(priv, ctx, hdr->
addr1);
1243 WARN_ON(!is_agg && freed != 1);
1250 WARN_ON(is_offchannel_skb && freed != 1);
1253 iwl_check_abort_status(priv, tx_resp->
frame_count, status);
1256 while (!skb_queue_empty(&skbs)) {
1257 skb = __skb_dequeue(&skbs);
1261 if (is_offchannel_skb)
1295 if (
scd_flow >= priv->
cfg->base_params->num_of_queues) {
1297 "BUG_ON scd_flow is bigger than number of queues\n");
1301 sta_id = ba_resp->
sta_id;
1309 IWL_ERR(priv,
"Received BA when not expected\n");
1314 __skb_queue_head_init(&reclaimed_skbs);
1319 if (iwl_reclaim(priv, sta_id, tid,
scd_flow,
1320 ba_resp_scd_ssn, &reclaimed_skbs)) {
1331 "scd_flow = %d, scd_ssn = %d sent:%d, acked:%d\n",
1343 "bogus sent(%d) and ack(%d) count\n",
1354 iwlagn_check_ratid_empty(priv, sta_id, tid);
1357 skb_queue_walk(&reclaimed_skbs, skb) {
1365 info = IEEE80211_SKB_CB(skb);
1371 info = IEEE80211_SKB_CB(skb);
1384 while (!skb_queue_empty(&reclaimed_skbs)) {
1385 skb = __skb_dequeue(&reclaimed_skbs);