aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-tx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-tx.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c121
1 files changed, 73 insertions, 48 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index 2e89040e63be..288b871e974b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -141,7 +141,7 @@ void iwl_tx_queue_free(struct iwl_priv *priv, int txq_id)
141 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) 141 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
142 priv->cfg->ops->lib->txq_free_tfd(priv, txq); 142 priv->cfg->ops->lib->txq_free_tfd(priv, txq);
143 143
144 len = sizeof(struct iwl_cmd) * q->n_window; 144 len = sizeof(struct iwl_device_cmd) * q->n_window;
145 145
146 /* De-alloc array of command/tx buffers */ 146 /* De-alloc array of command/tx buffers */
147 for (i = 0; i < TFD_TX_CMD_SLOTS; i++) 147 for (i = 0; i < TFD_TX_CMD_SLOTS; i++)
@@ -156,6 +156,12 @@ void iwl_tx_queue_free(struct iwl_priv *priv, int txq_id)
156 kfree(txq->txb); 156 kfree(txq->txb);
157 txq->txb = NULL; 157 txq->txb = NULL;
158 158
159 /* deallocate arrays */
160 kfree(txq->cmd);
161 kfree(txq->meta);
162 txq->cmd = NULL;
163 txq->meta = NULL;
164
159 /* 0-fill queue descriptor structure */ 165 /* 0-fill queue descriptor structure */
160 memset(txq, 0, sizeof(*txq)); 166 memset(txq, 0, sizeof(*txq));
161} 167}
@@ -179,7 +185,7 @@ void iwl_cmd_queue_free(struct iwl_priv *priv)
179 if (q->n_bd == 0) 185 if (q->n_bd == 0)
180 return; 186 return;
181 187
182 len = sizeof(struct iwl_cmd) * q->n_window; 188 len = sizeof(struct iwl_device_cmd) * q->n_window;
183 len += IWL_MAX_SCAN_SIZE; 189 len += IWL_MAX_SCAN_SIZE;
184 190
185 /* De-alloc array of command/tx buffers */ 191 /* De-alloc array of command/tx buffers */
@@ -318,6 +324,7 @@ int iwl_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq,
318{ 324{
319 int i, len; 325 int i, len;
320 int ret; 326 int ret;
327 int actual_slots = slots_num;
321 328
322 /* 329 /*
323 * Alloc buffer array for commands (Tx or other types of commands). 330 * Alloc buffer array for commands (Tx or other types of commands).
@@ -327,14 +334,22 @@ int iwl_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq,
327 * For normal Tx queues (all other queues), no super-size command 334 * For normal Tx queues (all other queues), no super-size command
328 * space is needed. 335 * space is needed.
329 */ 336 */
330 len = sizeof(struct iwl_cmd); 337 if (txq_id == IWL_CMD_QUEUE_NUM)
331 for (i = 0; i <= slots_num; i++) { 338 actual_slots++;
332 if (i == slots_num) { 339
333 if (txq_id == IWL_CMD_QUEUE_NUM) 340 txq->meta = kzalloc(sizeof(struct iwl_cmd_meta) * actual_slots,
334 len += IWL_MAX_SCAN_SIZE; 341 GFP_KERNEL);
335 else 342 txq->cmd = kzalloc(sizeof(struct iwl_device_cmd *) * actual_slots,
336 continue; 343 GFP_KERNEL);
337 } 344
345 if (!txq->meta || !txq->cmd)
346 goto out_free_arrays;
347
348 len = sizeof(struct iwl_device_cmd);
349 for (i = 0; i < actual_slots; i++) {
350 /* only happens for cmd queue */
351 if (i == slots_num)
352 len += IWL_MAX_SCAN_SIZE;
338 353
339 txq->cmd[i] = kmalloc(len, GFP_KERNEL); 354 txq->cmd[i] = kmalloc(len, GFP_KERNEL);
340 if (!txq->cmd[i]) 355 if (!txq->cmd[i])
@@ -348,6 +363,10 @@ int iwl_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq,
348 363
349 txq->need_update = 0; 364 txq->need_update = 0;
350 365
366 /* aggregation TX queues will get their ID when aggregation begins */
367 if (txq_id <= IWL_TX_FIFO_AC3)
368 txq->swq_id = txq_id;
369
351 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise 370 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
352 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ 371 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
353 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); 372 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
@@ -360,15 +379,12 @@ int iwl_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq,
360 379
361 return 0; 380 return 0;
362err: 381err:
363 for (i = 0; i < slots_num; i++) { 382 for (i = 0; i < actual_slots; i++)
364 kfree(txq->cmd[i]); 383 kfree(txq->cmd[i]);
365 txq->cmd[i] = NULL; 384out_free_arrays:
366 } 385 kfree(txq->meta);
386 kfree(txq->cmd);
367 387
368 if (txq_id == IWL_CMD_QUEUE_NUM) {
369 kfree(txq->cmd[slots_num]);
370 txq->cmd[slots_num] = NULL;
371 }
372 return -ENOMEM; 388 return -ENOMEM;
373} 389}
374EXPORT_SYMBOL(iwl_tx_queue_init); 390EXPORT_SYMBOL(iwl_tx_queue_init);
@@ -669,7 +685,8 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
669 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 685 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
670 struct iwl_tx_queue *txq; 686 struct iwl_tx_queue *txq;
671 struct iwl_queue *q; 687 struct iwl_queue *q;
672 struct iwl_cmd *out_cmd; 688 struct iwl_device_cmd *out_cmd;
689 struct iwl_cmd_meta *out_meta;
673 struct iwl_tx_cmd *tx_cmd; 690 struct iwl_tx_cmd *tx_cmd;
674 int swq_id, txq_id; 691 int swq_id, txq_id;
675 dma_addr_t phys_addr; 692 dma_addr_t phys_addr;
@@ -732,8 +749,7 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
732 749
733 IWL_DEBUG_TX(priv, "station Id %d\n", sta_id); 750 IWL_DEBUG_TX(priv, "station Id %d\n", sta_id);
734 751
735 swq_id = skb_get_queue_mapping(skb); 752 txq_id = skb_get_queue_mapping(skb);
736 txq_id = swq_id;
737 if (ieee80211_is_data_qos(fc)) { 753 if (ieee80211_is_data_qos(fc)) {
738 qc = ieee80211_get_qos_ctl(hdr); 754 qc = ieee80211_get_qos_ctl(hdr);
739 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; 755 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
@@ -744,15 +760,13 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
744 hdr->seq_ctrl |= cpu_to_le16(seq_number); 760 hdr->seq_ctrl |= cpu_to_le16(seq_number);
745 seq_number += 0x10; 761 seq_number += 0x10;
746 /* aggregation is on for this <sta,tid> */ 762 /* aggregation is on for this <sta,tid> */
747 if (info->flags & IEEE80211_TX_CTL_AMPDU) { 763 if (info->flags & IEEE80211_TX_CTL_AMPDU)
748 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; 764 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
749 swq_id = iwl_virtual_agg_queue_num(swq_id, txq_id);
750 }
751 } 765 }
752 766
753 txq = &priv->txq[txq_id]; 767 txq = &priv->txq[txq_id];
768 swq_id = txq->swq_id;
754 q = &txq->q; 769 q = &txq->q;
755 txq->swq_id = swq_id;
756 770
757 if (unlikely(iwl_queue_space(q) < q->high_mark)) 771 if (unlikely(iwl_queue_space(q) < q->high_mark))
758 goto drop_unlock; 772 goto drop_unlock;
@@ -766,6 +780,7 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
766 780
767 /* Set up first empty entry in queue's array of Tx/cmd buffers */ 781 /* Set up first empty entry in queue's array of Tx/cmd buffers */
768 out_cmd = txq->cmd[q->write_ptr]; 782 out_cmd = txq->cmd[q->write_ptr];
783 out_meta = &txq->meta[q->write_ptr];
769 tx_cmd = &out_cmd->cmd.tx; 784 tx_cmd = &out_cmd->cmd.tx;
770 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); 785 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
771 memset(tx_cmd, 0, sizeof(struct iwl_tx_cmd)); 786 memset(tx_cmd, 0, sizeof(struct iwl_tx_cmd));
@@ -828,8 +843,8 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
828 txcmd_phys = pci_map_single(priv->pci_dev, 843 txcmd_phys = pci_map_single(priv->pci_dev,
829 &out_cmd->hdr, len, 844 &out_cmd->hdr, len,
830 PCI_DMA_BIDIRECTIONAL); 845 PCI_DMA_BIDIRECTIONAL);
831 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys); 846 pci_unmap_addr_set(out_meta, mapping, txcmd_phys);
832 pci_unmap_len_set(&out_cmd->meta, len, len); 847 pci_unmap_len_set(out_meta, len, len);
833 /* Add buffer containing Tx command and MAC(!) header to TFD's 848 /* Add buffer containing Tx command and MAC(!) header to TFD's
834 * first entry */ 849 * first entry */
835 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq, 850 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
@@ -869,8 +884,8 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
869 IWL_DEBUG_TX(priv, "sequence nr = 0X%x \n", 884 IWL_DEBUG_TX(priv, "sequence nr = 0X%x \n",
870 le16_to_cpu(out_cmd->hdr.sequence)); 885 le16_to_cpu(out_cmd->hdr.sequence));
871 IWL_DEBUG_TX(priv, "tx_flags = 0X%x \n", le32_to_cpu(tx_cmd->tx_flags)); 886 IWL_DEBUG_TX(priv, "tx_flags = 0X%x \n", le32_to_cpu(tx_cmd->tx_flags));
872 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd, sizeof(*tx_cmd)); 887 iwl_print_hex_dump(IWL_DL_TX, (u8 *)tx_cmd, sizeof(*tx_cmd));
873 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd->hdr, hdr_len); 888 iwl_print_hex_dump(IWL_DL_TX, (u8 *)tx_cmd->hdr, hdr_len);
874 889
875 /* Set up entry for this TFD in Tx byte-count array */ 890 /* Set up entry for this TFD in Tx byte-count array */
876 if (info->flags & IEEE80211_TX_CTL_AMPDU) 891 if (info->flags & IEEE80211_TX_CTL_AMPDU)
@@ -922,7 +937,8 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
922{ 937{
923 struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; 938 struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
924 struct iwl_queue *q = &txq->q; 939 struct iwl_queue *q = &txq->q;
925 struct iwl_cmd *out_cmd; 940 struct iwl_device_cmd *out_cmd;
941 struct iwl_cmd_meta *out_meta;
926 dma_addr_t phys_addr; 942 dma_addr_t phys_addr;
927 unsigned long flags; 943 unsigned long flags;
928 int len, ret; 944 int len, ret;
@@ -936,25 +952,32 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
936 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then 952 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
937 * we will need to increase the size of the TFD entries */ 953 * we will need to increase the size of the TFD entries */
938 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && 954 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
939 !(cmd->meta.flags & CMD_SIZE_HUGE)); 955 !(cmd->flags & CMD_SIZE_HUGE));
940 956
941 if (iwl_is_rfkill(priv)) { 957 if (iwl_is_rfkill(priv)) {
942 IWL_DEBUG_INFO(priv, "Not sending command - RF KILL"); 958 IWL_DEBUG_INFO(priv, "Not sending command - RF KILL\n");
943 return -EIO; 959 return -EIO;
944 } 960 }
945 961
946 if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { 962 if (iwl_queue_space(q) < ((cmd->flags & CMD_ASYNC) ? 2 : 1)) {
947 IWL_ERR(priv, "No space for Tx\n"); 963 IWL_ERR(priv, "No space for Tx\n");
948 return -ENOSPC; 964 return -ENOSPC;
949 } 965 }
950 966
951 spin_lock_irqsave(&priv->hcmd_lock, flags); 967 spin_lock_irqsave(&priv->hcmd_lock, flags);
952 968
953 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE); 969 idx = get_cmd_index(q, q->write_ptr, cmd->flags & CMD_SIZE_HUGE);
954 out_cmd = txq->cmd[idx]; 970 out_cmd = txq->cmd[idx];
971 out_meta = &txq->meta[idx];
972
973 memset(out_meta, 0, sizeof(*out_meta)); /* re-initialize to NULL */
974 out_meta->flags = cmd->flags;
975 if (cmd->flags & CMD_WANT_SKB)
976 out_meta->source = cmd;
977 if (cmd->flags & CMD_ASYNC)
978 out_meta->callback = cmd->callback;
955 979
956 out_cmd->hdr.cmd = cmd->id; 980 out_cmd->hdr.cmd = cmd->id;
957 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
958 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); 981 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
959 982
960 /* At this point, the out_cmd now has all of the incoming cmd 983 /* At this point, the out_cmd now has all of the incoming cmd
@@ -963,9 +986,9 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
963 out_cmd->hdr.flags = 0; 986 out_cmd->hdr.flags = 0;
964 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) | 987 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
965 INDEX_TO_SEQ(q->write_ptr)); 988 INDEX_TO_SEQ(q->write_ptr));
966 if (out_cmd->meta.flags & CMD_SIZE_HUGE) 989 if (cmd->flags & CMD_SIZE_HUGE)
967 out_cmd->hdr.sequence |= SEQ_HUGE_FRAME; 990 out_cmd->hdr.sequence |= SEQ_HUGE_FRAME;
968 len = sizeof(struct iwl_cmd) - sizeof(struct iwl_cmd_meta); 991 len = sizeof(struct iwl_device_cmd);
969 len += (idx == TFD_CMD_SLOTS) ? IWL_MAX_SCAN_SIZE : 0; 992 len += (idx == TFD_CMD_SLOTS) ? IWL_MAX_SCAN_SIZE : 0;
970 993
971 994
@@ -997,8 +1020,8 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
997 1020
998 phys_addr = pci_map_single(priv->pci_dev, &out_cmd->hdr, 1021 phys_addr = pci_map_single(priv->pci_dev, &out_cmd->hdr,
999 fix_size, PCI_DMA_BIDIRECTIONAL); 1022 fix_size, PCI_DMA_BIDIRECTIONAL);
1000 pci_unmap_addr_set(&out_cmd->meta, mapping, phys_addr); 1023 pci_unmap_addr_set(out_meta, mapping, phys_addr);
1001 pci_unmap_len_set(&out_cmd->meta, len, fix_size); 1024 pci_unmap_len_set(out_meta, len, fix_size);
1002 1025
1003 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq, 1026 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1004 phys_addr, fix_size, 1, 1027 phys_addr, fix_size, 1,
@@ -1067,8 +1090,8 @@ static void iwl_hcmd_queue_reclaim(struct iwl_priv *priv, int txq_id,
1067 } 1090 }
1068 1091
1069 pci_unmap_single(priv->pci_dev, 1092 pci_unmap_single(priv->pci_dev,
1070 pci_unmap_addr(&txq->cmd[cmd_idx]->meta, mapping), 1093 pci_unmap_addr(&txq->meta[cmd_idx], mapping),
1071 pci_unmap_len(&txq->cmd[cmd_idx]->meta, len), 1094 pci_unmap_len(&txq->meta[cmd_idx], len),
1072 PCI_DMA_BIDIRECTIONAL); 1095 PCI_DMA_BIDIRECTIONAL);
1073 1096
1074 for (idx = iwl_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx; 1097 for (idx = iwl_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx;
@@ -1099,7 +1122,8 @@ void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1099 int index = SEQ_TO_INDEX(sequence); 1122 int index = SEQ_TO_INDEX(sequence);
1100 int cmd_index; 1123 int cmd_index;
1101 bool huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME); 1124 bool huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
1102 struct iwl_cmd *cmd; 1125 struct iwl_device_cmd *cmd;
1126 struct iwl_cmd_meta *meta;
1103 1127
1104 /* If a Tx command is being handled and it isn't in the actual 1128 /* If a Tx command is being handled and it isn't in the actual
1105 * command queue then there a command routing bug has been introduced 1129 * command queue then there a command routing bug has been introduced
@@ -1109,24 +1133,24 @@ void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1109 txq_id, sequence, 1133 txq_id, sequence,
1110 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr, 1134 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1111 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) { 1135 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1112 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32); 1136 iwl_print_hex_error(priv, pkt, 32);
1113 return; 1137 return;
1114 } 1138 }
1115 1139
1116 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); 1140 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1117 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; 1141 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
1142 meta = &priv->txq[IWL_CMD_QUEUE_NUM].meta[cmd_index];
1118 1143
1119 /* Input error checking is done when commands are added to queue. */ 1144 /* Input error checking is done when commands are added to queue. */
1120 if (cmd->meta.flags & CMD_WANT_SKB) { 1145 if (meta->flags & CMD_WANT_SKB) {
1121 cmd->meta.source->u.skb = rxb->skb; 1146 meta->source->reply_skb = rxb->skb;
1122 rxb->skb = NULL;
1123 } else if (cmd->meta.u.callback &&
1124 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1125 rxb->skb = NULL; 1147 rxb->skb = NULL;
1148 } else if (meta->callback)
1149 meta->callback(priv, cmd, rxb->skb);
1126 1150
1127 iwl_hcmd_queue_reclaim(priv, txq_id, index, cmd_index); 1151 iwl_hcmd_queue_reclaim(priv, txq_id, index, cmd_index);
1128 1152
1129 if (!(cmd->meta.flags & CMD_ASYNC)) { 1153 if (!(meta->flags & CMD_ASYNC)) {
1130 clear_bit(STATUS_HCMD_ACTIVE, &priv->status); 1154 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1131 wake_up_interruptible(&priv->wait_command_queue); 1155 wake_up_interruptible(&priv->wait_command_queue);
1132 } 1156 }
@@ -1189,6 +1213,7 @@ int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
1189 tid_data = &priv->stations[sta_id].tid[tid]; 1213 tid_data = &priv->stations[sta_id].tid[tid];
1190 *ssn = SEQ_TO_SN(tid_data->seq_number); 1214 *ssn = SEQ_TO_SN(tid_data->seq_number);
1191 tid_data->agg.txq_id = txq_id; 1215 tid_data->agg.txq_id = txq_id;
1216 priv->txq[txq_id].swq_id = iwl_virtual_agg_queue_num(tx_fifo, txq_id);
1192 spin_unlock_irqrestore(&priv->sta_lock, flags); 1217 spin_unlock_irqrestore(&priv->sta_lock, flags);
1193 1218
1194 ret = priv->cfg->ops->lib->txq_agg_enable(priv, txq_id, tx_fifo, 1219 ret = priv->cfg->ops->lib->txq_agg_enable(priv, txq_id, tx_fifo,