aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c16
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c25
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.h5
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965-hw.h7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965-rs.c169
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965-rs.h8
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c1019
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c897
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-calib.c27
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-calib.h9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h243
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c327
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h56
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-csr.h6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debug.h10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debugfs.c55
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h152
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.c28
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-hcmd.c8
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-helpers.h21
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-prph.h39
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rx.c48
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c501
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.h7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c1058
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c90
-rw-r--r--drivers/net/wireless/iwlwifi/iwl4965-base.c1670
28 files changed, 3994 insertions, 2508 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index e51eeeff6992..10c64bdb314c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -445,8 +445,7 @@ static int rs_adjust_next_rate(struct iwl3945_priv *priv, int rate)
445 */ 445 */
446static void rs_tx_status(void *priv_rate, 446static void rs_tx_status(void *priv_rate,
447 struct net_device *dev, 447 struct net_device *dev,
448 struct sk_buff *skb, 448 struct sk_buff *skb)
449 struct ieee80211_tx_status *tx_resp)
450{ 449{
451 u8 retries, current_count; 450 u8 retries, current_count;
452 int scale_rate_index, first_index, last_index; 451 int scale_rate_index, first_index, last_index;
@@ -457,14 +456,15 @@ static void rs_tx_status(void *priv_rate,
457 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 456 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
458 struct iwl3945_rs_sta *rs_sta; 457 struct iwl3945_rs_sta *rs_sta;
459 struct ieee80211_supported_band *sband; 458 struct ieee80211_supported_band *sband;
459 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
460 460
461 IWL_DEBUG_RATE("enter\n"); 461 IWL_DEBUG_RATE("enter\n");
462 462
463 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 463 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
464 464
465 465
466 retries = tx_resp->retry_count; 466 retries = info->status.retry_count;
467 first_index = tx_resp->control.tx_rate->hw_value; 467 first_index = sband->bitrates[info->tx_rate_idx].hw_value;
468 if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) { 468 if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) {
469 IWL_DEBUG_RATE("leave: Rate out of bounds: %d\n", first_index); 469 IWL_DEBUG_RATE("leave: Rate out of bounds: %d\n", first_index);
470 return; 470 return;
@@ -525,11 +525,11 @@ static void rs_tx_status(void *priv_rate,
525 /* Update the last index window with success/failure based on ACK */ 525 /* Update the last index window with success/failure based on ACK */
526 IWL_DEBUG_RATE("Update rate %d with %s.\n", 526 IWL_DEBUG_RATE("Update rate %d with %s.\n",
527 last_index, 527 last_index,
528 (tx_resp->flags & IEEE80211_TX_STATUS_ACK) ? 528 (info->flags & IEEE80211_TX_STAT_ACK) ?
529 "success" : "failure"); 529 "success" : "failure");
530 iwl3945_collect_tx_data(rs_sta, 530 iwl3945_collect_tx_data(rs_sta,
531 &rs_sta->win[last_index], 531 &rs_sta->win[last_index],
532 tx_resp->flags & IEEE80211_TX_STATUS_ACK, 1); 532 info->flags & IEEE80211_TX_STAT_ACK, 1);
533 533
534 /* We updated the rate scale window -- if its been more than 534 /* We updated the rate scale window -- if its been more than
535 * flush_time since the last run, schedule the flush 535 * flush_time since the last run, schedule the flush
@@ -669,7 +669,7 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
669 is_multicast_ether_addr(hdr->addr1) || 669 is_multicast_ether_addr(hdr->addr1) ||
670 !sta || !sta->rate_ctrl_priv) { 670 !sta || !sta->rate_ctrl_priv) {
671 IWL_DEBUG_RATE("leave: No STA priv data to update!\n"); 671 IWL_DEBUG_RATE("leave: No STA priv data to update!\n");
672 sel->rate = rate_lowest(local, sband, sta); 672 sel->rate_idx = rate_lowest_index(local, sband, sta);
673 rcu_read_unlock(); 673 rcu_read_unlock();
674 return; 674 return;
675 } 675 }
@@ -813,7 +813,7 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
813 813
814 IWL_DEBUG_RATE("leave: %d\n", index); 814 IWL_DEBUG_RATE("leave: %d\n", index);
815 815
816 sel->rate = &sband->bitrates[sta->txrate_idx]; 816 sel->rate_idx = sta->txrate_idx;
817} 817}
818 818
819static struct rate_control_ops rs_ops = { 819static struct rate_control_ops rs_ops = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index ad4e7b74ca24..0ba6889dfd41 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -283,8 +283,7 @@ static void iwl3945_tx_queue_reclaim(struct iwl3945_priv *priv,
283 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { 283 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
284 284
285 tx_info = &txq->txb[txq->q.read_ptr]; 285 tx_info = &txq->txb[txq->q.read_ptr];
286 ieee80211_tx_status_irqsafe(priv->hw, tx_info->skb[0], 286 ieee80211_tx_status_irqsafe(priv->hw, tx_info->skb[0]);
287 &tx_info->status);
288 tx_info->skb[0] = NULL; 287 tx_info->skb[0] = NULL;
289 iwl3945_hw_txq_free_tfd(priv, txq); 288 iwl3945_hw_txq_free_tfd(priv, txq);
290 } 289 }
@@ -306,7 +305,7 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
306 int txq_id = SEQ_TO_QUEUE(sequence); 305 int txq_id = SEQ_TO_QUEUE(sequence);
307 int index = SEQ_TO_INDEX(sequence); 306 int index = SEQ_TO_INDEX(sequence);
308 struct iwl3945_tx_queue *txq = &priv->txq[txq_id]; 307 struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
309 struct ieee80211_tx_status *tx_status; 308 struct ieee80211_tx_info *info;
310 struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; 309 struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
311 u32 status = le32_to_cpu(tx_resp->status); 310 u32 status = le32_to_cpu(tx_resp->status);
312 int rate_idx; 311 int rate_idx;
@@ -319,19 +318,22 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
319 return; 318 return;
320 } 319 }
321 320
322 tx_status = &(txq->txb[txq->q.read_ptr].status); 321 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
322 memset(&info->status, 0, sizeof(info->status));
323 323
324 tx_status->retry_count = tx_resp->failure_frame; 324 info->status.retry_count = tx_resp->failure_frame;
325 /* tx_status->rts_retry_count = tx_resp->failure_rts; */ 325 /* tx_status->rts_retry_count = tx_resp->failure_rts; */
326 tx_status->flags = ((status & TX_STATUS_MSK) == TX_STATUS_SUCCESS) ? 326 info->flags |= ((status & TX_STATUS_MSK) == TX_STATUS_SUCCESS) ?
327 IEEE80211_TX_STATUS_ACK : 0; 327 IEEE80211_TX_STAT_ACK : 0;
328 328
329 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n", 329 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
330 txq_id, iwl3945_get_tx_fail_reason(status), status, 330 txq_id, iwl3945_get_tx_fail_reason(status), status,
331 tx_resp->rate, tx_resp->failure_frame); 331 tx_resp->rate, tx_resp->failure_frame);
332 332
333 rate_idx = iwl3945_hwrate_to_plcp_idx(tx_resp->rate); 333 rate_idx = iwl3945_hwrate_to_plcp_idx(tx_resp->rate);
334 tx_status->control.tx_rate = &priv->ieee_rates[rate_idx]; 334 if (info->band == IEEE80211_BAND_5GHZ)
335 rate_idx -= IWL_FIRST_OFDM_RATE;
336 info->tx_rate_idx = rate_idx;
335 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); 337 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
336 iwl3945_tx_queue_reclaim(priv, txq_id, index); 338 iwl3945_tx_queue_reclaim(priv, txq_id, index);
337 339
@@ -958,11 +960,12 @@ u8 iwl3945_hw_find_station(struct iwl3945_priv *priv, const u8 *addr)
958*/ 960*/
959void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv, 961void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv,
960 struct iwl3945_cmd *cmd, 962 struct iwl3945_cmd *cmd,
961 struct ieee80211_tx_control *ctrl, 963 struct ieee80211_tx_info *info,
962 struct ieee80211_hdr *hdr, int sta_id, int tx_id) 964 struct ieee80211_hdr *hdr, int sta_id, int tx_id)
963{ 965{
964 unsigned long flags; 966 unsigned long flags;
965 u16 rate_index = min(ctrl->tx_rate->hw_value & 0xffff, IWL_RATE_COUNT - 1); 967 u16 hw_value = ieee80211_get_tx_rate(priv->hw, info)->hw_value;
968 u16 rate_index = min(hw_value & 0xffff, IWL_RATE_COUNT - 1);
966 u16 rate_mask; 969 u16 rate_mask;
967 int rate; 970 int rate;
968 u8 rts_retry_limit; 971 u8 rts_retry_limit;
@@ -974,7 +977,7 @@ void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv,
974 tx_flags = cmd->cmd.tx.tx_flags; 977 tx_flags = cmd->cmd.tx.tx_flags;
975 978
976 /* We need to figure out how to get the sta->supp_rates while 979 /* We need to figure out how to get the sta->supp_rates while
977 * in this running context; perhaps encoding into ctrl->tx_rate? */ 980 * in this running context */
978 rate_mask = IWL_RATES_MASK; 981 rate_mask = IWL_RATES_MASK;
979 982
980 spin_lock_irqsave(&priv->sta_lock, flags); 983 spin_lock_irqsave(&priv->sta_lock, flags);
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.h b/drivers/net/wireless/iwlwifi/iwl-3945.h
index 9fdc1405e853..a9b3edad3868 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.h
@@ -124,7 +124,6 @@ int iwl3945_x2_queue_used(const struct iwl3945_queue *q, int i);
124 124
125/* One for each TFD */ 125/* One for each TFD */
126struct iwl3945_tx_info { 126struct iwl3945_tx_info {
127 struct ieee80211_tx_status status;
128 struct sk_buff *skb[MAX_NUM_OF_TBS]; 127 struct sk_buff *skb[MAX_NUM_OF_TBS];
129}; 128};
130 129
@@ -645,7 +644,7 @@ extern unsigned int iwl3945_hw_get_beacon_cmd(struct iwl3945_priv *priv,
645extern int iwl3945_hw_get_rx_read(struct iwl3945_priv *priv); 644extern int iwl3945_hw_get_rx_read(struct iwl3945_priv *priv);
646extern void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv, 645extern void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv,
647 struct iwl3945_cmd *cmd, 646 struct iwl3945_cmd *cmd,
648 struct ieee80211_tx_control *ctrl, 647 struct ieee80211_tx_info *info,
649 struct ieee80211_hdr *hdr, 648 struct ieee80211_hdr *hdr,
650 int sta_id, int tx_id); 649 int sta_id, int tx_id);
651extern int iwl3945_hw_reg_send_txpower(struct iwl3945_priv *priv); 650extern int iwl3945_hw_reg_send_txpower(struct iwl3945_priv *priv);
@@ -836,8 +835,6 @@ struct iwl3945_priv {
836 835
837 u8 mac80211_registered; 836 u8 mac80211_registered;
838 837
839 u32 notif_missed_beacons;
840
841 /* Rx'd packet timing information */ 838 /* Rx'd packet timing information */
842 u32 last_beacon_time; 839 u32 last_beacon_time;
843 u64 last_tsf; 840 u64 last_tsf;
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-hw.h b/drivers/net/wireless/iwlwifi/iwl-4965-hw.h
index ee55b283226b..fc118335b60f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-hw.h
+++ b/drivers/net/wireless/iwlwifi/iwl-4965-hw.h
@@ -100,9 +100,14 @@
100 100
101#include "iwl-commands.h" 101#include "iwl-commands.h"
102 102
103#define PCI_LINK_CTRL 0x0F0 103/* PCI registers */
104#define PCI_LINK_CTRL 0x0F0 /* 1 byte */
104#define PCI_POWER_SOURCE 0x0C8 105#define PCI_POWER_SOURCE 0x0C8
105#define PCI_REG_WUM8 0x0E8 106#define PCI_REG_WUM8 0x0E8
107
108/* PCI register values */
109#define PCI_LINK_VAL_L0S_EN 0x01
110#define PCI_LINK_VAL_L1_EN 0x02
106#define PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT (0x80000000) 111#define PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT (0x80000000)
107 112
108#define TFD_QUEUE_SIZE_MAX (256) 113#define TFD_QUEUE_SIZE_MAX (256)
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-rs.c b/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
index 8e3660ebba7d..a955f9c1b9ee 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
@@ -282,14 +282,20 @@ static void rs_tl_rm_old_stats(struct iwl4965_traffic_load *tl, u32 curr_time)
282 * increment traffic load value for tid and also remove 282 * increment traffic load value for tid and also remove
283 * any old values if passed the certain time period 283 * any old values if passed the certain time period
284 */ 284 */
285static void rs_tl_add_packet(struct iwl4965_lq_sta *lq_data, u8 tid) 285static void rs_tl_add_packet(struct iwl4965_lq_sta *lq_data,
286 struct ieee80211_hdr *hdr)
286{ 287{
287 u32 curr_time = jiffies_to_msecs(jiffies); 288 u32 curr_time = jiffies_to_msecs(jiffies);
288 u32 time_diff; 289 u32 time_diff;
289 s32 index; 290 s32 index;
290 struct iwl4965_traffic_load *tl = NULL; 291 struct iwl4965_traffic_load *tl = NULL;
292 u16 fc = le16_to_cpu(hdr->frame_control);
293 u8 tid;
291 294
292 if (tid >= TID_MAX_LOAD_COUNT) 295 if (ieee80211_is_qos_data(fc)) {
296 u8 *qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
297 tid = qc[0] & 0xf;
298 } else
293 return; 299 return;
294 300
295 tl = &lq_data->load[tid]; 301 tl = &lq_data->load[tid];
@@ -481,7 +487,7 @@ static u32 rate_n_flags_from_tbl(struct iwl4965_scale_tbl_info *tbl,
481 u32 rate_n_flags = 0; 487 u32 rate_n_flags = 0;
482 488
483 if (is_legacy(tbl->lq_type)) { 489 if (is_legacy(tbl->lq_type)) {
484 rate_n_flags = iwl4965_rates[index].plcp; 490 rate_n_flags = iwl_rates[index].plcp;
485 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE) 491 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
486 rate_n_flags |= RATE_MCS_CCK_MSK; 492 rate_n_flags |= RATE_MCS_CCK_MSK;
487 493
@@ -493,11 +499,11 @@ static u32 rate_n_flags_from_tbl(struct iwl4965_scale_tbl_info *tbl,
493 rate_n_flags = RATE_MCS_HT_MSK; 499 rate_n_flags = RATE_MCS_HT_MSK;
494 500
495 if (is_siso(tbl->lq_type)) 501 if (is_siso(tbl->lq_type))
496 rate_n_flags |= iwl4965_rates[index].plcp_siso; 502 rate_n_flags |= iwl_rates[index].plcp_siso;
497 else if (is_mimo2(tbl->lq_type)) 503 else if (is_mimo2(tbl->lq_type))
498 rate_n_flags |= iwl4965_rates[index].plcp_mimo2; 504 rate_n_flags |= iwl_rates[index].plcp_mimo2;
499 else 505 else
500 rate_n_flags |= iwl4965_rates[index].plcp_mimo3; 506 rate_n_flags |= iwl_rates[index].plcp_mimo3;
501 } else { 507 } else {
502 IWL_ERROR("Invalid tbl->lq_type %d\n", tbl->lq_type); 508 IWL_ERROR("Invalid tbl->lq_type %d\n", tbl->lq_type);
503 } 509 }
@@ -697,7 +703,7 @@ static u16 rs_get_adjacent_rate(struct iwl_priv *priv, u8 index, u16 rate_mask,
697 703
698 low = index; 704 low = index;
699 while (low != IWL_RATE_INVALID) { 705 while (low != IWL_RATE_INVALID) {
700 low = iwl4965_rates[low].prev_rs; 706 low = iwl_rates[low].prev_rs;
701 if (low == IWL_RATE_INVALID) 707 if (low == IWL_RATE_INVALID)
702 break; 708 break;
703 if (rate_mask & (1 << low)) 709 if (rate_mask & (1 << low))
@@ -707,7 +713,7 @@ static u16 rs_get_adjacent_rate(struct iwl_priv *priv, u8 index, u16 rate_mask,
707 713
708 high = index; 714 high = index;
709 while (high != IWL_RATE_INVALID) { 715 while (high != IWL_RATE_INVALID) {
710 high = iwl4965_rates[high].next_rs; 716 high = iwl_rates[high].next_rs;
711 if (high == IWL_RATE_INVALID) 717 if (high == IWL_RATE_INVALID)
712 break; 718 break;
713 if (rate_mask & (1 << high)) 719 if (rate_mask & (1 << high))
@@ -779,8 +785,7 @@ out:
779 * mac80211 sends us Tx status 785 * mac80211 sends us Tx status
780 */ 786 */
781static void rs_tx_status(void *priv_rate, struct net_device *dev, 787static void rs_tx_status(void *priv_rate, struct net_device *dev,
782 struct sk_buff *skb, 788 struct sk_buff *skb)
783 struct ieee80211_tx_status *tx_resp)
784{ 789{
785 int status; 790 int status;
786 u8 retries; 791 u8 retries;
@@ -792,6 +797,7 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
792 struct iwl_priv *priv = (struct iwl_priv *)priv_rate; 797 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
793 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 798 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
794 struct ieee80211_hw *hw = local_to_hw(local); 799 struct ieee80211_hw *hw = local_to_hw(local);
800 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
795 struct iwl4965_rate_scale_data *window = NULL; 801 struct iwl4965_rate_scale_data *window = NULL;
796 struct iwl4965_rate_scale_data *search_win = NULL; 802 struct iwl4965_rate_scale_data *search_win = NULL;
797 u32 tx_rate; 803 u32 tx_rate;
@@ -807,11 +813,11 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
807 return; 813 return;
808 814
809 /* This packet was aggregated but doesn't carry rate scale info */ 815 /* This packet was aggregated but doesn't carry rate scale info */
810 if ((tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) && 816 if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
811 !(tx_resp->flags & IEEE80211_TX_STATUS_AMPDU)) 817 !(info->flags & IEEE80211_TX_STAT_AMPDU))
812 return; 818 return;
813 819
814 retries = tx_resp->retry_count; 820 retries = info->status.retry_count;
815 821
816 if (retries > 15) 822 if (retries > 15)
817 retries = 15; 823 retries = 15;
@@ -856,20 +862,20 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
856 if (priv->band == IEEE80211_BAND_5GHZ) 862 if (priv->band == IEEE80211_BAND_5GHZ)
857 rs_index -= IWL_FIRST_OFDM_RATE; 863 rs_index -= IWL_FIRST_OFDM_RATE;
858 864
859 if ((tx_resp->control.tx_rate == NULL) || 865 if ((info->tx_rate_idx < 0) ||
860 (tbl_type.is_SGI ^ 866 (tbl_type.is_SGI ^
861 !!(tx_resp->control.flags & IEEE80211_TXCTL_SHORT_GI)) || 867 !!(info->flags & IEEE80211_TX_CTL_SHORT_GI)) ||
862 (tbl_type.is_fat ^ 868 (tbl_type.is_fat ^
863 !!(tx_resp->control.flags & IEEE80211_TXCTL_40_MHZ_WIDTH)) || 869 !!(info->flags & IEEE80211_TX_CTL_40_MHZ_WIDTH)) ||
864 (tbl_type.is_dup ^ 870 (tbl_type.is_dup ^
865 !!(tx_resp->control.flags & IEEE80211_TXCTL_DUP_DATA)) || 871 !!(info->flags & IEEE80211_TX_CTL_DUP_DATA)) ||
866 (tbl_type.ant_type ^ tx_resp->control.antenna_sel_tx) || 872 (tbl_type.ant_type ^ info->antenna_sel_tx) ||
867 (!!(tx_rate & RATE_MCS_HT_MSK) ^ 873 (!!(tx_rate & RATE_MCS_HT_MSK) ^
868 !!(tx_resp->control.flags & IEEE80211_TXCTL_OFDM_HT)) || 874 !!(info->flags & IEEE80211_TX_CTL_OFDM_HT)) ||
869 (!!(tx_rate & RATE_MCS_GF_MSK) ^ 875 (!!(tx_rate & RATE_MCS_GF_MSK) ^
870 !!(tx_resp->control.flags & IEEE80211_TXCTL_GREEN_FIELD)) || 876 !!(info->flags & IEEE80211_TX_CTL_GREEN_FIELD)) ||
871 (hw->wiphy->bands[priv->band]->bitrates[rs_index].bitrate != 877 (hw->wiphy->bands[priv->band]->bitrates[rs_index].bitrate !=
872 tx_resp->control.tx_rate->bitrate)) { 878 hw->wiphy->bands[info->band]->bitrates[info->tx_rate_idx].bitrate)) {
873 IWL_DEBUG_RATE("initial rate does not match 0x%x\n", tx_rate); 879 IWL_DEBUG_RATE("initial rate does not match 0x%x\n", tx_rate);
874 goto out; 880 goto out;
875 } 881 }
@@ -923,10 +929,7 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
923 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index); 929 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
924 930
925 /* Update frame history window with "success" if Tx got ACKed ... */ 931 /* Update frame history window with "success" if Tx got ACKed ... */
926 if (tx_resp->flags & IEEE80211_TX_STATUS_ACK) 932 status = !!(info->flags & IEEE80211_TX_STAT_ACK);
927 status = 1;
928 else
929 status = 0;
930 933
931 /* If type matches "search" table, 934 /* If type matches "search" table,
932 * add final tx status to "search" history */ 935 * add final tx status to "search" history */
@@ -937,10 +940,10 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
937 tpt = search_tbl->expected_tpt[rs_index]; 940 tpt = search_tbl->expected_tpt[rs_index];
938 else 941 else
939 tpt = 0; 942 tpt = 0;
940 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) 943 if (info->flags & IEEE80211_TX_CTL_AMPDU)
941 rs_collect_tx_data(search_win, rs_index, tpt, 944 rs_collect_tx_data(search_win, rs_index, tpt,
942 tx_resp->ampdu_ack_len, 945 info->status.ampdu_ack_len,
943 tx_resp->ampdu_ack_map); 946 info->status.ampdu_ack_map);
944 else 947 else
945 rs_collect_tx_data(search_win, rs_index, tpt, 948 rs_collect_tx_data(search_win, rs_index, tpt,
946 1, status); 949 1, status);
@@ -953,10 +956,10 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
953 tpt = curr_tbl->expected_tpt[rs_index]; 956 tpt = curr_tbl->expected_tpt[rs_index];
954 else 957 else
955 tpt = 0; 958 tpt = 0;
956 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) 959 if (info->flags & IEEE80211_TX_CTL_AMPDU)
957 rs_collect_tx_data(window, rs_index, tpt, 960 rs_collect_tx_data(window, rs_index, tpt,
958 tx_resp->ampdu_ack_len, 961 info->status.ampdu_ack_len,
959 tx_resp->ampdu_ack_map); 962 info->status.ampdu_ack_map);
960 else 963 else
961 rs_collect_tx_data(window, rs_index, tpt, 964 rs_collect_tx_data(window, rs_index, tpt,
962 1, status); 965 1, status);
@@ -965,10 +968,10 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
965 /* If not searching for new mode, increment success/failed counter 968 /* If not searching for new mode, increment success/failed counter
966 * ... these help determine when to start searching again */ 969 * ... these help determine when to start searching again */
967 if (lq_sta->stay_in_tbl) { 970 if (lq_sta->stay_in_tbl) {
968 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) { 971 if (info->flags & IEEE80211_TX_CTL_AMPDU) {
969 lq_sta->total_success += tx_resp->ampdu_ack_map; 972 lq_sta->total_success += info->status.ampdu_ack_map;
970 lq_sta->total_failed += 973 lq_sta->total_failed +=
971 (tx_resp->ampdu_ack_len - tx_resp->ampdu_ack_map); 974 (info->status.ampdu_ack_len - info->status.ampdu_ack_map);
972 } else { 975 } else {
973 if (status) 976 if (status)
974 lq_sta->total_success++; 977 lq_sta->total_success++;
@@ -1333,7 +1336,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1333 lq_sta->search_better_tbl = 1; 1336 lq_sta->search_better_tbl = 1;
1334 goto out; 1337 goto out;
1335 } 1338 }
1336 1339 break;
1337 case IWL_LEGACY_SWITCH_SISO: 1340 case IWL_LEGACY_SWITCH_SISO:
1338 IWL_DEBUG_RATE("LQ: Legacy switch to SISO\n"); 1341 IWL_DEBUG_RATE("LQ: Legacy switch to SISO\n");
1339 1342
@@ -1419,9 +1422,9 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1419 lq_sta->search_better_tbl = 1; 1422 lq_sta->search_better_tbl = 1;
1420 goto out; 1423 goto out;
1421 } 1424 }
1422 1425 break;
1423 case IWL_SISO_SWITCH_MIMO2: 1426 case IWL_SISO_SWITCH_MIMO2:
1424 IWL_DEBUG_RATE("LQ: SISO switch to MIMO\n"); 1427 IWL_DEBUG_RATE("LQ: SISO switch to MIMO2\n");
1425 memcpy(search_tbl, tbl, sz); 1428 memcpy(search_tbl, tbl, sz);
1426 search_tbl->is_SGI = 0; 1429 search_tbl->is_SGI = 0;
1427 search_tbl->ant_type = ANT_AB; /*FIXME:RS*/ 1430 search_tbl->ant_type = ANT_AB; /*FIXME:RS*/
@@ -1433,6 +1436,15 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1433 } 1436 }
1434 break; 1437 break;
1435 case IWL_SISO_SWITCH_GI: 1438 case IWL_SISO_SWITCH_GI:
1439 if (!tbl->is_fat &&
1440 !(priv->current_ht_config.sgf &
1441 HT_SHORT_GI_20MHZ))
1442 break;
1443 if (tbl->is_fat &&
1444 !(priv->current_ht_config.sgf &
1445 HT_SHORT_GI_40MHZ))
1446 break;
1447
1436 IWL_DEBUG_RATE("LQ: SISO toggle SGI/NGI\n"); 1448 IWL_DEBUG_RATE("LQ: SISO toggle SGI/NGI\n");
1437 1449
1438 memcpy(search_tbl, tbl, sz); 1450 memcpy(search_tbl, tbl, sz);
@@ -1515,6 +1527,15 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1515 break; 1527 break;
1516 1528
1517 case IWL_MIMO_SWITCH_GI: 1529 case IWL_MIMO_SWITCH_GI:
1530 if (!tbl->is_fat &&
1531 !(priv->current_ht_config.sgf &
1532 HT_SHORT_GI_20MHZ))
1533 break;
1534 if (tbl->is_fat &&
1535 !(priv->current_ht_config.sgf &
1536 HT_SHORT_GI_40MHZ))
1537 break;
1538
1518 IWL_DEBUG_RATE("LQ: MIMO toggle SGI/NGI\n"); 1539 IWL_DEBUG_RATE("LQ: MIMO toggle SGI/NGI\n");
1519 1540
1520 /* Set up new search table for MIMO */ 1541 /* Set up new search table for MIMO */
@@ -1668,9 +1689,9 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1668 u8 active_tbl = 0; 1689 u8 active_tbl = 0;
1669 u8 done_search = 0; 1690 u8 done_search = 0;
1670 u16 high_low; 1691 u16 high_low;
1692 s32 sr;
1671#ifdef CONFIG_IWL4965_HT 1693#ifdef CONFIG_IWL4965_HT
1672 u8 tid = MAX_TID_COUNT; 1694 u8 tid = MAX_TID_COUNT;
1673 __le16 *qc;
1674#endif 1695#endif
1675 1696
1676 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n"); 1697 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
@@ -1693,11 +1714,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1693 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv; 1714 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
1694 1715
1695#ifdef CONFIG_IWL4965_HT 1716#ifdef CONFIG_IWL4965_HT
1696 qc = ieee80211_get_qos_ctrl(hdr); 1717 rs_tl_add_packet(lq_sta, hdr);
1697 if (qc) {
1698 tid = (u8)(le16_to_cpu(*qc) & 0xf);
1699 rs_tl_add_packet(lq_sta, tid);
1700 }
1701#endif 1718#endif
1702 /* 1719 /*
1703 * Select rate-scale / modulation-mode table to work with in 1720 * Select rate-scale / modulation-mode table to work with in
@@ -1848,6 +1865,8 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1848 low = high_low & 0xff; 1865 low = high_low & 0xff;
1849 high = (high_low >> 8) & 0xff; 1866 high = (high_low >> 8) & 0xff;
1850 1867
1868 sr = window->success_ratio;
1869
1851 /* Collect measured throughputs for current and adjacent rates */ 1870 /* Collect measured throughputs for current and adjacent rates */
1852 current_tpt = window->average_tpt; 1871 current_tpt = window->average_tpt;
1853 if (low != IWL_RATE_INVALID) 1872 if (low != IWL_RATE_INVALID)
@@ -1855,19 +1874,22 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1855 if (high != IWL_RATE_INVALID) 1874 if (high != IWL_RATE_INVALID)
1856 high_tpt = tbl->win[high].average_tpt; 1875 high_tpt = tbl->win[high].average_tpt;
1857 1876
1858 /* Assume rate increase */ 1877 scale_action = 0;
1859 scale_action = 1;
1860 1878
1861 /* Too many failures, decrease rate */ 1879 /* Too many failures, decrease rate */
1862 if ((window->success_ratio <= IWL_RATE_DECREASE_TH) || 1880 if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) {
1863 (current_tpt == 0)) {
1864 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n"); 1881 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
1865 scale_action = -1; 1882 scale_action = -1;
1866 1883
1867 /* No throughput measured yet for adjacent rates; try increase. */ 1884 /* No throughput measured yet for adjacent rates; try increase. */
1868 } else if ((low_tpt == IWL_INVALID_VALUE) && 1885 } else if ((low_tpt == IWL_INVALID_VALUE) &&
1869 (high_tpt == IWL_INVALID_VALUE)) 1886 (high_tpt == IWL_INVALID_VALUE)) {
1870 scale_action = 1; 1887
1888 if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH)
1889 scale_action = 1;
1890 else if (low != IWL_RATE_INVALID)
1891 scale_action = -1;
1892 }
1871 1893
1872 /* Both adjacent throughputs are measured, but neither one has better 1894 /* Both adjacent throughputs are measured, but neither one has better
1873 * throughput; we're using the best rate, don't change it! */ 1895 * throughput; we're using the best rate, don't change it! */
@@ -1883,9 +1905,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1883 /* Higher adjacent rate's throughput is measured */ 1905 /* Higher adjacent rate's throughput is measured */
1884 if (high_tpt != IWL_INVALID_VALUE) { 1906 if (high_tpt != IWL_INVALID_VALUE) {
1885 /* Higher rate has better throughput */ 1907 /* Higher rate has better throughput */
1886 if (high_tpt > current_tpt) 1908 if (high_tpt > current_tpt &&
1909 sr >= IWL_RATE_INCREASE_TH) {
1887 scale_action = 1; 1910 scale_action = 1;
1888 else { 1911 } else {
1889 IWL_DEBUG_RATE 1912 IWL_DEBUG_RATE
1890 ("decrease rate because of high tpt\n"); 1913 ("decrease rate because of high tpt\n");
1891 scale_action = -1; 1914 scale_action = -1;
@@ -1898,23 +1921,17 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1898 IWL_DEBUG_RATE 1921 IWL_DEBUG_RATE
1899 ("decrease rate because of low tpt\n"); 1922 ("decrease rate because of low tpt\n");
1900 scale_action = -1; 1923 scale_action = -1;
1901 } else 1924 } else if (sr >= IWL_RATE_INCREASE_TH) {
1902 scale_action = 1; 1925 scale_action = 1;
1926 }
1903 } 1927 }
1904 } 1928 }
1905 1929
1906 /* Sanity check; asked for decrease, but success rate or throughput 1930 /* Sanity check; asked for decrease, but success rate or throughput
1907 * has been good at old rate. Don't change it. */ 1931 * has been good at old rate. Don't change it. */
1908 if (scale_action == -1) { 1932 if ((scale_action == -1) && (low != IWL_RATE_INVALID) &&
1909 if ((low != IWL_RATE_INVALID) && 1933 ((sr > IWL_RATE_HIGH_TH) ||
1910 ((window->success_ratio > IWL_RATE_HIGH_TH) ||
1911 (current_tpt > (100 * tbl->expected_tpt[low])))) 1934 (current_tpt > (100 * tbl->expected_tpt[low]))))
1912 scale_action = 0;
1913
1914 /* Sanity check; asked for increase, but success rate has not been great
1915 * even at old rate, higher rate will be worse. Don't change it. */
1916 } else if ((scale_action == 1) &&
1917 (window->success_ratio < IWL_RATE_INCREASE_TH))
1918 scale_action = 0; 1935 scale_action = 0;
1919 1936
1920 switch (scale_action) { 1937 switch (scale_action) {
@@ -1943,7 +1960,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1943 "high %d type %d\n", 1960 "high %d type %d\n",
1944 index, scale_action, low, high, tbl->lq_type); 1961 index, scale_action, low, high, tbl->lq_type);
1945 1962
1946 lq_update: 1963lq_update:
1947 /* Replace uCode's rate table for the destination station. */ 1964 /* Replace uCode's rate table for the destination station. */
1948 if (update_lq) { 1965 if (update_lq) {
1949 rate = rate_n_flags_from_tbl(tbl, index, is_green); 1966 rate = rate_n_flags_from_tbl(tbl, index, is_green);
@@ -2088,7 +2105,7 @@ static void rs_initialize_lq(struct iwl_priv *priv,
2088 i = 0; 2105 i = 0;
2089 2106
2090 /* FIXME:RS: This is also wrong in 4965 */ 2107 /* FIXME:RS: This is also wrong in 4965 */
2091 rate = iwl4965_rates[i].plcp; 2108 rate = iwl_rates[i].plcp;
2092 rate |= RATE_MCS_ANT_B_MSK; 2109 rate |= RATE_MCS_ANT_B_MSK;
2093 rate &= ~RATE_MCS_ANT_A_MSK; 2110 rate &= ~RATE_MCS_ANT_A_MSK;
2094 2111
@@ -2135,7 +2152,7 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
2135 fc = le16_to_cpu(hdr->frame_control); 2152 fc = le16_to_cpu(hdr->frame_control);
2136 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1) || 2153 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1) ||
2137 !sta || !sta->rate_ctrl_priv) { 2154 !sta || !sta->rate_ctrl_priv) {
2138 sel->rate = rate_lowest(local, sband, sta); 2155 sel->rate_idx = rate_lowest_index(local, sband, sta);
2139 goto out; 2156 goto out;
2140 } 2157 }
2141 2158
@@ -2150,7 +2167,7 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
2150 if (sta_id == IWL_INVALID_STATION) { 2167 if (sta_id == IWL_INVALID_STATION) {
2151 IWL_DEBUG_RATE("LQ: ADD station %s\n", 2168 IWL_DEBUG_RATE("LQ: ADD station %s\n",
2152 print_mac(mac, hdr->addr1)); 2169 print_mac(mac, hdr->addr1));
2153 sta_id = iwl4965_add_station_flags(priv, hdr->addr1, 2170 sta_id = iwl_add_station_flags(priv, hdr->addr1,
2154 0, CMD_ASYNC, NULL); 2171 0, CMD_ASYNC, NULL);
2155 } 2172 }
2156 if ((sta_id != IWL_INVALID_STATION)) { 2173 if ((sta_id != IWL_INVALID_STATION)) {
@@ -2165,11 +2182,13 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
2165 2182
2166done: 2183done:
2167 if ((i < 0) || (i > IWL_RATE_COUNT)) { 2184 if ((i < 0) || (i > IWL_RATE_COUNT)) {
2168 sel->rate = rate_lowest(local, sband, sta); 2185 sel->rate_idx = rate_lowest_index(local, sband, sta);
2169 goto out; 2186 goto out;
2170 } 2187 }
2171 2188
2172 sel->rate = &priv->ieee_rates[i]; 2189 if (sband->band == IEEE80211_BAND_5GHZ)
2190 i -= IWL_FIRST_OFDM_RATE;
2191 sel->rate_idx = i;
2173out: 2192out:
2174 rcu_read_unlock(); 2193 rcu_read_unlock();
2175} 2194}
@@ -2234,7 +2253,7 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
2234 if (sta_id == IWL_INVALID_STATION) { 2253 if (sta_id == IWL_INVALID_STATION) {
2235 IWL_DEBUG_RATE("LQ: ADD station %s\n", 2254 IWL_DEBUG_RATE("LQ: ADD station %s\n",
2236 print_mac(mac, sta->addr)); 2255 print_mac(mac, sta->addr));
2237 sta_id = iwl4965_add_station_flags(priv, sta->addr, 2256 sta_id = iwl_add_station_flags(priv, sta->addr,
2238 0, CMD_ASYNC, NULL); 2257 0, CMD_ASYNC, NULL);
2239 } 2258 }
2240 if ((sta_id != IWL_INVALID_STATION)) { 2259 if ((sta_id != IWL_INVALID_STATION)) {
@@ -2425,6 +2444,7 @@ static void rs_fill_link_cmd(const struct iwl_priv *priv,
2425 repeat_rate--; 2444 repeat_rate--;
2426 } 2445 }
2427 2446
2447 lq_cmd->agg_params.agg_frame_cnt_limit = 64;
2428 lq_cmd->agg_params.agg_dis_start_th = 3; 2448 lq_cmd->agg_params.agg_dis_start_th = 3;
2429 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000); 2449 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000);
2430} 2450}
@@ -2691,7 +2711,7 @@ int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
2691 int active = lq_sta->active_tbl; 2711 int active = lq_sta->active_tbl;
2692 2712
2693 cnt += 2713 cnt +=
2694 sprintf(&buf[cnt], " %2dMbs: ", iwl4965_rates[i].ieee / 2); 2714 sprintf(&buf[cnt], " %2dMbs: ", iwl_rates[i].ieee / 2);
2695 2715
2696 mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1)); 2716 mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));
2697 for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1) 2717 for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)
@@ -2702,7 +2722,7 @@ int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
2702 samples += lq_sta->lq_info[active].win[i].counter; 2722 samples += lq_sta->lq_info[active].win[i].counter;
2703 good += lq_sta->lq_info[active].win[i].success_counter; 2723 good += lq_sta->lq_info[active].win[i].success_counter;
2704 success += lq_sta->lq_info[active].win[i].success_counter * 2724 success += lq_sta->lq_info[active].win[i].success_counter *
2705 iwl4965_rates[i].ieee; 2725 iwl_rates[i].ieee;
2706 2726
2707 if (lq_sta->lq_info[active].win[i].stamp) { 2727 if (lq_sta->lq_info[active].win[i].stamp) {
2708 int delta = 2728 int delta =
@@ -2722,10 +2742,11 @@ int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
2722 i = j; 2742 i = j;
2723 } 2743 }
2724 2744
2725 /* Display the average rate of all samples taken. 2745 /*
2726 * 2746 * Display the average rate of all samples taken.
2727 * NOTE: We multiply # of samples by 2 since the IEEE measurement 2747 * NOTE: We multiply # of samples by 2 since the IEEE measurement
2728 * added from iwl4965_rates is actually 2X the rate */ 2748 * added from iwl_rates is actually 2X the rate.
2749 */
2729 if (samples) 2750 if (samples)
2730 cnt += sprintf(&buf[cnt], 2751 cnt += sprintf(&buf[cnt],
2731 "\nAverage rate is %3d.%02dMbs over last %4dms\n" 2752 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-rs.h b/drivers/net/wireless/iwlwifi/iwl-4965-rs.h
index 7ea2041a22e0..1dd4124227a5 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-rs.h
+++ b/drivers/net/wireless/iwlwifi/iwl-4965-rs.h
@@ -29,7 +29,7 @@
29 29
30#include "iwl-dev.h" 30#include "iwl-dev.h"
31 31
32struct iwl4965_rate_info { 32struct iwl_rate_info {
33 u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */ 33 u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */
34 u8 plcp_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */ 34 u8 plcp_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */
35 u8 plcp_mimo2; /* uCode API: IWL_RATE_MIMO2_6M_PLCP, etc. */ 35 u8 plcp_mimo2; /* uCode API: IWL_RATE_MIMO2_6M_PLCP, etc. */
@@ -45,7 +45,7 @@ struct iwl4965_rate_info {
45 45
46/* 46/*
47 * These serve as indexes into 47 * These serve as indexes into
48 * struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT]; 48 * struct iwl_rate_info iwl_rates[IWL_RATE_COUNT];
49 */ 49 */
50enum { 50enum {
51 IWL_RATE_1M_INDEX = 0, 51 IWL_RATE_1M_INDEX = 0,
@@ -240,7 +240,7 @@ enum {
240#define TID_MAX_TIME_DIFF ((TID_QUEUE_MAX_SIZE - 1) * TID_QUEUE_CELL_SPACING) 240#define TID_MAX_TIME_DIFF ((TID_QUEUE_MAX_SIZE - 1) * TID_QUEUE_CELL_SPACING)
241#define TIME_WRAP_AROUND(x, y) (((y) > (x)) ? (y) - (x) : (0-(x)) + (y)) 241#define TIME_WRAP_AROUND(x, y) (((y) > (x)) ? (y) - (x) : (0-(x)) + (y))
242 242
243extern const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT]; 243extern const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT];
244 244
245enum iwl_table_type { 245enum iwl_table_type {
246 LQ_NONE, 246 LQ_NONE,
@@ -279,7 +279,7 @@ static inline u8 num_of_ant(u8 mask)
279 279
280static inline u8 iwl4965_get_prev_ieee_rate(u8 rate_index) 280static inline u8 iwl4965_get_prev_ieee_rate(u8 rate_index)
281{ 281{
282 u8 rate = iwl4965_rates[rate_index].prev_ieee; 282 u8 rate = iwl_rates[rate_index].prev_ieee;
283 283
284 if (rate == IWL_RATE_INVALID) 284 if (rate == IWL_RATE_INVALID)
285 rate = rate_index; 285 rate = rate_index;
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index 17847f981e11..aee7014bcb94 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -44,6 +44,7 @@
44#include "iwl-io.h" 44#include "iwl-io.h"
45#include "iwl-helpers.h" 45#include "iwl-helpers.h"
46#include "iwl-calib.h" 46#include "iwl-calib.h"
47#include "iwl-sta.h"
47 48
48/* module parameters */ 49/* module parameters */
49static struct iwl_mod_params iwl4965_mod_params = { 50static struct iwl_mod_params iwl4965_mod_params = {
@@ -54,30 +55,6 @@ static struct iwl_mod_params iwl4965_mod_params = {
54 /* the rest are 0 by default */ 55 /* the rest are 0 by default */
55}; 56};
56 57
57#ifdef CONFIG_IWL4965_HT
58
59static const u16 default_tid_to_tx_fifo[] = {
60 IWL_TX_FIFO_AC1,
61 IWL_TX_FIFO_AC0,
62 IWL_TX_FIFO_AC0,
63 IWL_TX_FIFO_AC1,
64 IWL_TX_FIFO_AC2,
65 IWL_TX_FIFO_AC2,
66 IWL_TX_FIFO_AC3,
67 IWL_TX_FIFO_AC3,
68 IWL_TX_FIFO_NONE,
69 IWL_TX_FIFO_NONE,
70 IWL_TX_FIFO_NONE,
71 IWL_TX_FIFO_NONE,
72 IWL_TX_FIFO_NONE,
73 IWL_TX_FIFO_NONE,
74 IWL_TX_FIFO_NONE,
75 IWL_TX_FIFO_NONE,
76 IWL_TX_FIFO_AC3
77};
78
79#endif /*CONFIG_IWL4965_HT */
80
81/* check contents of special bootstrap uCode SRAM */ 58/* check contents of special bootstrap uCode SRAM */
82static int iwl4965_verify_bsm(struct iwl_priv *priv) 59static int iwl4965_verify_bsm(struct iwl_priv *priv)
83{ 60{
@@ -156,15 +133,18 @@ static int iwl4965_load_bsm(struct iwl_priv *priv)
156 133
157 IWL_DEBUG_INFO("Begin load bsm\n"); 134 IWL_DEBUG_INFO("Begin load bsm\n");
158 135
136 priv->ucode_type = UCODE_RT;
137
159 /* make sure bootstrap program is no larger than BSM's SRAM size */ 138 /* make sure bootstrap program is no larger than BSM's SRAM size */
160 if (len > IWL_MAX_BSM_SIZE) 139 if (len > IWL_MAX_BSM_SIZE)
161 return -EINVAL; 140 return -EINVAL;
162 141
163 /* Tell bootstrap uCode where to find the "Initialize" uCode 142 /* Tell bootstrap uCode where to find the "Initialize" uCode
164 * in host DRAM ... host DRAM physical address bits 35:4 for 4965. 143 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
165 * NOTE: iwl4965_initialize_alive_start() will replace these values, 144 * NOTE: iwl_init_alive_start() will replace these values,
166 * after the "initialize" uCode has run, to point to 145 * after the "initialize" uCode has run, to point to
167 * runtime/protocol instructions and backup data cache. */ 146 * runtime/protocol instructions and backup data cache.
147 */
168 pinst = priv->ucode_init.p_addr >> 4; 148 pinst = priv->ucode_init.p_addr >> 4;
169 pdata = priv->ucode_init_data.p_addr >> 4; 149 pdata = priv->ucode_init_data.p_addr >> 4;
170 inst_len = priv->ucode_init.len; 150 inst_len = priv->ucode_init.len;
@@ -345,8 +325,8 @@ int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
345 325
346 /* 4965 legacy rate format, search for match in table */ 326 /* 4965 legacy rate format, search for match in table */
347 } else { 327 } else {
348 for (idx = 0; idx < ARRAY_SIZE(iwl4965_rates); idx++) 328 for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
349 if (iwl4965_rates[idx].plcp == (rate_n_flags & 0xFF)) 329 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
350 return idx; 330 return idx;
351 } 331 }
352 332
@@ -357,55 +337,26 @@ int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
357 * translate ucode response to mac80211 tx status control values 337 * translate ucode response to mac80211 tx status control values
358 */ 338 */
359void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags, 339void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
360 struct ieee80211_tx_control *control) 340 struct ieee80211_tx_info *control)
361{ 341{
362 int rate_index; 342 int rate_index;
363 343
364 control->antenna_sel_tx = 344 control->antenna_sel_tx =
365 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS); 345 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
366 if (rate_n_flags & RATE_MCS_HT_MSK) 346 if (rate_n_flags & RATE_MCS_HT_MSK)
367 control->flags |= IEEE80211_TXCTL_OFDM_HT; 347 control->flags |= IEEE80211_TX_CTL_OFDM_HT;
368 if (rate_n_flags & RATE_MCS_GF_MSK) 348 if (rate_n_flags & RATE_MCS_GF_MSK)
369 control->flags |= IEEE80211_TXCTL_GREEN_FIELD; 349 control->flags |= IEEE80211_TX_CTL_GREEN_FIELD;
370 if (rate_n_flags & RATE_MCS_FAT_MSK) 350 if (rate_n_flags & RATE_MCS_FAT_MSK)
371 control->flags |= IEEE80211_TXCTL_40_MHZ_WIDTH; 351 control->flags |= IEEE80211_TX_CTL_40_MHZ_WIDTH;
372 if (rate_n_flags & RATE_MCS_DUP_MSK) 352 if (rate_n_flags & RATE_MCS_DUP_MSK)
373 control->flags |= IEEE80211_TXCTL_DUP_DATA; 353 control->flags |= IEEE80211_TX_CTL_DUP_DATA;
374 if (rate_n_flags & RATE_MCS_SGI_MSK) 354 if (rate_n_flags & RATE_MCS_SGI_MSK)
375 control->flags |= IEEE80211_TXCTL_SHORT_GI; 355 control->flags |= IEEE80211_TX_CTL_SHORT_GI;
376 /* since iwl4965_hwrate_to_plcp_idx is band indifferent, we always use
377 * IEEE80211_BAND_2GHZ band as it contains all the rates */
378 rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags); 356 rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags);
379 if (rate_index == -1) 357 if (control->band == IEEE80211_BAND_5GHZ)
380 control->tx_rate = NULL; 358 rate_index -= IWL_FIRST_OFDM_RATE;
381 else 359 control->tx_rate_idx = rate_index;
382 control->tx_rate =
383 &priv->bands[IEEE80211_BAND_2GHZ].bitrates[rate_index];
384}
385
386int iwl4965_hw_rxq_stop(struct iwl_priv *priv)
387{
388 int rc;
389 unsigned long flags;
390
391 spin_lock_irqsave(&priv->lock, flags);
392 rc = iwl_grab_nic_access(priv);
393 if (rc) {
394 spin_unlock_irqrestore(&priv->lock, flags);
395 return rc;
396 }
397
398 /* stop Rx DMA */
399 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
400 rc = iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
401 (1 << 24), 1000);
402 if (rc < 0)
403 IWL_ERROR("Can't stop Rx DMA.\n");
404
405 iwl_release_nic_access(priv);
406 spin_unlock_irqrestore(&priv->lock, flags);
407
408 return 0;
409} 360}
410 361
411/* 362/*
@@ -467,25 +418,13 @@ int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
467 return ret; 418 return ret;
468} 419}
469 420
470static int iwl4965_disable_tx_fifo(struct iwl_priv *priv) 421/*
422 * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
423 * must be called under priv->lock and mac access
424 */
425static void iwl4965_txq_set_sched(struct iwl_priv *priv, u32 mask)
471{ 426{
472 unsigned long flags; 427 iwl_write_prph(priv, IWL49_SCD_TXFACT, mask);
473 int ret;
474
475 spin_lock_irqsave(&priv->lock, flags);
476
477 ret = iwl_grab_nic_access(priv);
478 if (unlikely(ret)) {
479 IWL_ERROR("Tx fifo reset failed");
480 spin_unlock_irqrestore(&priv->lock, flags);
481 return ret;
482 }
483
484 iwl_write_prph(priv, IWL49_SCD_TXFACT, 0);
485 iwl_release_nic_access(priv);
486 spin_unlock_irqrestore(&priv->lock, flags);
487
488 return 0;
489} 428}
490 429
491static int iwl4965_apm_init(struct iwl_priv *priv) 430static int iwl4965_apm_init(struct iwl_priv *priv)
@@ -495,6 +434,10 @@ static int iwl4965_apm_init(struct iwl_priv *priv)
495 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, 434 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
496 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); 435 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
497 436
437 /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
438 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
439 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
440
498 /* set "initialization complete" bit to move adapter 441 /* set "initialization complete" bit to move adapter
499 * D0U* --> D0A* state */ 442 * D0U* --> D0A* state */
500 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); 443 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
@@ -513,11 +456,12 @@ static int iwl4965_apm_init(struct iwl_priv *priv)
513 goto out; 456 goto out;
514 457
515 /* enable DMA */ 458 /* enable DMA */
516 iwl_write_prph(priv, APMG_CLK_CTRL_REG, 459 iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT |
517 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT); 460 APMG_CLK_VAL_BSM_CLK_RQT);
518 461
519 udelay(20); 462 udelay(20);
520 463
464 /* disable L1-Active */
521 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, 465 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
522 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 466 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
523 467
@@ -545,8 +489,13 @@ static void iwl4965_nic_config(struct iwl_priv *priv)
545 489
546 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link); 490 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
547 491
548 /* disable L1 entry -- workaround for pre-B1 */ 492 /* L1 is enabled by BIOS */
549 pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02); 493 if ((val_link & PCI_LINK_VAL_L1_EN) == PCI_LINK_VAL_L1_EN)
494 /* diable L0S disabled L1A enabled */
495 iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
496 else
497 /* L0S enabled L1A disabled */
498 iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
550 499
551 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG); 500 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
552 501
@@ -568,10 +517,9 @@ static void iwl4965_nic_config(struct iwl_priv *priv)
568 spin_unlock_irqrestore(&priv->lock, flags); 517 spin_unlock_irqrestore(&priv->lock, flags);
569} 518}
570 519
571int iwl4965_hw_nic_stop_master(struct iwl_priv *priv) 520static int iwl4965_apm_stop_master(struct iwl_priv *priv)
572{ 521{
573 int rc = 0; 522 int ret = 0;
574 u32 reg_val;
575 unsigned long flags; 523 unsigned long flags;
576 524
577 spin_lock_irqsave(&priv->lock, flags); 525 spin_lock_irqsave(&priv->lock, flags);
@@ -579,64 +527,41 @@ int iwl4965_hw_nic_stop_master(struct iwl_priv *priv)
579 /* set stop master bit */ 527 /* set stop master bit */
580 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); 528 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
581 529
582 reg_val = iwl_read32(priv, CSR_GP_CNTRL); 530 ret = iwl_poll_bit(priv, CSR_RESET,
583
584 if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE ==
585 (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE))
586 IWL_DEBUG_INFO("Card in power save, master is already "
587 "stopped\n");
588 else {
589 rc = iwl_poll_bit(priv, CSR_RESET,
590 CSR_RESET_REG_FLAG_MASTER_DISABLED, 531 CSR_RESET_REG_FLAG_MASTER_DISABLED,
591 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100); 532 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
592 if (rc < 0) { 533 if (ret < 0)
593 spin_unlock_irqrestore(&priv->lock, flags); 534 goto out;
594 return rc;
595 }
596 }
597 535
536out:
598 spin_unlock_irqrestore(&priv->lock, flags); 537 spin_unlock_irqrestore(&priv->lock, flags);
599 IWL_DEBUG_INFO("stop master\n"); 538 IWL_DEBUG_INFO("stop master\n");
600 539
601 return rc; 540 return ret;
602} 541}
603 542
604/** 543static void iwl4965_apm_stop(struct iwl_priv *priv)
605 * iwl4965_hw_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory
606 */
607void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv)
608{ 544{
609
610 int txq_id;
611 unsigned long flags; 545 unsigned long flags;
612 546
613 /* Stop each Tx DMA channel, and wait for it to be idle */ 547 iwl4965_apm_stop_master(priv);
614 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
615 spin_lock_irqsave(&priv->lock, flags);
616 if (iwl_grab_nic_access(priv)) {
617 spin_unlock_irqrestore(&priv->lock, flags);
618 continue;
619 }
620 548
621 iwl_write_direct32(priv, 549 spin_lock_irqsave(&priv->lock, flags);
622 FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0); 550
623 iwl_poll_direct_bit(priv, FH_TSSR_TX_STATUS_REG, 551 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
624 FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
625 (txq_id), 200);
626 iwl_release_nic_access(priv);
627 spin_unlock_irqrestore(&priv->lock, flags);
628 }
629 552
630 /* Deallocate memory for all Tx queues */ 553 udelay(10);
631 iwl_hw_txq_ctx_free(priv); 554
555 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
556 spin_unlock_irqrestore(&priv->lock, flags);
632} 557}
633 558
634int iwl4965_hw_nic_reset(struct iwl_priv *priv) 559static int iwl4965_apm_reset(struct iwl_priv *priv)
635{ 560{
636 int rc = 0; 561 int ret = 0;
637 unsigned long flags; 562 unsigned long flags;
638 563
639 iwl4965_hw_nic_stop_master(priv); 564 iwl4965_apm_stop_master(priv);
640 565
641 spin_lock_irqsave(&priv->lock, flags); 566 spin_lock_irqsave(&priv->lock, flags);
642 567
@@ -644,34 +569,41 @@ int iwl4965_hw_nic_reset(struct iwl_priv *priv)
644 569
645 udelay(10); 570 udelay(10);
646 571
572 /* FIXME: put here L1A -L0S w/a */
573
647 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); 574 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
648 rc = iwl_poll_bit(priv, CSR_RESET, 575
576 ret = iwl_poll_bit(priv, CSR_RESET,
649 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 577 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
650 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25); 578 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25);
651 579
580 if (ret)
581 goto out;
582
652 udelay(10); 583 udelay(10);
653 584
654 rc = iwl_grab_nic_access(priv); 585 ret = iwl_grab_nic_access(priv);
655 if (!rc) { 586 if (ret)
656 iwl_write_prph(priv, APMG_CLK_EN_REG, 587 goto out;
657 APMG_CLK_VAL_DMA_CLK_RQT | 588 /* Enable DMA and BSM Clock */
658 APMG_CLK_VAL_BSM_CLK_RQT); 589 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT |
590 APMG_CLK_VAL_BSM_CLK_RQT);
659 591
660 udelay(10); 592 udelay(10);
661 593
662 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, 594 /* disable L1A */
663 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 595 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
596 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
664 597
665 iwl_release_nic_access(priv); 598 iwl_release_nic_access(priv);
666 }
667 599
668 clear_bit(STATUS_HCMD_ACTIVE, &priv->status); 600 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
669 wake_up_interruptible(&priv->wait_command_queue); 601 wake_up_interruptible(&priv->wait_command_queue);
670 602
603out:
671 spin_unlock_irqrestore(&priv->lock, flags); 604 spin_unlock_irqrestore(&priv->lock, flags);
672 605
673 return rc; 606 return ret;
674
675} 607}
676 608
677#define REG_RECALIB_PERIOD (60) 609#define REG_RECALIB_PERIOD (60)
@@ -911,16 +843,6 @@ static const u16 default_queue_to_tx_fifo[] = {
911 IWL_TX_FIFO_HCCA_2 843 IWL_TX_FIFO_HCCA_2
912}; 844};
913 845
914static inline void iwl4965_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
915{
916 set_bit(txq_id, &priv->txq_ctx_active_msk);
917}
918
919static inline void iwl4965_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
920{
921 clear_bit(txq_id, &priv->txq_ctx_active_msk);
922}
923
924int iwl4965_alive_notify(struct iwl_priv *priv) 846int iwl4965_alive_notify(struct iwl_priv *priv)
925{ 847{
926 u32 a; 848 u32 a;
@@ -930,15 +852,6 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
930 852
931 spin_lock_irqsave(&priv->lock, flags); 853 spin_lock_irqsave(&priv->lock, flags);
932 854
933#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
934 memset(&(priv->sensitivity_data), 0,
935 sizeof(struct iwl_sensitivity_data));
936 memset(&(priv->chain_noise_data), 0,
937 sizeof(struct iwl_chain_noise_data));
938 for (i = 0; i < NUM_RX_CHAINS; i++)
939 priv->chain_noise_data.delta_gain_code[i] =
940 CHAIN_NOISE_DELTA_GAIN_INIT_VAL;
941#endif /* CONFIG_IWL4965_RUN_TIME_CALIB*/
942 ret = iwl_grab_nic_access(priv); 855 ret = iwl_grab_nic_access(priv);
943 if (ret) { 856 if (ret) {
944 spin_unlock_irqrestore(&priv->lock, flags); 857 spin_unlock_irqrestore(&priv->lock, flags);
@@ -990,24 +903,20 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
990 (1 << priv->hw_params.max_txq_num) - 1); 903 (1 << priv->hw_params.max_txq_num) - 1);
991 904
992 /* Activate all Tx DMA/FIFO channels */ 905 /* Activate all Tx DMA/FIFO channels */
993 iwl_write_prph(priv, IWL49_SCD_TXFACT, 906 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
994 SCD_TXFACT_REG_TXFIFO_MASK(0, 7));
995 907
996 iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0); 908 iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
997 909
998 /* Map each Tx/cmd queue to its corresponding fifo */ 910 /* Map each Tx/cmd queue to its corresponding fifo */
999 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) { 911 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
1000 int ac = default_queue_to_tx_fifo[i]; 912 int ac = default_queue_to_tx_fifo[i];
1001 iwl4965_txq_ctx_activate(priv, i); 913 iwl_txq_ctx_activate(priv, i);
1002 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0); 914 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
1003 } 915 }
1004 916
1005 iwl_release_nic_access(priv); 917 iwl_release_nic_access(priv);
1006 spin_unlock_irqrestore(&priv->lock, flags); 918 spin_unlock_irqrestore(&priv->lock, flags);
1007 919
1008 /* Ask for statistics now, the uCode will send statistics notification
1009 * periodically after association */
1010 iwl_send_statistics_request(priv, CMD_ASYNC);
1011 return ret; 920 return ret;
1012} 921}
1013 922
@@ -1053,7 +962,6 @@ int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
1053 962
1054 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues; 963 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
1055 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto; 964 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
1056 priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd);
1057 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE; 965 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
1058 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG; 966 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
1059 if (priv->cfg->mod_params->amsdu_size_8K) 967 if (priv->cfg->mod_params->amsdu_size_8K)
@@ -1857,8 +1765,8 @@ static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
1857{ 1765{
1858 int ret = 0; 1766 int ret = 0;
1859 struct iwl4965_rxon_assoc_cmd rxon_assoc; 1767 struct iwl4965_rxon_assoc_cmd rxon_assoc;
1860 const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon; 1768 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1861 const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon; 1769 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
1862 1770
1863 if ((rxon1->flags == rxon2->flags) && 1771 if ((rxon1->flags == rxon2->flags) &&
1864 (rxon1->filter_flags == rxon2->filter_flags) && 1772 (rxon1->filter_flags == rxon2->filter_flags) &&
@@ -1934,76 +1842,6 @@ int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
1934 return rc; 1842 return rc;
1935} 1843}
1936 1844
1937#define RTS_HCCA_RETRY_LIMIT 3
1938#define RTS_DFAULT_RETRY_LIMIT 60
1939
1940void iwl4965_hw_build_tx_cmd_rate(struct iwl_priv *priv,
1941 struct iwl_cmd *cmd,
1942 struct ieee80211_tx_control *ctrl,
1943 struct ieee80211_hdr *hdr, int sta_id,
1944 int is_hcca)
1945{
1946 struct iwl4965_tx_cmd *tx = &cmd->cmd.tx;
1947 u8 rts_retry_limit = 0;
1948 u8 data_retry_limit = 0;
1949 u16 fc = le16_to_cpu(hdr->frame_control);
1950 u8 rate_plcp;
1951 u16 rate_flags = 0;
1952 int rate_idx = min(ctrl->tx_rate->hw_value & 0xffff, IWL_RATE_COUNT - 1);
1953
1954 rate_plcp = iwl4965_rates[rate_idx].plcp;
1955
1956 rts_retry_limit = (is_hcca) ?
1957 RTS_HCCA_RETRY_LIMIT : RTS_DFAULT_RETRY_LIMIT;
1958
1959 if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
1960 rate_flags |= RATE_MCS_CCK_MSK;
1961
1962
1963 if (ieee80211_is_probe_response(fc)) {
1964 data_retry_limit = 3;
1965 if (data_retry_limit < rts_retry_limit)
1966 rts_retry_limit = data_retry_limit;
1967 } else
1968 data_retry_limit = IWL_DEFAULT_TX_RETRY;
1969
1970 if (priv->data_retry_limit != -1)
1971 data_retry_limit = priv->data_retry_limit;
1972
1973
1974 if (ieee80211_is_data(fc)) {
1975 tx->initial_rate_index = 0;
1976 tx->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
1977 } else {
1978 switch (fc & IEEE80211_FCTL_STYPE) {
1979 case IEEE80211_STYPE_AUTH:
1980 case IEEE80211_STYPE_DEAUTH:
1981 case IEEE80211_STYPE_ASSOC_REQ:
1982 case IEEE80211_STYPE_REASSOC_REQ:
1983 if (tx->tx_flags & TX_CMD_FLG_RTS_MSK) {
1984 tx->tx_flags &= ~TX_CMD_FLG_RTS_MSK;
1985 tx->tx_flags |= TX_CMD_FLG_CTS_MSK;
1986 }
1987 break;
1988 default:
1989 break;
1990 }
1991
1992 /* Alternate between antenna A and B for successive frames */
1993 if (priv->use_ant_b_for_management_frame) {
1994 priv->use_ant_b_for_management_frame = 0;
1995 rate_flags |= RATE_MCS_ANT_B_MSK;
1996 } else {
1997 priv->use_ant_b_for_management_frame = 1;
1998 rate_flags |= RATE_MCS_ANT_A_MSK;
1999 }
2000 }
2001
2002 tx->rts_retry_limit = rts_retry_limit;
2003 tx->data_retry_limit = data_retry_limit;
2004 tx->rate_n_flags = iwl4965_hw_set_rate_n_flags(rate_plcp, rate_flags);
2005}
2006
2007static int iwl4965_shared_mem_rx_idx(struct iwl_priv *priv) 1845static int iwl4965_shared_mem_rx_idx(struct iwl_priv *priv)
2008{ 1846{
2009 struct iwl4965_shared *s = priv->shared_virt; 1847 struct iwl4965_shared *s = priv->shared_virt;
@@ -2016,7 +1854,7 @@ int iwl4965_hw_get_temperature(struct iwl_priv *priv)
2016} 1854}
2017 1855
2018unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv, 1856unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
2019 struct iwl4965_frame *frame, u8 rate) 1857 struct iwl_frame *frame, u8 rate)
2020{ 1858{
2021 struct iwl4965_tx_beacon_cmd *tx_beacon_cmd; 1859 struct iwl4965_tx_beacon_cmd *tx_beacon_cmd;
2022 unsigned int frame_size; 1860 unsigned int frame_size;
@@ -2029,7 +1867,7 @@ unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
2029 1867
2030 frame_size = iwl4965_fill_beacon_frame(priv, 1868 frame_size = iwl4965_fill_beacon_frame(priv,
2031 tx_beacon_cmd->frame, 1869 tx_beacon_cmd->frame,
2032 iwl4965_broadcast_addr, 1870 iwl_bcast_addr,
2033 sizeof(frame->u) - sizeof(*tx_beacon_cmd)); 1871 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
2034 1872
2035 BUG_ON(frame_size > MAX_MPDU_SIZE); 1873 BUG_ON(frame_size > MAX_MPDU_SIZE);
@@ -2047,40 +1885,6 @@ unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
2047 return (sizeof(*tx_beacon_cmd) + frame_size); 1885 return (sizeof(*tx_beacon_cmd) + frame_size);
2048} 1886}
2049 1887
2050int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr,
2051 dma_addr_t addr, u16 len)
2052{
2053 int index, is_odd;
2054 struct iwl_tfd_frame *tfd = ptr;
2055 u32 num_tbs = IWL_GET_BITS(*tfd, num_tbs);
2056
2057 /* Each TFD can point to a maximum 20 Tx buffers */
2058 if ((num_tbs >= MAX_NUM_OF_TBS) || (num_tbs < 0)) {
2059 IWL_ERROR("Error can not send more than %d chunks\n",
2060 MAX_NUM_OF_TBS);
2061 return -EINVAL;
2062 }
2063
2064 index = num_tbs / 2;
2065 is_odd = num_tbs & 0x1;
2066
2067 if (!is_odd) {
2068 tfd->pa[index].tb1_addr = cpu_to_le32(addr);
2069 IWL_SET_BITS(tfd->pa[index], tb1_addr_hi,
2070 iwl_get_dma_hi_address(addr));
2071 IWL_SET_BITS(tfd->pa[index], tb1_len, len);
2072 } else {
2073 IWL_SET_BITS(tfd->pa[index], tb2_addr_lo16,
2074 (u32) (addr & 0xffff));
2075 IWL_SET_BITS(tfd->pa[index], tb2_addr_hi20, addr >> 16);
2076 IWL_SET_BITS(tfd->pa[index], tb2_len, len);
2077 }
2078
2079 IWL_SET_BITS(*tfd, num_tbs, num_tbs + 1);
2080
2081 return 0;
2082}
2083
2084static int iwl4965_alloc_shared_mem(struct iwl_priv *priv) 1888static int iwl4965_alloc_shared_mem(struct iwl_priv *priv)
2085{ 1889{
2086 priv->shared_virt = pci_alloc_consistent(priv->pci_dev, 1890 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
@@ -2436,7 +2240,7 @@ static void iwl4965_add_radiotap(struct iwl_priv *priv,
2436 if (rate == -1) 2240 if (rate == -1)
2437 iwl4965_rt->rt_rate = 0; 2241 iwl4965_rt->rt_rate = 0;
2438 else 2242 else
2439 iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee; 2243 iwl4965_rt->rt_rate = iwl_rates[rate].ieee;
2440 2244
2441 /* 2245 /*
2442 * "antenna number" 2246 * "antenna number"
@@ -2494,6 +2298,7 @@ static int iwl4965_set_decrypted_flag(struct iwl_priv *priv,
2494 RX_RES_STATUS_BAD_KEY_TTAK) 2298 RX_RES_STATUS_BAD_KEY_TTAK)
2495 break; 2299 break;
2496 2300
2301 case RX_RES_STATUS_SEC_TYPE_WEP:
2497 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == 2302 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2498 RX_RES_STATUS_BAD_ICV_MIC) { 2303 RX_RES_STATUS_BAD_ICV_MIC) {
2499 /* bad ICV, the packet is destroyed since the 2304 /* bad ICV, the packet is destroyed since the
@@ -2501,7 +2306,6 @@ static int iwl4965_set_decrypted_flag(struct iwl_priv *priv,
2501 IWL_DEBUG_RX("Packet destroyed\n"); 2306 IWL_DEBUG_RX("Packet destroyed\n");
2502 return -1; 2307 return -1;
2503 } 2308 }
2504 case RX_RES_STATUS_SEC_TYPE_WEP:
2505 case RX_RES_STATUS_SEC_TYPE_CCMP: 2309 case RX_RES_STATUS_SEC_TYPE_CCMP:
2506 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == 2310 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2507 RX_RES_STATUS_DECRYPT_OK) { 2311 RX_RES_STATUS_DECRYPT_OK) {
@@ -2848,7 +2652,7 @@ static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
2848 if (unlikely(rate_idx == -1)) 2652 if (unlikely(rate_idx == -1))
2849 bitrate = 0; 2653 bitrate = 0;
2850 else 2654 else
2851 bitrate = iwl4965_rates[rate_idx].ieee / 2; 2655 bitrate = iwl_rates[rate_idx].ieee / 2;
2852 2656
2853 /* print frame summary. 2657 /* print frame summary.
2854 * MAC addresses show just the last byte (for brevity), 2658 * MAC addresses show just the last byte (for brevity),
@@ -2885,7 +2689,7 @@ static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
2885 2689
2886/* Called for REPLY_RX (legacy ABG frames), or 2690/* Called for REPLY_RX (legacy ABG frames), or
2887 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */ 2691 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
2888static void iwl4965_rx_reply_rx(struct iwl_priv *priv, 2692void iwl4965_rx_reply_rx(struct iwl_priv *priv,
2889 struct iwl_rx_mem_buffer *rxb) 2693 struct iwl_rx_mem_buffer *rxb)
2890{ 2694{
2891 struct ieee80211_hdr *header; 2695 struct ieee80211_hdr *header;
@@ -3059,57 +2863,9 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv,
3059 } 2863 }
3060} 2864}
3061 2865
3062/* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
3063 * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
3064static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
3065 struct iwl_rx_mem_buffer *rxb)
3066{
3067 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
3068 priv->last_phy_res[0] = 1;
3069 memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
3070 sizeof(struct iwl4965_rx_phy_res));
3071}
3072static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv,
3073 struct iwl_rx_mem_buffer *rxb)
3074
3075{
3076#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
3077 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
3078 struct iwl4965_missed_beacon_notif *missed_beacon;
3079
3080 missed_beacon = &pkt->u.missed_beacon;
3081 if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) {
3082 IWL_DEBUG_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
3083 le32_to_cpu(missed_beacon->consequtive_missed_beacons),
3084 le32_to_cpu(missed_beacon->total_missed_becons),
3085 le32_to_cpu(missed_beacon->num_recvd_beacons),
3086 le32_to_cpu(missed_beacon->num_expected_beacons));
3087 if (!test_bit(STATUS_SCANNING, &priv->status))
3088 iwl_init_sensitivity(priv);
3089 }
3090#endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
3091}
3092#ifdef CONFIG_IWL4965_HT 2866#ifdef CONFIG_IWL4965_HT
3093 2867
3094/** 2868/**
3095 * iwl4965_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
3096 */
3097static void iwl4965_sta_modify_enable_tid_tx(struct iwl_priv *priv,
3098 int sta_id, int tid)
3099{
3100 unsigned long flags;
3101
3102 /* Remove "disable" flag, to enable Tx for this TID */
3103 spin_lock_irqsave(&priv->sta_lock, flags);
3104 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
3105 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
3106 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3107 spin_unlock_irqrestore(&priv->sta_lock, flags);
3108
3109 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
3110}
3111
3112/**
3113 * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack 2869 * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack
3114 * 2870 *
3115 * Go through block-ack's bitmap of ACK'd frames, update driver's record of 2871 * Go through block-ack's bitmap of ACK'd frames, update driver's record of
@@ -3126,7 +2882,7 @@ static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
3126 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow); 2882 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
3127 u64 bitmap; 2883 u64 bitmap;
3128 int successes = 0; 2884 int successes = 0;
3129 struct ieee80211_tx_status *tx_status; 2885 struct ieee80211_tx_info *info;
3130 2886
3131 if (unlikely(!agg->wait_for_ba)) { 2887 if (unlikely(!agg->wait_for_ba)) {
3132 IWL_ERROR("Received BA when not expected\n"); 2888 IWL_ERROR("Received BA when not expected\n");
@@ -3164,13 +2920,13 @@ static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
3164 agg->start_idx + i); 2920 agg->start_idx + i);
3165 } 2921 }
3166 2922
3167 tx_status = &priv->txq[scd_flow].txb[agg->start_idx].status; 2923 info = IEEE80211_SKB_CB(priv->txq[scd_flow].txb[agg->start_idx].skb[0]);
3168 tx_status->flags = IEEE80211_TX_STATUS_ACK; 2924 memset(&info->status, 0, sizeof(info->status));
3169 tx_status->flags |= IEEE80211_TX_STATUS_AMPDU; 2925 info->flags = IEEE80211_TX_STAT_ACK;
3170 tx_status->ampdu_ack_map = successes; 2926 info->flags |= IEEE80211_TX_STAT_AMPDU;
3171 tx_status->ampdu_ack_len = agg->frame_count; 2927 info->status.ampdu_ack_map = successes;
3172 iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags, 2928 info->status.ampdu_ack_len = agg->frame_count;
3173 &tx_status->control); 2929 iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags, info);
3174 2930
3175 IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap); 2931 IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
3176 2932
@@ -3195,8 +2951,8 @@ static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
3195 * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID 2951 * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID
3196 * priv->lock must be held by the caller 2952 * priv->lock must be held by the caller
3197 */ 2953 */
3198static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id, 2954static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
3199 u16 ssn_idx, u8 tx_fifo) 2955 u16 ssn_idx, u8 tx_fifo)
3200{ 2956{
3201 int ret = 0; 2957 int ret = 0;
3202 2958
@@ -3220,7 +2976,7 @@ static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id,
3220 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx); 2976 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
3221 2977
3222 iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id)); 2978 iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
3223 iwl4965_txq_ctx_deactivate(priv, txq_id); 2979 iwl_txq_ctx_deactivate(priv, txq_id);
3224 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0); 2980 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
3225 2981
3226 iwl_release_nic_access(priv); 2982 iwl_release_nic_access(priv);
@@ -3228,49 +2984,6 @@ static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id,
3228 return 0; 2984 return 0;
3229} 2985}
3230 2986
3231int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
3232 u8 tid, int txq_id)
3233{
3234 struct iwl4965_queue *q = &priv->txq[txq_id].q;
3235 u8 *addr = priv->stations[sta_id].sta.sta.addr;
3236 struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
3237
3238 switch (priv->stations[sta_id].tid[tid].agg.state) {
3239 case IWL_EMPTYING_HW_QUEUE_DELBA:
3240 /* We are reclaiming the last packet of the */
3241 /* aggregated HW queue */
3242 if (txq_id == tid_data->agg.txq_id &&
3243 q->read_ptr == q->write_ptr) {
3244 u16 ssn = SEQ_TO_SN(tid_data->seq_number);
3245 int tx_fifo = default_tid_to_tx_fifo[tid];
3246 IWL_DEBUG_HT("HW queue empty: continue DELBA flow\n");
3247 iwl4965_tx_queue_agg_disable(priv, txq_id,
3248 ssn, tx_fifo);
3249 tid_data->agg.state = IWL_AGG_OFF;
3250 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, addr, tid);
3251 }
3252 break;
3253 case IWL_EMPTYING_HW_QUEUE_ADDBA:
3254 /* We are reclaiming the last packet of the queue */
3255 if (tid_data->tfds_in_queue == 0) {
3256 IWL_DEBUG_HT("HW queue empty: continue ADDBA flow\n");
3257 tid_data->agg.state = IWL_AGG_ON;
3258 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, addr, tid);
3259 }
3260 break;
3261 }
3262 return 0;
3263}
3264
3265/**
3266 * iwl4965_queue_dec_wrap - Decrement queue index, wrap back to end if needed
3267 * @index -- current index
3268 * @n_bd -- total number of entries in queue (s/b power of 2)
3269 */
3270static inline int iwl4965_queue_dec_wrap(int index, int n_bd)
3271{
3272 return (index == 0) ? n_bd - 1 : index - 1;
3273}
3274 2987
3275/** 2988/**
3276 * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA 2989 * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
@@ -3304,7 +3017,7 @@ static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
3304 agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg; 3017 agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
3305 3018
3306 /* Find index just before block-ack window */ 3019 /* Find index just before block-ack window */
3307 index = iwl4965_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd); 3020 index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
3308 3021
3309 /* TODO: Need to get this copy more safely - now good for debug */ 3022 /* TODO: Need to get this copy more safely - now good for debug */
3310 3023
@@ -3334,15 +3047,16 @@ static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
3334 /* calculate mac80211 ampdu sw queue to wake */ 3047 /* calculate mac80211 ampdu sw queue to wake */
3335 int ampdu_q = 3048 int ampdu_q =
3336 scd_flow - IWL_BACK_QUEUE_FIRST_ID + priv->hw->queues; 3049 scd_flow - IWL_BACK_QUEUE_FIRST_ID + priv->hw->queues;
3337 int freed = iwl4965_tx_queue_reclaim(priv, scd_flow, index); 3050 int freed = iwl_tx_queue_reclaim(priv, scd_flow, index);
3338 priv->stations[ba_resp->sta_id]. 3051 priv->stations[ba_resp->sta_id].
3339 tid[ba_resp->tid].tfds_in_queue -= freed; 3052 tid[ba_resp->tid].tfds_in_queue -= freed;
3340 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && 3053 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
3341 priv->mac80211_registered && 3054 priv->mac80211_registered &&
3342 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) 3055 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
3343 ieee80211_wake_queue(priv->hw, ampdu_q); 3056 ieee80211_wake_queue(priv->hw, ampdu_q);
3344 iwl4965_check_empty_hw_queue(priv, ba_resp->sta_id, 3057
3345 ba_resp->tid, scd_flow); 3058 iwl_txq_check_empty(priv, ba_resp->sta_id,
3059 ba_resp->tid, scd_flow);
3346 } 3060 }
3347} 3061}
3348 3062
@@ -3356,7 +3070,7 @@ static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
3356 u32 tbl_dw; 3070 u32 tbl_dw;
3357 u16 scd_q2ratid; 3071 u16 scd_q2ratid;
3358 3072
3359 scd_q2ratid = ra_tid & IWL49_SCD_QUEUE_RA_TID_MAP_RATID_MSK; 3073 scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
3360 3074
3361 tbl_dw_addr = priv->scd_base_addr + 3075 tbl_dw_addr = priv->scd_base_addr +
3362 IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id); 3076 IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
@@ -3380,12 +3094,11 @@ static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
3380 * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID, 3094 * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID,
3381 * i.e. it must be one of the higher queues used for aggregation 3095 * i.e. it must be one of the higher queues used for aggregation
3382 */ 3096 */
3383static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id, 3097static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
3384 int tx_fifo, int sta_id, int tid, 3098 int tx_fifo, int sta_id, int tid, u16 ssn_idx)
3385 u16 ssn_idx)
3386{ 3099{
3387 unsigned long flags; 3100 unsigned long flags;
3388 int rc; 3101 int ret;
3389 u16 ra_tid; 3102 u16 ra_tid;
3390 3103
3391 if (IWL_BACK_QUEUE_FIRST_ID > txq_id) 3104 if (IWL_BACK_QUEUE_FIRST_ID > txq_id)
@@ -3395,13 +3108,13 @@ static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
3395 ra_tid = BUILD_RAxTID(sta_id, tid); 3108 ra_tid = BUILD_RAxTID(sta_id, tid);
3396 3109
3397 /* Modify device's station table to Tx this TID */ 3110 /* Modify device's station table to Tx this TID */
3398 iwl4965_sta_modify_enable_tid_tx(priv, sta_id, tid); 3111 iwl_sta_modify_enable_tid_tx(priv, sta_id, tid);
3399 3112
3400 spin_lock_irqsave(&priv->lock, flags); 3113 spin_lock_irqsave(&priv->lock, flags);
3401 rc = iwl_grab_nic_access(priv); 3114 ret = iwl_grab_nic_access(priv);
3402 if (rc) { 3115 if (ret) {
3403 spin_unlock_irqrestore(&priv->lock, flags); 3116 spin_unlock_irqrestore(&priv->lock, flags);
3404 return rc; 3117 return ret;
3405 } 3118 }
3406 3119
3407 /* Stop this Tx queue before configuring it */ 3120 /* Stop this Tx queue before configuring it */
@@ -3443,109 +3156,8 @@ static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
3443 3156
3444#endif /* CONFIG_IWL4965_HT */ 3157#endif /* CONFIG_IWL4965_HT */
3445 3158
3446/**
3447 * iwl4965_add_station - Initialize a station's hardware rate table
3448 *
3449 * The uCode's station table contains a table of fallback rates
3450 * for automatic fallback during transmission.
3451 *
3452 * NOTE: This sets up a default set of values. These will be replaced later
3453 * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
3454 * rc80211_simple.
3455 *
3456 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
3457 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
3458 * which requires station table entry to exist).
3459 */
3460void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
3461{
3462 int i, r;
3463 struct iwl_link_quality_cmd link_cmd = {
3464 .reserved1 = 0,
3465 };
3466 u16 rate_flags;
3467
3468 /* Set up the rate scaling to start at selected rate, fall back
3469 * all the way down to 1M in IEEE order, and then spin on 1M */
3470 if (is_ap)
3471 r = IWL_RATE_54M_INDEX;
3472 else if (priv->band == IEEE80211_BAND_5GHZ)
3473 r = IWL_RATE_6M_INDEX;
3474 else
3475 r = IWL_RATE_1M_INDEX;
3476
3477 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
3478 rate_flags = 0;
3479 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
3480 rate_flags |= RATE_MCS_CCK_MSK;
3481
3482 /* Use Tx antenna B only */
3483 rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/
3484
3485 link_cmd.rs_table[i].rate_n_flags =
3486 iwl4965_hw_set_rate_n_flags(iwl4965_rates[r].plcp, rate_flags);
3487 r = iwl4965_get_prev_ieee_rate(r);
3488 }
3489
3490 link_cmd.general_params.single_stream_ant_msk = 2;
3491 link_cmd.general_params.dual_stream_ant_msk = 3;
3492 link_cmd.agg_params.agg_dis_start_th = 3;
3493 link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
3494
3495 /* Update the rate scaling for control frame Tx to AP */
3496 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
3497
3498 iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
3499 sizeof(link_cmd), &link_cmd, NULL);
3500}
3501 3159
3502#ifdef CONFIG_IWL4965_HT 3160#ifdef CONFIG_IWL4965_HT
3503
3504void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index,
3505 struct ieee80211_ht_info *sta_ht_inf)
3506{
3507 __le32 sta_flags;
3508 u8 mimo_ps_mode;
3509
3510 if (!sta_ht_inf || !sta_ht_inf->ht_supported)
3511 goto done;
3512
3513 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2;
3514
3515 sta_flags = priv->stations[index].sta.station_flags;
3516
3517 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
3518
3519 switch (mimo_ps_mode) {
3520 case WLAN_HT_CAP_MIMO_PS_STATIC:
3521 sta_flags |= STA_FLG_MIMO_DIS_MSK;
3522 break;
3523 case WLAN_HT_CAP_MIMO_PS_DYNAMIC:
3524 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
3525 break;
3526 case WLAN_HT_CAP_MIMO_PS_DISABLED:
3527 break;
3528 default:
3529 IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode);
3530 break;
3531 }
3532
3533 sta_flags |= cpu_to_le32(
3534 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
3535
3536 sta_flags |= cpu_to_le32(
3537 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
3538
3539 if (iwl_is_fat_tx_allowed(priv, sta_ht_inf))
3540 sta_flags |= STA_FLG_FAT_EN_MSK;
3541 else
3542 sta_flags &= ~STA_FLG_FAT_EN_MSK;
3543
3544 priv->stations[index].sta.station_flags = sta_flags;
3545 done:
3546 return;
3547}
3548
3549static int iwl4965_rx_agg_start(struct iwl_priv *priv, 3161static int iwl4965_rx_agg_start(struct iwl_priv *priv,
3550 const u8 *addr, int tid, u16 ssn) 3162 const u8 *addr, int tid, u16 ssn)
3551{ 3163{
@@ -3589,137 +3201,6 @@ static int iwl4965_rx_agg_stop(struct iwl_priv *priv,
3589 CMD_ASYNC); 3201 CMD_ASYNC);
3590} 3202}
3591 3203
3592/*
3593 * Find first available (lowest unused) Tx Queue, mark it "active".
3594 * Called only when finding queue for aggregation.
3595 * Should never return anything < 7, because they should already
3596 * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
3597 */
3598static int iwl4965_txq_ctx_activate_free(struct iwl_priv *priv)
3599{
3600 int txq_id;
3601
3602 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
3603 if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
3604 return txq_id;
3605 return -1;
3606}
3607
3608static int iwl4965_tx_agg_start(struct ieee80211_hw *hw, const u8 *ra,
3609 u16 tid, u16 *start_seq_num)
3610{
3611 struct iwl_priv *priv = hw->priv;
3612 int sta_id;
3613 int tx_fifo;
3614 int txq_id;
3615 int ssn = -1;
3616 int ret = 0;
3617 unsigned long flags;
3618 struct iwl_tid_data *tid_data;
3619 DECLARE_MAC_BUF(mac);
3620
3621 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
3622 tx_fifo = default_tid_to_tx_fifo[tid];
3623 else
3624 return -EINVAL;
3625
3626 IWL_WARNING("%s on ra = %s tid = %d\n",
3627 __func__, print_mac(mac, ra), tid);
3628
3629 sta_id = iwl_find_station(priv, ra);
3630 if (sta_id == IWL_INVALID_STATION)
3631 return -ENXIO;
3632
3633 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
3634 IWL_ERROR("Start AGG when state is not IWL_AGG_OFF !\n");
3635 return -ENXIO;
3636 }
3637
3638 txq_id = iwl4965_txq_ctx_activate_free(priv);
3639 if (txq_id == -1)
3640 return -ENXIO;
3641
3642 spin_lock_irqsave(&priv->sta_lock, flags);
3643 tid_data = &priv->stations[sta_id].tid[tid];
3644 ssn = SEQ_TO_SN(tid_data->seq_number);
3645 tid_data->agg.txq_id = txq_id;
3646 spin_unlock_irqrestore(&priv->sta_lock, flags);
3647
3648 *start_seq_num = ssn;
3649 ret = iwl4965_tx_queue_agg_enable(priv, txq_id, tx_fifo,
3650 sta_id, tid, ssn);
3651 if (ret)
3652 return ret;
3653
3654 ret = 0;
3655 if (tid_data->tfds_in_queue == 0) {
3656 printk(KERN_ERR "HW queue is empty\n");
3657 tid_data->agg.state = IWL_AGG_ON;
3658 ieee80211_start_tx_ba_cb_irqsafe(hw, ra, tid);
3659 } else {
3660 IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n",
3661 tid_data->tfds_in_queue);
3662 tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
3663 }
3664 return ret;
3665}
3666
3667static int iwl4965_tx_agg_stop(struct ieee80211_hw *hw, const u8 *ra, u16 tid)
3668{
3669 struct iwl_priv *priv = hw->priv;
3670 int tx_fifo_id, txq_id, sta_id, ssn = -1;
3671 struct iwl_tid_data *tid_data;
3672 int ret, write_ptr, read_ptr;
3673 unsigned long flags;
3674 DECLARE_MAC_BUF(mac);
3675
3676 if (!ra) {
3677 IWL_ERROR("ra = NULL\n");
3678 return -EINVAL;
3679 }
3680
3681 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
3682 tx_fifo_id = default_tid_to_tx_fifo[tid];
3683 else
3684 return -EINVAL;
3685
3686 sta_id = iwl_find_station(priv, ra);
3687
3688 if (sta_id == IWL_INVALID_STATION)
3689 return -ENXIO;
3690
3691 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
3692 IWL_WARNING("Stopping AGG while state not IWL_AGG_ON\n");
3693
3694 tid_data = &priv->stations[sta_id].tid[tid];
3695 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
3696 txq_id = tid_data->agg.txq_id;
3697 write_ptr = priv->txq[txq_id].q.write_ptr;
3698 read_ptr = priv->txq[txq_id].q.read_ptr;
3699
3700 /* The queue is not empty */
3701 if (write_ptr != read_ptr) {
3702 IWL_DEBUG_HT("Stopping a non empty AGG HW QUEUE\n");
3703 priv->stations[sta_id].tid[tid].agg.state =
3704 IWL_EMPTYING_HW_QUEUE_DELBA;
3705 return 0;
3706 }
3707
3708 IWL_DEBUG_HT("HW queue is empty\n");
3709 priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
3710
3711 spin_lock_irqsave(&priv->lock, flags);
3712 ret = iwl4965_tx_queue_agg_disable(priv, txq_id, ssn, tx_fifo_id);
3713 spin_unlock_irqrestore(&priv->lock, flags);
3714
3715 if (ret)
3716 return ret;
3717
3718 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, ra, tid);
3719
3720 return 0;
3721}
3722
3723int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw, 3204int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
3724 enum ieee80211_ampdu_mlme_action action, 3205 enum ieee80211_ampdu_mlme_action action,
3725 const u8 *addr, u16 tid, u16 *ssn) 3206 const u8 *addr, u16 tid, u16 *ssn)
@@ -3739,10 +3220,10 @@ int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
3739 return iwl4965_rx_agg_stop(priv, addr, tid); 3220 return iwl4965_rx_agg_stop(priv, addr, tid);
3740 case IEEE80211_AMPDU_TX_START: 3221 case IEEE80211_AMPDU_TX_START:
3741 IWL_DEBUG_HT("start Tx\n"); 3222 IWL_DEBUG_HT("start Tx\n");
3742 return iwl4965_tx_agg_start(hw, addr, tid, ssn); 3223 return iwl_tx_agg_start(priv, addr, tid, ssn);
3743 case IEEE80211_AMPDU_TX_STOP: 3224 case IEEE80211_AMPDU_TX_STOP:
3744 IWL_DEBUG_HT("stop Tx\n"); 3225 IWL_DEBUG_HT("stop Tx\n");
3745 return iwl4965_tx_agg_stop(hw, addr, tid); 3226 return iwl_tx_agg_stop(priv, addr, tid);
3746 default: 3227 default:
3747 IWL_DEBUG_HT("unknown\n"); 3228 IWL_DEBUG_HT("unknown\n");
3748 return -EINVAL; 3229 return -EINVAL;
@@ -3753,6 +3234,16 @@ int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
3753#endif /* CONFIG_IWL4965_HT */ 3234#endif /* CONFIG_IWL4965_HT */
3754 3235
3755 3236
3237static u16 iwl4965_get_hcmd_size(u8 cmd_id, u16 len)
3238{
3239 switch (cmd_id) {
3240 case REPLY_RXON:
3241 return (u16) sizeof(struct iwl4965_rxon_cmd);
3242 default:
3243 return len;
3244 }
3245}
3246
3756static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data) 3247static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
3757{ 3248{
3758 struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data; 3249 struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data;
@@ -3770,18 +3261,258 @@ static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
3770 3261
3771 return (u16)sizeof(struct iwl4965_addsta_cmd); 3262 return (u16)sizeof(struct iwl4965_addsta_cmd);
3772} 3263}
3264
3265#ifdef CONFIG_IWL4965_HT
3266static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
3267{
3268 __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
3269 tx_resp->frame_count);
3270 return le32_to_cpu(*scd_ssn) & MAX_SN;
3271
3272}
3273
3274/**
3275 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
3276 */
3277static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
3278 struct iwl_ht_agg *agg,
3279 struct iwl4965_tx_resp_agg *tx_resp,
3280 u16 start_idx)
3281{
3282 u16 status;
3283 struct agg_tx_status *frame_status = &tx_resp->status;
3284 struct ieee80211_tx_info *info = NULL;
3285 struct ieee80211_hdr *hdr = NULL;
3286 int i, sh;
3287 int txq_id, idx;
3288 u16 seq;
3289
3290 if (agg->wait_for_ba)
3291 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
3292
3293 agg->frame_count = tx_resp->frame_count;
3294 agg->start_idx = start_idx;
3295 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3296 agg->bitmap = 0;
3297
3298 /* # frames attempted by Tx command */
3299 if (agg->frame_count == 1) {
3300 /* Only one frame was attempted; no block-ack will arrive */
3301 status = le16_to_cpu(frame_status[0].status);
3302 seq = le16_to_cpu(frame_status[0].sequence);
3303 idx = SEQ_TO_INDEX(seq);
3304 txq_id = SEQ_TO_QUEUE(seq);
3305
3306 /* FIXME: code repetition */
3307 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
3308 agg->frame_count, agg->start_idx, idx);
3309
3310 info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
3311 info->status.retry_count = tx_resp->failure_frame;
3312 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
3313 info->flags |= iwl_is_tx_success(status)?
3314 IEEE80211_TX_STAT_ACK : 0;
3315 iwl4965_hwrate_to_tx_control(priv,
3316 le32_to_cpu(tx_resp->rate_n_flags),
3317 info);
3318 /* FIXME: code repetition end */
3319
3320 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3321 status & 0xff, tx_resp->failure_frame);
3322 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
3323 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
3324
3325 agg->wait_for_ba = 0;
3326 } else {
3327 /* Two or more frames were attempted; expect block-ack */
3328 u64 bitmap = 0;
3329 int start = agg->start_idx;
3330
3331 /* Construct bit-map of pending frames within Tx window */
3332 for (i = 0; i < agg->frame_count; i++) {
3333 u16 sc;
3334 status = le16_to_cpu(frame_status[i].status);
3335 seq = le16_to_cpu(frame_status[i].sequence);
3336 idx = SEQ_TO_INDEX(seq);
3337 txq_id = SEQ_TO_QUEUE(seq);
3338
3339 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
3340 AGG_TX_STATE_ABORT_MSK))
3341 continue;
3342
3343 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3344 agg->frame_count, txq_id, idx);
3345
3346 hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
3347
3348 sc = le16_to_cpu(hdr->seq_ctrl);
3349 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
3350 IWL_ERROR("BUG_ON idx doesn't match seq control"
3351 " idx=%d, seq_idx=%d, seq=%d\n",
3352 idx, SEQ_TO_SN(sc),
3353 hdr->seq_ctrl);
3354 return -1;
3355 }
3356
3357 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3358 i, idx, SEQ_TO_SN(sc));
3359
3360 sh = idx - start;
3361 if (sh > 64) {
3362 sh = (start - idx) + 0xff;
3363 bitmap = bitmap << sh;
3364 sh = 0;
3365 start = idx;
3366 } else if (sh < -64)
3367 sh = 0xff - (start - idx);
3368 else if (sh < 0) {
3369 sh = start - idx;
3370 start = idx;
3371 bitmap = bitmap << sh;
3372 sh = 0;
3373 }
3374 bitmap |= (1 << sh);
3375 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3376 start, (u32)(bitmap & 0xFFFFFFFF));
3377 }
3378
3379 agg->bitmap = bitmap;
3380 agg->start_idx = start;
3381 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3382 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
3383 agg->frame_count, agg->start_idx,
3384 (unsigned long long)agg->bitmap);
3385
3386 if (bitmap)
3387 agg->wait_for_ba = 1;
3388 }
3389 return 0;
3390}
3391#endif
3392
3393/**
3394 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
3395 */
3396static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
3397 struct iwl_rx_mem_buffer *rxb)
3398{
3399 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
3400 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3401 int txq_id = SEQ_TO_QUEUE(sequence);
3402 int index = SEQ_TO_INDEX(sequence);
3403 struct iwl_tx_queue *txq = &priv->txq[txq_id];
3404 struct ieee80211_tx_info *info;
3405 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
3406 u32 status = le32_to_cpu(tx_resp->status);
3407#ifdef CONFIG_IWL4965_HT
3408 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
3409 u16 fc;
3410 struct ieee80211_hdr *hdr;
3411 u8 *qc = NULL;
3412#endif
3413
3414 if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
3415 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3416 "is out of range [0-%d] %d %d\n", txq_id,
3417 index, txq->q.n_bd, txq->q.write_ptr,
3418 txq->q.read_ptr);
3419 return;
3420 }
3421
3422 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
3423 memset(&info->status, 0, sizeof(info->status));
3424
3425#ifdef CONFIG_IWL4965_HT
3426 hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
3427 fc = le16_to_cpu(hdr->frame_control);
3428 if (ieee80211_is_qos_data(fc)) {
3429 qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
3430 tid = qc[0] & 0xf;
3431 }
3432
3433 sta_id = iwl_get_ra_sta_id(priv, hdr);
3434 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
3435 IWL_ERROR("Station not known\n");
3436 return;
3437 }
3438
3439 if (txq->sched_retry) {
3440 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
3441 struct iwl_ht_agg *agg = NULL;
3442
3443 if (!qc)
3444 return;
3445
3446 agg = &priv->stations[sta_id].tid[tid].agg;
3447
3448 iwl4965_tx_status_reply_tx(priv, agg,
3449 (struct iwl4965_tx_resp_agg *)tx_resp, index);
3450
3451 if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status)) {
3452 /* TODO: send BAR */
3453 }
3454
3455 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
3456 int freed, ampdu_q;
3457 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
3458 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3459 "%d index %d\n", scd_ssn , index);
3460 freed = iwl_tx_queue_reclaim(priv, txq_id, index);
3461 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3462
3463 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
3464 txq_id >= 0 && priv->mac80211_registered &&
3465 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
3466 /* calculate mac80211 ampdu sw queue to wake */
3467 ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID +
3468 priv->hw->queues;
3469 if (agg->state == IWL_AGG_OFF)
3470 ieee80211_wake_queue(priv->hw, txq_id);
3471 else
3472 ieee80211_wake_queue(priv->hw, ampdu_q);
3473 }
3474 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
3475 }
3476 } else {
3477#endif /* CONFIG_IWL4965_HT */
3478
3479 info->status.retry_count = tx_resp->failure_frame;
3480 info->flags |= iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
3481 iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
3482 info);
3483
3484 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
3485 "retries %d\n", txq_id, iwl_get_tx_fail_reason(status),
3486 status, le32_to_cpu(tx_resp->rate_n_flags),
3487 tx_resp->failure_frame);
3488
3489 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
3490#ifdef CONFIG_IWL4965_HT
3491 if (index != -1) {
3492 int freed = iwl_tx_queue_reclaim(priv, txq_id, index);
3493 if (tid != MAX_TID_COUNT)
3494 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3495 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
3496 (txq_id >= 0) && priv->mac80211_registered)
3497 ieee80211_wake_queue(priv->hw, txq_id);
3498 if (tid != MAX_TID_COUNT)
3499 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
3500 }
3501 }
3502#endif /* CONFIG_IWL4965_HT */
3503
3504 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3505 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3506}
3507
3508
3773/* Set up 4965-specific Rx frame reply handlers */ 3509/* Set up 4965-specific Rx frame reply handlers */
3774static void iwl4965_rx_handler_setup(struct iwl_priv *priv) 3510static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
3775{ 3511{
3776 /* Legacy Rx frames */ 3512 /* Legacy Rx frames */
3777 priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx; 3513 priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
3778 3514 /* Tx response */
3779 /* High-throughput (HT) Rx frames */ 3515 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
3780 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
3781 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
3782
3783 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
3784 iwl4965_rx_missed_beacon_notif;
3785 3516
3786#ifdef CONFIG_IWL4965_HT 3517#ifdef CONFIG_IWL4965_HT
3787 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba; 3518 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
@@ -3812,7 +3543,7 @@ static struct iwl_hcmd_ops iwl4965_hcmd = {
3812}; 3543};
3813 3544
3814static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = { 3545static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
3815 .enqueue_hcmd = iwl4965_enqueue_hcmd, 3546 .get_hcmd_size = iwl4965_get_hcmd_size,
3816 .build_addsta_hcmd = iwl4965_build_addsta_hcmd, 3547 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
3817#ifdef CONFIG_IWL4965_RUN_TIME_CALIB 3548#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
3818 .chain_noise_reset = iwl4965_chain_noise_reset, 3549 .chain_noise_reset = iwl4965_chain_noise_reset,
@@ -3826,7 +3557,11 @@ static struct iwl_lib_ops iwl4965_lib = {
3826 .free_shared_mem = iwl4965_free_shared_mem, 3557 .free_shared_mem = iwl4965_free_shared_mem,
3827 .shared_mem_rx_idx = iwl4965_shared_mem_rx_idx, 3558 .shared_mem_rx_idx = iwl4965_shared_mem_rx_idx,
3828 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl, 3559 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
3829 .disable_tx_fifo = iwl4965_disable_tx_fifo, 3560 .txq_set_sched = iwl4965_txq_set_sched,
3561#ifdef CONFIG_IWL4965_HT
3562 .txq_agg_enable = iwl4965_txq_agg_enable,
3563 .txq_agg_disable = iwl4965_txq_agg_disable,
3564#endif
3830 .rx_handler_setup = iwl4965_rx_handler_setup, 3565 .rx_handler_setup = iwl4965_rx_handler_setup,
3831 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr, 3566 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
3832 .alive_notify = iwl4965_alive_notify, 3567 .alive_notify = iwl4965_alive_notify,
@@ -3834,6 +3569,8 @@ static struct iwl_lib_ops iwl4965_lib = {
3834 .load_ucode = iwl4965_load_bsm, 3569 .load_ucode = iwl4965_load_bsm,
3835 .apm_ops = { 3570 .apm_ops = {
3836 .init = iwl4965_apm_init, 3571 .init = iwl4965_apm_init,
3572 .reset = iwl4965_apm_reset,
3573 .stop = iwl4965_apm_stop,
3837 .config = iwl4965_nic_config, 3574 .config = iwl4965_nic_config,
3838 .set_pwr_src = iwl4965_set_pwr_src, 3575 .set_pwr_src = iwl4965_set_pwr_src,
3839 }, 3576 },
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index b5e28b811796..7e525ad45135 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -46,6 +46,41 @@
46 46
47#define IWL5000_UCODE_API "-1" 47#define IWL5000_UCODE_API "-1"
48 48
49static const u16 iwl5000_default_queue_to_tx_fifo[] = {
50 IWL_TX_FIFO_AC3,
51 IWL_TX_FIFO_AC2,
52 IWL_TX_FIFO_AC1,
53 IWL_TX_FIFO_AC0,
54 IWL50_CMD_FIFO_NUM,
55 IWL_TX_FIFO_HCCA_1,
56 IWL_TX_FIFO_HCCA_2
57};
58
59/* FIXME: same implementation as 4965 */
60static int iwl5000_apm_stop_master(struct iwl_priv *priv)
61{
62 int ret = 0;
63 unsigned long flags;
64
65 spin_lock_irqsave(&priv->lock, flags);
66
67 /* set stop master bit */
68 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
69
70 ret = iwl_poll_bit(priv, CSR_RESET,
71 CSR_RESET_REG_FLAG_MASTER_DISABLED,
72 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
73 if (ret < 0)
74 goto out;
75
76out:
77 spin_unlock_irqrestore(&priv->lock, flags);
78 IWL_DEBUG_INFO("stop master\n");
79
80 return ret;
81}
82
83
49static int iwl5000_apm_init(struct iwl_priv *priv) 84static int iwl5000_apm_init(struct iwl_priv *priv)
50{ 85{
51 int ret = 0; 86 int ret = 0;
@@ -53,6 +88,10 @@ static int iwl5000_apm_init(struct iwl_priv *priv)
53 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, 88 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
54 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); 89 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
55 90
91 /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
92 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
93 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
94
56 iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL); 95 iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
57 96
58 /* set "initialization complete" bit to move adapter 97 /* set "initialization complete" bit to move adapter
@@ -73,19 +112,91 @@ static int iwl5000_apm_init(struct iwl_priv *priv)
73 return ret; 112 return ret;
74 113
75 /* enable DMA */ 114 /* enable DMA */
76 iwl_write_prph(priv, APMG_CLK_EN_REG, 115 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
77 APMG_CLK_VAL_DMA_CLK_RQT);
78 116
79 udelay(20); 117 udelay(20);
80 118
119 /* disable L1-Active */
81 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, 120 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
82 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 121 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
83 122
84 iwl_release_nic_access(priv); 123 iwl_release_nic_access(priv);
85 124
86 return ret; 125 return ret;
87} 126}
88 127
128/* FIXME: this is indentical to 4965 */
129static void iwl5000_apm_stop(struct iwl_priv *priv)
130{
131 unsigned long flags;
132
133 iwl5000_apm_stop_master(priv);
134
135 spin_lock_irqsave(&priv->lock, flags);
136
137 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
138
139 udelay(10);
140
141 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
142
143 spin_unlock_irqrestore(&priv->lock, flags);
144}
145
146
147static int iwl5000_apm_reset(struct iwl_priv *priv)
148{
149 int ret = 0;
150 unsigned long flags;
151
152 iwl5000_apm_stop_master(priv);
153
154 spin_lock_irqsave(&priv->lock, flags);
155
156 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
157
158 udelay(10);
159
160
161 /* FIXME: put here L1A -L0S w/a */
162
163 iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
164
165 /* set "initialization complete" bit to move adapter
166 * D0U* --> D0A* state */
167 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
168
169 /* wait for clock stabilization */
170 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
171 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
172 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
173 if (ret < 0) {
174 IWL_DEBUG_INFO("Failed to init the card\n");
175 goto out;
176 }
177
178 ret = iwl_grab_nic_access(priv);
179 if (ret)
180 goto out;
181
182 /* enable DMA */
183 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
184
185 udelay(20);
186
187 /* disable L1-Active */
188 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
189 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
190
191 iwl_release_nic_access(priv);
192
193out:
194 spin_unlock_irqrestore(&priv->lock, flags);
195
196 return ret;
197}
198
199
89static void iwl5000_nic_config(struct iwl_priv *priv) 200static void iwl5000_nic_config(struct iwl_priv *priv)
90{ 201{
91 unsigned long flags; 202 unsigned long flags;
@@ -96,8 +207,13 @@ static void iwl5000_nic_config(struct iwl_priv *priv)
96 207
97 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link); 208 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
98 209
99 /* disable L1 entry -- workaround for pre-B1 */ 210 /* L1 is enabled by BIOS */
100 pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02); 211 if ((val_link & PCI_LINK_VAL_L1_EN) == PCI_LINK_VAL_L1_EN)
212 /* diable L0S disabled L1A enabled */
213 iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
214 else
215 /* L0S enabled L1A disabled */
216 iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
101 217
102 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG); 218 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
103 219
@@ -279,6 +395,8 @@ static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
279 395
280#endif /* CONFIG_IWL5000_RUN_TIME_CALIB */ 396#endif /* CONFIG_IWL5000_RUN_TIME_CALIB */
281 397
398
399
282static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv, 400static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
283 size_t offset) 401 size_t offset)
284{ 402{
@@ -287,6 +405,423 @@ static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
287 return &priv->eeprom[address]; 405 return &priv->eeprom[address];
288} 406}
289 407
408/*
409 * Calibration
410 */
411static int iwl5000_send_Xtal_calib(struct iwl_priv *priv)
412{
413 u16 *xtal_calib = (u16 *)iwl_eeprom_query_addr(priv, EEPROM_5000_XTAL);
414
415 struct iwl5000_calibration cal_cmd = {
416 .op_code = IWL5000_PHY_CALIBRATE_CRYSTAL_FRQ_CMD,
417 .data = {
418 (u8)xtal_calib[0],
419 (u8)xtal_calib[1],
420 }
421 };
422
423 return iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
424 sizeof(cal_cmd), &cal_cmd);
425}
426
427static int iwl5000_send_calib_results(struct iwl_priv *priv)
428{
429 int ret = 0;
430
431 struct iwl_host_cmd hcmd = {
432 .id = REPLY_PHY_CALIBRATION_CMD,
433 .meta.flags = CMD_SIZE_HUGE,
434 };
435
436 if (priv->calib_results.lo_res) {
437 hcmd.len = priv->calib_results.lo_res_len;
438 hcmd.data = priv->calib_results.lo_res;
439 ret = iwl_send_cmd_sync(priv, &hcmd);
440
441 if (ret)
442 goto err;
443 }
444
445 if (priv->calib_results.tx_iq_res) {
446 hcmd.len = priv->calib_results.tx_iq_res_len;
447 hcmd.data = priv->calib_results.tx_iq_res;
448 ret = iwl_send_cmd_sync(priv, &hcmd);
449
450 if (ret)
451 goto err;
452 }
453
454 if (priv->calib_results.tx_iq_perd_res) {
455 hcmd.len = priv->calib_results.tx_iq_perd_res_len;
456 hcmd.data = priv->calib_results.tx_iq_perd_res;
457 ret = iwl_send_cmd_sync(priv, &hcmd);
458
459 if (ret)
460 goto err;
461 }
462
463 return 0;
464err:
465 IWL_ERROR("Error %d\n", ret);
466 return ret;
467}
468
469static int iwl5000_send_calib_cfg(struct iwl_priv *priv)
470{
471 struct iwl5000_calib_cfg_cmd calib_cfg_cmd;
472 struct iwl_host_cmd cmd = {
473 .id = CALIBRATION_CFG_CMD,
474 .len = sizeof(struct iwl5000_calib_cfg_cmd),
475 .data = &calib_cfg_cmd,
476 };
477
478 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
479 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
480 calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
481 calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
482 calib_cfg_cmd.ucd_calib_cfg.flags = IWL_CALIB_INIT_CFG_ALL;
483
484 return iwl_send_cmd(priv, &cmd);
485}
486
487static void iwl5000_rx_calib_result(struct iwl_priv *priv,
488 struct iwl_rx_mem_buffer *rxb)
489{
490 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
491 struct iwl5000_calib_hdr *hdr = (struct iwl5000_calib_hdr *)pkt->u.raw;
492 int len = le32_to_cpu(pkt->len) & FH_RSCSR_FRAME_SIZE_MSK;
493
494 iwl_free_calib_results(priv);
495
496 /* reduce the size of the length field itself */
497 len -= 4;
498
499 switch (hdr->op_code) {
500 case IWL5000_PHY_CALIBRATE_LO_CMD:
501 priv->calib_results.lo_res = kzalloc(len, GFP_ATOMIC);
502 priv->calib_results.lo_res_len = len;
503 memcpy(priv->calib_results.lo_res, pkt->u.raw, len);
504 break;
505 case IWL5000_PHY_CALIBRATE_TX_IQ_CMD:
506 priv->calib_results.tx_iq_res = kzalloc(len, GFP_ATOMIC);
507 priv->calib_results.tx_iq_res_len = len;
508 memcpy(priv->calib_results.tx_iq_res, pkt->u.raw, len);
509 break;
510 case IWL5000_PHY_CALIBRATE_TX_IQ_PERD_CMD:
511 priv->calib_results.tx_iq_perd_res = kzalloc(len, GFP_ATOMIC);
512 priv->calib_results.tx_iq_perd_res_len = len;
513 memcpy(priv->calib_results.tx_iq_perd_res, pkt->u.raw, len);
514 break;
515 default:
516 IWL_ERROR("Unknown calibration notification %d\n",
517 hdr->op_code);
518 return;
519 }
520}
521
522static void iwl5000_rx_calib_complete(struct iwl_priv *priv,
523 struct iwl_rx_mem_buffer *rxb)
524{
525 IWL_DEBUG_INFO("Init. calibration is completed, restarting fw.\n");
526 queue_work(priv->workqueue, &priv->restart);
527}
528
529/*
530 * ucode
531 */
532static int iwl5000_load_section(struct iwl_priv *priv,
533 struct fw_desc *image,
534 u32 dst_addr)
535{
536 int ret = 0;
537 unsigned long flags;
538
539 dma_addr_t phy_addr = image->p_addr;
540 u32 byte_cnt = image->len;
541
542 spin_lock_irqsave(&priv->lock, flags);
543 ret = iwl_grab_nic_access(priv);
544 if (ret) {
545 spin_unlock_irqrestore(&priv->lock, flags);
546 return ret;
547 }
548
549 iwl_write_direct32(priv,
550 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
551 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
552
553 iwl_write_direct32(priv,
554 FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
555
556 iwl_write_direct32(priv,
557 FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
558 phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
559
560 /* FIME: write the MSB of the phy_addr in CTRL1
561 * iwl_write_direct32(priv,
562 IWL_FH_TFDIB_CTRL1_REG(IWL_FH_SRVC_CHNL),
563 ((phy_addr & MSB_MSK)
564 << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_count);
565 */
566 iwl_write_direct32(priv,
567 FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL), byte_cnt);
568 iwl_write_direct32(priv,
569 FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
570 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
571 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
572 FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
573
574 iwl_write_direct32(priv,
575 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
576 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
577 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL |
578 FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
579
580 iwl_release_nic_access(priv);
581 spin_unlock_irqrestore(&priv->lock, flags);
582 return 0;
583}
584
585static int iwl5000_load_given_ucode(struct iwl_priv *priv,
586 struct fw_desc *inst_image,
587 struct fw_desc *data_image)
588{
589 int ret = 0;
590
591 ret = iwl5000_load_section(
592 priv, inst_image, RTC_INST_LOWER_BOUND);
593 if (ret)
594 return ret;
595
596 IWL_DEBUG_INFO("INST uCode section being loaded...\n");
597 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
598 priv->ucode_write_complete, 5 * HZ);
599 if (ret == -ERESTARTSYS) {
600 IWL_ERROR("Could not load the INST uCode section due "
601 "to interrupt\n");
602 return ret;
603 }
604 if (!ret) {
605 IWL_ERROR("Could not load the INST uCode section\n");
606 return -ETIMEDOUT;
607 }
608
609 priv->ucode_write_complete = 0;
610
611 ret = iwl5000_load_section(
612 priv, data_image, RTC_DATA_LOWER_BOUND);
613 if (ret)
614 return ret;
615
616 IWL_DEBUG_INFO("DATA uCode section being loaded...\n");
617
618 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
619 priv->ucode_write_complete, 5 * HZ);
620 if (ret == -ERESTARTSYS) {
621 IWL_ERROR("Could not load the INST uCode section due "
622 "to interrupt\n");
623 return ret;
624 } else if (!ret) {
625 IWL_ERROR("Could not load the DATA uCode section\n");
626 return -ETIMEDOUT;
627 } else
628 ret = 0;
629
630 priv->ucode_write_complete = 0;
631
632 return ret;
633}
634
635static int iwl5000_load_ucode(struct iwl_priv *priv)
636{
637 int ret = 0;
638
639 /* check whether init ucode should be loaded, or rather runtime ucode */
640 if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
641 IWL_DEBUG_INFO("Init ucode found. Loading init ucode...\n");
642 ret = iwl5000_load_given_ucode(priv,
643 &priv->ucode_init, &priv->ucode_init_data);
644 if (!ret) {
645 IWL_DEBUG_INFO("Init ucode load complete.\n");
646 priv->ucode_type = UCODE_INIT;
647 }
648 } else {
649 IWL_DEBUG_INFO("Init ucode not found, or already loaded. "
650 "Loading runtime ucode...\n");
651 ret = iwl5000_load_given_ucode(priv,
652 &priv->ucode_code, &priv->ucode_data);
653 if (!ret) {
654 IWL_DEBUG_INFO("Runtime ucode load complete.\n");
655 priv->ucode_type = UCODE_RT;
656 }
657 }
658
659 return ret;
660}
661
662static void iwl5000_init_alive_start(struct iwl_priv *priv)
663{
664 int ret = 0;
665
666 /* Check alive response for "valid" sign from uCode */
667 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
668 /* We had an error bringing up the hardware, so take it
669 * all the way back down so we can try again */
670 IWL_DEBUG_INFO("Initialize Alive failed.\n");
671 goto restart;
672 }
673
674 /* initialize uCode was loaded... verify inst image.
675 * This is a paranoid check, because we would not have gotten the
676 * "initialize" alive if code weren't properly loaded. */
677 if (iwl_verify_ucode(priv)) {
678 /* Runtime instruction load was bad;
679 * take it all the way back down so we can try again */
680 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
681 goto restart;
682 }
683
684 iwlcore_clear_stations_table(priv);
685 ret = priv->cfg->ops->lib->alive_notify(priv);
686 if (ret) {
687 IWL_WARNING("Could not complete ALIVE transition: %d\n", ret);
688 goto restart;
689 }
690
691 iwl5000_send_calib_cfg(priv);
692 return;
693
694restart:
695 /* real restart (first load init_ucode) */
696 queue_work(priv->workqueue, &priv->restart);
697}
698
699static void iwl5000_set_wr_ptrs(struct iwl_priv *priv,
700 int txq_id, u32 index)
701{
702 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
703 (index & 0xff) | (txq_id << 8));
704 iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(txq_id), index);
705}
706
707static void iwl5000_tx_queue_set_status(struct iwl_priv *priv,
708 struct iwl_tx_queue *txq,
709 int tx_fifo_id, int scd_retry)
710{
711 int txq_id = txq->q.id;
712 int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
713
714 iwl_write_prph(priv, IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
715 (active << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
716 (tx_fifo_id << IWL50_SCD_QUEUE_STTS_REG_POS_TXF) |
717 (1 << IWL50_SCD_QUEUE_STTS_REG_POS_WSL) |
718 IWL50_SCD_QUEUE_STTS_REG_MSK);
719
720 txq->sched_retry = scd_retry;
721
722 IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
723 active ? "Activate" : "Deactivate",
724 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
725}
726
727static int iwl5000_send_wimax_coex(struct iwl_priv *priv)
728{
729 struct iwl_wimax_coex_cmd coex_cmd;
730
731 memset(&coex_cmd, 0, sizeof(coex_cmd));
732
733 return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
734 sizeof(coex_cmd), &coex_cmd);
735}
736
737static int iwl5000_alive_notify(struct iwl_priv *priv)
738{
739 u32 a;
740 int i = 0;
741 unsigned long flags;
742 int ret;
743
744 spin_lock_irqsave(&priv->lock, flags);
745
746 ret = iwl_grab_nic_access(priv);
747 if (ret) {
748 spin_unlock_irqrestore(&priv->lock, flags);
749 return ret;
750 }
751
752 priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR);
753 a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET;
754 for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET;
755 a += 4)
756 iwl_write_targ_mem(priv, a, 0);
757 for (; a < priv->scd_base_addr + IWL50_SCD_TRANSLATE_TBL_OFFSET;
758 a += 4)
759 iwl_write_targ_mem(priv, a, 0);
760 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
761 iwl_write_targ_mem(priv, a, 0);
762
763 iwl_write_prph(priv, IWL50_SCD_DRAM_BASE_ADDR,
764 (priv->shared_phys +
765 offsetof(struct iwl5000_shared, queues_byte_cnt_tbls)) >> 10);
766 iwl_write_prph(priv, IWL50_SCD_QUEUECHAIN_SEL,
767 IWL50_SCD_QUEUECHAIN_SEL_ALL(
768 priv->hw_params.max_txq_num));
769 iwl_write_prph(priv, IWL50_SCD_AGGR_SEL, 0);
770
771 /* initiate the queues */
772 for (i = 0; i < priv->hw_params.max_txq_num; i++) {
773 iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(i), 0);
774 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
775 iwl_write_targ_mem(priv, priv->scd_base_addr +
776 IWL50_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
777 iwl_write_targ_mem(priv, priv->scd_base_addr +
778 IWL50_SCD_CONTEXT_QUEUE_OFFSET(i) +
779 sizeof(u32),
780 ((SCD_WIN_SIZE <<
781 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
782 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
783 ((SCD_FRAME_LIMIT <<
784 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
785 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
786 }
787
788 iwl_write_prph(priv, IWL50_SCD_INTERRUPT_MASK,
789 IWL_MASK(0, priv->hw_params.max_txq_num));
790
791 /* Activate all Tx DMA/FIFO channels */
792 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
793
794 iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
795 /* map qos queues to fifos one-to-one */
796 for (i = 0; i < ARRAY_SIZE(iwl5000_default_queue_to_tx_fifo); i++) {
797 int ac = iwl5000_default_queue_to_tx_fifo[i];
798 iwl_txq_ctx_activate(priv, i);
799 iwl5000_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
800 }
801 /* TODO - need to initialize those FIFOs inside the loop above,
802 * not only mark them as active */
803 iwl_txq_ctx_activate(priv, 4);
804 iwl_txq_ctx_activate(priv, 7);
805 iwl_txq_ctx_activate(priv, 8);
806 iwl_txq_ctx_activate(priv, 9);
807
808 iwl_release_nic_access(priv);
809 spin_unlock_irqrestore(&priv->lock, flags);
810
811
812 iwl5000_send_wimax_coex(priv);
813
814 iwl5000_send_Xtal_calib(priv);
815
816 if (priv->ucode_type == UCODE_RT) {
817 iwl5000_send_calib_results(priv);
818 set_bit(STATUS_READY, &priv->status);
819 priv->is_open = 1;
820 }
821
822 return 0;
823}
824
290static int iwl5000_hw_set_hw_params(struct iwl_priv *priv) 825static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
291{ 826{
292 if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) || 827 if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
@@ -298,7 +833,6 @@ static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
298 833
299 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues; 834 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
300 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto; 835 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
301 priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd);
302 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE; 836 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
303 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG; 837 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
304 if (priv->cfg->mod_params->amsdu_size_8K) 838 if (priv->cfg->mod_params->amsdu_size_8K)
@@ -430,6 +964,26 @@ static void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
430 } 964 }
431} 965}
432 966
967static void iwl5000_txq_inval_byte_cnt_tbl(struct iwl_priv *priv,
968 struct iwl_tx_queue *txq)
969{
970 int txq_id = txq->q.id;
971 struct iwl5000_shared *shared_data = priv->shared_virt;
972 u8 sta = 0;
973
974 if (txq_id != IWL_CMD_QUEUE_NUM)
975 sta = txq->cmd[txq->q.read_ptr].cmd.tx.sta_id;
976
977 shared_data->queues_byte_cnt_tbls[txq_id].tfd_offset[txq->q.read_ptr].
978 val = cpu_to_le16(1 | (sta << 12));
979
980 if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
981 shared_data->queues_byte_cnt_tbls[txq_id].
982 tfd_offset[IWL50_QUEUE_SIZE + txq->q.read_ptr].
983 val = cpu_to_le16(1 | (sta << 12));
984 }
985}
986
433static u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data) 987static u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
434{ 988{
435 u16 size = (u16)sizeof(struct iwl_addsta_cmd); 989 u16 size = (u16)sizeof(struct iwl_addsta_cmd);
@@ -438,31 +992,326 @@ static u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
438} 992}
439 993
440 994
441static int iwl5000_disable_tx_fifo(struct iwl_priv *priv) 995/*
996 * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
997 * must be called under priv->lock and mac access
998 */
999static void iwl5000_txq_set_sched(struct iwl_priv *priv, u32 mask)
442{ 1000{
443 unsigned long flags; 1001 iwl_write_prph(priv, IWL50_SCD_TXFACT, mask);
444 int ret; 1002}
445 1003
446 spin_lock_irqsave(&priv->lock, flags);
447 1004
448 ret = iwl_grab_nic_access(priv); 1005static inline u32 iwl5000_get_scd_ssn(struct iwl5000_tx_resp *tx_resp)
449 if (unlikely(ret)) { 1006{
450 IWL_ERROR("Tx fifo reset failed"); 1007 __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
451 spin_unlock_irqrestore(&priv->lock, flags); 1008 tx_resp->frame_count);
452 return ret; 1009 return le32_to_cpu(*scd_ssn) & MAX_SN;
453 }
454 1010
455 iwl_write_prph(priv, IWL50_SCD_TXFACT, 0); 1011}
456 iwl_release_nic_access(priv); 1012
457 spin_unlock_irqrestore(&priv->lock, flags); 1013static int iwl5000_tx_status_reply_tx(struct iwl_priv *priv,
1014 struct iwl_ht_agg *agg,
1015 struct iwl5000_tx_resp *tx_resp,
1016 u16 start_idx)
1017{
1018 u16 status;
1019 struct agg_tx_status *frame_status = &tx_resp->status;
1020 struct ieee80211_tx_info *info = NULL;
1021 struct ieee80211_hdr *hdr = NULL;
1022 int i, sh;
1023 int txq_id, idx;
1024 u16 seq;
1025
1026 if (agg->wait_for_ba)
1027 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
1028
1029 agg->frame_count = tx_resp->frame_count;
1030 agg->start_idx = start_idx;
1031 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
1032 agg->bitmap = 0;
1033
1034 /* # frames attempted by Tx command */
1035 if (agg->frame_count == 1) {
1036 /* Only one frame was attempted; no block-ack will arrive */
1037 status = le16_to_cpu(frame_status[0].status);
1038 seq = le16_to_cpu(frame_status[0].sequence);
1039 idx = SEQ_TO_INDEX(seq);
1040 txq_id = SEQ_TO_QUEUE(seq);
1041
1042 /* FIXME: code repetition */
1043 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
1044 agg->frame_count, agg->start_idx, idx);
1045
1046 info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
1047 info->status.retry_count = tx_resp->failure_frame;
1048 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
1049 info->flags |= iwl_is_tx_success(status)?
1050 IEEE80211_TX_STAT_ACK : 0;
1051 iwl4965_hwrate_to_tx_control(priv,
1052 le32_to_cpu(tx_resp->rate_n_flags),
1053 info);
1054 /* FIXME: code repetition end */
1055
1056 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
1057 status & 0xff, tx_resp->failure_frame);
1058 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
1059 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
1060
1061 agg->wait_for_ba = 0;
1062 } else {
1063 /* Two or more frames were attempted; expect block-ack */
1064 u64 bitmap = 0;
1065 int start = agg->start_idx;
1066
1067 /* Construct bit-map of pending frames within Tx window */
1068 for (i = 0; i < agg->frame_count; i++) {
1069 u16 sc;
1070 status = le16_to_cpu(frame_status[i].status);
1071 seq = le16_to_cpu(frame_status[i].sequence);
1072 idx = SEQ_TO_INDEX(seq);
1073 txq_id = SEQ_TO_QUEUE(seq);
1074
1075 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
1076 AGG_TX_STATE_ABORT_MSK))
1077 continue;
1078
1079 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
1080 agg->frame_count, txq_id, idx);
1081
1082 hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
1083
1084 sc = le16_to_cpu(hdr->seq_ctrl);
1085 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
1086 IWL_ERROR("BUG_ON idx doesn't match seq control"
1087 " idx=%d, seq_idx=%d, seq=%d\n",
1088 idx, SEQ_TO_SN(sc),
1089 hdr->seq_ctrl);
1090 return -1;
1091 }
1092
1093 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
1094 i, idx, SEQ_TO_SN(sc));
1095
1096 sh = idx - start;
1097 if (sh > 64) {
1098 sh = (start - idx) + 0xff;
1099 bitmap = bitmap << sh;
1100 sh = 0;
1101 start = idx;
1102 } else if (sh < -64)
1103 sh = 0xff - (start - idx);
1104 else if (sh < 0) {
1105 sh = start - idx;
1106 start = idx;
1107 bitmap = bitmap << sh;
1108 sh = 0;
1109 }
1110 bitmap |= (1 << sh);
1111 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
1112 start, (u32)(bitmap & 0xFFFFFFFF));
1113 }
1114
1115 agg->bitmap = bitmap;
1116 agg->start_idx = start;
1117 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
1118 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
1119 agg->frame_count, agg->start_idx,
1120 (unsigned long long)agg->bitmap);
458 1121
1122 if (bitmap)
1123 agg->wait_for_ba = 1;
1124 }
459 return 0; 1125 return 0;
460} 1126}
461 1127
1128static void iwl5000_rx_reply_tx(struct iwl_priv *priv,
1129 struct iwl_rx_mem_buffer *rxb)
1130{
1131 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1132 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1133 int txq_id = SEQ_TO_QUEUE(sequence);
1134 int index = SEQ_TO_INDEX(sequence);
1135 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1136 struct ieee80211_tx_info *info;
1137 struct iwl5000_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
1138 u32 status = le16_to_cpu(tx_resp->status.status);
1139#ifdef CONFIG_IWL4965_HT
1140 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
1141 u16 fc;
1142 struct ieee80211_hdr *hdr;
1143 u8 *qc = NULL;
1144#endif
1145
1146 if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
1147 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
1148 "is out of range [0-%d] %d %d\n", txq_id,
1149 index, txq->q.n_bd, txq->q.write_ptr,
1150 txq->q.read_ptr);
1151 return;
1152 }
1153
1154 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
1155 memset(&info->status, 0, sizeof(info->status));
1156
1157#ifdef CONFIG_IWL4965_HT
1158 hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
1159 fc = le16_to_cpu(hdr->frame_control);
1160 if (ieee80211_is_qos_data(fc)) {
1161 qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
1162 tid = qc[0] & 0xf;
1163 }
1164
1165 sta_id = iwl_get_ra_sta_id(priv, hdr);
1166 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
1167 IWL_ERROR("Station not known\n");
1168 return;
1169 }
1170
1171 if (txq->sched_retry) {
1172 const u32 scd_ssn = iwl5000_get_scd_ssn(tx_resp);
1173 struct iwl_ht_agg *agg = NULL;
1174
1175 if (!qc)
1176 return;
1177
1178 agg = &priv->stations[sta_id].tid[tid].agg;
1179
1180 iwl5000_tx_status_reply_tx(priv, agg, tx_resp, index);
1181
1182 if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status)) {
1183 /* TODO: send BAR */
1184 }
1185
1186 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
1187 int freed, ampdu_q;
1188 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
1189 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
1190 "%d index %d\n", scd_ssn , index);
1191 freed = iwl_tx_queue_reclaim(priv, txq_id, index);
1192 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
1193
1194 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
1195 txq_id >= 0 && priv->mac80211_registered &&
1196 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
1197 /* calculate mac80211 ampdu sw queue to wake */
1198 ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID +
1199 priv->hw->queues;
1200 if (agg->state == IWL_AGG_OFF)
1201 ieee80211_wake_queue(priv->hw, txq_id);
1202 else
1203 ieee80211_wake_queue(priv->hw, ampdu_q);
1204 }
1205 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
1206 }
1207 } else {
1208#endif /* CONFIG_IWL4965_HT */
1209
1210 info->status.retry_count = tx_resp->failure_frame;
1211 info->flags = iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
1212 iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
1213 info);
1214
1215 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
1216 "retries %d\n", txq_id, iwl_get_tx_fail_reason(status),
1217 status, le32_to_cpu(tx_resp->rate_n_flags),
1218 tx_resp->failure_frame);
1219
1220 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
1221#ifdef CONFIG_IWL4965_HT
1222 if (index != -1) {
1223 int freed = iwl_tx_queue_reclaim(priv, txq_id, index);
1224 if (tid != MAX_TID_COUNT)
1225 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
1226 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
1227 (txq_id >= 0) && priv->mac80211_registered)
1228 ieee80211_wake_queue(priv->hw, txq_id);
1229 if (tid != MAX_TID_COUNT)
1230 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
1231 }
1232 }
1233#endif /* CONFIG_IWL4965_HT */
1234
1235 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
1236 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
1237}
1238
1239/* Currently 5000 is the supperset of everything */
1240static u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
1241{
1242 return len;
1243}
1244
1245static void iwl5000_rx_handler_setup(struct iwl_priv *priv)
1246{
1247 /* init calibration handlers */
1248 priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
1249 iwl5000_rx_calib_result;
1250 priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
1251 iwl5000_rx_calib_complete;
1252 priv->rx_handlers[REPLY_TX] = iwl5000_rx_reply_tx;
1253}
1254
1255
1256static int iwl5000_hw_valid_rtc_data_addr(u32 addr)
1257{
1258 return (addr >= RTC_DATA_LOWER_BOUND) &&
1259 (addr < IWL50_RTC_DATA_UPPER_BOUND);
1260}
1261
1262static int iwl5000_send_rxon_assoc(struct iwl_priv *priv)
1263{
1264 int ret = 0;
1265 struct iwl5000_rxon_assoc_cmd rxon_assoc;
1266 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1267 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
1268
1269 if ((rxon1->flags == rxon2->flags) &&
1270 (rxon1->filter_flags == rxon2->filter_flags) &&
1271 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1272 (rxon1->ofdm_ht_single_stream_basic_rates ==
1273 rxon2->ofdm_ht_single_stream_basic_rates) &&
1274 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1275 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1276 (rxon1->ofdm_ht_triple_stream_basic_rates ==
1277 rxon2->ofdm_ht_triple_stream_basic_rates) &&
1278 (rxon1->acquisition_data == rxon2->acquisition_data) &&
1279 (rxon1->rx_chain == rxon2->rx_chain) &&
1280 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1281 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1282 return 0;
1283 }
1284
1285 rxon_assoc.flags = priv->staging_rxon.flags;
1286 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1287 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1288 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1289 rxon_assoc.reserved1 = 0;
1290 rxon_assoc.reserved2 = 0;
1291 rxon_assoc.reserved3 = 0;
1292 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1293 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1294 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1295 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1296 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1297 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
1298 priv->staging_rxon.ofdm_ht_triple_stream_basic_rates;
1299 rxon_assoc.acquisition_data = priv->staging_rxon.acquisition_data;
1300
1301 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
1302 sizeof(rxon_assoc), &rxon_assoc, NULL);
1303 if (ret)
1304 return ret;
1305
1306 return ret;
1307}
1308
462static struct iwl_hcmd_ops iwl5000_hcmd = { 1309static struct iwl_hcmd_ops iwl5000_hcmd = {
1310 .rxon_assoc = iwl5000_send_rxon_assoc,
463}; 1311};
464 1312
465static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = { 1313static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
1314 .get_hcmd_size = iwl5000_get_hcmd_size,
466 .build_addsta_hcmd = iwl5000_build_addsta_hcmd, 1315 .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
467#ifdef CONFIG_IWL5000_RUN_TIME_CALIB 1316#ifdef CONFIG_IWL5000_RUN_TIME_CALIB
468 .gain_computation = iwl5000_gain_computation, 1317 .gain_computation = iwl5000_gain_computation,
@@ -476,9 +1325,17 @@ static struct iwl_lib_ops iwl5000_lib = {
476 .free_shared_mem = iwl5000_free_shared_mem, 1325 .free_shared_mem = iwl5000_free_shared_mem,
477 .shared_mem_rx_idx = iwl5000_shared_mem_rx_idx, 1326 .shared_mem_rx_idx = iwl5000_shared_mem_rx_idx,
478 .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl, 1327 .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
479 .disable_tx_fifo = iwl5000_disable_tx_fifo, 1328 .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
1329 .txq_set_sched = iwl5000_txq_set_sched,
1330 .rx_handler_setup = iwl5000_rx_handler_setup,
1331 .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
1332 .load_ucode = iwl5000_load_ucode,
1333 .init_alive_start = iwl5000_init_alive_start,
1334 .alive_notify = iwl5000_alive_notify,
480 .apm_ops = { 1335 .apm_ops = {
481 .init = iwl5000_apm_init, 1336 .init = iwl5000_apm_init,
1337 .reset = iwl5000_apm_reset,
1338 .stop = iwl5000_apm_stop,
482 .config = iwl5000_nic_config, 1339 .config = iwl5000_nic_config,
483 .set_pwr_src = iwl4965_set_pwr_src, 1340 .set_pwr_src = iwl4965_set_pwr_src,
484 }, 1341 },
diff --git a/drivers/net/wireless/iwlwifi/iwl-calib.c b/drivers/net/wireless/iwlwifi/iwl-calib.c
index 1289d4c91abe..a6c7f0d9a414 100644
--- a/drivers/net/wireless/iwlwifi/iwl-calib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-calib.c
@@ -426,6 +426,9 @@ void iwl_init_sensitivity(struct iwl_priv *priv)
426 struct iwl_sensitivity_data *data = NULL; 426 struct iwl_sensitivity_data *data = NULL;
427 const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens; 427 const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
428 428
429 if (priv->disable_sens_cal)
430 return;
431
429 IWL_DEBUG_CALIB("Start iwl_init_sensitivity\n"); 432 IWL_DEBUG_CALIB("Start iwl_init_sensitivity\n");
430 433
431 /* Clear driver's sensitivity algo data */ 434 /* Clear driver's sensitivity algo data */
@@ -486,6 +489,9 @@ void iwl_sensitivity_calibration(struct iwl_priv *priv,
486 unsigned long flags; 489 unsigned long flags;
487 struct statistics_general_data statis; 490 struct statistics_general_data statis;
488 491
492 if (priv->disable_sens_cal)
493 return;
494
489 data = &(priv->sensitivity_data); 495 data = &(priv->sensitivity_data);
490 496
491 if (!iwl_is_associated(priv)) { 497 if (!iwl_is_associated(priv)) {
@@ -608,6 +614,9 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv,
608 unsigned long flags; 614 unsigned long flags;
609 struct statistics_rx_non_phy *rx_info = &(stat_resp->rx.general); 615 struct statistics_rx_non_phy *rx_info = &(stat_resp->rx.general);
610 616
617 if (priv->disable_chain_noise_cal)
618 return;
619
611 data = &(priv->chain_noise_data); 620 data = &(priv->chain_noise_data);
612 621
613 /* Accumulate just the first 20 beacons after the first association, 622 /* Accumulate just the first 20 beacons after the first association,
@@ -777,3 +786,21 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv,
777} 786}
778EXPORT_SYMBOL(iwl_chain_noise_calibration); 787EXPORT_SYMBOL(iwl_chain_noise_calibration);
779 788
789
790void iwl_reset_run_time_calib(struct iwl_priv *priv)
791{
792 int i;
793 memset(&(priv->sensitivity_data), 0,
794 sizeof(struct iwl_sensitivity_data));
795 memset(&(priv->chain_noise_data), 0,
796 sizeof(struct iwl_chain_noise_data));
797 for (i = 0; i < NUM_RX_CHAINS; i++)
798 priv->chain_noise_data.delta_gain_code[i] =
799 CHAIN_NOISE_DELTA_GAIN_INIT_VAL;
800
801 /* Ask for statistics now, the uCode will send notification
802 * periodically after association */
803 iwl_send_statistics_request(priv, CMD_ASYNC);
804}
805EXPORT_SYMBOL(iwl_reset_run_time_calib);
806
diff --git a/drivers/net/wireless/iwlwifi/iwl-calib.h b/drivers/net/wireless/iwlwifi/iwl-calib.h
index 933b0b0a797b..b8e57c59eac8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-calib.h
+++ b/drivers/net/wireless/iwlwifi/iwl-calib.h
@@ -78,10 +78,12 @@ void iwl_sensitivity_calibration(struct iwl_priv *priv,
78 struct iwl4965_notif_statistics *resp); 78 struct iwl4965_notif_statistics *resp);
79 79
80void iwl_init_sensitivity(struct iwl_priv *priv); 80void iwl_init_sensitivity(struct iwl_priv *priv);
81 81void iwl_reset_run_time_calib(struct iwl_priv *priv);
82static inline void iwl_chain_noise_reset(struct iwl_priv *priv) 82static inline void iwl_chain_noise_reset(struct iwl_priv *priv)
83{ 83{
84 if (priv->cfg->ops->utils->chain_noise_reset) 84
85 if (!priv->disable_chain_noise_cal &&
86 priv->cfg->ops->utils->chain_noise_reset)
85 priv->cfg->ops->utils->chain_noise_reset(priv); 87 priv->cfg->ops->utils->chain_noise_reset(priv);
86} 88}
87#else 89#else
@@ -99,6 +101,9 @@ static inline void iwl_init_sensitivity(struct iwl_priv *priv)
99static inline void iwl_chain_noise_reset(struct iwl_priv *priv) 101static inline void iwl_chain_noise_reset(struct iwl_priv *priv)
100{ 102{
101} 103}
104static inline void iwl_reset_run_time_calib(struct iwl_priv *priv)
105{
106}
102#endif 107#endif
103 108
104#endif /* __iwl_calib_h__ */ 109#endif /* __iwl_calib_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index d16a853f376a..fb6f5ffb9f1d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -93,6 +93,11 @@ enum {
93 REPLY_LEDS_CMD = 0x48, 93 REPLY_LEDS_CMD = 0x48,
94 REPLY_TX_LINK_QUALITY_CMD = 0x4e, /* 4965 only */ 94 REPLY_TX_LINK_QUALITY_CMD = 0x4e, /* 4965 only */
95 95
96 /* WiMAX coexistence */
97 COEX_PRIORITY_TABLE_CMD = 0x5a, /*5000 only */
98 COEX_MEDIUM_NOTIFICATION = 0x5b,
99 COEX_EVENT_CMD = 0x5c,
100
96 /* 802.11h related */ 101 /* 802.11h related */
97 RADAR_NOTIFICATION = 0x70, /* not used */ 102 RADAR_NOTIFICATION = 0x70, /* not used */
98 REPLY_QUIET_CMD = 0x71, /* not used */ 103 REPLY_QUIET_CMD = 0x71, /* not used */
@@ -368,7 +373,7 @@ struct iwl4965_tx_power_db {
368 * 3) Tx gain compensation to balance 4965's 2 Tx chains for MIMO operation, 373 * 3) Tx gain compensation to balance 4965's 2 Tx chains for MIMO operation,
369 * for each of 5 frequency ranges. 374 * for each of 5 frequency ranges.
370 */ 375 */
371struct iwl4965_init_alive_resp { 376struct iwl_init_alive_resp {
372 u8 ucode_minor; 377 u8 ucode_minor;
373 u8 ucode_major; 378 u8 ucode_major;
374 __le16 reserved1; 379 __le16 reserved1;
@@ -444,7 +449,7 @@ struct iwl4965_init_alive_resp {
444 * The Linux driver can print both logs to the system log when a uCode error 449 * The Linux driver can print both logs to the system log when a uCode error
445 * occurs. 450 * occurs.
446 */ 451 */
447struct iwl4965_alive_resp { 452struct iwl_alive_resp {
448 u8 ucode_minor; 453 u8 ucode_minor;
449 u8 ucode_major; 454 u8 ucode_major;
450 __le16 reserved1; 455 __le16 reserved1;
@@ -468,7 +473,7 @@ union tsf {
468/* 473/*
469 * REPLY_ERROR = 0x2 (response only, not a command) 474 * REPLY_ERROR = 0x2 (response only, not a command)
470 */ 475 */
471struct iwl4965_error_resp { 476struct iwl_error_resp {
472 __le32 error_type; 477 __le32 error_type;
473 u8 cmd_id; 478 u8 cmd_id;
474 u8 reserved1; 479 u8 reserved1;
@@ -600,6 +605,46 @@ struct iwl4965_rxon_cmd {
600 u8 ofdm_ht_dual_stream_basic_rates; 605 u8 ofdm_ht_dual_stream_basic_rates;
601} __attribute__ ((packed)); 606} __attribute__ ((packed));
602 607
608/* 5000 HW just extend this cmmand */
609struct iwl_rxon_cmd {
610 u8 node_addr[6];
611 __le16 reserved1;
612 u8 bssid_addr[6];
613 __le16 reserved2;
614 u8 wlap_bssid_addr[6];
615 __le16 reserved3;
616 u8 dev_type;
617 u8 air_propagation;
618 __le16 rx_chain;
619 u8 ofdm_basic_rates;
620 u8 cck_basic_rates;
621 __le16 assoc_id;
622 __le32 flags;
623 __le32 filter_flags;
624 __le16 channel;
625 u8 ofdm_ht_single_stream_basic_rates;
626 u8 ofdm_ht_dual_stream_basic_rates;
627 u8 ofdm_ht_triple_stream_basic_rates;
628 u8 reserved5;
629 __le16 acquisition_data;
630 __le16 reserved6;
631} __attribute__ ((packed));
632
633struct iwl5000_rxon_assoc_cmd {
634 __le32 flags;
635 __le32 filter_flags;
636 u8 ofdm_basic_rates;
637 u8 cck_basic_rates;
638 __le16 reserved1;
639 u8 ofdm_ht_single_stream_basic_rates;
640 u8 ofdm_ht_dual_stream_basic_rates;
641 u8 ofdm_ht_triple_stream_basic_rates;
642 u8 reserved2;
643 __le16 rx_chain_select_flags;
644 __le16 acquisition_data;
645 __le32 reserved3;
646} __attribute__ ((packed));
647
603/* 648/*
604 * REPLY_RXON_ASSOC = 0x11 (command, has simple generic response) 649 * REPLY_RXON_ASSOC = 0x11 (command, has simple generic response)
605 */ 650 */
@@ -614,6 +659,9 @@ struct iwl4965_rxon_assoc_cmd {
614 __le16 reserved; 659 __le16 reserved;
615} __attribute__ ((packed)); 660} __attribute__ ((packed));
616 661
662
663
664
617/* 665/*
618 * REPLY_RXON_TIMING = 0x14 (command, has simple generic response) 666 * REPLY_RXON_TIMING = 0x14 (command, has simple generic response)
619 */ 667 */
@@ -897,10 +945,28 @@ struct iwl_addsta_cmd {
897/* 945/*
898 * REPLY_ADD_STA = 0x18 (response) 946 * REPLY_ADD_STA = 0x18 (response)
899 */ 947 */
900struct iwl4965_add_sta_resp { 948struct iwl_add_sta_resp {
901 u8 status; /* ADD_STA_* */ 949 u8 status; /* ADD_STA_* */
902} __attribute__ ((packed)); 950} __attribute__ ((packed));
903 951
952#define REM_STA_SUCCESS_MSK 0x1
953/*
954 * REPLY_REM_STA = 0x19 (response)
955 */
956struct iwl_rem_sta_resp {
957 u8 status;
958} __attribute__ ((packed));
959
960/*
961 * REPLY_REM_STA = 0x19 (command)
962 */
963struct iwl_rem_sta_cmd {
964 u8 num_sta; /* number of removed stations */
965 u8 reserved[3];
966 u8 addr[ETH_ALEN]; /* MAC addr of the first station */
967 u8 reserved2[2];
968} __attribute__ ((packed));
969
904/* 970/*
905 * REPLY_WEP_KEY = 0x20 971 * REPLY_WEP_KEY = 0x20
906 */ 972 */
@@ -1170,7 +1236,7 @@ struct iwl4965_dram_scratch {
1170/* 1236/*
1171 * REPLY_TX = 0x1c (command) 1237 * REPLY_TX = 0x1c (command)
1172 */ 1238 */
1173struct iwl4965_tx_cmd { 1239struct iwl_tx_cmd {
1174 /* 1240 /*
1175 * MPDU byte count: 1241 * MPDU byte count:
1176 * MAC header (24/26/30/32 bytes) + 2 bytes pad if 26/30 header size, 1242 * MAC header (24/26/30/32 bytes) + 2 bytes pad if 26/30 header size,
@@ -1316,6 +1382,15 @@ enum {
1316 TX_ABORT_REQUIRED_MSK = 0x80000000, /* bits 31:31 */ 1382 TX_ABORT_REQUIRED_MSK = 0x80000000, /* bits 31:31 */
1317}; 1383};
1318 1384
1385static inline int iwl_is_tx_success(u32 status)
1386{
1387 status &= TX_STATUS_MSK;
1388 return (status == TX_STATUS_SUCCESS)
1389 || (status == TX_STATUS_DIRECT_DONE);
1390}
1391
1392
1393
1319/* ******************************* 1394/* *******************************
1320 * TX aggregation status 1395 * TX aggregation status
1321 ******************************* */ 1396 ******************************* */
@@ -1370,6 +1445,11 @@ enum {
1370 * within the sending station (this 4965), rather than whether it was 1445 * within the sending station (this 4965), rather than whether it was
1371 * received successfully by the destination station. 1446 * received successfully by the destination station.
1372 */ 1447 */
1448struct agg_tx_status {
1449 __le16 status;
1450 __le16 sequence;
1451} __attribute__ ((packed));
1452
1373struct iwl4965_tx_resp { 1453struct iwl4965_tx_resp {
1374 u8 frame_count; /* 1 no aggregation, >1 aggregation */ 1454 u8 frame_count; /* 1 no aggregation, >1 aggregation */
1375 u8 bt_kill_count; /* # blocked by bluetooth (unused for agg) */ 1455 u8 bt_kill_count; /* # blocked by bluetooth (unused for agg) */
@@ -1404,11 +1484,6 @@ struct iwl4965_tx_resp {
1404 __le32 status; /* TX status (for aggregation status of 1st frame) */ 1484 __le32 status; /* TX status (for aggregation status of 1st frame) */
1405} __attribute__ ((packed)); 1485} __attribute__ ((packed));
1406 1486
1407struct agg_tx_status {
1408 __le16 status;
1409 __le16 sequence;
1410} __attribute__ ((packed));
1411
1412struct iwl4965_tx_resp_agg { 1487struct iwl4965_tx_resp_agg {
1413 u8 frame_count; /* 1 no aggregation, >1 aggregation */ 1488 u8 frame_count; /* 1 no aggregation, >1 aggregation */
1414 u8 reserved1; 1489 u8 reserved1;
@@ -1423,6 +1498,44 @@ struct iwl4965_tx_resp_agg {
1423 /* of 1st frame) */ 1498 /* of 1st frame) */
1424} __attribute__ ((packed)); 1499} __attribute__ ((packed));
1425 1500
1501struct iwl5000_tx_resp {
1502 u8 frame_count; /* 1 no aggregation, >1 aggregation */
1503 u8 bt_kill_count; /* # blocked by bluetooth (unused for agg) */
1504 u8 failure_rts; /* # failures due to unsuccessful RTS */
1505 u8 failure_frame; /* # failures due to no ACK (unused for agg) */
1506
1507 /* For non-agg: Rate at which frame was successful.
1508 * For agg: Rate at which all frames were transmitted. */
1509 __le32 rate_n_flags; /* RATE_MCS_* */
1510
1511 /* For non-agg: RTS + CTS + frame tx attempts time + ACK.
1512 * For agg: RTS + CTS + aggregation tx time + block-ack time. */
1513 __le16 wireless_media_time; /* uSecs */
1514
1515 __le16 reserved;
1516 __le32 pa_power1; /* RF power amplifier measurement (not used) */
1517 __le32 pa_power2;
1518
1519 __le32 tfd_info;
1520 __le16 seq_ctl;
1521 __le16 byte_cnt;
1522 __le32 tlc_info;
1523 /*
1524 * For non-agg: frame status TX_STATUS_*
1525 * For agg: status of 1st frame, AGG_TX_STATE_*; other frame status
1526 * fields follow this one, up to frame_count.
1527 * Bit fields:
1528 * 11- 0: AGG_TX_STATE_* status code
1529 * 15-12: Retry count for 1st frame in aggregation (retries
1530 * occur if tx failed for this frame when it was a
1531 * member of a previous aggregation block). If rate
1532 * scaling is used, retry count indicates the rate
1533 * table entry used for all frames in the new agg.
1534 * 31-16: Sequence # for this frame's Tx cmd (not SSN!)
1535 */
1536 struct agg_tx_status status; /* TX status (in aggregation -
1537 * status of 1st frame) */
1538} __attribute__ ((packed));
1426/* 1539/*
1427 * REPLY_COMPRESSED_BA = 0xc5 (response only, not a command) 1540 * REPLY_COMPRESSED_BA = 0xc5 (response only, not a command)
1428 * 1541 *
@@ -2109,7 +2222,7 @@ struct iwl4965_scan_cmd {
2109 2222
2110 /* For active scans (set to all-0s for passive scans). 2223 /* For active scans (set to all-0s for passive scans).
2111 * Does not include payload. Must specify Tx rate; no rate scaling. */ 2224 * Does not include payload. Must specify Tx rate; no rate scaling. */
2112 struct iwl4965_tx_cmd tx_cmd; 2225 struct iwl_tx_cmd tx_cmd;
2113 2226
2114 /* For directed active scans (set to all-0s otherwise) */ 2227 /* For directed active scans (set to all-0s otherwise) */
2115 struct iwl4965_ssid_ie direct_scan[PROBE_OPTION_MAX]; 2228 struct iwl4965_ssid_ie direct_scan[PROBE_OPTION_MAX];
@@ -2206,7 +2319,7 @@ struct iwl4965_beacon_notif {
2206 * REPLY_TX_BEACON = 0x91 (command, has simple generic response) 2319 * REPLY_TX_BEACON = 0x91 (command, has simple generic response)
2207 */ 2320 */
2208struct iwl4965_tx_beacon_cmd { 2321struct iwl4965_tx_beacon_cmd {
2209 struct iwl4965_tx_cmd tx; 2322 struct iwl_tx_cmd tx;
2210 __le16 tim_idx; 2323 __le16 tim_idx;
2211 u8 tim_size; 2324 u8 tim_size;
2212 u8 reserved1; 2325 u8 reserved1;
@@ -2729,10 +2842,59 @@ enum {
2729 IWL5000_PHY_CALIBRATE_AGC_TABLE_CMD = 14, 2842 IWL5000_PHY_CALIBRATE_AGC_TABLE_CMD = 14,
2730 IWL5000_PHY_CALIBRATE_CRYSTAL_FRQ_CMD = 15, 2843 IWL5000_PHY_CALIBRATE_CRYSTAL_FRQ_CMD = 15,
2731 IWL5000_PHY_CALIBRATE_BASE_BAND_CMD = 16, 2844 IWL5000_PHY_CALIBRATE_BASE_BAND_CMD = 16,
2845 IWL5000_PHY_CALIBRATE_TX_IQ_PERD_CMD = 17,
2732 IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD = 18, 2846 IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD = 18,
2733 IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD = 19, 2847 IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD = 19,
2734}; 2848};
2735 2849
2850enum {
2851 CALIBRATION_CFG_CMD = 0x65,
2852 CALIBRATION_RES_NOTIFICATION = 0x66,
2853 CALIBRATION_COMPLETE_NOTIFICATION = 0x67
2854};
2855
2856struct iwl_cal_crystal_freq_cmd {
2857 u8 cap_pin1;
2858 u8 cap_pin2;
2859} __attribute__ ((packed));
2860
2861struct iwl5000_calibration {
2862 u8 op_code;
2863 u8 first_group;
2864 u8 num_groups;
2865 u8 all_data_valid;
2866 struct iwl_cal_crystal_freq_cmd data;
2867} __attribute__ ((packed));
2868
2869#define IWL_CALIB_INIT_CFG_ALL __constant_cpu_to_le32(0xffffffff)
2870
2871struct iwl_calib_cfg_elmnt_s {
2872 __le32 is_enable;
2873 __le32 start;
2874 __le32 send_res;
2875 __le32 apply_res;
2876 __le32 reserved;
2877} __attribute__ ((packed));
2878
2879struct iwl_calib_cfg_status_s {
2880 struct iwl_calib_cfg_elmnt_s once;
2881 struct iwl_calib_cfg_elmnt_s perd;
2882 __le32 flags;
2883} __attribute__ ((packed));
2884
2885struct iwl5000_calib_cfg_cmd {
2886 struct iwl_calib_cfg_status_s ucd_calib_cfg;
2887 struct iwl_calib_cfg_status_s drv_calib_cfg;
2888 __le32 reserved1;
2889} __attribute__ ((packed));
2890
2891struct iwl5000_calib_hdr {
2892 u8 op_code;
2893 u8 first_group;
2894 u8 groups_num;
2895 u8 data_valid;
2896} __attribute__ ((packed));
2897
2736struct iwl5000_calibration_chain_noise_reset_cmd { 2898struct iwl5000_calibration_chain_noise_reset_cmd {
2737 u8 op_code; /* IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD */ 2899 u8 op_code; /* IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD */
2738 u8 flags; /* not used */ 2900 u8 flags; /* not used */
@@ -2771,6 +2933,55 @@ struct iwl4965_led_cmd {
2771 u8 reserved; 2933 u8 reserved;
2772} __attribute__ ((packed)); 2934} __attribute__ ((packed));
2773 2935
2936/*
2937 * Coexistence WIFI/WIMAX Command
2938 * COEX_PRIORITY_TABLE_CMD = 0x5a
2939 *
2940 */
2941enum {
2942 COEX_UNASSOC_IDLE = 0,
2943 COEX_UNASSOC_MANUAL_SCAN = 1,
2944 COEX_UNASSOC_AUTO_SCAN = 2,
2945 COEX_CALIBRATION = 3,
2946 COEX_PERIODIC_CALIBRATION = 4,
2947 COEX_CONNECTION_ESTAB = 5,
2948 COEX_ASSOCIATED_IDLE = 6,
2949 COEX_ASSOC_MANUAL_SCAN = 7,
2950 COEX_ASSOC_AUTO_SCAN = 8,
2951 COEX_ASSOC_ACTIVE_LEVEL = 9,
2952 COEX_RF_ON = 10,
2953 COEX_RF_OFF = 11,
2954 COEX_STAND_ALONE_DEBUG = 12,
2955 COEX_IPAN_ASSOC_LEVEL = 13,
2956 COEX_RSRVD1 = 14,
2957 COEX_RSRVD2 = 15,
2958 COEX_NUM_OF_EVENTS = 16
2959};
2960
2961struct iwl_wimax_coex_event_entry {
2962 u8 request_prio;
2963 u8 win_medium_prio;
2964 u8 reserved;
2965 u8 flags;
2966} __attribute__ ((packed));
2967
2968/* COEX flag masks */
2969
2970/* Staion table is valid */
2971#define COEX_FLAGS_STA_TABLE_VALID_MSK (0x1)
2972/* UnMask wakeup src at unassociated sleep */
2973#define COEX_FLAGS_UNASSOC_WA_UNMASK_MSK (0x4)
2974/* UnMask wakeup src at associated sleep */
2975#define COEX_FLAGS_ASSOC_WA_UNMASK_MSK (0x8)
2976/* Enable CoEx feature. */
2977#define COEX_FLAGS_COEX_ENABLE_MSK (0x80)
2978
2979struct iwl_wimax_coex_cmd {
2980 u8 flags;
2981 u8 reserved[3];
2982 struct iwl_wimax_coex_event_entry sta_prio[COEX_NUM_OF_EVENTS];
2983} __attribute__ ((packed));
2984
2774/****************************************************************************** 2985/******************************************************************************
2775 * (13) 2986 * (13)
2776 * Union of all expected notifications/responses: 2987 * Union of all expected notifications/responses:
@@ -2781,20 +2992,22 @@ struct iwl_rx_packet {
2781 __le32 len; 2992 __le32 len;
2782 struct iwl_cmd_header hdr; 2993 struct iwl_cmd_header hdr;
2783 union { 2994 union {
2784 struct iwl4965_alive_resp alive_frame; 2995 struct iwl_alive_resp alive_frame;
2785 struct iwl4965_rx_frame rx_frame; 2996 struct iwl4965_rx_frame rx_frame;
2786 struct iwl4965_tx_resp tx_resp; 2997 struct iwl4965_tx_resp tx_resp;
2787 struct iwl4965_spectrum_notification spectrum_notif; 2998 struct iwl4965_spectrum_notification spectrum_notif;
2788 struct iwl4965_csa_notification csa_notif; 2999 struct iwl4965_csa_notification csa_notif;
2789 struct iwl4965_error_resp err_resp; 3000 struct iwl_error_resp err_resp;
2790 struct iwl4965_card_state_notif card_state_notif; 3001 struct iwl4965_card_state_notif card_state_notif;
2791 struct iwl4965_beacon_notif beacon_status; 3002 struct iwl4965_beacon_notif beacon_status;
2792 struct iwl4965_add_sta_resp add_sta; 3003 struct iwl_add_sta_resp add_sta;
3004 struct iwl_rem_sta_resp rem_sta;
2793 struct iwl4965_sleep_notification sleep_notif; 3005 struct iwl4965_sleep_notification sleep_notif;
2794 struct iwl4965_spectrum_resp spectrum; 3006 struct iwl4965_spectrum_resp spectrum;
2795 struct iwl4965_notif_statistics stats; 3007 struct iwl4965_notif_statistics stats;
2796 struct iwl4965_compressed_ba_resp compressed_ba; 3008 struct iwl4965_compressed_ba_resp compressed_ba;
2797 struct iwl4965_missed_beacon_notif missed_beacon; 3009 struct iwl4965_missed_beacon_notif missed_beacon;
3010 struct iwl5000_calibration calib;
2798 __le32 status; 3011 __le32 status;
2799 u8 raw[0]; 3012 u8 raw[0];
2800 } u; 3013 } u;
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index d3cbad2bf877..61716ba90427 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -67,7 +67,7 @@ MODULE_LICENSE("GPL");
67 * maps to IWL_RATE_INVALID 67 * maps to IWL_RATE_INVALID
68 * 68 *
69 */ 69 */
70const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = { 70const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = {
71 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */ 71 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
72 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */ 72 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
73 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */ 73 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
@@ -83,7 +83,12 @@ const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = {
83 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */ 83 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
84 /* FIXME:RS: ^^ should be INV (legacy) */ 84 /* FIXME:RS: ^^ should be INV (legacy) */
85}; 85};
86EXPORT_SYMBOL(iwl4965_rates); 86EXPORT_SYMBOL(iwl_rates);
87
88
89const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
90EXPORT_SYMBOL(iwl_bcast_addr);
91
87 92
88/* This function both allocates and initializes hw and priv. */ 93/* This function both allocates and initializes hw and priv. */
89struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg, 94struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
@@ -317,24 +322,33 @@ void iwl_reset_qos(struct iwl_priv *priv)
317EXPORT_SYMBOL(iwl_reset_qos); 322EXPORT_SYMBOL(iwl_reset_qos);
318 323
319#ifdef CONFIG_IWL4965_HT 324#ifdef CONFIG_IWL4965_HT
325#define MAX_BIT_RATE_40_MHZ 0x96; /* 150 Mbps */
326#define MAX_BIT_RATE_20_MHZ 0x48; /* 72 Mbps */
320static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv, 327static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
321 struct ieee80211_ht_info *ht_info, 328 struct ieee80211_ht_info *ht_info,
322 enum ieee80211_band band) 329 enum ieee80211_band band)
323{ 330{
331 u16 max_bit_rate = 0;
332 u8 rx_chains_num = priv->hw_params.rx_chains_num;
333 u8 tx_chains_num = priv->hw_params.tx_chains_num;
334
324 ht_info->cap = 0; 335 ht_info->cap = 0;
325 memset(ht_info->supp_mcs_set, 0, 16); 336 memset(ht_info->supp_mcs_set, 0, 16);
326 337
327 ht_info->ht_supported = 1; 338 ht_info->ht_supported = 1;
328 339
340 ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD;
341 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
342 ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS &
343 (IWL_MIMO_PS_NONE << 2));
344
345 max_bit_rate = MAX_BIT_RATE_20_MHZ;
329 if (priv->hw_params.fat_channel & BIT(band)) { 346 if (priv->hw_params.fat_channel & BIT(band)) {
330 ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH; 347 ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH;
331 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40; 348 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40;
332 ht_info->supp_mcs_set[4] = 0x01; 349 ht_info->supp_mcs_set[4] = 0x01;
350 max_bit_rate = MAX_BIT_RATE_40_MHZ;
333 } 351 }
334 ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD;
335 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
336 ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS &
337 (IWL_MIMO_PS_NONE << 2));
338 352
339 if (priv->cfg->mod_params->amsdu_size_8K) 353 if (priv->cfg->mod_params->amsdu_size_8K)
340 ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU; 354 ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU;
@@ -343,10 +357,22 @@ static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
343 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF; 357 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
344 358
345 ht_info->supp_mcs_set[0] = 0xFF; 359 ht_info->supp_mcs_set[0] = 0xFF;
346 if (priv->hw_params.tx_chains_num >= 2) 360 if (rx_chains_num >= 2)
347 ht_info->supp_mcs_set[1] = 0xFF; 361 ht_info->supp_mcs_set[1] = 0xFF;
348 if (priv->hw_params.tx_chains_num >= 3) 362 if (rx_chains_num >= 3)
349 ht_info->supp_mcs_set[2] = 0xFF; 363 ht_info->supp_mcs_set[2] = 0xFF;
364
365 /* Highest supported Rx data rate */
366 max_bit_rate *= rx_chains_num;
367 ht_info->supp_mcs_set[10] = (u8)(max_bit_rate & 0x00FF);
368 ht_info->supp_mcs_set[11] = (u8)((max_bit_rate & 0xFF00) >> 8);
369
370 /* Tx MCS capabilities */
371 ht_info->supp_mcs_set[12] = IEEE80211_HT_CAP_MCS_TX_DEFINED;
372 if (tx_chains_num != rx_chains_num) {
373 ht_info->supp_mcs_set[12] |= IEEE80211_HT_CAP_MCS_TX_RX_DIFF;
374 ht_info->supp_mcs_set[12] |= ((tx_chains_num - 1) << 2);
375 }
350} 376}
351#else 377#else
352static inline void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv, 378static inline void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
@@ -362,7 +388,7 @@ static void iwlcore_init_hw_rates(struct iwl_priv *priv,
362 int i; 388 int i;
363 389
364 for (i = 0; i < IWL_RATE_COUNT; i++) { 390 for (i = 0; i < IWL_RATE_COUNT; i++) {
365 rates[i].bitrate = iwl4965_rates[i].ieee * 5; 391 rates[i].bitrate = iwl_rates[i].ieee * 5;
366 rates[i].hw_value = i; /* Rate scaling will work on indexes */ 392 rates[i].hw_value = i; /* Rate scaling will work on indexes */
367 rates[i].hw_value_short = i; 393 rates[i].hw_value_short = i;
368 rates[i].flags = 0; 394 rates[i].flags = 0;
@@ -371,7 +397,7 @@ static void iwlcore_init_hw_rates(struct iwl_priv *priv,
371 * If CCK != 1M then set short preamble rate flag. 397 * If CCK != 1M then set short preamble rate flag.
372 */ 398 */
373 rates[i].flags |= 399 rates[i].flags |=
374 (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ? 400 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
375 0 : IEEE80211_RATE_SHORT_PREAMBLE; 401 0 : IEEE80211_RATE_SHORT_PREAMBLE;
376 } 402 }
377 } 403 }
@@ -460,6 +486,25 @@ static int iwlcore_init_geos(struct iwl_priv *priv)
460 if (ch->flags & EEPROM_CHANNEL_RADAR) 486 if (ch->flags & EEPROM_CHANNEL_RADAR)
461 geo_ch->flags |= IEEE80211_CHAN_RADAR; 487 geo_ch->flags |= IEEE80211_CHAN_RADAR;
462 488
489 switch (ch->fat_extension_channel) {
490 case HT_IE_EXT_CHANNEL_ABOVE:
491 /* only above is allowed, disable below */
492 geo_ch->flags |= IEEE80211_CHAN_NO_FAT_BELOW;
493 break;
494 case HT_IE_EXT_CHANNEL_BELOW:
495 /* only below is allowed, disable above */
496 geo_ch->flags |= IEEE80211_CHAN_NO_FAT_ABOVE;
497 break;
498 case HT_IE_EXT_CHANNEL_NONE:
499 /* fat not allowed: disable both*/
500 geo_ch->flags |= (IEEE80211_CHAN_NO_FAT_ABOVE |
501 IEEE80211_CHAN_NO_FAT_BELOW);
502 break;
503 case HT_IE_EXT_CHANNEL_MAX:
504 /* both above and below are permitted */
505 break;
506 }
507
463 if (ch->max_power_avg > priv->max_channel_txpower_limit) 508 if (ch->max_power_avg > priv->max_channel_txpower_limit)
464 priv->max_channel_txpower_limit = 509 priv->max_channel_txpower_limit =
465 ch->max_power_avg; 510 ch->max_power_avg;
@@ -492,12 +537,6 @@ static int iwlcore_init_geos(struct iwl_priv *priv)
492 priv->bands[IEEE80211_BAND_2GHZ].n_channels, 537 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
493 priv->bands[IEEE80211_BAND_5GHZ].n_channels); 538 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
494 539
495 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
496 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
497 &priv->bands[IEEE80211_BAND_2GHZ];
498 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
499 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
500 &priv->bands[IEEE80211_BAND_5GHZ];
501 540
502 set_bit(STATUS_GEO_CONFIGURED, &priv->status); 541 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
503 542
@@ -507,13 +546,12 @@ static int iwlcore_init_geos(struct iwl_priv *priv)
507/* 546/*
508 * iwlcore_free_geos - undo allocations in iwlcore_init_geos 547 * iwlcore_free_geos - undo allocations in iwlcore_init_geos
509 */ 548 */
510void iwlcore_free_geos(struct iwl_priv *priv) 549static void iwlcore_free_geos(struct iwl_priv *priv)
511{ 550{
512 kfree(priv->ieee_channels); 551 kfree(priv->ieee_channels);
513 kfree(priv->ieee_rates); 552 kfree(priv->ieee_rates);
514 clear_bit(STATUS_GEO_CONFIGURED, &priv->status); 553 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
515} 554}
516EXPORT_SYMBOL(iwlcore_free_geos);
517 555
518#ifdef CONFIG_IWL4965_HT 556#ifdef CONFIG_IWL4965_HT
519static u8 is_single_rx_stream(struct iwl_priv *priv) 557static u8 is_single_rx_stream(struct iwl_priv *priv)
@@ -567,7 +605,7 @@ EXPORT_SYMBOL(iwl_is_fat_tx_allowed);
567 605
568void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info) 606void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
569{ 607{
570 struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; 608 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
571 u32 val; 609 u32 val;
572 610
573 if (!ht_info->is_ht) 611 if (!ht_info->is_ht)
@@ -741,8 +779,9 @@ int iwl_set_rxon_channel(struct iwl_priv *priv,
741} 779}
742EXPORT_SYMBOL(iwl_set_rxon_channel); 780EXPORT_SYMBOL(iwl_set_rxon_channel);
743 781
744static void iwlcore_init_hw(struct iwl_priv *priv) 782int iwl_setup_mac(struct iwl_priv *priv)
745{ 783{
784 int ret;
746 struct ieee80211_hw *hw = priv->hw; 785 struct ieee80211_hw *hw = priv->hw;
747 hw->rate_control_algorithm = "iwl-4965-rs"; 786 hw->rate_control_algorithm = "iwl-4965-rs";
748 787
@@ -756,9 +795,29 @@ static void iwlcore_init_hw(struct iwl_priv *priv)
756 /* Enhanced value; more queues, to support 11n aggregation */ 795 /* Enhanced value; more queues, to support 11n aggregation */
757 hw->ampdu_queues = 12; 796 hw->ampdu_queues = 12;
758#endif /* CONFIG_IWL4965_HT */ 797#endif /* CONFIG_IWL4965_HT */
798
799 hw->conf.beacon_int = 100;
800
801 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
802 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
803 &priv->bands[IEEE80211_BAND_2GHZ];
804 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
805 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
806 &priv->bands[IEEE80211_BAND_5GHZ];
807
808 ret = ieee80211_register_hw(priv->hw);
809 if (ret) {
810 IWL_ERROR("Failed to register hw (error %d)\n", ret);
811 return ret;
812 }
813 priv->mac80211_registered = 1;
814
815 return 0;
759} 816}
817EXPORT_SYMBOL(iwl_setup_mac);
760 818
761static int iwlcore_init_drv(struct iwl_priv *priv) 819
820int iwl_init_drv(struct iwl_priv *priv)
762{ 821{
763 int ret; 822 int ret;
764 int i; 823 int i;
@@ -795,6 +854,9 @@ static int iwlcore_init_drv(struct iwl_priv *priv)
795 /* Choose which receivers/antennas to use */ 854 /* Choose which receivers/antennas to use */
796 iwl_set_rxon_chain(priv); 855 iwl_set_rxon_chain(priv);
797 856
857 if (priv->cfg->mod_params->enable_qos)
858 priv->qos_data.qos_enable = 1;
859
798 iwl_reset_qos(priv); 860 iwl_reset_qos(priv);
799 861
800 priv->qos_data.qos_active = 0; 862 priv->qos_data.qos_active = 0;
@@ -819,34 +881,39 @@ static int iwlcore_init_drv(struct iwl_priv *priv)
819 goto err_free_channel_map; 881 goto err_free_channel_map;
820 } 882 }
821 883
822 ret = ieee80211_register_hw(priv->hw);
823 if (ret) {
824 IWL_ERROR("Failed to register network device (error %d)\n",
825 ret);
826 goto err_free_geos;
827 }
828
829 priv->hw->conf.beacon_int = 100;
830 priv->mac80211_registered = 1;
831
832 return 0; 884 return 0;
833 885
834err_free_geos:
835 iwlcore_free_geos(priv);
836err_free_channel_map: 886err_free_channel_map:
837 iwl_free_channel_map(priv); 887 iwl_free_channel_map(priv);
838err: 888err:
839 return ret; 889 return ret;
840} 890}
891EXPORT_SYMBOL(iwl_init_drv);
841 892
842int iwl_setup(struct iwl_priv *priv) 893void iwl_free_calib_results(struct iwl_priv *priv)
843{ 894{
844 int ret = 0; 895 kfree(priv->calib_results.lo_res);
845 iwlcore_init_hw(priv); 896 priv->calib_results.lo_res = NULL;
846 ret = iwlcore_init_drv(priv); 897 priv->calib_results.lo_res_len = 0;
847 return ret; 898
899 kfree(priv->calib_results.tx_iq_res);
900 priv->calib_results.tx_iq_res = NULL;
901 priv->calib_results.tx_iq_res_len = 0;
902
903 kfree(priv->calib_results.tx_iq_perd_res);
904 priv->calib_results.tx_iq_perd_res = NULL;
905 priv->calib_results.tx_iq_perd_res_len = 0;
906}
907EXPORT_SYMBOL(iwl_free_calib_results);
908
909void iwl_uninit_drv(struct iwl_priv *priv)
910{
911 iwl_free_calib_results(priv);
912 iwlcore_free_geos(priv);
913 iwl_free_channel_map(priv);
914 kfree(priv->scan);
848} 915}
849EXPORT_SYMBOL(iwl_setup); 916EXPORT_SYMBOL(iwl_uninit_drv);
850 917
851/* Low level driver call this function to update iwlcore with 918/* Low level driver call this function to update iwlcore with
852 * driver status. 919 * driver status.
@@ -1024,3 +1091,185 @@ int iwl_verify_ucode(struct iwl_priv *priv)
1024} 1091}
1025EXPORT_SYMBOL(iwl_verify_ucode); 1092EXPORT_SYMBOL(iwl_verify_ucode);
1026 1093
1094
1095static const char *desc_lookup(int i)
1096{
1097 switch (i) {
1098 case 1:
1099 return "FAIL";
1100 case 2:
1101 return "BAD_PARAM";
1102 case 3:
1103 return "BAD_CHECKSUM";
1104 case 4:
1105 return "NMI_INTERRUPT";
1106 case 5:
1107 return "SYSASSERT";
1108 case 6:
1109 return "FATAL_ERROR";
1110 }
1111
1112 return "UNKNOWN";
1113}
1114
1115#define ERROR_START_OFFSET (1 * sizeof(u32))
1116#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1117
1118void iwl_dump_nic_error_log(struct iwl_priv *priv)
1119{
1120 u32 data2, line;
1121 u32 desc, time, count, base, data1;
1122 u32 blink1, blink2, ilink1, ilink2;
1123 int ret;
1124
1125 if (priv->ucode_type == UCODE_INIT)
1126 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
1127 else
1128 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1129
1130 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
1131 IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
1132 return;
1133 }
1134
1135 ret = iwl_grab_nic_access(priv);
1136 if (ret) {
1137 IWL_WARNING("Can not read from adapter at this time.\n");
1138 return;
1139 }
1140
1141 count = iwl_read_targ_mem(priv, base);
1142
1143 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
1144 IWL_ERROR("Start IWL Error Log Dump:\n");
1145 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count);
1146 }
1147
1148 desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
1149 blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
1150 blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
1151 ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
1152 ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
1153 data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
1154 data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
1155 line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
1156 time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
1157
1158 IWL_ERROR("Desc Time "
1159 "data1 data2 line\n");
1160 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
1161 desc_lookup(desc), desc, time, data1, data2, line);
1162 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
1163 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
1164 ilink1, ilink2);
1165
1166 iwl_release_nic_access(priv);
1167}
1168EXPORT_SYMBOL(iwl_dump_nic_error_log);
1169
1170#define EVENT_START_OFFSET (4 * sizeof(u32))
1171
1172/**
1173 * iwl_print_event_log - Dump error event log to syslog
1174 *
1175 * NOTE: Must be called with iwl4965_grab_nic_access() already obtained!
1176 */
1177void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1178 u32 num_events, u32 mode)
1179{
1180 u32 i;
1181 u32 base; /* SRAM byte address of event log header */
1182 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1183 u32 ptr; /* SRAM byte address of log data */
1184 u32 ev, time, data; /* event log data */
1185
1186 if (num_events == 0)
1187 return;
1188 if (priv->ucode_type == UCODE_INIT)
1189 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1190 else
1191 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1192
1193 if (mode == 0)
1194 event_size = 2 * sizeof(u32);
1195 else
1196 event_size = 3 * sizeof(u32);
1197
1198 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1199
1200 /* "time" is actually "data" for mode 0 (no timestamp).
1201 * place event id # at far right for easier visual parsing. */
1202 for (i = 0; i < num_events; i++) {
1203 ev = iwl_read_targ_mem(priv, ptr);
1204 ptr += sizeof(u32);
1205 time = iwl_read_targ_mem(priv, ptr);
1206 ptr += sizeof(u32);
1207 if (mode == 0)
1208 IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
1209 else {
1210 data = iwl_read_targ_mem(priv, ptr);
1211 ptr += sizeof(u32);
1212 IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
1213 }
1214 }
1215}
1216EXPORT_SYMBOL(iwl_print_event_log);
1217
1218
1219void iwl_dump_nic_event_log(struct iwl_priv *priv)
1220{
1221 int ret;
1222 u32 base; /* SRAM byte address of event log header */
1223 u32 capacity; /* event log capacity in # entries */
1224 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1225 u32 num_wraps; /* # times uCode wrapped to top of log */
1226 u32 next_entry; /* index of next entry to be written by uCode */
1227 u32 size; /* # entries that we'll print */
1228
1229 if (priv->ucode_type == UCODE_INIT)
1230 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1231 else
1232 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1233
1234 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
1235 IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
1236 return;
1237 }
1238
1239 ret = iwl_grab_nic_access(priv);
1240 if (ret) {
1241 IWL_WARNING("Can not read from adapter at this time.\n");
1242 return;
1243 }
1244
1245 /* event log header */
1246 capacity = iwl_read_targ_mem(priv, base);
1247 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1248 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1249 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
1250
1251 size = num_wraps ? capacity : next_entry;
1252
1253 /* bail out if nothing in log */
1254 if (size == 0) {
1255 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
1256 iwl_release_nic_access(priv);
1257 return;
1258 }
1259
1260 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
1261 size, num_wraps);
1262
1263 /* if uCode has wrapped back to top of log, start at the oldest entry,
1264 * i.e the next one that uCode would fill. */
1265 if (num_wraps)
1266 iwl_print_event_log(priv, next_entry,
1267 capacity - next_entry, mode);
1268 /* (then/else) start at top of log */
1269 iwl_print_event_log(priv, 0, next_entry, mode);
1270
1271 iwl_release_nic_access(priv);
1272}
1273EXPORT_SYMBOL(iwl_dump_nic_event_log);
1274
1275
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index e139c8ffa9a2..6b5af7afbb25 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -86,7 +86,7 @@ struct iwl_hcmd_ops {
86 int (*rxon_assoc)(struct iwl_priv *priv); 86 int (*rxon_assoc)(struct iwl_priv *priv);
87}; 87};
88struct iwl_hcmd_utils_ops { 88struct iwl_hcmd_utils_ops {
89 int (*enqueue_hcmd)(struct iwl_priv *priv, struct iwl_host_cmd *cmd); 89 u16 (*get_hcmd_size)(u8 cmd_id, u16 len);
90 u16 (*build_addsta_hcmd)(const struct iwl_addsta_cmd *cmd, u8 *data); 90 u16 (*build_addsta_hcmd)(const struct iwl_addsta_cmd *cmd, u8 *data);
91#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB 91#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
92 void (*gain_computation)(struct iwl_priv *priv, 92 void (*gain_computation)(struct iwl_priv *priv,
@@ -104,13 +104,22 @@ struct iwl_lib_ops {
104 int (*alloc_shared_mem)(struct iwl_priv *priv); 104 int (*alloc_shared_mem)(struct iwl_priv *priv);
105 void (*free_shared_mem)(struct iwl_priv *priv); 105 void (*free_shared_mem)(struct iwl_priv *priv);
106 int (*shared_mem_rx_idx)(struct iwl_priv *priv); 106 int (*shared_mem_rx_idx)(struct iwl_priv *priv);
107 /* Handling TX */
107 void (*txq_update_byte_cnt_tbl)(struct iwl_priv *priv, 108 void (*txq_update_byte_cnt_tbl)(struct iwl_priv *priv,
108 struct iwl_tx_queue *txq, 109 struct iwl_tx_queue *txq,
109 u16 byte_cnt); 110 u16 byte_cnt);
111 void (*txq_inval_byte_cnt_tbl)(struct iwl_priv *priv,
112 struct iwl_tx_queue *txq);
113 void (*txq_set_sched)(struct iwl_priv *priv, u32 mask);
114#ifdef CONFIG_IWL4965_HT
115 /* aggregations */
116 int (*txq_agg_enable)(struct iwl_priv *priv, int txq_id, int tx_fifo,
117 int sta_id, int tid, u16 ssn_idx);
118 int (*txq_agg_disable)(struct iwl_priv *priv, u16 txq_id, u16 ssn_idx,
119 u8 tx_fifo);
120#endif /* CONFIG_IWL4965_HT */
110 /* setup Rx handler */ 121 /* setup Rx handler */
111 void (*rx_handler_setup)(struct iwl_priv *priv); 122 void (*rx_handler_setup)(struct iwl_priv *priv);
112 /* nic Tx fifo handling */
113 int (*disable_tx_fifo)(struct iwl_priv *priv);
114 /* alive notification after init uCode load */ 123 /* alive notification after init uCode load */
115 void (*init_alive_start)(struct iwl_priv *priv); 124 void (*init_alive_start)(struct iwl_priv *priv);
116 /* alive notification */ 125 /* alive notification */
@@ -124,6 +133,8 @@ struct iwl_lib_ops {
124 /* power management */ 133 /* power management */
125 struct { 134 struct {
126 int (*init)(struct iwl_priv *priv); 135 int (*init)(struct iwl_priv *priv);
136 int (*reset)(struct iwl_priv *priv);
137 void (*stop)(struct iwl_priv *priv);
127 void (*config)(struct iwl_priv *priv); 138 void (*config)(struct iwl_priv *priv);
128 int (*set_pwr_src)(struct iwl_priv *priv, enum iwl_pwr_src src); 139 int (*set_pwr_src)(struct iwl_priv *priv, enum iwl_pwr_src src);
129 } apm_ops; 140 } apm_ops;
@@ -170,18 +181,19 @@ struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
170void iwl_hw_detect(struct iwl_priv *priv); 181void iwl_hw_detect(struct iwl_priv *priv);
171 182
172void iwlcore_clear_stations_table(struct iwl_priv *priv); 183void iwlcore_clear_stations_table(struct iwl_priv *priv);
184void iwl_free_calib_results(struct iwl_priv *priv);
173void iwl_reset_qos(struct iwl_priv *priv); 185void iwl_reset_qos(struct iwl_priv *priv);
174void iwl_set_rxon_chain(struct iwl_priv *priv); 186void iwl_set_rxon_chain(struct iwl_priv *priv);
175int iwl_set_rxon_channel(struct iwl_priv *priv, 187int iwl_set_rxon_channel(struct iwl_priv *priv,
176 enum ieee80211_band band, 188 enum ieee80211_band band,
177 u16 channel); 189 u16 channel);
178void iwlcore_free_geos(struct iwl_priv *priv);
179int iwl_setup(struct iwl_priv *priv);
180void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info); 190void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info);
181u8 iwl_is_fat_tx_allowed(struct iwl_priv *priv, 191u8 iwl_is_fat_tx_allowed(struct iwl_priv *priv,
182 struct ieee80211_ht_info *sta_ht_inf); 192 struct ieee80211_ht_info *sta_ht_inf);
183int iwl_hw_nic_init(struct iwl_priv *priv); 193int iwl_hw_nic_init(struct iwl_priv *priv);
184 194int iwl_setup_mac(struct iwl_priv *priv);
195int iwl_init_drv(struct iwl_priv *priv);
196void iwl_uninit_drv(struct iwl_priv *priv);
185/* "keep warm" functions */ 197/* "keep warm" functions */
186int iwl_kw_init(struct iwl_priv *priv); 198int iwl_kw_init(struct iwl_priv *priv);
187int iwl_kw_alloc(struct iwl_priv *priv); 199int iwl_kw_alloc(struct iwl_priv *priv);
@@ -202,14 +214,30 @@ int iwl_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq);
202int iwl_rx_queue_restock(struct iwl_priv *priv); 214int iwl_rx_queue_restock(struct iwl_priv *priv);
203int iwl_rx_queue_space(const struct iwl_rx_queue *q); 215int iwl_rx_queue_space(const struct iwl_rx_queue *q);
204void iwl_rx_allocate(struct iwl_priv *priv); 216void iwl_rx_allocate(struct iwl_priv *priv);
217void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb);
218int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index);
219/* Handlers */
220void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
221 struct iwl_rx_mem_buffer *rxb);
222
223/* TX helpers */
205 224
206/***************************************************** 225/*****************************************************
207* TX 226* TX
208******************************************************/ 227******************************************************/
209int iwl_txq_ctx_reset(struct iwl_priv *priv); 228int iwl_txq_ctx_reset(struct iwl_priv *priv);
229int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb);
210/* FIXME: remove when free Tx is fully merged into iwlcore */ 230/* FIXME: remove when free Tx is fully merged into iwlcore */
211int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq); 231int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq);
212void iwl_hw_txq_ctx_free(struct iwl_priv *priv); 232void iwl_hw_txq_ctx_free(struct iwl_priv *priv);
233int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *tfd,
234 dma_addr_t addr, u16 len);
235int iwl_txq_update_write_ptr(struct iwl_priv *priv, struct iwl_tx_queue *txq);
236#ifdef CONFIG_IWL4965_HT
237int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn);
238int iwl_tx_agg_stop(struct iwl_priv *priv , const u8 *ra, u16 tid);
239int iwl_txq_check_empty(struct iwl_priv *priv, int sta_id, u8 tid, int txq_id);
240#endif
213 241
214/***************************************************** 242/*****************************************************
215 * S e n d i n g H o s t C o m m a n d s * 243 * S e n d i n g H o s t C o m m a n d s *
@@ -226,6 +254,17 @@ int iwl_send_cmd_pdu_async(struct iwl_priv *priv, u8 id, u16 len,
226 int (*callback)(struct iwl_priv *priv, 254 int (*callback)(struct iwl_priv *priv,
227 struct iwl_cmd *cmd, 255 struct iwl_cmd *cmd,
228 struct sk_buff *skb)); 256 struct sk_buff *skb));
257
258int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd);
259
260/*****************************************************
261* Error Handling Debugging
262******************************************************/
263void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
264 u32 num_events, u32 mode);
265void iwl_dump_nic_error_log(struct iwl_priv *priv);
266void iwl_dump_nic_event_log(struct iwl_priv *priv);
267
229/*************** DRIVER STATUS FUNCTIONS *****/ 268/*************** DRIVER STATUS FUNCTIONS *****/
230 269
231#define STATUS_HCMD_ACTIVE 0 /* host command in progress */ 270#define STATUS_HCMD_ACTIVE 0 /* host command in progress */
@@ -303,5 +342,10 @@ static inline int iwl_send_rxon_assoc(struct iwl_priv *priv)
303 return priv->cfg->ops->hcmd->rxon_assoc(priv); 342 return priv->cfg->ops->hcmd->rxon_assoc(priv);
304} 343}
305 344
345static inline const struct ieee80211_supported_band *iwl_get_hw_mode(
346 struct iwl_priv *priv, enum ieee80211_band band)
347{
348 return priv->hw->wiphy->bands[band];
349}
306 350
307#endif /* __iwl_core_h__ */ 351#endif /* __iwl_core_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-csr.h b/drivers/net/wireless/iwlwifi/iwl-csr.h
index 9d6e5d2072d2..545ed692d889 100644
--- a/drivers/net/wireless/iwlwifi/iwl-csr.h
+++ b/drivers/net/wireless/iwlwifi/iwl-csr.h
@@ -87,13 +87,14 @@
87/* EEPROM reads */ 87/* EEPROM reads */
88#define CSR_EEPROM_REG (CSR_BASE+0x02c) 88#define CSR_EEPROM_REG (CSR_BASE+0x02c)
89#define CSR_EEPROM_GP (CSR_BASE+0x030) 89#define CSR_EEPROM_GP (CSR_BASE+0x030)
90#define CSR_GIO_REG (CSR_BASE+0x03C)
90#define CSR_GP_UCODE (CSR_BASE+0x044) 91#define CSR_GP_UCODE (CSR_BASE+0x044)
91#define CSR_UCODE_DRV_GP1 (CSR_BASE+0x054) 92#define CSR_UCODE_DRV_GP1 (CSR_BASE+0x054)
92#define CSR_UCODE_DRV_GP1_SET (CSR_BASE+0x058) 93#define CSR_UCODE_DRV_GP1_SET (CSR_BASE+0x058)
93#define CSR_UCODE_DRV_GP1_CLR (CSR_BASE+0x05c) 94#define CSR_UCODE_DRV_GP1_CLR (CSR_BASE+0x05c)
94#define CSR_UCODE_DRV_GP2 (CSR_BASE+0x060) 95#define CSR_UCODE_DRV_GP2 (CSR_BASE+0x060)
95#define CSR_GIO_CHICKEN_BITS (CSR_BASE+0x100)
96#define CSR_LED_REG (CSR_BASE+0x094) 96#define CSR_LED_REG (CSR_BASE+0x094)
97#define CSR_GIO_CHICKEN_BITS (CSR_BASE+0x100)
97 98
98/* Analog phase-lock-loop configuration */ 99/* Analog phase-lock-loop configuration */
99#define CSR_ANA_PLL_CFG (CSR_BASE+0x20c) 100#define CSR_ANA_PLL_CFG (CSR_BASE+0x20c)
@@ -213,6 +214,9 @@
213#define CSR_EEPROM_GP_BAD_SIGNATURE (0x00000000) 214#define CSR_EEPROM_GP_BAD_SIGNATURE (0x00000000)
214#define CSR_EEPROM_GP_IF_OWNER_MSK (0x00000180) 215#define CSR_EEPROM_GP_IF_OWNER_MSK (0x00000180)
215 216
217/* CSR GIO */
218#define CSR_GIO_REG_VAL_L0S_ENABLED (0x00000002)
219
216/* UCODE DRV GP */ 220/* UCODE DRV GP */
217#define CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP (0x00000001) 221#define CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP (0x00000001)
218#define CSR_UCODE_SW_BIT_RFKILL (0x00000002) 222#define CSR_UCODE_SW_BIT_RFKILL (0x00000002)
diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
index 2f24594c5fea..11de561c7bf8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
@@ -45,13 +45,21 @@ struct iwl_debugfs {
45 const char *name; 45 const char *name;
46 struct dentry *dir_drv; 46 struct dentry *dir_drv;
47 struct dentry *dir_data; 47 struct dentry *dir_data;
48 struct dir_data_files{ 48 struct dentry *dir_rf;
49 struct dir_data_files {
49 struct dentry *file_sram; 50 struct dentry *file_sram;
50 struct dentry *file_eeprom; 51 struct dentry *file_eeprom;
51 struct dentry *file_stations; 52 struct dentry *file_stations;
52 struct dentry *file_rx_statistics; 53 struct dentry *file_rx_statistics;
53 struct dentry *file_tx_statistics; 54 struct dentry *file_tx_statistics;
55 struct dentry *file_log_event;
54 } dbgfs_data_files; 56 } dbgfs_data_files;
57 struct dir_rf_files {
58#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
59 struct dentry *file_disable_sensitivity;
60 struct dentry *file_disable_chain_noise;
61#endif /* CONFIG_IWLWIFI_RUN_TIME_CALIB */
62 } dbgfs_rf_files;
55 u32 sram_offset; 63 u32 sram_offset;
56 u32 sram_len; 64 u32 sram_len;
57}; 65};
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
index ad25806dfaf1..29e16ba69cdb 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
@@ -55,6 +55,13 @@
55 goto err; \ 55 goto err; \
56} while (0) 56} while (0)
57 57
58#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
59 dbgfs->dbgfs_##parent##_files.file_##name = \
60 debugfs_create_bool(#name, 0644, dbgfs->dir_##parent, ptr); \
61 if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name)) \
62 goto err; \
63} while (0)
64
58#define DEBUGFS_REMOVE(name) do { \ 65#define DEBUGFS_REMOVE(name) do { \
59 debugfs_remove(name); \ 66 debugfs_remove(name); \
60 name = NULL; \ 67 name = NULL; \
@@ -85,6 +92,14 @@ static const struct file_operations iwl_dbgfs_##name##_ops = { \
85 .open = iwl_dbgfs_open_file_generic, \ 92 .open = iwl_dbgfs_open_file_generic, \
86}; 93};
87 94
95#define DEBUGFS_WRITE_FILE_OPS(name) \
96 DEBUGFS_WRITE_FUNC(name); \
97static const struct file_operations iwl_dbgfs_##name##_ops = { \
98 .write = iwl_dbgfs_##name##_write, \
99 .open = iwl_dbgfs_open_file_generic, \
100};
101
102
88#define DEBUGFS_READ_WRITE_FILE_OPS(name) \ 103#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
89 DEBUGFS_READ_FUNC(name); \ 104 DEBUGFS_READ_FUNC(name); \
90 DEBUGFS_WRITE_FUNC(name); \ 105 DEBUGFS_WRITE_FUNC(name); \
@@ -317,7 +332,29 @@ static ssize_t iwl_dbgfs_eeprom_read(struct file *file,
317 return ret; 332 return ret;
318} 333}
319 334
335static ssize_t iwl_dbgfs_log_event_write(struct file *file,
336 const char __user *user_buf,
337 size_t count, loff_t *ppos)
338{
339 struct iwl_priv *priv = file->private_data;
340 u32 event_log_flag;
341 char buf[8];
342 int buf_size;
343
344 memset(buf, 0, sizeof(buf));
345 buf_size = min(count, sizeof(buf) - 1);
346 if (copy_from_user(buf, user_buf, buf_size))
347 return -EFAULT;
348 if (sscanf(buf, "%d", &event_log_flag) != 1)
349 return -EFAULT;
350 if (event_log_flag == 1)
351 iwl_dump_nic_event_log(priv);
352
353 return count;
354}
355
320DEBUGFS_READ_WRITE_FILE_OPS(sram); 356DEBUGFS_READ_WRITE_FILE_OPS(sram);
357DEBUGFS_WRITE_FILE_OPS(log_event);
321DEBUGFS_READ_FILE_OPS(eeprom); 358DEBUGFS_READ_FILE_OPS(eeprom);
322DEBUGFS_READ_FILE_OPS(stations); 359DEBUGFS_READ_FILE_OPS(stations);
323DEBUGFS_READ_FILE_OPS(rx_statistics); 360DEBUGFS_READ_FILE_OPS(rx_statistics);
@@ -330,6 +367,7 @@ DEBUGFS_READ_FILE_OPS(tx_statistics);
330int iwl_dbgfs_register(struct iwl_priv *priv, const char *name) 367int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
331{ 368{
332 struct iwl_debugfs *dbgfs; 369 struct iwl_debugfs *dbgfs;
370 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
333 371
334 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL); 372 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
335 if (!dbgfs) { 373 if (!dbgfs) {
@@ -338,18 +376,24 @@ int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
338 376
339 priv->dbgfs = dbgfs; 377 priv->dbgfs = dbgfs;
340 dbgfs->name = name; 378 dbgfs->name = name;
341 dbgfs->dir_drv = debugfs_create_dir(name, NULL); 379 dbgfs->dir_drv = debugfs_create_dir(name, phyd);
342 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){ 380 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){
343 goto err; 381 goto err;
344 } 382 }
345 383
346 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv); 384 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
385 DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
347 DEBUGFS_ADD_FILE(eeprom, data); 386 DEBUGFS_ADD_FILE(eeprom, data);
348 DEBUGFS_ADD_FILE(sram, data); 387 DEBUGFS_ADD_FILE(sram, data);
388 DEBUGFS_ADD_FILE(log_event, data);
349 DEBUGFS_ADD_FILE(stations, data); 389 DEBUGFS_ADD_FILE(stations, data);
350 DEBUGFS_ADD_FILE(rx_statistics, data); 390 DEBUGFS_ADD_FILE(rx_statistics, data);
351 DEBUGFS_ADD_FILE(tx_statistics, data); 391 DEBUGFS_ADD_FILE(tx_statistics, data);
352 392#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
393 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
394 DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
395 &priv->disable_chain_noise_cal);
396#endif /* CONFIG_IWLWIFI_RUN_TIME_CALIB */
353 return 0; 397 return 0;
354 398
355err: 399err:
@@ -372,8 +416,14 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv)
372 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics); 416 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
373 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics); 417 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
374 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram); 418 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
419 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
375 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations); 420 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
376 DEBUGFS_REMOVE(priv->dbgfs->dir_data); 421 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
422#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
423 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
424 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
425#endif /* CONFIG_IWLWIFI_RUN_TIME_CALIB */
426 DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
377 DEBUGFS_REMOVE(priv->dbgfs->dir_drv); 427 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
378 kfree(priv->dbgfs); 428 kfree(priv->dbgfs);
379 priv->dbgfs = NULL; 429 priv->dbgfs = NULL;
@@ -381,3 +431,4 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv)
381EXPORT_SYMBOL(iwl_dbgfs_unregister); 431EXPORT_SYMBOL(iwl_dbgfs_unregister);
382 432
383 433
434
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index 5dccc5a8fa94..802f1a12b1aa 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -102,7 +102,7 @@ struct iwl_rx_mem_buffer {
102 * 102 *
103 * Contains common data for Rx and Tx queues 103 * Contains common data for Rx and Tx queues
104 */ 104 */
105struct iwl4965_queue { 105struct iwl_queue {
106 int n_bd; /* number of BDs in this queue */ 106 int n_bd; /* number of BDs in this queue */
107 int write_ptr; /* 1-st empty entry (index) host_w*/ 107 int write_ptr; /* 1-st empty entry (index) host_w*/
108 int read_ptr; /* last used entry (index) host_r*/ 108 int read_ptr; /* last used entry (index) host_r*/
@@ -118,8 +118,7 @@ struct iwl4965_queue {
118#define MAX_NUM_OF_TBS (20) 118#define MAX_NUM_OF_TBS (20)
119 119
120/* One for each TFD */ 120/* One for each TFD */
121struct iwl4965_tx_info { 121struct iwl_tx_info {
122 struct ieee80211_tx_status status;
123 struct sk_buff *skb[MAX_NUM_OF_TBS]; 122 struct sk_buff *skb[MAX_NUM_OF_TBS];
124}; 123};
125 124
@@ -137,11 +136,11 @@ struct iwl4965_tx_info {
137 * descriptors) and required locking structures. 136 * descriptors) and required locking structures.
138 */ 137 */
139struct iwl_tx_queue { 138struct iwl_tx_queue {
140 struct iwl4965_queue q; 139 struct iwl_queue q;
141 struct iwl_tfd_frame *bd; 140 struct iwl_tfd_frame *bd;
142 struct iwl_cmd *cmd; 141 struct iwl_cmd *cmd;
143 dma_addr_t dma_addr_cmd; 142 dma_addr_t dma_addr_cmd;
144 struct iwl4965_tx_info *txb; 143 struct iwl_tx_info *txb;
145 int need_update; 144 int need_update;
146 int sched_retry; 145 int sched_retry;
147 int active; 146 int active;
@@ -262,7 +261,7 @@ enum iwl_pwr_src {
262#define IEEE80211_HLEN (IEEE80211_4ADDR_LEN) 261#define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
263#define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN) 262#define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
264 263
265struct iwl4965_frame { 264struct iwl_frame {
266 union { 265 union {
267 struct ieee80211_hdr frame; 266 struct ieee80211_hdr frame;
268 struct iwl4965_tx_beacon_cmd beacon; 267 struct iwl4965_tx_beacon_cmd beacon;
@@ -308,6 +307,8 @@ struct iwl_cmd_meta {
308 307
309} __attribute__ ((packed)); 308} __attribute__ ((packed));
310 309
310#define IWL_CMD_MAX_PAYLOAD 320
311
311/** 312/**
312 * struct iwl_cmd 313 * struct iwl_cmd
313 * 314 *
@@ -329,11 +330,12 @@ struct iwl_cmd {
329 struct iwl4965_rxon_time_cmd rxon_time; 330 struct iwl4965_rxon_time_cmd rxon_time;
330 struct iwl4965_powertable_cmd powertable; 331 struct iwl4965_powertable_cmd powertable;
331 struct iwl4965_qosparam_cmd qosparam; 332 struct iwl4965_qosparam_cmd qosparam;
332 struct iwl4965_tx_cmd tx; 333 struct iwl_tx_cmd tx;
333 struct iwl4965_tx_beacon_cmd tx_beacon; 334 struct iwl4965_tx_beacon_cmd tx_beacon;
334 struct iwl4965_rxon_assoc_cmd rxon_assoc; 335 struct iwl4965_rxon_assoc_cmd rxon_assoc;
336 struct iwl_rem_sta_cmd rm_sta;
335 u8 *indirect; 337 u8 *indirect;
336 u8 payload[360]; 338 u8 payload[IWL_CMD_MAX_PAYLOAD];
337 } __attribute__ ((packed)) cmd; 339 } __attribute__ ((packed)) cmd;
338} __attribute__ ((packed)); 340} __attribute__ ((packed));
339 341
@@ -442,7 +444,6 @@ struct iwl_hw_key {
442 enum ieee80211_key_alg alg; 444 enum ieee80211_key_alg alg;
443 int keylen; 445 int keylen;
444 u8 keyidx; 446 u8 keyidx;
445 struct ieee80211_key_conf *conf;
446 u8 key[32]; 447 u8 key[32];
447}; 448};
448 449
@@ -573,7 +574,6 @@ struct iwl_sensitivity_ranges {
573/** 574/**
574 * struct iwl_hw_params 575 * struct iwl_hw_params
575 * @max_txq_num: Max # Tx queues supported 576 * @max_txq_num: Max # Tx queues supported
576 * @tx_cmd_len: Size of Tx command (but not including frame itself)
577 * @tx/rx_chains_num: Number of TX/RX chains 577 * @tx/rx_chains_num: Number of TX/RX chains
578 * @valid_tx/rx_ant: usable antennas 578 * @valid_tx/rx_ant: usable antennas
579 * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2) 579 * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
@@ -590,7 +590,6 @@ struct iwl_sensitivity_ranges {
590 */ 590 */
591struct iwl_hw_params { 591struct iwl_hw_params {
592 u16 max_txq_num; 592 u16 max_txq_num;
593 u16 tx_cmd_len;
594 u8 tx_chains_num; 593 u8 tx_chains_num;
595 u8 rx_chains_num; 594 u8 rx_chains_num;
596 u8 valid_tx_ant; 595 u8 valid_tx_ant;
@@ -612,8 +611,8 @@ struct iwl_hw_params {
612#endif 611#endif
613}; 612};
614 613
615#define HT_SHORT_GI_20MHZ_ONLY (1 << 0) 614#define HT_SHORT_GI_20MHZ (1 << 0)
616#define HT_SHORT_GI_40MHZ_ONLY (1 << 1) 615#define HT_SHORT_GI_40MHZ (1 << 1)
617 616
618 617
619#define IWL_RX_HDR(x) ((struct iwl4965_rx_frame_hdr *)(\ 618#define IWL_RX_HDR(x) ((struct iwl4965_rx_frame_hdr *)(\
@@ -635,8 +634,8 @@ struct iwl_hw_params {
635struct iwl_addsta_cmd; 634struct iwl_addsta_cmd;
636extern int iwl_send_add_sta(struct iwl_priv *priv, 635extern int iwl_send_add_sta(struct iwl_priv *priv,
637 struct iwl_addsta_cmd *sta, u8 flags); 636 struct iwl_addsta_cmd *sta, u8 flags);
638extern u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr, 637u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
639 int is_ap, u8 flags, void *ht_data); 638 u8 flags, struct ieee80211_ht_info *ht_info);
640extern int iwl4965_is_network_packet(struct iwl_priv *priv, 639extern int iwl4965_is_network_packet(struct iwl_priv *priv,
641 struct ieee80211_hdr *header); 640 struct ieee80211_hdr *header);
642extern int iwl4965_power_init_handle(struct iwl_priv *priv); 641extern int iwl4965_power_init_handle(struct iwl_priv *priv);
@@ -652,14 +651,13 @@ extern int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm);
652extern unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv, 651extern unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
653 struct ieee80211_hdr *hdr, 652 struct ieee80211_hdr *hdr,
654 const u8 *dest, int left); 653 const u8 *dest, int left);
655extern __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr);
656extern void iwl4965_update_chain_flags(struct iwl_priv *priv); 654extern void iwl4965_update_chain_flags(struct iwl_priv *priv);
657int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src); 655int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src);
658 656
659int iwl4965_init_geos(struct iwl_priv *priv); 657int iwl4965_init_geos(struct iwl_priv *priv);
660void iwl4965_free_geos(struct iwl_priv *priv); 658void iwl4965_free_geos(struct iwl_priv *priv);
661 659
662extern const u8 iwl4965_broadcast_addr[ETH_ALEN]; 660extern const u8 iwl_bcast_addr[ETH_ALEN];
663int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd); 661int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd);
664 662
665/* 663/*
@@ -687,19 +685,15 @@ extern u8 iwl4965_sync_station(struct iwl_priv *priv, int sta_id,
687 ****************************************************************************/ 685 ****************************************************************************/
688extern void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv); 686extern void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv);
689extern void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv); 687extern void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv);
690extern int iwl4965_hw_rxq_stop(struct iwl_priv *priv);
691extern int iwl4965_hw_set_hw_params(struct iwl_priv *priv); 688extern int iwl4965_hw_set_hw_params(struct iwl_priv *priv);
692extern int iwl4965_hw_nic_stop_master(struct iwl_priv *priv); 689extern int iwl_rxq_stop(struct iwl_priv *priv);
693extern void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv); 690extern void iwl_txq_ctx_stop(struct iwl_priv *priv);
694extern int iwl4965_hw_nic_reset(struct iwl_priv *priv);
695extern int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *tfd,
696 dma_addr_t addr, u16 len);
697extern int iwl4965_hw_get_temperature(struct iwl_priv *priv); 691extern int iwl4965_hw_get_temperature(struct iwl_priv *priv);
698extern unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv, 692extern unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
699 struct iwl4965_frame *frame, u8 rate); 693 struct iwl_frame *frame, u8 rate);
700extern void iwl4965_hw_build_tx_cmd_rate(struct iwl_priv *priv, 694extern void iwl4965_hw_build_tx_cmd_rate(struct iwl_priv *priv,
701 struct iwl_cmd *cmd, 695 struct iwl_cmd *cmd,
702 struct ieee80211_tx_control *ctrl, 696 struct ieee80211_tx_info *info,
703 struct ieee80211_hdr *hdr, 697 struct ieee80211_hdr *hdr,
704 int sta_id, int tx_id); 698 int sta_id, int tx_id);
705extern int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv); 699extern int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv);
@@ -708,6 +702,8 @@ extern void iwl4965_hw_rx_statistics(struct iwl_priv *priv,
708 struct iwl_rx_mem_buffer *rxb); 702 struct iwl_rx_mem_buffer *rxb);
709extern void iwl4965_disable_events(struct iwl_priv *priv); 703extern void iwl4965_disable_events(struct iwl_priv *priv);
710extern int iwl4965_get_temperature(const struct iwl_priv *priv); 704extern int iwl4965_get_temperature(const struct iwl_priv *priv);
705extern void iwl4965_rx_reply_rx(struct iwl_priv *priv,
706 struct iwl_rx_mem_buffer *rxb);
711 707
712/** 708/**
713 * iwl_find_station - Find station id for a given BSSID 709 * iwl_find_station - Find station id for a given BSSID
@@ -720,8 +716,26 @@ extern int iwl4965_get_temperature(const struct iwl_priv *priv);
720extern u8 iwl_find_station(struct iwl_priv *priv, const u8 *bssid); 716extern u8 iwl_find_station(struct iwl_priv *priv, const u8 *bssid);
721 717
722extern int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel); 718extern int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel);
723extern int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index); 719extern int iwl_queue_space(const struct iwl_queue *q);
724extern int iwl4965_queue_space(const struct iwl4965_queue *q); 720static inline int iwl_queue_used(const struct iwl_queue *q, int i)
721{
722 return q->write_ptr > q->read_ptr ?
723 (i >= q->read_ptr && i < q->write_ptr) :
724 !(i < q->read_ptr && i >= q->write_ptr);
725}
726
727
728static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge)
729{
730 /* This is for scan command, the big buffer at end of command array */
731 if (is_huge)
732 return q->n_window; /* must be power of 2 */
733
734 /* Otherwise, use normal size buffers */
735 return index & (q->n_window - 1);
736}
737
738
725struct iwl_priv; 739struct iwl_priv;
726 740
727extern void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio); 741extern void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio);
@@ -731,14 +745,12 @@ extern void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio);
731extern int iwl4965_tx_queue_update_wr_ptr(struct iwl_priv *priv, 745extern int iwl4965_tx_queue_update_wr_ptr(struct iwl_priv *priv,
732 struct iwl_tx_queue *txq, 746 struct iwl_tx_queue *txq,
733 u16 byte_cnt); 747 u16 byte_cnt);
734extern void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr,
735 int is_ap);
736extern int iwl4965_alive_notify(struct iwl_priv *priv); 748extern int iwl4965_alive_notify(struct iwl_priv *priv);
737extern void iwl4965_update_rate_scaling(struct iwl_priv *priv, u8 mode); 749extern void iwl4965_update_rate_scaling(struct iwl_priv *priv, u8 mode);
738extern void iwl4965_rf_kill_ct_config(struct iwl_priv *priv); 750extern void iwl4965_rf_kill_ct_config(struct iwl_priv *priv);
739extern void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, 751extern void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv,
740 u32 rate_n_flags, 752 u32 rate_n_flags,
741 struct ieee80211_tx_control *control); 753 struct ieee80211_tx_info *info);
742 754
743#ifdef CONFIG_IWL4965_HT 755#ifdef CONFIG_IWL4965_HT
744extern void iwl4965_init_ht_hw_capab(const struct iwl_priv *priv, 756extern void iwl4965_init_ht_hw_capab(const struct iwl_priv *priv,
@@ -746,8 +758,6 @@ extern void iwl4965_init_ht_hw_capab(const struct iwl_priv *priv,
746 enum ieee80211_band band); 758 enum ieee80211_band band);
747void iwl4965_set_rxon_ht(struct iwl_priv *priv, 759void iwl4965_set_rxon_ht(struct iwl_priv *priv,
748 struct iwl_ht_info *ht_info); 760 struct iwl_ht_info *ht_info);
749void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index,
750 struct ieee80211_ht_info *sta_ht_inf);
751int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw, 761int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
752 enum ieee80211_ampdu_mlme_action action, 762 enum ieee80211_ampdu_mlme_action action,
753 const u8 *addr, u16 tid, u16 *ssn); 763 const u8 *addr, u16 tid, u16 *ssn);
@@ -867,6 +877,21 @@ struct statistics_general_data {
867 u32 beacon_energy_c; 877 u32 beacon_energy_c;
868}; 878};
869 879
880struct iwl_calib_results {
881 void *tx_iq_res;
882 void *tx_iq_perd_res;
883 void *lo_res;
884 u32 tx_iq_res_len;
885 u32 tx_iq_perd_res_len;
886 u32 lo_res_len;
887};
888
889enum ucode_type {
890 UCODE_NONE = 0,
891 UCODE_INIT,
892 UCODE_RT
893};
894
870#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB 895#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
871/* Sensitivity calib data */ 896/* Sensitivity calib data */
872struct iwl_sensitivity_data { 897struct iwl_sensitivity_data {
@@ -968,6 +993,9 @@ struct iwl_priv {
968 s32 temperature; /* degrees Kelvin */ 993 s32 temperature; /* degrees Kelvin */
969 s32 last_temperature; 994 s32 last_temperature;
970 995
996 /* init calibration results */
997 struct iwl_calib_results calib_results;
998
971 /* Scan related variables */ 999 /* Scan related variables */
972 unsigned long last_scan_jiffies; 1000 unsigned long last_scan_jiffies;
973 unsigned long next_scan_jiffies; 1001 unsigned long next_scan_jiffies;
@@ -1001,6 +1029,8 @@ struct iwl_priv {
1001 struct fw_desc ucode_init; /* initialization inst */ 1029 struct fw_desc ucode_init; /* initialization inst */
1002 struct fw_desc ucode_init_data; /* initialization data */ 1030 struct fw_desc ucode_init_data; /* initialization data */
1003 struct fw_desc ucode_boot; /* bootstrap inst */ 1031 struct fw_desc ucode_boot; /* bootstrap inst */
1032 enum ucode_type ucode_type;
1033 u8 ucode_write_complete; /* the image write is complete */
1004 1034
1005 1035
1006 struct iwl4965_rxon_time_cmd rxon_timing; 1036 struct iwl4965_rxon_time_cmd rxon_timing;
@@ -1009,16 +1039,16 @@ struct iwl_priv {
1009 * changed via explicit cast within the 1039 * changed via explicit cast within the
1010 * routines that actually update the physical 1040 * routines that actually update the physical
1011 * hardware */ 1041 * hardware */
1012 const struct iwl4965_rxon_cmd active_rxon; 1042 const struct iwl_rxon_cmd active_rxon;
1013 struct iwl4965_rxon_cmd staging_rxon; 1043 struct iwl_rxon_cmd staging_rxon;
1014 1044
1015 int error_recovering; 1045 int error_recovering;
1016 struct iwl4965_rxon_cmd recovery_rxon; 1046 struct iwl_rxon_cmd recovery_rxon;
1017 1047
1018 /* 1st responses from initialize and runtime uCode images. 1048 /* 1st responses from initialize and runtime uCode images.
1019 * 4965's initialize alive response contains some calibration data. */ 1049 * 4965's initialize alive response contains some calibration data. */
1020 struct iwl4965_init_alive_resp card_alive_init; 1050 struct iwl_init_alive_resp card_alive_init;
1021 struct iwl4965_alive_resp card_alive; 1051 struct iwl_alive_resp card_alive;
1022#ifdef CONFIG_IWLWIFI_RFKILL 1052#ifdef CONFIG_IWLWIFI_RFKILL
1023 struct iwl_rfkill_mngr rfkill_mngr; 1053 struct iwl_rfkill_mngr rfkill_mngr;
1024#endif 1054#endif
@@ -1107,8 +1137,6 @@ struct iwl_priv {
1107 1137
1108 u8 mac80211_registered; 1138 u8 mac80211_registered;
1109 1139
1110 u32 notif_missed_beacons;
1111
1112 /* Rx'd packet timing information */ 1140 /* Rx'd packet timing information */
1113 u32 last_beacon_time; 1141 u32 last_beacon_time;
1114 u64 last_tsf; 1142 u64 last_tsf;
@@ -1195,12 +1223,56 @@ struct iwl_priv {
1195#endif /* CONFIG_IWLWIFI_DEBUG */ 1223#endif /* CONFIG_IWLWIFI_DEBUG */
1196 1224
1197 struct work_struct txpower_work; 1225 struct work_struct txpower_work;
1226#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
1227 u32 disable_sens_cal;
1228 u32 disable_chain_noise_cal;
1229#endif /* CONFIG_IWLWIFI_RUN_TIME_CALIB */
1198#ifdef CONFIG_IWL4965_RUN_TIME_CALIB 1230#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1199 struct work_struct sensitivity_work; 1231 struct work_struct sensitivity_work;
1200#endif 1232#endif /* CONFIG_IWL4965_RUN_TIME_CALIB */
1201 struct timer_list statistics_periodic; 1233 struct timer_list statistics_periodic;
1202}; /*iwl_priv */ 1234}; /*iwl_priv */
1203 1235
1236static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
1237{
1238 set_bit(txq_id, &priv->txq_ctx_active_msk);
1239}
1240
1241static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
1242{
1243 clear_bit(txq_id, &priv->txq_ctx_active_msk);
1244}
1245
1246#ifdef CONFIG_IWLWIF_DEBUG
1247const char *iwl_get_tx_fail_reason(u32 status);
1248#else
1249static inline const char *iwl_get_tx_fail_reason(u32 status) { return ""; }
1250#endif
1251
1252
1253#ifdef CONFIG_IWL4965_HT
1254static inline int iwl_get_ra_sta_id(struct iwl_priv *priv,
1255 struct ieee80211_hdr *hdr)
1256{
1257 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
1258 return IWL_AP_ID;
1259 } else {
1260 u8 *da = ieee80211_get_DA(hdr);
1261 return iwl_find_station(priv, da);
1262 }
1263}
1264
1265static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
1266 int txq_id, int idx)
1267{
1268 if (priv->txq[txq_id].txb[idx].skb[0])
1269 return (struct ieee80211_hdr *)priv->txq[txq_id].
1270 txb[idx].skb[0]->data;
1271 return NULL;
1272}
1273#endif
1274
1275
1204static inline int iwl_is_associated(struct iwl_priv *priv) 1276static inline int iwl_is_associated(struct iwl_priv *priv)
1205{ 1277{
1206 return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0; 1278 return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.c b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
index fa306601a550..11f9d9557a0e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.c
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
@@ -365,11 +365,11 @@ static void iwl_init_band_reference(const struct iwl_priv *priv,
365 ? # x " " : "") 365 ? # x " " : "")
366 366
367/** 367/**
368 * iwl4965_set_fat_chan_info - Copy fat channel info into driver's priv. 368 * iwl_set_fat_chan_info - Copy fat channel info into driver's priv.
369 * 369 *
370 * Does not set up a command, or touch hardware. 370 * Does not set up a command, or touch hardware.
371 */ 371 */
372static int iwl4965_set_fat_chan_info(struct iwl_priv *priv, 372static int iwl_set_fat_chan_info(struct iwl_priv *priv,
373 enum ieee80211_band band, u16 channel, 373 enum ieee80211_band band, u16 channel,
374 const struct iwl_eeprom_channel *eeprom_ch, 374 const struct iwl_eeprom_channel *eeprom_ch,
375 u8 fat_extension_channel) 375 u8 fat_extension_channel)
@@ -542,16 +542,16 @@ int iwl_init_channel_map(struct iwl_priv *priv)
542 fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE; 542 fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE;
543 543
544 /* Set up driver's info for lower half */ 544 /* Set up driver's info for lower half */
545 iwl4965_set_fat_chan_info(priv, ieeeband, 545 iwl_set_fat_chan_info(priv, ieeeband,
546 eeprom_ch_index[ch], 546 eeprom_ch_index[ch],
547 &(eeprom_ch_info[ch]), 547 &(eeprom_ch_info[ch]),
548 fat_extension_chan); 548 fat_extension_chan);
549 549
550 /* Set up driver's info for upper half */ 550 /* Set up driver's info for upper half */
551 iwl4965_set_fat_chan_info(priv, ieeeband, 551 iwl_set_fat_chan_info(priv, ieeeband,
552 (eeprom_ch_index[ch] + 4), 552 (eeprom_ch_index[ch] + 4),
553 &(eeprom_ch_info[ch]), 553 &(eeprom_ch_info[ch]),
554 HT_IE_EXT_CHANNEL_BELOW); 554 HT_IE_EXT_CHANNEL_BELOW);
555 } 555 }
556 } 556 }
557 557
@@ -560,23 +560,21 @@ int iwl_init_channel_map(struct iwl_priv *priv)
560EXPORT_SYMBOL(iwl_init_channel_map); 560EXPORT_SYMBOL(iwl_init_channel_map);
561 561
562/* 562/*
563 * iwl_free_channel_map - undo allocations in iwl4965_init_channel_map 563 * iwl_free_channel_map - undo allocations in iwl_init_channel_map
564 */ 564 */
565void iwl_free_channel_map(struct iwl_priv *priv) 565void iwl_free_channel_map(struct iwl_priv *priv)
566{ 566{
567 kfree(priv->channel_info); 567 kfree(priv->channel_info);
568 priv->channel_count = 0; 568 priv->channel_count = 0;
569} 569}
570EXPORT_SYMBOL(iwl_free_channel_map);
571 570
572/** 571/**
573 * iwl_get_channel_info - Find driver's private channel info 572 * iwl_get_channel_info - Find driver's private channel info
574 * 573 *
575 * Based on band and channel number. 574 * Based on band and channel number.
576 */ 575 */
577const struct iwl_channel_info *iwl_get_channel_info( 576const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv,
578 const struct iwl_priv *priv, 577 enum ieee80211_band band, u16 channel)
579 enum ieee80211_band band, u16 channel)
580{ 578{
581 int i; 579 int i;
582 580
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.h b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
index dc1f027c66a0..d3a2a5b4ac56 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.h
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
@@ -146,6 +146,7 @@ struct iwl_eeprom_channel {
146 146
147/*5000 calibrations */ 147/*5000 calibrations */
148#define EEPROM_5000_CALIB_ALL (INDIRECT_ADDRESS | INDIRECT_CALIBRATION) 148#define EEPROM_5000_CALIB_ALL (INDIRECT_ADDRESS | INDIRECT_CALIBRATION)
149#define EEPROM_5000_XTAL ((2*0x128) | EEPROM_5000_CALIB_ALL)
149 150
150/* 5000 links */ 151/* 5000 links */
151#define EEPROM_5000_LINK_HOST (2*0x64) 152#define EEPROM_5000_LINK_HOST (2*0x64)
diff --git a/drivers/net/wireless/iwlwifi/iwl-hcmd.c b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
index 0412adf6ef8b..6c537360820b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-hcmd.c
+++ b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
@@ -56,6 +56,7 @@ const char *get_cmd_string(u8 cmd)
56 IWL_CMD(REPLY_RATE_SCALE); 56 IWL_CMD(REPLY_RATE_SCALE);
57 IWL_CMD(REPLY_LEDS_CMD); 57 IWL_CMD(REPLY_LEDS_CMD);
58 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD); 58 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
59 IWL_CMD(COEX_PRIORITY_TABLE_CMD);
59 IWL_CMD(RADAR_NOTIFICATION); 60 IWL_CMD(RADAR_NOTIFICATION);
60 IWL_CMD(REPLY_QUIET_CMD); 61 IWL_CMD(REPLY_QUIET_CMD);
61 IWL_CMD(REPLY_CHANNEL_SWITCH); 62 IWL_CMD(REPLY_CHANNEL_SWITCH);
@@ -89,6 +90,9 @@ const char *get_cmd_string(u8 cmd)
89 IWL_CMD(REPLY_RX_MPDU_CMD); 90 IWL_CMD(REPLY_RX_MPDU_CMD);
90 IWL_CMD(REPLY_RX); 91 IWL_CMD(REPLY_RX);
91 IWL_CMD(REPLY_COMPRESSED_BA); 92 IWL_CMD(REPLY_COMPRESSED_BA);
93 IWL_CMD(CALIBRATION_CFG_CMD);
94 IWL_CMD(CALIBRATION_RES_NOTIFICATION);
95 IWL_CMD(CALIBRATION_COMPLETE_NOTIFICATION);
92 default: 96 default:
93 return "UNKNOWN"; 97 return "UNKNOWN";
94 98
@@ -139,7 +143,7 @@ static int iwl_send_cmd_async(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
139 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 143 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
140 return -EBUSY; 144 return -EBUSY;
141 145
142 ret = priv->cfg->ops->utils->enqueue_hcmd(priv, cmd); 146 ret = iwl_enqueue_hcmd(priv, cmd);
143 if (ret < 0) { 147 if (ret < 0) {
144 IWL_ERROR("Error sending %s: enqueue_hcmd failed: %d\n", 148 IWL_ERROR("Error sending %s: enqueue_hcmd failed: %d\n",
145 get_cmd_string(cmd->id), ret); 149 get_cmd_string(cmd->id), ret);
@@ -170,7 +174,7 @@ int iwl_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
170 if (cmd->meta.flags & CMD_WANT_SKB) 174 if (cmd->meta.flags & CMD_WANT_SKB)
171 cmd->meta.source = &cmd->meta; 175 cmd->meta.source = &cmd->meta;
172 176
173 cmd_idx = priv->cfg->ops->utils->enqueue_hcmd(priv, cmd); 177 cmd_idx = iwl_enqueue_hcmd(priv, cmd);
174 if (cmd_idx < 0) { 178 if (cmd_idx < 0) {
175 ret = cmd_idx; 179 ret = cmd_idx;
176 IWL_ERROR("Error sending %s: enqueue_hcmd failed: %d\n", 180 IWL_ERROR("Error sending %s: enqueue_hcmd failed: %d\n",
diff --git a/drivers/net/wireless/iwlwifi/iwl-helpers.h b/drivers/net/wireless/iwlwifi/iwl-helpers.h
index a443472bea62..dedefa06ad8f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-helpers.h
+++ b/drivers/net/wireless/iwlwifi/iwl-helpers.h
@@ -136,6 +136,8 @@ static inline void iwl_set_bits16(__le16 *dst, u8 pos, u8 len, int val)
136 136
137#define KELVIN_TO_CELSIUS(x) ((x)-273) 137#define KELVIN_TO_CELSIUS(x) ((x)-273)
138#define CELSIUS_TO_KELVIN(x) ((x)+273) 138#define CELSIUS_TO_KELVIN(x) ((x)+273)
139#define IWL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
140
139 141
140#define IEEE80211_CHAN_W_RADAR_DETECT 0x00000010 142#define IEEE80211_CHAN_W_RADAR_DETECT 0x00000010
141 143
@@ -235,6 +237,25 @@ static inline int ieee80211_is_reassoc_response(u16 fc)
235 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_RESP); 237 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_RESP);
236} 238}
237 239
240static inline int ieee80211_is_qos_data(u16 fc)
241{
242 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
243 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_QOS_DATA);
244}
245/**
246 * ieee80211_get_qos_ctrl - get pointer to the QoS control field
247 *
248 * This function returns the pointer to 802.11 header QoS field (2 bytes)
249 * This function doesn't check whether hdr is a QoS hdr, use with care
250 * @hdr: struct ieee80211_hdr *hdr
251 * @hdr_len: header length
252 */
253
254static inline u8 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr, int hdr_len)
255{
256 return ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
257}
258
238static inline int iwl_check_bits(unsigned long field, unsigned long mask) 259static inline int iwl_check_bits(unsigned long field, unsigned long mask)
239{ 260{
240 return ((field & mask) == mask) ? 1 : 0; 261 return ((field & mask) == mask) ? 1 : 0;
diff --git a/drivers/net/wireless/iwlwifi/iwl-prph.h b/drivers/net/wireless/iwlwifi/iwl-prph.h
index acac629386e0..70d9c7568b98 100644
--- a/drivers/net/wireless/iwlwifi/iwl-prph.h
+++ b/drivers/net/wireless/iwlwifi/iwl-prph.h
@@ -358,11 +358,6 @@
358 * 7- 0: Enable (1), disable (0), one bit for each channel 0-7 358 * 7- 0: Enable (1), disable (0), one bit for each channel 0-7
359 */ 359 */
360#define IWL49_SCD_TXFACT (IWL49_SCD_START_OFFSET + 0x1c) 360#define IWL49_SCD_TXFACT (IWL49_SCD_START_OFFSET + 0x1c)
361
362/* Mask to enable contiguous Tx DMA/FIFO channels between "lo" and "hi". */
363#define SCD_TXFACT_REG_TXFIFO_MASK(lo, hi) \
364 ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
365
366/* 361/*
367 * Queue (x) Write Pointers (indexes, really!), one for each Tx queue. 362 * Queue (x) Write Pointers (indexes, really!), one for each Tx queue.
368 * Initialized and updated by driver as new TFDs are added to queue. 363 * Initialized and updated by driver as new TFDs are added to queue.
@@ -512,11 +507,39 @@
512#define IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \ 507#define IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \
513 ((IWL49_SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffffffc) 508 ((IWL49_SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffffffc)
514 509
515#define IWL49_SCD_TXFIFO_POS_TID (0) 510#define IWL_SCD_TXFIFO_POS_TID (0)
516#define IWL49_SCD_TXFIFO_POS_RA (4) 511#define IWL_SCD_TXFIFO_POS_RA (4)
517#define IWL49_SCD_QUEUE_RA_TID_MAP_RATID_MSK (0x01FF) 512#define IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK (0x01FF)
518 513
519/* 5000 SCD */ 514/* 5000 SCD */
515#define IWL50_SCD_QUEUE_STTS_REG_POS_TXF (0)
516#define IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE (3)
517#define IWL50_SCD_QUEUE_STTS_REG_POS_WSL (4)
518#define IWL50_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN (19)
519#define IWL50_SCD_QUEUE_STTS_REG_MSK (0x00FF0000)
520
521#define IWL50_SCD_QUEUE_CTX_REG1_CREDIT_POS (8)
522#define IWL50_SCD_QUEUE_CTX_REG1_CREDIT_MSK (0x00FFFF00)
523#define IWL50_SCD_QUEUE_CTX_REG1_SUPER_CREDIT_POS (24)
524#define IWL50_SCD_QUEUE_CTX_REG1_SUPER_CREDIT_MSK (0xFF000000)
525#define IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS (0)
526#define IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK (0x0000007F)
527#define IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS (16)
528#define IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK (0x007F0000)
529
530#define IWL50_SCD_CONTEXT_DATA_OFFSET (0x600)
531#define IWL50_SCD_TX_STTS_BITMAP_OFFSET (0x7B1)
532#define IWL50_SCD_TRANSLATE_TBL_OFFSET (0x7E0)
533
534#define IWL50_SCD_CONTEXT_QUEUE_OFFSET(x)\
535 (IWL50_SCD_CONTEXT_DATA_OFFSET + ((x) * 8))
536
537#define IWL50_SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \
538 ((IWL50_SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffc)
539
540#define IWL50_SCD_QUEUECHAIN_SEL_ALL(x) (((1<<(x)) - 1) &\
541 (~(1<<IWL_CMD_QUEUE_NUM)))
542
520#define IWL50_SCD_BASE (PRPH_BASE + 0xa02c00) 543#define IWL50_SCD_BASE (PRPH_BASE + 0xa02c00)
521 544
522#define IWL50_SCD_SRAM_BASE_ADDR (IWL50_SCD_BASE + 0x0) 545#define IWL50_SCD_SRAM_BASE_ADDR (IWL50_SCD_BASE + 0x0)
diff --git a/drivers/net/wireless/iwlwifi/iwl-rx.c b/drivers/net/wireless/iwlwifi/iwl-rx.c
index a2eb90d40b7e..cc61c937320f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rx.c
@@ -33,6 +33,7 @@
33#include "iwl-core.h" 33#include "iwl-core.h"
34#include "iwl-sta.h" 34#include "iwl-sta.h"
35#include "iwl-io.h" 35#include "iwl-io.h"
36#include "iwl-calib.h"
36#include "iwl-helpers.h" 37#include "iwl-helpers.h"
37/************************** RX-FUNCTIONS ****************************/ 38/************************** RX-FUNCTIONS ****************************/
38/* 39/*
@@ -420,3 +421,50 @@ int iwl_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
420 return 0; 421 return 0;
421} 422}
422 423
424int iwl_rxq_stop(struct iwl_priv *priv)
425{
426 int ret;
427 unsigned long flags;
428
429 spin_lock_irqsave(&priv->lock, flags);
430 ret = iwl_grab_nic_access(priv);
431 if (unlikely(ret)) {
432 spin_unlock_irqrestore(&priv->lock, flags);
433 return ret;
434 }
435
436 /* stop Rx DMA */
437 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
438 ret = iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
439 (1 << 24), 1000);
440 if (ret < 0)
441 IWL_ERROR("Can't stop Rx DMA.\n");
442
443 iwl_release_nic_access(priv);
444 spin_unlock_irqrestore(&priv->lock, flags);
445
446 return 0;
447}
448EXPORT_SYMBOL(iwl_rxq_stop);
449
450void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
451 struct iwl_rx_mem_buffer *rxb)
452
453{
454#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
455 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
456 struct iwl4965_missed_beacon_notif *missed_beacon;
457
458 missed_beacon = &pkt->u.missed_beacon;
459 if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) {
460 IWL_DEBUG_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
461 le32_to_cpu(missed_beacon->consequtive_missed_beacons),
462 le32_to_cpu(missed_beacon->total_missed_becons),
463 le32_to_cpu(missed_beacon->num_recvd_beacons),
464 le32_to_cpu(missed_beacon->num_expected_beacons));
465 if (!test_bit(STATUS_SCANNING, &priv->status))
466 iwl_init_sensitivity(priv);
467 }
468#endif /* CONFIG_IWLWIFI_RUN_TIME_CALIB */
469}
470EXPORT_SYMBOL(iwl_rx_missed_beacon_notif);
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index f2267047d102..983f10760fb0 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -37,6 +37,10 @@
37#include "iwl-io.h" 37#include "iwl-io.h"
38#include "iwl-helpers.h" 38#include "iwl-helpers.h"
39 39
40
41#define IWL_STA_DRIVER_ACTIVE 0x1 /* ucode entry is active */
42#define IWL_STA_UCODE_ACTIVE 0x2 /* ucode entry is active */
43
40u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr) 44u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
41{ 45{
42 int i; 46 int i;
@@ -70,6 +74,39 @@ u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
70} 74}
71EXPORT_SYMBOL(iwl_find_station); 75EXPORT_SYMBOL(iwl_find_station);
72 76
77static int iwl_add_sta_callback(struct iwl_priv *priv,
78 struct iwl_cmd *cmd, struct sk_buff *skb)
79{
80 struct iwl_rx_packet *res = NULL;
81
82 if (!skb) {
83 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
84 return 1;
85 }
86
87 res = (struct iwl_rx_packet *)skb->data;
88 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
89 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
90 res->hdr.flags);
91 return 1;
92 }
93
94 switch (res->u.add_sta.status) {
95 case ADD_STA_SUCCESS_MSK:
96 /* FIXME: implement iwl_sta_ucode_activate(priv, addr); */
97 /* fail through */
98 default:
99 IWL_DEBUG_HC("Received REPLY_ADD_STA:(0x%08X)\n",
100 res->u.add_sta.status);
101 break;
102 }
103
104 /* We didn't cache the SKB; let the caller free it */
105 return 1;
106}
107
108
109
73int iwl_send_add_sta(struct iwl_priv *priv, 110int iwl_send_add_sta(struct iwl_priv *priv,
74 struct iwl_addsta_cmd *sta, u8 flags) 111 struct iwl_addsta_cmd *sta, u8 flags)
75{ 112{
@@ -82,7 +119,9 @@ int iwl_send_add_sta(struct iwl_priv *priv,
82 .data = data, 119 .data = data,
83 }; 120 };
84 121
85 if (!(flags & CMD_ASYNC)) 122 if (flags & CMD_ASYNC)
123 cmd.meta.u.callback = iwl_add_sta_callback;
124 else
86 cmd.meta.flags |= CMD_WANT_SKB; 125 cmd.meta.flags |= CMD_WANT_SKB;
87 126
88 cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data); 127 cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data);
@@ -117,6 +156,276 @@ int iwl_send_add_sta(struct iwl_priv *priv,
117} 156}
118EXPORT_SYMBOL(iwl_send_add_sta); 157EXPORT_SYMBOL(iwl_send_add_sta);
119 158
159#ifdef CONFIG_IWL4965_HT
160
161static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
162 struct ieee80211_ht_info *sta_ht_inf)
163{
164 __le32 sta_flags;
165 u8 mimo_ps_mode;
166
167 if (!sta_ht_inf || !sta_ht_inf->ht_supported)
168 goto done;
169
170 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2;
171
172 sta_flags = priv->stations[index].sta.station_flags;
173
174 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
175
176 switch (mimo_ps_mode) {
177 case WLAN_HT_CAP_MIMO_PS_STATIC:
178 sta_flags |= STA_FLG_MIMO_DIS_MSK;
179 break;
180 case WLAN_HT_CAP_MIMO_PS_DYNAMIC:
181 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
182 break;
183 case WLAN_HT_CAP_MIMO_PS_DISABLED:
184 break;
185 default:
186 IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode);
187 break;
188 }
189
190 sta_flags |= cpu_to_le32(
191 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
192
193 sta_flags |= cpu_to_le32(
194 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
195
196 if (iwl_is_fat_tx_allowed(priv, sta_ht_inf))
197 sta_flags |= STA_FLG_FAT_EN_MSK;
198 else
199 sta_flags &= ~STA_FLG_FAT_EN_MSK;
200
201 priv->stations[index].sta.station_flags = sta_flags;
202 done:
203 return;
204}
205#else
206static inline void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
207 struct ieee80211_ht_info *sta_ht_info)
208{
209}
210#endif
211
212/**
213 * iwl_add_station_flags - Add station to tables in driver and device
214 */
215u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
216 u8 flags, struct ieee80211_ht_info *ht_info)
217{
218 int i;
219 int index = IWL_INVALID_STATION;
220 struct iwl_station_entry *station;
221 unsigned long flags_spin;
222 DECLARE_MAC_BUF(mac);
223
224 spin_lock_irqsave(&priv->sta_lock, flags_spin);
225 if (is_ap)
226 index = IWL_AP_ID;
227 else if (is_broadcast_ether_addr(addr))
228 index = priv->hw_params.bcast_sta_id;
229 else
230 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
231 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
232 addr)) {
233 index = i;
234 break;
235 }
236
237 if (!priv->stations[i].used &&
238 index == IWL_INVALID_STATION)
239 index = i;
240 }
241
242
243 /* These two conditions have the same outcome, but keep them separate
244 since they have different meanings */
245 if (unlikely(index == IWL_INVALID_STATION)) {
246 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
247 return index;
248 }
249
250 if (priv->stations[index].used &&
251 !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
252 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
253 return index;
254 }
255
256
257 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
258 station = &priv->stations[index];
259 station->used = 1;
260 priv->num_stations++;
261
262 /* Set up the REPLY_ADD_STA command to send to device */
263 memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
264 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
265 station->sta.mode = 0;
266 station->sta.sta.sta_id = index;
267 station->sta.station_flags = 0;
268
269 /* BCAST station and IBSS stations do not work in HT mode */
270 if (index != priv->hw_params.bcast_sta_id &&
271 priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
272 iwl_set_ht_add_station(priv, index, ht_info);
273
274 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
275
276 /* Add station to device's station table */
277 iwl_send_add_sta(priv, &station->sta, flags);
278 return index;
279
280}
281EXPORT_SYMBOL(iwl_add_station_flags);
282
283
284static int iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr)
285{
286 unsigned long flags;
287 u8 sta_id;
288 DECLARE_MAC_BUF(mac);
289
290 sta_id = iwl_find_station(priv, addr);
291 if (sta_id != IWL_INVALID_STATION) {
292 IWL_DEBUG_ASSOC("Removed STA from Ucode: %s\n",
293 print_mac(mac, addr));
294 spin_lock_irqsave(&priv->sta_lock, flags);
295 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
296 memset(&priv->stations[sta_id], 0,
297 sizeof(struct iwl_station_entry));
298 spin_unlock_irqrestore(&priv->sta_lock, flags);
299 return 0;
300 }
301 return -EINVAL;
302}
303
304static int iwl_remove_sta_callback(struct iwl_priv *priv,
305 struct iwl_cmd *cmd, struct sk_buff *skb)
306{
307 struct iwl_rx_packet *res = NULL;
308 const char *addr = cmd->cmd.rm_sta.addr;
309
310 if (!skb) {
311 IWL_ERROR("Error: Response NULL in REPLY_REMOVE_STA.\n");
312 return 1;
313 }
314
315 res = (struct iwl_rx_packet *)skb->data;
316 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
317 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
318 res->hdr.flags);
319 return 1;
320 }
321
322 switch (res->u.rem_sta.status) {
323 case REM_STA_SUCCESS_MSK:
324 iwl_sta_ucode_deactivate(priv, addr);
325 break;
326 default:
327 break;
328 }
329
330 /* We didn't cache the SKB; let the caller free it */
331 return 1;
332}
333
334static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
335 u8 flags)
336{
337 struct iwl_rx_packet *res = NULL;
338 int ret;
339
340 struct iwl_rem_sta_cmd rm_sta_cmd;
341
342 struct iwl_host_cmd cmd = {
343 .id = REPLY_REMOVE_STA,
344 .len = sizeof(struct iwl_rem_sta_cmd),
345 .meta.flags = flags,
346 .data = &rm_sta_cmd,
347 };
348
349 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
350 rm_sta_cmd.num_sta = 1;
351 memcpy(&rm_sta_cmd.addr, addr , ETH_ALEN);
352
353 if (flags & CMD_ASYNC)
354 cmd.meta.u.callback = iwl_remove_sta_callback;
355 else
356 cmd.meta.flags |= CMD_WANT_SKB;
357 ret = iwl_send_cmd(priv, &cmd);
358
359 if (ret || (flags & CMD_ASYNC))
360 return ret;
361
362 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
363 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
364 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
365 res->hdr.flags);
366 ret = -EIO;
367 }
368
369 if (!ret) {
370 switch (res->u.rem_sta.status) {
371 case REM_STA_SUCCESS_MSK:
372 iwl_sta_ucode_deactivate(priv, addr);
373 IWL_DEBUG_ASSOC("REPLY_REMOVE_STA PASSED\n");
374 break;
375 default:
376 ret = -EIO;
377 IWL_ERROR("REPLY_REMOVE_STA failed\n");
378 break;
379 }
380 }
381
382 priv->alloc_rxb_skb--;
383 dev_kfree_skb_any(cmd.meta.u.skb);
384
385 return ret;
386}
387/**
388 * iwl_remove_station - Remove driver's knowledge of station.
389 *
390 */
391u8 iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
392{
393 int index = IWL_INVALID_STATION;
394 int i;
395 unsigned long flags;
396
397 spin_lock_irqsave(&priv->sta_lock, flags);
398
399 if (is_ap)
400 index = IWL_AP_ID;
401 else if (is_broadcast_ether_addr(addr))
402 index = priv->hw_params.bcast_sta_id;
403 else
404 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
405 if (priv->stations[i].used &&
406 !compare_ether_addr(priv->stations[i].sta.sta.addr,
407 addr)) {
408 index = i;
409 break;
410 }
411
412 if (unlikely(index == IWL_INVALID_STATION))
413 goto out;
414
415 if (priv->stations[index].used) {
416 priv->stations[index].used = 0;
417 priv->num_stations--;
418 }
419
420 BUG_ON(priv->num_stations < 0);
421 spin_unlock_irqrestore(&priv->sta_lock, flags);
422 iwl_send_remove_station(priv, addr, CMD_ASYNC);
423 return index;
424out:
425 spin_unlock_irqrestore(&priv->sta_lock, flags);
426 return 0;
427}
428EXPORT_SYMBOL(iwl_remove_station);
120int iwl_get_free_ucode_key_index(struct iwl_priv *priv) 429int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
121{ 430{
122 int i; 431 int i;
@@ -200,7 +509,7 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
200 unsigned long flags; 509 unsigned long flags;
201 510
202 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; 511 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
203 keyconf->hw_key_idx = keyconf->keyidx; 512 keyconf->hw_key_idx = HW_KEY_DEFAULT;
204 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP; 513 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
205 514
206 spin_lock_irqsave(&priv->sta_lock, flags); 515 spin_lock_irqsave(&priv->sta_lock, flags);
@@ -230,7 +539,6 @@ static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
230 int ret; 539 int ret;
231 540
232 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; 541 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
233 keyconf->hw_key_idx = keyconf->keyidx;
234 542
235 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK); 543 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
236 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); 544 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
@@ -287,7 +595,6 @@ static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
287 key_flags |= STA_KEY_MULTICAST_MSK; 595 key_flags |= STA_KEY_MULTICAST_MSK;
288 596
289 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 597 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
290 keyconf->hw_key_idx = keyconf->keyidx;
291 598
292 spin_lock_irqsave(&priv->sta_lock, flags); 599 spin_lock_irqsave(&priv->sta_lock, flags);
293 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 600 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
@@ -325,12 +632,10 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
325 632
326 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 633 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
327 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 634 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
328 keyconf->hw_key_idx = keyconf->keyidx;
329 635
330 spin_lock_irqsave(&priv->sta_lock, flags); 636 spin_lock_irqsave(&priv->sta_lock, flags);
331 637
332 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 638 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
333 priv->stations[sta_id].keyinfo.conf = keyconf;
334 priv->stations[sta_id].keyinfo.keylen = 16; 639 priv->stations[sta_id].keyinfo.keylen = 16;
335 640
336 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) 641 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
@@ -359,7 +664,7 @@ int iwl_remove_dynamic_key(struct iwl_priv *priv,
359 u16 key_flags; 664 u16 key_flags;
360 u8 keyidx; 665 u8 keyidx;
361 666
362 priv->key_mapping_key = 0; 667 priv->key_mapping_key--;
363 668
364 spin_lock_irqsave(&priv->sta_lock, flags); 669 spin_lock_irqsave(&priv->sta_lock, flags);
365 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags); 670 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
@@ -390,31 +695,32 @@ int iwl_remove_dynamic_key(struct iwl_priv *priv,
390 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 695 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
391 696
392 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); 697 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
393 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, 0); 698 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
394 spin_unlock_irqrestore(&priv->sta_lock, flags); 699 spin_unlock_irqrestore(&priv->sta_lock, flags);
395 return ret; 700 return ret;
396} 701}
397EXPORT_SYMBOL(iwl_remove_dynamic_key); 702EXPORT_SYMBOL(iwl_remove_dynamic_key);
398 703
399int iwl_set_dynamic_key(struct iwl_priv *priv, 704int iwl_set_dynamic_key(struct iwl_priv *priv,
400 struct ieee80211_key_conf *key, u8 sta_id) 705 struct ieee80211_key_conf *keyconf, u8 sta_id)
401{ 706{
402 int ret; 707 int ret;
403 708
404 priv->key_mapping_key = 1; 709 priv->key_mapping_key++;
710 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
405 711
406 switch (key->alg) { 712 switch (keyconf->alg) {
407 case ALG_CCMP: 713 case ALG_CCMP:
408 ret = iwl_set_ccmp_dynamic_key_info(priv, key, sta_id); 714 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
409 break; 715 break;
410 case ALG_TKIP: 716 case ALG_TKIP:
411 ret = iwl_set_tkip_dynamic_key_info(priv, key, sta_id); 717 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
412 break; 718 break;
413 case ALG_WEP: 719 case ALG_WEP:
414 ret = iwl_set_wep_dynamic_key_info(priv, key, sta_id); 720 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
415 break; 721 break;
416 default: 722 default:
417 IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, key->alg); 723 IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
418 ret = -EINVAL; 724 ret = -EINVAL;
419 } 725 }
420 726
@@ -470,3 +776,168 @@ int iwl_send_lq_cmd(struct iwl_priv *priv,
470} 776}
471EXPORT_SYMBOL(iwl_send_lq_cmd); 777EXPORT_SYMBOL(iwl_send_lq_cmd);
472 778
779/**
780 * iwl_sta_init_lq - Initialize a station's hardware rate table
781 *
782 * The uCode's station table contains a table of fallback rates
783 * for automatic fallback during transmission.
784 *
785 * NOTE: This sets up a default set of values. These will be replaced later
786 * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
787 * rc80211_simple.
788 *
789 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
790 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
791 * which requires station table entry to exist).
792 */
793static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap)
794{
795 int i, r;
796 struct iwl_link_quality_cmd link_cmd = {
797 .reserved1 = 0,
798 };
799 u16 rate_flags;
800
801 /* Set up the rate scaling to start at selected rate, fall back
802 * all the way down to 1M in IEEE order, and then spin on 1M */
803 if (is_ap)
804 r = IWL_RATE_54M_INDEX;
805 else if (priv->band == IEEE80211_BAND_5GHZ)
806 r = IWL_RATE_6M_INDEX;
807 else
808 r = IWL_RATE_1M_INDEX;
809
810 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
811 rate_flags = 0;
812 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
813 rate_flags |= RATE_MCS_CCK_MSK;
814
815 /* Use Tx antenna B only */
816 rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/
817
818 link_cmd.rs_table[i].rate_n_flags =
819 iwl4965_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
820 r = iwl4965_get_prev_ieee_rate(r);
821 }
822
823 link_cmd.general_params.single_stream_ant_msk = 2;
824 link_cmd.general_params.dual_stream_ant_msk = 3;
825 link_cmd.agg_params.agg_dis_start_th = 3;
826 link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
827
828 /* Update the rate scaling for control frame Tx to AP */
829 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
830
831 iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
832 sizeof(link_cmd), &link_cmd, NULL);
833}
834/**
835 * iwl_rxon_add_station - add station into station table.
836 *
837 * there is only one AP station with id= IWL_AP_ID
838 * NOTE: mutex must be held before calling this fnction
839 */
840int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
841{
842 u8 sta_id;
843
844 /* Add station to device's station table */
845#ifdef CONFIG_IWL4965_HT
846 struct ieee80211_conf *conf = &priv->hw->conf;
847 struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf;
848
849 if ((is_ap) &&
850 (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
851 (priv->iw_mode == IEEE80211_IF_TYPE_STA))
852 sta_id = iwl_add_station_flags(priv, addr, is_ap,
853 0, cur_ht_config);
854 else
855#endif /* CONFIG_IWL4965_HT */
856 sta_id = iwl_add_station_flags(priv, addr, is_ap,
857 0, NULL);
858
859 /* Set up default rate scaling table in device's station table */
860 iwl_sta_init_lq(priv, addr, is_ap);
861
862 return sta_id;
863}
864EXPORT_SYMBOL(iwl_rxon_add_station);
865
866
867/**
868 * iwl_get_sta_id - Find station's index within station table
869 *
870 * If new IBSS station, create new entry in station table
871 */
872int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
873{
874 int sta_id;
875 u16 fc = le16_to_cpu(hdr->frame_control);
876 DECLARE_MAC_BUF(mac);
877
878 /* If this frame is broadcast or management, use broadcast station id */
879 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
880 is_multicast_ether_addr(hdr->addr1))
881 return priv->hw_params.bcast_sta_id;
882
883 switch (priv->iw_mode) {
884
885 /* If we are a client station in a BSS network, use the special
886 * AP station entry (that's the only station we communicate with) */
887 case IEEE80211_IF_TYPE_STA:
888 return IWL_AP_ID;
889
890 /* If we are an AP, then find the station, or use BCAST */
891 case IEEE80211_IF_TYPE_AP:
892 sta_id = iwl_find_station(priv, hdr->addr1);
893 if (sta_id != IWL_INVALID_STATION)
894 return sta_id;
895 return priv->hw_params.bcast_sta_id;
896
897 /* If this frame is going out to an IBSS network, find the station,
898 * or create a new station table entry */
899 case IEEE80211_IF_TYPE_IBSS:
900 sta_id = iwl_find_station(priv, hdr->addr1);
901 if (sta_id != IWL_INVALID_STATION)
902 return sta_id;
903
904 /* Create new station table entry */
905 sta_id = iwl_add_station_flags(priv, hdr->addr1,
906 0, CMD_ASYNC, NULL);
907
908 if (sta_id != IWL_INVALID_STATION)
909 return sta_id;
910
911 IWL_DEBUG_DROP("Station %s not in station map. "
912 "Defaulting to broadcast...\n",
913 print_mac(mac, hdr->addr1));
914 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
915 return priv->hw_params.bcast_sta_id;
916
917 default:
918 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
919 return priv->hw_params.bcast_sta_id;
920 }
921}
922EXPORT_SYMBOL(iwl_get_sta_id);
923
924
925/**
926 * iwl_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
927 */
928void iwl_sta_modify_enable_tid_tx(struct iwl_priv *priv, int sta_id, int tid)
929{
930 unsigned long flags;
931
932 /* Remove "disable" flag, to enable Tx for this TID */
933 spin_lock_irqsave(&priv->sta_lock, flags);
934 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
935 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
936 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
937 spin_unlock_irqrestore(&priv->sta_lock, flags);
938
939 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
940}
941EXPORT_SYMBOL(iwl_sta_modify_enable_tid_tx);
942
943
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.h b/drivers/net/wireless/iwlwifi/iwl-sta.h
index 38b1b0a98845..3d55716f5301 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.h
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.h
@@ -29,6 +29,9 @@
29#ifndef __iwl_sta_h__ 29#ifndef __iwl_sta_h__
30#define __iwl_sta_h__ 30#define __iwl_sta_h__
31 31
32#define HW_KEY_DYNAMIC 0
33#define HW_KEY_DEFAULT 1
34
32int iwl_get_free_ucode_key_index(struct iwl_priv *priv); 35int iwl_get_free_ucode_key_index(struct iwl_priv *priv);
33int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty); 36int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty);
34int iwl_remove_default_wep_key(struct iwl_priv *priv, 37int iwl_remove_default_wep_key(struct iwl_priv *priv,
@@ -39,4 +42,8 @@ int iwl_set_dynamic_key(struct iwl_priv *priv,
39 struct ieee80211_key_conf *key, u8 sta_id); 42 struct ieee80211_key_conf *key, u8 sta_id);
40int iwl_remove_dynamic_key(struct iwl_priv *priv, 43int iwl_remove_dynamic_key(struct iwl_priv *priv,
41 struct ieee80211_key_conf *key, u8 sta_id); 44 struct ieee80211_key_conf *key, u8 sta_id);
45int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap);
46u8 iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap);
47int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr);
48void iwl_sta_modify_enable_tid_tx(struct iwl_priv *priv, int sta_id, int tid);
42#endif /* __iwl_sta_h__ */ 49#endif /* __iwl_sta_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index a1e03ccd5147..cfe6f4b233dd 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -27,6 +27,7 @@
27 * 27 *
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include <linux/etherdevice.h>
30#include <net/mac80211.h> 31#include <net/mac80211.h>
31#include "iwl-eeprom.h" 32#include "iwl-eeprom.h"
32#include "iwl-dev.h" 33#include "iwl-dev.h"
@@ -35,6 +36,32 @@
35#include "iwl-io.h" 36#include "iwl-io.h"
36#include "iwl-helpers.h" 37#include "iwl-helpers.h"
37 38
39#ifdef CONFIG_IWL4965_HT
40
41static const u16 default_tid_to_tx_fifo[] = {
42 IWL_TX_FIFO_AC1,
43 IWL_TX_FIFO_AC0,
44 IWL_TX_FIFO_AC0,
45 IWL_TX_FIFO_AC1,
46 IWL_TX_FIFO_AC2,
47 IWL_TX_FIFO_AC2,
48 IWL_TX_FIFO_AC3,
49 IWL_TX_FIFO_AC3,
50 IWL_TX_FIFO_NONE,
51 IWL_TX_FIFO_NONE,
52 IWL_TX_FIFO_NONE,
53 IWL_TX_FIFO_NONE,
54 IWL_TX_FIFO_NONE,
55 IWL_TX_FIFO_NONE,
56 IWL_TX_FIFO_NONE,
57 IWL_TX_FIFO_NONE,
58 IWL_TX_FIFO_AC3
59};
60
61#endif /*CONFIG_IWL4965_HT */
62
63
64
38/** 65/**
39 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr] 66 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
40 * 67 *
@@ -95,6 +122,89 @@ int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
95} 122}
96EXPORT_SYMBOL(iwl_hw_txq_free_tfd); 123EXPORT_SYMBOL(iwl_hw_txq_free_tfd);
97 124
125
126int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr,
127 dma_addr_t addr, u16 len)
128{
129 int index, is_odd;
130 struct iwl_tfd_frame *tfd = ptr;
131 u32 num_tbs = IWL_GET_BITS(*tfd, num_tbs);
132
133 /* Each TFD can point to a maximum 20 Tx buffers */
134 if ((num_tbs >= MAX_NUM_OF_TBS) || (num_tbs < 0)) {
135 IWL_ERROR("Error can not send more than %d chunks\n",
136 MAX_NUM_OF_TBS);
137 return -EINVAL;
138 }
139
140 index = num_tbs / 2;
141 is_odd = num_tbs & 0x1;
142
143 if (!is_odd) {
144 tfd->pa[index].tb1_addr = cpu_to_le32(addr);
145 IWL_SET_BITS(tfd->pa[index], tb1_addr_hi,
146 iwl_get_dma_hi_address(addr));
147 IWL_SET_BITS(tfd->pa[index], tb1_len, len);
148 } else {
149 IWL_SET_BITS(tfd->pa[index], tb2_addr_lo16,
150 (u32) (addr & 0xffff));
151 IWL_SET_BITS(tfd->pa[index], tb2_addr_hi20, addr >> 16);
152 IWL_SET_BITS(tfd->pa[index], tb2_len, len);
153 }
154
155 IWL_SET_BITS(*tfd, num_tbs, num_tbs + 1);
156
157 return 0;
158}
159EXPORT_SYMBOL(iwl_hw_txq_attach_buf_to_tfd);
160
161/**
162 * iwl_txq_update_write_ptr - Send new write index to hardware
163 */
164int iwl_txq_update_write_ptr(struct iwl_priv *priv, struct iwl_tx_queue *txq)
165{
166 u32 reg = 0;
167 int ret = 0;
168 int txq_id = txq->q.id;
169
170 if (txq->need_update == 0)
171 return ret;
172
173 /* if we're trying to save power */
174 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
175 /* wake up nic if it's powered down ...
176 * uCode will wake up, and interrupt us again, so next
177 * time we'll skip this part. */
178 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
179
180 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
181 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
182 iwl_set_bit(priv, CSR_GP_CNTRL,
183 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
184 return ret;
185 }
186
187 /* restore this queue's parameters in nic hardware. */
188 ret = iwl_grab_nic_access(priv);
189 if (ret)
190 return ret;
191 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
192 txq->q.write_ptr | (txq_id << 8));
193 iwl_release_nic_access(priv);
194
195 /* else not in power-save mode, uCode will never sleep when we're
196 * trying to tx (during RFKILL, we're not trying to tx). */
197 } else
198 iwl_write32(priv, HBUS_TARG_WRPTR,
199 txq->q.write_ptr | (txq_id << 8));
200
201 txq->need_update = 0;
202
203 return ret;
204}
205EXPORT_SYMBOL(iwl_txq_update_write_ptr);
206
207
98/** 208/**
99 * iwl_tx_queue_free - Deallocate DMA queue. 209 * iwl_tx_queue_free - Deallocate DMA queue.
100 * @txq: Transmit queue to deallocate. 210 * @txq: Transmit queue to deallocate.
@@ -105,7 +215,7 @@ EXPORT_SYMBOL(iwl_hw_txq_free_tfd);
105 */ 215 */
106static void iwl_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq) 216static void iwl_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq)
107{ 217{
108 struct iwl4965_queue *q = &txq->q; 218 struct iwl_queue *q = &txq->q;
109 struct pci_dev *dev = priv->pci_dev; 219 struct pci_dev *dev = priv->pci_dev;
110 int len; 220 int len;
111 221
@@ -137,28 +247,51 @@ static void iwl_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq)
137 memset(txq, 0, sizeof(*txq)); 247 memset(txq, 0, sizeof(*txq));
138} 248}
139 249
140/** 250/*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
141 * iwl_hw_txq_ctx_free - Free TXQ Context 251 * DMA services
142 * 252 *
143 * Destroy all TX DMA queues and structures 253 * Theory of operation
144 */ 254 *
145void iwl_hw_txq_ctx_free(struct iwl_priv *priv) 255 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
256 * of buffer descriptors, each of which points to one or more data buffers for
257 * the device to read from or fill. Driver and device exchange status of each
258 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
259 * entries in each circular buffer, to protect against confusing empty and full
260 * queue states.
261 *
262 * The device reads or writes the data in the queues via the device's several
263 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
264 *
265 * For Tx queue, there are low mark and high mark limits. If, after queuing
266 * the packet for Tx, free space become < low mark, Tx queue stopped. When
267 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
268 * Tx queue resumed.
269 *
270 * See more detailed info in iwl-4965-hw.h.
271 ***************************************************/
272
273int iwl_queue_space(const struct iwl_queue *q)
146{ 274{
147 int txq_id; 275 int s = q->read_ptr - q->write_ptr;
148 276
149 /* Tx queues */ 277 if (q->read_ptr > q->write_ptr)
150 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) 278 s -= q->n_bd;
151 iwl_tx_queue_free(priv, &priv->txq[txq_id]);
152 279
153 /* Keep-warm buffer */ 280 if (s <= 0)
154 iwl_kw_free(priv); 281 s += q->n_window;
282 /* keep some reserve to not confuse empty and full situations */
283 s -= 2;
284 if (s < 0)
285 s = 0;
286 return s;
155} 287}
156EXPORT_SYMBOL(iwl_hw_txq_ctx_free); 288EXPORT_SYMBOL(iwl_queue_space);
289
157 290
158/** 291/**
159 * iwl_queue_init - Initialize queue's high/low-water and read/write indexes 292 * iwl_queue_init - Initialize queue's high/low-water and read/write indexes
160 */ 293 */
161static int iwl_queue_init(struct iwl_priv *priv, struct iwl4965_queue *q, 294static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q,
162 int count, int slots_num, u32 id) 295 int count, int slots_num, u32 id)
163{ 296{
164 q->n_bd = count; 297 q->n_bd = count;
@@ -312,6 +445,24 @@ static int iwl_tx_queue_init(struct iwl_priv *priv,
312 445
313 return 0; 446 return 0;
314} 447}
448/**
449 * iwl_hw_txq_ctx_free - Free TXQ Context
450 *
451 * Destroy all TX DMA queues and structures
452 */
453void iwl_hw_txq_ctx_free(struct iwl_priv *priv)
454{
455 int txq_id;
456
457 /* Tx queues */
458 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
459 iwl_tx_queue_free(priv, &priv->txq[txq_id]);
460
461 /* Keep-warm buffer */
462 iwl_kw_free(priv);
463}
464EXPORT_SYMBOL(iwl_hw_txq_ctx_free);
465
315 466
316/** 467/**
317 * iwl_txq_ctx_reset - Reset TX queue context 468 * iwl_txq_ctx_reset - Reset TX queue context
@@ -324,6 +475,7 @@ int iwl_txq_ctx_reset(struct iwl_priv *priv)
324{ 475{
325 int ret = 0; 476 int ret = 0;
326 int txq_id, slots_num; 477 int txq_id, slots_num;
478 unsigned long flags;
327 479
328 iwl_kw_free(priv); 480 iwl_kw_free(priv);
329 481
@@ -336,11 +488,19 @@ int iwl_txq_ctx_reset(struct iwl_priv *priv)
336 IWL_ERROR("Keep Warm allocation failed"); 488 IWL_ERROR("Keep Warm allocation failed");
337 goto error_kw; 489 goto error_kw;
338 } 490 }
491 spin_lock_irqsave(&priv->lock, flags);
492 ret = iwl_grab_nic_access(priv);
493 if (unlikely(ret)) {
494 spin_unlock_irqrestore(&priv->lock, flags);
495 goto error_reset;
496 }
339 497
340 /* Turn off all Tx DMA fifos */ 498 /* Turn off all Tx DMA fifos */
341 ret = priv->cfg->ops->lib->disable_tx_fifo(priv); 499 priv->cfg->ops->lib->txq_set_sched(priv, 0);
342 if (unlikely(ret)) 500
343 goto error_reset; 501 iwl_release_nic_access(priv);
502 spin_unlock_irqrestore(&priv->lock, flags);
503
344 504
345 /* Tell nic where to find the keep-warm buffer */ 505 /* Tell nic where to find the keep-warm buffer */
346 ret = iwl_kw_init(priv); 506 ret = iwl_kw_init(priv);
@@ -349,8 +509,7 @@ int iwl_txq_ctx_reset(struct iwl_priv *priv)
349 goto error_reset; 509 goto error_reset;
350 } 510 }
351 511
352 /* Alloc and init all (default 16) Tx queues, 512 /* Alloc and init all Tx queues, including the command queue (#4) */
353 * including the command queue (#4) */
354 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) { 513 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
355 slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ? 514 slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ?
356 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS; 515 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
@@ -371,3 +530,864 @@ int iwl_txq_ctx_reset(struct iwl_priv *priv)
371 error_kw: 530 error_kw:
372 return ret; 531 return ret;
373} 532}
533/**
534 * iwl_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory
535 */
536void iwl_txq_ctx_stop(struct iwl_priv *priv)
537{
538
539 int txq_id;
540 unsigned long flags;
541
542
543 /* Turn off all Tx DMA fifos */
544 spin_lock_irqsave(&priv->lock, flags);
545 if (iwl_grab_nic_access(priv)) {
546 spin_unlock_irqrestore(&priv->lock, flags);
547 return;
548 }
549
550 priv->cfg->ops->lib->txq_set_sched(priv, 0);
551
552 /* Stop each Tx DMA channel, and wait for it to be idle */
553 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
554 iwl_write_direct32(priv,
555 FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0);
556 iwl_poll_direct_bit(priv, FH_TSSR_TX_STATUS_REG,
557 FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
558 (txq_id), 200);
559 }
560 iwl_release_nic_access(priv);
561 spin_unlock_irqrestore(&priv->lock, flags);
562
563 /* Deallocate memory for all Tx queues */
564 iwl_hw_txq_ctx_free(priv);
565}
566EXPORT_SYMBOL(iwl_txq_ctx_stop);
567
568/*
569 * handle build REPLY_TX command notification.
570 */
571static void iwl_tx_cmd_build_basic(struct iwl_priv *priv,
572 struct iwl_tx_cmd *tx_cmd,
573 struct ieee80211_tx_info *info,
574 struct ieee80211_hdr *hdr,
575 int is_unicast, u8 std_id)
576{
577 u16 fc = le16_to_cpu(hdr->frame_control);
578 __le32 tx_flags = tx_cmd->tx_flags;
579
580 tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
581 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
582 tx_flags |= TX_CMD_FLG_ACK_MSK;
583 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
584 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
585 if (ieee80211_is_probe_response(fc) &&
586 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
587 tx_flags |= TX_CMD_FLG_TSF_MSK;
588 } else {
589 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
590 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
591 }
592
593 if (ieee80211_is_back_request(fc))
594 tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
595
596
597 tx_cmd->sta_id = std_id;
598 if (ieee80211_get_morefrag(hdr))
599 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
600
601 if (ieee80211_is_qos_data(fc)) {
602 u8 *qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
603 tx_cmd->tid_tspec = qc[0] & 0xf;
604 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
605 } else {
606 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
607 }
608
609 if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) {
610 tx_flags |= TX_CMD_FLG_RTS_MSK;
611 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
612 } else if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
613 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
614 tx_flags |= TX_CMD_FLG_CTS_MSK;
615 }
616
617 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
618 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
619
620 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
621 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
622 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
623 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
624 tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
625 else
626 tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
627 } else {
628 tx_cmd->timeout.pm_frame_timeout = 0;
629 }
630
631 tx_cmd->driver_txop = 0;
632 tx_cmd->tx_flags = tx_flags;
633 tx_cmd->next_frame_len = 0;
634}
635
636#define RTS_HCCA_RETRY_LIMIT 3
637#define RTS_DFAULT_RETRY_LIMIT 60
638
639static void iwl_tx_cmd_build_rate(struct iwl_priv *priv,
640 struct iwl_tx_cmd *tx_cmd,
641 struct ieee80211_tx_info *info,
642 u16 fc, int sta_id,
643 int is_hcca)
644{
645 u8 rts_retry_limit = 0;
646 u8 data_retry_limit = 0;
647 u8 rate_plcp;
648 u16 rate_flags = 0;
649 int rate_idx;
650
651 rate_idx = min(ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xffff,
652 IWL_RATE_COUNT - 1);
653
654 rate_plcp = iwl_rates[rate_idx].plcp;
655
656 rts_retry_limit = (is_hcca) ?
657 RTS_HCCA_RETRY_LIMIT : RTS_DFAULT_RETRY_LIMIT;
658
659 if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
660 rate_flags |= RATE_MCS_CCK_MSK;
661
662
663 if (ieee80211_is_probe_response(fc)) {
664 data_retry_limit = 3;
665 if (data_retry_limit < rts_retry_limit)
666 rts_retry_limit = data_retry_limit;
667 } else
668 data_retry_limit = IWL_DEFAULT_TX_RETRY;
669
670 if (priv->data_retry_limit != -1)
671 data_retry_limit = priv->data_retry_limit;
672
673
674 if (ieee80211_is_data(fc)) {
675 tx_cmd->initial_rate_index = 0;
676 tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
677 } else {
678 switch (fc & IEEE80211_FCTL_STYPE) {
679 case IEEE80211_STYPE_AUTH:
680 case IEEE80211_STYPE_DEAUTH:
681 case IEEE80211_STYPE_ASSOC_REQ:
682 case IEEE80211_STYPE_REASSOC_REQ:
683 if (tx_cmd->tx_flags & TX_CMD_FLG_RTS_MSK) {
684 tx_cmd->tx_flags &= ~TX_CMD_FLG_RTS_MSK;
685 tx_cmd->tx_flags |= TX_CMD_FLG_CTS_MSK;
686 }
687 break;
688 default:
689 break;
690 }
691
692 /* Alternate between antenna A and B for successive frames */
693 if (priv->use_ant_b_for_management_frame) {
694 priv->use_ant_b_for_management_frame = 0;
695 rate_flags |= RATE_MCS_ANT_B_MSK;
696 } else {
697 priv->use_ant_b_for_management_frame = 1;
698 rate_flags |= RATE_MCS_ANT_A_MSK;
699 }
700 }
701
702 tx_cmd->rts_retry_limit = rts_retry_limit;
703 tx_cmd->data_retry_limit = data_retry_limit;
704 tx_cmd->rate_n_flags = iwl4965_hw_set_rate_n_flags(rate_plcp, rate_flags);
705}
706
707static void iwl_tx_cmd_build_hwcrypto(struct iwl_priv *priv,
708 struct ieee80211_tx_info *info,
709 struct iwl_tx_cmd *tx_cmd,
710 struct sk_buff *skb_frag,
711 int sta_id)
712{
713 struct ieee80211_key_conf *keyconf = info->control.hw_key;
714
715 switch (keyconf->alg) {
716 case ALG_CCMP:
717 tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
718 memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
719 if (info->flags & IEEE80211_TX_CTL_AMPDU)
720 tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
721 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
722 break;
723
724 case ALG_TKIP:
725 tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
726 ieee80211_get_tkip_key(keyconf, skb_frag,
727 IEEE80211_TKIP_P2_KEY, tx_cmd->key);
728 IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
729 break;
730
731 case ALG_WEP:
732 tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP |
733 (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
734
735 if (keyconf->keylen == WEP_KEY_LEN_128)
736 tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
737
738 memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
739
740 IWL_DEBUG_TX("Configuring packet for WEP encryption "
741 "with key %d\n", keyconf->keyidx);
742 break;
743
744 default:
745 printk(KERN_ERR "Unknown encode alg %d\n", keyconf->alg);
746 break;
747 }
748}
749
750static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len)
751{
752 /* 0 - mgmt, 1 - cnt, 2 - data */
753 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
754 priv->tx_stats[idx].cnt++;
755 priv->tx_stats[idx].bytes += len;
756}
757
758/*
759 * start REPLY_TX command process
760 */
761int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
762{
763 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
764 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
765 struct iwl_tfd_frame *tfd;
766 u32 *control_flags;
767 int txq_id = skb_get_queue_mapping(skb);
768 struct iwl_tx_queue *txq = NULL;
769 struct iwl_queue *q = NULL;
770 dma_addr_t phys_addr;
771 dma_addr_t txcmd_phys;
772 dma_addr_t scratch_phys;
773 struct iwl_cmd *out_cmd = NULL;
774 struct iwl_tx_cmd *tx_cmd;
775 u16 len, idx, len_org;
776 u16 seq_number = 0;
777 u8 id, hdr_len, unicast;
778 u8 sta_id;
779 u16 fc;
780 u8 wait_write_ptr = 0;
781 u8 tid = 0;
782 u8 *qc = NULL;
783 unsigned long flags;
784 int ret;
785
786 spin_lock_irqsave(&priv->lock, flags);
787 if (iwl_is_rfkill(priv)) {
788 IWL_DEBUG_DROP("Dropping - RF KILL\n");
789 goto drop_unlock;
790 }
791
792 if (!priv->vif) {
793 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
794 goto drop_unlock;
795 }
796
797 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) ==
798 IWL_INVALID_RATE) {
799 IWL_ERROR("ERROR: No TX rate available.\n");
800 goto drop_unlock;
801 }
802
803 unicast = !is_multicast_ether_addr(hdr->addr1);
804 id = 0;
805
806 fc = le16_to_cpu(hdr->frame_control);
807
808#ifdef CONFIG_IWLWIFI_DEBUG
809 if (ieee80211_is_auth(fc))
810 IWL_DEBUG_TX("Sending AUTH frame\n");
811 else if (ieee80211_is_assoc_request(fc))
812 IWL_DEBUG_TX("Sending ASSOC frame\n");
813 else if (ieee80211_is_reassoc_request(fc))
814 IWL_DEBUG_TX("Sending REASSOC frame\n");
815#endif
816
817 /* drop all data frame if we are not associated */
818 if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
819 (!iwl_is_associated(priv) ||
820 ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) ||
821 !priv->assoc_station_added)) {
822 IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
823 goto drop_unlock;
824 }
825
826 spin_unlock_irqrestore(&priv->lock, flags);
827
828 hdr_len = ieee80211_get_hdrlen(fc);
829
830 /* Find (or create) index into station table for destination station */
831 sta_id = iwl_get_sta_id(priv, hdr);
832 if (sta_id == IWL_INVALID_STATION) {
833 DECLARE_MAC_BUF(mac);
834
835 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
836 print_mac(mac, hdr->addr1));
837 goto drop;
838 }
839
840 IWL_DEBUG_TX("station Id %d\n", sta_id);
841
842 if (ieee80211_is_qos_data(fc)) {
843 qc = ieee80211_get_qos_ctrl(hdr, hdr_len);
844 tid = qc[0] & 0xf;
845 seq_number = priv->stations[sta_id].tid[tid].seq_number &
846 IEEE80211_SCTL_SEQ;
847 hdr->seq_ctrl = cpu_to_le16(seq_number) |
848 (hdr->seq_ctrl &
849 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
850 seq_number += 0x10;
851#ifdef CONFIG_IWL4965_HT
852 /* aggregation is on for this <sta,tid> */
853 if (info->flags & IEEE80211_TX_CTL_AMPDU)
854 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
855 priv->stations[sta_id].tid[tid].tfds_in_queue++;
856#endif /* CONFIG_IWL4965_HT */
857 }
858
859 /* Descriptor for chosen Tx queue */
860 txq = &priv->txq[txq_id];
861 q = &txq->q;
862
863 spin_lock_irqsave(&priv->lock, flags);
864
865 /* Set up first empty TFD within this queue's circular TFD buffer */
866 tfd = &txq->bd[q->write_ptr];
867 memset(tfd, 0, sizeof(*tfd));
868 control_flags = (u32 *) tfd;
869 idx = get_cmd_index(q, q->write_ptr, 0);
870
871 /* Set up driver data for this TFD */
872 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
873 txq->txb[q->write_ptr].skb[0] = skb;
874
875 /* Set up first empty entry in queue's array of Tx/cmd buffers */
876 out_cmd = &txq->cmd[idx];
877 tx_cmd = &out_cmd->cmd.tx;
878 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
879 memset(tx_cmd, 0, sizeof(struct iwl_tx_cmd));
880
881 /*
882 * Set up the Tx-command (not MAC!) header.
883 * Store the chosen Tx queue and TFD index within the sequence field;
884 * after Tx, uCode's Tx response will return this value so driver can
885 * locate the frame within the tx queue and do post-tx processing.
886 */
887 out_cmd->hdr.cmd = REPLY_TX;
888 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
889 INDEX_TO_SEQ(q->write_ptr)));
890
891 /* Copy MAC header from skb into command buffer */
892 memcpy(tx_cmd->hdr, hdr, hdr_len);
893
894 /*
895 * Use the first empty entry in this queue's command buffer array
896 * to contain the Tx command and MAC header concatenated together
897 * (payload data will be in another buffer).
898 * Size of this varies, due to varying MAC header length.
899 * If end is not dword aligned, we'll have 2 extra bytes at the end
900 * of the MAC header (device reads on dword boundaries).
901 * We'll tell device about this padding later.
902 */
903 len = sizeof(struct iwl_tx_cmd) +
904 sizeof(struct iwl_cmd_header) + hdr_len;
905
906 len_org = len;
907 len = (len + 3) & ~3;
908
909 if (len_org != len)
910 len_org = 1;
911 else
912 len_org = 0;
913
914 /* Physical address of this Tx command's header (not MAC header!),
915 * within command buffer array. */
916 txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx +
917 offsetof(struct iwl_cmd, hdr);
918
919 /* Add buffer containing Tx command and MAC(!) header to TFD's
920 * first entry */
921 iwl_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
922
923 if (!(info->flags & IEEE80211_TX_CTL_DO_NOT_ENCRYPT))
924 iwl_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb, sta_id);
925
926 /* Set up TFD's 2nd entry to point directly to remainder of skb,
927 * if any (802.11 null frames have no payload). */
928 len = skb->len - hdr_len;
929 if (len) {
930 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
931 len, PCI_DMA_TODEVICE);
932 iwl_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
933 }
934
935 /* Tell NIC about any 2-byte padding after MAC header */
936 if (len_org)
937 tx_cmd->tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
938
939 /* Total # bytes to be transmitted */
940 len = (u16)skb->len;
941 tx_cmd->len = cpu_to_le16(len);
942 /* TODO need this for burst mode later on */
943 iwl_tx_cmd_build_basic(priv, tx_cmd, info, hdr, unicast, sta_id);
944
945 /* set is_hcca to 0; it probably will never be implemented */
946 iwl_tx_cmd_build_rate(priv, tx_cmd, info, fc, sta_id, 0);
947
948 iwl_update_tx_stats(priv, fc, len);
949
950 scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) +
951 offsetof(struct iwl_tx_cmd, scratch);
952 tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys);
953 tx_cmd->dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys);
954
955 if (!ieee80211_get_morefrag(hdr)) {
956 txq->need_update = 1;
957 if (qc)
958 priv->stations[sta_id].tid[tid].seq_number = seq_number;
959 } else {
960 wait_write_ptr = 1;
961 txq->need_update = 0;
962 }
963
964 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd, sizeof(*tx_cmd));
965
966 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd->hdr, hdr_len);
967
968 /* Set up entry for this TFD in Tx byte-count array */
969 priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, len);
970
971 /* Tell device the write index *just past* this latest filled TFD */
972 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
973 ret = iwl_txq_update_write_ptr(priv, txq);
974 spin_unlock_irqrestore(&priv->lock, flags);
975
976 if (ret)
977 return ret;
978
979 if ((iwl_queue_space(q) < q->high_mark)
980 && priv->mac80211_registered) {
981 if (wait_write_ptr) {
982 spin_lock_irqsave(&priv->lock, flags);
983 txq->need_update = 1;
984 iwl_txq_update_write_ptr(priv, txq);
985 spin_unlock_irqrestore(&priv->lock, flags);
986 }
987
988 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
989 }
990
991 return 0;
992
993drop_unlock:
994 spin_unlock_irqrestore(&priv->lock, flags);
995drop:
996 return -1;
997}
998EXPORT_SYMBOL(iwl_tx_skb);
999
1000/*************** HOST COMMAND QUEUE FUNCTIONS *****/
1001
1002/**
1003 * iwl_enqueue_hcmd - enqueue a uCode command
1004 * @priv: device private data point
1005 * @cmd: a point to the ucode command structure
1006 *
1007 * The function returns < 0 values to indicate the operation is
1008 * failed. On success, it turns the index (> 0) of command in the
1009 * command queue.
1010 */
1011int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
1012{
1013 struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
1014 struct iwl_queue *q = &txq->q;
1015 struct iwl_tfd_frame *tfd;
1016 u32 *control_flags;
1017 struct iwl_cmd *out_cmd;
1018 u32 idx;
1019 u16 fix_size;
1020 dma_addr_t phys_addr;
1021 int ret;
1022 unsigned long flags;
1023
1024 cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len);
1025 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
1026
1027 /* If any of the command structures end up being larger than
1028 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
1029 * we will need to increase the size of the TFD entries */
1030 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
1031 !(cmd->meta.flags & CMD_SIZE_HUGE));
1032
1033 if (iwl_is_rfkill(priv)) {
1034 IWL_DEBUG_INFO("Not sending command - RF KILL");
1035 return -EIO;
1036 }
1037
1038 if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
1039 IWL_ERROR("No space for Tx\n");
1040 return -ENOSPC;
1041 }
1042
1043 spin_lock_irqsave(&priv->hcmd_lock, flags);
1044
1045 tfd = &txq->bd[q->write_ptr];
1046 memset(tfd, 0, sizeof(*tfd));
1047
1048 control_flags = (u32 *) tfd;
1049
1050 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
1051 out_cmd = &txq->cmd[idx];
1052
1053 out_cmd->hdr.cmd = cmd->id;
1054 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
1055 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
1056
1057 /* At this point, the out_cmd now has all of the incoming cmd
1058 * information */
1059
1060 out_cmd->hdr.flags = 0;
1061 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
1062 INDEX_TO_SEQ(q->write_ptr));
1063 if (out_cmd->meta.flags & CMD_SIZE_HUGE)
1064 out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
1065
1066 phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
1067 offsetof(struct iwl_cmd, hdr);
1068 iwl_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
1069
1070 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
1071 "%d bytes at %d[%d]:%d\n",
1072 get_cmd_string(out_cmd->hdr.cmd),
1073 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
1074 fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
1075
1076 txq->need_update = 1;
1077
1078 /* Set up entry in queue's byte count circular buffer */
1079 priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, 0);
1080
1081 /* Increment and update queue's write index */
1082 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
1083 ret = iwl_txq_update_write_ptr(priv, txq);
1084
1085 spin_unlock_irqrestore(&priv->hcmd_lock, flags);
1086 return ret ? ret : idx;
1087}
1088
1089int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
1090{
1091 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1092 struct iwl_queue *q = &txq->q;
1093 struct iwl_tx_info *tx_info;
1094 int nfreed = 0;
1095
1096 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
1097 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
1098 "is out of range [0-%d] %d %d.\n", txq_id,
1099 index, q->n_bd, q->write_ptr, q->read_ptr);
1100 return 0;
1101 }
1102
1103 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1104 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1105
1106 tx_info = &txq->txb[txq->q.read_ptr];
1107 ieee80211_tx_status_irqsafe(priv->hw, tx_info->skb[0]);
1108 tx_info->skb[0] = NULL;
1109
1110 if (priv->cfg->ops->lib->txq_inval_byte_cnt_tbl)
1111 priv->cfg->ops->lib->txq_inval_byte_cnt_tbl(priv, txq);
1112
1113 iwl_hw_txq_free_tfd(priv, txq);
1114 nfreed++;
1115 }
1116 return nfreed;
1117}
1118EXPORT_SYMBOL(iwl_tx_queue_reclaim);
1119
1120
1121/**
1122 * iwl_hcmd_queue_reclaim - Reclaim TX command queue entries already Tx'd
1123 *
1124 * When FW advances 'R' index, all entries between old and new 'R' index
1125 * need to be reclaimed. As result, some free space forms. If there is
1126 * enough free space (> low mark), wake the stack that feeds us.
1127 */
1128static void iwl_hcmd_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
1129{
1130 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1131 struct iwl_queue *q = &txq->q;
1132 int nfreed = 0;
1133
1134 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
1135 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
1136 "is out of range [0-%d] %d %d.\n", txq_id,
1137 index, q->n_bd, q->write_ptr, q->read_ptr);
1138 return;
1139 }
1140
1141 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1142 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1143
1144 if (nfreed > 1) {
1145 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
1146 q->write_ptr, q->read_ptr);
1147 queue_work(priv->workqueue, &priv->restart);
1148 }
1149 nfreed++;
1150 }
1151}
1152
1153/**
1154 * iwl_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
1155 * @rxb: Rx buffer to reclaim
1156 *
1157 * If an Rx buffer has an async callback associated with it the callback
1158 * will be executed. The attached skb (if present) will only be freed
1159 * if the callback returns 1
1160 */
1161void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1162{
1163 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1164 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1165 int txq_id = SEQ_TO_QUEUE(sequence);
1166 int index = SEQ_TO_INDEX(sequence);
1167 int huge = sequence & SEQ_HUGE_FRAME;
1168 int cmd_index;
1169 struct iwl_cmd *cmd;
1170
1171 /* If a Tx command is being handled and it isn't in the actual
1172 * command queue then there a command routing bug has been introduced
1173 * in the queue management code. */
1174 if (txq_id != IWL_CMD_QUEUE_NUM)
1175 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
1176 txq_id, pkt->hdr.cmd);
1177 BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
1178
1179 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1180 cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
1181
1182 /* Input error checking is done when commands are added to queue. */
1183 if (cmd->meta.flags & CMD_WANT_SKB) {
1184 cmd->meta.source->u.skb = rxb->skb;
1185 rxb->skb = NULL;
1186 } else if (cmd->meta.u.callback &&
1187 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1188 rxb->skb = NULL;
1189
1190 iwl_hcmd_queue_reclaim(priv, txq_id, index);
1191
1192 if (!(cmd->meta.flags & CMD_ASYNC)) {
1193 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1194 wake_up_interruptible(&priv->wait_command_queue);
1195 }
1196}
1197EXPORT_SYMBOL(iwl_tx_cmd_complete);
1198
1199
1200#ifdef CONFIG_IWL4965_HT
1201/*
1202 * Find first available (lowest unused) Tx Queue, mark it "active".
1203 * Called only when finding queue for aggregation.
1204 * Should never return anything < 7, because they should already
1205 * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
1206 */
1207static int iwl_txq_ctx_activate_free(struct iwl_priv *priv)
1208{
1209 int txq_id;
1210
1211 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
1212 if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
1213 return txq_id;
1214 return -1;
1215}
1216
1217int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
1218{
1219 int sta_id;
1220 int tx_fifo;
1221 int txq_id;
1222 int ret;
1223 unsigned long flags;
1224 struct iwl_tid_data *tid_data;
1225 DECLARE_MAC_BUF(mac);
1226
1227 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
1228 tx_fifo = default_tid_to_tx_fifo[tid];
1229 else
1230 return -EINVAL;
1231
1232 IWL_WARNING("%s on ra = %s tid = %d\n",
1233 __func__, print_mac(mac, ra), tid);
1234
1235 sta_id = iwl_find_station(priv, ra);
1236 if (sta_id == IWL_INVALID_STATION)
1237 return -ENXIO;
1238
1239 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
1240 IWL_ERROR("Start AGG when state is not IWL_AGG_OFF !\n");
1241 return -ENXIO;
1242 }
1243
1244 txq_id = iwl_txq_ctx_activate_free(priv);
1245 if (txq_id == -1)
1246 return -ENXIO;
1247
1248 spin_lock_irqsave(&priv->sta_lock, flags);
1249 tid_data = &priv->stations[sta_id].tid[tid];
1250 *ssn = SEQ_TO_SN(tid_data->seq_number);
1251 tid_data->agg.txq_id = txq_id;
1252 spin_unlock_irqrestore(&priv->sta_lock, flags);
1253
1254 ret = priv->cfg->ops->lib->txq_agg_enable(priv, txq_id, tx_fifo,
1255 sta_id, tid, *ssn);
1256 if (ret)
1257 return ret;
1258
1259 if (tid_data->tfds_in_queue == 0) {
1260 printk(KERN_ERR "HW queue is empty\n");
1261 tid_data->agg.state = IWL_AGG_ON;
1262 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, ra, tid);
1263 } else {
1264 IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n",
1265 tid_data->tfds_in_queue);
1266 tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
1267 }
1268 return ret;
1269}
1270EXPORT_SYMBOL(iwl_tx_agg_start);
1271
1272int iwl_tx_agg_stop(struct iwl_priv *priv , const u8 *ra, u16 tid)
1273{
1274 int tx_fifo_id, txq_id, sta_id, ssn = -1;
1275 struct iwl_tid_data *tid_data;
1276 int ret, write_ptr, read_ptr;
1277 unsigned long flags;
1278 DECLARE_MAC_BUF(mac);
1279
1280 if (!ra) {
1281 IWL_ERROR("ra = NULL\n");
1282 return -EINVAL;
1283 }
1284
1285 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
1286 tx_fifo_id = default_tid_to_tx_fifo[tid];
1287 else
1288 return -EINVAL;
1289
1290 sta_id = iwl_find_station(priv, ra);
1291
1292 if (sta_id == IWL_INVALID_STATION)
1293 return -ENXIO;
1294
1295 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
1296 IWL_WARNING("Stopping AGG while state not IWL_AGG_ON\n");
1297
1298 tid_data = &priv->stations[sta_id].tid[tid];
1299 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
1300 txq_id = tid_data->agg.txq_id;
1301 write_ptr = priv->txq[txq_id].q.write_ptr;
1302 read_ptr = priv->txq[txq_id].q.read_ptr;
1303
1304 /* The queue is not empty */
1305 if (write_ptr != read_ptr) {
1306 IWL_DEBUG_HT("Stopping a non empty AGG HW QUEUE\n");
1307 priv->stations[sta_id].tid[tid].agg.state =
1308 IWL_EMPTYING_HW_QUEUE_DELBA;
1309 return 0;
1310 }
1311
1312 IWL_DEBUG_HT("HW queue is empty\n");
1313 priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
1314
1315 spin_lock_irqsave(&priv->lock, flags);
1316 ret = priv->cfg->ops->lib->txq_agg_disable(priv, txq_id, ssn,
1317 tx_fifo_id);
1318 spin_unlock_irqrestore(&priv->lock, flags);
1319
1320 if (ret)
1321 return ret;
1322
1323 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, ra, tid);
1324
1325 return 0;
1326}
1327EXPORT_SYMBOL(iwl_tx_agg_stop);
1328
1329int iwl_txq_check_empty(struct iwl_priv *priv, int sta_id, u8 tid, int txq_id)
1330{
1331 struct iwl_queue *q = &priv->txq[txq_id].q;
1332 u8 *addr = priv->stations[sta_id].sta.sta.addr;
1333 struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
1334
1335 switch (priv->stations[sta_id].tid[tid].agg.state) {
1336 case IWL_EMPTYING_HW_QUEUE_DELBA:
1337 /* We are reclaiming the last packet of the */
1338 /* aggregated HW queue */
1339 if (txq_id == tid_data->agg.txq_id &&
1340 q->read_ptr == q->write_ptr) {
1341 u16 ssn = SEQ_TO_SN(tid_data->seq_number);
1342 int tx_fifo = default_tid_to_tx_fifo[tid];
1343 IWL_DEBUG_HT("HW queue empty: continue DELBA flow\n");
1344 priv->cfg->ops->lib->txq_agg_disable(priv, txq_id,
1345 ssn, tx_fifo);
1346 tid_data->agg.state = IWL_AGG_OFF;
1347 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, addr, tid);
1348 }
1349 break;
1350 case IWL_EMPTYING_HW_QUEUE_ADDBA:
1351 /* We are reclaiming the last packet of the queue */
1352 if (tid_data->tfds_in_queue == 0) {
1353 IWL_DEBUG_HT("HW queue empty: continue ADDBA flow\n");
1354 tid_data->agg.state = IWL_AGG_ON;
1355 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, addr, tid);
1356 }
1357 break;
1358 }
1359 return 0;
1360}
1361EXPORT_SYMBOL(iwl_txq_check_empty);
1362#endif /* CONFIG_IWL4965_HT */
1363
1364#ifdef CONFIG_IWLWIF_DEBUG
1365#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1366
1367const char *iwl_get_tx_fail_reason(u32 status)
1368{
1369 switch (status & TX_STATUS_MSK) {
1370 case TX_STATUS_SUCCESS:
1371 return "SUCCESS";
1372 TX_STATUS_ENTRY(SHORT_LIMIT);
1373 TX_STATUS_ENTRY(LONG_LIMIT);
1374 TX_STATUS_ENTRY(FIFO_UNDERRUN);
1375 TX_STATUS_ENTRY(MGMNT_ABORT);
1376 TX_STATUS_ENTRY(NEXT_FRAG);
1377 TX_STATUS_ENTRY(LIFE_EXPIRE);
1378 TX_STATUS_ENTRY(DEST_PS);
1379 TX_STATUS_ENTRY(ABORTED);
1380 TX_STATUS_ENTRY(BT_RETRY);
1381 TX_STATUS_ENTRY(STA_INVALID);
1382 TX_STATUS_ENTRY(FRAG_DROPPED);
1383 TX_STATUS_ENTRY(TID_DISABLE);
1384 TX_STATUS_ENTRY(FRAME_FLUSHED);
1385 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
1386 TX_STATUS_ENTRY(TX_LOCKED);
1387 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
1388 }
1389
1390 return "UNKNOWN";
1391}
1392EXPORT_SYMBOL(iwl_get_tx_fail_reason);
1393#endif /* CONFIG_IWLWIFI_DEBUG */
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index c1234ff4fc98..72279e07fe32 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -102,16 +102,6 @@ MODULE_VERSION(DRV_VERSION);
102MODULE_AUTHOR(DRV_COPYRIGHT); 102MODULE_AUTHOR(DRV_COPYRIGHT);
103MODULE_LICENSE("GPL"); 103MODULE_LICENSE("GPL");
104 104
105static __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
106{
107 u16 fc = le16_to_cpu(hdr->frame_control);
108 int hdr_len = ieee80211_get_hdrlen(fc);
109
110 if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
111 return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
112 return NULL;
113}
114
115static const struct ieee80211_supported_band *iwl3945_get_band( 105static const struct ieee80211_supported_band *iwl3945_get_band(
116 struct iwl3945_priv *priv, enum ieee80211_band band) 106 struct iwl3945_priv *priv, enum ieee80211_band band)
117{ 107{
@@ -2386,13 +2376,13 @@ static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode)
2386} 2376}
2387 2377
2388static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv, 2378static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2389 struct ieee80211_tx_control *ctl, 2379 struct ieee80211_tx_info *info,
2390 struct iwl3945_cmd *cmd, 2380 struct iwl3945_cmd *cmd,
2391 struct sk_buff *skb_frag, 2381 struct sk_buff *skb_frag,
2392 int last_frag) 2382 int last_frag)
2393{ 2383{
2394 struct iwl3945_hw_key *keyinfo = 2384 struct iwl3945_hw_key *keyinfo =
2395 &priv->stations[ctl->hw_key->hw_key_idx].keyinfo; 2385 &priv->stations[info->control.hw_key->hw_key_idx].keyinfo;
2396 2386
2397 switch (keyinfo->alg) { 2387 switch (keyinfo->alg) {
2398 case ALG_CCMP: 2388 case ALG_CCMP:
@@ -2415,7 +2405,7 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2415 2405
2416 case ALG_WEP: 2406 case ALG_WEP:
2417 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | 2407 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2418 (ctl->hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; 2408 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2419 2409
2420 if (keyinfo->keylen == 13) 2410 if (keyinfo->keylen == 13)
2421 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; 2411 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
@@ -2423,7 +2413,7 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2423 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); 2413 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2424 2414
2425 IWL_DEBUG_TX("Configuring packet for WEP encryption " 2415 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2426 "with key %d\n", ctl->hw_key->hw_key_idx); 2416 "with key %d\n", info->control.hw_key->hw_key_idx);
2427 break; 2417 break;
2428 2418
2429 default: 2419 default:
@@ -2437,16 +2427,15 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2437 */ 2427 */
2438static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv, 2428static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv,
2439 struct iwl3945_cmd *cmd, 2429 struct iwl3945_cmd *cmd,
2440 struct ieee80211_tx_control *ctrl, 2430 struct ieee80211_tx_info *info,
2441 struct ieee80211_hdr *hdr, 2431 struct ieee80211_hdr *hdr,
2442 int is_unicast, u8 std_id) 2432 int is_unicast, u8 std_id)
2443{ 2433{
2444 __le16 *qc;
2445 u16 fc = le16_to_cpu(hdr->frame_control); 2434 u16 fc = le16_to_cpu(hdr->frame_control);
2446 __le32 tx_flags = cmd->cmd.tx.tx_flags; 2435 __le32 tx_flags = cmd->cmd.tx.tx_flags;
2447 2436
2448 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; 2437 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2449 if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { 2438 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
2450 tx_flags |= TX_CMD_FLG_ACK_MSK; 2439 tx_flags |= TX_CMD_FLG_ACK_MSK;
2451 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) 2440 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
2452 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; 2441 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
@@ -2462,17 +2451,18 @@ static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv,
2462 if (ieee80211_get_morefrag(hdr)) 2451 if (ieee80211_get_morefrag(hdr))
2463 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; 2452 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2464 2453
2465 qc = ieee80211_get_qos_ctrl(hdr); 2454 if (ieee80211_is_qos_data(fc)) {
2466 if (qc) { 2455 u8 *qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
2467 cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); 2456 cmd->cmd.tx.tid_tspec = qc[0] & 0xf;
2468 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; 2457 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2469 } else 2458 } else {
2470 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; 2459 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2460 }
2471 2461
2472 if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { 2462 if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) {
2473 tx_flags |= TX_CMD_FLG_RTS_MSK; 2463 tx_flags |= TX_CMD_FLG_RTS_MSK;
2474 tx_flags &= ~TX_CMD_FLG_CTS_MSK; 2464 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2475 } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { 2465 } else if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
2476 tx_flags &= ~TX_CMD_FLG_RTS_MSK; 2466 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2477 tx_flags |= TX_CMD_FLG_CTS_MSK; 2467 tx_flags |= TX_CMD_FLG_CTS_MSK;
2478 } 2468 }
@@ -2556,25 +2546,27 @@ static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *h
2556/* 2546/*
2557 * start REPLY_TX command process 2547 * start REPLY_TX command process
2558 */ 2548 */
2559static int iwl3945_tx_skb(struct iwl3945_priv *priv, 2549static int iwl3945_tx_skb(struct iwl3945_priv *priv, struct sk_buff *skb)
2560 struct sk_buff *skb, struct ieee80211_tx_control *ctl)
2561{ 2550{
2562 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 2551 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2552 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2563 struct iwl3945_tfd_frame *tfd; 2553 struct iwl3945_tfd_frame *tfd;
2564 u32 *control_flags; 2554 u32 *control_flags;
2565 int txq_id = ctl->queue; 2555 int txq_id = skb_get_queue_mapping(skb);
2566 struct iwl3945_tx_queue *txq = NULL; 2556 struct iwl3945_tx_queue *txq = NULL;
2567 struct iwl3945_queue *q = NULL; 2557 struct iwl3945_queue *q = NULL;
2568 dma_addr_t phys_addr; 2558 dma_addr_t phys_addr;
2569 dma_addr_t txcmd_phys; 2559 dma_addr_t txcmd_phys;
2570 struct iwl3945_cmd *out_cmd = NULL; 2560 struct iwl3945_cmd *out_cmd = NULL;
2571 u16 len, idx, len_org; 2561 u16 len, idx, len_org, hdr_len;
2572 u8 id, hdr_len, unicast; 2562 u8 id;
2563 u8 unicast;
2573 u8 sta_id; 2564 u8 sta_id;
2565 u8 tid = 0;
2574 u16 seq_number = 0; 2566 u16 seq_number = 0;
2575 u16 fc; 2567 u16 fc;
2576 __le16 *qc;
2577 u8 wait_write_ptr = 0; 2568 u8 wait_write_ptr = 0;
2569 u8 *qc = NULL;
2578 unsigned long flags; 2570 unsigned long flags;
2579 int rc; 2571 int rc;
2580 2572
@@ -2589,7 +2581,7 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2589 goto drop_unlock; 2581 goto drop_unlock;
2590 } 2582 }
2591 2583
2592 if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) { 2584 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
2593 IWL_ERROR("ERROR: No TX rate available.\n"); 2585 IWL_ERROR("ERROR: No TX rate available.\n");
2594 goto drop_unlock; 2586 goto drop_unlock;
2595 } 2587 }
@@ -2632,9 +2624,9 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2632 2624
2633 IWL_DEBUG_RATE("station Id %d\n", sta_id); 2625 IWL_DEBUG_RATE("station Id %d\n", sta_id);
2634 2626
2635 qc = ieee80211_get_qos_ctrl(hdr); 2627 if (ieee80211_is_qos_data(fc)) {
2636 if (qc) { 2628 qc = ieee80211_get_qos_ctrl(hdr, hdr_len);
2637 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); 2629 tid = qc[0] & 0xf;
2638 seq_number = priv->stations[sta_id].tid[tid].seq_number & 2630 seq_number = priv->stations[sta_id].tid[tid].seq_number &
2639 IEEE80211_SCTL_SEQ; 2631 IEEE80211_SCTL_SEQ;
2640 hdr->seq_ctrl = cpu_to_le16(seq_number) | 2632 hdr->seq_ctrl = cpu_to_le16(seq_number) |
@@ -2658,8 +2650,6 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2658 /* Set up driver data for this TFD */ 2650 /* Set up driver data for this TFD */
2659 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info)); 2651 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info));
2660 txq->txb[q->write_ptr].skb[0] = skb; 2652 txq->txb[q->write_ptr].skb[0] = skb;
2661 memcpy(&(txq->txb[q->write_ptr].status.control),
2662 ctl, sizeof(struct ieee80211_tx_control));
2663 2653
2664 /* Init first empty entry in queue's array of Tx/cmd buffers */ 2654 /* Init first empty entry in queue's array of Tx/cmd buffers */
2665 out_cmd = &txq->cmd[idx]; 2655 out_cmd = &txq->cmd[idx];
@@ -2708,8 +2698,8 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2708 * first entry */ 2698 * first entry */
2709 iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); 2699 iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
2710 2700
2711 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) 2701 if (!(info->flags & IEEE80211_TX_CTL_DO_NOT_ENCRYPT))
2712 iwl3945_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); 2702 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
2713 2703
2714 /* Set up TFD's 2nd entry to point directly to remainder of skb, 2704 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2715 * if any (802.11 null frames have no payload). */ 2705 * if any (802.11 null frames have no payload). */
@@ -2734,10 +2724,10 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2734 out_cmd->cmd.tx.len = cpu_to_le16(len); 2724 out_cmd->cmd.tx.len = cpu_to_le16(len);
2735 2725
2736 /* TODO need this for burst mode later on */ 2726 /* TODO need this for burst mode later on */
2737 iwl3945_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id); 2727 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, unicast, sta_id);
2738 2728
2739 /* set is_hcca to 0; it probably will never be implemented */ 2729 /* set is_hcca to 0; it probably will never be implemented */
2740 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0); 2730 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
2741 2731
2742 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK; 2732 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
2743 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK; 2733 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
@@ -2745,7 +2735,6 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2745 if (!ieee80211_get_morefrag(hdr)) { 2735 if (!ieee80211_get_morefrag(hdr)) {
2746 txq->need_update = 1; 2736 txq->need_update = 1;
2747 if (qc) { 2737 if (qc) {
2748 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2749 priv->stations[sta_id].tid[tid].seq_number = seq_number; 2738 priv->stations[sta_id].tid[tid].seq_number = seq_number;
2750 } 2739 }
2751 } else { 2740 } else {
@@ -2776,7 +2765,7 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2776 spin_unlock_irqrestore(&priv->lock, flags); 2765 spin_unlock_irqrestore(&priv->lock, flags);
2777 } 2766 }
2778 2767
2779 ieee80211_stop_queue(priv->hw, ctl->queue); 2768 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
2780 } 2769 }
2781 2770
2782 return 0; 2771 return 0;
@@ -3239,7 +3228,7 @@ static void iwl3945_bg_beacon_update(struct work_struct *work)
3239 struct sk_buff *beacon; 3228 struct sk_buff *beacon;
3240 3229
3241 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ 3230 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3242 beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); 3231 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
3243 3232
3244 if (!beacon) { 3233 if (!beacon) {
3245 IWL_ERROR("update beacon failed\n"); 3234 IWL_ERROR("update beacon failed\n");
@@ -5832,7 +5821,7 @@ static void iwl3945_alive_start(struct iwl3945_priv *priv)
5832 if (iwl3945_is_rfkill(priv)) 5821 if (iwl3945_is_rfkill(priv))
5833 return; 5822 return;
5834 5823
5835 ieee80211_start_queues(priv->hw); 5824 ieee80211_wake_queues(priv->hw);
5836 5825
5837 priv->active_rate = priv->rates_mask; 5826 priv->active_rate = priv->rates_mask;
5838 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; 5827 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
@@ -5858,9 +5847,6 @@ static void iwl3945_alive_start(struct iwl3945_priv *priv)
5858 /* Configure the adapter for unassociated operation */ 5847 /* Configure the adapter for unassociated operation */
5859 iwl3945_commit_rxon(priv); 5848 iwl3945_commit_rxon(priv);
5860 5849
5861 /* At this point, the NIC is initialized and operational */
5862 priv->notif_missed_beacons = 0;
5863
5864 iwl3945_reg_txpower_periodic(priv); 5850 iwl3945_reg_txpower_periodic(priv);
5865 5851
5866 iwl3945_led_register(priv); 5852 iwl3945_led_register(priv);
@@ -6690,8 +6676,7 @@ static void iwl3945_mac_stop(struct ieee80211_hw *hw)
6690 IWL_DEBUG_MAC80211("leave\n"); 6676 IWL_DEBUG_MAC80211("leave\n");
6691} 6677}
6692 6678
6693static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, 6679static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
6694 struct ieee80211_tx_control *ctl)
6695{ 6680{
6696 struct iwl3945_priv *priv = hw->priv; 6681 struct iwl3945_priv *priv = hw->priv;
6697 6682
@@ -6703,9 +6688,9 @@ static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
6703 } 6688 }
6704 6689
6705 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, 6690 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
6706 ctl->tx_rate->bitrate); 6691 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
6707 6692
6708 if (iwl3945_tx_skb(priv, skb, ctl)) 6693 if (iwl3945_tx_skb(priv, skb))
6709 dev_kfree_skb_any(skb); 6694 dev_kfree_skb_any(skb);
6710 6695
6711 IWL_DEBUG_MAC80211("leave\n"); 6696 IWL_DEBUG_MAC80211("leave\n");
@@ -7342,8 +7327,7 @@ static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
7342 7327
7343} 7328}
7344 7329
7345static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, 7330static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
7346 struct ieee80211_tx_control *control)
7347{ 7331{
7348 struct iwl3945_priv *priv = hw->priv; 7332 struct iwl3945_priv *priv = hw->priv;
7349 unsigned long flags; 7333 unsigned long flags;
@@ -8273,7 +8257,7 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
8273 8257
8274 iwl3945_free_channel_map(priv); 8258 iwl3945_free_channel_map(priv);
8275 iwl3945_free_geos(priv); 8259 iwl3945_free_geos(priv);
8276 8260 kfree(priv->scan);
8277 if (priv->ibss_beacon) 8261 if (priv->ibss_beacon)
8278 dev_kfree_skb(priv->ibss_beacon); 8262 dev_kfree_skb(priv->ibss_beacon);
8279 8263
diff --git a/drivers/net/wireless/iwlwifi/iwl4965-base.c b/drivers/net/wireless/iwlwifi/iwl4965-base.c
index 55ca752ae9e6..c71daec8c746 100644
--- a/drivers/net/wireless/iwlwifi/iwl4965-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl4965-base.c
@@ -53,8 +53,6 @@
53#include "iwl-sta.h" 53#include "iwl-sta.h"
54#include "iwl-calib.h" 54#include "iwl-calib.h"
55 55
56static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
57 struct iwl_tx_queue *txq);
58 56
59/****************************************************************************** 57/******************************************************************************
60 * 58 *
@@ -89,22 +87,6 @@ MODULE_VERSION(DRV_VERSION);
89MODULE_AUTHOR(DRV_COPYRIGHT); 87MODULE_AUTHOR(DRV_COPYRIGHT);
90MODULE_LICENSE("GPL"); 88MODULE_LICENSE("GPL");
91 89
92__le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
93{
94 u16 fc = le16_to_cpu(hdr->frame_control);
95 int hdr_len = ieee80211_get_hdrlen(fc);
96
97 if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
98 return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
99 return NULL;
100}
101
102static const struct ieee80211_supported_band *iwl_get_hw_mode(
103 struct iwl_priv *priv, enum ieee80211_band band)
104{
105 return priv->hw->wiphy->bands[band];
106}
107
108static int iwl4965_is_empty_essid(const char *essid, int essid_len) 90static int iwl4965_is_empty_essid(const char *essid, int essid_len)
109{ 91{
110 /* Single white space is for Linksys APs */ 92 /* Single white space is for Linksys APs */
@@ -145,70 +127,6 @@ static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
145 return escaped; 127 return escaped;
146} 128}
147 129
148
149/*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
150 * DMA services
151 *
152 * Theory of operation
153 *
154 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
155 * of buffer descriptors, each of which points to one or more data buffers for
156 * the device to read from or fill. Driver and device exchange status of each
157 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
158 * entries in each circular buffer, to protect against confusing empty and full
159 * queue states.
160 *
161 * The device reads or writes the data in the queues via the device's several
162 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
163 *
164 * For Tx queue, there are low mark and high mark limits. If, after queuing
165 * the packet for Tx, free space become < low mark, Tx queue stopped. When
166 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
167 * Tx queue resumed.
168 *
169 * The 4965 operates with up to 17 queues: One receive queue, one transmit
170 * queue (#4) for sending commands to the device firmware, and 15 other
171 * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
172 *
173 * See more detailed info in iwl-4965-hw.h.
174 ***************************************************/
175
176int iwl4965_queue_space(const struct iwl4965_queue *q)
177{
178 int s = q->read_ptr - q->write_ptr;
179
180 if (q->read_ptr > q->write_ptr)
181 s -= q->n_bd;
182
183 if (s <= 0)
184 s += q->n_window;
185 /* keep some reserve to not confuse empty and full situations */
186 s -= 2;
187 if (s < 0)
188 s = 0;
189 return s;
190}
191
192
193static inline int x2_queue_used(const struct iwl4965_queue *q, int i)
194{
195 return q->write_ptr > q->read_ptr ?
196 (i >= q->read_ptr && i < q->write_ptr) :
197 !(i < q->read_ptr && i >= q->write_ptr);
198}
199
200static inline u8 get_cmd_index(struct iwl4965_queue *q, u32 index, int is_huge)
201{
202 /* This is for scan command, the big buffer at end of command array */
203 if (is_huge)
204 return q->n_window; /* must be power of 2 */
205
206 /* Otherwise, use normal size buffers */
207 return index & (q->n_window - 1);
208}
209
210const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
211
212/*************** STATION TABLE MANAGEMENT **** 130/*************** STATION TABLE MANAGEMENT ****
213 * mac80211 should be examined to determine if sta_info is duplicating 131 * mac80211 should be examined to determine if sta_info is duplicating
214 * the functionality provided here 132 * the functionality provided here
@@ -216,213 +134,11 @@ const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
216 134
217/**************************************************************/ 135/**************************************************************/
218 136
219#if 0 /* temporary disable till we add real remove station */
220/**
221 * iwl4965_remove_station - Remove driver's knowledge of station.
222 *
223 * NOTE: This does not remove station from device's station table.
224 */
225static u8 iwl4965_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
226{
227 int index = IWL_INVALID_STATION;
228 int i;
229 unsigned long flags;
230
231 spin_lock_irqsave(&priv->sta_lock, flags);
232 137
233 if (is_ap)
234 index = IWL_AP_ID;
235 else if (is_broadcast_ether_addr(addr))
236 index = priv->hw_params.bcast_sta_id;
237 else
238 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
239 if (priv->stations[i].used &&
240 !compare_ether_addr(priv->stations[i].sta.sta.addr,
241 addr)) {
242 index = i;
243 break;
244 }
245
246 if (unlikely(index == IWL_INVALID_STATION))
247 goto out;
248
249 if (priv->stations[index].used) {
250 priv->stations[index].used = 0;
251 priv->num_stations--;
252 }
253
254 BUG_ON(priv->num_stations < 0);
255
256out:
257 spin_unlock_irqrestore(&priv->sta_lock, flags);
258 return 0;
259}
260#endif
261
262/**
263 * iwl4965_add_station_flags - Add station to tables in driver and device
264 */
265u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr,
266 int is_ap, u8 flags, void *ht_data)
267{
268 int i;
269 int index = IWL_INVALID_STATION;
270 struct iwl_station_entry *station;
271 unsigned long flags_spin;
272 DECLARE_MAC_BUF(mac);
273
274 spin_lock_irqsave(&priv->sta_lock, flags_spin);
275 if (is_ap)
276 index = IWL_AP_ID;
277 else if (is_broadcast_ether_addr(addr))
278 index = priv->hw_params.bcast_sta_id;
279 else
280 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
281 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
282 addr)) {
283 index = i;
284 break;
285 }
286
287 if (!priv->stations[i].used &&
288 index == IWL_INVALID_STATION)
289 index = i;
290 }
291
292
293 /* These two conditions have the same outcome, but keep them separate
294 since they have different meanings */
295 if (unlikely(index == IWL_INVALID_STATION)) {
296 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
297 return index;
298 }
299
300 if (priv->stations[index].used &&
301 !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
302 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
303 return index;
304 }
305
306
307 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
308 station = &priv->stations[index];
309 station->used = 1;
310 priv->num_stations++;
311
312 /* Set up the REPLY_ADD_STA command to send to device */
313 memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
314 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
315 station->sta.mode = 0;
316 station->sta.sta.sta_id = index;
317 station->sta.station_flags = 0;
318
319#ifdef CONFIG_IWL4965_HT
320 /* BCAST station and IBSS stations do not work in HT mode */
321 if (index != priv->hw_params.bcast_sta_id &&
322 priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
323 iwl4965_set_ht_add_station(priv, index,
324 (struct ieee80211_ht_info *) ht_data);
325#endif /*CONFIG_IWL4965_HT*/
326
327 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
328
329 /* Add station to device's station table */
330 iwl_send_add_sta(priv, &station->sta, flags);
331 return index;
332
333}
334
335
336
337/*************** HOST COMMAND QUEUE FUNCTIONS *****/
338
339/**
340 * iwl4965_enqueue_hcmd - enqueue a uCode command
341 * @priv: device private data point
342 * @cmd: a point to the ucode command structure
343 *
344 * The function returns < 0 values to indicate the operation is
345 * failed. On success, it turns the index (> 0) of command in the
346 * command queue.
347 */
348int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
349{
350 struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
351 struct iwl4965_queue *q = &txq->q;
352 struct iwl_tfd_frame *tfd;
353 u32 *control_flags;
354 struct iwl_cmd *out_cmd;
355 u32 idx;
356 u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
357 dma_addr_t phys_addr;
358 int ret;
359 unsigned long flags;
360
361 /* If any of the command structures end up being larger than
362 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
363 * we will need to increase the size of the TFD entries */
364 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
365 !(cmd->meta.flags & CMD_SIZE_HUGE));
366
367 if (iwl_is_rfkill(priv)) {
368 IWL_DEBUG_INFO("Not sending command - RF KILL");
369 return -EIO;
370 }
371
372 if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
373 IWL_ERROR("No space for Tx\n");
374 return -ENOSPC;
375 }
376
377 spin_lock_irqsave(&priv->hcmd_lock, flags);
378
379 tfd = &txq->bd[q->write_ptr];
380 memset(tfd, 0, sizeof(*tfd));
381
382 control_flags = (u32 *) tfd;
383
384 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
385 out_cmd = &txq->cmd[idx];
386
387 out_cmd->hdr.cmd = cmd->id;
388 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
389 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
390
391 /* At this point, the out_cmd now has all of the incoming cmd
392 * information */
393
394 out_cmd->hdr.flags = 0;
395 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
396 INDEX_TO_SEQ(q->write_ptr));
397 if (out_cmd->meta.flags & CMD_SIZE_HUGE)
398 out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
399
400 phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
401 offsetof(struct iwl_cmd, hdr);
402 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
403
404 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
405 "%d bytes at %d[%d]:%d\n",
406 get_cmd_string(out_cmd->hdr.cmd),
407 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
408 fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
409
410 txq->need_update = 1;
411
412 /* Set up entry in queue's byte count circular buffer */
413 priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, 0);
414
415 /* Increment and update queue's write index */
416 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
417 ret = iwl4965_tx_queue_update_write_ptr(priv, txq);
418
419 spin_unlock_irqrestore(&priv->hcmd_lock, flags);
420 return ret ? ret : idx;
421}
422 138
423static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) 139static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
424{ 140{
425 struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; 141 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
426 142
427 if (hw_decrypt) 143 if (hw_decrypt)
428 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; 144 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
@@ -432,45 +148,13 @@ static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
432} 148}
433 149
434/** 150/**
435 * iwl4965_rxon_add_station - add station into station table.
436 *
437 * there is only one AP station with id= IWL_AP_ID
438 * NOTE: mutex must be held before calling this fnction
439 */
440static int iwl4965_rxon_add_station(struct iwl_priv *priv,
441 const u8 *addr, int is_ap)
442{
443 u8 sta_id;
444
445 /* Add station to device's station table */
446#ifdef CONFIG_IWL4965_HT
447 struct ieee80211_conf *conf = &priv->hw->conf;
448 struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf;
449
450 if ((is_ap) &&
451 (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
452 (priv->iw_mode == IEEE80211_IF_TYPE_STA))
453 sta_id = iwl4965_add_station_flags(priv, addr, is_ap,
454 0, cur_ht_config);
455 else
456#endif /* CONFIG_IWL4965_HT */
457 sta_id = iwl4965_add_station_flags(priv, addr, is_ap,
458 0, NULL);
459
460 /* Set up default rate scaling table in device's station table */
461 iwl4965_add_station(priv, addr, is_ap);
462
463 return sta_id;
464}
465
466/**
467 * iwl4965_check_rxon_cmd - validate RXON structure is valid 151 * iwl4965_check_rxon_cmd - validate RXON structure is valid
468 * 152 *
469 * NOTE: This is really only useful during development and can eventually 153 * NOTE: This is really only useful during development and can eventually
470 * be #ifdef'd out once the driver is stable and folks aren't actively 154 * be #ifdef'd out once the driver is stable and folks aren't actively
471 * making changes 155 * making changes
472 */ 156 */
473static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon) 157static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
474{ 158{
475 int error = 0; 159 int error = 0;
476 int counter = 1; 160 int counter = 1;
@@ -595,7 +279,7 @@ static int iwl4965_full_rxon_required(struct iwl_priv *priv)
595static int iwl4965_commit_rxon(struct iwl_priv *priv) 279static int iwl4965_commit_rxon(struct iwl_priv *priv)
596{ 280{
597 /* cast away the const for active_rxon in this function */ 281 /* cast away the const for active_rxon in this function */
598 struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon; 282 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
599 DECLARE_MAC_BUF(mac); 283 DECLARE_MAC_BUF(mac);
600 int rc = 0; 284 int rc = 0;
601 285
@@ -640,7 +324,7 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
640 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; 324 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
641 325
642 rc = iwl_send_cmd_pdu(priv, REPLY_RXON, 326 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
643 sizeof(struct iwl4965_rxon_cmd), 327 sizeof(struct iwl_rxon_cmd),
644 &priv->active_rxon); 328 &priv->active_rxon);
645 329
646 /* If the mask clearing failed then we set 330 /* If the mask clearing failed then we set
@@ -665,12 +349,13 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
665 iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); 349 iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
666 /* Apply the new configuration */ 350 /* Apply the new configuration */
667 rc = iwl_send_cmd_pdu(priv, REPLY_RXON, 351 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
668 sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon); 352 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
669 if (rc) { 353 if (rc) {
670 IWL_ERROR("Error setting new configuration (%d).\n", rc); 354 IWL_ERROR("Error setting new configuration (%d).\n", rc);
671 return rc; 355 return rc;
672 } 356 }
673 357
358 iwl_remove_station(priv, iwl_bcast_addr, 0);
674 iwlcore_clear_stations_table(priv); 359 iwlcore_clear_stations_table(priv);
675 360
676 if (!priv->error_recovering) 361 if (!priv->error_recovering)
@@ -689,7 +374,7 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
689 } 374 }
690 375
691 /* Add the broadcast address so we can send broadcast frames */ 376 /* Add the broadcast address so we can send broadcast frames */
692 if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) == 377 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
693 IWL_INVALID_STATION) { 378 IWL_INVALID_STATION) {
694 IWL_ERROR("Error adding BROADCAST address for transmit.\n"); 379 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
695 return -EIO; 380 return -EIO;
@@ -699,7 +384,7 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
699 * add the IWL_AP_ID to the station rate table */ 384 * add the IWL_AP_ID to the station rate table */
700 if (iwl_is_associated(priv) && 385 if (iwl_is_associated(priv) &&
701 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { 386 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
702 if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) 387 if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
703 == IWL_INVALID_STATION) { 388 == IWL_INVALID_STATION) {
704 IWL_ERROR("Error adding AP address for transmit.\n"); 389 IWL_ERROR("Error adding AP address for transmit.\n");
705 return -EIO; 390 return -EIO;
@@ -797,7 +482,7 @@ static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_fla
797 return iwl_send_cmd(priv, &cmd); 482 return iwl_send_cmd(priv, &cmd);
798} 483}
799 484
800static void iwl4965_clear_free_frames(struct iwl_priv *priv) 485static void iwl_clear_free_frames(struct iwl_priv *priv)
801{ 486{
802 struct list_head *element; 487 struct list_head *element;
803 488
@@ -807,7 +492,7 @@ static void iwl4965_clear_free_frames(struct iwl_priv *priv)
807 while (!list_empty(&priv->free_frames)) { 492 while (!list_empty(&priv->free_frames)) {
808 element = priv->free_frames.next; 493 element = priv->free_frames.next;
809 list_del(element); 494 list_del(element);
810 kfree(list_entry(element, struct iwl4965_frame, list)); 495 kfree(list_entry(element, struct iwl_frame, list));
811 priv->frames_count--; 496 priv->frames_count--;
812 } 497 }
813 498
@@ -818,9 +503,9 @@ static void iwl4965_clear_free_frames(struct iwl_priv *priv)
818 } 503 }
819} 504}
820 505
821static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl_priv *priv) 506static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
822{ 507{
823 struct iwl4965_frame *frame; 508 struct iwl_frame *frame;
824 struct list_head *element; 509 struct list_head *element;
825 if (list_empty(&priv->free_frames)) { 510 if (list_empty(&priv->free_frames)) {
826 frame = kzalloc(sizeof(*frame), GFP_KERNEL); 511 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
@@ -835,10 +520,10 @@ static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl_priv *priv)
835 520
836 element = priv->free_frames.next; 521 element = priv->free_frames.next;
837 list_del(element); 522 list_del(element);
838 return list_entry(element, struct iwl4965_frame, list); 523 return list_entry(element, struct iwl_frame, list);
839} 524}
840 525
841static void iwl4965_free_frame(struct iwl_priv *priv, struct iwl4965_frame *frame) 526static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
842{ 527{
843 memset(frame, 0, sizeof(*frame)); 528 memset(frame, 0, sizeof(*frame));
844 list_add(&frame->list, &priv->free_frames); 529 list_add(&frame->list, &priv->free_frames);
@@ -875,9 +560,9 @@ static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
875 560
876 /* Find lowest valid rate */ 561 /* Find lowest valid rate */
877 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; 562 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
878 i = iwl4965_rates[i].next_ieee) { 563 i = iwl_rates[i].next_ieee) {
879 if (rate_mask & (1 << i)) 564 if (rate_mask & (1 << i))
880 return iwl4965_rates[i].plcp; 565 return iwl_rates[i].plcp;
881 } 566 }
882 567
883 /* No valid rate was found. Assign the lowest one */ 568 /* No valid rate was found. Assign the lowest one */
@@ -889,12 +574,12 @@ static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
889 574
890static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) 575static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
891{ 576{
892 struct iwl4965_frame *frame; 577 struct iwl_frame *frame;
893 unsigned int frame_size; 578 unsigned int frame_size;
894 int rc; 579 int rc;
895 u8 rate; 580 u8 rate;
896 581
897 frame = iwl4965_get_free_frame(priv); 582 frame = iwl_get_free_frame(priv);
898 583
899 if (!frame) { 584 if (!frame) {
900 IWL_ERROR("Could not obtain free frame buffer for beacon " 585 IWL_ERROR("Could not obtain free frame buffer for beacon "
@@ -909,7 +594,7 @@ static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
909 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, 594 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
910 &frame->u.cmd[0]); 595 &frame->u.cmd[0]);
911 596
912 iwl4965_free_frame(priv, frame); 597 iwl_free_frame(priv, frame);
913 598
914 return rc; 599 return rc;
915} 600}
@@ -936,7 +621,7 @@ static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
936 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { 621 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
937 if (bit & supported_rate) { 622 if (bit & supported_rate) {
938 ret_rates |= bit; 623 ret_rates |= bit;
939 rates[*cnt] = iwl4965_rates[i].ieee | 624 rates[*cnt] = iwl_rates[i].ieee |
940 ((bit & basic_rate) ? 0x80 : 0x00); 625 ((bit & basic_rate) ? 0x80 : 0x00);
941 (*cnt)++; 626 (*cnt)++;
942 (*left)--; 627 (*left)--;
@@ -967,9 +652,9 @@ static void iwl4965_ht_conf(struct iwl_priv *priv,
967 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); 652 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
968 653
969 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) 654 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
970 iwl_conf->sgf |= 0x1; 655 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
971 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) 656 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
972 iwl_conf->sgf |= 0x2; 657 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
973 658
974 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); 659 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
975 iwl_conf->max_amsdu_size = 660 iwl_conf->max_amsdu_size =
@@ -1056,9 +741,9 @@ static u16 iwl4965_fill_probe_req(struct iwl_priv *priv,
1056 len += 24; 741 len += 24;
1057 742
1058 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); 743 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
1059 memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN); 744 memcpy(frame->da, iwl_bcast_addr, ETH_ALEN);
1060 memcpy(frame->sa, priv->mac_addr, ETH_ALEN); 745 memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
1061 memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN); 746 memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN);
1062 frame->seq_ctrl = 0; 747 frame->seq_ctrl = 0;
1063 748
1064 /* fill in our indirect SSID IE */ 749 /* fill in our indirect SSID IE */
@@ -1224,33 +909,7 @@ int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *heade
1224 return 1; 909 return 1;
1225} 910}
1226 911
1227#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1228
1229static const char *iwl4965_get_tx_fail_reason(u32 status)
1230{
1231 switch (status & TX_STATUS_MSK) {
1232 case TX_STATUS_SUCCESS:
1233 return "SUCCESS";
1234 TX_STATUS_ENTRY(SHORT_LIMIT);
1235 TX_STATUS_ENTRY(LONG_LIMIT);
1236 TX_STATUS_ENTRY(FIFO_UNDERRUN);
1237 TX_STATUS_ENTRY(MGMNT_ABORT);
1238 TX_STATUS_ENTRY(NEXT_FRAG);
1239 TX_STATUS_ENTRY(LIFE_EXPIRE);
1240 TX_STATUS_ENTRY(DEST_PS);
1241 TX_STATUS_ENTRY(ABORTED);
1242 TX_STATUS_ENTRY(BT_RETRY);
1243 TX_STATUS_ENTRY(STA_INVALID);
1244 TX_STATUS_ENTRY(FRAG_DROPPED);
1245 TX_STATUS_ENTRY(TID_DISABLE);
1246 TX_STATUS_ENTRY(FRAME_FLUSHED);
1247 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
1248 TX_STATUS_ENTRY(TX_LOCKED);
1249 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
1250 }
1251 912
1252 return "UNKNOWN";
1253}
1254 913
1255/** 914/**
1256 * iwl4965_scan_cancel - Cancel any currently executing HW scan 915 * iwl4965_scan_cancel - Cancel any currently executing HW scan
@@ -1425,8 +1084,8 @@ static int iwl4965_scan_initiate(struct iwl_priv *priv)
1425} 1084}
1426 1085
1427 1086
1428static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv, 1087static void iwl_set_flags_for_band(struct iwl_priv *priv,
1429 enum ieee80211_band band) 1088 enum ieee80211_band band)
1430{ 1089{
1431 if (band == IEEE80211_BAND_5GHZ) { 1090 if (band == IEEE80211_BAND_5GHZ) {
1432 priv->staging_rxon.flags &= 1091 priv->staging_rxon.flags &=
@@ -1511,7 +1170,7 @@ static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
1511 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); 1170 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
1512 priv->band = ch_info->band; 1171 priv->band = ch_info->band;
1513 1172
1514 iwl4965_set_flags_for_phymode(priv, priv->band); 1173 iwl_set_flags_for_band(priv, priv->band);
1515 1174
1516 priv->staging_rxon.ofdm_basic_rates = 1175 priv->staging_rxon.ofdm_basic_rates =
1517 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; 1176 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
@@ -1566,441 +1225,6 @@ static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
1566 return 0; 1225 return 0;
1567} 1226}
1568 1227
1569static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
1570 struct ieee80211_tx_control *ctl,
1571 struct iwl_cmd *cmd,
1572 struct sk_buff *skb_frag,
1573 int sta_id)
1574{
1575 struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
1576 struct iwl_wep_key *wepkey;
1577 int keyidx = 0;
1578
1579 BUG_ON(ctl->hw_key->hw_key_idx > 3);
1580
1581 switch (keyinfo->alg) {
1582 case ALG_CCMP:
1583 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
1584 memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
1585 if (ctl->flags & IEEE80211_TXCTL_AMPDU)
1586 cmd->cmd.tx.tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
1587 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
1588 break;
1589
1590 case ALG_TKIP:
1591 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
1592 ieee80211_get_tkip_key(keyinfo->conf, skb_frag,
1593 IEEE80211_TKIP_P2_KEY, cmd->cmd.tx.key);
1594 IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
1595 break;
1596
1597 case ALG_WEP:
1598 wepkey = &priv->wep_keys[ctl->hw_key->hw_key_idx];
1599 cmd->cmd.tx.sec_ctl = 0;
1600 if (priv->default_wep_key) {
1601 /* the WEP key was sent as static */
1602 keyidx = ctl->hw_key->hw_key_idx;
1603 memcpy(&cmd->cmd.tx.key[3], wepkey->key,
1604 wepkey->key_size);
1605 if (wepkey->key_size == WEP_KEY_LEN_128)
1606 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
1607 } else {
1608 /* the WEP key was sent as dynamic */
1609 keyidx = keyinfo->keyidx;
1610 memcpy(&cmd->cmd.tx.key[3], keyinfo->key,
1611 keyinfo->keylen);
1612 if (keyinfo->keylen == WEP_KEY_LEN_128)
1613 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
1614 }
1615
1616 cmd->cmd.tx.sec_ctl |= (TX_CMD_SEC_WEP |
1617 (keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
1618
1619 IWL_DEBUG_TX("Configuring packet for WEP encryption "
1620 "with key %d\n", keyidx);
1621 break;
1622
1623 default:
1624 printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
1625 break;
1626 }
1627}
1628
1629/*
1630 * handle build REPLY_TX command notification.
1631 */
1632static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv,
1633 struct iwl_cmd *cmd,
1634 struct ieee80211_tx_control *ctrl,
1635 struct ieee80211_hdr *hdr,
1636 int is_unicast, u8 std_id)
1637{
1638 __le16 *qc;
1639 u16 fc = le16_to_cpu(hdr->frame_control);
1640 __le32 tx_flags = cmd->cmd.tx.tx_flags;
1641
1642 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
1643 if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
1644 tx_flags |= TX_CMD_FLG_ACK_MSK;
1645 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
1646 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
1647 if (ieee80211_is_probe_response(fc) &&
1648 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
1649 tx_flags |= TX_CMD_FLG_TSF_MSK;
1650 } else {
1651 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
1652 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
1653 }
1654
1655 if (ieee80211_is_back_request(fc))
1656 tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
1657
1658
1659 cmd->cmd.tx.sta_id = std_id;
1660 if (ieee80211_get_morefrag(hdr))
1661 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
1662
1663 qc = ieee80211_get_qos_ctrl(hdr);
1664 if (qc) {
1665 cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
1666 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
1667 } else
1668 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
1669
1670 if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
1671 tx_flags |= TX_CMD_FLG_RTS_MSK;
1672 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
1673 } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
1674 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
1675 tx_flags |= TX_CMD_FLG_CTS_MSK;
1676 }
1677
1678 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
1679 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
1680
1681 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
1682 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
1683 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
1684 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
1685 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
1686 else
1687 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
1688 } else {
1689 cmd->cmd.tx.timeout.pm_frame_timeout = 0;
1690 }
1691
1692 cmd->cmd.tx.driver_txop = 0;
1693 cmd->cmd.tx.tx_flags = tx_flags;
1694 cmd->cmd.tx.next_frame_len = 0;
1695}
1696static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len)
1697{
1698 /* 0 - mgmt, 1 - cnt, 2 - data */
1699 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
1700 priv->tx_stats[idx].cnt++;
1701 priv->tx_stats[idx].bytes += len;
1702}
1703/**
1704 * iwl4965_get_sta_id - Find station's index within station table
1705 *
1706 * If new IBSS station, create new entry in station table
1707 */
1708static int iwl4965_get_sta_id(struct iwl_priv *priv,
1709 struct ieee80211_hdr *hdr)
1710{
1711 int sta_id;
1712 u16 fc = le16_to_cpu(hdr->frame_control);
1713 DECLARE_MAC_BUF(mac);
1714
1715 /* If this frame is broadcast or management, use broadcast station id */
1716 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
1717 is_multicast_ether_addr(hdr->addr1))
1718 return priv->hw_params.bcast_sta_id;
1719
1720 switch (priv->iw_mode) {
1721
1722 /* If we are a client station in a BSS network, use the special
1723 * AP station entry (that's the only station we communicate with) */
1724 case IEEE80211_IF_TYPE_STA:
1725 return IWL_AP_ID;
1726
1727 /* If we are an AP, then find the station, or use BCAST */
1728 case IEEE80211_IF_TYPE_AP:
1729 sta_id = iwl_find_station(priv, hdr->addr1);
1730 if (sta_id != IWL_INVALID_STATION)
1731 return sta_id;
1732 return priv->hw_params.bcast_sta_id;
1733
1734 /* If this frame is going out to an IBSS network, find the station,
1735 * or create a new station table entry */
1736 case IEEE80211_IF_TYPE_IBSS:
1737 sta_id = iwl_find_station(priv, hdr->addr1);
1738 if (sta_id != IWL_INVALID_STATION)
1739 return sta_id;
1740
1741 /* Create new station table entry */
1742 sta_id = iwl4965_add_station_flags(priv, hdr->addr1,
1743 0, CMD_ASYNC, NULL);
1744
1745 if (sta_id != IWL_INVALID_STATION)
1746 return sta_id;
1747
1748 IWL_DEBUG_DROP("Station %s not in station map. "
1749 "Defaulting to broadcast...\n",
1750 print_mac(mac, hdr->addr1));
1751 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
1752 return priv->hw_params.bcast_sta_id;
1753
1754 default:
1755 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
1756 return priv->hw_params.bcast_sta_id;
1757 }
1758}
1759
1760/*
1761 * start REPLY_TX command process
1762 */
1763static int iwl4965_tx_skb(struct iwl_priv *priv,
1764 struct sk_buff *skb, struct ieee80211_tx_control *ctl)
1765{
1766 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1767 struct iwl_tfd_frame *tfd;
1768 u32 *control_flags;
1769 int txq_id = ctl->queue;
1770 struct iwl_tx_queue *txq = NULL;
1771 struct iwl4965_queue *q = NULL;
1772 dma_addr_t phys_addr;
1773 dma_addr_t txcmd_phys;
1774 dma_addr_t scratch_phys;
1775 struct iwl_cmd *out_cmd = NULL;
1776 u16 len, idx, len_org;
1777 u8 id, hdr_len, unicast;
1778 u8 sta_id;
1779 u16 seq_number = 0;
1780 u16 fc;
1781 __le16 *qc;
1782 u8 wait_write_ptr = 0;
1783 unsigned long flags;
1784 int rc;
1785
1786 spin_lock_irqsave(&priv->lock, flags);
1787 if (iwl_is_rfkill(priv)) {
1788 IWL_DEBUG_DROP("Dropping - RF KILL\n");
1789 goto drop_unlock;
1790 }
1791
1792 if (!priv->vif) {
1793 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
1794 goto drop_unlock;
1795 }
1796
1797 if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) {
1798 IWL_ERROR("ERROR: No TX rate available.\n");
1799 goto drop_unlock;
1800 }
1801
1802 unicast = !is_multicast_ether_addr(hdr->addr1);
1803 id = 0;
1804
1805 fc = le16_to_cpu(hdr->frame_control);
1806
1807#ifdef CONFIG_IWLWIFI_DEBUG
1808 if (ieee80211_is_auth(fc))
1809 IWL_DEBUG_TX("Sending AUTH frame\n");
1810 else if (ieee80211_is_assoc_request(fc))
1811 IWL_DEBUG_TX("Sending ASSOC frame\n");
1812 else if (ieee80211_is_reassoc_request(fc))
1813 IWL_DEBUG_TX("Sending REASSOC frame\n");
1814#endif
1815
1816 /* drop all data frame if we are not associated */
1817 if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
1818 (!iwl_is_associated(priv) ||
1819 ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) ||
1820 !priv->assoc_station_added)) {
1821 IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
1822 goto drop_unlock;
1823 }
1824
1825 spin_unlock_irqrestore(&priv->lock, flags);
1826
1827 hdr_len = ieee80211_get_hdrlen(fc);
1828
1829 /* Find (or create) index into station table for destination station */
1830 sta_id = iwl4965_get_sta_id(priv, hdr);
1831 if (sta_id == IWL_INVALID_STATION) {
1832 DECLARE_MAC_BUF(mac);
1833
1834 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
1835 print_mac(mac, hdr->addr1));
1836 goto drop;
1837 }
1838
1839 IWL_DEBUG_TX("station Id %d\n", sta_id);
1840
1841 qc = ieee80211_get_qos_ctrl(hdr);
1842 if (qc) {
1843 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
1844 seq_number = priv->stations[sta_id].tid[tid].seq_number &
1845 IEEE80211_SCTL_SEQ;
1846 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1847 (hdr->seq_ctrl &
1848 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
1849 seq_number += 0x10;
1850#ifdef CONFIG_IWL4965_HT
1851 /* aggregation is on for this <sta,tid> */
1852 if (ctl->flags & IEEE80211_TXCTL_AMPDU)
1853 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
1854 priv->stations[sta_id].tid[tid].tfds_in_queue++;
1855#endif /* CONFIG_IWL4965_HT */
1856 }
1857
1858 /* Descriptor for chosen Tx queue */
1859 txq = &priv->txq[txq_id];
1860 q = &txq->q;
1861
1862 spin_lock_irqsave(&priv->lock, flags);
1863
1864 /* Set up first empty TFD within this queue's circular TFD buffer */
1865 tfd = &txq->bd[q->write_ptr];
1866 memset(tfd, 0, sizeof(*tfd));
1867 control_flags = (u32 *) tfd;
1868 idx = get_cmd_index(q, q->write_ptr, 0);
1869
1870 /* Set up driver data for this TFD */
1871 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info));
1872 txq->txb[q->write_ptr].skb[0] = skb;
1873 memcpy(&(txq->txb[q->write_ptr].status.control),
1874 ctl, sizeof(struct ieee80211_tx_control));
1875
1876 /* Set up first empty entry in queue's array of Tx/cmd buffers */
1877 out_cmd = &txq->cmd[idx];
1878 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
1879 memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
1880
1881 /*
1882 * Set up the Tx-command (not MAC!) header.
1883 * Store the chosen Tx queue and TFD index within the sequence field;
1884 * after Tx, uCode's Tx response will return this value so driver can
1885 * locate the frame within the tx queue and do post-tx processing.
1886 */
1887 out_cmd->hdr.cmd = REPLY_TX;
1888 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
1889 INDEX_TO_SEQ(q->write_ptr)));
1890
1891 /* Copy MAC header from skb into command buffer */
1892 memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
1893
1894 /*
1895 * Use the first empty entry in this queue's command buffer array
1896 * to contain the Tx command and MAC header concatenated together
1897 * (payload data will be in another buffer).
1898 * Size of this varies, due to varying MAC header length.
1899 * If end is not dword aligned, we'll have 2 extra bytes at the end
1900 * of the MAC header (device reads on dword boundaries).
1901 * We'll tell device about this padding later.
1902 */
1903 len = priv->hw_params.tx_cmd_len +
1904 sizeof(struct iwl_cmd_header) + hdr_len;
1905
1906 len_org = len;
1907 len = (len + 3) & ~3;
1908
1909 if (len_org != len)
1910 len_org = 1;
1911 else
1912 len_org = 0;
1913
1914 /* Physical address of this Tx command's header (not MAC header!),
1915 * within command buffer array. */
1916 txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx +
1917 offsetof(struct iwl_cmd, hdr);
1918
1919 /* Add buffer containing Tx command and MAC(!) header to TFD's
1920 * first entry */
1921 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
1922
1923 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
1924 iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, sta_id);
1925
1926 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1927 * if any (802.11 null frames have no payload). */
1928 len = skb->len - hdr_len;
1929 if (len) {
1930 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1931 len, PCI_DMA_TODEVICE);
1932 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
1933 }
1934
1935 /* Tell 4965 about any 2-byte padding after MAC header */
1936 if (len_org)
1937 out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
1938
1939 /* Total # bytes to be transmitted */
1940 len = (u16)skb->len;
1941 out_cmd->cmd.tx.len = cpu_to_le16(len);
1942
1943 /* TODO need this for burst mode later on */
1944 iwl4965_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
1945
1946 /* set is_hcca to 0; it probably will never be implemented */
1947 iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
1948
1949 iwl_update_tx_stats(priv, fc, len);
1950
1951 scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) +
1952 offsetof(struct iwl4965_tx_cmd, scratch);
1953 out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys);
1954 out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys);
1955
1956 if (!ieee80211_get_morefrag(hdr)) {
1957 txq->need_update = 1;
1958 if (qc) {
1959 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
1960 priv->stations[sta_id].tid[tid].seq_number = seq_number;
1961 }
1962 } else {
1963 wait_write_ptr = 1;
1964 txq->need_update = 0;
1965 }
1966
1967 iwl_print_hex_dump(priv, IWL_DL_TX, out_cmd->cmd.payload,
1968 sizeof(out_cmd->cmd.tx));
1969
1970 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
1971 ieee80211_get_hdrlen(fc));
1972
1973 /* Set up entry for this TFD in Tx byte-count array */
1974 priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, len);
1975
1976 /* Tell device the write index *just past* this latest filled TFD */
1977 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
1978 rc = iwl4965_tx_queue_update_write_ptr(priv, txq);
1979 spin_unlock_irqrestore(&priv->lock, flags);
1980
1981 if (rc)
1982 return rc;
1983
1984 if ((iwl4965_queue_space(q) < q->high_mark)
1985 && priv->mac80211_registered) {
1986 if (wait_write_ptr) {
1987 spin_lock_irqsave(&priv->lock, flags);
1988 txq->need_update = 1;
1989 iwl4965_tx_queue_update_write_ptr(priv, txq);
1990 spin_unlock_irqrestore(&priv->lock, flags);
1991 }
1992
1993 ieee80211_stop_queue(priv->hw, ctl->queue);
1994 }
1995
1996 return 0;
1997
1998drop_unlock:
1999 spin_unlock_irqrestore(&priv->lock, flags);
2000drop:
2001 return -1;
2002}
2003
2004static void iwl4965_set_rate(struct iwl_priv *priv) 1228static void iwl4965_set_rate(struct iwl_priv *priv)
2005{ 1229{
2006 const struct ieee80211_supported_band *hw = NULL; 1230 const struct ieee80211_supported_band *hw = NULL;
@@ -2305,341 +1529,16 @@ static int iwl4965_get_measurement(struct iwl_priv *priv,
2305} 1529}
2306#endif 1530#endif
2307 1531
2308static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv,
2309 struct iwl4965_tx_info *tx_sta)
2310{
2311
2312 tx_sta->status.ack_signal = 0;
2313 tx_sta->status.excessive_retries = 0;
2314
2315 if (in_interrupt())
2316 ieee80211_tx_status_irqsafe(priv->hw,
2317 tx_sta->skb[0], &(tx_sta->status));
2318 else
2319 ieee80211_tx_status(priv->hw,
2320 tx_sta->skb[0], &(tx_sta->status));
2321
2322 tx_sta->skb[0] = NULL;
2323}
2324
2325/**
2326 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
2327 *
2328 * When FW advances 'R' index, all entries between old and new 'R' index
2329 * need to be reclaimed. As result, some free space forms. If there is
2330 * enough free space (> low mark), wake the stack that feeds us.
2331 */
2332int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
2333{
2334 struct iwl_tx_queue *txq = &priv->txq[txq_id];
2335 struct iwl4965_queue *q = &txq->q;
2336 int nfreed = 0;
2337
2338 if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) {
2339 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
2340 "is out of range [0-%d] %d %d.\n", txq_id,
2341 index, q->n_bd, q->write_ptr, q->read_ptr);
2342 return 0;
2343 }
2344
2345 for (index = iwl_queue_inc_wrap(index, q->n_bd);
2346 q->read_ptr != index;
2347 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
2348 if (txq_id != IWL_CMD_QUEUE_NUM) {
2349 iwl4965_txstatus_to_ieee(priv,
2350 &(txq->txb[txq->q.read_ptr]));
2351 iwl_hw_txq_free_tfd(priv, txq);
2352 } else if (nfreed > 1) {
2353 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
2354 q->write_ptr, q->read_ptr);
2355 queue_work(priv->workqueue, &priv->restart);
2356 }
2357 nfreed++;
2358 }
2359
2360 return nfreed;
2361}
2362
2363static int iwl4965_is_tx_success(u32 status)
2364{
2365 status &= TX_STATUS_MSK;
2366 return (status == TX_STATUS_SUCCESS)
2367 || (status == TX_STATUS_DIRECT_DONE);
2368}
2369
2370/****************************************************************************** 1532/******************************************************************************
2371 * 1533 *
2372 * Generic RX handler implementations 1534 * Generic RX handler implementations
2373 * 1535 *
2374 ******************************************************************************/ 1536 ******************************************************************************/
2375#ifdef CONFIG_IWL4965_HT 1537static void iwl_rx_reply_alive(struct iwl_priv *priv,
2376
2377static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv,
2378 struct ieee80211_hdr *hdr)
2379{
2380 if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
2381 return IWL_AP_ID;
2382 else {
2383 u8 *da = ieee80211_get_DA(hdr);
2384 return iwl_find_station(priv, da);
2385 }
2386}
2387
2388static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr(
2389 struct iwl_priv *priv, int txq_id, int idx)
2390{
2391 if (priv->txq[txq_id].txb[idx].skb[0])
2392 return (struct ieee80211_hdr *)priv->txq[txq_id].
2393 txb[idx].skb[0]->data;
2394 return NULL;
2395}
2396
2397static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
2398{
2399 __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
2400 tx_resp->frame_count);
2401 return le32_to_cpu(*scd_ssn) & MAX_SN;
2402
2403}
2404
2405/**
2406 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
2407 */
2408static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
2409 struct iwl_ht_agg *agg,
2410 struct iwl4965_tx_resp_agg *tx_resp,
2411 u16 start_idx)
2412{
2413 u16 status;
2414 struct agg_tx_status *frame_status = &tx_resp->status;
2415 struct ieee80211_tx_status *tx_status = NULL;
2416 struct ieee80211_hdr *hdr = NULL;
2417 int i, sh;
2418 int txq_id, idx;
2419 u16 seq;
2420
2421 if (agg->wait_for_ba)
2422 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
2423
2424 agg->frame_count = tx_resp->frame_count;
2425 agg->start_idx = start_idx;
2426 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
2427 agg->bitmap = 0;
2428
2429 /* # frames attempted by Tx command */
2430 if (agg->frame_count == 1) {
2431 /* Only one frame was attempted; no block-ack will arrive */
2432 status = le16_to_cpu(frame_status[0].status);
2433 seq = le16_to_cpu(frame_status[0].sequence);
2434 idx = SEQ_TO_INDEX(seq);
2435 txq_id = SEQ_TO_QUEUE(seq);
2436
2437 /* FIXME: code repetition */
2438 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
2439 agg->frame_count, agg->start_idx, idx);
2440
2441 tx_status = &(priv->txq[txq_id].txb[idx].status);
2442 tx_status->retry_count = tx_resp->failure_frame;
2443 tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU;
2444 tx_status->flags = iwl4965_is_tx_success(status)?
2445 IEEE80211_TX_STATUS_ACK : 0;
2446 iwl4965_hwrate_to_tx_control(priv,
2447 le32_to_cpu(tx_resp->rate_n_flags),
2448 &tx_status->control);
2449 /* FIXME: code repetition end */
2450
2451 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
2452 status & 0xff, tx_resp->failure_frame);
2453 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
2454 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
2455
2456 agg->wait_for_ba = 0;
2457 } else {
2458 /* Two or more frames were attempted; expect block-ack */
2459 u64 bitmap = 0;
2460 int start = agg->start_idx;
2461
2462 /* Construct bit-map of pending frames within Tx window */
2463 for (i = 0; i < agg->frame_count; i++) {
2464 u16 sc;
2465 status = le16_to_cpu(frame_status[i].status);
2466 seq = le16_to_cpu(frame_status[i].sequence);
2467 idx = SEQ_TO_INDEX(seq);
2468 txq_id = SEQ_TO_QUEUE(seq);
2469
2470 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
2471 AGG_TX_STATE_ABORT_MSK))
2472 continue;
2473
2474 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
2475 agg->frame_count, txq_id, idx);
2476
2477 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx);
2478
2479 sc = le16_to_cpu(hdr->seq_ctrl);
2480 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
2481 IWL_ERROR("BUG_ON idx doesn't match seq control"
2482 " idx=%d, seq_idx=%d, seq=%d\n",
2483 idx, SEQ_TO_SN(sc),
2484 hdr->seq_ctrl);
2485 return -1;
2486 }
2487
2488 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
2489 i, idx, SEQ_TO_SN(sc));
2490
2491 sh = idx - start;
2492 if (sh > 64) {
2493 sh = (start - idx) + 0xff;
2494 bitmap = bitmap << sh;
2495 sh = 0;
2496 start = idx;
2497 } else if (sh < -64)
2498 sh = 0xff - (start - idx);
2499 else if (sh < 0) {
2500 sh = start - idx;
2501 start = idx;
2502 bitmap = bitmap << sh;
2503 sh = 0;
2504 }
2505 bitmap |= (1 << sh);
2506 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
2507 start, (u32)(bitmap & 0xFFFFFFFF));
2508 }
2509
2510 agg->bitmap = bitmap;
2511 agg->start_idx = start;
2512 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
2513 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
2514 agg->frame_count, agg->start_idx,
2515 (unsigned long long)agg->bitmap);
2516
2517 if (bitmap)
2518 agg->wait_for_ba = 1;
2519 }
2520 return 0;
2521}
2522#endif
2523
2524/**
2525 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
2526 */
2527static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
2528 struct iwl_rx_mem_buffer *rxb) 1538 struct iwl_rx_mem_buffer *rxb)
2529{ 1539{
2530 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; 1540 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2531 u16 sequence = le16_to_cpu(pkt->hdr.sequence); 1541 struct iwl_alive_resp *palive;
2532 int txq_id = SEQ_TO_QUEUE(sequence);
2533 int index = SEQ_TO_INDEX(sequence);
2534 struct iwl_tx_queue *txq = &priv->txq[txq_id];
2535 struct ieee80211_tx_status *tx_status;
2536 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
2537 u32 status = le32_to_cpu(tx_resp->status);
2538#ifdef CONFIG_IWL4965_HT
2539 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
2540 struct ieee80211_hdr *hdr;
2541 __le16 *qc;
2542#endif
2543
2544 if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) {
2545 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
2546 "is out of range [0-%d] %d %d\n", txq_id,
2547 index, txq->q.n_bd, txq->q.write_ptr,
2548 txq->q.read_ptr);
2549 return;
2550 }
2551
2552#ifdef CONFIG_IWL4965_HT
2553 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index);
2554 qc = ieee80211_get_qos_ctrl(hdr);
2555
2556 if (qc)
2557 tid = le16_to_cpu(*qc) & 0xf;
2558
2559 sta_id = iwl4965_get_ra_sta_id(priv, hdr);
2560 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
2561 IWL_ERROR("Station not known\n");
2562 return;
2563 }
2564
2565 if (txq->sched_retry) {
2566 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
2567 struct iwl_ht_agg *agg = NULL;
2568
2569 if (!qc)
2570 return;
2571
2572 agg = &priv->stations[sta_id].tid[tid].agg;
2573
2574 iwl4965_tx_status_reply_tx(priv, agg,
2575 (struct iwl4965_tx_resp_agg *)tx_resp, index);
2576
2577 if ((tx_resp->frame_count == 1) &&
2578 !iwl4965_is_tx_success(status)) {
2579 /* TODO: send BAR */
2580 }
2581
2582 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
2583 int freed, ampdu_q;
2584 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
2585 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
2586 "%d index %d\n", scd_ssn , index);
2587 freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
2588 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
2589
2590 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
2591 txq_id >= 0 && priv->mac80211_registered &&
2592 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
2593 /* calculate mac80211 ampdu sw queue to wake */
2594 ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID +
2595 priv->hw->queues;
2596 if (agg->state == IWL_AGG_OFF)
2597 ieee80211_wake_queue(priv->hw, txq_id);
2598 else
2599 ieee80211_wake_queue(priv->hw, ampdu_q);
2600 }
2601 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
2602 }
2603 } else {
2604#endif /* CONFIG_IWL4965_HT */
2605 tx_status = &(txq->txb[txq->q.read_ptr].status);
2606
2607 tx_status->retry_count = tx_resp->failure_frame;
2608 tx_status->flags =
2609 iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
2610 iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
2611 &tx_status->control);
2612
2613 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
2614 "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
2615 status, le32_to_cpu(tx_resp->rate_n_flags),
2616 tx_resp->failure_frame);
2617
2618 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
2619#ifdef CONFIG_IWL4965_HT
2620 if (index != -1) {
2621 int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
2622 if (tid != MAX_TID_COUNT)
2623 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
2624 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
2625 (txq_id >= 0) && priv->mac80211_registered)
2626 ieee80211_wake_queue(priv->hw, txq_id);
2627 if (tid != MAX_TID_COUNT)
2628 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
2629 }
2630 }
2631#endif /* CONFIG_IWL4965_HT */
2632
2633 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
2634 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
2635}
2636
2637
2638static void iwl4965_rx_reply_alive(struct iwl_priv *priv,
2639 struct iwl_rx_mem_buffer *rxb)
2640{
2641 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2642 struct iwl4965_alive_resp *palive;
2643 struct delayed_work *pwork; 1542 struct delayed_work *pwork;
2644 1543
2645 palive = &pkt->u.alive_frame; 1544 palive = &pkt->u.alive_frame;
@@ -2653,12 +1552,12 @@ static void iwl4965_rx_reply_alive(struct iwl_priv *priv,
2653 IWL_DEBUG_INFO("Initialization Alive received.\n"); 1552 IWL_DEBUG_INFO("Initialization Alive received.\n");
2654 memcpy(&priv->card_alive_init, 1553 memcpy(&priv->card_alive_init,
2655 &pkt->u.alive_frame, 1554 &pkt->u.alive_frame,
2656 sizeof(struct iwl4965_init_alive_resp)); 1555 sizeof(struct iwl_init_alive_resp));
2657 pwork = &priv->init_alive_start; 1556 pwork = &priv->init_alive_start;
2658 } else { 1557 } else {
2659 IWL_DEBUG_INFO("Runtime Alive received.\n"); 1558 IWL_DEBUG_INFO("Runtime Alive received.\n");
2660 memcpy(&priv->card_alive, &pkt->u.alive_frame, 1559 memcpy(&priv->card_alive, &pkt->u.alive_frame,
2661 sizeof(struct iwl4965_alive_resp)); 1560 sizeof(struct iwl_alive_resp));
2662 pwork = &priv->alive_start; 1561 pwork = &priv->alive_start;
2663 } 1562 }
2664 1563
@@ -2671,15 +1570,6 @@ static void iwl4965_rx_reply_alive(struct iwl_priv *priv,
2671 IWL_WARNING("uCode did not respond OK.\n"); 1570 IWL_WARNING("uCode did not respond OK.\n");
2672} 1571}
2673 1572
2674static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv,
2675 struct iwl_rx_mem_buffer *rxb)
2676{
2677 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2678
2679 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
2680 return;
2681}
2682
2683static void iwl4965_rx_reply_error(struct iwl_priv *priv, 1573static void iwl4965_rx_reply_error(struct iwl_priv *priv,
2684 struct iwl_rx_mem_buffer *rxb) 1574 struct iwl_rx_mem_buffer *rxb)
2685{ 1575{
@@ -2699,7 +1589,7 @@ static void iwl4965_rx_reply_error(struct iwl_priv *priv,
2699static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) 1589static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
2700{ 1590{
2701 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; 1591 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2702 struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon; 1592 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
2703 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); 1593 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
2704 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", 1594 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
2705 le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); 1595 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
@@ -2753,7 +1643,7 @@ static void iwl4965_bg_beacon_update(struct work_struct *work)
2753 struct sk_buff *beacon; 1643 struct sk_buff *beacon;
2754 1644
2755 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ 1645 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
2756 beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); 1646 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
2757 1647
2758 if (!beacon) { 1648 if (!beacon) {
2759 IWL_ERROR("update beacon failed\n"); 1649 IWL_ERROR("update beacon failed\n");
@@ -2976,6 +1866,17 @@ static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
2976 wake_up_interruptible(&priv->wait_command_queue); 1866 wake_up_interruptible(&priv->wait_command_queue);
2977} 1867}
2978 1868
1869/* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
1870 * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
1871static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
1872 struct iwl_rx_mem_buffer *rxb)
1873{
1874 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1875 priv->last_phy_res[0] = 1;
1876 memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
1877 sizeof(struct iwl4965_rx_phy_res));
1878}
1879
2979/** 1880/**
2980 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks 1881 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
2981 * 1882 *
@@ -2987,8 +1888,7 @@ static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
2987 */ 1888 */
2988static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) 1889static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
2989{ 1890{
2990 priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; 1891 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
2991 priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta;
2992 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; 1892 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
2993 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; 1893 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
2994 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = 1894 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
@@ -3005,66 +1905,25 @@ static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
3005 */ 1905 */
3006 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; 1906 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
3007 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; 1907 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
3008 1908 /* scan handlers */
3009 priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; 1909 priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
3010 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; 1910 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
3011 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = 1911 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
3012 iwl4965_rx_scan_results_notif; 1912 iwl4965_rx_scan_results_notif;
3013 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = 1913 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
3014 iwl4965_rx_scan_complete_notif; 1914 iwl4965_rx_scan_complete_notif;
1915 /* status change handler */
3015 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; 1916 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
3016 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
3017 1917
1918 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1919 iwl_rx_missed_beacon_notif;
1920 /* Rx handlers */
1921 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
1922 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
3018 /* Set up hardware specific Rx handlers */ 1923 /* Set up hardware specific Rx handlers */
3019 priv->cfg->ops->lib->rx_handler_setup(priv); 1924 priv->cfg->ops->lib->rx_handler_setup(priv);
3020} 1925}
3021 1926
3022/**
3023 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3024 * @rxb: Rx buffer to reclaim
3025 *
3026 * If an Rx buffer has an async callback associated with it the callback
3027 * will be executed. The attached skb (if present) will only be freed
3028 * if the callback returns 1
3029 */
3030static void iwl4965_tx_cmd_complete(struct iwl_priv *priv,
3031 struct iwl_rx_mem_buffer *rxb)
3032{
3033 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
3034 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3035 int txq_id = SEQ_TO_QUEUE(sequence);
3036 int index = SEQ_TO_INDEX(sequence);
3037 int huge = sequence & SEQ_HUGE_FRAME;
3038 int cmd_index;
3039 struct iwl_cmd *cmd;
3040
3041 /* If a Tx command is being handled and it isn't in the actual
3042 * command queue then there a command routing bug has been introduced
3043 * in the queue management code. */
3044 if (txq_id != IWL_CMD_QUEUE_NUM)
3045 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3046 txq_id, pkt->hdr.cmd);
3047 BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
3048
3049 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
3050 cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
3051
3052 /* Input error checking is done when commands are added to queue. */
3053 if (cmd->meta.flags & CMD_WANT_SKB) {
3054 cmd->meta.source->u.skb = rxb->skb;
3055 rxb->skb = NULL;
3056 } else if (cmd->meta.u.callback &&
3057 !cmd->meta.u.callback(priv, cmd, rxb->skb))
3058 rxb->skb = NULL;
3059
3060 iwl4965_tx_queue_reclaim(priv, txq_id, index);
3061
3062 if (!(cmd->meta.flags & CMD_ASYNC)) {
3063 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
3064 wake_up_interruptible(&priv->wait_command_queue);
3065 }
3066}
3067
3068/* 1927/*
3069 * this should be called while priv->lock is locked 1928 * this should be called while priv->lock is locked
3070*/ 1929*/
@@ -3153,7 +2012,7 @@ void iwl_rx_handle(struct iwl_priv *priv)
3153 * fire off the (possibly) blocking iwl_send_cmd() 2012 * fire off the (possibly) blocking iwl_send_cmd()
3154 * as we reclaim the driver command queue */ 2013 * as we reclaim the driver command queue */
3155 if (rxb && rxb->skb) 2014 if (rxb && rxb->skb)
3156 iwl4965_tx_cmd_complete(priv, rxb); 2015 iwl_tx_cmd_complete(priv, rxb);
3157 else 2016 else
3158 IWL_WARNING("Claim null rxb?\n"); 2017 IWL_WARNING("Claim null rxb?\n");
3159 } 2018 }
@@ -3268,56 +2127,10 @@ int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
3268 return sig_qual; 2127 return sig_qual;
3269} 2128}
3270 2129
3271/**
3272 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
3273 */
3274static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
3275 struct iwl_tx_queue *txq)
3276{
3277 u32 reg = 0;
3278 int rc = 0;
3279 int txq_id = txq->q.id;
3280
3281 if (txq->need_update == 0)
3282 return rc;
3283
3284 /* if we're trying to save power */
3285 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
3286 /* wake up nic if it's powered down ...
3287 * uCode will wake up, and interrupt us again, so next
3288 * time we'll skip this part. */
3289 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
3290
3291 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
3292 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
3293 iwl_set_bit(priv, CSR_GP_CNTRL,
3294 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
3295 return rc;
3296 }
3297
3298 /* restore this queue's parameters in nic hardware. */
3299 rc = iwl_grab_nic_access(priv);
3300 if (rc)
3301 return rc;
3302 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
3303 txq->q.write_ptr | (txq_id << 8));
3304 iwl_release_nic_access(priv);
3305
3306 /* else not in power-save mode, uCode will never sleep when we're
3307 * trying to tx (during RFKILL, we're not trying to tx). */
3308 } else
3309 iwl_write32(priv, HBUS_TARG_WRPTR,
3310 txq->q.write_ptr | (txq_id << 8));
3311
3312 txq->need_update = 0;
3313
3314 return rc;
3315}
3316
3317#ifdef CONFIG_IWLWIFI_DEBUG 2130#ifdef CONFIG_IWLWIFI_DEBUG
3318static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv) 2131static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
3319{ 2132{
3320 struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; 2133 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
3321 DECLARE_MAC_BUF(mac); 2134 DECLARE_MAC_BUF(mac);
3322 2135
3323 IWL_DEBUG_RADIO("RX CONFIG:\n"); 2136 IWL_DEBUG_RADIO("RX CONFIG:\n");
@@ -3367,173 +2180,6 @@ static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
3367 IWL_DEBUG_ISR("Disabled interrupts\n"); 2180 IWL_DEBUG_ISR("Disabled interrupts\n");
3368} 2181}
3369 2182
3370static const char *desc_lookup(int i)
3371{
3372 switch (i) {
3373 case 1:
3374 return "FAIL";
3375 case 2:
3376 return "BAD_PARAM";
3377 case 3:
3378 return "BAD_CHECKSUM";
3379 case 4:
3380 return "NMI_INTERRUPT";
3381 case 5:
3382 return "SYSASSERT";
3383 case 6:
3384 return "FATAL_ERROR";
3385 }
3386
3387 return "UNKNOWN";
3388}
3389
3390#define ERROR_START_OFFSET (1 * sizeof(u32))
3391#define ERROR_ELEM_SIZE (7 * sizeof(u32))
3392
3393static void iwl4965_dump_nic_error_log(struct iwl_priv *priv)
3394{
3395 u32 data2, line;
3396 u32 desc, time, count, base, data1;
3397 u32 blink1, blink2, ilink1, ilink2;
3398 int rc;
3399
3400 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
3401
3402 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
3403 IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
3404 return;
3405 }
3406
3407 rc = iwl_grab_nic_access(priv);
3408 if (rc) {
3409 IWL_WARNING("Can not read from adapter at this time.\n");
3410 return;
3411 }
3412
3413 count = iwl_read_targ_mem(priv, base);
3414
3415 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
3416 IWL_ERROR("Start IWL Error Log Dump:\n");
3417 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count);
3418 }
3419
3420 desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
3421 blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
3422 blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
3423 ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
3424 ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
3425 data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
3426 data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
3427 line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
3428 time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
3429
3430 IWL_ERROR("Desc Time "
3431 "data1 data2 line\n");
3432 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
3433 desc_lookup(desc), desc, time, data1, data2, line);
3434 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
3435 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
3436 ilink1, ilink2);
3437
3438 iwl_release_nic_access(priv);
3439}
3440
3441#define EVENT_START_OFFSET (4 * sizeof(u32))
3442
3443/**
3444 * iwl4965_print_event_log - Dump error event log to syslog
3445 *
3446 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
3447 */
3448static void iwl4965_print_event_log(struct iwl_priv *priv, u32 start_idx,
3449 u32 num_events, u32 mode)
3450{
3451 u32 i;
3452 u32 base; /* SRAM byte address of event log header */
3453 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
3454 u32 ptr; /* SRAM byte address of log data */
3455 u32 ev, time, data; /* event log data */
3456
3457 if (num_events == 0)
3458 return;
3459
3460 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
3461
3462 if (mode == 0)
3463 event_size = 2 * sizeof(u32);
3464 else
3465 event_size = 3 * sizeof(u32);
3466
3467 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
3468
3469 /* "time" is actually "data" for mode 0 (no timestamp).
3470 * place event id # at far right for easier visual parsing. */
3471 for (i = 0; i < num_events; i++) {
3472 ev = iwl_read_targ_mem(priv, ptr);
3473 ptr += sizeof(u32);
3474 time = iwl_read_targ_mem(priv, ptr);
3475 ptr += sizeof(u32);
3476 if (mode == 0)
3477 IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
3478 else {
3479 data = iwl_read_targ_mem(priv, ptr);
3480 ptr += sizeof(u32);
3481 IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
3482 }
3483 }
3484}
3485
3486static void iwl4965_dump_nic_event_log(struct iwl_priv *priv)
3487{
3488 int rc;
3489 u32 base; /* SRAM byte address of event log header */
3490 u32 capacity; /* event log capacity in # entries */
3491 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
3492 u32 num_wraps; /* # times uCode wrapped to top of log */
3493 u32 next_entry; /* index of next entry to be written by uCode */
3494 u32 size; /* # entries that we'll print */
3495
3496 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
3497 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
3498 IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
3499 return;
3500 }
3501
3502 rc = iwl_grab_nic_access(priv);
3503 if (rc) {
3504 IWL_WARNING("Can not read from adapter at this time.\n");
3505 return;
3506 }
3507
3508 /* event log header */
3509 capacity = iwl_read_targ_mem(priv, base);
3510 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
3511 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
3512 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
3513
3514 size = num_wraps ? capacity : next_entry;
3515
3516 /* bail out if nothing in log */
3517 if (size == 0) {
3518 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
3519 iwl_release_nic_access(priv);
3520 return;
3521 }
3522
3523 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
3524 size, num_wraps);
3525
3526 /* if uCode has wrapped back to top of log, start at the oldest entry,
3527 * i.e the next one that uCode would fill. */
3528 if (num_wraps)
3529 iwl4965_print_event_log(priv, next_entry,
3530 capacity - next_entry, mode);
3531
3532 /* (then/else) start at top of log */
3533 iwl4965_print_event_log(priv, 0, next_entry, mode);
3534
3535 iwl_release_nic_access(priv);
3536}
3537 2183
3538/** 2184/**
3539 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card 2185 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
@@ -3548,8 +2194,8 @@ static void iwl4965_irq_handle_error(struct iwl_priv *priv)
3548 2194
3549#ifdef CONFIG_IWLWIFI_DEBUG 2195#ifdef CONFIG_IWLWIFI_DEBUG
3550 if (priv->debug_level & IWL_DL_FW_ERRORS) { 2196 if (priv->debug_level & IWL_DL_FW_ERRORS) {
3551 iwl4965_dump_nic_error_log(priv); 2197 iwl_dump_nic_error_log(priv);
3552 iwl4965_dump_nic_event_log(priv); 2198 iwl_dump_nic_event_log(priv);
3553 iwl4965_print_rx_config_cmd(priv); 2199 iwl4965_print_rx_config_cmd(priv);
3554 } 2200 }
3555#endif 2201#endif
@@ -3583,7 +2229,7 @@ static void iwl4965_error_recovery(struct iwl_priv *priv)
3583 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2229 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3584 iwl4965_commit_rxon(priv); 2230 iwl4965_commit_rxon(priv);
3585 2231
3586 iwl4965_rxon_add_station(priv, priv->bssid, 1); 2232 iwl_rxon_add_station(priv, priv->bssid, 1);
3587 2233
3588 spin_lock_irqsave(&priv->lock, flags); 2234 spin_lock_irqsave(&priv->lock, flags);
3589 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); 2235 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
@@ -3703,12 +2349,12 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
3703 if (inta & CSR_INT_BIT_WAKEUP) { 2349 if (inta & CSR_INT_BIT_WAKEUP) {
3704 IWL_DEBUG_ISR("Wakeup interrupt\n"); 2350 IWL_DEBUG_ISR("Wakeup interrupt\n");
3705 iwl_rx_queue_update_write_ptr(priv, &priv->rxq); 2351 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
3706 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]); 2352 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
3707 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]); 2353 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
3708 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]); 2354 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
3709 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]); 2355 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
3710 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]); 2356 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
3711 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]); 2357 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
3712 2358
3713 handled |= CSR_INT_BIT_WAKEUP; 2359 handled |= CSR_INT_BIT_WAKEUP;
3714 } 2360 }
@@ -3724,6 +2370,9 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
3724 if (inta & CSR_INT_BIT_FH_TX) { 2370 if (inta & CSR_INT_BIT_FH_TX) {
3725 IWL_DEBUG_ISR("Tx interrupt\n"); 2371 IWL_DEBUG_ISR("Tx interrupt\n");
3726 handled |= CSR_INT_BIT_FH_TX; 2372 handled |= CSR_INT_BIT_FH_TX;
2373 /* FH finished to write, send event */
2374 priv->ucode_write_complete = 1;
2375 wake_up_interruptible(&priv->wait_command_queue);
3727 } 2376 }
3728 2377
3729 if (inta & ~handled) 2378 if (inta & ~handled)
@@ -4162,11 +2811,11 @@ static int iwl4965_read_ucode(struct iwl_priv *priv)
4162} 2811}
4163 2812
4164/** 2813/**
4165 * iwl4965_alive_start - called after REPLY_ALIVE notification received 2814 * iwl_alive_start - called after REPLY_ALIVE notification received
4166 * from protocol/runtime uCode (initialization uCode's 2815 * from protocol/runtime uCode (initialization uCode's
4167 * Alive gets handled by iwl4965_init_alive_start()). 2816 * Alive gets handled by iwl_init_alive_start()).
4168 */ 2817 */
4169static void iwl4965_alive_start(struct iwl_priv *priv) 2818static void iwl_alive_start(struct iwl_priv *priv)
4170{ 2819{
4171 int ret = 0; 2820 int ret = 0;
4172 2821
@@ -4190,7 +2839,6 @@ static void iwl4965_alive_start(struct iwl_priv *priv)
4190 } 2839 }
4191 2840
4192 iwlcore_clear_stations_table(priv); 2841 iwlcore_clear_stations_table(priv);
4193
4194 ret = priv->cfg->ops->lib->alive_notify(priv); 2842 ret = priv->cfg->ops->lib->alive_notify(priv);
4195 if (ret) { 2843 if (ret) {
4196 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", 2844 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
@@ -4207,14 +2855,14 @@ static void iwl4965_alive_start(struct iwl_priv *priv)
4207 if (iwl_is_rfkill(priv)) 2855 if (iwl_is_rfkill(priv))
4208 return; 2856 return;
4209 2857
4210 ieee80211_start_queues(priv->hw); 2858 ieee80211_wake_queues(priv->hw);
4211 2859
4212 priv->active_rate = priv->rates_mask; 2860 priv->active_rate = priv->rates_mask;
4213 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; 2861 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
4214 2862
4215 if (iwl_is_associated(priv)) { 2863 if (iwl_is_associated(priv)) {
4216 struct iwl4965_rxon_cmd *active_rxon = 2864 struct iwl_rxon_cmd *active_rxon =
4217 (struct iwl4965_rxon_cmd *)(&priv->active_rxon); 2865 (struct iwl_rxon_cmd *)&priv->active_rxon;
4218 2866
4219 memcpy(&priv->staging_rxon, &priv->active_rxon, 2867 memcpy(&priv->staging_rxon, &priv->active_rxon,
4220 sizeof(priv->staging_rxon)); 2868 sizeof(priv->staging_rxon));
@@ -4228,12 +2876,12 @@ static void iwl4965_alive_start(struct iwl_priv *priv)
4228 /* Configure Bluetooth device coexistence support */ 2876 /* Configure Bluetooth device coexistence support */
4229 iwl4965_send_bt_config(priv); 2877 iwl4965_send_bt_config(priv);
4230 2878
2879 iwl_reset_run_time_calib(priv);
2880
4231 /* Configure the adapter for unassociated operation */ 2881 /* Configure the adapter for unassociated operation */
4232 iwl4965_commit_rxon(priv); 2882 iwl4965_commit_rxon(priv);
4233 2883
4234 /* At this point, the NIC is initialized and operational */ 2884 /* At this point, the NIC is initialized and operational */
4235 priv->notif_missed_beacons = 0;
4236
4237 iwl4965_rf_kill_ct_config(priv); 2885 iwl4965_rf_kill_ct_config(priv);
4238 2886
4239 iwl_leds_register(priv); 2887 iwl_leds_register(priv);
@@ -4259,12 +2907,9 @@ static void __iwl4965_down(struct iwl_priv *priv)
4259{ 2907{
4260 unsigned long flags; 2908 unsigned long flags;
4261 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); 2909 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
4262 struct ieee80211_conf *conf = NULL;
4263 2910
4264 IWL_DEBUG_INFO(DRV_NAME " is going down\n"); 2911 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
4265 2912
4266 conf = ieee80211_get_hw_conf(priv->hw);
4267
4268 if (!exit_pending) 2913 if (!exit_pending)
4269 set_bit(STATUS_EXIT_PENDING, &priv->status); 2914 set_bit(STATUS_EXIT_PENDING, &priv->status);
4270 2915
@@ -4326,8 +2971,8 @@ static void __iwl4965_down(struct iwl_priv *priv)
4326 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); 2971 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4327 spin_unlock_irqrestore(&priv->lock, flags); 2972 spin_unlock_irqrestore(&priv->lock, flags);
4328 2973
4329 iwl4965_hw_txq_ctx_stop(priv); 2974 iwl_txq_ctx_stop(priv);
4330 iwl4965_hw_rxq_stop(priv); 2975 iwl_rxq_stop(priv);
4331 2976
4332 spin_lock_irqsave(&priv->lock, flags); 2977 spin_lock_irqsave(&priv->lock, flags);
4333 if (!iwl_grab_nic_access(priv)) { 2978 if (!iwl_grab_nic_access(priv)) {
@@ -4339,20 +2984,19 @@ static void __iwl4965_down(struct iwl_priv *priv)
4339 2984
4340 udelay(5); 2985 udelay(5);
4341 2986
4342 iwl4965_hw_nic_stop_master(priv); 2987 /* FIXME: apm_ops.suspend(priv) */
4343 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); 2988 priv->cfg->ops->lib->apm_ops.reset(priv);
4344 iwl4965_hw_nic_reset(priv);
4345 priv->cfg->ops->lib->free_shared_mem(priv); 2989 priv->cfg->ops->lib->free_shared_mem(priv);
4346 2990
4347 exit: 2991 exit:
4348 memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); 2992 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
4349 2993
4350 if (priv->ibss_beacon) 2994 if (priv->ibss_beacon)
4351 dev_kfree_skb(priv->ibss_beacon); 2995 dev_kfree_skb(priv->ibss_beacon);
4352 priv->ibss_beacon = NULL; 2996 priv->ibss_beacon = NULL;
4353 2997
4354 /* clear out any free frames */ 2998 /* clear out any free frames */
4355 iwl4965_clear_free_frames(priv); 2999 iwl_clear_free_frames(priv);
4356} 3000}
4357 3001
4358static void iwl4965_down(struct iwl_priv *priv) 3002static void iwl4965_down(struct iwl_priv *priv)
@@ -4477,7 +3121,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
4477 * 3121 *
4478 *****************************************************************************/ 3122 *****************************************************************************/
4479 3123
4480static void iwl4965_bg_init_alive_start(struct work_struct *data) 3124static void iwl_bg_init_alive_start(struct work_struct *data)
4481{ 3125{
4482 struct iwl_priv *priv = 3126 struct iwl_priv *priv =
4483 container_of(data, struct iwl_priv, init_alive_start.work); 3127 container_of(data, struct iwl_priv, init_alive_start.work);
@@ -4490,7 +3134,7 @@ static void iwl4965_bg_init_alive_start(struct work_struct *data)
4490 mutex_unlock(&priv->mutex); 3134 mutex_unlock(&priv->mutex);
4491} 3135}
4492 3136
4493static void iwl4965_bg_alive_start(struct work_struct *data) 3137static void iwl_bg_alive_start(struct work_struct *data)
4494{ 3138{
4495 struct iwl_priv *priv = 3139 struct iwl_priv *priv =
4496 container_of(data, struct iwl_priv, alive_start.work); 3140 container_of(data, struct iwl_priv, alive_start.work);
@@ -4499,7 +3143,7 @@ static void iwl4965_bg_alive_start(struct work_struct *data)
4499 return; 3143 return;
4500 3144
4501 mutex_lock(&priv->mutex); 3145 mutex_lock(&priv->mutex);
4502 iwl4965_alive_start(priv); 3146 iwl_alive_start(priv);
4503 mutex_unlock(&priv->mutex); 3147 mutex_unlock(&priv->mutex);
4504} 3148}
4505 3149
@@ -4909,8 +3553,8 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
4909 /* clear out the station table */ 3553 /* clear out the station table */
4910 iwlcore_clear_stations_table(priv); 3554 iwlcore_clear_stations_table(priv);
4911 3555
4912 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); 3556 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
4913 iwl4965_rxon_add_station(priv, priv->bssid, 0); 3557 iwl_rxon_add_station(priv, priv->bssid, 0);
4914 iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); 3558 iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
4915 iwl4965_send_beacon_cmd(priv); 3559 iwl4965_send_beacon_cmd(priv);
4916 3560
@@ -5021,7 +3665,7 @@ static int iwl4965_mac_start(struct ieee80211_hw *hw)
5021 /* we should be verifying the device is ready to be opened */ 3665 /* we should be verifying the device is ready to be opened */
5022 mutex_lock(&priv->mutex); 3666 mutex_lock(&priv->mutex);
5023 3667
5024 memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd)); 3668 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
5025 /* fetch ucode file from disk, alloc and copy to bus-master buffers ... 3669 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
5026 * ucode filename and max sizes are card-specific. */ 3670 * ucode filename and max sizes are card-specific. */
5027 3671
@@ -5046,21 +3690,23 @@ static int iwl4965_mac_start(struct ieee80211_hw *hw)
5046 if (test_bit(STATUS_IN_SUSPEND, &priv->status)) 3690 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
5047 return 0; 3691 return 0;
5048 3692
5049 /* Wait for START_ALIVE from ucode. Otherwise callbacks from 3693 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
5050 * mac80211 will not be run successfully. */ 3694 * mac80211 will not be run successfully. */
5051 ret = wait_event_interruptible_timeout(priv->wait_command_queue, 3695 if (priv->ucode_type == UCODE_RT) {
5052 test_bit(STATUS_READY, &priv->status), 3696 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
5053 UCODE_READY_TIMEOUT); 3697 test_bit(STATUS_READY, &priv->status),
5054 if (!ret) { 3698 UCODE_READY_TIMEOUT);
5055 if (!test_bit(STATUS_READY, &priv->status)) { 3699 if (!ret) {
5056 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", 3700 if (!test_bit(STATUS_READY, &priv->status)) {
5057 jiffies_to_msecs(UCODE_READY_TIMEOUT)); 3701 IWL_ERROR("START_ALIVE timeout after %dms.\n",
5058 ret = -ETIMEDOUT; 3702 jiffies_to_msecs(UCODE_READY_TIMEOUT));
5059 goto out_release_irq; 3703 ret = -ETIMEDOUT;
3704 goto out_release_irq;
3705 }
5060 } 3706 }
5061 }
5062 3707
5063 priv->is_open = 1; 3708 priv->is_open = 1;
3709 }
5064 IWL_DEBUG_MAC80211("leave\n"); 3710 IWL_DEBUG_MAC80211("leave\n");
5065 return 0; 3711 return 0;
5066 3712
@@ -5108,8 +3754,7 @@ static void iwl4965_mac_stop(struct ieee80211_hw *hw)
5108 IWL_DEBUG_MAC80211("leave\n"); 3754 IWL_DEBUG_MAC80211("leave\n");
5109} 3755}
5110 3756
5111static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, 3757static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
5112 struct ieee80211_tx_control *ctl)
5113{ 3758{
5114 struct iwl_priv *priv = hw->priv; 3759 struct iwl_priv *priv = hw->priv;
5115 3760
@@ -5121,9 +3766,9 @@ static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
5121 } 3766 }
5122 3767
5123 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, 3768 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
5124 ctl->tx_rate->bitrate); 3769 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
5125 3770
5126 if (iwl4965_tx_skb(priv, skb, ctl)) 3771 if (iwl_tx_skb(priv, skb))
5127 dev_kfree_skb_any(skb); 3772 dev_kfree_skb_any(skb);
5128 3773
5129 IWL_DEBUG_MAC80211("leave\n"); 3774 IWL_DEBUG_MAC80211("leave\n");
@@ -5178,6 +3823,7 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
5178 const struct iwl_channel_info *ch_info; 3823 const struct iwl_channel_info *ch_info;
5179 unsigned long flags; 3824 unsigned long flags;
5180 int ret = 0; 3825 int ret = 0;
3826 u16 channel;
5181 3827
5182 mutex_lock(&priv->mutex); 3828 mutex_lock(&priv->mutex);
5183 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); 3829 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
@@ -5198,22 +3844,21 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
5198 return 0; 3844 return 0;
5199 } 3845 }
5200 3846
5201 spin_lock_irqsave(&priv->lock, flags); 3847 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
5202 3848 ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
5203 ch_info = iwl_get_channel_info(priv, conf->channel->band,
5204 ieee80211_frequency_to_channel(conf->channel->center_freq));
5205 if (!is_channel_valid(ch_info)) { 3849 if (!is_channel_valid(ch_info)) {
5206 IWL_DEBUG_MAC80211("leave - invalid channel\n"); 3850 IWL_DEBUG_MAC80211("leave - invalid channel\n");
5207 spin_unlock_irqrestore(&priv->lock, flags);
5208 ret = -EINVAL; 3851 ret = -EINVAL;
5209 goto out; 3852 goto out;
5210 } 3853 }
5211 3854
3855 spin_lock_irqsave(&priv->lock, flags);
3856
5212#ifdef CONFIG_IWL4965_HT 3857#ifdef CONFIG_IWL4965_HT
5213 /* if we are switching from ht to 2.4 clear flags 3858 /* if we are switching from ht to 2.4 clear flags
5214 * from any ht related info since 2.4 does not 3859 * from any ht related info since 2.4 does not
5215 * support ht */ 3860 * support ht */
5216 if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) 3861 if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
5217#ifdef IEEE80211_CONF_CHANNEL_SWITCH 3862#ifdef IEEE80211_CONF_CHANNEL_SWITCH
5218 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) 3863 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
5219#endif 3864#endif
@@ -5221,10 +3866,9 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
5221 priv->staging_rxon.flags = 0; 3866 priv->staging_rxon.flags = 0;
5222#endif /* CONFIG_IWL4965_HT */ 3867#endif /* CONFIG_IWL4965_HT */
5223 3868
5224 iwl_set_rxon_channel(priv, conf->channel->band, 3869 iwl_set_rxon_channel(priv, conf->channel->band, channel);
5225 ieee80211_frequency_to_channel(conf->channel->center_freq));
5226 3870
5227 iwl4965_set_flags_for_phymode(priv, conf->channel->band); 3871 iwl_set_flags_for_band(priv, conf->channel->band);
5228 3872
5229 /* The list of supported rates and rate mask can be different 3873 /* The list of supported rates and rate mask can be different
5230 * for each band; since the band may have changed, reset 3874 * for each band; since the band may have changed, reset
@@ -5321,7 +3965,7 @@ static void iwl4965_config_ap(struct iwl_priv *priv)
5321 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 3965 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
5322 iwl4965_commit_rxon(priv); 3966 iwl4965_commit_rxon(priv);
5323 iwl4965_activate_qos(priv, 1); 3967 iwl4965_activate_qos(priv, 1);
5324 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); 3968 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
5325 } 3969 }
5326 iwl4965_send_beacon_cmd(priv); 3970 iwl4965_send_beacon_cmd(priv);
5327 3971
@@ -5410,7 +4054,7 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
5410 else { 4054 else {
5411 rc = iwl4965_commit_rxon(priv); 4055 rc = iwl4965_commit_rxon(priv);
5412 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) 4056 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
5413 iwl4965_rxon_add_station( 4057 iwl_rxon_add_station(
5414 priv, priv->active_rxon.bssid_addr, 1); 4058 priv, priv->active_rxon.bssid_addr, 1);
5415 } 4059 }
5416 4060
@@ -5697,7 +4341,8 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5697 if (cmd == SET_KEY) 4341 if (cmd == SET_KEY)
5698 is_default_wep_key = !priv->key_mapping_key; 4342 is_default_wep_key = !priv->key_mapping_key;
5699 else 4343 else
5700 is_default_wep_key = priv->default_wep_key; 4344 is_default_wep_key =
4345 (key->hw_key_idx == HW_KEY_DEFAULT);
5701 } 4346 }
5702 4347
5703 switch (cmd) { 4348 switch (cmd) {
@@ -5783,7 +4428,7 @@ static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
5783 struct iwl_priv *priv = hw->priv; 4428 struct iwl_priv *priv = hw->priv;
5784 int i, avail; 4429 int i, avail;
5785 struct iwl_tx_queue *txq; 4430 struct iwl_tx_queue *txq;
5786 struct iwl4965_queue *q; 4431 struct iwl_queue *q;
5787 unsigned long flags; 4432 unsigned long flags;
5788 4433
5789 IWL_DEBUG_MAC80211("enter\n"); 4434 IWL_DEBUG_MAC80211("enter\n");
@@ -5798,7 +4443,7 @@ static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
5798 for (i = 0; i < AC_NUM; i++) { 4443 for (i = 0; i < AC_NUM; i++) {
5799 txq = &priv->txq[i]; 4444 txq = &priv->txq[i];
5800 q = &txq->q; 4445 q = &txq->q;
5801 avail = iwl4965_queue_space(q); 4446 avail = iwl_queue_space(q);
5802 4447
5803 stats[i].len = q->n_window - avail; 4448 stats[i].len = q->n_window - avail;
5804 stats[i].limit = q->n_window - q->high_mark; 4449 stats[i].limit = q->n_window - q->high_mark;
@@ -5904,8 +4549,7 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
5904 IWL_DEBUG_MAC80211("leave\n"); 4549 IWL_DEBUG_MAC80211("leave\n");
5905} 4550}
5906 4551
5907static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, 4552static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
5908 struct ieee80211_tx_control *control)
5909{ 4553{
5910 struct iwl_priv *priv = hw->priv; 4554 struct iwl_priv *priv = hw->priv;
5911 unsigned long flags; 4555 unsigned long flags;
@@ -5998,7 +4642,7 @@ static ssize_t show_version(struct device *d,
5998 struct device_attribute *attr, char *buf) 4642 struct device_attribute *attr, char *buf)
5999{ 4643{
6000 struct iwl_priv *priv = d->driver_data; 4644 struct iwl_priv *priv = d->driver_data;
6001 struct iwl4965_alive_resp *palive = &priv->card_alive; 4645 struct iwl_alive_resp *palive = &priv->card_alive;
6002 4646
6003 if (palive->is_valid) 4647 if (palive->is_valid)
6004 return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n" 4648 return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
@@ -6368,34 +5012,6 @@ static ssize_t show_status(struct device *d,
6368 5012
6369static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); 5013static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
6370 5014
6371static ssize_t dump_error_log(struct device *d,
6372 struct device_attribute *attr,
6373 const char *buf, size_t count)
6374{
6375 char *p = (char *)buf;
6376
6377 if (p[0] == '1')
6378 iwl4965_dump_nic_error_log((struct iwl_priv *)d->driver_data);
6379
6380 return strnlen(buf, count);
6381}
6382
6383static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
6384
6385static ssize_t dump_event_log(struct device *d,
6386 struct device_attribute *attr,
6387 const char *buf, size_t count)
6388{
6389 char *p = (char *)buf;
6390
6391 if (p[0] == '1')
6392 iwl4965_dump_nic_event_log((struct iwl_priv *)d->driver_data);
6393
6394 return strnlen(buf, count);
6395}
6396
6397static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
6398
6399/***************************************************************************** 5015/*****************************************************************************
6400 * 5016 *
6401 * driver setup and teardown 5017 * driver setup and teardown
@@ -6418,8 +5034,8 @@ static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
6418 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); 5034 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
6419 INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor); 5035 INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
6420 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); 5036 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
6421 INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); 5037 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
6422 INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); 5038 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
6423 INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); 5039 INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
6424 5040
6425 iwl4965_hw_setup_deferred_work(priv); 5041 iwl4965_hw_setup_deferred_work(priv);
@@ -6441,8 +5057,6 @@ static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
6441 5057
6442static struct attribute *iwl4965_sysfs_entries[] = { 5058static struct attribute *iwl4965_sysfs_entries[] = {
6443 &dev_attr_channels.attr, 5059 &dev_attr_channels.attr,
6444 &dev_attr_dump_errors.attr,
6445 &dev_attr_dump_events.attr,
6446 &dev_attr_flags.attr, 5060 &dev_attr_flags.attr,
6447 &dev_attr_filter_flags.attr, 5061 &dev_attr_filter_flags.attr,
6448#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT 5062#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
@@ -6605,7 +5219,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
6605 if (err) 5219 if (err)
6606 goto out_iounmap; 5220 goto out_iounmap;
6607 5221
6608 /* MAC Address location in EEPROM same for 3945/4965 */ 5222 /* extract MAC Address */
6609 iwl_eeprom_get_mac(priv, priv->mac_addr); 5223 iwl_eeprom_get_mac(priv, priv->mac_addr);
6610 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); 5224 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
6611 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); 5225 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
@@ -6620,10 +5234,10 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
6620 } 5234 }
6621 5235
6622 /******************* 5236 /*******************
6623 * 6. Setup hw/priv 5237 * 6. Setup priv
6624 *******************/ 5238 *******************/
6625 5239
6626 err = iwl_setup(priv); 5240 err = iwl_init_drv(priv);
6627 if (err) 5241 if (err)
6628 goto out_free_eeprom; 5242 goto out_free_eeprom;
6629 /* At this point both hw and priv are initialized. */ 5243 /* At this point both hw and priv are initialized. */
@@ -6638,9 +5252,6 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
6638 IWL_DEBUG_INFO("Radio disabled.\n"); 5252 IWL_DEBUG_INFO("Radio disabled.\n");
6639 } 5253 }
6640 5254
6641 if (priv->cfg->mod_params->enable_qos)
6642 priv->qos_data.qos_enable = 1;
6643
6644 /******************** 5255 /********************
6645 * 8. Setup services 5256 * 8. Setup services
6646 ********************/ 5257 ********************/
@@ -6651,14 +5262,9 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
6651 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); 5262 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
6652 if (err) { 5263 if (err) {
6653 IWL_ERROR("failed to create sysfs device attributes\n"); 5264 IWL_ERROR("failed to create sysfs device attributes\n");
6654 goto out_free_eeprom; 5265 goto out_uninit_drv;
6655 } 5266 }
6656 5267
6657 err = iwl_dbgfs_register(priv, DRV_NAME);
6658 if (err) {
6659 IWL_ERROR("failed to create debugfs files\n");
6660 goto out_remove_sysfs;
6661 }
6662 5268
6663 iwl4965_setup_deferred_work(priv); 5269 iwl4965_setup_deferred_work(priv);
6664 iwl4965_setup_rx_handlers(priv); 5270 iwl4965_setup_rx_handlers(priv);
@@ -6669,12 +5275,26 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
6669 pci_save_state(pdev); 5275 pci_save_state(pdev);
6670 pci_disable_device(pdev); 5276 pci_disable_device(pdev);
6671 5277
5278 /**********************************
5279 * 10. Setup and register mac80211
5280 **********************************/
5281
5282 err = iwl_setup_mac(priv);
5283 if (err)
5284 goto out_remove_sysfs;
5285
5286 err = iwl_dbgfs_register(priv, DRV_NAME);
5287 if (err)
5288 IWL_ERROR("failed to create debugfs files\n");
5289
6672 /* notify iwlcore to init */ 5290 /* notify iwlcore to init */
6673 iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT); 5291 iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT);
6674 return 0; 5292 return 0;
6675 5293
6676 out_remove_sysfs: 5294 out_remove_sysfs:
6677 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); 5295 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
5296 out_uninit_drv:
5297 iwl_uninit_drv(priv);
6678 out_free_eeprom: 5298 out_free_eeprom:
6679 iwl_eeprom_free(priv); 5299 iwl_eeprom_free(priv);
6680 out_iounmap: 5300 out_iounmap:
@@ -6702,6 +5322,9 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
6702 5322
6703 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); 5323 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
6704 5324
5325 iwl_dbgfs_unregister(priv);
5326 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
5327
6705 if (priv->mac80211_registered) { 5328 if (priv->mac80211_registered) {
6706 ieee80211_unregister_hw(priv->hw); 5329 ieee80211_unregister_hw(priv->hw);
6707 priv->mac80211_registered = 0; 5330 priv->mac80211_registered = 0;
@@ -6729,8 +5352,6 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
6729 } 5352 }
6730 5353
6731 iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT); 5354 iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT);
6732 iwl_dbgfs_unregister(priv);
6733 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
6734 5355
6735 iwl4965_dealloc_ucode_pci(priv); 5356 iwl4965_dealloc_ucode_pci(priv);
6736 5357
@@ -6756,8 +5377,7 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
6756 pci_disable_device(pdev); 5377 pci_disable_device(pdev);
6757 pci_set_drvdata(pdev, NULL); 5378 pci_set_drvdata(pdev, NULL);
6758 5379
6759 iwl_free_channel_map(priv); 5380 iwl_uninit_drv(priv);
6760 iwlcore_free_geos(priv);
6761 5381
6762 if (priv->ibss_beacon) 5382 if (priv->ibss_beacon)
6763 dev_kfree_skb(priv->ibss_beacon); 5383 dev_kfree_skb(priv->ibss_beacon);
@@ -6848,10 +5468,6 @@ static int __init iwl4965_init(void)
6848 5468
6849 return ret; 5469 return ret;
6850 5470
6851
6852#ifdef CONFIG_IWLWIFI_DEBUG
6853 pci_unregister_driver(&iwl_driver);
6854#endif
6855error_register: 5471error_register:
6856 iwl4965_rate_control_unregister(); 5472 iwl4965_rate_control_unregister();
6857 return ret; 5473 return ret;