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/Kconfig5
-rw-r--r--drivers/net/wireless/iwlwifi/Makefile1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-led.c66
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c16
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c412
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.h13
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c95
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000-hw.h12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c175
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c593
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.h27
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c1273
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-calib.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h35
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c1189
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h107
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-csr.h22
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debug.h3
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debugfs.c193
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h69
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.c153
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.h4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-io.h253
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-led.c4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-power.c233
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-power.h39
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rfkill.c145
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rfkill.h48
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rx.c70
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-scan.c214
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c47
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.h7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c29
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c1451
34 files changed, 3301 insertions, 3704 deletions
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig
index 736162324ba4..e092af09d6bf 100644
--- a/drivers/net/wireless/iwlwifi/Kconfig
+++ b/drivers/net/wireless/iwlwifi/Kconfig
@@ -5,16 +5,11 @@ config IWLWIFI
5 select FW_LOADER 5 select FW_LOADER
6 select MAC80211_LEDS if IWLWIFI_LEDS 6 select MAC80211_LEDS if IWLWIFI_LEDS
7 select LEDS_CLASS if IWLWIFI_LEDS 7 select LEDS_CLASS if IWLWIFI_LEDS
8 select RFKILL if IWLWIFI_RFKILL
9 8
10config IWLWIFI_LEDS 9config IWLWIFI_LEDS
11 bool "Enable LED support in iwlagn and iwl3945 drivers" 10 bool "Enable LED support in iwlagn and iwl3945 drivers"
12 depends on IWLWIFI 11 depends on IWLWIFI
13 12
14config IWLWIFI_RFKILL
15 bool "Enable RF kill support in iwlagn and iwl3945 drivers"
16 depends on IWLWIFI
17
18config IWLWIFI_SPECTRUM_MEASUREMENT 13config IWLWIFI_SPECTRUM_MEASUREMENT
19 bool "Enable Spectrum Measurement in iwlagn driver" 14 bool "Enable Spectrum Measurement in iwlagn driver"
20 depends on IWLWIFI 15 depends on IWLWIFI
diff --git a/drivers/net/wireless/iwlwifi/Makefile b/drivers/net/wireless/iwlwifi/Makefile
index d79d97ad61a5..1d4e0a226fd4 100644
--- a/drivers/net/wireless/iwlwifi/Makefile
+++ b/drivers/net/wireless/iwlwifi/Makefile
@@ -4,7 +4,6 @@ iwlcore-objs += iwl-rx.o iwl-tx.o iwl-sta.o iwl-calib.o
4iwlcore-objs += iwl-scan.o 4iwlcore-objs += iwl-scan.o
5iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o 5iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o
6iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o 6iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o
7iwlcore-$(CONFIG_IWLWIFI_RFKILL) += iwl-rfkill.o
8iwlcore-$(CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT) += iwl-spectrum.o 7iwlcore-$(CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT) += iwl-spectrum.o
9 8
10obj-$(CONFIG_IWLAGN) += iwlagn.o 9obj-$(CONFIG_IWLAGN) += iwlagn.o
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-led.c b/drivers/net/wireless/iwlwifi/iwl-3945-led.c
index ac22f59be9ef..225e5f889346 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-led.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-led.c
@@ -44,6 +44,15 @@
44#include "iwl-core.h" 44#include "iwl-core.h"
45#include "iwl-dev.h" 45#include "iwl-dev.h"
46 46
47#ifdef CONFIG_IWLWIFI_DEBUG
48static const char *led_type_str[] = {
49 __stringify(IWL_LED_TRG_TX),
50 __stringify(IWL_LED_TRG_RX),
51 __stringify(IWL_LED_TRG_ASSOC),
52 __stringify(IWL_LED_TRG_RADIO),
53 NULL
54};
55#endif /* CONFIG_IWLWIFI_DEBUG */
47 56
48static const struct { 57static const struct {
49 u16 brightness; 58 u16 brightness;
@@ -61,7 +70,7 @@ static const struct {
61 {10, 110, 110}, 70 {10, 110, 110},
62 {5, 130, 130}, 71 {5, 130, 130},
63 {0, 167, 167}, 72 {0, 167, 167},
64 /*SOLID_ON*/ 73 /* SOLID_ON */
65 {-1, IWL_LED_SOLID, 0} 74 {-1, IWL_LED_SOLID, 0}
66}; 75};
67 76
@@ -143,6 +152,26 @@ static int iwl3945_led_off(struct iwl_priv *priv, int led_id)
143} 152}
144 153
145/* 154/*
155 * Set led on in case of association
156 * */
157static int iwl3945_led_associate(struct iwl_priv *priv, int led_id)
158{
159 IWL_DEBUG_LED(priv, "Associated\n");
160
161 priv->allow_blinking = 1;
162 return iwl3945_led_on(priv, led_id);
163}
164/* Set Led off in case of disassociation */
165static int iwl3945_led_disassociate(struct iwl_priv *priv, int led_id)
166{
167 IWL_DEBUG_LED(priv, "Disassociated\n");
168
169 priv->allow_blinking = 0;
170
171 return 0;
172}
173
174/*
146 * brightness call back function for Tx/Rx LED 175 * brightness call back function for Tx/Rx LED
147 */ 176 */
148static int iwl3945_led_associated(struct iwl_priv *priv, int led_id) 177static int iwl3945_led_associated(struct iwl_priv *priv, int led_id)
@@ -165,26 +194,21 @@ static void iwl3945_led_brightness_set(struct led_classdev *led_cdev,
165 enum led_brightness brightness) 194 enum led_brightness brightness)
166{ 195{
167 struct iwl_led *led = container_of(led_cdev, 196 struct iwl_led *led = container_of(led_cdev,
168 struct iwl_led, led_dev); 197 struct iwl_led, led_dev);
169 struct iwl_priv *priv = led->priv; 198 struct iwl_priv *priv = led->priv;
170 199
171 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 200 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
172 return; 201 return;
173 202
203 IWL_DEBUG_LED(priv, "Led type = %s brightness = %d\n",
204 led_type_str[led->type], brightness);
205
174 switch (brightness) { 206 switch (brightness) {
175 case LED_FULL: 207 case LED_FULL:
176 if (led->type == IWL_LED_TRG_ASSOC) {
177 priv->allow_blinking = 1;
178 IWL_DEBUG_LED(priv, "MAC is associated\n");
179 }
180 if (led->led_on) 208 if (led->led_on)
181 led->led_on(priv, IWL_LED_LINK); 209 led->led_on(priv, IWL_LED_LINK);
182 break; 210 break;
183 case LED_OFF: 211 case LED_OFF:
184 if (led->type == IWL_LED_TRG_ASSOC) {
185 priv->allow_blinking = 0;
186 IWL_DEBUG_LED(priv, "MAC is disassociated\n");
187 }
188 if (led->led_off) 212 if (led->led_off)
189 led->led_off(priv, IWL_LED_LINK); 213 led->led_off(priv, IWL_LED_LINK);
190 break; 214 break;
@@ -197,8 +221,6 @@ static void iwl3945_led_brightness_set(struct led_classdev *led_cdev,
197 } 221 }
198} 222}
199 223
200
201
202/* 224/*
203 * Register led class with the system 225 * Register led class with the system
204 */ 226 */
@@ -237,12 +259,12 @@ static int iwl3945_led_register_led(struct iwl_priv *priv,
237static inline u8 get_blink_rate(struct iwl_priv *priv) 259static inline u8 get_blink_rate(struct iwl_priv *priv)
238{ 260{
239 int index; 261 int index;
240 u64 current_tpt = priv->rxtxpackets; 262 s64 tpt = priv->rxtxpackets;
241 s64 tpt = current_tpt - priv->led_tpt;
242 263
243 if (tpt < 0) 264 if (tpt < 0)
244 tpt = -tpt; 265 tpt = -tpt;
245 priv->led_tpt = current_tpt; 266
267 IWL_DEBUG_LED(priv, "tpt %lld \n", (long long)tpt);
246 268
247 if (!priv->allow_blinking) 269 if (!priv->allow_blinking)
248 index = IWL_MAX_BLINK_TBL; 270 index = IWL_MAX_BLINK_TBL;
@@ -250,13 +272,9 @@ static inline u8 get_blink_rate(struct iwl_priv *priv)
250 for (index = 0; index < IWL_MAX_BLINK_TBL; index++) 272 for (index = 0; index < IWL_MAX_BLINK_TBL; index++)
251 if (tpt > (blink_tbl[index].brightness * IWL_1MB_RATE)) 273 if (tpt > (blink_tbl[index].brightness * IWL_1MB_RATE))
252 break; 274 break;
253 return index;
254}
255 275
256static inline int is_rf_kill(struct iwl_priv *priv) 276 IWL_DEBUG_LED(priv, "LED BLINK IDX=%d\n", index);
257{ 277 return index;
258 return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
259 test_bit(STATUS_RF_KILL_SW, &priv->status);
260} 278}
261 279
262/* 280/*
@@ -272,7 +290,7 @@ void iwl3945_led_background(struct iwl_priv *priv)
272 priv->last_blink_time = 0; 290 priv->last_blink_time = 0;
273 return; 291 return;
274 } 292 }
275 if (is_rf_kill(priv)) { 293 if (iwl_is_rfkill(priv)) {
276 priv->last_blink_time = 0; 294 priv->last_blink_time = 0;
277 return; 295 return;
278 } 296 }
@@ -341,8 +359,8 @@ int iwl3945_led_register(struct iwl_priv *priv)
341 IWL_LED_TRG_ASSOC, 0, trigger); 359 IWL_LED_TRG_ASSOC, 0, trigger);
342 360
343 /* for assoc always turn led on */ 361 /* for assoc always turn led on */
344 priv->led[IWL_LED_TRG_ASSOC].led_on = iwl3945_led_on; 362 priv->led[IWL_LED_TRG_ASSOC].led_on = iwl3945_led_associate;
345 priv->led[IWL_LED_TRG_ASSOC].led_off = iwl3945_led_on; 363 priv->led[IWL_LED_TRG_ASSOC].led_off = iwl3945_led_disassociate;
346 priv->led[IWL_LED_TRG_ASSOC].led_pattern = NULL; 364 priv->led[IWL_LED_TRG_ASSOC].led_pattern = NULL;
347 365
348 if (ret) 366 if (ret)
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index af6b9d444778..5eb538d18a80 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -38,6 +38,7 @@
38 38
39#include "iwl-commands.h" 39#include "iwl-commands.h"
40#include "iwl-3945.h" 40#include "iwl-3945.h"
41#include "iwl-sta.h"
41 42
42#define RS_NAME "iwl-3945-rs" 43#define RS_NAME "iwl-3945-rs"
43 44
@@ -683,11 +684,10 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
683 if (sta) 684 if (sta)
684 rate_mask = sta->supp_rates[sband->band]; 685 rate_mask = sta->supp_rates[sband->band];
685 686
686 /* Send management frames and broadcast/multicast data using lowest 687 /* Send management frames and NO_ACK data using lowest rate. */
687 * rate. */
688 fc = le16_to_cpu(hdr->frame_control); 688 fc = le16_to_cpu(hdr->frame_control);
689 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || 689 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
690 is_multicast_ether_addr(hdr->addr1) || 690 info->flags & IEEE80211_TX_CTL_NO_ACK ||
691 !sta || !priv_sta) { 691 !sta || !priv_sta) {
692 IWL_DEBUG_RATE(priv, "leave: No STA priv data to update!\n"); 692 IWL_DEBUG_RATE(priv, "leave: No STA priv data to update!\n");
693 if (!rate_mask) 693 if (!rate_mask)
@@ -696,6 +696,8 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
696 else 696 else
697 info->control.rates[0].idx = 697 info->control.rates[0].idx =
698 rate_lowest_index(sband, sta); 698 rate_lowest_index(sband, sta);
699 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
700 info->control.rates[0].count = 1;
699 return; 701 return;
700 } 702 }
701 703
@@ -713,13 +715,13 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
713 715
714 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) && 716 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
715 !rs_sta->ibss_sta_added) { 717 !rs_sta->ibss_sta_added) {
716 u8 sta_id = iwl3945_hw_find_station(priv, hdr->addr1); 718 u8 sta_id = iwl_find_station(priv, hdr->addr1);
717 719
718 if (sta_id == IWL_INVALID_STATION) { 720 if (sta_id == IWL_INVALID_STATION) {
719 IWL_DEBUG_RATE(priv, "LQ: ADD station %pm\n", 721 IWL_DEBUG_RATE(priv, "LQ: ADD station %pm\n",
720 hdr->addr1); 722 hdr->addr1);
721 sta_id = iwl3945_add_station(priv, 723 sta_id = iwl_add_station(priv, hdr->addr1, false,
722 hdr->addr1, 0, CMD_ASYNC); 724 CMD_ASYNC, NULL);
723 } 725 }
724 if (sta_id != IWL_INVALID_STATION) 726 if (sta_id != IWL_INVALID_STATION)
725 rs_sta->ibss_sta_added = 1; 727 rs_sta->ibss_sta_added = 1;
@@ -974,7 +976,7 @@ void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
974 976
975 rcu_read_lock(); 977 rcu_read_lock();
976 978
977 sta = ieee80211_find_sta(hw, priv->stations_39[sta_id].sta.sta.addr); 979 sta = ieee80211_find_sta(hw, priv->stations[sta_id].sta.sta.addr);
978 if (!sta) { 980 if (!sta) {
979 rcu_read_unlock(); 981 rcu_read_unlock();
980 return; 982 return;
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index 527525cc0919..46288e724889 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -98,7 +98,6 @@ const struct iwl3945_rate_info iwl3945_rates[IWL_RATE_COUNT_3945] = {
98 * ... and set IWL_EVT_DISABLE to 1. */ 98 * ... and set IWL_EVT_DISABLE to 1. */
99void iwl3945_disable_events(struct iwl_priv *priv) 99void iwl3945_disable_events(struct iwl_priv *priv)
100{ 100{
101 int ret;
102 int i; 101 int i;
103 u32 base; /* SRAM address of event log header */ 102 u32 base; /* SRAM address of event log header */
104 u32 disable_ptr; /* SRAM address of event-disable bitmap array */ 103 u32 disable_ptr; /* SRAM address of event-disable bitmap array */
@@ -159,26 +158,17 @@ void iwl3945_disable_events(struct iwl_priv *priv)
159 return; 158 return;
160 } 159 }
161 160
162 ret = iwl_grab_nic_access(priv);
163 if (ret) {
164 IWL_WARN(priv, "Can not read from adapter at this time.\n");
165 return;
166 }
167
168 disable_ptr = iwl_read_targ_mem(priv, base + (4 * sizeof(u32))); 161 disable_ptr = iwl_read_targ_mem(priv, base + (4 * sizeof(u32)));
169 array_size = iwl_read_targ_mem(priv, base + (5 * sizeof(u32))); 162 array_size = iwl_read_targ_mem(priv, base + (5 * sizeof(u32)));
170 iwl_release_nic_access(priv);
171 163
172 if (IWL_EVT_DISABLE && (array_size == IWL_EVT_DISABLE_SIZE)) { 164 if (IWL_EVT_DISABLE && (array_size == IWL_EVT_DISABLE_SIZE)) {
173 IWL_DEBUG_INFO(priv, "Disabling selected uCode log events at 0x%x\n", 165 IWL_DEBUG_INFO(priv, "Disabling selected uCode log events at 0x%x\n",
174 disable_ptr); 166 disable_ptr);
175 ret = iwl_grab_nic_access(priv);
176 for (i = 0; i < IWL_EVT_DISABLE_SIZE; i++) 167 for (i = 0; i < IWL_EVT_DISABLE_SIZE; i++)
177 iwl_write_targ_mem(priv, 168 iwl_write_targ_mem(priv,
178 disable_ptr + (i * sizeof(u32)), 169 disable_ptr + (i * sizeof(u32)),
179 evt_disable[i]); 170 evt_disable[i]);
180 171
181 iwl_release_nic_access(priv);
182 } else { 172 } else {
183 IWL_DEBUG_INFO(priv, "Selected uCode log events may be disabled\n"); 173 IWL_DEBUG_INFO(priv, "Selected uCode log events may be disabled\n");
184 IWL_DEBUG_INFO(priv, " by writing \"1\"s into disable bitmap\n"); 174 IWL_DEBUG_INFO(priv, " by writing \"1\"s into disable bitmap\n");
@@ -779,35 +769,6 @@ void iwl3945_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
779 return ; 769 return ;
780} 770}
781 771
782u8 iwl3945_hw_find_station(struct iwl_priv *priv, const u8 *addr)
783{
784 int i, start = IWL_AP_ID;
785 int ret = IWL_INVALID_STATION;
786 unsigned long flags;
787
788 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) ||
789 (priv->iw_mode == NL80211_IFTYPE_AP))
790 start = IWL_STA_ID;
791
792 if (is_broadcast_ether_addr(addr))
793 return priv->hw_params.bcast_sta_id;
794
795 spin_lock_irqsave(&priv->sta_lock, flags);
796 for (i = start; i < priv->hw_params.max_stations; i++)
797 if ((priv->stations_39[i].used) &&
798 (!compare_ether_addr
799 (priv->stations_39[i].sta.sta.addr, addr))) {
800 ret = i;
801 goto out;
802 }
803
804 IWL_DEBUG_INFO(priv, "can not find STA %pM (total %d)\n",
805 addr, priv->num_stations);
806 out:
807 spin_unlock_irqrestore(&priv->sta_lock, flags);
808 return ret;
809}
810
811/** 772/**
812 * iwl3945_hw_build_tx_cmd_rate - Add rate portion to TX_CMD: 773 * iwl3945_hw_build_tx_cmd_rate - Add rate portion to TX_CMD:
813 * 774 *
@@ -885,13 +846,13 @@ void iwl3945_hw_build_tx_cmd_rate(struct iwl_priv *priv, struct iwl_cmd *cmd,
885u8 iwl3945_sync_sta(struct iwl_priv *priv, int sta_id, u16 tx_rate, u8 flags) 846u8 iwl3945_sync_sta(struct iwl_priv *priv, int sta_id, u16 tx_rate, u8 flags)
886{ 847{
887 unsigned long flags_spin; 848 unsigned long flags_spin;
888 struct iwl3945_station_entry *station; 849 struct iwl_station_entry *station;
889 850
890 if (sta_id == IWL_INVALID_STATION) 851 if (sta_id == IWL_INVALID_STATION)
891 return IWL_INVALID_STATION; 852 return IWL_INVALID_STATION;
892 853
893 spin_lock_irqsave(&priv->sta_lock, flags_spin); 854 spin_lock_irqsave(&priv->sta_lock, flags_spin);
894 station = &priv->stations_39[sta_id]; 855 station = &priv->stations[sta_id];
895 856
896 station->sta.sta.modify_mask = STA_MODIFY_TX_RATE_MSK; 857 station->sta.sta.modify_mask = STA_MODIFY_TX_RATE_MSK;
897 station->sta.rate_n_flags = cpu_to_le16(tx_rate); 858 station->sta.rate_n_flags = cpu_to_le16(tx_rate);
@@ -899,8 +860,7 @@ u8 iwl3945_sync_sta(struct iwl_priv *priv, int sta_id, u16 tx_rate, u8 flags)
899 860
900 spin_unlock_irqrestore(&priv->sta_lock, flags_spin); 861 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
901 862
902 iwl_send_add_sta(priv, 863 iwl_send_add_sta(priv, &station->sta, flags);
903 (struct iwl_addsta_cmd *)&station->sta, flags);
904 IWL_DEBUG_RATE(priv, "SCALE sync station %d to rate %d\n", 864 IWL_DEBUG_RATE(priv, "SCALE sync station %d to rate %d\n",
905 sta_id, tx_rate); 865 sta_id, tx_rate);
906 return sta_id; 866 return sta_id;
@@ -908,55 +868,30 @@ u8 iwl3945_sync_sta(struct iwl_priv *priv, int sta_id, u16 tx_rate, u8 flags)
908 868
909static int iwl3945_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src) 869static int iwl3945_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
910{ 870{
911 int ret;
912 unsigned long flags;
913
914 spin_lock_irqsave(&priv->lock, flags);
915 ret = iwl_grab_nic_access(priv);
916 if (ret) {
917 spin_unlock_irqrestore(&priv->lock, flags);
918 return ret;
919 }
920
921 if (src == IWL_PWR_SRC_VAUX) { 871 if (src == IWL_PWR_SRC_VAUX) {
922 if (pci_pme_capable(priv->pci_dev, PCI_D3cold)) { 872 if (pci_pme_capable(priv->pci_dev, PCI_D3cold)) {
923 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, 873 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
924 APMG_PS_CTRL_VAL_PWR_SRC_VAUX, 874 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
925 ~APMG_PS_CTRL_MSK_PWR_SRC); 875 ~APMG_PS_CTRL_MSK_PWR_SRC);
926 iwl_release_nic_access(priv);
927 876
928 iwl_poll_bit(priv, CSR_GPIO_IN, 877 iwl_poll_bit(priv, CSR_GPIO_IN,
929 CSR_GPIO_IN_VAL_VAUX_PWR_SRC, 878 CSR_GPIO_IN_VAL_VAUX_PWR_SRC,
930 CSR_GPIO_IN_BIT_AUX_POWER, 5000); 879 CSR_GPIO_IN_BIT_AUX_POWER, 5000);
931 } else {
932 iwl_release_nic_access(priv);
933 } 880 }
934 } else { 881 } else {
935 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, 882 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
936 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN, 883 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
937 ~APMG_PS_CTRL_MSK_PWR_SRC); 884 ~APMG_PS_CTRL_MSK_PWR_SRC);
938 885
939 iwl_release_nic_access(priv);
940 iwl_poll_bit(priv, CSR_GPIO_IN, CSR_GPIO_IN_VAL_VMAIN_PWR_SRC, 886 iwl_poll_bit(priv, CSR_GPIO_IN, CSR_GPIO_IN_VAL_VMAIN_PWR_SRC,
941 CSR_GPIO_IN_BIT_AUX_POWER, 5000); /* uS */ 887 CSR_GPIO_IN_BIT_AUX_POWER, 5000); /* uS */
942 } 888 }
943 spin_unlock_irqrestore(&priv->lock, flags);
944 889
945 return ret; 890 return 0;
946} 891}
947 892
948static int iwl3945_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq) 893static int iwl3945_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
949{ 894{
950 int rc;
951 unsigned long flags;
952
953 spin_lock_irqsave(&priv->lock, flags);
954 rc = iwl_grab_nic_access(priv);
955 if (rc) {
956 spin_unlock_irqrestore(&priv->lock, flags);
957 return rc;
958 }
959
960 iwl_write_direct32(priv, FH39_RCSR_RBD_BASE(0), rxq->dma_addr); 895 iwl_write_direct32(priv, FH39_RCSR_RBD_BASE(0), rxq->dma_addr);
961 iwl_write_direct32(priv, FH39_RCSR_RPTR_ADDR(0), rxq->rb_stts_dma); 896 iwl_write_direct32(priv, FH39_RCSR_RPTR_ADDR(0), rxq->rb_stts_dma);
962 iwl_write_direct32(priv, FH39_RCSR_WPTR(0), 0); 897 iwl_write_direct32(priv, FH39_RCSR_WPTR(0), 0);
@@ -973,23 +908,11 @@ static int iwl3945_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
973 /* fake read to flush all prev I/O */ 908 /* fake read to flush all prev I/O */
974 iwl_read_direct32(priv, FH39_RSSR_CTRL); 909 iwl_read_direct32(priv, FH39_RSSR_CTRL);
975 910
976 iwl_release_nic_access(priv);
977 spin_unlock_irqrestore(&priv->lock, flags);
978
979 return 0; 911 return 0;
980} 912}
981 913
982static int iwl3945_tx_reset(struct iwl_priv *priv) 914static int iwl3945_tx_reset(struct iwl_priv *priv)
983{ 915{
984 int rc;
985 unsigned long flags;
986
987 spin_lock_irqsave(&priv->lock, flags);
988 rc = iwl_grab_nic_access(priv);
989 if (rc) {
990 spin_unlock_irqrestore(&priv->lock, flags);
991 return rc;
992 }
993 916
994 /* bypass mode */ 917 /* bypass mode */
995 iwl_write_prph(priv, ALM_SCD_MODE_REG, 0x2); 918 iwl_write_prph(priv, ALM_SCD_MODE_REG, 0x2);
@@ -1017,8 +940,6 @@ static int iwl3945_tx_reset(struct iwl_priv *priv)
1017 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RSP_WAIT_TH | 940 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RSP_WAIT_TH |
1018 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_RSP_WAIT_TH); 941 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_RSP_WAIT_TH);
1019 942
1020 iwl_release_nic_access(priv);
1021 spin_unlock_irqrestore(&priv->lock, flags);
1022 943
1023 return 0; 944 return 0;
1024} 945}
@@ -1061,7 +982,7 @@ static int iwl3945_txq_ctx_reset(struct iwl_priv *priv)
1061 982
1062static int iwl3945_apm_init(struct iwl_priv *priv) 983static int iwl3945_apm_init(struct iwl_priv *priv)
1063{ 984{
1064 int ret = 0; 985 int ret;
1065 986
1066 iwl_power_initialize(priv); 987 iwl_power_initialize(priv);
1067 988
@@ -1083,10 +1004,6 @@ static int iwl3945_apm_init(struct iwl_priv *priv)
1083 goto out; 1004 goto out;
1084 } 1005 }
1085 1006
1086 ret = iwl_grab_nic_access(priv);
1087 if (ret)
1088 goto out;
1089
1090 /* enable DMA */ 1007 /* enable DMA */
1091 iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT | 1008 iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT |
1092 APMG_CLK_VAL_BSM_CLK_RQT); 1009 APMG_CLK_VAL_BSM_CLK_RQT);
@@ -1097,7 +1014,6 @@ static int iwl3945_apm_init(struct iwl_priv *priv)
1097 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, 1014 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
1098 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 1015 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
1099 1016
1100 iwl_release_nic_access(priv);
1101out: 1017out:
1102 return ret; 1018 return ret;
1103} 1019}
@@ -1110,6 +1026,11 @@ static void iwl3945_nic_config(struct iwl_priv *priv)
1110 1026
1111 spin_lock_irqsave(&priv->lock, flags); 1027 spin_lock_irqsave(&priv->lock, flags);
1112 1028
1029 /* Determine HW type */
1030 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
1031
1032 IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", rev_id);
1033
1113 if (rev_id & PCI_CFG_REV_ID_BIT_RTP) 1034 if (rev_id & PCI_CFG_REV_ID_BIT_RTP)
1114 IWL_DEBUG_INFO(priv, "RTP type \n"); 1035 IWL_DEBUG_INFO(priv, "RTP type \n");
1115 else if (rev_id & PCI_CFG_REV_ID_BIT_BASIC_SKU) { 1036 else if (rev_id & PCI_CFG_REV_ID_BIT_BASIC_SKU) {
@@ -1163,7 +1084,6 @@ static void iwl3945_nic_config(struct iwl_priv *priv)
1163 1084
1164int iwl3945_hw_nic_init(struct iwl_priv *priv) 1085int iwl3945_hw_nic_init(struct iwl_priv *priv)
1165{ 1086{
1166 u8 rev_id;
1167 int rc; 1087 int rc;
1168 unsigned long flags; 1088 unsigned long flags;
1169 struct iwl_rx_queue *rxq = &priv->rxq; 1089 struct iwl_rx_queue *rxq = &priv->rxq;
@@ -1172,12 +1092,6 @@ int iwl3945_hw_nic_init(struct iwl_priv *priv)
1172 priv->cfg->ops->lib->apm_ops.init(priv); 1092 priv->cfg->ops->lib->apm_ops.init(priv);
1173 spin_unlock_irqrestore(&priv->lock, flags); 1093 spin_unlock_irqrestore(&priv->lock, flags);
1174 1094
1175 /* Determine HW type */
1176 rc = pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
1177 if (rc)
1178 return rc;
1179 IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", rev_id);
1180
1181 rc = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN); 1095 rc = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
1182 if (rc) 1096 if (rc)
1183 return rc; 1097 return rc;
@@ -1198,22 +1112,13 @@ int iwl3945_hw_nic_init(struct iwl_priv *priv)
1198 1112
1199 iwl3945_rx_init(priv, rxq); 1113 iwl3945_rx_init(priv, rxq);
1200 1114
1201 spin_lock_irqsave(&priv->lock, flags);
1202 1115
1203 /* Look at using this instead: 1116 /* Look at using this instead:
1204 rxq->need_update = 1; 1117 rxq->need_update = 1;
1205 iwl_rx_queue_update_write_ptr(priv, rxq); 1118 iwl_rx_queue_update_write_ptr(priv, rxq);
1206 */ 1119 */
1207 1120
1208 rc = iwl_grab_nic_access(priv);
1209 if (rc) {
1210 spin_unlock_irqrestore(&priv->lock, flags);
1211 return rc;
1212 }
1213 iwl_write_direct32(priv, FH39_RCSR_WPTR(0), rxq->write & ~7); 1121 iwl_write_direct32(priv, FH39_RCSR_WPTR(0), rxq->write & ~7);
1214 iwl_release_nic_access(priv);
1215
1216 spin_unlock_irqrestore(&priv->lock, flags);
1217 1122
1218 rc = iwl3945_txq_ctx_reset(priv); 1123 rc = iwl3945_txq_ctx_reset(priv);
1219 if (rc) 1124 if (rc)
@@ -1245,14 +1150,6 @@ void iwl3945_hw_txq_ctx_free(struct iwl_priv *priv)
1245void iwl3945_hw_txq_ctx_stop(struct iwl_priv *priv) 1150void iwl3945_hw_txq_ctx_stop(struct iwl_priv *priv)
1246{ 1151{
1247 int txq_id; 1152 int txq_id;
1248 unsigned long flags;
1249
1250 spin_lock_irqsave(&priv->lock, flags);
1251 if (iwl_grab_nic_access(priv)) {
1252 spin_unlock_irqrestore(&priv->lock, flags);
1253 iwl3945_hw_txq_ctx_free(priv);
1254 return;
1255 }
1256 1153
1257 /* stop SCD */ 1154 /* stop SCD */
1258 iwl_write_prph(priv, ALM_SCD_MODE_REG, 0); 1155 iwl_write_prph(priv, ALM_SCD_MODE_REG, 0);
@@ -1265,9 +1162,6 @@ void iwl3945_hw_txq_ctx_stop(struct iwl_priv *priv)
1265 1000); 1162 1000);
1266 } 1163 }
1267 1164
1268 iwl_release_nic_access(priv);
1269 spin_unlock_irqrestore(&priv->lock, flags);
1270
1271 iwl3945_hw_txq_ctx_free(priv); 1165 iwl3945_hw_txq_ctx_free(priv);
1272} 1166}
1273 1167
@@ -1312,12 +1206,8 @@ static void iwl3945_apm_stop(struct iwl_priv *priv)
1312 1206
1313static int iwl3945_apm_reset(struct iwl_priv *priv) 1207static int iwl3945_apm_reset(struct iwl_priv *priv)
1314{ 1208{
1315 int rc;
1316 unsigned long flags;
1317
1318 iwl3945_apm_stop_master(priv); 1209 iwl3945_apm_stop_master(priv);
1319 1210
1320 spin_lock_irqsave(&priv->lock, flags);
1321 1211
1322 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); 1212 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
1323 udelay(10); 1213 udelay(10);
@@ -1327,36 +1217,31 @@ static int iwl3945_apm_reset(struct iwl_priv *priv)
1327 iwl_poll_direct_bit(priv, CSR_GP_CNTRL, 1217 iwl_poll_direct_bit(priv, CSR_GP_CNTRL,
1328 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); 1218 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
1329 1219
1330 rc = iwl_grab_nic_access(priv); 1220 iwl_write_prph(priv, APMG_CLK_CTRL_REG,
1331 if (!rc) { 1221 APMG_CLK_VAL_BSM_CLK_RQT);
1332 iwl_write_prph(priv, APMG_CLK_CTRL_REG,
1333 APMG_CLK_VAL_BSM_CLK_RQT);
1334 1222
1335 iwl_write_prph(priv, APMG_RTC_INT_MSK_REG, 0x0); 1223 iwl_write_prph(priv, APMG_RTC_INT_MSK_REG, 0x0);
1336 iwl_write_prph(priv, APMG_RTC_INT_STT_REG, 1224 iwl_write_prph(priv, APMG_RTC_INT_STT_REG,
1337 0xFFFFFFFF); 1225 0xFFFFFFFF);
1338 1226
1339 /* enable DMA */ 1227 /* enable DMA */
1340 iwl_write_prph(priv, APMG_CLK_EN_REG, 1228 iwl_write_prph(priv, APMG_CLK_EN_REG,
1341 APMG_CLK_VAL_DMA_CLK_RQT | 1229 APMG_CLK_VAL_DMA_CLK_RQT |
1342 APMG_CLK_VAL_BSM_CLK_RQT); 1230 APMG_CLK_VAL_BSM_CLK_RQT);
1343 udelay(10); 1231 udelay(10);
1344 1232
1345 iwl_set_bits_prph(priv, APMG_PS_CTRL_REG, 1233 iwl_set_bits_prph(priv, APMG_PS_CTRL_REG,
1346 APMG_PS_CTRL_VAL_RESET_REQ); 1234 APMG_PS_CTRL_VAL_RESET_REQ);
1347 udelay(5); 1235 udelay(5);
1348 iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG, 1236 iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG,
1349 APMG_PS_CTRL_VAL_RESET_REQ); 1237 APMG_PS_CTRL_VAL_RESET_REQ);
1350 iwl_release_nic_access(priv);
1351 }
1352 1238
1353 /* Clear the 'host command active' bit... */ 1239 /* Clear the 'host command active' bit... */
1354 clear_bit(STATUS_HCMD_ACTIVE, &priv->status); 1240 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1355 1241
1356 wake_up_interruptible(&priv->wait_command_queue); 1242 wake_up_interruptible(&priv->wait_command_queue);
1357 spin_unlock_irqrestore(&priv->lock, flags);
1358 1243
1359 return rc; 1244 return 0;
1360} 1245}
1361 1246
1362/** 1247/**
@@ -1964,6 +1849,193 @@ int iwl3945_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
1964 return 0; 1849 return 0;
1965} 1850}
1966 1851
1852static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
1853{
1854 int rc = 0;
1855 struct iwl_rx_packet *res = NULL;
1856 struct iwl3945_rxon_assoc_cmd rxon_assoc;
1857 struct iwl_host_cmd cmd = {
1858 .id = REPLY_RXON_ASSOC,
1859 .len = sizeof(rxon_assoc),
1860 .meta.flags = CMD_WANT_SKB,
1861 .data = &rxon_assoc,
1862 };
1863 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1864 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
1865
1866 if ((rxon1->flags == rxon2->flags) &&
1867 (rxon1->filter_flags == rxon2->filter_flags) &&
1868 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1869 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1870 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
1871 return 0;
1872 }
1873
1874 rxon_assoc.flags = priv->staging_rxon.flags;
1875 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1876 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1877 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1878 rxon_assoc.reserved = 0;
1879
1880 rc = iwl_send_cmd_sync(priv, &cmd);
1881 if (rc)
1882 return rc;
1883
1884 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
1885 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1886 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
1887 rc = -EIO;
1888 }
1889
1890 priv->alloc_rxb_skb--;
1891 dev_kfree_skb_any(cmd.meta.u.skb);
1892
1893 return rc;
1894}
1895
1896/**
1897 * iwl3945_commit_rxon - commit staging_rxon to hardware
1898 *
1899 * The RXON command in staging_rxon is committed to the hardware and
1900 * the active_rxon structure is updated with the new data. This
1901 * function correctly transitions out of the RXON_ASSOC_MSK state if
1902 * a HW tune is required based on the RXON structure changes.
1903 */
1904static int iwl3945_commit_rxon(struct iwl_priv *priv)
1905{
1906 /* cast away the const for active_rxon in this function */
1907 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
1908 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
1909 int rc = 0;
1910 bool new_assoc =
1911 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
1912
1913 if (!iwl_is_alive(priv))
1914 return -1;
1915
1916 /* always get timestamp with Rx frame */
1917 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
1918
1919 /* select antenna */
1920 staging_rxon->flags &=
1921 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
1922 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
1923
1924 rc = iwl_check_rxon_cmd(priv);
1925 if (rc) {
1926 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
1927 return -EINVAL;
1928 }
1929
1930 /* If we don't need to send a full RXON, we can use
1931 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
1932 * and other flags for the current radio configuration. */
1933 if (!iwl_full_rxon_required(priv)) {
1934 rc = iwl_send_rxon_assoc(priv);
1935 if (rc) {
1936 IWL_ERR(priv, "Error setting RXON_ASSOC "
1937 "configuration (%d).\n", rc);
1938 return rc;
1939 }
1940
1941 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
1942
1943 return 0;
1944 }
1945
1946 /* If we are currently associated and the new config requires
1947 * an RXON_ASSOC and the new config wants the associated mask enabled,
1948 * we must clear the associated from the active configuration
1949 * before we apply the new config */
1950 if (iwl_is_associated(priv) && new_assoc) {
1951 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
1952 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1953
1954 /*
1955 * reserved4 and 5 could have been filled by the iwlcore code.
1956 * Let's clear them before pushing to the 3945.
1957 */
1958 active_rxon->reserved4 = 0;
1959 active_rxon->reserved5 = 0;
1960 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
1961 sizeof(struct iwl3945_rxon_cmd),
1962 &priv->active_rxon);
1963
1964 /* If the mask clearing failed then we set
1965 * active_rxon back to what it was previously */
1966 if (rc) {
1967 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
1968 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
1969 "configuration (%d).\n", rc);
1970 return rc;
1971 }
1972 }
1973
1974 IWL_DEBUG_INFO(priv, "Sending RXON\n"
1975 "* with%s RXON_FILTER_ASSOC_MSK\n"
1976 "* channel = %d\n"
1977 "* bssid = %pM\n",
1978 (new_assoc ? "" : "out"),
1979 le16_to_cpu(staging_rxon->channel),
1980 staging_rxon->bssid_addr);
1981
1982 /*
1983 * reserved4 and 5 could have been filled by the iwlcore code.
1984 * Let's clear them before pushing to the 3945.
1985 */
1986 staging_rxon->reserved4 = 0;
1987 staging_rxon->reserved5 = 0;
1988
1989 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
1990
1991 /* Apply the new configuration */
1992 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
1993 sizeof(struct iwl3945_rxon_cmd),
1994 staging_rxon);
1995 if (rc) {
1996 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
1997 return rc;
1998 }
1999
2000 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
2001
2002 iwl_clear_stations_table(priv);
2003
2004 /* If we issue a new RXON command which required a tune then we must
2005 * send a new TXPOWER command or we won't be able to Tx any frames */
2006 rc = priv->cfg->ops->lib->send_tx_power(priv);
2007 if (rc) {
2008 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
2009 return rc;
2010 }
2011
2012 /* Add the broadcast address so we can send broadcast frames */
2013 if (iwl_add_station(priv, iwl_bcast_addr, false, CMD_SYNC, NULL) ==
2014 IWL_INVALID_STATION) {
2015 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
2016 return -EIO;
2017 }
2018
2019 /* If we have set the ASSOC_MSK and we are in BSS mode then
2020 * add the IWL_AP_ID to the station rate table */
2021 if (iwl_is_associated(priv) &&
2022 (priv->iw_mode == NL80211_IFTYPE_STATION))
2023 if (iwl_add_station(priv, priv->active_rxon.bssid_addr,
2024 true, CMD_SYNC, NULL) == IWL_INVALID_STATION) {
2025 IWL_ERR(priv, "Error adding AP address for transmit\n");
2026 return -EIO;
2027 }
2028
2029 /* Init the hardware's rate fallback order based on the band */
2030 rc = iwl3945_init_hw_rate_table(priv);
2031 if (rc) {
2032 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
2033 return -EIO;
2034 }
2035
2036 return 0;
2037}
2038
1967/* will add 3945 channel switch cmd handling later */ 2039/* will add 3945 channel switch cmd handling later */
1968int iwl3945_hw_channel_switch(struct iwl_priv *priv, u16 channel) 2040int iwl3945_hw_channel_switch(struct iwl_priv *priv, u16 channel)
1969{ 2041{
@@ -2314,14 +2386,6 @@ int iwl3945_txpower_set_from_eeprom(struct iwl_priv *priv)
2314int iwl3945_hw_rxq_stop(struct iwl_priv *priv) 2386int iwl3945_hw_rxq_stop(struct iwl_priv *priv)
2315{ 2387{
2316 int rc; 2388 int rc;
2317 unsigned long flags;
2318
2319 spin_lock_irqsave(&priv->lock, flags);
2320 rc = iwl_grab_nic_access(priv);
2321 if (rc) {
2322 spin_unlock_irqrestore(&priv->lock, flags);
2323 return rc;
2324 }
2325 2389
2326 iwl_write_direct32(priv, FH39_RCSR_CONFIG(0), 0); 2390 iwl_write_direct32(priv, FH39_RCSR_CONFIG(0), 0);
2327 rc = iwl_poll_direct_bit(priv, FH39_RSSR_STATUS, 2391 rc = iwl_poll_direct_bit(priv, FH39_RSSR_STATUS,
@@ -2329,28 +2393,17 @@ int iwl3945_hw_rxq_stop(struct iwl_priv *priv)
2329 if (rc < 0) 2393 if (rc < 0)
2330 IWL_ERR(priv, "Can't stop Rx DMA.\n"); 2394 IWL_ERR(priv, "Can't stop Rx DMA.\n");
2331 2395
2332 iwl_release_nic_access(priv);
2333 spin_unlock_irqrestore(&priv->lock, flags);
2334
2335 return 0; 2396 return 0;
2336} 2397}
2337 2398
2338int iwl3945_hw_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq) 2399int iwl3945_hw_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq)
2339{ 2400{
2340 int rc;
2341 unsigned long flags;
2342 int txq_id = txq->q.id; 2401 int txq_id = txq->q.id;
2343 2402
2344 struct iwl3945_shared *shared_data = priv->shared_virt; 2403 struct iwl3945_shared *shared_data = priv->shared_virt;
2345 2404
2346 shared_data->tx_base_ptr[txq_id] = cpu_to_le32((u32)txq->q.dma_addr); 2405 shared_data->tx_base_ptr[txq_id] = cpu_to_le32((u32)txq->q.dma_addr);
2347 2406
2348 spin_lock_irqsave(&priv->lock, flags);
2349 rc = iwl_grab_nic_access(priv);
2350 if (rc) {
2351 spin_unlock_irqrestore(&priv->lock, flags);
2352 return rc;
2353 }
2354 iwl_write_direct32(priv, FH39_CBCC_CTRL(txq_id), 0); 2407 iwl_write_direct32(priv, FH39_CBCC_CTRL(txq_id), 0);
2355 iwl_write_direct32(priv, FH39_CBCC_BASE(txq_id), 0); 2408 iwl_write_direct32(priv, FH39_CBCC_BASE(txq_id), 0);
2356 2409
@@ -2360,11 +2413,9 @@ int iwl3945_hw_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq)
2360 FH39_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD | 2413 FH39_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD |
2361 FH39_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL | 2414 FH39_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL |
2362 FH39_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE); 2415 FH39_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE);
2363 iwl_release_nic_access(priv);
2364 2416
2365 /* fake read to flush all prev. writes */ 2417 /* fake read to flush all prev. writes */
2366 iwl_read32(priv, FH39_TSSR_CBB_BASE); 2418 iwl_read32(priv, FH39_TSSR_CBB_BASE);
2367 spin_unlock_irqrestore(&priv->lock, flags);
2368 2419
2369 return 0; 2420 return 0;
2370} 2421}
@@ -2384,13 +2435,25 @@ static u16 iwl3945_get_hcmd_size(u8 cmd_id, u16 len)
2384 } 2435 }
2385} 2436}
2386 2437
2438
2387static u16 iwl3945_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data) 2439static u16 iwl3945_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
2388{ 2440{
2389 u16 size = (u16)sizeof(struct iwl3945_addsta_cmd); 2441 struct iwl3945_addsta_cmd *addsta = (struct iwl3945_addsta_cmd *)data;
2390 memcpy(data, cmd, size); 2442 addsta->mode = cmd->mode;
2391 return size; 2443 memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
2444 memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo));
2445 addsta->station_flags = cmd->station_flags;
2446 addsta->station_flags_msk = cmd->station_flags_msk;
2447 addsta->tid_disable_tx = cpu_to_le16(0);
2448 addsta->rate_n_flags = cmd->rate_n_flags;
2449 addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
2450 addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
2451 addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
2452
2453 return (u16)sizeof(struct iwl3945_addsta_cmd);
2392} 2454}
2393 2455
2456
2394/** 2457/**
2395 * iwl3945_init_hw_rate_table - Initialize the hardware rate fallback table 2458 * iwl3945_init_hw_rate_table - Initialize the hardware rate fallback table
2396 */ 2459 */
@@ -2672,10 +2735,6 @@ static int iwl3945_load_bsm(struct iwl_priv *priv)
2672 inst_len = priv->ucode_init.len; 2735 inst_len = priv->ucode_init.len;
2673 data_len = priv->ucode_init_data.len; 2736 data_len = priv->ucode_init_data.len;
2674 2737
2675 rc = iwl_grab_nic_access(priv);
2676 if (rc)
2677 return rc;
2678
2679 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); 2738 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2680 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); 2739 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2681 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); 2740 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
@@ -2689,10 +2748,8 @@ static int iwl3945_load_bsm(struct iwl_priv *priv)
2689 le32_to_cpu(*image)); 2748 le32_to_cpu(*image));
2690 2749
2691 rc = iwl3945_verify_bsm(priv); 2750 rc = iwl3945_verify_bsm(priv);
2692 if (rc) { 2751 if (rc)
2693 iwl_release_nic_access(priv);
2694 return rc; 2752 return rc;
2695 }
2696 2753
2697 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ 2754 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
2698 iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); 2755 iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
@@ -2724,11 +2781,14 @@ static int iwl3945_load_bsm(struct iwl_priv *priv)
2724 iwl_write_prph(priv, BSM_WR_CTRL_REG, 2781 iwl_write_prph(priv, BSM_WR_CTRL_REG,
2725 BSM_WR_CTRL_REG_BIT_START_EN); 2782 BSM_WR_CTRL_REG_BIT_START_EN);
2726 2783
2727 iwl_release_nic_access(priv);
2728
2729 return 0; 2784 return 0;
2730} 2785}
2731 2786
2787static struct iwl_hcmd_ops iwl3945_hcmd = {
2788 .rxon_assoc = iwl3945_send_rxon_assoc,
2789 .commit_rxon = iwl3945_commit_rxon,
2790};
2791
2732static struct iwl_lib_ops iwl3945_lib = { 2792static struct iwl_lib_ops iwl3945_lib = {
2733 .txq_attach_buf_to_tfd = iwl3945_hw_txq_attach_buf_to_tfd, 2793 .txq_attach_buf_to_tfd = iwl3945_hw_txq_attach_buf_to_tfd,
2734 .txq_free_tfd = iwl3945_hw_txq_free_tfd, 2794 .txq_free_tfd = iwl3945_hw_txq_free_tfd,
@@ -2758,6 +2818,9 @@ static struct iwl_lib_ops iwl3945_lib = {
2758 }, 2818 },
2759 .send_tx_power = iwl3945_send_tx_power, 2819 .send_tx_power = iwl3945_send_tx_power,
2760 .is_valid_rtc_data_addr = iwl3945_hw_valid_rtc_data_addr, 2820 .is_valid_rtc_data_addr = iwl3945_hw_valid_rtc_data_addr,
2821 .post_associate = iwl3945_post_associate,
2822 .isr = iwl_isr_legacy,
2823 .config_ap = iwl3945_config_ap,
2761}; 2824};
2762 2825
2763static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = { 2826static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
@@ -2767,6 +2830,7 @@ static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
2767 2830
2768static struct iwl_ops iwl3945_ops = { 2831static struct iwl_ops iwl3945_ops = {
2769 .lib = &iwl3945_lib, 2832 .lib = &iwl3945_lib,
2833 .hcmd = &iwl3945_hcmd,
2770 .utils = &iwl3945_hcmd_utils, 2834 .utils = &iwl3945_hcmd_utils,
2771}; 2835};
2772 2836
@@ -2779,7 +2843,8 @@ static struct iwl_cfg iwl3945_bg_cfg = {
2779 .eeprom_size = IWL3945_EEPROM_IMG_SIZE, 2843 .eeprom_size = IWL3945_EEPROM_IMG_SIZE,
2780 .eeprom_ver = EEPROM_3945_EEPROM_VERSION, 2844 .eeprom_ver = EEPROM_3945_EEPROM_VERSION,
2781 .ops = &iwl3945_ops, 2845 .ops = &iwl3945_ops,
2782 .mod_params = &iwl3945_mod_params 2846 .mod_params = &iwl3945_mod_params,
2847 .use_isr_legacy = true
2783}; 2848};
2784 2849
2785static struct iwl_cfg iwl3945_abg_cfg = { 2850static struct iwl_cfg iwl3945_abg_cfg = {
@@ -2791,7 +2856,8 @@ static struct iwl_cfg iwl3945_abg_cfg = {
2791 .eeprom_size = IWL3945_EEPROM_IMG_SIZE, 2856 .eeprom_size = IWL3945_EEPROM_IMG_SIZE,
2792 .eeprom_ver = EEPROM_3945_EEPROM_VERSION, 2857 .eeprom_ver = EEPROM_3945_EEPROM_VERSION,
2793 .ops = &iwl3945_ops, 2858 .ops = &iwl3945_ops,
2794 .mod_params = &iwl3945_mod_params 2859 .mod_params = &iwl3945_mod_params,
2860 .use_isr_legacy = true
2795}; 2861};
2796 2862
2797struct pci_device_id iwl3945_hw_card_ids[] = { 2863struct pci_device_id iwl3945_hw_card_ids[] = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.h b/drivers/net/wireless/iwlwifi/iwl-3945.h
index 55188844657b..fbb3a573463e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.h
@@ -36,10 +36,6 @@
36#include <linux/kernel.h> 36#include <linux/kernel.h>
37#include <net/ieee80211_radiotap.h> 37#include <net/ieee80211_radiotap.h>
38 38
39/*used for rfkill*/
40#include <linux/rfkill.h>
41#include <linux/input.h>
42
43/* Hardware specific file defines the PCI IDs table for that hardware module */ 39/* Hardware specific file defines the PCI IDs table for that hardware module */
44extern struct pci_device_id iwl3945_hw_card_ids[]; 40extern struct pci_device_id iwl3945_hw_card_ids[];
45 41
@@ -155,14 +151,12 @@ struct iwl3945_frame {
155#define STATUS_HCMD_SYNC_ACTIVE 1 /* sync host command in progress */ 151#define STATUS_HCMD_SYNC_ACTIVE 1 /* sync host command in progress */
156#define STATUS_INT_ENABLED 2 152#define STATUS_INT_ENABLED 2
157#define STATUS_RF_KILL_HW 3 153#define STATUS_RF_KILL_HW 3
158#define STATUS_RF_KILL_SW 4
159#define STATUS_INIT 5 154#define STATUS_INIT 5
160#define STATUS_ALIVE 6 155#define STATUS_ALIVE 6
161#define STATUS_READY 7 156#define STATUS_READY 7
162#define STATUS_TEMPERATURE 8 157#define STATUS_TEMPERATURE 8
163#define STATUS_GEO_CONFIGURED 9 158#define STATUS_GEO_CONFIGURED 9
164#define STATUS_EXIT_PENDING 10 159#define STATUS_EXIT_PENDING 10
165#define STATUS_IN_SUSPEND 11
166#define STATUS_STATISTICS 12 160#define STATUS_STATISTICS 12
167#define STATUS_SCANNING 13 161#define STATUS_SCANNING 13
168#define STATUS_SCAN_ABORTING 14 162#define STATUS_SCAN_ABORTING 14
@@ -203,11 +197,6 @@ struct iwl3945_ibss_seq {
203 * for use by iwl-*.c 197 * for use by iwl-*.c
204 * 198 *
205 *****************************************************************************/ 199 *****************************************************************************/
206struct iwl3945_addsta_cmd;
207extern int iwl3945_send_add_station(struct iwl_priv *priv,
208 struct iwl3945_addsta_cmd *sta, u8 flags);
209extern u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *bssid,
210 int is_ap, u8 flags);
211extern int iwl3945_power_init_handle(struct iwl_priv *priv); 200extern int iwl3945_power_init_handle(struct iwl_priv *priv);
212extern int iwl3945_eeprom_init(struct iwl_priv *priv); 201extern int iwl3945_eeprom_init(struct iwl_priv *priv);
213extern int iwl3945_calc_db_from_ratio(int sig_ratio); 202extern int iwl3945_calc_db_from_ratio(int sig_ratio);
@@ -278,6 +267,8 @@ extern void iwl3945_hw_rx_statistics(struct iwl_priv *priv,
278 struct iwl_rx_mem_buffer *rxb); 267 struct iwl_rx_mem_buffer *rxb);
279extern void iwl3945_disable_events(struct iwl_priv *priv); 268extern void iwl3945_disable_events(struct iwl_priv *priv);
280extern int iwl4965_get_temperature(const struct iwl_priv *priv); 269extern int iwl4965_get_temperature(const struct iwl_priv *priv);
270extern void iwl3945_post_associate(struct iwl_priv *priv);
271extern void iwl3945_config_ap(struct iwl_priv *priv);
281 272
282/** 273/**
283 * iwl3945_hw_find_station - Find station id for a given BSSID 274 * iwl3945_hw_find_station - Find station id for a given BSSID
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index 847a6220c5e6..8f3d4bc6a03f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -163,10 +163,6 @@ static int iwl4965_load_bsm(struct iwl_priv *priv)
163 inst_len = priv->ucode_init.len; 163 inst_len = priv->ucode_init.len;
164 data_len = priv->ucode_init_data.len; 164 data_len = priv->ucode_init_data.len;
165 165
166 ret = iwl_grab_nic_access(priv);
167 if (ret)
168 return ret;
169
170 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); 166 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
171 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); 167 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
172 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); 168 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
@@ -179,10 +175,8 @@ static int iwl4965_load_bsm(struct iwl_priv *priv)
179 _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image)); 175 _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image));
180 176
181 ret = iwl4965_verify_bsm(priv); 177 ret = iwl4965_verify_bsm(priv);
182 if (ret) { 178 if (ret)
183 iwl_release_nic_access(priv);
184 return ret; 179 return ret;
185 }
186 180
187 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ 181 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
188 iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); 182 iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
@@ -211,7 +205,6 @@ static int iwl4965_load_bsm(struct iwl_priv *priv)
211 * (e.g. when powering back up after power-save shutdown) */ 205 * (e.g. when powering back up after power-save shutdown) */
212 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN); 206 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
213 207
214 iwl_release_nic_access(priv);
215 208
216 return 0; 209 return 0;
217} 210}
@@ -229,20 +222,12 @@ static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
229{ 222{
230 dma_addr_t pinst; 223 dma_addr_t pinst;
231 dma_addr_t pdata; 224 dma_addr_t pdata;
232 unsigned long flags;
233 int ret = 0; 225 int ret = 0;
234 226
235 /* bits 35:4 for 4965 */ 227 /* bits 35:4 for 4965 */
236 pinst = priv->ucode_code.p_addr >> 4; 228 pinst = priv->ucode_code.p_addr >> 4;
237 pdata = priv->ucode_data_backup.p_addr >> 4; 229 pdata = priv->ucode_data_backup.p_addr >> 4;
238 230
239 spin_lock_irqsave(&priv->lock, flags);
240 ret = iwl_grab_nic_access(priv);
241 if (ret) {
242 spin_unlock_irqrestore(&priv->lock, flags);
243 return ret;
244 }
245
246 /* Tell bootstrap uCode where to find image to load */ 231 /* Tell bootstrap uCode where to find image to load */
247 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); 232 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
248 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); 233 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
@@ -253,10 +238,6 @@ static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
253 * that all new ptr/size info is in place */ 238 * that all new ptr/size info is in place */
254 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, 239 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
255 priv->ucode_code.len | BSM_DRAM_INST_LOAD); 240 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
256 iwl_release_nic_access(priv);
257
258 spin_unlock_irqrestore(&priv->lock, flags);
259
260 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n"); 241 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
261 242
262 return ret; 243 return ret;
@@ -312,10 +293,12 @@ restart:
312 queue_work(priv->workqueue, &priv->restart); 293 queue_work(priv->workqueue, &priv->restart);
313} 294}
314 295
315static int is_fat_channel(__le32 rxon_flags) 296static bool is_fat_channel(__le32 rxon_flags)
316{ 297{
317 return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) || 298 int chan_mod = le32_to_cpu(rxon_flags & RXON_FLG_CHANNEL_MODE_MSK)
318 (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK); 299 >> RXON_FLG_CHANNEL_MODE_POS;
300 return ((chan_mod == CHANNEL_MODE_PURE_40) ||
301 (chan_mod == CHANNEL_MODE_MIXED));
319} 302}
320 303
321/* 304/*
@@ -358,10 +341,6 @@ static int iwl4965_apm_init(struct iwl_priv *priv)
358 goto out; 341 goto out;
359 } 342 }
360 343
361 ret = iwl_grab_nic_access(priv);
362 if (ret)
363 goto out;
364
365 /* enable DMA */ 344 /* enable DMA */
366 iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT | 345 iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT |
367 APMG_CLK_VAL_BSM_CLK_RQT); 346 APMG_CLK_VAL_BSM_CLK_RQT);
@@ -372,7 +351,6 @@ static int iwl4965_apm_init(struct iwl_priv *priv)
372 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, 351 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
373 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 352 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
374 353
375 iwl_release_nic_access(priv);
376out: 354out:
377 return ret; 355 return ret;
378} 356}
@@ -454,11 +432,9 @@ static void iwl4965_apm_stop(struct iwl_priv *priv)
454static int iwl4965_apm_reset(struct iwl_priv *priv) 432static int iwl4965_apm_reset(struct iwl_priv *priv)
455{ 433{
456 int ret = 0; 434 int ret = 0;
457 unsigned long flags;
458 435
459 iwl4965_apm_stop_master(priv); 436 iwl4965_apm_stop_master(priv);
460 437
461 spin_lock_irqsave(&priv->lock, flags);
462 438
463 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); 439 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
464 440
@@ -475,9 +451,6 @@ static int iwl4965_apm_reset(struct iwl_priv *priv)
475 451
476 udelay(10); 452 udelay(10);
477 453
478 ret = iwl_grab_nic_access(priv);
479 if (ret)
480 goto out;
481 /* Enable DMA and BSM Clock */ 454 /* Enable DMA and BSM Clock */
482 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT | 455 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT |
483 APMG_CLK_VAL_BSM_CLK_RQT); 456 APMG_CLK_VAL_BSM_CLK_RQT);
@@ -488,14 +461,10 @@ static int iwl4965_apm_reset(struct iwl_priv *priv)
488 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, 461 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
489 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 462 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
490 463
491 iwl_release_nic_access(priv);
492
493 clear_bit(STATUS_HCMD_ACTIVE, &priv->status); 464 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
494 wake_up_interruptible(&priv->wait_command_queue); 465 wake_up_interruptible(&priv->wait_command_queue);
495 466
496out: 467out:
497 spin_unlock_irqrestore(&priv->lock, flags);
498
499 return ret; 468 return ret;
500} 469}
501 470
@@ -681,18 +650,11 @@ static int iwl4965_alive_notify(struct iwl_priv *priv)
681{ 650{
682 u32 a; 651 u32 a;
683 unsigned long flags; 652 unsigned long flags;
684 int ret;
685 int i, chan; 653 int i, chan;
686 u32 reg_val; 654 u32 reg_val;
687 655
688 spin_lock_irqsave(&priv->lock, flags); 656 spin_lock_irqsave(&priv->lock, flags);
689 657
690 ret = iwl_grab_nic_access(priv);
691 if (ret) {
692 spin_unlock_irqrestore(&priv->lock, flags);
693 return ret;
694 }
695
696 /* Clear 4965's internal Tx Scheduler data base */ 658 /* Clear 4965's internal Tx Scheduler data base */
697 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR); 659 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
698 a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET; 660 a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET;
@@ -759,10 +721,9 @@ static int iwl4965_alive_notify(struct iwl_priv *priv)
759 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0); 721 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
760 } 722 }
761 723
762 iwl_release_nic_access(priv);
763 spin_unlock_irqrestore(&priv->lock, flags); 724 spin_unlock_irqrestore(&priv->lock, flags);
764 725
765 return ret; 726 return 0;
766} 727}
767 728
768static struct iwl_sensitivity_ranges iwl4965_sensitivity = { 729static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
@@ -788,6 +749,12 @@ static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
788 .nrg_th_ofdm = 100, 749 .nrg_th_ofdm = 100,
789}; 750};
790 751
752static void iwl4965_set_ct_threshold(struct iwl_priv *priv)
753{
754 /* want Kelvin */
755 priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
756}
757
791/** 758/**
792 * iwl4965_hw_set_hw_params 759 * iwl4965_hw_set_hw_params
793 * 760 *
@@ -822,7 +789,8 @@ static int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
822 priv->hw_params.rx_chains_num = 2; 789 priv->hw_params.rx_chains_num = 2;
823 priv->hw_params.valid_tx_ant = ANT_A | ANT_B; 790 priv->hw_params.valid_tx_ant = ANT_A | ANT_B;
824 priv->hw_params.valid_rx_ant = ANT_A | ANT_B; 791 priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
825 priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD); 792 if (priv->cfg->ops->lib->temp_ops.set_ct_kill)
793 priv->cfg->ops->lib->temp_ops.set_ct_kill(priv);
826 794
827 priv->hw_params.sens = &iwl4965_sensitivity; 795 priv->hw_params.sens = &iwl4965_sensitivity;
828 796
@@ -1524,7 +1492,7 @@ static int iwl4965_send_tx_power(struct iwl_priv *priv)
1524 struct iwl4965_txpowertable_cmd cmd = { 0 }; 1492 struct iwl4965_txpowertable_cmd cmd = { 0 };
1525 int ret; 1493 int ret;
1526 u8 band = 0; 1494 u8 band = 0;
1527 u8 is_fat = 0; 1495 bool is_fat = false;
1528 u8 ctrl_chan_high = 0; 1496 u8 ctrl_chan_high = 0;
1529 1497
1530 if (test_bit(STATUS_SCANNING, &priv->status)) { 1498 if (test_bit(STATUS_SCANNING, &priv->status)) {
@@ -1602,7 +1570,7 @@ static int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
1602{ 1570{
1603 int rc; 1571 int rc;
1604 u8 band = 0; 1572 u8 band = 0;
1605 u8 is_fat = 0; 1573 bool is_fat = false;
1606 u8 ctrl_chan_high = 0; 1574 u8 ctrl_chan_high = 0;
1607 struct iwl4965_channel_switch_cmd cmd = { 0 }; 1575 struct iwl4965_channel_switch_cmd cmd = { 0 };
1608 const struct iwl_channel_info *ch_info; 1576 const struct iwl_channel_info *ch_info;
@@ -1833,8 +1801,6 @@ static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
1833static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id, 1801static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
1834 u16 ssn_idx, u8 tx_fifo) 1802 u16 ssn_idx, u8 tx_fifo)
1835{ 1803{
1836 int ret = 0;
1837
1838 if ((IWL49_FIRST_AMPDU_QUEUE > txq_id) || 1804 if ((IWL49_FIRST_AMPDU_QUEUE > txq_id) ||
1839 (IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES <= txq_id)) { 1805 (IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES <= txq_id)) {
1840 IWL_WARN(priv, 1806 IWL_WARN(priv,
@@ -1844,10 +1810,6 @@ static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
1844 return -EINVAL; 1810 return -EINVAL;
1845 } 1811 }
1846 1812
1847 ret = iwl_grab_nic_access(priv);
1848 if (ret)
1849 return ret;
1850
1851 iwl4965_tx_queue_stop_scheduler(priv, txq_id); 1813 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
1852 1814
1853 iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id)); 1815 iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
@@ -1861,8 +1823,6 @@ static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
1861 iwl_txq_ctx_deactivate(priv, txq_id); 1823 iwl_txq_ctx_deactivate(priv, txq_id);
1862 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0); 1824 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
1863 1825
1864 iwl_release_nic_access(priv);
1865
1866 return 0; 1826 return 0;
1867} 1827}
1868 1828
@@ -1904,7 +1864,6 @@ static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
1904 int tx_fifo, int sta_id, int tid, u16 ssn_idx) 1864 int tx_fifo, int sta_id, int tid, u16 ssn_idx)
1905{ 1865{
1906 unsigned long flags; 1866 unsigned long flags;
1907 int ret;
1908 u16 ra_tid; 1867 u16 ra_tid;
1909 1868
1910 if ((IWL49_FIRST_AMPDU_QUEUE > txq_id) || 1869 if ((IWL49_FIRST_AMPDU_QUEUE > txq_id) ||
@@ -1922,11 +1881,6 @@ static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
1922 iwl_sta_tx_modify_enable_tid(priv, sta_id, tid); 1881 iwl_sta_tx_modify_enable_tid(priv, sta_id, tid);
1923 1882
1924 spin_lock_irqsave(&priv->lock, flags); 1883 spin_lock_irqsave(&priv->lock, flags);
1925 ret = iwl_grab_nic_access(priv);
1926 if (ret) {
1927 spin_unlock_irqrestore(&priv->lock, flags);
1928 return ret;
1929 }
1930 1884
1931 /* Stop this Tx queue before configuring it */ 1885 /* Stop this Tx queue before configuring it */
1932 iwl4965_tx_queue_stop_scheduler(priv, txq_id); 1886 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
@@ -1959,7 +1913,6 @@ static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
1959 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */ 1913 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
1960 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1); 1914 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
1961 1915
1962 iwl_release_nic_access(priv);
1963 spin_unlock_irqrestore(&priv->lock, flags); 1916 spin_unlock_irqrestore(&priv->lock, flags);
1964 1917
1965 return 0; 1918 return 0;
@@ -2268,9 +2221,10 @@ static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
2268 cancel_work_sync(&priv->txpower_work); 2221 cancel_work_sync(&priv->txpower_work);
2269} 2222}
2270 2223
2271
2272static struct iwl_hcmd_ops iwl4965_hcmd = { 2224static struct iwl_hcmd_ops iwl4965_hcmd = {
2273 .rxon_assoc = iwl4965_send_rxon_assoc, 2225 .rxon_assoc = iwl4965_send_rxon_assoc,
2226 .commit_rxon = iwl_commit_rxon,
2227 .set_rxon_chain = iwl_set_rxon_chain,
2274}; 2228};
2275 2229
2276static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = { 2230static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
@@ -2323,7 +2277,13 @@ static struct iwl_lib_ops iwl4965_lib = {
2323 }, 2277 },
2324 .send_tx_power = iwl4965_send_tx_power, 2278 .send_tx_power = iwl4965_send_tx_power,
2325 .update_chain_flags = iwl_update_chain_flags, 2279 .update_chain_flags = iwl_update_chain_flags,
2326 .temperature = iwl4965_temperature_calib, 2280 .post_associate = iwl_post_associate,
2281 .config_ap = iwl_config_ap,
2282 .isr = iwl_isr_legacy,
2283 .temp_ops = {
2284 .temperature = iwl4965_temperature_calib,
2285 .set_ct_kill = iwl4965_set_ct_threshold,
2286 },
2327}; 2287};
2328 2288
2329static struct iwl_ops iwl4965_ops = { 2289static struct iwl_ops iwl4965_ops = {
@@ -2343,6 +2303,7 @@ struct iwl_cfg iwl4965_agn_cfg = {
2343 .eeprom_calib_ver = EEPROM_4965_TX_POWER_VERSION, 2303 .eeprom_calib_ver = EEPROM_4965_TX_POWER_VERSION,
2344 .ops = &iwl4965_ops, 2304 .ops = &iwl4965_ops,
2345 .mod_params = &iwl4965_mod_params, 2305 .mod_params = &iwl4965_mod_params,
2306 .use_isr_legacy = true
2346}; 2307};
2347 2308
2348/* Module firmware */ 2309/* Module firmware */
@@ -2350,8 +2311,6 @@ MODULE_FIRMWARE(IWL4965_MODULE_FIRMWARE(IWL4965_UCODE_API_MAX));
2350 2311
2351module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444); 2312module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
2352MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); 2313MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
2353module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
2354MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
2355module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444); 2314module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
2356MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])"); 2315MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
2357module_param_named(debug, iwl4965_mod_params.debug, uint, 0444); 2316module_param_named(debug, iwl4965_mod_params.debug, uint, 0444);
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000-hw.h b/drivers/net/wireless/iwlwifi/iwl-5000-hw.h
index 15cac70e36e2..4ef6804a455a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000-hw.h
+++ b/drivers/net/wireless/iwlwifi/iwl-5000-hw.h
@@ -87,6 +87,18 @@
87#define IWL50_NUM_AMPDU_QUEUES 10 87#define IWL50_NUM_AMPDU_QUEUES 10
88#define IWL50_FIRST_AMPDU_QUEUE 10 88#define IWL50_FIRST_AMPDU_QUEUE 10
89 89
90/* 5150 only */
91#define IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF (-5)
92
93static inline s32 iwl_temp_calib_to_offset(struct iwl_priv *priv)
94{
95 u16 *temp_calib = (u16 *)iwl_eeprom_query_addr(priv,
96 EEPROM_5000_TEMPERATURE);
97 /* offset = temperature - voltage / coef */
98 s32 offset = (s32)(temp_calib[0] - temp_calib[1] / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF);
99 return offset;
100}
101
90/* Fixed (non-configurable) rx data from phy */ 102/* Fixed (non-configurable) rx data from phy */
91 103
92/** 104/**
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index 9452461ce864..b3c648ce8c7b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -124,10 +124,6 @@ static int iwl5000_apm_init(struct iwl_priv *priv)
124 return ret; 124 return ret;
125 } 125 }
126 126
127 ret = iwl_grab_nic_access(priv);
128 if (ret)
129 return ret;
130
131 /* enable DMA */ 127 /* enable DMA */
132 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT); 128 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
133 129
@@ -137,8 +133,6 @@ static int iwl5000_apm_init(struct iwl_priv *priv)
137 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, 133 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
138 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 134 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
139 135
140 iwl_release_nic_access(priv);
141
142 return ret; 136 return ret;
143} 137}
144 138
@@ -165,12 +159,9 @@ static void iwl5000_apm_stop(struct iwl_priv *priv)
165static int iwl5000_apm_reset(struct iwl_priv *priv) 159static int iwl5000_apm_reset(struct iwl_priv *priv)
166{ 160{
167 int ret = 0; 161 int ret = 0;
168 unsigned long flags;
169 162
170 iwl5000_apm_stop_master(priv); 163 iwl5000_apm_stop_master(priv);
171 164
172 spin_lock_irqsave(&priv->lock, flags);
173
174 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); 165 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
175 166
176 udelay(10); 167 udelay(10);
@@ -193,10 +184,6 @@ static int iwl5000_apm_reset(struct iwl_priv *priv)
193 goto out; 184 goto out;
194 } 185 }
195 186
196 ret = iwl_grab_nic_access(priv);
197 if (ret)
198 goto out;
199
200 /* enable DMA */ 187 /* enable DMA */
201 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT); 188 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
202 189
@@ -205,11 +192,7 @@ static int iwl5000_apm_reset(struct iwl_priv *priv)
205 /* disable L1-Active */ 192 /* disable L1-Active */
206 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, 193 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
207 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 194 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
208
209 iwl_release_nic_access(priv);
210
211out: 195out:
212 spin_unlock_irqrestore(&priv->lock, flags);
213 196
214 return ret; 197 return ret;
215} 198}
@@ -252,11 +235,9 @@ static void iwl5000_nic_config(struct iwl_priv *priv)
252 * (PCIe power is lost before PERST# is asserted), 235 * (PCIe power is lost before PERST# is asserted),
253 * causing ME FW to lose ownership and not being able to obtain it back. 236 * causing ME FW to lose ownership and not being able to obtain it back.
254 */ 237 */
255 iwl_grab_nic_access(priv);
256 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, 238 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
257 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS, 239 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
258 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS); 240 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
259 iwl_release_nic_access(priv);
260 241
261 spin_unlock_irqrestore(&priv->lock, flags); 242 spin_unlock_irqrestore(&priv->lock, flags);
262} 243}
@@ -434,15 +415,19 @@ static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
434 return &priv->eeprom[address]; 415 return &priv->eeprom[address];
435} 416}
436 417
437static s32 iwl5150_get_ct_threshold(struct iwl_priv *priv) 418static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
438{ 419{
439 const s32 volt2temp_coef = -5; 420 const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
440 u16 *temp_calib = (u16 *)iwl_eeprom_query_addr(priv, 421 s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD) -
441 EEPROM_5000_TEMPERATURE); 422 iwl_temp_calib_to_offset(priv);
442 /* offset = temperate - voltage / coef */ 423
443 s32 offset = temp_calib[0] - temp_calib[1] / volt2temp_coef; 424 priv->hw_params.ct_kill_threshold = threshold * volt2temp_coef;
444 s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD) - offset; 425}
445 return threshold * volt2temp_coef; 426
427static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
428{
429 /* want Celsius */
430 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
446} 431}
447 432
448/* 433/*
@@ -533,19 +518,9 @@ static int iwl5000_load_section(struct iwl_priv *priv,
533 struct fw_desc *image, 518 struct fw_desc *image,
534 u32 dst_addr) 519 u32 dst_addr)
535{ 520{
536 int ret = 0;
537 unsigned long flags;
538
539 dma_addr_t phy_addr = image->p_addr; 521 dma_addr_t phy_addr = image->p_addr;
540 u32 byte_cnt = image->len; 522 u32 byte_cnt = image->len;
541 523
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, 524 iwl_write_direct32(priv,
550 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL), 525 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
551 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE); 526 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
@@ -574,8 +549,6 @@ static int iwl5000_load_section(struct iwl_priv *priv,
574 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE | 549 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE |
575 FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD); 550 FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
576 551
577 iwl_release_nic_access(priv);
578 spin_unlock_irqrestore(&priv->lock, flags);
579 return 0; 552 return 0;
580} 553}
581 554
@@ -736,18 +709,11 @@ static int iwl5000_alive_notify(struct iwl_priv *priv)
736{ 709{
737 u32 a; 710 u32 a;
738 unsigned long flags; 711 unsigned long flags;
739 int ret;
740 int i, chan; 712 int i, chan;
741 u32 reg_val; 713 u32 reg_val;
742 714
743 spin_lock_irqsave(&priv->lock, flags); 715 spin_lock_irqsave(&priv->lock, flags);
744 716
745 ret = iwl_grab_nic_access(priv);
746 if (ret) {
747 spin_unlock_irqrestore(&priv->lock, flags);
748 return ret;
749 }
750
751 priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR); 717 priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR);
752 a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET; 718 a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET;
753 for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET; 719 for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET;
@@ -815,7 +781,6 @@ static int iwl5000_alive_notify(struct iwl_priv *priv)
815 iwl_txq_ctx_activate(priv, 8); 781 iwl_txq_ctx_activate(priv, 8);
816 iwl_txq_ctx_activate(priv, 9); 782 iwl_txq_ctx_activate(priv, 9);
817 783
818 iwl_release_nic_access(priv);
819 spin_unlock_irqrestore(&priv->lock, flags); 784 spin_unlock_irqrestore(&priv->lock, flags);
820 785
821 786
@@ -868,17 +833,8 @@ static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
868 priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant; 833 priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
869 priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant; 834 priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
870 835
871 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) { 836 if (priv->cfg->ops->lib->temp_ops.set_ct_kill)
872 case CSR_HW_REV_TYPE_5150: 837 priv->cfg->ops->lib->temp_ops.set_ct_kill(priv);
873 /* 5150 wants in Kelvin */
874 priv->hw_params.ct_kill_threshold =
875 iwl5150_get_ct_threshold(priv);
876 break;
877 default:
878 /* all others want Celsius */
879 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
880 break;
881 }
882 838
883 /* Set initial calibration set */ 839 /* Set initial calibration set */
884 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) { 840 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
@@ -900,7 +856,6 @@ static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
900 break; 856 break;
901 } 857 }
902 858
903
904 return 0; 859 return 0;
905} 860}
906 861
@@ -1006,7 +961,6 @@ static int iwl5000_txq_agg_enable(struct iwl_priv *priv, int txq_id,
1006 int tx_fifo, int sta_id, int tid, u16 ssn_idx) 961 int tx_fifo, int sta_id, int tid, u16 ssn_idx)
1007{ 962{
1008 unsigned long flags; 963 unsigned long flags;
1009 int ret;
1010 u16 ra_tid; 964 u16 ra_tid;
1011 965
1012 if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) || 966 if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
@@ -1024,11 +978,6 @@ static int iwl5000_txq_agg_enable(struct iwl_priv *priv, int txq_id,
1024 iwl_sta_tx_modify_enable_tid(priv, sta_id, tid); 978 iwl_sta_tx_modify_enable_tid(priv, sta_id, tid);
1025 979
1026 spin_lock_irqsave(&priv->lock, flags); 980 spin_lock_irqsave(&priv->lock, flags);
1027 ret = iwl_grab_nic_access(priv);
1028 if (ret) {
1029 spin_unlock_irqrestore(&priv->lock, flags);
1030 return ret;
1031 }
1032 981
1033 /* Stop this Tx queue before configuring it */ 982 /* Stop this Tx queue before configuring it */
1034 iwl5000_tx_queue_stop_scheduler(priv, txq_id); 983 iwl5000_tx_queue_stop_scheduler(priv, txq_id);
@@ -1064,7 +1013,6 @@ static int iwl5000_txq_agg_enable(struct iwl_priv *priv, int txq_id,
1064 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */ 1013 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
1065 iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1); 1014 iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
1066 1015
1067 iwl_release_nic_access(priv);
1068 spin_unlock_irqrestore(&priv->lock, flags); 1016 spin_unlock_irqrestore(&priv->lock, flags);
1069 1017
1070 return 0; 1018 return 0;
@@ -1073,8 +1021,6 @@ static int iwl5000_txq_agg_enable(struct iwl_priv *priv, int txq_id,
1073static int iwl5000_txq_agg_disable(struct iwl_priv *priv, u16 txq_id, 1021static int iwl5000_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
1074 u16 ssn_idx, u8 tx_fifo) 1022 u16 ssn_idx, u8 tx_fifo)
1075{ 1023{
1076 int ret;
1077
1078 if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) || 1024 if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
1079 (IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES <= txq_id)) { 1025 (IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES <= txq_id)) {
1080 IWL_ERR(priv, 1026 IWL_ERR(priv,
@@ -1084,10 +1030,6 @@ static int iwl5000_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
1084 return -EINVAL; 1030 return -EINVAL;
1085 } 1031 }
1086 1032
1087 ret = iwl_grab_nic_access(priv);
1088 if (ret)
1089 return ret;
1090
1091 iwl5000_tx_queue_stop_scheduler(priv, txq_id); 1033 iwl5000_tx_queue_stop_scheduler(priv, txq_id);
1092 1034
1093 iwl_clear_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1 << txq_id)); 1035 iwl_clear_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1 << txq_id));
@@ -1101,15 +1043,16 @@ static int iwl5000_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
1101 iwl_txq_ctx_deactivate(priv, txq_id); 1043 iwl_txq_ctx_deactivate(priv, txq_id);
1102 iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0); 1044 iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
1103 1045
1104 iwl_release_nic_access(priv);
1105
1106 return 0; 1046 return 0;
1107} 1047}
1108 1048
1109u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data) 1049u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
1110{ 1050{
1111 u16 size = (u16)sizeof(struct iwl_addsta_cmd); 1051 u16 size = (u16)sizeof(struct iwl_addsta_cmd);
1112 memcpy(data, cmd, size); 1052 struct iwl_addsta_cmd *addsta = (struct iwl_addsta_cmd *)data;
1053 memcpy(addsta, cmd, size);
1054 /* resrved in 5000 */
1055 addsta->rate_n_flags = cpu_to_le16(0);
1113 return size; 1056 return size;
1114} 1057}
1115 1058
@@ -1434,6 +1377,17 @@ static void iwl5000_temperature(struct iwl_priv *priv)
1434 priv->temperature = le32_to_cpu(priv->statistics.general.temperature); 1377 priv->temperature = le32_to_cpu(priv->statistics.general.temperature);
1435} 1378}
1436 1379
1380static void iwl5150_temperature(struct iwl_priv *priv)
1381{
1382 u32 vt = 0;
1383 s32 offset = iwl_temp_calib_to_offset(priv);
1384
1385 vt = le32_to_cpu(priv->statistics.general.temperature);
1386 vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
1387 /* now vt hold the temperature in Kelvin */
1388 priv->temperature = KELVIN_TO_CELSIUS(vt);
1389}
1390
1437/* Calc max signal level (dBm) among 3 possible receivers */ 1391/* Calc max signal level (dBm) among 3 possible receivers */
1438int iwl5000_calc_rssi(struct iwl_priv *priv, 1392int iwl5000_calc_rssi(struct iwl_priv *priv,
1439 struct iwl_rx_phy_res *rx_resp) 1393 struct iwl_rx_phy_res *rx_resp)
@@ -1474,6 +1428,8 @@ int iwl5000_calc_rssi(struct iwl_priv *priv,
1474 1428
1475struct iwl_hcmd_ops iwl5000_hcmd = { 1429struct iwl_hcmd_ops iwl5000_hcmd = {
1476 .rxon_assoc = iwl5000_send_rxon_assoc, 1430 .rxon_assoc = iwl5000_send_rxon_assoc,
1431 .commit_rxon = iwl_commit_rxon,
1432 .set_rxon_chain = iwl_set_rxon_chain,
1477}; 1433};
1478 1434
1479struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = { 1435struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
@@ -1502,7 +1458,6 @@ struct iwl_lib_ops iwl5000_lib = {
1502 .init_alive_start = iwl5000_init_alive_start, 1458 .init_alive_start = iwl5000_init_alive_start,
1503 .alive_notify = iwl5000_alive_notify, 1459 .alive_notify = iwl5000_alive_notify,
1504 .send_tx_power = iwl5000_send_tx_power, 1460 .send_tx_power = iwl5000_send_tx_power,
1505 .temperature = iwl5000_temperature,
1506 .update_chain_flags = iwl_update_chain_flags, 1461 .update_chain_flags = iwl_update_chain_flags,
1507 .apm_ops = { 1462 .apm_ops = {
1508 .init = iwl5000_apm_init, 1463 .init = iwl5000_apm_init,
@@ -1527,6 +1482,63 @@ struct iwl_lib_ops iwl5000_lib = {
1527 .calib_version = iwl5000_eeprom_calib_version, 1482 .calib_version = iwl5000_eeprom_calib_version,
1528 .query_addr = iwl5000_eeprom_query_addr, 1483 .query_addr = iwl5000_eeprom_query_addr,
1529 }, 1484 },
1485 .post_associate = iwl_post_associate,
1486 .isr = iwl_isr_ict,
1487 .config_ap = iwl_config_ap,
1488 .temp_ops = {
1489 .temperature = iwl5000_temperature,
1490 .set_ct_kill = iwl5000_set_ct_threshold,
1491 },
1492};
1493
1494static struct iwl_lib_ops iwl5150_lib = {
1495 .set_hw_params = iwl5000_hw_set_hw_params,
1496 .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
1497 .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
1498 .txq_set_sched = iwl5000_txq_set_sched,
1499 .txq_agg_enable = iwl5000_txq_agg_enable,
1500 .txq_agg_disable = iwl5000_txq_agg_disable,
1501 .txq_attach_buf_to_tfd = iwl_hw_txq_attach_buf_to_tfd,
1502 .txq_free_tfd = iwl_hw_txq_free_tfd,
1503 .txq_init = iwl_hw_tx_queue_init,
1504 .rx_handler_setup = iwl5000_rx_handler_setup,
1505 .setup_deferred_work = iwl5000_setup_deferred_work,
1506 .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
1507 .load_ucode = iwl5000_load_ucode,
1508 .init_alive_start = iwl5000_init_alive_start,
1509 .alive_notify = iwl5000_alive_notify,
1510 .send_tx_power = iwl5000_send_tx_power,
1511 .update_chain_flags = iwl_update_chain_flags,
1512 .apm_ops = {
1513 .init = iwl5000_apm_init,
1514 .reset = iwl5000_apm_reset,
1515 .stop = iwl5000_apm_stop,
1516 .config = iwl5000_nic_config,
1517 .set_pwr_src = iwl_set_pwr_src,
1518 },
1519 .eeprom_ops = {
1520 .regulatory_bands = {
1521 EEPROM_5000_REG_BAND_1_CHANNELS,
1522 EEPROM_5000_REG_BAND_2_CHANNELS,
1523 EEPROM_5000_REG_BAND_3_CHANNELS,
1524 EEPROM_5000_REG_BAND_4_CHANNELS,
1525 EEPROM_5000_REG_BAND_5_CHANNELS,
1526 EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
1527 EEPROM_5000_REG_BAND_52_FAT_CHANNELS
1528 },
1529 .verify_signature = iwlcore_eeprom_verify_signature,
1530 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
1531 .release_semaphore = iwlcore_eeprom_release_semaphore,
1532 .calib_version = iwl5000_eeprom_calib_version,
1533 .query_addr = iwl5000_eeprom_query_addr,
1534 },
1535 .post_associate = iwl_post_associate,
1536 .isr = iwl_isr_ict,
1537 .config_ap = iwl_config_ap,
1538 .temp_ops = {
1539 .temperature = iwl5150_temperature,
1540 .set_ct_kill = iwl5150_set_ct_threshold,
1541 },
1530}; 1542};
1531 1543
1532struct iwl_ops iwl5000_ops = { 1544struct iwl_ops iwl5000_ops = {
@@ -1535,6 +1547,12 @@ struct iwl_ops iwl5000_ops = {
1535 .utils = &iwl5000_hcmd_utils, 1547 .utils = &iwl5000_hcmd_utils,
1536}; 1548};
1537 1549
1550static struct iwl_ops iwl5150_ops = {
1551 .lib = &iwl5150_lib,
1552 .hcmd = &iwl5000_hcmd,
1553 .utils = &iwl5000_hcmd_utils,
1554};
1555
1538struct iwl_mod_params iwl50_mod_params = { 1556struct iwl_mod_params iwl50_mod_params = {
1539 .num_of_queues = IWL50_NUM_QUEUES, 1557 .num_of_queues = IWL50_NUM_QUEUES,
1540 .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES, 1558 .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
@@ -1630,7 +1648,7 @@ struct iwl_cfg iwl5150_agn_cfg = {
1630 .ucode_api_max = IWL5150_UCODE_API_MAX, 1648 .ucode_api_max = IWL5150_UCODE_API_MAX,
1631 .ucode_api_min = IWL5150_UCODE_API_MIN, 1649 .ucode_api_min = IWL5150_UCODE_API_MIN,
1632 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N, 1650 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
1633 .ops = &iwl5000_ops, 1651 .ops = &iwl5150_ops,
1634 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE, 1652 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
1635 .eeprom_ver = EEPROM_5050_EEPROM_VERSION, 1653 .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
1636 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION, 1654 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
@@ -1643,9 +1661,6 @@ struct iwl_cfg iwl5150_agn_cfg = {
1643MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX)); 1661MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX));
1644MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX)); 1662MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX));
1645 1663
1646module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
1647MODULE_PARM_DESC(disable50,
1648 "manually disable the 50XX radio (default 0 [radio on])");
1649module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444); 1664module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
1650MODULE_PARM_DESC(swcrypto50, 1665MODULE_PARM_DESC(swcrypto50,
1651 "using software crypto engine (default 0 [hardware])\n"); 1666 "using software crypto engine (default 0 [hardware])\n");
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index cab7842a73aa..ff20e5048a55 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -52,7 +52,7 @@
52/* max allowed rate miss before sync LQ cmd */ 52/* max allowed rate miss before sync LQ cmd */
53#define IWL_MISSED_RATE_MAX 15 53#define IWL_MISSED_RATE_MAX 15
54/* max time to accum history 2 seconds */ 54/* max time to accum history 2 seconds */
55#define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ) 55#define IWL_RATE_SCALE_FLUSH_INTVL (3*HZ)
56 56
57static u8 rs_ht_to_legacy[] = { 57static u8 rs_ht_to_legacy[] = {
58 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX, 58 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
@@ -100,6 +100,7 @@ struct iwl_scale_tbl_info {
100 u8 is_fat; /* 1 = 40 MHz channel width */ 100 u8 is_fat; /* 1 = 40 MHz channel width */
101 u8 is_dup; /* 1 = duplicated data streams */ 101 u8 is_dup; /* 1 = duplicated data streams */
102 u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */ 102 u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */
103 u8 max_search; /* maximun number of tables we can search */
103 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */ 104 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */
104 u32 current_rate; /* rate_n_flags, uCode API format */ 105 u32 current_rate; /* rate_n_flags, uCode API format */
105 struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */ 106 struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */
@@ -135,7 +136,7 @@ struct iwl_lq_sta {
135 u32 table_count; 136 u32 table_count;
136 u32 total_failed; /* total failed frames, any/all rates */ 137 u32 total_failed; /* total failed frames, any/all rates */
137 u32 total_success; /* total successful frames, any/all rates */ 138 u32 total_success; /* total successful frames, any/all rates */
138 u32 flush_timer; /* time staying in mode before new search */ 139 u64 flush_timer; /* time staying in mode before new search */
139 140
140 u8 action_counter; /* # mode-switch actions tried */ 141 u8 action_counter; /* # mode-switch actions tried */
141 u8 is_green; 142 u8 is_green;
@@ -160,6 +161,7 @@ struct iwl_lq_sta {
160#ifdef CONFIG_MAC80211_DEBUGFS 161#ifdef CONFIG_MAC80211_DEBUGFS
161 struct dentry *rs_sta_dbgfs_scale_table_file; 162 struct dentry *rs_sta_dbgfs_scale_table_file;
162 struct dentry *rs_sta_dbgfs_stats_table_file; 163 struct dentry *rs_sta_dbgfs_stats_table_file;
164 struct dentry *rs_sta_dbgfs_rate_scale_data_file;
163 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file; 165 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file;
164 u32 dbg_fixed_rate; 166 u32 dbg_fixed_rate;
165#endif 167#endif
@@ -167,10 +169,12 @@ struct iwl_lq_sta {
167 169
168 /* used to be in sta_info */ 170 /* used to be in sta_info */
169 int last_txrate_idx; 171 int last_txrate_idx;
172 /* last tx rate_n_flags */
173 u32 last_rate_n_flags;
170}; 174};
171 175
172static void rs_rate_scale_perform(struct iwl_priv *priv, 176static void rs_rate_scale_perform(struct iwl_priv *priv,
173 struct ieee80211_hdr *hdr, 177 struct sk_buff *skb,
174 struct ieee80211_sta *sta, 178 struct ieee80211_sta *sta,
175 struct iwl_lq_sta *lq_sta); 179 struct iwl_lq_sta *lq_sta);
176static void rs_fill_link_cmd(const struct iwl_priv *priv, 180static void rs_fill_link_cmd(const struct iwl_priv *priv,
@@ -191,7 +195,7 @@ static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
191 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits 195 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
192 * "G" is the only table that supports CCK (the first 4 rates). 196 * "G" is the only table that supports CCK (the first 4 rates).
193 */ 197 */
194/*FIXME:RS:need to separate tables for MIMO2/MIMO3*/ 198
195static s32 expected_tpt_A[IWL_RATE_COUNT] = { 199static s32 expected_tpt_A[IWL_RATE_COUNT] = {
196 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186 200 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
197}; 201};
@@ -208,11 +212,11 @@ static s32 expected_tpt_siso20MHzSGI[IWL_RATE_COUNT] = {
208 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211 212 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211
209}; 213};
210 214
211static s32 expected_tpt_mimo20MHz[IWL_RATE_COUNT] = { 215static s32 expected_tpt_mimo2_20MHz[IWL_RATE_COUNT] = {
212 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251 216 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251
213}; 217};
214 218
215static s32 expected_tpt_mimo20MHzSGI[IWL_RATE_COUNT] = { 219static s32 expected_tpt_mimo2_20MHzSGI[IWL_RATE_COUNT] = {
216 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257 220 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257
217}; 221};
218 222
@@ -224,14 +228,50 @@ static s32 expected_tpt_siso40MHzSGI[IWL_RATE_COUNT] = {
224 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264 228 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264
225}; 229};
226 230
227static s32 expected_tpt_mimo40MHz[IWL_RATE_COUNT] = { 231static s32 expected_tpt_mimo2_40MHz[IWL_RATE_COUNT] = {
228 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289 232 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289
229}; 233};
230 234
231static s32 expected_tpt_mimo40MHzSGI[IWL_RATE_COUNT] = { 235static s32 expected_tpt_mimo2_40MHzSGI[IWL_RATE_COUNT] = {
232 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293 236 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
233}; 237};
234 238
239/* Expected throughput metric MIMO3 */
240static s32 expected_tpt_mimo3_20MHz[IWL_RATE_COUNT] = {
241 0, 0, 0, 0, 99, 99, 153, 186, 208, 239, 256, 263, 268
242};
243
244static s32 expected_tpt_mimo3_20MHzSGI[IWL_RATE_COUNT] = {
245 0, 0, 0, 0, 106, 106, 162, 194, 215, 246, 262, 268, 273
246};
247
248static s32 expected_tpt_mimo3_40MHz[IWL_RATE_COUNT] = {
249 0, 0, 0, 0, 152, 152, 211, 239, 255, 279, 290, 294, 297
250};
251
252static s32 expected_tpt_mimo3_40MHzSGI[IWL_RATE_COUNT] = {
253 0, 0, 0, 0, 160, 160, 219, 245, 261, 284, 294, 297, 300
254};
255
256/* mbps, mcs */
257const static struct iwl_rate_mcs_info iwl_rate_mcs[IWL_RATE_COUNT] = {
258 {"1", ""},
259 {"2", ""},
260 {"5.5", ""},
261 {"11", ""},
262 {"6", "BPSK 1/2"},
263 {"9", "BPSK 1/2"},
264 {"12", "QPSK 1/2"},
265 {"18", "QPSK 3/4"},
266 {"24", "16QAM 1/2"},
267 {"36", "16QAM 3/4"},
268 {"48", "64QAM 2/3"},
269 {"54", "64QAM 3/4"},
270 {"60", "64QAM 5/6"}
271};
272
273#define MCS_INDEX_PER_STREAM (8)
274
235static inline u8 rs_extract_rate(u32 rate_n_flags) 275static inline u8 rs_extract_rate(u32 rate_n_flags)
236{ 276{
237 return (u8)(rate_n_flags & 0xFF); 277 return (u8)(rate_n_flags & 0xFF);
@@ -543,6 +583,7 @@ static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
543 tbl->is_dup = 0; 583 tbl->is_dup = 0;
544 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS); 584 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
545 tbl->lq_type = LQ_NONE; 585 tbl->lq_type = LQ_NONE;
586 tbl->max_search = IWL_MAX_SEARCH;
546 587
547 /* legacy rate format */ 588 /* legacy rate format */
548 if (!(rate_n_flags & RATE_MCS_HT_MSK)) { 589 if (!(rate_n_flags & RATE_MCS_HT_MSK)) {
@@ -576,8 +617,10 @@ static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
576 tbl->lq_type = LQ_MIMO2; 617 tbl->lq_type = LQ_MIMO2;
577 /* MIMO3 */ 618 /* MIMO3 */
578 } else { 619 } else {
579 if (num_of_ant == 3) 620 if (num_of_ant == 3) {
621 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
580 tbl->lq_type = LQ_MIMO3; 622 tbl->lq_type = LQ_MIMO3;
623 }
581 } 624 }
582 } 625 }
583 return 0; 626 return 0;
@@ -611,19 +654,19 @@ static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
611 return 1; 654 return 1;
612} 655}
613 656
614/* FIXME:RS: in 4965 we don't use greenfield at all */ 657/* in 4965 we don't use greenfield at all */
615/* FIXME:RS: don't use greenfield for now in TX */ 658static inline u8 rs_use_green(struct iwl_priv *priv,
616#if 0 659 struct ieee80211_conf *conf)
617static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf)
618{ 660{
619 return (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && 661 u8 is_green;
620 priv->current_ht_config.is_green_field && 662
621 !priv->current_ht_config.non_GF_STA_present; 663 if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)
622} 664 is_green = 0;
623#endif 665 else
624static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf) 666 is_green = (conf_is_ht(conf) &&
625{ 667 priv->current_ht_config.is_green_field &&
626 return 0; 668 !priv->current_ht_config.non_GF_STA_present);
669 return is_green;
627} 670}
628 671
629/** 672/**
@@ -735,6 +778,7 @@ static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta,
735 778
736 tbl->is_fat = 0; 779 tbl->is_fat = 0;
737 tbl->is_SGI = 0; 780 tbl->is_SGI = 0;
781 tbl->max_search = IWL_MAX_SEARCH;
738 } 782 }
739 783
740 rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type); 784 rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
@@ -793,7 +837,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
793 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n"); 837 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
794 838
795 if (!ieee80211_is_data(hdr->frame_control) || 839 if (!ieee80211_is_data(hdr->frame_control) ||
796 is_multicast_ether_addr(hdr->addr1)) 840 info->flags & IEEE80211_TX_CTL_NO_ACK)
797 return; 841 return;
798 842
799 /* This packet was aggregated but doesn't carry rate scale info */ 843 /* This packet was aggregated but doesn't carry rate scale info */
@@ -902,6 +946,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
902 * else look up the rate that was, finally, successful. 946 * else look up the rate that was, finally, successful.
903 */ 947 */
904 tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags); 948 tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags);
949 lq_sta->last_rate_n_flags = tx_rate;
905 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index); 950 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
906 951
907 /* Update frame history window with "success" if Tx got ACKed ... */ 952 /* Update frame history window with "success" if Tx got ACKed ... */
@@ -958,7 +1003,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
958 1003
959 /* See if there's a better rate or modulation mode to try. */ 1004 /* See if there's a better rate or modulation mode to try. */
960 if (sta && sta->supp_rates[sband->band]) 1005 if (sta && sta->supp_rates[sband->band])
961 rs_rate_scale_perform(priv, hdr, sta, lq_sta); 1006 rs_rate_scale_perform(priv, skb, sta, lq_sta);
962out: 1007out:
963 return; 1008 return;
964} 1009}
@@ -988,6 +1033,8 @@ static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy,
988 lq_sta->table_count = 0; 1033 lq_sta->table_count = 0;
989 lq_sta->total_failed = 0; 1034 lq_sta->total_failed = 0;
990 lq_sta->total_success = 0; 1035 lq_sta->total_success = 0;
1036 lq_sta->flush_timer = jiffies;
1037 lq_sta->action_counter = 0;
991} 1038}
992 1039
993/* 1040/*
@@ -1011,17 +1058,26 @@ static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta,
1011 tbl->expected_tpt = expected_tpt_siso20MHzSGI; 1058 tbl->expected_tpt = expected_tpt_siso20MHzSGI;
1012 else 1059 else
1013 tbl->expected_tpt = expected_tpt_siso20MHz; 1060 tbl->expected_tpt = expected_tpt_siso20MHz;
1014 1061 } else if (is_mimo2(tbl->lq_type)) {
1015 } else if (is_mimo(tbl->lq_type)) { /* FIXME:need to separate mimo2/3 */
1016 if (tbl->is_fat && !lq_sta->is_dup) 1062 if (tbl->is_fat && !lq_sta->is_dup)
1017 if (tbl->is_SGI) 1063 if (tbl->is_SGI)
1018 tbl->expected_tpt = expected_tpt_mimo40MHzSGI; 1064 tbl->expected_tpt = expected_tpt_mimo2_40MHzSGI;
1019 else 1065 else
1020 tbl->expected_tpt = expected_tpt_mimo40MHz; 1066 tbl->expected_tpt = expected_tpt_mimo2_40MHz;
1021 else if (tbl->is_SGI) 1067 else if (tbl->is_SGI)
1022 tbl->expected_tpt = expected_tpt_mimo20MHzSGI; 1068 tbl->expected_tpt = expected_tpt_mimo2_20MHzSGI;
1023 else 1069 else
1024 tbl->expected_tpt = expected_tpt_mimo20MHz; 1070 tbl->expected_tpt = expected_tpt_mimo2_20MHz;
1071 } else if (is_mimo3(tbl->lq_type)) {
1072 if (tbl->is_fat && !lq_sta->is_dup)
1073 if (tbl->is_SGI)
1074 tbl->expected_tpt = expected_tpt_mimo3_40MHzSGI;
1075 else
1076 tbl->expected_tpt = expected_tpt_mimo3_40MHz;
1077 else if (tbl->is_SGI)
1078 tbl->expected_tpt = expected_tpt_mimo3_20MHzSGI;
1079 else
1080 tbl->expected_tpt = expected_tpt_mimo3_20MHz;
1025 } else 1081 } else
1026 tbl->expected_tpt = expected_tpt_G; 1082 tbl->expected_tpt = expected_tpt_G;
1027} 1083}
@@ -1130,7 +1186,7 @@ static s32 rs_get_best_rate(struct iwl_priv *priv,
1130} 1186}
1131 1187
1132/* 1188/*
1133 * Set up search table for MIMO 1189 * Set up search table for MIMO2
1134 */ 1190 */
1135static int rs_switch_to_mimo2(struct iwl_priv *priv, 1191static int rs_switch_to_mimo2(struct iwl_priv *priv,
1136 struct iwl_lq_sta *lq_sta, 1192 struct iwl_lq_sta *lq_sta,
@@ -1158,10 +1214,10 @@ static int rs_switch_to_mimo2(struct iwl_priv *priv,
1158 tbl->lq_type = LQ_MIMO2; 1214 tbl->lq_type = LQ_MIMO2;
1159 tbl->is_dup = lq_sta->is_dup; 1215 tbl->is_dup = lq_sta->is_dup;
1160 tbl->action = 0; 1216 tbl->action = 0;
1217 tbl->max_search = IWL_MAX_SEARCH;
1161 rate_mask = lq_sta->active_mimo2_rate; 1218 rate_mask = lq_sta->active_mimo2_rate;
1162 1219
1163 if (priv->current_ht_config.supported_chan_width 1220 if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
1164 == IWL_CHANNEL_WIDTH_40MHZ)
1165 tbl->is_fat = 1; 1221 tbl->is_fat = 1;
1166 else 1222 else
1167 tbl->is_fat = 0; 1223 tbl->is_fat = 0;
@@ -1183,7 +1239,73 @@ static int rs_switch_to_mimo2(struct iwl_priv *priv,
1183 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); 1239 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1184 1240
1185 IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask); 1241 IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask);
1242 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1243 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
1244 rate, rate_mask);
1245 return -1;
1246 }
1247 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
1248
1249 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
1250 tbl->current_rate, is_green);
1251 return 0;
1252}
1253
1254/*
1255 * Set up search table for MIMO3
1256 */
1257static int rs_switch_to_mimo3(struct iwl_priv *priv,
1258 struct iwl_lq_sta *lq_sta,
1259 struct ieee80211_conf *conf,
1260 struct ieee80211_sta *sta,
1261 struct iwl_scale_tbl_info *tbl, int index)
1262{
1263 u16 rate_mask;
1264 s32 rate;
1265 s8 is_green = lq_sta->is_green;
1266
1267 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1268 return -1;
1269
1270 if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
1271 == WLAN_HT_CAP_SM_PS_STATIC)
1272 return -1;
1273
1274 /* Need both Tx chains/antennas to support MIMO */
1275 if (priv->hw_params.tx_chains_num < 3)
1276 return -1;
1277
1278 IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO3\n");
1279
1280 tbl->lq_type = LQ_MIMO3;
1281 tbl->is_dup = lq_sta->is_dup;
1282 tbl->action = 0;
1283 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
1284 rate_mask = lq_sta->active_mimo3_rate;
1285
1286 if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
1287 tbl->is_fat = 1;
1288 else
1289 tbl->is_fat = 0;
1186 1290
1291 /* FIXME: - don't toggle SGI here
1292 if (tbl->is_fat) {
1293 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY)
1294 tbl->is_SGI = 1;
1295 else
1296 tbl->is_SGI = 0;
1297 } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY)
1298 tbl->is_SGI = 1;
1299 else
1300 tbl->is_SGI = 0;
1301 */
1302
1303 rs_set_expected_tpt_table(lq_sta, tbl);
1304
1305 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1306
1307 IWL_DEBUG_RATE(priv, "LQ: MIMO3 best rate %d mask %X\n",
1308 rate, rate_mask);
1187 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { 1309 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1188 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n", 1310 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
1189 rate, rate_mask); 1311 rate, rate_mask);
@@ -1217,10 +1339,10 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
1217 tbl->is_dup = lq_sta->is_dup; 1339 tbl->is_dup = lq_sta->is_dup;
1218 tbl->lq_type = LQ_SISO; 1340 tbl->lq_type = LQ_SISO;
1219 tbl->action = 0; 1341 tbl->action = 0;
1342 tbl->max_search = IWL_MAX_SEARCH;
1220 rate_mask = lq_sta->active_siso_rate; 1343 rate_mask = lq_sta->active_siso_rate;
1221 1344
1222 if (priv->current_ht_config.supported_chan_width 1345 if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
1223 == IWL_CHANNEL_WIDTH_40MHZ)
1224 tbl->is_fat = 1; 1346 tbl->is_fat = 1;
1225 else 1347 else
1226 tbl->is_fat = 0; 1348 tbl->is_fat = 0;
@@ -1274,15 +1396,15 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1274 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1396 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1275 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1397 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1276 int ret = 0; 1398 int ret = 0;
1399 u8 update_search_tbl_counter = 0;
1277 1400
1278 for (; ;) { 1401 for (; ;) {
1402 lq_sta->action_counter++;
1279 switch (tbl->action) { 1403 switch (tbl->action) {
1280 case IWL_LEGACY_SWITCH_ANTENNA1: 1404 case IWL_LEGACY_SWITCH_ANTENNA1:
1281 case IWL_LEGACY_SWITCH_ANTENNA2: 1405 case IWL_LEGACY_SWITCH_ANTENNA2:
1282 IWL_DEBUG_RATE(priv, "LQ: Legacy toggle Antenna\n"); 1406 IWL_DEBUG_RATE(priv, "LQ: Legacy toggle Antenna\n");
1283 1407
1284 lq_sta->action_counter++;
1285
1286 if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 && 1408 if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 &&
1287 tx_chains_num <= 1) || 1409 tx_chains_num <= 1) ||
1288 (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 && 1410 (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 &&
@@ -1298,6 +1420,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1298 1420
1299 if (rs_toggle_antenna(valid_tx_ant, 1421 if (rs_toggle_antenna(valid_tx_ant,
1300 &search_tbl->current_rate, search_tbl)) { 1422 &search_tbl->current_rate, search_tbl)) {
1423 update_search_tbl_counter = 1;
1301 rs_set_expected_tpt_table(lq_sta, search_tbl); 1424 rs_set_expected_tpt_table(lq_sta, search_tbl);
1302 goto out; 1425 goto out;
1303 } 1426 }
@@ -1342,9 +1465,29 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1342 goto out; 1465 goto out;
1343 } 1466 }
1344 break; 1467 break;
1468
1469 case IWL_LEGACY_SWITCH_MIMO3_ABC:
1470 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO3\n");
1471
1472 /* Set up search table to try MIMO3 */
1473 memcpy(search_tbl, tbl, sz);
1474 search_tbl->is_SGI = 0;
1475
1476 search_tbl->ant_type = ANT_ABC;
1477
1478 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1479 break;
1480
1481 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1482 search_tbl, index);
1483 if (!ret) {
1484 lq_sta->action_counter = 0;
1485 goto out;
1486 }
1487 break;
1345 } 1488 }
1346 tbl->action++; 1489 tbl->action++;
1347 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2_BC) 1490 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
1348 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; 1491 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
1349 1492
1350 if (tbl->action == start_action) 1493 if (tbl->action == start_action)
@@ -1357,8 +1500,10 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1357out: 1500out:
1358 lq_sta->search_better_tbl = 1; 1501 lq_sta->search_better_tbl = 1;
1359 tbl->action++; 1502 tbl->action++;
1360 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2_BC) 1503 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
1361 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; 1504 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
1505 if (update_search_tbl_counter)
1506 search_tbl->action = tbl->action;
1362 return 0; 1507 return 0;
1363 1508
1364} 1509}
@@ -1381,6 +1526,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1381 u8 start_action = tbl->action; 1526 u8 start_action = tbl->action;
1382 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1527 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1383 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1528 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1529 u8 update_search_tbl_counter = 0;
1384 int ret; 1530 int ret;
1385 1531
1386 for (;;) { 1532 for (;;) {
@@ -1401,8 +1547,10 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1401 1547
1402 memcpy(search_tbl, tbl, sz); 1548 memcpy(search_tbl, tbl, sz);
1403 if (rs_toggle_antenna(valid_tx_ant, 1549 if (rs_toggle_antenna(valid_tx_ant,
1404 &search_tbl->current_rate, search_tbl)) 1550 &search_tbl->current_rate, search_tbl)) {
1551 update_search_tbl_counter = 1;
1405 goto out; 1552 goto out;
1553 }
1406 break; 1554 break;
1407 case IWL_SISO_SWITCH_MIMO2_AB: 1555 case IWL_SISO_SWITCH_MIMO2_AB:
1408 case IWL_SISO_SWITCH_MIMO2_AC: 1556 case IWL_SISO_SWITCH_MIMO2_AC:
@@ -1456,10 +1604,25 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1456 search_tbl->current_rate = 1604 search_tbl->current_rate =
1457 rate_n_flags_from_tbl(priv, search_tbl, 1605 rate_n_flags_from_tbl(priv, search_tbl,
1458 index, is_green); 1606 index, is_green);
1607 update_search_tbl_counter = 1;
1459 goto out; 1608 goto out;
1609 case IWL_SISO_SWITCH_MIMO3_ABC:
1610 IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO3\n");
1611 memcpy(search_tbl, tbl, sz);
1612 search_tbl->is_SGI = 0;
1613 search_tbl->ant_type = ANT_ABC;
1614
1615 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1616 break;
1617
1618 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1619 search_tbl, index);
1620 if (!ret)
1621 goto out;
1622 break;
1460 } 1623 }
1461 tbl->action++; 1624 tbl->action++;
1462 if (tbl->action > IWL_SISO_SWITCH_GI) 1625 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
1463 tbl->action = IWL_SISO_SWITCH_ANTENNA1; 1626 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1464 1627
1465 if (tbl->action == start_action) 1628 if (tbl->action == start_action)
@@ -1471,15 +1634,18 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1471 out: 1634 out:
1472 lq_sta->search_better_tbl = 1; 1635 lq_sta->search_better_tbl = 1;
1473 tbl->action++; 1636 tbl->action++;
1474 if (tbl->action > IWL_SISO_SWITCH_GI) 1637 if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC)
1475 tbl->action = IWL_SISO_SWITCH_ANTENNA1; 1638 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1639 if (update_search_tbl_counter)
1640 search_tbl->action = tbl->action;
1641
1476 return 0; 1642 return 0;
1477} 1643}
1478 1644
1479/* 1645/*
1480 * Try to switch to new modulation mode from MIMO 1646 * Try to switch to new modulation mode from MIMO2
1481 */ 1647 */
1482static int rs_move_mimo_to_other(struct iwl_priv *priv, 1648static int rs_move_mimo2_to_other(struct iwl_priv *priv,
1483 struct iwl_lq_sta *lq_sta, 1649 struct iwl_lq_sta *lq_sta,
1484 struct ieee80211_conf *conf, 1650 struct ieee80211_conf *conf,
1485 struct ieee80211_sta *sta, int index) 1651 struct ieee80211_sta *sta, int index)
@@ -1494,6 +1660,7 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1494 u8 start_action = tbl->action; 1660 u8 start_action = tbl->action;
1495 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1661 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1496 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1662 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1663 u8 update_search_tbl_counter = 0;
1497 int ret; 1664 int ret;
1498 1665
1499 for (;;) { 1666 for (;;) {
@@ -1501,7 +1668,7 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1501 switch (tbl->action) { 1668 switch (tbl->action) {
1502 case IWL_MIMO2_SWITCH_ANTENNA1: 1669 case IWL_MIMO2_SWITCH_ANTENNA1:
1503 case IWL_MIMO2_SWITCH_ANTENNA2: 1670 case IWL_MIMO2_SWITCH_ANTENNA2:
1504 IWL_DEBUG_RATE(priv, "LQ: MIMO toggle Antennas\n"); 1671 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle Antennas\n");
1505 1672
1506 if (tx_chains_num <= 2) 1673 if (tx_chains_num <= 2)
1507 break; 1674 break;
@@ -1511,8 +1678,10 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1511 1678
1512 memcpy(search_tbl, tbl, sz); 1679 memcpy(search_tbl, tbl, sz);
1513 if (rs_toggle_antenna(valid_tx_ant, 1680 if (rs_toggle_antenna(valid_tx_ant,
1514 &search_tbl->current_rate, search_tbl)) 1681 &search_tbl->current_rate, search_tbl)) {
1682 update_search_tbl_counter = 1;
1515 goto out; 1683 goto out;
1684 }
1516 break; 1685 break;
1517 case IWL_MIMO2_SWITCH_SISO_A: 1686 case IWL_MIMO2_SWITCH_SISO_A:
1518 case IWL_MIMO2_SWITCH_SISO_B: 1687 case IWL_MIMO2_SWITCH_SISO_B:
@@ -1549,9 +1718,9 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1549 HT_SHORT_GI_40MHZ)) 1718 HT_SHORT_GI_40MHZ))
1550 break; 1719 break;
1551 1720
1552 IWL_DEBUG_RATE(priv, "LQ: MIMO toggle SGI/NGI\n"); 1721 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle SGI/NGI\n");
1553 1722
1554 /* Set up new search table for MIMO */ 1723 /* Set up new search table for MIMO2 */
1555 memcpy(search_tbl, tbl, sz); 1724 memcpy(search_tbl, tbl, sz);
1556 search_tbl->is_SGI = !tbl->is_SGI; 1725 search_tbl->is_SGI = !tbl->is_SGI;
1557 rs_set_expected_tpt_table(lq_sta, search_tbl); 1726 rs_set_expected_tpt_table(lq_sta, search_tbl);
@@ -1569,11 +1738,27 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1569 search_tbl->current_rate = 1738 search_tbl->current_rate =
1570 rate_n_flags_from_tbl(priv, search_tbl, 1739 rate_n_flags_from_tbl(priv, search_tbl,
1571 index, is_green); 1740 index, is_green);
1741 update_search_tbl_counter = 1;
1572 goto out; 1742 goto out;
1573 1743
1744 case IWL_MIMO2_SWITCH_MIMO3_ABC:
1745 IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to MIMO3\n");
1746 memcpy(search_tbl, tbl, sz);
1747 search_tbl->is_SGI = 0;
1748 search_tbl->ant_type = ANT_ABC;
1749
1750 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1751 break;
1752
1753 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1754 search_tbl, index);
1755 if (!ret)
1756 goto out;
1757
1758 break;
1574 } 1759 }
1575 tbl->action++; 1760 tbl->action++;
1576 if (tbl->action > IWL_MIMO2_SWITCH_GI) 1761 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1577 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; 1762 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
1578 1763
1579 if (tbl->action == start_action) 1764 if (tbl->action == start_action)
@@ -1584,8 +1769,153 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1584 out: 1769 out:
1585 lq_sta->search_better_tbl = 1; 1770 lq_sta->search_better_tbl = 1;
1586 tbl->action++; 1771 tbl->action++;
1587 if (tbl->action > IWL_MIMO2_SWITCH_GI) 1772 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1588 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; 1773 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
1774 if (update_search_tbl_counter)
1775 search_tbl->action = tbl->action;
1776
1777 return 0;
1778
1779}
1780
1781/*
1782 * Try to switch to new modulation mode from MIMO3
1783 */
1784static int rs_move_mimo3_to_other(struct iwl_priv *priv,
1785 struct iwl_lq_sta *lq_sta,
1786 struct ieee80211_conf *conf,
1787 struct ieee80211_sta *sta, int index)
1788{
1789 s8 is_green = lq_sta->is_green;
1790 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1791 struct iwl_scale_tbl_info *search_tbl =
1792 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1793 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1794 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1795 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1796 u8 start_action = tbl->action;
1797 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1798 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1799 int ret;
1800 u8 update_search_tbl_counter = 0;
1801
1802 for (;;) {
1803 lq_sta->action_counter++;
1804 switch (tbl->action) {
1805 case IWL_MIMO3_SWITCH_ANTENNA1:
1806 case IWL_MIMO3_SWITCH_ANTENNA2:
1807 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle Antennas\n");
1808
1809 if (tx_chains_num <= 3)
1810 break;
1811
1812 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1813 break;
1814
1815 memcpy(search_tbl, tbl, sz);
1816 if (rs_toggle_antenna(valid_tx_ant,
1817 &search_tbl->current_rate, search_tbl))
1818 goto out;
1819 break;
1820 case IWL_MIMO3_SWITCH_SISO_A:
1821 case IWL_MIMO3_SWITCH_SISO_B:
1822 case IWL_MIMO3_SWITCH_SISO_C:
1823 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to SISO\n");
1824
1825 /* Set up new search table for SISO */
1826 memcpy(search_tbl, tbl, sz);
1827
1828 if (tbl->action == IWL_MIMO3_SWITCH_SISO_A)
1829 search_tbl->ant_type = ANT_A;
1830 else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B)
1831 search_tbl->ant_type = ANT_B;
1832 else
1833 search_tbl->ant_type = ANT_C;
1834
1835 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1836 break;
1837
1838 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
1839 search_tbl, index);
1840 if (!ret)
1841 goto out;
1842
1843 break;
1844
1845 case IWL_MIMO3_SWITCH_MIMO2_AB:
1846 case IWL_MIMO3_SWITCH_MIMO2_AC:
1847 case IWL_MIMO3_SWITCH_MIMO2_BC:
1848 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to MIMO2\n");
1849
1850 memcpy(search_tbl, tbl, sz);
1851 search_tbl->is_SGI = 0;
1852 if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB)
1853 search_tbl->ant_type = ANT_AB;
1854 else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC)
1855 search_tbl->ant_type = ANT_AC;
1856 else
1857 search_tbl->ant_type = ANT_BC;
1858
1859 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1860 break;
1861
1862 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
1863 search_tbl, index);
1864 if (!ret)
1865 goto out;
1866
1867 break;
1868
1869 case IWL_MIMO3_SWITCH_GI:
1870 if (!tbl->is_fat &&
1871 !(priv->current_ht_config.sgf &
1872 HT_SHORT_GI_20MHZ))
1873 break;
1874 if (tbl->is_fat &&
1875 !(priv->current_ht_config.sgf &
1876 HT_SHORT_GI_40MHZ))
1877 break;
1878
1879 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle SGI/NGI\n");
1880
1881 /* Set up new search table for MIMO */
1882 memcpy(search_tbl, tbl, sz);
1883 search_tbl->is_SGI = !tbl->is_SGI;
1884 rs_set_expected_tpt_table(lq_sta, search_tbl);
1885 /*
1886 * If active table already uses the fastest possible
1887 * modulation (dual stream with short guard interval),
1888 * and it's working well, there's no need to look
1889 * for a better type of modulation!
1890 */
1891 if (tbl->is_SGI) {
1892 s32 tpt = lq_sta->last_tpt / 100;
1893 if (tpt >= search_tbl->expected_tpt[index])
1894 break;
1895 }
1896 search_tbl->current_rate =
1897 rate_n_flags_from_tbl(priv, search_tbl,
1898 index, is_green);
1899 update_search_tbl_counter = 1;
1900 goto out;
1901 }
1902 tbl->action++;
1903 if (tbl->action > IWL_MIMO3_SWITCH_GI)
1904 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
1905
1906 if (tbl->action == start_action)
1907 break;
1908 }
1909 search_tbl->lq_type = LQ_NONE;
1910 return 0;
1911 out:
1912 lq_sta->search_better_tbl = 1;
1913 tbl->action++;
1914 if (tbl->action > IWL_MIMO3_SWITCH_GI)
1915 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
1916 if (update_search_tbl_counter)
1917 search_tbl->action = tbl->action;
1918
1589 return 0; 1919 return 0;
1590 1920
1591} 1921}
@@ -1616,8 +1946,8 @@ static void rs_stay_in_table(struct iwl_lq_sta *lq_sta)
1616 /* Elapsed time using current modulation mode */ 1946 /* Elapsed time using current modulation mode */
1617 if (lq_sta->flush_timer) 1947 if (lq_sta->flush_timer)
1618 flush_interval_passed = 1948 flush_interval_passed =
1619 time_after(jiffies, 1949 time_after(jiffies,
1620 (unsigned long)(lq_sta->flush_timer + 1950 (unsigned long)(lq_sta->flush_timer +
1621 IWL_RATE_SCALE_FLUSH_INTVL)); 1951 IWL_RATE_SCALE_FLUSH_INTVL));
1622 1952
1623 /* 1953 /*
@@ -1676,12 +2006,14 @@ static void rs_stay_in_table(struct iwl_lq_sta *lq_sta)
1676 * Do rate scaling and search for new modulation mode. 2006 * Do rate scaling and search for new modulation mode.
1677 */ 2007 */
1678static void rs_rate_scale_perform(struct iwl_priv *priv, 2008static void rs_rate_scale_perform(struct iwl_priv *priv,
1679 struct ieee80211_hdr *hdr, 2009 struct sk_buff *skb,
1680 struct ieee80211_sta *sta, 2010 struct ieee80211_sta *sta,
1681 struct iwl_lq_sta *lq_sta) 2011 struct iwl_lq_sta *lq_sta)
1682{ 2012{
1683 struct ieee80211_hw *hw = priv->hw; 2013 struct ieee80211_hw *hw = priv->hw;
1684 struct ieee80211_conf *conf = &hw->conf; 2014 struct ieee80211_conf *conf = &hw->conf;
2015 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2016 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1685 int low = IWL_RATE_INVALID; 2017 int low = IWL_RATE_INVALID;
1686 int high = IWL_RATE_INVALID; 2018 int high = IWL_RATE_INVALID;
1687 int index; 2019 int index;
@@ -1707,11 +2039,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1707 2039
1708 IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n"); 2040 IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n");
1709 2041
1710 /* Send management frames and broadcast/multicast data using 2042 /* Send management frames and NO_ACK data using lowest rate. */
1711 * lowest rate. */
1712 /* TODO: this could probably be improved.. */ 2043 /* TODO: this could probably be improved.. */
1713 if (!ieee80211_is_data(hdr->frame_control) || 2044 if (!ieee80211_is_data(hdr->frame_control) ||
1714 is_multicast_ether_addr(hdr->addr1)) 2045 info->flags & IEEE80211_TX_CTL_NO_ACK)
1715 return; 2046 return;
1716 2047
1717 if (!sta || !lq_sta) 2048 if (!sta || !lq_sta)
@@ -1732,6 +2063,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1732 active_tbl = 1 - lq_sta->active_tbl; 2063 active_tbl = 1 - lq_sta->active_tbl;
1733 2064
1734 tbl = &(lq_sta->lq_info[active_tbl]); 2065 tbl = &(lq_sta->lq_info[active_tbl]);
2066 if (is_legacy(tbl->lq_type))
2067 lq_sta->is_green = 0;
2068 else
2069 lq_sta->is_green = rs_use_green(priv, conf);
1735 is_green = lq_sta->is_green; 2070 is_green = lq_sta->is_green;
1736 2071
1737 /* current tx rate */ 2072 /* current tx rate */
@@ -1951,6 +2286,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1951 update_lq = 1; 2286 update_lq = 1;
1952 index = low; 2287 index = low;
1953 } 2288 }
2289
1954 break; 2290 break;
1955 case 1: 2291 case 1:
1956 /* Increase starting rate, update uCode's rate table */ 2292 /* Increase starting rate, update uCode's rate table */
@@ -1997,8 +2333,10 @@ lq_update:
1997 rs_move_legacy_other(priv, lq_sta, conf, sta, index); 2333 rs_move_legacy_other(priv, lq_sta, conf, sta, index);
1998 else if (is_siso(tbl->lq_type)) 2334 else if (is_siso(tbl->lq_type))
1999 rs_move_siso_to_other(priv, lq_sta, conf, sta, index); 2335 rs_move_siso_to_other(priv, lq_sta, conf, sta, index);
2336 else if (is_mimo2(tbl->lq_type))
2337 rs_move_mimo2_to_other(priv, lq_sta, conf, sta, index);
2000 else 2338 else
2001 rs_move_mimo_to_other(priv, lq_sta, conf, sta, index); 2339 rs_move_mimo3_to_other(priv, lq_sta, conf, sta, index);
2002 2340
2003 /* If new "search" mode was selected, set up in uCode table */ 2341 /* If new "search" mode was selected, set up in uCode table */
2004 if (lq_sta->search_better_tbl) { 2342 if (lq_sta->search_better_tbl) {
@@ -2014,8 +2352,11 @@ lq_update:
2014 tbl->current_rate, index); 2352 tbl->current_rate, index);
2015 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate); 2353 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
2016 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 2354 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
2017 } 2355 } else
2356 done_search = 1;
2357 }
2018 2358
2359 if (done_search && !lq_sta->stay_in_tbl) {
2019 /* If the "active" (non-search) mode was legacy, 2360 /* If the "active" (non-search) mode was legacy,
2020 * and we've tried switching antennas, 2361 * and we've tried switching antennas,
2021 * but we haven't been able to try HT modes (not available), 2362 * but we haven't been able to try HT modes (not available),
@@ -2023,8 +2364,7 @@ lq_update:
2023 * before next round of mode comparisons. */ 2364 * before next round of mode comparisons. */
2024 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]); 2365 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
2025 if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) && 2366 if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) &&
2026 lq_sta->action_counter >= 1) { 2367 lq_sta->action_counter > tbl1->max_search) {
2027 lq_sta->action_counter = 0;
2028 IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n"); 2368 IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n");
2029 rs_set_stay_in_table(priv, 1, lq_sta); 2369 rs_set_stay_in_table(priv, 1, lq_sta);
2030 } 2370 }
@@ -2033,7 +2373,7 @@ lq_update:
2033 * have been tried and compared, stay in this best modulation 2373 * have been tried and compared, stay in this best modulation
2034 * mode for a while before next round of mode comparisons. */ 2374 * mode for a while before next round of mode comparisons. */
2035 if (lq_sta->enable_counter && 2375 if (lq_sta->enable_counter &&
2036 (lq_sta->action_counter >= IWL_ACTION_LIMIT)) { 2376 (lq_sta->action_counter >= tbl1->max_search)) {
2037 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) && 2377 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
2038 (lq_sta->tx_agg_tid_en & (1 << tid)) && 2378 (lq_sta->tx_agg_tid_en & (1 << tid)) &&
2039 (tid != MAX_TID_COUNT)) { 2379 (tid != MAX_TID_COUNT)) {
@@ -2047,20 +2387,8 @@ lq_update:
2047 lq_sta, sta); 2387 lq_sta, sta);
2048 } 2388 }
2049 } 2389 }
2050 lq_sta->action_counter = 0;
2051 rs_set_stay_in_table(priv, 0, lq_sta); 2390 rs_set_stay_in_table(priv, 0, lq_sta);
2052 } 2391 }
2053
2054 /*
2055 * Else, don't search for a new modulation mode.
2056 * Put new timestamp in stay-in-modulation-mode flush timer if:
2057 * 1) Not changing rates right now
2058 * 2) Not just finishing up a search
2059 * 3) flush timer is empty
2060 */
2061 } else {
2062 if ((!update_lq) && (!done_search) && (!lq_sta->flush_timer))
2063 lq_sta->flush_timer = jiffies;
2064 } 2392 }
2065 2393
2066out: 2394out:
@@ -2156,16 +2484,17 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2156 if (sta) 2484 if (sta)
2157 mask_bit = sta->supp_rates[sband->band]; 2485 mask_bit = sta->supp_rates[sband->band];
2158 2486
2159 /* Send management frames and broadcast/multicast data using lowest 2487 /* Send management frames and NO_ACK data using lowest rate. */
2160 * rate. */
2161 if (!ieee80211_is_data(hdr->frame_control) || 2488 if (!ieee80211_is_data(hdr->frame_control) ||
2162 is_multicast_ether_addr(hdr->addr1) || !sta || !lq_sta) { 2489 info->flags & IEEE80211_TX_CTL_NO_ACK || !sta || !lq_sta) {
2163 if (!mask_bit) 2490 if (!mask_bit)
2164 info->control.rates[0].idx = 2491 info->control.rates[0].idx =
2165 rate_lowest_index(sband, NULL); 2492 rate_lowest_index(sband, NULL);
2166 else 2493 else
2167 info->control.rates[0].idx = 2494 info->control.rates[0].idx =
2168 rate_lowest_index(sband, sta); 2495 rate_lowest_index(sband, sta);
2496 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
2497 info->control.rates[0].count = 1;
2169 return; 2498 return;
2170 } 2499 }
2171 2500
@@ -2178,8 +2507,8 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2178 if (sta_id == IWL_INVALID_STATION) { 2507 if (sta_id == IWL_INVALID_STATION) {
2179 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", 2508 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n",
2180 hdr->addr1); 2509 hdr->addr1);
2181 sta_id = iwl_add_station_flags(priv, hdr->addr1, 2510 sta_id = iwl_add_station(priv, hdr->addr1,
2182 0, CMD_ASYNC, NULL); 2511 false, CMD_ASYNC, NULL);
2183 } 2512 }
2184 if ((sta_id != IWL_INVALID_STATION)) { 2513 if ((sta_id != IWL_INVALID_STATION)) {
2185 lq_sta->lq.sta_id = sta_id; 2514 lq_sta->lq.sta_id = sta_id;
@@ -2189,12 +2518,33 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2189 } 2518 }
2190 } 2519 }
2191 2520
2192 if (rate_idx < 0 || rate_idx > IWL_RATE_COUNT) 2521 if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) {
2193 rate_idx = rate_lowest_index(sband, sta);
2194 else if (sband->band == IEEE80211_BAND_5GHZ)
2195 rate_idx -= IWL_FIRST_OFDM_RATE; 2522 rate_idx -= IWL_FIRST_OFDM_RATE;
2196 2523 /* 6M and 9M shared same MCS index */
2524 rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0;
2525 if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
2526 IWL_RATE_MIMO3_6M_PLCP)
2527 rate_idx = rate_idx + (2 * MCS_INDEX_PER_STREAM);
2528 else if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
2529 IWL_RATE_MIMO2_6M_PLCP)
2530 rate_idx = rate_idx + MCS_INDEX_PER_STREAM;
2531 info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
2532 if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK)
2533 info->control.rates[0].flags |= IEEE80211_TX_RC_SHORT_GI;
2534 if (lq_sta->last_rate_n_flags & RATE_MCS_DUP_MSK)
2535 info->control.rates[0].flags |= IEEE80211_TX_RC_DUP_DATA;
2536 if (lq_sta->last_rate_n_flags & RATE_MCS_FAT_MSK)
2537 info->control.rates[0].flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2538 if (lq_sta->last_rate_n_flags & RATE_MCS_GF_MSK)
2539 info->control.rates[0].flags |= IEEE80211_TX_RC_GREEN_FIELD;
2540 } else {
2541 if (rate_idx < 0 || rate_idx > IWL_RATE_COUNT)
2542 rate_idx = rate_lowest_index(sband, sta);
2543 else if (sband->band == IEEE80211_BAND_5GHZ)
2544 rate_idx -= IWL_FIRST_OFDM_RATE;
2545 }
2197 info->control.rates[0].idx = rate_idx; 2546 info->control.rates[0].idx = rate_idx;
2547
2198} 2548}
2199 2549
2200static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta, 2550static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta,
@@ -2246,15 +2596,16 @@ static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband,
2246 2596
2247 lq_sta->ibss_sta_added = 0; 2597 lq_sta->ibss_sta_added = 0;
2248 if (priv->iw_mode == NL80211_IFTYPE_AP) { 2598 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2249 u8 sta_id = iwl_find_station(priv, sta->addr); 2599 u8 sta_id = iwl_find_station(priv,
2600 sta->addr);
2250 2601
2251 /* for IBSS the call are from tasklet */ 2602 /* for IBSS the call are from tasklet */
2252 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr); 2603 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr);
2253 2604
2254 if (sta_id == IWL_INVALID_STATION) { 2605 if (sta_id == IWL_INVALID_STATION) {
2255 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr); 2606 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr);
2256 sta_id = iwl_add_station_flags(priv, sta->addr, 2607 sta_id = iwl_add_station(priv, sta->addr, false,
2257 0, CMD_ASYNC, NULL); 2608 CMD_ASYNC, NULL);
2258 } 2609 }
2259 if ((sta_id != IWL_INVALID_STATION)) { 2610 if ((sta_id != IWL_INVALID_STATION)) {
2260 lq_sta->lq.sta_id = sta_id; 2611 lq_sta->lq.sta_id = sta_id;
@@ -2436,9 +2787,10 @@ static void rs_fill_link_cmd(const struct iwl_priv *priv,
2436 repeat_rate--; 2787 repeat_rate--;
2437 } 2788 }
2438 2789
2439 lq_cmd->agg_params.agg_frame_cnt_limit = 64; 2790 lq_cmd->agg_params.agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_MAX;
2440 lq_cmd->agg_params.agg_dis_start_th = 3; 2791 lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
2441 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000); 2792 lq_cmd->agg_params.agg_time_limit =
2793 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
2442} 2794}
2443 2795
2444static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) 2796static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
@@ -2539,6 +2891,7 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2539 char *buff; 2891 char *buff;
2540 int desc = 0; 2892 int desc = 0;
2541 int i = 0; 2893 int i = 0;
2894 int index = 0;
2542 ssize_t ret; 2895 ssize_t ret;
2543 2896
2544 struct iwl_lq_sta *lq_sta = file->private_data; 2897 struct iwl_lq_sta *lq_sta = file->private_data;
@@ -2568,8 +2921,11 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2568 ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3")); 2921 ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3"));
2569 desc += sprintf(buff+desc, " %s", 2922 desc += sprintf(buff+desc, " %s",
2570 (tbl->is_fat) ? "40MHz" : "20MHz"); 2923 (tbl->is_fat) ? "40MHz" : "20MHz");
2571 desc += sprintf(buff+desc, " %s\n", (tbl->is_SGI) ? "SGI" : ""); 2924 desc += sprintf(buff+desc, " %s %s\n", (tbl->is_SGI) ? "SGI" : "",
2925 (lq_sta->is_green) ? "GF enabled" : "");
2572 } 2926 }
2927 desc += sprintf(buff+desc, "last tx rate=0x%X\n",
2928 lq_sta->last_rate_n_flags);
2573 desc += sprintf(buff+desc, "general:" 2929 desc += sprintf(buff+desc, "general:"
2574 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n", 2930 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2575 lq_sta->lq.general_params.flags, 2931 lq_sta->lq.general_params.flags,
@@ -2590,10 +2946,19 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2590 lq_sta->lq.general_params.start_rate_index[2], 2946 lq_sta->lq.general_params.start_rate_index[2],
2591 lq_sta->lq.general_params.start_rate_index[3]); 2947 lq_sta->lq.general_params.start_rate_index[3]);
2592 2948
2593 2949 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
2594 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) 2950 index = iwl_hwrate_to_plcp_idx(
2595 desc += sprintf(buff+desc, " rate[%d] 0x%X\n", 2951 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
2596 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags)); 2952 if (is_legacy(tbl->lq_type)) {
2953 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
2954 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
2955 iwl_rate_mcs[index].mbps);
2956 } else {
2957 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps (%s)\n",
2958 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
2959 iwl_rate_mcs[index].mbps, iwl_rate_mcs[index].mcs);
2960 }
2961 }
2597 2962
2598 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); 2963 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2599 kfree(buff); 2964 kfree(buff);
@@ -2620,13 +2985,14 @@ static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
2620 return -ENOMEM; 2985 return -ENOMEM;
2621 2986
2622 for (i = 0; i < LQ_SIZE; i++) { 2987 for (i = 0; i < LQ_SIZE; i++) {
2623 desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n" 2988 desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d GF=%d\n"
2624 "rate=0x%X\n", 2989 "rate=0x%X\n",
2625 lq_sta->active_tbl == i ? "*" : "x", 2990 lq_sta->active_tbl == i ? "*" : "x",
2626 lq_sta->lq_info[i].lq_type, 2991 lq_sta->lq_info[i].lq_type,
2627 lq_sta->lq_info[i].is_SGI, 2992 lq_sta->lq_info[i].is_SGI,
2628 lq_sta->lq_info[i].is_fat, 2993 lq_sta->lq_info[i].is_fat,
2629 lq_sta->lq_info[i].is_dup, 2994 lq_sta->lq_info[i].is_dup,
2995 lq_sta->is_green,
2630 lq_sta->lq_info[i].current_rate); 2996 lq_sta->lq_info[i].current_rate);
2631 for (j = 0; j < IWL_RATE_COUNT; j++) { 2997 for (j = 0; j < IWL_RATE_COUNT; j++) {
2632 desc += sprintf(buff+desc, 2998 desc += sprintf(buff+desc,
@@ -2646,6 +3012,43 @@ static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
2646 .open = open_file_generic, 3012 .open = open_file_generic,
2647}; 3013};
2648 3014
3015static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file,
3016 char __user *user_buf, size_t count, loff_t *ppos)
3017{
3018 char buff[120];
3019 int desc = 0;
3020 ssize_t ret;
3021
3022 struct iwl_lq_sta *lq_sta = file->private_data;
3023 struct iwl_priv *priv;
3024 struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl];
3025
3026 priv = lq_sta->drv;
3027
3028 if (is_Ht(tbl->lq_type))
3029 desc += sprintf(buff+desc,
3030 "Bit Rate= %d Mb/s\n",
3031 tbl->expected_tpt[lq_sta->last_txrate_idx]);
3032 else
3033 desc += sprintf(buff+desc,
3034 "Bit Rate= %d Mb/s\n",
3035 iwl_rates[lq_sta->last_txrate_idx].ieee >> 1);
3036 desc += sprintf(buff+desc,
3037 "Signal Level= %d dBm\tNoise Level= %d dBm\n",
3038 priv->last_rx_rssi, priv->last_rx_noise);
3039 desc += sprintf(buff+desc,
3040 "Tsf= 0x%llx\tBeacon time= 0x%08X\n",
3041 priv->last_tsf, priv->last_beacon_time);
3042
3043 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
3044 return ret;
3045}
3046
3047static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
3048 .read = rs_sta_dbgfs_rate_scale_data_read,
3049 .open = open_file_generic,
3050};
3051
2649static void rs_add_debugfs(void *priv, void *priv_sta, 3052static void rs_add_debugfs(void *priv, void *priv_sta,
2650 struct dentry *dir) 3053 struct dentry *dir)
2651{ 3054{
@@ -2656,6 +3059,9 @@ static void rs_add_debugfs(void *priv, void *priv_sta,
2656 lq_sta->rs_sta_dbgfs_stats_table_file = 3059 lq_sta->rs_sta_dbgfs_stats_table_file =
2657 debugfs_create_file("rate_stats_table", 0600, dir, 3060 debugfs_create_file("rate_stats_table", 0600, dir,
2658 lq_sta, &rs_sta_dbgfs_stats_table_ops); 3061 lq_sta, &rs_sta_dbgfs_stats_table_ops);
3062 lq_sta->rs_sta_dbgfs_rate_scale_data_file =
3063 debugfs_create_file("rate_scale_data", 0600, dir,
3064 lq_sta, &rs_sta_dbgfs_rate_scale_data_ops);
2659 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file = 3065 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
2660 debugfs_create_u8("tx_agg_tid_enable", 0600, dir, 3066 debugfs_create_u8("tx_agg_tid_enable", 0600, dir,
2661 &lq_sta->tx_agg_tid_en); 3067 &lq_sta->tx_agg_tid_en);
@@ -2667,6 +3073,7 @@ static void rs_remove_debugfs(void *priv, void *priv_sta)
2667 struct iwl_lq_sta *lq_sta = priv_sta; 3073 struct iwl_lq_sta *lq_sta = priv_sta;
2668 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file); 3074 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
2669 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file); 3075 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
3076 debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file);
2670 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file); 3077 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
2671} 3078}
2672#endif 3079#endif
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.h b/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
index ab59acc405d9..25050bf315a2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
@@ -241,6 +241,7 @@ enum {
241#define IWL_LEGACY_SWITCH_MIMO2_AB 3 241#define IWL_LEGACY_SWITCH_MIMO2_AB 3
242#define IWL_LEGACY_SWITCH_MIMO2_AC 4 242#define IWL_LEGACY_SWITCH_MIMO2_AC 4
243#define IWL_LEGACY_SWITCH_MIMO2_BC 5 243#define IWL_LEGACY_SWITCH_MIMO2_BC 5
244#define IWL_LEGACY_SWITCH_MIMO3_ABC 6
244 245
245/* possible actions when in siso mode */ 246/* possible actions when in siso mode */
246#define IWL_SISO_SWITCH_ANTENNA1 0 247#define IWL_SISO_SWITCH_ANTENNA1 0
@@ -249,6 +250,8 @@ enum {
249#define IWL_SISO_SWITCH_MIMO2_AC 3 250#define IWL_SISO_SWITCH_MIMO2_AC 3
250#define IWL_SISO_SWITCH_MIMO2_BC 4 251#define IWL_SISO_SWITCH_MIMO2_BC 4
251#define IWL_SISO_SWITCH_GI 5 252#define IWL_SISO_SWITCH_GI 5
253#define IWL_SISO_SWITCH_MIMO3_ABC 6
254
252 255
253/* possible actions when in mimo mode */ 256/* possible actions when in mimo mode */
254#define IWL_MIMO2_SWITCH_ANTENNA1 0 257#define IWL_MIMO2_SWITCH_ANTENNA1 0
@@ -257,6 +260,23 @@ enum {
257#define IWL_MIMO2_SWITCH_SISO_B 3 260#define IWL_MIMO2_SWITCH_SISO_B 3
258#define IWL_MIMO2_SWITCH_SISO_C 4 261#define IWL_MIMO2_SWITCH_SISO_C 4
259#define IWL_MIMO2_SWITCH_GI 5 262#define IWL_MIMO2_SWITCH_GI 5
263#define IWL_MIMO2_SWITCH_MIMO3_ABC 6
264
265
266/* possible actions when in mimo3 mode */
267#define IWL_MIMO3_SWITCH_ANTENNA1 0
268#define IWL_MIMO3_SWITCH_ANTENNA2 1
269#define IWL_MIMO3_SWITCH_SISO_A 2
270#define IWL_MIMO3_SWITCH_SISO_B 3
271#define IWL_MIMO3_SWITCH_SISO_C 4
272#define IWL_MIMO3_SWITCH_MIMO2_AB 5
273#define IWL_MIMO3_SWITCH_MIMO2_AC 6
274#define IWL_MIMO3_SWITCH_MIMO2_BC 7
275#define IWL_MIMO3_SWITCH_GI 8
276
277
278#define IWL_MAX_11N_MIMO3_SEARCH IWL_MIMO3_SWITCH_GI
279#define IWL_MAX_SEARCH IWL_MIMO2_SWITCH_MIMO3_ABC
260 280
261/*FIXME:RS:add possible actions for MIMO3*/ 281/*FIXME:RS:add possible actions for MIMO3*/
262 282
@@ -307,6 +327,13 @@ enum iwl_table_type {
307#define ANT_BC (ANT_B | ANT_C) 327#define ANT_BC (ANT_B | ANT_C)
308#define ANT_ABC (ANT_AB | ANT_C) 328#define ANT_ABC (ANT_AB | ANT_C)
309 329
330#define IWL_MAX_MCS_DISPLAY_SIZE 12
331
332struct iwl_rate_mcs_info {
333 char mbps[IWL_MAX_MCS_DISPLAY_SIZE];
334 char mcs[IWL_MAX_MCS_DISPLAY_SIZE];
335};
336
310static inline u8 num_of_ant(u8 mask) 337static inline u8 num_of_ant(u8 mask)
311{ 338{
312 return !!((mask) & ANT_A) + 339 return !!((mask) & ANT_A) +
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index f46ba2475776..a5637c4aa85d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -102,7 +102,7 @@ MODULE_ALIAS("iwl4965");
102 * function correctly transitions out of the RXON_ASSOC_MSK state if 102 * function correctly transitions out of the RXON_ASSOC_MSK state if
103 * a HW tune is required based on the RXON structure changes. 103 * a HW tune is required based on the RXON structure changes.
104 */ 104 */
105static int iwl_commit_rxon(struct iwl_priv *priv) 105int iwl_commit_rxon(struct iwl_priv *priv)
106{ 106{
107 /* cast away the const for active_rxon in this function */ 107 /* cast away the const for active_rxon in this function */
108 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; 108 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
@@ -190,8 +190,7 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
190 190
191 iwl_clear_stations_table(priv); 191 iwl_clear_stations_table(priv);
192 192
193 if (!priv->error_recovering) 193 priv->start_calib = 0;
194 priv->start_calib = 0;
195 194
196 /* Add the broadcast address so we can send broadcast frames */ 195 /* Add the broadcast address so we can send broadcast frames */
197 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) == 196 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
@@ -246,8 +245,9 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
246void iwl_update_chain_flags(struct iwl_priv *priv) 245void iwl_update_chain_flags(struct iwl_priv *priv)
247{ 246{
248 247
249 iwl_set_rxon_chain(priv); 248 if (priv->cfg->ops->hcmd->set_rxon_chain)
250 iwl_commit_rxon(priv); 249 priv->cfg->ops->hcmd->set_rxon_chain(priv);
250 iwlcore_commit_rxon(priv);
251} 251}
252 252
253static void iwl_clear_free_frames(struct iwl_priv *priv) 253static void iwl_clear_free_frames(struct iwl_priv *priv)
@@ -503,24 +503,12 @@ int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
503int iwl_hw_tx_queue_init(struct iwl_priv *priv, 503int iwl_hw_tx_queue_init(struct iwl_priv *priv,
504 struct iwl_tx_queue *txq) 504 struct iwl_tx_queue *txq)
505{ 505{
506 int ret;
507 unsigned long flags;
508 int txq_id = txq->q.id; 506 int txq_id = txq->q.id;
509 507
510 spin_lock_irqsave(&priv->lock, flags);
511 ret = iwl_grab_nic_access(priv);
512 if (ret) {
513 spin_unlock_irqrestore(&priv->lock, flags);
514 return ret;
515 }
516
517 /* Circular buffer (TFD queue in DRAM) physical base address */ 508 /* Circular buffer (TFD queue in DRAM) physical base address */
518 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id), 509 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
519 txq->q.dma_addr >> 8); 510 txq->q.dma_addr >> 8);
520 511
521 iwl_release_nic_access(priv);
522 spin_unlock_irqrestore(&priv->lock, flags);
523
524 return 0; 512 return 0;
525} 513}
526 514
@@ -531,76 +519,6 @@ int iwl_hw_tx_queue_init(struct iwl_priv *priv,
531 * 519 *
532 ******************************************************************************/ 520 ******************************************************************************/
533 521
534static void iwl_ht_conf(struct iwl_priv *priv,
535 struct ieee80211_bss_conf *bss_conf)
536{
537 struct ieee80211_sta_ht_cap *ht_conf;
538 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
539 struct ieee80211_sta *sta;
540
541 IWL_DEBUG_MAC80211(priv, "enter: \n");
542
543 if (!iwl_conf->is_ht)
544 return;
545
546
547 /*
548 * It is totally wrong to base global information on something
549 * that is valid only when associated, alas, this driver works
550 * that way and I don't know how to fix it.
551 */
552
553 rcu_read_lock();
554 sta = ieee80211_find_sta(priv->hw, priv->bssid);
555 if (!sta) {
556 rcu_read_unlock();
557 return;
558 }
559 ht_conf = &sta->ht_cap;
560
561 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
562 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
563 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
564 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
565
566 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
567 iwl_conf->max_amsdu_size =
568 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
569
570 iwl_conf->supported_chan_width =
571 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
572
573 /*
574 * XXX: The HT configuration needs to be moved into iwl_mac_config()
575 * to be done there correctly.
576 */
577
578 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
579 if (conf_is_ht40_minus(&priv->hw->conf))
580 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
581 else if (conf_is_ht40_plus(&priv->hw->conf))
582 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
583
584 /* If no above or below channel supplied disable FAT channel */
585 if (iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_ABOVE &&
586 iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_BELOW)
587 iwl_conf->supported_chan_width = 0;
588
589 iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
590
591 memcpy(&iwl_conf->mcs, &ht_conf->mcs, 16);
592
593 iwl_conf->tx_chan_width = iwl_conf->supported_chan_width != 0;
594 iwl_conf->ht_protection =
595 bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
596 iwl_conf->non_GF_STA_present =
597 !!(bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
598
599 rcu_read_unlock();
600
601 IWL_DEBUG_MAC80211(priv, "leave\n");
602}
603
604#define MAX_UCODE_BEACON_INTERVAL 4096 522#define MAX_UCODE_BEACON_INTERVAL 4096
605 523
606static u16 iwl_adjust_beacon_interval(u16 beacon_val) 524static u16 iwl_adjust_beacon_interval(u16 beacon_val)
@@ -636,7 +554,8 @@ static void iwl_setup_rxon_timing(struct iwl_priv *priv)
636 beacon_int = iwl_adjust_beacon_interval(priv->beacon_int); 554 beacon_int = iwl_adjust_beacon_interval(priv->beacon_int);
637 priv->rxon_timing.atim_window = 0; 555 priv->rxon_timing.atim_window = 0;
638 } else { 556 } else {
639 beacon_int = iwl_adjust_beacon_interval(conf->beacon_int); 557 beacon_int = iwl_adjust_beacon_interval(
558 priv->vif->bss_conf.beacon_int);
640 559
641 /* TODO: we need to get atim_window from upper stack 560 /* TODO: we need to get atim_window from upper stack
642 * for now we set to 0 */ 561 * for now we set to 0 */
@@ -657,23 +576,6 @@ static void iwl_setup_rxon_timing(struct iwl_priv *priv)
657 le16_to_cpu(priv->rxon_timing.atim_window)); 576 le16_to_cpu(priv->rxon_timing.atim_window));
658} 577}
659 578
660static int iwl_set_mode(struct iwl_priv *priv, int mode)
661{
662 iwl_connection_init_rx_config(priv, mode);
663 iwl_set_rxon_chain(priv);
664 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
665
666 iwl_clear_stations_table(priv);
667
668 /* dont commit rxon if rf-kill is on*/
669 if (!iwl_is_ready_rf(priv))
670 return -EAGAIN;
671
672 iwl_commit_rxon(priv);
673
674 return 0;
675}
676
677/****************************************************************************** 579/******************************************************************************
678 * 580 *
679 * Generic RX handler implementations 581 * Generic RX handler implementations
@@ -795,6 +697,7 @@ static void iwl_rx_card_state_notif(struct iwl_priv *priv,
795 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; 697 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
796 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); 698 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
797 unsigned long status = priv->status; 699 unsigned long status = priv->status;
700 unsigned long reg_flags;
798 701
799 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n", 702 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
800 (flags & HW_CARD_DISABLED) ? "Kill" : "On", 703 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
@@ -806,32 +709,25 @@ static void iwl_rx_card_state_notif(struct iwl_priv *priv,
806 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, 709 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
807 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); 710 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
808 711
809 if (!iwl_grab_nic_access(priv)) { 712 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
810 iwl_write_direct32( 713 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
811 priv, HBUS_TARG_MBX_C,
812 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
813
814 iwl_release_nic_access(priv);
815 }
816 714
817 if (!(flags & RXON_CARD_DISABLED)) { 715 if (!(flags & RXON_CARD_DISABLED)) {
818 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, 716 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
819 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); 717 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
820 if (!iwl_grab_nic_access(priv)) { 718 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
821 iwl_write_direct32(
822 priv, HBUS_TARG_MBX_C,
823 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); 719 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
824 720
825 iwl_release_nic_access(priv);
826 }
827 } 721 }
828 722
829 if (flags & RF_CARD_DISABLED) { 723 if (flags & RF_CARD_DISABLED) {
830 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, 724 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
831 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); 725 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
832 iwl_read32(priv, CSR_UCODE_DRV_GP1); 726 iwl_read32(priv, CSR_UCODE_DRV_GP1);
727 spin_lock_irqsave(&priv->reg_lock, reg_flags);
833 if (!iwl_grab_nic_access(priv)) 728 if (!iwl_grab_nic_access(priv))
834 iwl_release_nic_access(priv); 729 iwl_release_nic_access(priv);
730 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
835 } 731 }
836 } 732 }
837 733
@@ -841,33 +737,19 @@ static void iwl_rx_card_state_notif(struct iwl_priv *priv,
841 clear_bit(STATUS_RF_KILL_HW, &priv->status); 737 clear_bit(STATUS_RF_KILL_HW, &priv->status);
842 738
843 739
844 if (flags & SW_CARD_DISABLED)
845 set_bit(STATUS_RF_KILL_SW, &priv->status);
846 else
847 clear_bit(STATUS_RF_KILL_SW, &priv->status);
848
849 if (!(flags & RXON_CARD_DISABLED)) 740 if (!(flags & RXON_CARD_DISABLED))
850 iwl_scan_cancel(priv); 741 iwl_scan_cancel(priv);
851 742
852 if ((test_bit(STATUS_RF_KILL_HW, &status) != 743 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
853 test_bit(STATUS_RF_KILL_HW, &priv->status)) || 744 test_bit(STATUS_RF_KILL_HW, &priv->status)))
854 (test_bit(STATUS_RF_KILL_SW, &status) != 745 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
855 test_bit(STATUS_RF_KILL_SW, &priv->status))) 746 test_bit(STATUS_RF_KILL_HW, &priv->status));
856 queue_work(priv->workqueue, &priv->rf_kill);
857 else 747 else
858 wake_up_interruptible(&priv->wait_command_queue); 748 wake_up_interruptible(&priv->wait_command_queue);
859} 749}
860 750
861int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src) 751int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
862{ 752{
863 int ret;
864 unsigned long flags;
865
866 spin_lock_irqsave(&priv->lock, flags);
867 ret = iwl_grab_nic_access(priv);
868 if (ret)
869 goto err;
870
871 if (src == IWL_PWR_SRC_VAUX) { 753 if (src == IWL_PWR_SRC_VAUX) {
872 if (pci_pme_capable(priv->pci_dev, PCI_D3cold)) 754 if (pci_pme_capable(priv->pci_dev, PCI_D3cold))
873 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, 755 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
@@ -879,10 +761,7 @@ int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
879 ~APMG_PS_CTRL_MSK_PWR_SRC); 761 ~APMG_PS_CTRL_MSK_PWR_SRC);
880 } 762 }
881 763
882 iwl_release_nic_access(priv); 764 return 0;
883err:
884 spin_unlock_irqrestore(&priv->lock, flags);
885 return ret;
886} 765}
887 766
888/** 767/**
@@ -946,6 +825,7 @@ void iwl_rx_handle(struct iwl_priv *priv)
946 unsigned long flags; 825 unsigned long flags;
947 u8 fill_rx = 0; 826 u8 fill_rx = 0;
948 u32 count = 8; 827 u32 count = 8;
828 int total_empty;
949 829
950 /* uCode's read index (stored in shared DRAM) indicates the last Rx 830 /* uCode's read index (stored in shared DRAM) indicates the last Rx
951 * buffer that the driver may process (last buffer filled by ucode). */ 831 * buffer that the driver may process (last buffer filled by ucode). */
@@ -956,7 +836,12 @@ void iwl_rx_handle(struct iwl_priv *priv)
956 if (i == r) 836 if (i == r)
957 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i); 837 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
958 838
959 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) 839 /* calculate total frames need to be restock after handling RX */
840 total_empty = r - priv->rxq.write_actual;
841 if (total_empty < 0)
842 total_empty += RX_QUEUE_SIZE;
843
844 if (total_empty > (RX_QUEUE_SIZE / 2))
960 fill_rx = 1; 845 fill_rx = 1;
961 846
962 while (i != r) { 847 while (i != r) {
@@ -995,6 +880,7 @@ void iwl_rx_handle(struct iwl_priv *priv)
995 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r, 880 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
996 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); 881 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
997 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); 882 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
883 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
998 } else { 884 } else {
999 /* No handling needed */ 885 /* No handling needed */
1000 IWL_DEBUG_RX(priv, 886 IWL_DEBUG_RX(priv,
@@ -1032,7 +918,7 @@ void iwl_rx_handle(struct iwl_priv *priv)
1032 count++; 918 count++;
1033 if (count >= 8) { 919 if (count >= 8) {
1034 priv->rxq.read = i; 920 priv->rxq.read = i;
1035 iwl_rx_queue_restock(priv); 921 iwl_rx_replenish_now(priv);
1036 count = 0; 922 count = 0;
1037 } 923 }
1038 } 924 }
@@ -1040,7 +926,10 @@ void iwl_rx_handle(struct iwl_priv *priv)
1040 926
1041 /* Backtrack one entry */ 927 /* Backtrack one entry */
1042 priv->rxq.read = i; 928 priv->rxq.read = i;
1043 iwl_rx_queue_restock(priv); 929 if (fill_rx)
930 iwl_rx_replenish_now(priv);
931 else
932 iwl_rx_queue_restock(priv);
1044} 933}
1045 934
1046/* call this function to flush any scheduled tasklet */ 935/* call this function to flush any scheduled tasklet */
@@ -1051,24 +940,7 @@ static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1051 tasklet_kill(&priv->irq_tasklet); 940 tasklet_kill(&priv->irq_tasklet);
1052} 941}
1053 942
1054static void iwl_error_recovery(struct iwl_priv *priv) 943static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
1055{
1056 unsigned long flags;
1057
1058 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1059 sizeof(priv->staging_rxon));
1060 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1061 iwl_commit_rxon(priv);
1062
1063 iwl_rxon_add_station(priv, priv->bssid, 1);
1064
1065 spin_lock_irqsave(&priv->lock, flags);
1066 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
1067 priv->error_recovering = 0;
1068 spin_unlock_irqrestore(&priv->lock, flags);
1069}
1070
1071static void iwl_irq_tasklet(struct iwl_priv *priv)
1072{ 944{
1073 u32 inta, handled = 0; 945 u32 inta, handled = 0;
1074 u32 inta_fh; 946 u32 inta_fh;
@@ -1116,6 +988,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1116 /* Tell the device to stop sending interrupts */ 988 /* Tell the device to stop sending interrupts */
1117 iwl_disable_interrupts(priv); 989 iwl_disable_interrupts(priv);
1118 990
991 priv->isr_stats.hw++;
1119 iwl_irq_handle_error(priv); 992 iwl_irq_handle_error(priv);
1120 993
1121 handled |= CSR_INT_BIT_HW_ERR; 994 handled |= CSR_INT_BIT_HW_ERR;
@@ -1128,13 +1001,17 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1128#ifdef CONFIG_IWLWIFI_DEBUG 1001#ifdef CONFIG_IWLWIFI_DEBUG
1129 if (priv->debug_level & (IWL_DL_ISR)) { 1002 if (priv->debug_level & (IWL_DL_ISR)) {
1130 /* NIC fires this, but we don't use it, redundant with WAKEUP */ 1003 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1131 if (inta & CSR_INT_BIT_SCD) 1004 if (inta & CSR_INT_BIT_SCD) {
1132 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit " 1005 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
1133 "the frame/frames.\n"); 1006 "the frame/frames.\n");
1007 priv->isr_stats.sch++;
1008 }
1134 1009
1135 /* Alive notification via Rx interrupt will do the real work */ 1010 /* Alive notification via Rx interrupt will do the real work */
1136 if (inta & CSR_INT_BIT_ALIVE) 1011 if (inta & CSR_INT_BIT_ALIVE) {
1137 IWL_DEBUG_ISR(priv, "Alive interrupt\n"); 1012 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
1013 priv->isr_stats.alive++;
1014 }
1138 } 1015 }
1139#endif 1016#endif
1140 /* Safely ignore these bits for debug checks below */ 1017 /* Safely ignore these bits for debug checks below */
@@ -1150,6 +1027,8 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1150 IWL_DEBUG_RF_KILL(priv, "RF_KILL bit toggled to %s.\n", 1027 IWL_DEBUG_RF_KILL(priv, "RF_KILL bit toggled to %s.\n",
1151 hw_rf_kill ? "disable radio" : "enable radio"); 1028 hw_rf_kill ? "disable radio" : "enable radio");
1152 1029
1030 priv->isr_stats.rfkill++;
1031
1153 /* driver only loads ucode once setting the interface up. 1032 /* driver only loads ucode once setting the interface up.
1154 * the driver allows loading the ucode even if the radio 1033 * the driver allows loading the ucode even if the radio
1155 * is killed. Hence update the killswitch state here. The 1034 * is killed. Hence update the killswitch state here. The
@@ -1160,7 +1039,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1160 set_bit(STATUS_RF_KILL_HW, &priv->status); 1039 set_bit(STATUS_RF_KILL_HW, &priv->status);
1161 else 1040 else
1162 clear_bit(STATUS_RF_KILL_HW, &priv->status); 1041 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1163 queue_work(priv->workqueue, &priv->rf_kill); 1042 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
1164 } 1043 }
1165 1044
1166 handled |= CSR_INT_BIT_RF_KILL; 1045 handled |= CSR_INT_BIT_RF_KILL;
@@ -1169,6 +1048,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1169 /* Chip got too hot and stopped itself */ 1048 /* Chip got too hot and stopped itself */
1170 if (inta & CSR_INT_BIT_CT_KILL) { 1049 if (inta & CSR_INT_BIT_CT_KILL) {
1171 IWL_ERR(priv, "Microcode CT kill error detected.\n"); 1050 IWL_ERR(priv, "Microcode CT kill error detected.\n");
1051 priv->isr_stats.ctkill++;
1172 handled |= CSR_INT_BIT_CT_KILL; 1052 handled |= CSR_INT_BIT_CT_KILL;
1173 } 1053 }
1174 1054
@@ -1176,6 +1056,8 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1176 if (inta & CSR_INT_BIT_SW_ERR) { 1056 if (inta & CSR_INT_BIT_SW_ERR) {
1177 IWL_ERR(priv, "Microcode SW error detected. " 1057 IWL_ERR(priv, "Microcode SW error detected. "
1178 " Restarting 0x%X.\n", inta); 1058 " Restarting 0x%X.\n", inta);
1059 priv->isr_stats.sw++;
1060 priv->isr_stats.sw_err = inta;
1179 iwl_irq_handle_error(priv); 1061 iwl_irq_handle_error(priv);
1180 handled |= CSR_INT_BIT_SW_ERR; 1062 handled |= CSR_INT_BIT_SW_ERR;
1181 } 1063 }
@@ -1191,6 +1073,8 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1191 iwl_txq_update_write_ptr(priv, &priv->txq[4]); 1073 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1192 iwl_txq_update_write_ptr(priv, &priv->txq[5]); 1074 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
1193 1075
1076 priv->isr_stats.wakeup++;
1077
1194 handled |= CSR_INT_BIT_WAKEUP; 1078 handled |= CSR_INT_BIT_WAKEUP;
1195 } 1079 }
1196 1080
@@ -1199,23 +1083,27 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1199 * notifications from uCode come through here*/ 1083 * notifications from uCode come through here*/
1200 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { 1084 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1201 iwl_rx_handle(priv); 1085 iwl_rx_handle(priv);
1086 priv->isr_stats.rx++;
1202 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); 1087 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1203 } 1088 }
1204 1089
1205 if (inta & CSR_INT_BIT_FH_TX) { 1090 if (inta & CSR_INT_BIT_FH_TX) {
1206 IWL_DEBUG_ISR(priv, "Tx interrupt\n"); 1091 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
1092 priv->isr_stats.tx++;
1207 handled |= CSR_INT_BIT_FH_TX; 1093 handled |= CSR_INT_BIT_FH_TX;
1208 /* FH finished to write, send event */ 1094 /* FH finished to write, send event */
1209 priv->ucode_write_complete = 1; 1095 priv->ucode_write_complete = 1;
1210 wake_up_interruptible(&priv->wait_command_queue); 1096 wake_up_interruptible(&priv->wait_command_queue);
1211 } 1097 }
1212 1098
1213 if (inta & ~handled) 1099 if (inta & ~handled) {
1214 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); 1100 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1101 priv->isr_stats.unhandled++;
1102 }
1215 1103
1216 if (inta & ~CSR_INI_SET_MASK) { 1104 if (inta & ~(priv->inta_mask)) {
1217 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", 1105 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
1218 inta & ~CSR_INI_SET_MASK); 1106 inta & ~priv->inta_mask);
1219 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh); 1107 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
1220 } 1108 }
1221 1109
@@ -1236,6 +1124,200 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1236 spin_unlock_irqrestore(&priv->lock, flags); 1124 spin_unlock_irqrestore(&priv->lock, flags);
1237} 1125}
1238 1126
1127/* tasklet for iwlagn interrupt */
1128static void iwl_irq_tasklet(struct iwl_priv *priv)
1129{
1130 u32 inta = 0;
1131 u32 handled = 0;
1132 unsigned long flags;
1133#ifdef CONFIG_IWLWIFI_DEBUG
1134 u32 inta_mask;
1135#endif
1136
1137 spin_lock_irqsave(&priv->lock, flags);
1138
1139 /* Ack/clear/reset pending uCode interrupts.
1140 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1141 */
1142 iwl_write32(priv, CSR_INT, priv->inta);
1143
1144 inta = priv->inta;
1145
1146#ifdef CONFIG_IWLWIFI_DEBUG
1147 if (priv->debug_level & IWL_DL_ISR) {
1148 /* just for debug */
1149 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1150 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
1151 inta, inta_mask);
1152 }
1153#endif
1154 /* saved interrupt in inta variable now we can reset priv->inta */
1155 priv->inta = 0;
1156
1157 /* Now service all interrupt bits discovered above. */
1158 if (inta & CSR_INT_BIT_HW_ERR) {
1159 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
1160
1161 /* Tell the device to stop sending interrupts */
1162 iwl_disable_interrupts(priv);
1163
1164 priv->isr_stats.hw++;
1165 iwl_irq_handle_error(priv);
1166
1167 handled |= CSR_INT_BIT_HW_ERR;
1168
1169 spin_unlock_irqrestore(&priv->lock, flags);
1170
1171 return;
1172 }
1173
1174#ifdef CONFIG_IWLWIFI_DEBUG
1175 if (priv->debug_level & (IWL_DL_ISR)) {
1176 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1177 if (inta & CSR_INT_BIT_SCD) {
1178 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
1179 "the frame/frames.\n");
1180 priv->isr_stats.sch++;
1181 }
1182
1183 /* Alive notification via Rx interrupt will do the real work */
1184 if (inta & CSR_INT_BIT_ALIVE) {
1185 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
1186 priv->isr_stats.alive++;
1187 }
1188 }
1189#endif
1190 /* Safely ignore these bits for debug checks below */
1191 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
1192
1193 /* HW RF KILL switch toggled */
1194 if (inta & CSR_INT_BIT_RF_KILL) {
1195 int hw_rf_kill = 0;
1196 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
1197 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1198 hw_rf_kill = 1;
1199
1200 IWL_DEBUG_RF_KILL(priv, "RF_KILL bit toggled to %s.\n",
1201 hw_rf_kill ? "disable radio" : "enable radio");
1202
1203 priv->isr_stats.rfkill++;
1204
1205 /* driver only loads ucode once setting the interface up.
1206 * the driver allows loading the ucode even if the radio
1207 * is killed. Hence update the killswitch state here. The
1208 * rfkill handler will care about restarting if needed.
1209 */
1210 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1211 if (hw_rf_kill)
1212 set_bit(STATUS_RF_KILL_HW, &priv->status);
1213 else
1214 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1215 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
1216 }
1217
1218 handled |= CSR_INT_BIT_RF_KILL;
1219 }
1220
1221 /* Chip got too hot and stopped itself */
1222 if (inta & CSR_INT_BIT_CT_KILL) {
1223 IWL_ERR(priv, "Microcode CT kill error detected.\n");
1224 priv->isr_stats.ctkill++;
1225 handled |= CSR_INT_BIT_CT_KILL;
1226 }
1227
1228 /* Error detected by uCode */
1229 if (inta & CSR_INT_BIT_SW_ERR) {
1230 IWL_ERR(priv, "Microcode SW error detected. "
1231 " Restarting 0x%X.\n", inta);
1232 priv->isr_stats.sw++;
1233 priv->isr_stats.sw_err = inta;
1234 iwl_irq_handle_error(priv);
1235 handled |= CSR_INT_BIT_SW_ERR;
1236 }
1237
1238 /* uCode wakes up after power-down sleep */
1239 if (inta & CSR_INT_BIT_WAKEUP) {
1240 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
1241 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
1242 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1243 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1244 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1245 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1246 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1247 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
1248
1249 priv->isr_stats.wakeup++;
1250
1251 handled |= CSR_INT_BIT_WAKEUP;
1252 }
1253
1254 /* All uCode command responses, including Tx command responses,
1255 * Rx "responses" (frame-received notification), and other
1256 * notifications from uCode come through here*/
1257 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
1258 CSR_INT_BIT_RX_PERIODIC)) {
1259 IWL_DEBUG_ISR(priv, "Rx interrupt\n");
1260 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1261 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1262 iwl_write32(priv, CSR_FH_INT_STATUS,
1263 CSR49_FH_INT_RX_MASK);
1264 }
1265 if (inta & CSR_INT_BIT_RX_PERIODIC) {
1266 handled |= CSR_INT_BIT_RX_PERIODIC;
1267 iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
1268 }
1269 /* Sending RX interrupt require many steps to be done in the
1270 * the device:
1271 * 1- write interrupt to current index in ICT table.
1272 * 2- dma RX frame.
1273 * 3- update RX shared data to indicate last write index.
1274 * 4- send interrupt.
1275 * This could lead to RX race, driver could receive RX interrupt
1276 * but the shared data changes does not reflect this.
1277 * this could lead to RX race, RX periodic will solve this race
1278 */
1279 iwl_write32(priv, CSR_INT_PERIODIC_REG,
1280 CSR_INT_PERIODIC_DIS);
1281 iwl_rx_handle(priv);
1282 /* Only set RX periodic if real RX is received. */
1283 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
1284 iwl_write32(priv, CSR_INT_PERIODIC_REG,
1285 CSR_INT_PERIODIC_ENA);
1286
1287 priv->isr_stats.rx++;
1288 }
1289
1290 if (inta & CSR_INT_BIT_FH_TX) {
1291 iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK);
1292 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
1293 priv->isr_stats.tx++;
1294 handled |= CSR_INT_BIT_FH_TX;
1295 /* FH finished to write, send event */
1296 priv->ucode_write_complete = 1;
1297 wake_up_interruptible(&priv->wait_command_queue);
1298 }
1299
1300 if (inta & ~handled) {
1301 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1302 priv->isr_stats.unhandled++;
1303 }
1304
1305 if (inta & ~(priv->inta_mask)) {
1306 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
1307 inta & ~priv->inta_mask);
1308 }
1309
1310
1311 /* Re-enable all interrupts */
1312 /* only Re-enable if diabled by irq */
1313 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1314 iwl_enable_interrupts(priv);
1315
1316 spin_unlock_irqrestore(&priv->lock, flags);
1317
1318}
1319
1320
1239/****************************************************************************** 1321/******************************************************************************
1240 * 1322 *
1241 * uCode download functions 1323 * uCode download functions
@@ -1501,10 +1583,6 @@ static int iwl_read_ucode(struct iwl_priv *priv)
1501 return ret; 1583 return ret;
1502} 1584}
1503 1585
1504/* temporary */
1505static int iwl_mac_beacon_update(struct ieee80211_hw *hw,
1506 struct sk_buff *skb);
1507
1508/** 1586/**
1509 * iwl_alive_start - called after REPLY_ALIVE notification received 1587 * iwl_alive_start - called after REPLY_ALIVE notification received
1510 * from protocol/runtime uCode (initialization uCode's 1588 * from protocol/runtime uCode (initialization uCode's
@@ -1561,7 +1639,10 @@ static void iwl_alive_start(struct iwl_priv *priv)
1561 } else { 1639 } else {
1562 /* Initialize our rx_config data */ 1640 /* Initialize our rx_config data */
1563 iwl_connection_init_rx_config(priv, priv->iw_mode); 1641 iwl_connection_init_rx_config(priv, priv->iw_mode);
1564 iwl_set_rxon_chain(priv); 1642
1643 if (priv->cfg->ops->hcmd->set_rxon_chain)
1644 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1645
1565 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); 1646 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1566 } 1647 }
1567 1648
@@ -1571,7 +1652,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
1571 iwl_reset_run_time_calib(priv); 1652 iwl_reset_run_time_calib(priv);
1572 1653
1573 /* Configure the adapter for unassociated operation */ 1654 /* Configure the adapter for unassociated operation */
1574 iwl_commit_rxon(priv); 1655 iwlcore_commit_rxon(priv);
1575 1656
1576 /* At this point, the NIC is initialized and operational */ 1657 /* At this point, the NIC is initialized and operational */
1577 iwl_rf_kill_ct_config(priv); 1658 iwl_rf_kill_ct_config(priv);
@@ -1582,9 +1663,6 @@ static void iwl_alive_start(struct iwl_priv *priv)
1582 set_bit(STATUS_READY, &priv->status); 1663 set_bit(STATUS_READY, &priv->status);
1583 wake_up_interruptible(&priv->wait_command_queue); 1664 wake_up_interruptible(&priv->wait_command_queue);
1584 1665
1585 if (priv->error_recovering)
1586 iwl_error_recovery(priv);
1587
1588 iwl_power_update_mode(priv, 1); 1666 iwl_power_update_mode(priv, 1);
1589 1667
1590 /* reassociate for ADHOC mode */ 1668 /* reassociate for ADHOC mode */
@@ -1642,36 +1720,30 @@ static void __iwl_down(struct iwl_priv *priv)
1642 ieee80211_stop_queues(priv->hw); 1720 ieee80211_stop_queues(priv->hw);
1643 1721
1644 /* If we have not previously called iwl_init() then 1722 /* If we have not previously called iwl_init() then
1645 * clear all bits but the RF Kill and SUSPEND bits and return */ 1723 * clear all bits but the RF Kill bit and return */
1646 if (!iwl_is_init(priv)) { 1724 if (!iwl_is_init(priv)) {
1647 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << 1725 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
1648 STATUS_RF_KILL_HW | 1726 STATUS_RF_KILL_HW |
1649 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
1650 STATUS_RF_KILL_SW |
1651 test_bit(STATUS_GEO_CONFIGURED, &priv->status) << 1727 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
1652 STATUS_GEO_CONFIGURED | 1728 STATUS_GEO_CONFIGURED |
1653 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
1654 STATUS_IN_SUSPEND |
1655 test_bit(STATUS_EXIT_PENDING, &priv->status) << 1729 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
1656 STATUS_EXIT_PENDING; 1730 STATUS_EXIT_PENDING;
1657 goto exit; 1731 goto exit;
1658 } 1732 }
1659 1733
1660 /* ...otherwise clear out all the status bits but the RF Kill and 1734 /* ...otherwise clear out all the status bits but the RF Kill
1661 * SUSPEND bits and continue taking the NIC down. */ 1735 * bit and continue taking the NIC down. */
1662 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << 1736 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
1663 STATUS_RF_KILL_HW | 1737 STATUS_RF_KILL_HW |
1664 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
1665 STATUS_RF_KILL_SW |
1666 test_bit(STATUS_GEO_CONFIGURED, &priv->status) << 1738 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
1667 STATUS_GEO_CONFIGURED | 1739 STATUS_GEO_CONFIGURED |
1668 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
1669 STATUS_IN_SUSPEND |
1670 test_bit(STATUS_FW_ERROR, &priv->status) << 1740 test_bit(STATUS_FW_ERROR, &priv->status) <<
1671 STATUS_FW_ERROR | 1741 STATUS_FW_ERROR |
1672 test_bit(STATUS_EXIT_PENDING, &priv->status) << 1742 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
1673 STATUS_EXIT_PENDING; 1743 STATUS_EXIT_PENDING;
1674 1744
1745 /* device going down, Stop using ICT table */
1746 iwl_disable_ict(priv);
1675 spin_lock_irqsave(&priv->lock, flags); 1747 spin_lock_irqsave(&priv->lock, flags);
1676 iwl_clear_bit(priv, CSR_GP_CNTRL, 1748 iwl_clear_bit(priv, CSR_GP_CNTRL,
1677 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); 1749 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
@@ -1680,18 +1752,13 @@ static void __iwl_down(struct iwl_priv *priv)
1680 iwl_txq_ctx_stop(priv); 1752 iwl_txq_ctx_stop(priv);
1681 iwl_rxq_stop(priv); 1753 iwl_rxq_stop(priv);
1682 1754
1683 spin_lock_irqsave(&priv->lock, flags); 1755 iwl_write_prph(priv, APMG_CLK_DIS_REG,
1684 if (!iwl_grab_nic_access(priv)) { 1756 APMG_CLK_VAL_DMA_CLK_RQT);
1685 iwl_write_prph(priv, APMG_CLK_DIS_REG,
1686 APMG_CLK_VAL_DMA_CLK_RQT);
1687 iwl_release_nic_access(priv);
1688 }
1689 spin_unlock_irqrestore(&priv->lock, flags);
1690 1757
1691 udelay(5); 1758 udelay(5);
1692 1759
1693 /* FIXME: apm_ops.suspend(priv) */ 1760 /* FIXME: apm_ops.suspend(priv) */
1694 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status)) 1761 if (exit_pending)
1695 priv->cfg->ops->lib->apm_ops.stop(priv); 1762 priv->cfg->ops->lib->apm_ops.stop(priv);
1696 else 1763 else
1697 priv->cfg->ops->lib->apm_ops.reset(priv); 1764 priv->cfg->ops->lib->apm_ops.reset(priv);
@@ -1715,6 +1782,49 @@ static void iwl_down(struct iwl_priv *priv)
1715 iwl_cancel_deferred_work(priv); 1782 iwl_cancel_deferred_work(priv);
1716} 1783}
1717 1784
1785#define HW_READY_TIMEOUT (50)
1786
1787static int iwl_set_hw_ready(struct iwl_priv *priv)
1788{
1789 int ret = 0;
1790
1791 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1792 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
1793
1794 /* See if we got it */
1795 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
1796 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
1797 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
1798 HW_READY_TIMEOUT);
1799 if (ret != -ETIMEDOUT)
1800 priv->hw_ready = true;
1801 else
1802 priv->hw_ready = false;
1803
1804 IWL_DEBUG_INFO(priv, "hardware %s\n",
1805 (priv->hw_ready == 1) ? "ready" : "not ready");
1806 return ret;
1807}
1808
1809static int iwl_prepare_card_hw(struct iwl_priv *priv)
1810{
1811 int ret = 0;
1812
1813 IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter \n");
1814
1815 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1816 CSR_HW_IF_CONFIG_REG_PREPARE);
1817
1818 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
1819 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
1820 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
1821
1822 if (ret != -ETIMEDOUT)
1823 iwl_set_hw_ready(priv);
1824
1825 return ret;
1826}
1827
1718#define MAX_HW_RESTARTS 5 1828#define MAX_HW_RESTARTS 5
1719 1829
1720static int __iwl_up(struct iwl_priv *priv) 1830static int __iwl_up(struct iwl_priv *priv)
@@ -1732,6 +1842,13 @@ static int __iwl_up(struct iwl_priv *priv)
1732 return -EIO; 1842 return -EIO;
1733 } 1843 }
1734 1844
1845 iwl_prepare_card_hw(priv);
1846
1847 if (!priv->hw_ready) {
1848 IWL_WARN(priv, "Exit HW not ready\n");
1849 return -EIO;
1850 }
1851
1735 /* If platform's RF_KILL switch is NOT set to KILL */ 1852 /* If platform's RF_KILL switch is NOT set to KILL */
1736 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) 1853 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
1737 clear_bit(STATUS_RF_KILL_HW, &priv->status); 1854 clear_bit(STATUS_RF_KILL_HW, &priv->status);
@@ -1739,9 +1856,10 @@ static int __iwl_up(struct iwl_priv *priv)
1739 set_bit(STATUS_RF_KILL_HW, &priv->status); 1856 set_bit(STATUS_RF_KILL_HW, &priv->status);
1740 1857
1741 if (iwl_is_rfkill(priv)) { 1858 if (iwl_is_rfkill(priv)) {
1859 wiphy_rfkill_set_hw_state(priv->hw->wiphy, true);
1860
1742 iwl_enable_interrupts(priv); 1861 iwl_enable_interrupts(priv);
1743 IWL_WARN(priv, "Radio disabled by %s RF Kill switch\n", 1862 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
1744 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
1745 return 0; 1863 return 0;
1746 } 1864 }
1747 1865
@@ -1787,9 +1905,6 @@ static int __iwl_up(struct iwl_priv *priv)
1787 continue; 1905 continue;
1788 } 1906 }
1789 1907
1790 /* Clear out the uCode error bit if it is set */
1791 clear_bit(STATUS_FW_ERROR, &priv->status);
1792
1793 /* start card; "initialize" will load runtime ucode */ 1908 /* start card; "initialize" will load runtime ucode */
1794 iwl_nic_start(priv); 1909 iwl_nic_start(priv);
1795 1910
@@ -1836,6 +1951,9 @@ static void iwl_bg_alive_start(struct work_struct *data)
1836 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 1951 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1837 return; 1952 return;
1838 1953
1954 /* enable dram interrupt */
1955 iwl_reset_ict(priv);
1956
1839 mutex_lock(&priv->mutex); 1957 mutex_lock(&priv->mutex);
1840 iwl_alive_start(priv); 1958 iwl_alive_start(priv);
1841 mutex_unlock(&priv->mutex); 1959 mutex_unlock(&priv->mutex);
@@ -1874,7 +1992,6 @@ static void iwl_bg_up(struct work_struct *data)
1874 mutex_lock(&priv->mutex); 1992 mutex_lock(&priv->mutex);
1875 __iwl_up(priv); 1993 __iwl_up(priv);
1876 mutex_unlock(&priv->mutex); 1994 mutex_unlock(&priv->mutex);
1877 iwl_rfkill_set_hw_state(priv);
1878} 1995}
1879 1996
1880static void iwl_bg_restart(struct work_struct *data) 1997static void iwl_bg_restart(struct work_struct *data)
@@ -1884,8 +2001,17 @@ static void iwl_bg_restart(struct work_struct *data)
1884 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 2001 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1885 return; 2002 return;
1886 2003
1887 iwl_down(priv); 2004 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
1888 queue_work(priv->workqueue, &priv->up); 2005 mutex_lock(&priv->mutex);
2006 priv->vif = NULL;
2007 priv->is_open = 0;
2008 mutex_unlock(&priv->mutex);
2009 iwl_down(priv);
2010 ieee80211_restart_hw(priv->hw);
2011 } else {
2012 iwl_down(priv);
2013 queue_work(priv->workqueue, &priv->up);
2014 }
1889} 2015}
1890 2016
1891static void iwl_bg_rx_replenish(struct work_struct *data) 2017static void iwl_bg_rx_replenish(struct work_struct *data)
@@ -1903,7 +2029,7 @@ static void iwl_bg_rx_replenish(struct work_struct *data)
1903 2029
1904#define IWL_DELAY_NEXT_SCAN (HZ*2) 2030#define IWL_DELAY_NEXT_SCAN (HZ*2)
1905 2031
1906static void iwl_post_associate(struct iwl_priv *priv) 2032void iwl_post_associate(struct iwl_priv *priv)
1907{ 2033{
1908 struct ieee80211_conf *conf = NULL; 2034 struct ieee80211_conf *conf = NULL;
1909 int ret = 0; 2035 int ret = 0;
@@ -1925,13 +2051,12 @@ static void iwl_post_associate(struct iwl_priv *priv)
1925 if (!priv->vif || !priv->is_open) 2051 if (!priv->vif || !priv->is_open)
1926 return; 2052 return;
1927 2053
1928 iwl_power_cancel_timeout(priv);
1929 iwl_scan_cancel_timeout(priv, 200); 2054 iwl_scan_cancel_timeout(priv, 200);
1930 2055
1931 conf = ieee80211_get_hw_conf(priv->hw); 2056 conf = ieee80211_get_hw_conf(priv->hw);
1932 2057
1933 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2058 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1934 iwl_commit_rxon(priv); 2059 iwlcore_commit_rxon(priv);
1935 2060
1936 iwl_setup_rxon_timing(priv); 2061 iwl_setup_rxon_timing(priv);
1937 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, 2062 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
@@ -1944,7 +2069,9 @@ static void iwl_post_associate(struct iwl_priv *priv)
1944 2069
1945 iwl_set_rxon_ht(priv, &priv->current_ht_config); 2070 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1946 2071
1947 iwl_set_rxon_chain(priv); 2072 if (priv->cfg->ops->hcmd->set_rxon_chain)
2073 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2074
1948 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); 2075 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
1949 2076
1950 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n", 2077 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
@@ -1966,7 +2093,7 @@ static void iwl_post_associate(struct iwl_priv *priv)
1966 2093
1967 } 2094 }
1968 2095
1969 iwl_commit_rxon(priv); 2096 iwlcore_commit_rxon(priv);
1970 2097
1971 switch (priv->iw_mode) { 2098 switch (priv->iw_mode) {
1972 case NL80211_IFTYPE_STATION: 2099 case NL80211_IFTYPE_STATION:
@@ -1999,7 +2126,7 @@ static void iwl_post_associate(struct iwl_priv *priv)
1999 * If chain noise has already been run, then we need to enable 2126 * If chain noise has already been run, then we need to enable
2000 * power management here */ 2127 * power management here */
2001 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE) 2128 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
2002 iwl_power_enable_management(priv); 2129 iwl_power_update_mode(priv, 0);
2003 2130
2004 /* Enable Rx differential gain and sensitivity calibrations */ 2131 /* Enable Rx differential gain and sensitivity calibrations */
2005 iwl_chain_noise_reset(priv); 2132 iwl_chain_noise_reset(priv);
@@ -2042,8 +2169,6 @@ static int iwl_mac_start(struct ieee80211_hw *hw)
2042 2169
2043 mutex_unlock(&priv->mutex); 2170 mutex_unlock(&priv->mutex);
2044 2171
2045 iwl_rfkill_set_hw_state(priv);
2046
2047 if (ret) 2172 if (ret)
2048 return ret; 2173 return ret;
2049 2174
@@ -2052,9 +2177,6 @@ static int iwl_mac_start(struct ieee80211_hw *hw)
2052 2177
2053 IWL_DEBUG_INFO(priv, "Start UP work done.\n"); 2178 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
2054 2179
2055 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2056 return 0;
2057
2058 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from 2180 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
2059 * mac80211 will not be run successfully. */ 2181 * mac80211 will not be run successfully. */
2060 ret = wait_event_interruptible_timeout(priv->wait_command_queue, 2182 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
@@ -2080,10 +2202,8 @@ static void iwl_mac_stop(struct ieee80211_hw *hw)
2080 2202
2081 IWL_DEBUG_MAC80211(priv, "enter\n"); 2203 IWL_DEBUG_MAC80211(priv, "enter\n");
2082 2204
2083 if (!priv->is_open) { 2205 if (!priv->is_open)
2084 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
2085 return; 2206 return;
2086 }
2087 2207
2088 priv->is_open = 0; 2208 priv->is_open = 0;
2089 2209
@@ -2123,175 +2243,7 @@ static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2123 return NETDEV_TX_OK; 2243 return NETDEV_TX_OK;
2124} 2244}
2125 2245
2126static int iwl_mac_add_interface(struct ieee80211_hw *hw, 2246void iwl_config_ap(struct iwl_priv *priv)
2127 struct ieee80211_if_init_conf *conf)
2128{
2129 struct iwl_priv *priv = hw->priv;
2130 unsigned long flags;
2131
2132 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
2133
2134 if (priv->vif) {
2135 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
2136 return -EOPNOTSUPP;
2137 }
2138
2139 spin_lock_irqsave(&priv->lock, flags);
2140 priv->vif = conf->vif;
2141 priv->iw_mode = conf->type;
2142
2143 spin_unlock_irqrestore(&priv->lock, flags);
2144
2145 mutex_lock(&priv->mutex);
2146
2147 if (conf->mac_addr) {
2148 IWL_DEBUG_MAC80211(priv, "Set %pM\n", conf->mac_addr);
2149 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2150 }
2151
2152 if (iwl_set_mode(priv, conf->type) == -EAGAIN)
2153 /* we are not ready, will run again when ready */
2154 set_bit(STATUS_MODE_PENDING, &priv->status);
2155
2156 mutex_unlock(&priv->mutex);
2157
2158 IWL_DEBUG_MAC80211(priv, "leave\n");
2159 return 0;
2160}
2161
2162/**
2163 * iwl_mac_config - mac80211 config callback
2164 *
2165 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2166 * be set inappropriately and the driver currently sets the hardware up to
2167 * use it whenever needed.
2168 */
2169static int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2170{
2171 struct iwl_priv *priv = hw->priv;
2172 const struct iwl_channel_info *ch_info;
2173 struct ieee80211_conf *conf = &hw->conf;
2174 unsigned long flags = 0;
2175 int ret = 0;
2176 u16 ch;
2177 int scan_active = 0;
2178
2179 mutex_lock(&priv->mutex);
2180 IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
2181 conf->channel->hw_value, changed);
2182
2183 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
2184 test_bit(STATUS_SCANNING, &priv->status))) {
2185 scan_active = 1;
2186 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
2187 }
2188
2189
2190 /* during scanning mac80211 will delay channel setting until
2191 * scan finish with changed = 0
2192 */
2193 if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
2194 if (scan_active)
2195 goto set_ch_out;
2196
2197 ch = ieee80211_frequency_to_channel(conf->channel->center_freq);
2198 ch_info = iwl_get_channel_info(priv, conf->channel->band, ch);
2199 if (!is_channel_valid(ch_info)) {
2200 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
2201 ret = -EINVAL;
2202 goto set_ch_out;
2203 }
2204
2205 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2206 !is_channel_ibss(ch_info)) {
2207 IWL_ERR(priv, "channel %d in band %d not "
2208 "IBSS channel\n",
2209 conf->channel->hw_value, conf->channel->band);
2210 ret = -EINVAL;
2211 goto set_ch_out;
2212 }
2213
2214 priv->current_ht_config.is_ht = conf_is_ht(conf);
2215
2216 spin_lock_irqsave(&priv->lock, flags);
2217
2218
2219 /* if we are switching from ht to 2.4 clear flags
2220 * from any ht related info since 2.4 does not
2221 * support ht */
2222 if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
2223 priv->staging_rxon.flags = 0;
2224
2225 iwl_set_rxon_channel(priv, conf->channel);
2226
2227 iwl_set_flags_for_band(priv, conf->channel->band);
2228 spin_unlock_irqrestore(&priv->lock, flags);
2229 set_ch_out:
2230 /* The list of supported rates and rate mask can be different
2231 * for each band; since the band may have changed, reset
2232 * the rate mask to what mac80211 lists */
2233 iwl_set_rate(priv);
2234 }
2235
2236 if (changed & IEEE80211_CONF_CHANGE_PS) {
2237 if (conf->flags & IEEE80211_CONF_PS)
2238 ret = iwl_power_set_user_mode(priv, IWL_POWER_INDEX_3);
2239 else
2240 ret = iwl_power_set_user_mode(priv, IWL_POWER_MODE_CAM);
2241 if (ret)
2242 IWL_DEBUG_MAC80211(priv, "Error setting power level\n");
2243
2244 }
2245
2246 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2247 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
2248 priv->tx_power_user_lmt, conf->power_level);
2249
2250 iwl_set_tx_power(priv, conf->power_level, false);
2251 }
2252
2253 /* call to ensure that 4965 rx_chain is set properly in monitor mode */
2254 iwl_set_rxon_chain(priv);
2255
2256 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
2257 if (conf->radio_enabled &&
2258 iwl_radio_kill_sw_enable_radio(priv)) {
2259 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - "
2260 "waiting for uCode\n");
2261 goto out;
2262 }
2263
2264 if (!conf->radio_enabled)
2265 iwl_radio_kill_sw_disable_radio(priv);
2266 }
2267
2268 if (!conf->radio_enabled) {
2269 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
2270 goto out;
2271 }
2272
2273 if (!iwl_is_ready(priv)) {
2274 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2275 goto out;
2276 }
2277
2278 if (scan_active)
2279 goto out;
2280
2281 if (memcmp(&priv->active_rxon,
2282 &priv->staging_rxon, sizeof(priv->staging_rxon)))
2283 iwl_commit_rxon(priv);
2284 else
2285 IWL_DEBUG_INFO(priv, "No re-sending same RXON configuration.\n");
2286
2287
2288out:
2289 IWL_DEBUG_MAC80211(priv, "leave\n");
2290 mutex_unlock(&priv->mutex);
2291 return ret;
2292}
2293
2294static void iwl_config_ap(struct iwl_priv *priv)
2295{ 2247{
2296 int ret = 0; 2248 int ret = 0;
2297 unsigned long flags; 2249 unsigned long flags;
@@ -2304,7 +2256,7 @@ static void iwl_config_ap(struct iwl_priv *priv)
2304 2256
2305 /* RXON - unassoc (to set timing command) */ 2257 /* RXON - unassoc (to set timing command) */
2306 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2258 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2307 iwl_commit_rxon(priv); 2259 iwlcore_commit_rxon(priv);
2308 2260
2309 /* RXON Timing */ 2261 /* RXON Timing */
2310 iwl_setup_rxon_timing(priv); 2262 iwl_setup_rxon_timing(priv);
@@ -2314,7 +2266,8 @@ static void iwl_config_ap(struct iwl_priv *priv)
2314 IWL_WARN(priv, "REPLY_RXON_TIMING failed - " 2266 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
2315 "Attempting to continue.\n"); 2267 "Attempting to continue.\n");
2316 2268
2317 iwl_set_rxon_chain(priv); 2269 if (priv->cfg->ops->hcmd->set_rxon_chain)
2270 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2318 2271
2319 /* FIXME: what should be the assoc_id for AP? */ 2272 /* FIXME: what should be the assoc_id for AP? */
2320 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); 2273 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
@@ -2340,7 +2293,7 @@ static void iwl_config_ap(struct iwl_priv *priv)
2340 } 2293 }
2341 /* restore RXON assoc */ 2294 /* restore RXON assoc */
2342 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 2295 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2343 iwl_commit_rxon(priv); 2296 iwlcore_commit_rxon(priv);
2344 spin_lock_irqsave(&priv->lock, flags); 2297 spin_lock_irqsave(&priv->lock, flags);
2345 iwl_activate_qos(priv, 1); 2298 iwl_activate_qos(priv, 1);
2346 spin_unlock_irqrestore(&priv->lock, flags); 2299 spin_unlock_irqrestore(&priv->lock, flags);
@@ -2353,194 +2306,6 @@ static void iwl_config_ap(struct iwl_priv *priv)
2353 * clear sta table, add BCAST sta... */ 2306 * clear sta table, add BCAST sta... */
2354} 2307}
2355 2308
2356
2357static int iwl_mac_config_interface(struct ieee80211_hw *hw,
2358 struct ieee80211_vif *vif,
2359 struct ieee80211_if_conf *conf)
2360{
2361 struct iwl_priv *priv = hw->priv;
2362 int rc;
2363
2364 if (conf == NULL)
2365 return -EIO;
2366
2367 if (priv->vif != vif) {
2368 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
2369 return 0;
2370 }
2371
2372 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2373 conf->changed & IEEE80211_IFCC_BEACON) {
2374 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2375 if (!beacon)
2376 return -ENOMEM;
2377 mutex_lock(&priv->mutex);
2378 rc = iwl_mac_beacon_update(hw, beacon);
2379 mutex_unlock(&priv->mutex);
2380 if (rc)
2381 return rc;
2382 }
2383
2384 if (!iwl_is_alive(priv))
2385 return -EAGAIN;
2386
2387 mutex_lock(&priv->mutex);
2388
2389 if (conf->bssid)
2390 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
2391
2392/*
2393 * very dubious code was here; the probe filtering flag is never set:
2394 *
2395 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2396 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
2397 */
2398
2399 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2400 if (!conf->bssid) {
2401 conf->bssid = priv->mac_addr;
2402 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
2403 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
2404 conf->bssid);
2405 }
2406 if (priv->ibss_beacon)
2407 dev_kfree_skb(priv->ibss_beacon);
2408
2409 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
2410 }
2411
2412 if (iwl_is_rfkill(priv))
2413 goto done;
2414
2415 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2416 !is_multicast_ether_addr(conf->bssid)) {
2417 /* If there is currently a HW scan going on in the background
2418 * then we need to cancel it else the RXON below will fail. */
2419 if (iwl_scan_cancel_timeout(priv, 100)) {
2420 IWL_WARN(priv, "Aborted scan still in progress "
2421 "after 100ms\n");
2422 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
2423 mutex_unlock(&priv->mutex);
2424 return -EAGAIN;
2425 }
2426 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2427
2428 /* TODO: Audit driver for usage of these members and see
2429 * if mac80211 deprecates them (priv->bssid looks like it
2430 * shouldn't be there, but I haven't scanned the IBSS code
2431 * to verify) - jpk */
2432 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2433
2434 if (priv->iw_mode == NL80211_IFTYPE_AP)
2435 iwl_config_ap(priv);
2436 else {
2437 rc = iwl_commit_rxon(priv);
2438 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
2439 iwl_rxon_add_station(
2440 priv, priv->active_rxon.bssid_addr, 1);
2441 }
2442
2443 } else {
2444 iwl_scan_cancel_timeout(priv, 100);
2445 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2446 iwl_commit_rxon(priv);
2447 }
2448
2449 done:
2450 IWL_DEBUG_MAC80211(priv, "leave\n");
2451 mutex_unlock(&priv->mutex);
2452
2453 return 0;
2454}
2455
2456static void iwl_mac_remove_interface(struct ieee80211_hw *hw,
2457 struct ieee80211_if_init_conf *conf)
2458{
2459 struct iwl_priv *priv = hw->priv;
2460
2461 IWL_DEBUG_MAC80211(priv, "enter\n");
2462
2463 mutex_lock(&priv->mutex);
2464
2465 if (iwl_is_ready_rf(priv)) {
2466 iwl_scan_cancel_timeout(priv, 100);
2467 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2468 iwl_commit_rxon(priv);
2469 }
2470 if (priv->vif == conf->vif) {
2471 priv->vif = NULL;
2472 memset(priv->bssid, 0, ETH_ALEN);
2473 }
2474 mutex_unlock(&priv->mutex);
2475
2476 IWL_DEBUG_MAC80211(priv, "leave\n");
2477
2478}
2479
2480#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
2481static void iwl_bss_info_changed(struct ieee80211_hw *hw,
2482 struct ieee80211_vif *vif,
2483 struct ieee80211_bss_conf *bss_conf,
2484 u32 changes)
2485{
2486 struct iwl_priv *priv = hw->priv;
2487
2488 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
2489
2490 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
2491 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
2492 bss_conf->use_short_preamble);
2493 if (bss_conf->use_short_preamble)
2494 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2495 else
2496 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2497 }
2498
2499 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
2500 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
2501 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
2502 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
2503 else
2504 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
2505 }
2506
2507 if (changes & BSS_CHANGED_HT) {
2508 iwl_ht_conf(priv, bss_conf);
2509 iwl_set_rxon_chain(priv);
2510 }
2511
2512 if (changes & BSS_CHANGED_ASSOC) {
2513 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
2514 /* This should never happen as this function should
2515 * never be called from interrupt context. */
2516 if (WARN_ON_ONCE(in_interrupt()))
2517 return;
2518 if (bss_conf->assoc) {
2519 priv->assoc_id = bss_conf->aid;
2520 priv->beacon_int = bss_conf->beacon_int;
2521 priv->power_data.dtim_period = bss_conf->dtim_period;
2522 priv->timestamp = bss_conf->timestamp;
2523 priv->assoc_capability = bss_conf->assoc_capability;
2524
2525 /* we have just associated, don't start scan too early
2526 * leave time for EAPOL exchange to complete
2527 */
2528 priv->next_scan_jiffies = jiffies +
2529 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
2530 mutex_lock(&priv->mutex);
2531 iwl_post_associate(priv);
2532 mutex_unlock(&priv->mutex);
2533 } else {
2534 priv->assoc_id = 0;
2535 IWL_DEBUG_MAC80211(priv, "DISASSOC %d\n", bss_conf->assoc);
2536 }
2537 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
2538 IWL_DEBUG_MAC80211(priv, "Associated Changes %d\n", changes);
2539 iwl_send_rxon_assoc(priv);
2540 }
2541
2542}
2543
2544static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw, 2309static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
2545 struct ieee80211_key_conf *keyconf, const u8 *addr, 2310 struct ieee80211_key_conf *keyconf, const u8 *addr,
2546 u32 iv32, u16 *phase1key) 2311 u32 iv32, u16 *phase1key)
@@ -2623,49 +2388,6 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2623 return ret; 2388 return ret;
2624} 2389}
2625 2390
2626static int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
2627 const struct ieee80211_tx_queue_params *params)
2628{
2629 struct iwl_priv *priv = hw->priv;
2630 unsigned long flags;
2631 int q;
2632
2633 IWL_DEBUG_MAC80211(priv, "enter\n");
2634
2635 if (!iwl_is_ready_rf(priv)) {
2636 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2637 return -EIO;
2638 }
2639
2640 if (queue >= AC_NUM) {
2641 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
2642 return 0;
2643 }
2644
2645 q = AC_NUM - 1 - queue;
2646
2647 spin_lock_irqsave(&priv->lock, flags);
2648
2649 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
2650 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
2651 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
2652 priv->qos_data.def_qos_parm.ac[q].edca_txop =
2653 cpu_to_le16((params->txop * 32));
2654
2655 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
2656 priv->qos_data.qos_active = 1;
2657
2658 if (priv->iw_mode == NL80211_IFTYPE_AP)
2659 iwl_activate_qos(priv, 1);
2660 else if (priv->assoc_id && iwl_is_associated(priv))
2661 iwl_activate_qos(priv, 0);
2662
2663 spin_unlock_irqrestore(&priv->lock, flags);
2664
2665 IWL_DEBUG_MAC80211(priv, "leave\n");
2666 return 0;
2667}
2668
2669static int iwl_mac_ampdu_action(struct ieee80211_hw *hw, 2391static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
2670 enum ieee80211_ampdu_mlme_action action, 2392 enum ieee80211_ampdu_mlme_action action,
2671 struct ieee80211_sta *sta, u16 tid, u16 *ssn) 2393 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
@@ -2708,41 +2430,6 @@ static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
2708 return 0; 2430 return 0;
2709} 2431}
2710 2432
2711static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
2712 struct ieee80211_tx_queue_stats *stats)
2713{
2714 struct iwl_priv *priv = hw->priv;
2715 int i, avail;
2716 struct iwl_tx_queue *txq;
2717 struct iwl_queue *q;
2718 unsigned long flags;
2719
2720 IWL_DEBUG_MAC80211(priv, "enter\n");
2721
2722 if (!iwl_is_ready_rf(priv)) {
2723 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2724 return -EIO;
2725 }
2726
2727 spin_lock_irqsave(&priv->lock, flags);
2728
2729 for (i = 0; i < AC_NUM; i++) {
2730 txq = &priv->txq[i];
2731 q = &txq->q;
2732 avail = iwl_queue_space(q);
2733
2734 stats[i].len = q->n_window - avail;
2735 stats[i].limit = q->n_window - q->high_mark;
2736 stats[i].count = q->n_window;
2737
2738 }
2739 spin_unlock_irqrestore(&priv->lock, flags);
2740
2741 IWL_DEBUG_MAC80211(priv, "leave\n");
2742
2743 return 0;
2744}
2745
2746static int iwl_mac_get_stats(struct ieee80211_hw *hw, 2433static int iwl_mac_get_stats(struct ieee80211_hw *hw,
2747 struct ieee80211_low_level_stats *stats) 2434 struct ieee80211_low_level_stats *stats)
2748{ 2435{
@@ -2755,120 +2442,6 @@ static int iwl_mac_get_stats(struct ieee80211_hw *hw,
2755 return 0; 2442 return 0;
2756} 2443}
2757 2444
2758static void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2759{
2760 struct iwl_priv *priv = hw->priv;
2761 unsigned long flags;
2762
2763 mutex_lock(&priv->mutex);
2764 IWL_DEBUG_MAC80211(priv, "enter\n");
2765
2766 spin_lock_irqsave(&priv->lock, flags);
2767 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
2768 spin_unlock_irqrestore(&priv->lock, flags);
2769
2770 iwl_reset_qos(priv);
2771
2772 spin_lock_irqsave(&priv->lock, flags);
2773 priv->assoc_id = 0;
2774 priv->assoc_capability = 0;
2775 priv->assoc_station_added = 0;
2776
2777 /* new association get rid of ibss beacon skb */
2778 if (priv->ibss_beacon)
2779 dev_kfree_skb(priv->ibss_beacon);
2780
2781 priv->ibss_beacon = NULL;
2782
2783 priv->beacon_int = priv->hw->conf.beacon_int;
2784 priv->timestamp = 0;
2785 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
2786 priv->beacon_int = 0;
2787
2788 spin_unlock_irqrestore(&priv->lock, flags);
2789
2790 if (!iwl_is_ready_rf(priv)) {
2791 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2792 mutex_unlock(&priv->mutex);
2793 return;
2794 }
2795
2796 /* we are restarting association process
2797 * clear RXON_FILTER_ASSOC_MSK bit
2798 */
2799 if (priv->iw_mode != NL80211_IFTYPE_AP) {
2800 iwl_scan_cancel_timeout(priv, 100);
2801 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2802 iwl_commit_rxon(priv);
2803 }
2804
2805 iwl_power_update_mode(priv, 0);
2806
2807 /* Per mac80211.h: This is only used in IBSS mode... */
2808 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
2809
2810 /* switch to CAM during association period.
2811 * the ucode will block any association/authentication
2812 * frome during assiciation period if it can not hear
2813 * the AP because of PM. the timer enable PM back is
2814 * association do not complete
2815 */
2816 if (priv->hw->conf.channel->flags & (IEEE80211_CHAN_PASSIVE_SCAN |
2817 IEEE80211_CHAN_RADAR))
2818 iwl_power_disable_management(priv, 3000);
2819
2820 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
2821 mutex_unlock(&priv->mutex);
2822 return;
2823 }
2824
2825 iwl_set_rate(priv);
2826
2827 mutex_unlock(&priv->mutex);
2828
2829 IWL_DEBUG_MAC80211(priv, "leave\n");
2830}
2831
2832static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
2833{
2834 struct iwl_priv *priv = hw->priv;
2835 unsigned long flags;
2836 __le64 timestamp;
2837
2838 IWL_DEBUG_MAC80211(priv, "enter\n");
2839
2840 if (!iwl_is_ready_rf(priv)) {
2841 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2842 return -EIO;
2843 }
2844
2845 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
2846 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
2847 return -EIO;
2848 }
2849
2850 spin_lock_irqsave(&priv->lock, flags);
2851
2852 if (priv->ibss_beacon)
2853 dev_kfree_skb(priv->ibss_beacon);
2854
2855 priv->ibss_beacon = skb;
2856
2857 priv->assoc_id = 0;
2858 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
2859 priv->timestamp = le64_to_cpu(timestamp);
2860
2861 IWL_DEBUG_MAC80211(priv, "leave\n");
2862 spin_unlock_irqrestore(&priv->lock, flags);
2863
2864 iwl_reset_qos(priv);
2865
2866 iwl_post_associate(priv);
2867
2868
2869 return 0;
2870}
2871
2872/***************************************************************************** 2445/*****************************************************************************
2873 * 2446 *
2874 * sysfs attributes 2447 * sysfs attributes
@@ -2888,7 +2461,7 @@ static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
2888static ssize_t show_debug_level(struct device *d, 2461static ssize_t show_debug_level(struct device *d,
2889 struct device_attribute *attr, char *buf) 2462 struct device_attribute *attr, char *buf)
2890{ 2463{
2891 struct iwl_priv *priv = d->driver_data; 2464 struct iwl_priv *priv = dev_get_drvdata(d);
2892 2465
2893 return sprintf(buf, "0x%08X\n", priv->debug_level); 2466 return sprintf(buf, "0x%08X\n", priv->debug_level);
2894} 2467}
@@ -2896,7 +2469,7 @@ static ssize_t store_debug_level(struct device *d,
2896 struct device_attribute *attr, 2469 struct device_attribute *attr,
2897 const char *buf, size_t count) 2470 const char *buf, size_t count)
2898{ 2471{
2899 struct iwl_priv *priv = d->driver_data; 2472 struct iwl_priv *priv = dev_get_drvdata(d);
2900 unsigned long val; 2473 unsigned long val;
2901 int ret; 2474 int ret;
2902 2475
@@ -2919,7 +2492,7 @@ static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
2919static ssize_t show_version(struct device *d, 2492static ssize_t show_version(struct device *d,
2920 struct device_attribute *attr, char *buf) 2493 struct device_attribute *attr, char *buf)
2921{ 2494{
2922 struct iwl_priv *priv = d->driver_data; 2495 struct iwl_priv *priv = dev_get_drvdata(d);
2923 struct iwl_alive_resp *palive = &priv->card_alive; 2496 struct iwl_alive_resp *palive = &priv->card_alive;
2924 ssize_t pos = 0; 2497 ssize_t pos = 0;
2925 u16 eeprom_ver; 2498 u16 eeprom_ver;
@@ -2936,8 +2509,10 @@ static ssize_t show_version(struct device *d,
2936 2509
2937 if (priv->eeprom) { 2510 if (priv->eeprom) {
2938 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION); 2511 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
2939 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n", 2512 pos += sprintf(buf + pos, "NVM Type: %s, version: 0x%x\n",
2940 eeprom_ver); 2513 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
2514 ? "OTP" : "EEPROM", eeprom_ver);
2515
2941 } else { 2516 } else {
2942 pos += sprintf(buf + pos, "EEPROM not initialzed\n"); 2517 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
2943 } 2518 }
@@ -2950,7 +2525,7 @@ static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
2950static ssize_t show_temperature(struct device *d, 2525static ssize_t show_temperature(struct device *d,
2951 struct device_attribute *attr, char *buf) 2526 struct device_attribute *attr, char *buf)
2952{ 2527{
2953 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2528 struct iwl_priv *priv = dev_get_drvdata(d);
2954 2529
2955 if (!iwl_is_alive(priv)) 2530 if (!iwl_is_alive(priv))
2956 return -EAGAIN; 2531 return -EAGAIN;
@@ -2963,7 +2538,7 @@ static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
2963static ssize_t show_tx_power(struct device *d, 2538static ssize_t show_tx_power(struct device *d,
2964 struct device_attribute *attr, char *buf) 2539 struct device_attribute *attr, char *buf)
2965{ 2540{
2966 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2541 struct iwl_priv *priv = dev_get_drvdata(d);
2967 2542
2968 if (!iwl_is_ready_rf(priv)) 2543 if (!iwl_is_ready_rf(priv))
2969 return sprintf(buf, "off\n"); 2544 return sprintf(buf, "off\n");
@@ -2975,7 +2550,7 @@ static ssize_t store_tx_power(struct device *d,
2975 struct device_attribute *attr, 2550 struct device_attribute *attr,
2976 const char *buf, size_t count) 2551 const char *buf, size_t count)
2977{ 2552{
2978 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2553 struct iwl_priv *priv = dev_get_drvdata(d);
2979 unsigned long val; 2554 unsigned long val;
2980 int ret; 2555 int ret;
2981 2556
@@ -2993,7 +2568,7 @@ static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
2993static ssize_t show_flags(struct device *d, 2568static ssize_t show_flags(struct device *d,
2994 struct device_attribute *attr, char *buf) 2569 struct device_attribute *attr, char *buf)
2995{ 2570{
2996 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2571 struct iwl_priv *priv = dev_get_drvdata(d);
2997 2572
2998 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); 2573 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
2999} 2574}
@@ -3002,7 +2577,7 @@ static ssize_t store_flags(struct device *d,
3002 struct device_attribute *attr, 2577 struct device_attribute *attr,
3003 const char *buf, size_t count) 2578 const char *buf, size_t count)
3004{ 2579{
3005 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2580 struct iwl_priv *priv = dev_get_drvdata(d);
3006 unsigned long val; 2581 unsigned long val;
3007 u32 flags; 2582 u32 flags;
3008 int ret = strict_strtoul(buf, 0, &val); 2583 int ret = strict_strtoul(buf, 0, &val);
@@ -3018,7 +2593,7 @@ static ssize_t store_flags(struct device *d,
3018 else { 2593 else {
3019 IWL_DEBUG_INFO(priv, "Commit rxon.flags = 0x%04X\n", flags); 2594 IWL_DEBUG_INFO(priv, "Commit rxon.flags = 0x%04X\n", flags);
3020 priv->staging_rxon.flags = cpu_to_le32(flags); 2595 priv->staging_rxon.flags = cpu_to_le32(flags);
3021 iwl_commit_rxon(priv); 2596 iwlcore_commit_rxon(priv);
3022 } 2597 }
3023 } 2598 }
3024 mutex_unlock(&priv->mutex); 2599 mutex_unlock(&priv->mutex);
@@ -3031,7 +2606,7 @@ static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3031static ssize_t show_filter_flags(struct device *d, 2606static ssize_t show_filter_flags(struct device *d,
3032 struct device_attribute *attr, char *buf) 2607 struct device_attribute *attr, char *buf)
3033{ 2608{
3034 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2609 struct iwl_priv *priv = dev_get_drvdata(d);
3035 2610
3036 return sprintf(buf, "0x%04X\n", 2611 return sprintf(buf, "0x%04X\n",
3037 le32_to_cpu(priv->active_rxon.filter_flags)); 2612 le32_to_cpu(priv->active_rxon.filter_flags));
@@ -3041,7 +2616,7 @@ static ssize_t store_filter_flags(struct device *d,
3041 struct device_attribute *attr, 2616 struct device_attribute *attr,
3042 const char *buf, size_t count) 2617 const char *buf, size_t count)
3043{ 2618{
3044 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2619 struct iwl_priv *priv = dev_get_drvdata(d);
3045 unsigned long val; 2620 unsigned long val;
3046 u32 filter_flags; 2621 u32 filter_flags;
3047 int ret = strict_strtoul(buf, 0, &val); 2622 int ret = strict_strtoul(buf, 0, &val);
@@ -3059,7 +2634,7 @@ static ssize_t store_filter_flags(struct device *d,
3059 "0x%04X\n", filter_flags); 2634 "0x%04X\n", filter_flags);
3060 priv->staging_rxon.filter_flags = 2635 priv->staging_rxon.filter_flags =
3061 cpu_to_le32(filter_flags); 2636 cpu_to_le32(filter_flags);
3062 iwl_commit_rxon(priv); 2637 iwlcore_commit_rxon(priv);
3063 } 2638 }
3064 } 2639 }
3065 mutex_unlock(&priv->mutex); 2640 mutex_unlock(&priv->mutex);
@@ -3102,32 +2677,37 @@ static ssize_t show_power_level(struct device *d,
3102{ 2677{
3103 struct iwl_priv *priv = dev_get_drvdata(d); 2678 struct iwl_priv *priv = dev_get_drvdata(d);
3104 int mode = priv->power_data.user_power_setting; 2679 int mode = priv->power_data.user_power_setting;
3105 int system = priv->power_data.system_power_setting;
3106 int level = priv->power_data.power_mode; 2680 int level = priv->power_data.power_mode;
3107 char *p = buf; 2681 char *p = buf;
3108 2682
3109 switch (system) { 2683 p += sprintf(p, "INDEX:%d\t", level);
3110 case IWL_POWER_SYS_AUTO: 2684 p += sprintf(p, "USER:%d\n", mode);
3111 p += sprintf(p, "SYSTEM:auto");
3112 break;
3113 case IWL_POWER_SYS_AC:
3114 p += sprintf(p, "SYSTEM:ac");
3115 break;
3116 case IWL_POWER_SYS_BATTERY:
3117 p += sprintf(p, "SYSTEM:battery");
3118 break;
3119 }
3120
3121 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
3122 "fixed" : "auto");
3123 p += sprintf(p, "\tINDEX:%d", level);
3124 p += sprintf(p, "\n");
3125 return p - buf + 1; 2685 return p - buf + 1;
3126} 2686}
3127 2687
3128static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, 2688static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
3129 store_power_level); 2689 store_power_level);
3130 2690
2691static ssize_t show_qos(struct device *d,
2692 struct device_attribute *attr, char *buf)
2693{
2694 struct iwl_priv *priv = dev_get_drvdata(d);
2695 char *p = buf;
2696 int q;
2697
2698 for (q = 0; q < AC_NUM; q++) {
2699 p += sprintf(p, "\tcw_min\tcw_max\taifsn\ttxop\n");
2700 p += sprintf(p, "AC[%d]\t%u\t%u\t%u\t%u\n", q,
2701 priv->qos_data.def_qos_parm.ac[q].cw_min,
2702 priv->qos_data.def_qos_parm.ac[q].cw_max,
2703 priv->qos_data.def_qos_parm.ac[q].aifsn,
2704 priv->qos_data.def_qos_parm.ac[q].edca_txop);
2705 }
2706
2707 return p - buf + 1;
2708}
2709
2710static DEVICE_ATTR(qos, S_IRUGO, show_qos, NULL);
3131 2711
3132static ssize_t show_statistics(struct device *d, 2712static ssize_t show_statistics(struct device *d,
3133 struct device_attribute *attr, char *buf) 2713 struct device_attribute *attr, char *buf)
@@ -3183,14 +2763,12 @@ static void iwl_setup_deferred_work(struct iwl_priv *priv)
3183 INIT_WORK(&priv->up, iwl_bg_up); 2763 INIT_WORK(&priv->up, iwl_bg_up);
3184 INIT_WORK(&priv->restart, iwl_bg_restart); 2764 INIT_WORK(&priv->restart, iwl_bg_restart);
3185 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish); 2765 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
3186 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
3187 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update); 2766 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
3188 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work); 2767 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
3189 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); 2768 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
3190 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); 2769 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
3191 2770
3192 iwl_setup_scan_deferred_work(priv); 2771 iwl_setup_scan_deferred_work(priv);
3193 iwl_setup_power_deferred_work(priv);
3194 2772
3195 if (priv->cfg->ops->lib->setup_deferred_work) 2773 if (priv->cfg->ops->lib->setup_deferred_work)
3196 priv->cfg->ops->lib->setup_deferred_work(priv); 2774 priv->cfg->ops->lib->setup_deferred_work(priv);
@@ -3199,8 +2777,12 @@ static void iwl_setup_deferred_work(struct iwl_priv *priv)
3199 priv->statistics_periodic.data = (unsigned long)priv; 2777 priv->statistics_periodic.data = (unsigned long)priv;
3200 priv->statistics_periodic.function = iwl_bg_statistics_periodic; 2778 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
3201 2779
3202 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) 2780 if (!priv->cfg->use_isr_legacy)
3203 iwl_irq_tasklet, (unsigned long)priv); 2781 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
2782 iwl_irq_tasklet, (unsigned long)priv);
2783 else
2784 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
2785 iwl_irq_tasklet_legacy, (unsigned long)priv);
3204} 2786}
3205 2787
3206static void iwl_cancel_deferred_work(struct iwl_priv *priv) 2788static void iwl_cancel_deferred_work(struct iwl_priv *priv)
@@ -3210,7 +2792,6 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv)
3210 2792
3211 cancel_delayed_work_sync(&priv->init_alive_start); 2793 cancel_delayed_work_sync(&priv->init_alive_start);
3212 cancel_delayed_work(&priv->scan_check); 2794 cancel_delayed_work(&priv->scan_check);
3213 cancel_delayed_work_sync(&priv->set_power_save);
3214 cancel_delayed_work(&priv->alive_start); 2795 cancel_delayed_work(&priv->alive_start);
3215 cancel_work_sync(&priv->beacon_update); 2796 cancel_work_sync(&priv->beacon_update);
3216 del_timer_sync(&priv->statistics_periodic); 2797 del_timer_sync(&priv->statistics_periodic);
@@ -3227,7 +2808,7 @@ static struct attribute *iwl_sysfs_entries[] = {
3227 &dev_attr_debug_level.attr, 2808 &dev_attr_debug_level.attr,
3228#endif 2809#endif
3229 &dev_attr_version.attr, 2810 &dev_attr_version.attr,
3230 2811 &dev_attr_qos.attr,
3231 NULL 2812 NULL
3232}; 2813};
3233 2814
@@ -3243,7 +2824,6 @@ static struct ieee80211_ops iwl_hw_ops = {
3243 .add_interface = iwl_mac_add_interface, 2824 .add_interface = iwl_mac_add_interface,
3244 .remove_interface = iwl_mac_remove_interface, 2825 .remove_interface = iwl_mac_remove_interface,
3245 .config = iwl_mac_config, 2826 .config = iwl_mac_config,
3246 .config_interface = iwl_mac_config_interface,
3247 .configure_filter = iwl_configure_filter, 2827 .configure_filter = iwl_configure_filter,
3248 .set_key = iwl_mac_set_key, 2828 .set_key = iwl_mac_set_key,
3249 .update_tkip_key = iwl_mac_update_tkip_key, 2829 .update_tkip_key = iwl_mac_update_tkip_key,
@@ -3291,6 +2871,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3291 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n"); 2871 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
3292 priv->cfg = cfg; 2872 priv->cfg = cfg;
3293 priv->pci_dev = pdev; 2873 priv->pci_dev = pdev;
2874 priv->inta_mask = CSR_INI_SET_MASK;
3294 2875
3295#ifdef CONFIG_IWLWIFI_DEBUG 2876#ifdef CONFIG_IWLWIFI_DEBUG
3296 priv->debug_level = priv->cfg->mod_params->debug; 2877 priv->debug_level = priv->cfg->mod_params->debug;
@@ -3341,6 +2922,10 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3341 (unsigned long long) pci_resource_len(pdev, 0)); 2922 (unsigned long long) pci_resource_len(pdev, 0));
3342 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base); 2923 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
3343 2924
2925 /* this spin lock will be used in apm_ops.init and EEPROM access
2926 * we should init now
2927 */
2928 spin_lock_init(&priv->reg_lock);
3344 iwl_hw_detect(priv); 2929 iwl_hw_detect(priv);
3345 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n", 2930 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
3346 priv->cfg->name, priv->hw_rev); 2931 priv->cfg->name, priv->hw_rev);
@@ -3349,6 +2934,12 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3349 * PCI Tx retries from interfering with C3 CPU state */ 2934 * PCI Tx retries from interfering with C3 CPU state */
3350 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00); 2935 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
3351 2936
2937 iwl_prepare_card_hw(priv);
2938 if (!priv->hw_ready) {
2939 IWL_WARN(priv, "Failed, HW not ready\n");
2940 goto out_iounmap;
2941 }
2942
3352 /* amp init */ 2943 /* amp init */
3353 err = priv->cfg->ops->lib->apm_ops.init(priv); 2944 err = priv->cfg->ops->lib->apm_ops.init(priv);
3354 if (err < 0) { 2945 if (err < 0) {
@@ -3390,18 +2981,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3390 goto out_free_eeprom; 2981 goto out_free_eeprom;
3391 /* At this point both hw and priv are initialized. */ 2982 /* At this point both hw and priv are initialized. */
3392 2983
3393 /**********************************
3394 * 7. Initialize module parameters
3395 **********************************/
3396
3397 /* Disable radio (SW RF KILL) via parameter when loading driver */
3398 if (priv->cfg->mod_params->disable) {
3399 set_bit(STATUS_RF_KILL_SW, &priv->status);
3400 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
3401 }
3402
3403 /******************** 2984 /********************
3404 * 8. Setup services 2985 * 7. Setup services
3405 ********************/ 2986 ********************/
3406 spin_lock_irqsave(&priv->lock, flags); 2987 spin_lock_irqsave(&priv->lock, flags);
3407 iwl_disable_interrupts(priv); 2988 iwl_disable_interrupts(priv);
@@ -3409,8 +2990,9 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3409 2990
3410 pci_enable_msi(priv->pci_dev); 2991 pci_enable_msi(priv->pci_dev);
3411 2992
3412 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED, 2993 iwl_alloc_isr_ict(priv);
3413 DRV_NAME, priv); 2994 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
2995 IRQF_SHARED, DRV_NAME, priv);
3414 if (err) { 2996 if (err) {
3415 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq); 2997 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3416 goto out_disable_msi; 2998 goto out_disable_msi;
@@ -3425,7 +3007,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3425 iwl_setup_rx_handlers(priv); 3007 iwl_setup_rx_handlers(priv);
3426 3008
3427 /********************************** 3009 /**********************************
3428 * 9. Setup and register mac80211 3010 * 8. Setup and register mac80211
3429 **********************************/ 3011 **********************************/
3430 3012
3431 /* enable interrupts if needed: hw bug w/a */ 3013 /* enable interrupts if needed: hw bug w/a */
@@ -3443,7 +3025,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3443 3025
3444 err = iwl_dbgfs_register(priv, DRV_NAME); 3026 err = iwl_dbgfs_register(priv, DRV_NAME);
3445 if (err) 3027 if (err)
3446 IWL_ERR(priv, "failed to create debugfs files\n"); 3028 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
3447 3029
3448 /* If platform's RF_KILL switch is NOT set to KILL */ 3030 /* If platform's RF_KILL switch is NOT set to KILL */
3449 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) 3031 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
@@ -3451,12 +3033,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3451 else 3033 else
3452 set_bit(STATUS_RF_KILL_HW, &priv->status); 3034 set_bit(STATUS_RF_KILL_HW, &priv->status);
3453 3035
3454 err = iwl_rfkill_init(priv); 3036 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
3455 if (err) 3037 test_bit(STATUS_RF_KILL_HW, &priv->status));
3456 IWL_ERR(priv, "Unable to initialize RFKILL system. "
3457 "Ignoring error: %d\n", err);
3458 else
3459 iwl_rfkill_set_hw_state(priv);
3460 3038
3461 iwl_power_initialize(priv); 3039 iwl_power_initialize(priv);
3462 return 0; 3040 return 0;
@@ -3467,6 +3045,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3467 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group); 3045 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
3468 out_free_irq: 3046 out_free_irq:
3469 free_irq(priv->pci_dev->irq, priv); 3047 free_irq(priv->pci_dev->irq, priv);
3048 iwl_free_isr_ict(priv);
3470 out_disable_msi: 3049 out_disable_msi:
3471 pci_disable_msi(priv->pci_dev); 3050 pci_disable_msi(priv->pci_dev);
3472 iwl_uninit_drv(priv); 3051 iwl_uninit_drv(priv);
@@ -3519,7 +3098,6 @@ static void __devexit iwl_pci_remove(struct pci_dev *pdev)
3519 3098
3520 iwl_synchronize_irq(priv); 3099 iwl_synchronize_irq(priv);
3521 3100
3522 iwl_rfkill_unregister(priv);
3523 iwl_dealloc_ucode_pci(priv); 3101 iwl_dealloc_ucode_pci(priv);
3524 3102
3525 if (priv->rxq.bd) 3103 if (priv->rxq.bd)
@@ -3548,51 +3126,14 @@ static void __devexit iwl_pci_remove(struct pci_dev *pdev)
3548 3126
3549 iwl_uninit_drv(priv); 3127 iwl_uninit_drv(priv);
3550 3128
3129 iwl_free_isr_ict(priv);
3130
3551 if (priv->ibss_beacon) 3131 if (priv->ibss_beacon)
3552 dev_kfree_skb(priv->ibss_beacon); 3132 dev_kfree_skb(priv->ibss_beacon);
3553 3133
3554 ieee80211_free_hw(priv->hw); 3134 ieee80211_free_hw(priv->hw);
3555} 3135}
3556 3136
3557#ifdef CONFIG_PM
3558
3559static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
3560{
3561 struct iwl_priv *priv = pci_get_drvdata(pdev);
3562
3563 if (priv->is_open) {
3564 set_bit(STATUS_IN_SUSPEND, &priv->status);
3565 iwl_mac_stop(priv->hw);
3566 priv->is_open = 1;
3567 }
3568
3569 pci_save_state(pdev);
3570 pci_disable_device(pdev);
3571 pci_set_power_state(pdev, PCI_D3hot);
3572
3573 return 0;
3574}
3575
3576static int iwl_pci_resume(struct pci_dev *pdev)
3577{
3578 struct iwl_priv *priv = pci_get_drvdata(pdev);
3579 int ret;
3580
3581 pci_set_power_state(pdev, PCI_D0);
3582 ret = pci_enable_device(pdev);
3583 if (ret)
3584 return ret;
3585 pci_restore_state(pdev);
3586 iwl_enable_interrupts(priv);
3587
3588 if (priv->is_open)
3589 iwl_mac_start(priv->hw);
3590
3591 clear_bit(STATUS_IN_SUSPEND, &priv->status);
3592 return 0;
3593}
3594
3595#endif /* CONFIG_PM */
3596 3137
3597/***************************************************************************** 3138/*****************************************************************************
3598 * 3139 *
diff --git a/drivers/net/wireless/iwlwifi/iwl-calib.c b/drivers/net/wireless/iwlwifi/iwl-calib.c
index 735f3f19928c..a5d63672ad39 100644
--- a/drivers/net/wireless/iwlwifi/iwl-calib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-calib.c
@@ -857,7 +857,7 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv,
857 priv->cfg->ops->lib->update_chain_flags(priv); 857 priv->cfg->ops->lib->update_chain_flags(priv);
858 858
859 data->state = IWL_CHAIN_NOISE_DONE; 859 data->state = IWL_CHAIN_NOISE_DONE;
860 iwl_power_enable_management(priv); 860 iwl_power_update_mode(priv, 0);
861} 861}
862EXPORT_SYMBOL(iwl_chain_noise_calibration); 862EXPORT_SYMBOL(iwl_chain_noise_calibration);
863 863
diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index 29d40746da6a..c87033bf3ad2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -614,8 +614,18 @@ enum {
614 614
615#define RXON_FLG_CHANNEL_MODE_POS (25) 615#define RXON_FLG_CHANNEL_MODE_POS (25)
616#define RXON_FLG_CHANNEL_MODE_MSK cpu_to_le32(0x3 << 25) 616#define RXON_FLG_CHANNEL_MODE_MSK cpu_to_le32(0x3 << 25)
617#define RXON_FLG_CHANNEL_MODE_PURE_40_MSK cpu_to_le32(0x1 << 25) 617
618#define RXON_FLG_CHANNEL_MODE_MIXED_MSK cpu_to_le32(0x2 << 25) 618/* channel mode */
619enum {
620 CHANNEL_MODE_LEGACY = 0,
621 CHANNEL_MODE_PURE_40 = 1,
622 CHANNEL_MODE_MIXED = 2,
623 CHANNEL_MODE_RESERVED = 3,
624};
625#define RXON_FLG_CHANNEL_MODE_LEGACY cpu_to_le32(CHANNEL_MODE_LEGACY << RXON_FLG_CHANNEL_MODE_POS)
626#define RXON_FLG_CHANNEL_MODE_PURE_40 cpu_to_le32(CHANNEL_MODE_PURE_40 << RXON_FLG_CHANNEL_MODE_POS)
627#define RXON_FLG_CHANNEL_MODE_MIXED cpu_to_le32(CHANNEL_MODE_MIXED << RXON_FLG_CHANNEL_MODE_POS)
628
619/* CTS to self (if spec allows) flag */ 629/* CTS to self (if spec allows) flag */
620#define RXON_FLG_SELF_CTS_EN cpu_to_le32(0x1<<30) 630#define RXON_FLG_SELF_CTS_EN cpu_to_le32(0x1<<30)
621 631
@@ -1057,7 +1067,7 @@ struct iwl_addsta_cmd {
1057 * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */ 1067 * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */
1058 __le16 tid_disable_tx; 1068 __le16 tid_disable_tx;
1059 1069
1060 __le16 reserved1; 1070 __le16 rate_n_flags; /* 3945 only */
1061 1071
1062 /* TID for which to add block-ack support. 1072 /* TID for which to add block-ack support.
1063 * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */ 1073 * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
@@ -1903,6 +1913,18 @@ struct iwl_link_qual_general_params {
1903 u8 start_rate_index[LINK_QUAL_AC_NUM]; 1913 u8 start_rate_index[LINK_QUAL_AC_NUM];
1904} __attribute__ ((packed)); 1914} __attribute__ ((packed));
1905 1915
1916#define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000) /* 4 milliseconds */
1917#define LINK_QUAL_AGG_TIME_LIMIT_MAX (65535)
1918#define LINK_QUAL_AGG_TIME_LIMIT_MIN (0)
1919
1920#define LINK_QUAL_AGG_DISABLE_START_DEF (3)
1921#define LINK_QUAL_AGG_DISABLE_START_MAX (255)
1922#define LINK_QUAL_AGG_DISABLE_START_MIN (0)
1923
1924#define LINK_QUAL_AGG_FRAME_LIMIT_DEF (31)
1925#define LINK_QUAL_AGG_FRAME_LIMIT_MAX (64)
1926#define LINK_QUAL_AGG_FRAME_LIMIT_MIN (0)
1927
1906/** 1928/**
1907 * struct iwl_link_qual_agg_params 1929 * struct iwl_link_qual_agg_params
1908 * 1930 *
@@ -2469,11 +2491,12 @@ struct iwl_ssid_ie {
2469 u8 ssid[32]; 2491 u8 ssid[32];
2470} __attribute__ ((packed)); 2492} __attribute__ ((packed));
2471 2493
2472#define PROBE_OPTION_MAX_API1 0x4 2494#define PROBE_OPTION_MAX_3945 4
2473#define PROBE_OPTION_MAX 0x14 2495#define PROBE_OPTION_MAX 20
2474#define TX_CMD_LIFE_TIME_INFINITE cpu_to_le32(0xFFFFFFFF) 2496#define TX_CMD_LIFE_TIME_INFINITE cpu_to_le32(0xFFFFFFFF)
2475#define IWL_GOOD_CRC_TH cpu_to_le16(1) 2497#define IWL_GOOD_CRC_TH cpu_to_le16(1)
2476#define IWL_MAX_SCAN_SIZE 1024 2498#define IWL_MAX_SCAN_SIZE 1024
2499#define IWL_MAX_PROBE_REQUEST 200
2477 2500
2478/* 2501/*
2479 * REPLY_SCAN_CMD = 0x80 (command) 2502 * REPLY_SCAN_CMD = 0x80 (command)
@@ -2552,7 +2575,7 @@ struct iwl3945_scan_cmd {
2552 struct iwl3945_tx_cmd tx_cmd; 2575 struct iwl3945_tx_cmd tx_cmd;
2553 2576
2554 /* For directed active scans (set to all-0s otherwise) */ 2577 /* For directed active scans (set to all-0s otherwise) */
2555 struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX_API1]; 2578 struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX_3945];
2556 2579
2557 /* 2580 /*
2558 * Probe request frame, followed by channel list. 2581 * Probe request frame, followed by channel list.
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index c54fb93e9d72..f9d16ca5b3d9 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -36,9 +36,9 @@
36#include "iwl-debug.h" 36#include "iwl-debug.h"
37#include "iwl-core.h" 37#include "iwl-core.h"
38#include "iwl-io.h" 38#include "iwl-io.h"
39#include "iwl-rfkill.h"
40#include "iwl-power.h" 39#include "iwl-power.h"
41#include "iwl-sta.h" 40#include "iwl-sta.h"
41#include "iwl-helpers.h"
42 42
43 43
44MODULE_DESCRIPTION("iwl core"); 44MODULE_DESCRIPTION("iwl core");
@@ -59,6 +59,8 @@ MODULE_LICENSE("GPL");
59 IWL_RATE_##pp##M_INDEX, \ 59 IWL_RATE_##pp##M_INDEX, \
60 IWL_RATE_##np##M_INDEX } 60 IWL_RATE_##np##M_INDEX }
61 61
62static irqreturn_t iwl_isr(int irq, void *data);
63
62/* 64/*
63 * Parameter order: 65 * Parameter order:
64 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate 66 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
@@ -273,6 +275,14 @@ void iwl_activate_qos(struct iwl_priv *priv, u8 force)
273} 275}
274EXPORT_SYMBOL(iwl_activate_qos); 276EXPORT_SYMBOL(iwl_activate_qos);
275 277
278/*
279 * AC CWmin CW max AIFSN TXOP Limit TXOP Limit
280 * (802.11b) (802.11a/g)
281 * AC_BK 15 1023 7 0 0
282 * AC_BE 15 1023 3 0 0
283 * AC_VI 7 15 2 6.016ms 3.008ms
284 * AC_VO 3 7 2 3.264ms 1.504ms
285 */
276void iwl_reset_qos(struct iwl_priv *priv) 286void iwl_reset_qos(struct iwl_priv *priv)
277{ 287{
278 u16 cw_min = 15; 288 u16 cw_min = 15;
@@ -304,6 +314,7 @@ void iwl_reset_qos(struct iwl_priv *priv)
304 if (priv->qos_data.qos_active) 314 if (priv->qos_data.qos_active)
305 aifs = 3; 315 aifs = 3;
306 316
317 /* AC_BE */
307 priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min); 318 priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
308 priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max); 319 priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
309 priv->qos_data.def_qos_parm.ac[0].aifsn = aifs; 320 priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
@@ -311,6 +322,7 @@ void iwl_reset_qos(struct iwl_priv *priv)
311 priv->qos_data.def_qos_parm.ac[0].reserved1 = 0; 322 priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
312 323
313 if (priv->qos_data.qos_active) { 324 if (priv->qos_data.qos_active) {
325 /* AC_BK */
314 i = 1; 326 i = 1;
315 priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min); 327 priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
316 priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max); 328 priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
@@ -318,11 +330,12 @@ void iwl_reset_qos(struct iwl_priv *priv)
318 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; 330 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
319 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; 331 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
320 332
333 /* AC_VI */
321 i = 2; 334 i = 2;
322 priv->qos_data.def_qos_parm.ac[i].cw_min = 335 priv->qos_data.def_qos_parm.ac[i].cw_min =
323 cpu_to_le16((cw_min + 1) / 2 - 1); 336 cpu_to_le16((cw_min + 1) / 2 - 1);
324 priv->qos_data.def_qos_parm.ac[i].cw_max = 337 priv->qos_data.def_qos_parm.ac[i].cw_max =
325 cpu_to_le16(cw_max); 338 cpu_to_le16(cw_min);
326 priv->qos_data.def_qos_parm.ac[i].aifsn = 2; 339 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
327 if (is_legacy) 340 if (is_legacy)
328 priv->qos_data.def_qos_parm.ac[i].edca_txop = 341 priv->qos_data.def_qos_parm.ac[i].edca_txop =
@@ -332,11 +345,12 @@ void iwl_reset_qos(struct iwl_priv *priv)
332 cpu_to_le16(3008); 345 cpu_to_le16(3008);
333 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; 346 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
334 347
348 /* AC_VO */
335 i = 3; 349 i = 3;
336 priv->qos_data.def_qos_parm.ac[i].cw_min = 350 priv->qos_data.def_qos_parm.ac[i].cw_min =
337 cpu_to_le16((cw_min + 1) / 4 - 1); 351 cpu_to_le16((cw_min + 1) / 4 - 1);
338 priv->qos_data.def_qos_parm.ac[i].cw_max = 352 priv->qos_data.def_qos_parm.ac[i].cw_max =
339 cpu_to_le16((cw_max + 1) / 2 - 1); 353 cpu_to_le16((cw_min + 1) / 2 - 1);
340 priv->qos_data.def_qos_parm.ac[i].aifsn = 2; 354 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
341 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; 355 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
342 if (is_legacy) 356 if (is_legacy)
@@ -591,10 +605,10 @@ static u8 iwl_is_channel_extension(struct iwl_priv *priv,
591 605
592 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE) 606 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
593 return !(ch_info->fat_extension_channel & 607 return !(ch_info->fat_extension_channel &
594 IEEE80211_CHAN_NO_FAT_ABOVE); 608 IEEE80211_CHAN_NO_HT40PLUS);
595 else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW) 609 else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
596 return !(ch_info->fat_extension_channel & 610 return !(ch_info->fat_extension_channel &
597 IEEE80211_CHAN_NO_FAT_BELOW); 611 IEEE80211_CHAN_NO_HT40MINUS);
598 612
599 return 0; 613 return 0;
600} 614}
@@ -605,19 +619,23 @@ u8 iwl_is_fat_tx_allowed(struct iwl_priv *priv,
605 struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config; 619 struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config;
606 620
607 if ((!iwl_ht_conf->is_ht) || 621 if ((!iwl_ht_conf->is_ht) ||
608 (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ) || 622 (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ))
609 (iwl_ht_conf->extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_NONE))
610 return 0; 623 return 0;
611 624
625 /* We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
626 * the bit will not set if it is pure 40MHz case
627 */
612 if (sta_ht_inf) { 628 if (sta_ht_inf) {
613 if ((!sta_ht_inf->ht_supported) || 629 if (!sta_ht_inf->ht_supported)
614 (!(sta_ht_inf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)))
615 return 0; 630 return 0;
616 } 631 }
617 632
618 return iwl_is_channel_extension(priv, priv->band, 633 if (iwl_ht_conf->ht_protection & IEEE80211_HT_OP_MODE_PROTECTION_20MHZ)
619 le16_to_cpu(priv->staging_rxon.channel), 634 return 1;
620 iwl_ht_conf->extension_chan_offset); 635 else
636 return iwl_is_channel_extension(priv, priv->band,
637 le16_to_cpu(priv->staging_rxon.channel),
638 iwl_ht_conf->extension_chan_offset);
621} 639}
622EXPORT_SYMBOL(iwl_is_fat_tx_allowed); 640EXPORT_SYMBOL(iwl_is_fat_tx_allowed);
623 641
@@ -735,6 +753,8 @@ int iwl_full_rxon_required(struct iwl_priv *priv)
735 priv->active_rxon.ofdm_ht_single_stream_basic_rates) || 753 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
736 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != 754 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
737 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || 755 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
756 (priv->staging_rxon.ofdm_ht_triple_stream_basic_rates !=
757 priv->active_rxon.ofdm_ht_triple_stream_basic_rates) ||
738 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) 758 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
739 return 1; 759 return 1;
740 760
@@ -785,43 +805,53 @@ EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
785void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info) 805void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
786{ 806{
787 struct iwl_rxon_cmd *rxon = &priv->staging_rxon; 807 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
788 u32 val;
789 808
790 if (!ht_info->is_ht) { 809 if (!ht_info->is_ht) {
791 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | 810 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
792 RXON_FLG_CHANNEL_MODE_PURE_40_MSK |
793 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK | 811 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
794 RXON_FLG_FAT_PROT_MSK | 812 RXON_FLG_FAT_PROT_MSK |
795 RXON_FLG_HT_PROT_MSK); 813 RXON_FLG_HT_PROT_MSK);
796 return; 814 return;
797 } 815 }
798 816
799 /* Set up channel bandwidth: 20 MHz only, or 20/40 mixed if fat ok */ 817 /* FIXME: if the definition of ht_protection changed, the "translation"
800 if (iwl_is_fat_tx_allowed(priv, NULL)) 818 * will be needed for rxon->flags
801 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED_MSK; 819 */
802 else 820 rxon->flags |= cpu_to_le32(ht_info->ht_protection << RXON_FLG_HT_OPERATING_MODE_POS);
803 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | 821
804 RXON_FLG_CHANNEL_MODE_PURE_40_MSK); 822 /* Set up channel bandwidth:
805 823 * 20 MHz only, 20/40 mixed or pure 40 if fat ok */
806 /* Note: control channel is opposite of extension channel */ 824 /* clear the HT channel mode before set the mode */
807 switch (ht_info->extension_chan_offset) { 825 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
808 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: 826 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
809 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); 827 if (iwl_is_fat_tx_allowed(priv, NULL)) {
810 break; 828 /* pure 40 fat */
811 case IEEE80211_HT_PARAM_CHA_SEC_BELOW: 829 if (rxon->flags & RXON_FLG_FAT_PROT_MSK)
812 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; 830 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
813 break; 831 else {
814 case IEEE80211_HT_PARAM_CHA_SEC_NONE: 832 /* Note: control channel is opposite of extension channel */
815 default: 833 switch (ht_info->extension_chan_offset) {
816 rxon->flags &= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK; 834 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
817 break; 835 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
836 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
837 break;
838 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
839 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
840 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
841 break;
842 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
843 default:
844 /* channel location only valid if in Mixed mode */
845 IWL_ERR(priv, "invalid extension channel offset\n");
846 break;
847 }
848 }
849 } else {
850 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
818 } 851 }
819 852
820 val = ht_info->ht_protection; 853 if (priv->cfg->ops->hcmd->set_rxon_chain)
821 854 priv->cfg->ops->hcmd->set_rxon_chain(priv);
822 rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS);
823
824 iwl_set_rxon_chain(priv);
825 855
826 IWL_DEBUG_ASSOC(priv, "supported HT rate 0x%X 0x%X 0x%X " 856 IWL_DEBUG_ASSOC(priv, "supported HT rate 0x%X 0x%X 0x%X "
827 "rxon flags 0x%X operation mode :0x%X " 857 "rxon flags 0x%X operation mode :0x%X "
@@ -901,10 +931,11 @@ static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
901 * never called for monitor mode. The only way mac80211 informs us about 931 * never called for monitor mode. The only way mac80211 informs us about
902 * monitor mode is through configuring filters (call to configure_filter). 932 * monitor mode is through configuring filters (call to configure_filter).
903 */ 933 */
904static bool iwl_is_monitor_mode(struct iwl_priv *priv) 934bool iwl_is_monitor_mode(struct iwl_priv *priv)
905{ 935{
906 return !!(priv->staging_rxon.filter_flags & RXON_FILTER_PROMISC_MSK); 936 return !!(priv->staging_rxon.filter_flags & RXON_FILTER_PROMISC_MSK);
907} 937}
938EXPORT_SYMBOL(iwl_is_monitor_mode);
908 939
909/** 940/**
910 * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image 941 * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
@@ -956,10 +987,10 @@ void iwl_set_rxon_chain(struct iwl_priv *priv)
956 if (iwl_is_monitor_mode(priv) && 987 if (iwl_is_monitor_mode(priv) &&
957 !(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) && 988 !(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) &&
958 ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)) { 989 ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)) {
959 rx_chain = 0x07 << RXON_RX_CHAIN_VALID_POS; 990 rx_chain = ANT_ABC << RXON_RX_CHAIN_VALID_POS;
960 rx_chain |= 0x06 << RXON_RX_CHAIN_FORCE_SEL_POS; 991 rx_chain |= ANT_BC << RXON_RX_CHAIN_FORCE_SEL_POS;
961 rx_chain |= 0x07 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS; 992 rx_chain |= ANT_ABC << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
962 rx_chain |= 0x01 << RXON_RX_CHAIN_DRIVER_FORCE_POS; 993 rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
963 } 994 }
964 995
965 priv->staging_rxon.rx_chain = cpu_to_le16(rx_chain); 996 priv->staging_rxon.rx_chain = cpu_to_le16(rx_chain);
@@ -1068,11 +1099,6 @@ void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
1068 RXON_FILTER_ACCEPT_GRP_MSK; 1099 RXON_FILTER_ACCEPT_GRP_MSK;
1069 break; 1100 break;
1070 1101
1071 case NL80211_IFTYPE_MONITOR:
1072 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
1073 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
1074 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
1075 break;
1076 default: 1102 default:
1077 IWL_ERR(priv, "Unsupported interface type %d\n", mode); 1103 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
1078 break; 1104 break;
@@ -1111,16 +1137,18 @@ void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
1111 priv->staging_rxon.cck_basic_rates = 1137 priv->staging_rxon.cck_basic_rates =
1112 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; 1138 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1113 1139
1114 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | 1140 /* clear both MIX and PURE40 mode flag */
1115 RXON_FLG_CHANNEL_MODE_PURE_40_MSK); 1141 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
1142 RXON_FLG_CHANNEL_MODE_PURE_40);
1116 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); 1143 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1117 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); 1144 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
1118 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; 1145 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
1119 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; 1146 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
1147 priv->staging_rxon.ofdm_ht_triple_stream_basic_rates = 0xff;
1120} 1148}
1121EXPORT_SYMBOL(iwl_connection_init_rx_config); 1149EXPORT_SYMBOL(iwl_connection_init_rx_config);
1122 1150
1123void iwl_set_rate(struct iwl_priv *priv) 1151static void iwl_set_rate(struct iwl_priv *priv)
1124{ 1152{
1125 const struct ieee80211_supported_band *hw = NULL; 1153 const struct ieee80211_supported_band *hw = NULL;
1126 struct ieee80211_rate *rate; 1154 struct ieee80211_rate *rate;
@@ -1166,7 +1194,6 @@ void iwl_set_rate(struct iwl_priv *priv)
1166 priv->staging_rxon.ofdm_basic_rates = 1194 priv->staging_rxon.ofdm_basic_rates =
1167 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; 1195 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1168} 1196}
1169EXPORT_SYMBOL(iwl_set_rate);
1170 1197
1171void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) 1198void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1172{ 1199{
@@ -1230,11 +1257,6 @@ void iwl_irq_handle_error(struct iwl_priv *priv)
1230 IWL_DEBUG(priv, IWL_DL_FW_ERRORS, 1257 IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
1231 "Restarting adapter due to uCode error.\n"); 1258 "Restarting adapter due to uCode error.\n");
1232 1259
1233 if (iwl_is_associated(priv)) {
1234 memcpy(&priv->recovery_rxon, &priv->active_rxon,
1235 sizeof(priv->recovery_rxon));
1236 priv->error_recovering = 1;
1237 }
1238 if (priv->cfg->mod_params->restart_fw) 1260 if (priv->cfg->mod_params->restart_fw)
1239 queue_work(priv->workqueue, &priv->restart); 1261 queue_work(priv->workqueue, &priv->restart);
1240 } 1262 }
@@ -1298,19 +1320,20 @@ int iwl_setup_mac(struct iwl_priv *priv)
1298 hw->flags = IEEE80211_HW_SIGNAL_DBM | 1320 hw->flags = IEEE80211_HW_SIGNAL_DBM |
1299 IEEE80211_HW_NOISE_DBM | 1321 IEEE80211_HW_NOISE_DBM |
1300 IEEE80211_HW_AMPDU_AGGREGATION | 1322 IEEE80211_HW_AMPDU_AGGREGATION |
1301 IEEE80211_HW_SPECTRUM_MGMT | 1323 IEEE80211_HW_SPECTRUM_MGMT;
1302 IEEE80211_HW_SUPPORTS_PS;
1303 hw->wiphy->interface_modes = 1324 hw->wiphy->interface_modes =
1304 BIT(NL80211_IFTYPE_STATION) | 1325 BIT(NL80211_IFTYPE_STATION) |
1305 BIT(NL80211_IFTYPE_ADHOC); 1326 BIT(NL80211_IFTYPE_ADHOC);
1306 1327
1307 hw->wiphy->custom_regulatory = true; 1328 hw->wiphy->custom_regulatory = true;
1308 hw->wiphy->max_scan_ssids = 1; 1329
1330 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
1331 /* we create the 802.11 header and a zero-length SSID element */
1332 hw->wiphy->max_scan_ie_len = IWL_MAX_PROBE_REQUEST - 24 - 2;
1309 1333
1310 /* Default value; 4 EDCA QOS priorities */ 1334 /* Default value; 4 EDCA QOS priorities */
1311 hw->queues = 4; 1335 hw->queues = 4;
1312 1336
1313 hw->conf.beacon_int = 100;
1314 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; 1337 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
1315 1338
1316 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) 1339 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
@@ -1357,7 +1380,6 @@ int iwl_init_drv(struct iwl_priv *priv)
1357 priv->ibss_beacon = NULL; 1380 priv->ibss_beacon = NULL;
1358 1381
1359 spin_lock_init(&priv->lock); 1382 spin_lock_init(&priv->lock);
1360 spin_lock_init(&priv->power_data.lock);
1361 spin_lock_init(&priv->sta_lock); 1383 spin_lock_init(&priv->sta_lock);
1362 spin_lock_init(&priv->hcmd_lock); 1384 spin_lock_init(&priv->hcmd_lock);
1363 1385
@@ -1378,7 +1400,9 @@ int iwl_init_drv(struct iwl_priv *priv)
1378 priv->current_ht_config.sm_ps = WLAN_HT_CAP_SM_PS_DISABLED; 1400 priv->current_ht_config.sm_ps = WLAN_HT_CAP_SM_PS_DISABLED;
1379 1401
1380 /* Choose which receivers/antennas to use */ 1402 /* Choose which receivers/antennas to use */
1381 iwl_set_rxon_chain(priv); 1403 if (priv->cfg->ops->hcmd->set_rxon_chain)
1404 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1405
1382 iwl_init_scan_params(priv); 1406 iwl_init_scan_params(priv);
1383 1407
1384 iwl_reset_qos(priv); 1408 iwl_reset_qos(priv);
@@ -1475,11 +1499,273 @@ void iwl_enable_interrupts(struct iwl_priv *priv)
1475{ 1499{
1476 IWL_DEBUG_ISR(priv, "Enabling interrupts\n"); 1500 IWL_DEBUG_ISR(priv, "Enabling interrupts\n");
1477 set_bit(STATUS_INT_ENABLED, &priv->status); 1501 set_bit(STATUS_INT_ENABLED, &priv->status);
1478 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); 1502 iwl_write32(priv, CSR_INT_MASK, priv->inta_mask);
1479} 1503}
1480EXPORT_SYMBOL(iwl_enable_interrupts); 1504EXPORT_SYMBOL(iwl_enable_interrupts);
1481 1505
1482irqreturn_t iwl_isr(int irq, void *data) 1506
1507#define ICT_COUNT (PAGE_SIZE/sizeof(u32))
1508
1509/* Free dram table */
1510void iwl_free_isr_ict(struct iwl_priv *priv)
1511{
1512 if (priv->ict_tbl_vir) {
1513 pci_free_consistent(priv->pci_dev, (sizeof(u32) * ICT_COUNT) +
1514 PAGE_SIZE, priv->ict_tbl_vir,
1515 priv->ict_tbl_dma);
1516 priv->ict_tbl_vir = NULL;
1517 }
1518}
1519EXPORT_SYMBOL(iwl_free_isr_ict);
1520
1521
1522/* allocate dram shared table it is a PAGE_SIZE aligned
1523 * also reset all data related to ICT table interrupt.
1524 */
1525int iwl_alloc_isr_ict(struct iwl_priv *priv)
1526{
1527
1528 if (priv->cfg->use_isr_legacy)
1529 return 0;
1530 /* allocate shrared data table */
1531 priv->ict_tbl_vir = pci_alloc_consistent(priv->pci_dev, (sizeof(u32) *
1532 ICT_COUNT) + PAGE_SIZE,
1533 &priv->ict_tbl_dma);
1534 if (!priv->ict_tbl_vir)
1535 return -ENOMEM;
1536
1537 /* align table to PAGE_SIZE boundry */
1538 priv->aligned_ict_tbl_dma = ALIGN(priv->ict_tbl_dma, PAGE_SIZE);
1539
1540 IWL_DEBUG_ISR(priv, "ict dma addr %Lx dma aligned %Lx diff %d\n",
1541 (unsigned long long)priv->ict_tbl_dma,
1542 (unsigned long long)priv->aligned_ict_tbl_dma,
1543 (int)(priv->aligned_ict_tbl_dma - priv->ict_tbl_dma));
1544
1545 priv->ict_tbl = priv->ict_tbl_vir +
1546 (priv->aligned_ict_tbl_dma - priv->ict_tbl_dma);
1547
1548 IWL_DEBUG_ISR(priv, "ict vir addr %p vir aligned %p diff %d\n",
1549 priv->ict_tbl, priv->ict_tbl_vir,
1550 (int)(priv->aligned_ict_tbl_dma - priv->ict_tbl_dma));
1551
1552 /* reset table and index to all 0 */
1553 memset(priv->ict_tbl_vir,0, (sizeof(u32) * ICT_COUNT) + PAGE_SIZE);
1554 priv->ict_index = 0;
1555
1556 /* add periodic RX interrupt */
1557 priv->inta_mask |= CSR_INT_BIT_RX_PERIODIC;
1558 return 0;
1559}
1560EXPORT_SYMBOL(iwl_alloc_isr_ict);
1561
1562/* Device is going up inform it about using ICT interrupt table,
1563 * also we need to tell the driver to start using ICT interrupt.
1564 */
1565int iwl_reset_ict(struct iwl_priv *priv)
1566{
1567 u32 val;
1568 unsigned long flags;
1569
1570 if (!priv->ict_tbl_vir)
1571 return 0;
1572
1573 spin_lock_irqsave(&priv->lock, flags);
1574 iwl_disable_interrupts(priv);
1575
1576 memset(&priv->ict_tbl[0],0, sizeof(u32) * ICT_COUNT);
1577
1578 val = priv->aligned_ict_tbl_dma >> PAGE_SHIFT;
1579
1580 val |= CSR_DRAM_INT_TBL_ENABLE;
1581 val |= CSR_DRAM_INIT_TBL_WRAP_CHECK;
1582
1583 IWL_DEBUG_ISR(priv, "CSR_DRAM_INT_TBL_REG =0x%X "
1584 "aligned dma address %Lx\n",
1585 val, (unsigned long long)priv->aligned_ict_tbl_dma);
1586
1587 iwl_write32(priv, CSR_DRAM_INT_TBL_REG, val);
1588 priv->use_ict = true;
1589 priv->ict_index = 0;
1590 iwl_write32(priv, CSR_INT, priv->inta_mask);
1591 iwl_enable_interrupts(priv);
1592 spin_unlock_irqrestore(&priv->lock, flags);
1593
1594 return 0;
1595}
1596EXPORT_SYMBOL(iwl_reset_ict);
1597
1598/* Device is going down disable ict interrupt usage */
1599void iwl_disable_ict(struct iwl_priv *priv)
1600{
1601 unsigned long flags;
1602
1603 spin_lock_irqsave(&priv->lock, flags);
1604 priv->use_ict = false;
1605 spin_unlock_irqrestore(&priv->lock, flags);
1606}
1607EXPORT_SYMBOL(iwl_disable_ict);
1608
1609/* interrupt handler using ict table, with this interrupt driver will
1610 * stop using INTA register to get device's interrupt, reading this register
1611 * is expensive, device will write interrupts in ICT dram table, increment
1612 * index then will fire interrupt to driver, driver will OR all ICT table
1613 * entries from current index up to table entry with 0 value. the result is
1614 * the interrupt we need to service, driver will set the entries back to 0 and
1615 * set index.
1616 */
1617irqreturn_t iwl_isr_ict(int irq, void *data)
1618{
1619 struct iwl_priv *priv = data;
1620 u32 inta, inta_mask;
1621 u32 val = 0;
1622
1623 if (!priv)
1624 return IRQ_NONE;
1625
1626 /* dram interrupt table not set yet,
1627 * use legacy interrupt.
1628 */
1629 if (!priv->use_ict)
1630 return iwl_isr(irq, data);
1631
1632 spin_lock(&priv->lock);
1633
1634 /* Disable (but don't clear!) interrupts here to avoid
1635 * back-to-back ISRs and sporadic interrupts from our NIC.
1636 * If we have something to service, the tasklet will re-enable ints.
1637 * If we *don't* have something, we'll re-enable before leaving here.
1638 */
1639 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1640 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1641
1642
1643 /* Ignore interrupt if there's nothing in NIC to service.
1644 * This may be due to IRQ shared with another device,
1645 * or due to sporadic interrupts thrown from our NIC. */
1646 if (!priv->ict_tbl[priv->ict_index]) {
1647 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
1648 goto none;
1649 }
1650
1651 /* read all entries that not 0 start with ict_index */
1652 while (priv->ict_tbl[priv->ict_index]) {
1653
1654 val |= priv->ict_tbl[priv->ict_index];
1655 IWL_DEBUG_ISR(priv, "ICT index %d value 0x%08X\n",
1656 priv->ict_index,
1657 priv->ict_tbl[priv->ict_index]);
1658 priv->ict_tbl[priv->ict_index] = 0;
1659 priv->ict_index = iwl_queue_inc_wrap(priv->ict_index,
1660 ICT_COUNT);
1661
1662 }
1663
1664 /* We should not get this value, just ignore it. */
1665 if (val == 0xffffffff)
1666 val = 0;
1667
1668 inta = (0xff & val) | ((0xff00 & val) << 16);
1669 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n",
1670 inta, inta_mask, val);
1671
1672 inta &= priv->inta_mask;
1673 priv->inta |= inta;
1674
1675 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1676 if (likely(inta))
1677 tasklet_schedule(&priv->irq_tasklet);
1678 else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta) {
1679 /* Allow interrupt if was disabled by this handler and
1680 * no tasklet was schedules, We should not enable interrupt,
1681 * tasklet will enable it.
1682 */
1683 iwl_enable_interrupts(priv);
1684 }
1685
1686 spin_unlock(&priv->lock);
1687 return IRQ_HANDLED;
1688
1689 none:
1690 /* re-enable interrupts here since we don't have anything to service.
1691 * only Re-enable if disabled by irq.
1692 */
1693 if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
1694 iwl_enable_interrupts(priv);
1695
1696 spin_unlock(&priv->lock);
1697 return IRQ_NONE;
1698}
1699EXPORT_SYMBOL(iwl_isr_ict);
1700
1701
1702static irqreturn_t iwl_isr(int irq, void *data)
1703{
1704 struct iwl_priv *priv = data;
1705 u32 inta, inta_mask;
1706#ifdef CONFIG_IWLWIFI_DEBUG
1707 u32 inta_fh;
1708#endif
1709 if (!priv)
1710 return IRQ_NONE;
1711
1712 spin_lock(&priv->lock);
1713
1714 /* Disable (but don't clear!) interrupts here to avoid
1715 * back-to-back ISRs and sporadic interrupts from our NIC.
1716 * If we have something to service, the tasklet will re-enable ints.
1717 * If we *don't* have something, we'll re-enable before leaving here. */
1718 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1719 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1720
1721 /* Discover which interrupts are active/pending */
1722 inta = iwl_read32(priv, CSR_INT);
1723
1724 /* Ignore interrupt if there's nothing in NIC to service.
1725 * This may be due to IRQ shared with another device,
1726 * or due to sporadic interrupts thrown from our NIC. */
1727 if (!inta) {
1728 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
1729 goto none;
1730 }
1731
1732 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1733 /* Hardware disappeared. It might have already raised
1734 * an interrupt */
1735 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
1736 goto unplugged;
1737 }
1738
1739#ifdef CONFIG_IWLWIFI_DEBUG
1740 if (priv->debug_level & (IWL_DL_ISR)) {
1741 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1742 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, "
1743 "fh 0x%08x\n", inta, inta_mask, inta_fh);
1744 }
1745#endif
1746
1747 priv->inta |= inta;
1748 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1749 if (likely(inta))
1750 tasklet_schedule(&priv->irq_tasklet);
1751 else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
1752 iwl_enable_interrupts(priv);
1753
1754 unplugged:
1755 spin_unlock(&priv->lock);
1756 return IRQ_HANDLED;
1757
1758 none:
1759 /* re-enable interrupts here since we don't have anything to service. */
1760 /* only Re-enable if diabled by irq and no schedules tasklet. */
1761 if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
1762 iwl_enable_interrupts(priv);
1763
1764 spin_unlock(&priv->lock);
1765 return IRQ_NONE;
1766}
1767
1768irqreturn_t iwl_isr_legacy(int irq, void *data)
1483{ 1769{
1484 struct iwl_priv *priv = data; 1770 struct iwl_priv *priv = data;
1485 u32 inta, inta_mask; 1771 u32 inta, inta_mask;
@@ -1536,7 +1822,7 @@ irqreturn_t iwl_isr(int irq, void *data)
1536 spin_unlock(&priv->lock); 1822 spin_unlock(&priv->lock);
1537 return IRQ_NONE; 1823 return IRQ_NONE;
1538} 1824}
1539EXPORT_SYMBOL(iwl_isr); 1825EXPORT_SYMBOL(iwl_isr_legacy);
1540 1826
1541int iwl_send_bt_config(struct iwl_priv *priv) 1827int iwl_send_bt_config(struct iwl_priv *priv)
1542{ 1828{
@@ -1580,10 +1866,6 @@ static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32
1580 1866
1581 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len); 1867 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
1582 1868
1583 ret = iwl_grab_nic_access(priv);
1584 if (ret)
1585 return ret;
1586
1587 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { 1869 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
1588 /* read data comes through single port, auto-incr addr */ 1870 /* read data comes through single port, auto-incr addr */
1589 /* NOTE: Use the debugless read so we don't flood kernel log 1871 /* NOTE: Use the debugless read so we don't flood kernel log
@@ -1599,8 +1881,6 @@ static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32
1599 } 1881 }
1600 } 1882 }
1601 1883
1602 iwl_release_nic_access(priv);
1603
1604 return ret; 1884 return ret;
1605} 1885}
1606 1886
@@ -1618,10 +1898,6 @@ static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
1618 1898
1619 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len); 1899 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
1620 1900
1621 ret = iwl_grab_nic_access(priv);
1622 if (ret)
1623 return ret;
1624
1625 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, 1901 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
1626 IWL49_RTC_INST_LOWER_BOUND); 1902 IWL49_RTC_INST_LOWER_BOUND);
1627 1903
@@ -1642,8 +1918,6 @@ static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
1642 } 1918 }
1643 } 1919 }
1644 1920
1645 iwl_release_nic_access(priv);
1646
1647 if (!errcnt) 1921 if (!errcnt)
1648 IWL_DEBUG_INFO(priv, 1922 IWL_DEBUG_INFO(priv,
1649 "ucode image in INSTRUCTION memory is good\n"); 1923 "ucode image in INSTRUCTION memory is good\n");
@@ -1752,7 +2026,6 @@ void iwl_dump_nic_error_log(struct iwl_priv *priv)
1752 u32 data2, line; 2026 u32 data2, line;
1753 u32 desc, time, count, base, data1; 2027 u32 desc, time, count, base, data1;
1754 u32 blink1, blink2, ilink1, ilink2; 2028 u32 blink1, blink2, ilink1, ilink2;
1755 int ret;
1756 2029
1757 if (priv->ucode_type == UCODE_INIT) 2030 if (priv->ucode_type == UCODE_INIT)
1758 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr); 2031 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
@@ -1764,12 +2037,6 @@ void iwl_dump_nic_error_log(struct iwl_priv *priv)
1764 return; 2037 return;
1765 } 2038 }
1766 2039
1767 ret = iwl_grab_nic_access(priv);
1768 if (ret) {
1769 IWL_WARN(priv, "Can not read from adapter at this time.\n");
1770 return;
1771 }
1772
1773 count = iwl_read_targ_mem(priv, base); 2040 count = iwl_read_targ_mem(priv, base);
1774 2041
1775 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { 2042 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
@@ -1796,7 +2063,6 @@ void iwl_dump_nic_error_log(struct iwl_priv *priv)
1796 IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, 2063 IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
1797 ilink1, ilink2); 2064 ilink1, ilink2);
1798 2065
1799 iwl_release_nic_access(priv);
1800} 2066}
1801EXPORT_SYMBOL(iwl_dump_nic_error_log); 2067EXPORT_SYMBOL(iwl_dump_nic_error_log);
1802 2068
@@ -1805,7 +2071,6 @@ EXPORT_SYMBOL(iwl_dump_nic_error_log);
1805/** 2071/**
1806 * iwl_print_event_log - Dump error event log to syslog 2072 * iwl_print_event_log - Dump error event log to syslog
1807 * 2073 *
1808 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
1809 */ 2074 */
1810static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx, 2075static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1811 u32 num_events, u32 mode) 2076 u32 num_events, u32 mode)
@@ -1851,7 +2116,6 @@ static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1851 2116
1852void iwl_dump_nic_event_log(struct iwl_priv *priv) 2117void iwl_dump_nic_event_log(struct iwl_priv *priv)
1853{ 2118{
1854 int ret;
1855 u32 base; /* SRAM byte address of event log header */ 2119 u32 base; /* SRAM byte address of event log header */
1856 u32 capacity; /* event log capacity in # entries */ 2120 u32 capacity; /* event log capacity in # entries */
1857 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ 2121 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
@@ -1869,12 +2133,6 @@ void iwl_dump_nic_event_log(struct iwl_priv *priv)
1869 return; 2133 return;
1870 } 2134 }
1871 2135
1872 ret = iwl_grab_nic_access(priv);
1873 if (ret) {
1874 IWL_WARN(priv, "Can not read from adapter at this time.\n");
1875 return;
1876 }
1877
1878 /* event log header */ 2136 /* event log header */
1879 capacity = iwl_read_targ_mem(priv, base); 2137 capacity = iwl_read_targ_mem(priv, base);
1880 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); 2138 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
@@ -1886,7 +2144,6 @@ void iwl_dump_nic_event_log(struct iwl_priv *priv)
1886 /* bail out if nothing in log */ 2144 /* bail out if nothing in log */
1887 if (size == 0) { 2145 if (size == 0) {
1888 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n"); 2146 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
1889 iwl_release_nic_access(priv);
1890 return; 2147 return;
1891 } 2148 }
1892 2149
@@ -1901,7 +2158,6 @@ void iwl_dump_nic_event_log(struct iwl_priv *priv)
1901 /* (then/else) start at top of log */ 2158 /* (then/else) start at top of log */
1902 iwl_print_event_log(priv, 0, next_entry, mode); 2159 iwl_print_event_log(priv, 0, next_entry, mode);
1903 2160
1904 iwl_release_nic_access(priv);
1905} 2161}
1906EXPORT_SYMBOL(iwl_dump_nic_event_log); 2162EXPORT_SYMBOL(iwl_dump_nic_event_log);
1907 2163
@@ -1954,161 +2210,680 @@ int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
1954} 2210}
1955EXPORT_SYMBOL(iwl_send_card_state); 2211EXPORT_SYMBOL(iwl_send_card_state);
1956 2212
1957void iwl_radio_kill_sw_disable_radio(struct iwl_priv *priv) 2213void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
2214 struct iwl_rx_mem_buffer *rxb)
1958{ 2215{
1959 unsigned long flags; 2216#ifdef CONFIG_IWLWIFI_DEBUG
2217 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2218 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
2219 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
2220 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
2221#endif
2222}
2223EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
1960 2224
1961 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) 2225void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
1962 return; 2226 struct iwl_rx_mem_buffer *rxb)
2227{
2228 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2229 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
2230 "notification for %s:\n",
2231 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
2232 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
2233}
2234EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
1963 2235
1964 IWL_DEBUG_RF_KILL(priv, "Manual SW RF KILL set to: RADIO OFF\n"); 2236void iwl_rx_reply_error(struct iwl_priv *priv,
2237 struct iwl_rx_mem_buffer *rxb)
2238{
2239 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1965 2240
1966 iwl_scan_cancel(priv); 2241 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
1967 /* FIXME: This is a workaround for AP */ 2242 "seq 0x%04X ser 0x%08X\n",
1968 if (priv->iw_mode != NL80211_IFTYPE_AP) { 2243 le32_to_cpu(pkt->u.err_resp.error_type),
1969 spin_lock_irqsave(&priv->lock, flags); 2244 get_cmd_string(pkt->u.err_resp.cmd_id),
1970 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, 2245 pkt->u.err_resp.cmd_id,
1971 CSR_UCODE_SW_BIT_RFKILL); 2246 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1972 spin_unlock_irqrestore(&priv->lock, flags); 2247 le32_to_cpu(pkt->u.err_resp.error_info));
1973 /* call the host command only if no hw rf-kill set */
1974 if (!test_bit(STATUS_RF_KILL_HW, &priv->status) &&
1975 iwl_is_ready(priv))
1976 iwl_send_card_state(priv,
1977 CARD_STATE_CMD_DISABLE, 0);
1978 set_bit(STATUS_RF_KILL_SW, &priv->status);
1979 /* make sure mac80211 stop sending Tx frame */
1980 if (priv->mac80211_registered)
1981 ieee80211_stop_queues(priv->hw);
1982 }
1983} 2248}
1984EXPORT_SYMBOL(iwl_radio_kill_sw_disable_radio); 2249EXPORT_SYMBOL(iwl_rx_reply_error);
2250
2251void iwl_clear_isr_stats(struct iwl_priv *priv)
2252{
2253 memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
2254}
2255EXPORT_SYMBOL(iwl_clear_isr_stats);
1985 2256
1986int iwl_radio_kill_sw_enable_radio(struct iwl_priv *priv) 2257int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
2258 const struct ieee80211_tx_queue_params *params)
1987{ 2259{
2260 struct iwl_priv *priv = hw->priv;
1988 unsigned long flags; 2261 unsigned long flags;
2262 int q;
2263
2264 IWL_DEBUG_MAC80211(priv, "enter\n");
2265
2266 if (!iwl_is_ready_rf(priv)) {
2267 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2268 return -EIO;
2269 }
1989 2270
1990 if (!test_bit(STATUS_RF_KILL_SW, &priv->status)) 2271 if (queue >= AC_NUM) {
2272 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
1991 return 0; 2273 return 0;
2274 }
1992 2275
1993 IWL_DEBUG_RF_KILL(priv, "Manual SW RF KILL set to: RADIO ON\n"); 2276 q = AC_NUM - 1 - queue;
1994 2277
1995 spin_lock_irqsave(&priv->lock, flags); 2278 spin_lock_irqsave(&priv->lock, flags);
1996 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
1997 2279
1998 /* If the driver is up it will receive CARD_STATE_NOTIFICATION 2280 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
1999 * notification where it will clear SW rfkill status. 2281 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
2000 * Setting it here would break the handler. Only if the 2282 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
2001 * interface is down we can set here since we don't 2283 priv->qos_data.def_qos_parm.ac[q].edca_txop =
2002 * receive any further notification. 2284 cpu_to_le16((params->txop * 32));
2003 */
2004 if (!priv->is_open)
2005 clear_bit(STATUS_RF_KILL_SW, &priv->status);
2006 spin_unlock_irqrestore(&priv->lock, flags);
2007 2285
2008 /* wake up ucode */ 2286 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
2009 msleep(10); 2287 priv->qos_data.qos_active = 1;
2288
2289 if (priv->iw_mode == NL80211_IFTYPE_AP)
2290 iwl_activate_qos(priv, 1);
2291 else if (priv->assoc_id && iwl_is_associated(priv))
2292 iwl_activate_qos(priv, 0);
2010 2293
2011 spin_lock_irqsave(&priv->lock, flags);
2012 iwl_read32(priv, CSR_UCODE_DRV_GP1);
2013 if (!iwl_grab_nic_access(priv))
2014 iwl_release_nic_access(priv);
2015 spin_unlock_irqrestore(&priv->lock, flags); 2294 spin_unlock_irqrestore(&priv->lock, flags);
2016 2295
2017 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { 2296 IWL_DEBUG_MAC80211(priv, "leave\n");
2018 IWL_DEBUG_RF_KILL(priv, "Can not turn radio back on - " 2297 return 0;
2019 "disabled by HW switch\n"); 2298}
2020 return 0; 2299EXPORT_SYMBOL(iwl_mac_conf_tx);
2021 } 2300
2301static void iwl_ht_conf(struct iwl_priv *priv,
2302 struct ieee80211_bss_conf *bss_conf)
2303{
2304 struct ieee80211_sta_ht_cap *ht_conf;
2305 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
2306 struct ieee80211_sta *sta;
2307
2308 IWL_DEBUG_MAC80211(priv, "enter: \n");
2309
2310 if (!iwl_conf->is_ht)
2311 return;
2312
2022 2313
2023 /* when driver is up while rfkill is on, it wont receive 2314 /*
2024 * any CARD_STATE_NOTIFICATION notifications so we have to 2315 * It is totally wrong to base global information on something
2025 * restart it in here 2316 * that is valid only when associated, alas, this driver works
2317 * that way and I don't know how to fix it.
2026 */ 2318 */
2027 if (priv->is_open && !test_bit(STATUS_ALIVE, &priv->status)) { 2319
2028 clear_bit(STATUS_RF_KILL_SW, &priv->status); 2320 rcu_read_lock();
2029 if (!iwl_is_rfkill(priv)) 2321 sta = ieee80211_find_sta(priv->hw, priv->bssid);
2030 queue_work(priv->workqueue, &priv->up); 2322 if (!sta) {
2323 rcu_read_unlock();
2324 return;
2031 } 2325 }
2326 ht_conf = &sta->ht_cap;
2327
2328 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
2329 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
2330 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
2331 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
2032 2332
2033 /* If the driver is already loaded, it will receive 2333 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
2034 * CARD_STATE_NOTIFICATION notifications and the handler will 2334 iwl_conf->max_amsdu_size =
2035 * call restart to reload the driver. 2335 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
2336
2337 iwl_conf->supported_chan_width =
2338 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
2339
2340 /*
2341 * XXX: The HT configuration needs to be moved into iwl_mac_config()
2342 * to be done there correctly.
2036 */ 2343 */
2037 return 1; 2344
2345 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
2346 if (conf_is_ht40_minus(&priv->hw->conf))
2347 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
2348 else if (conf_is_ht40_plus(&priv->hw->conf))
2349 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
2350
2351 /* If no above or below channel supplied disable FAT channel */
2352 if (iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_ABOVE &&
2353 iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_BELOW)
2354 iwl_conf->supported_chan_width = 0;
2355
2356 iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
2357
2358 memcpy(&iwl_conf->mcs, &ht_conf->mcs, 16);
2359
2360 iwl_conf->tx_chan_width = iwl_conf->supported_chan_width != 0;
2361 iwl_conf->ht_protection =
2362 bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
2363 iwl_conf->non_GF_STA_present =
2364 !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
2365
2366 rcu_read_unlock();
2367
2368 IWL_DEBUG_MAC80211(priv, "leave\n");
2038} 2369}
2039EXPORT_SYMBOL(iwl_radio_kill_sw_enable_radio);
2040 2370
2041void iwl_bg_rf_kill(struct work_struct *work) 2371#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
2372void iwl_bss_info_changed(struct ieee80211_hw *hw,
2373 struct ieee80211_vif *vif,
2374 struct ieee80211_bss_conf *bss_conf,
2375 u32 changes)
2042{ 2376{
2043 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); 2377 struct iwl_priv *priv = hw->priv;
2378 int ret;
2044 2379
2045 wake_up_interruptible(&priv->wait_command_queue); 2380 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
2046 2381
2047 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 2382 if (!iwl_is_alive(priv))
2048 return; 2383 return;
2049 2384
2050 mutex_lock(&priv->mutex); 2385 mutex_lock(&priv->mutex);
2051 2386
2052 if (!iwl_is_rfkill(priv)) { 2387 if (changes & BSS_CHANGED_BEACON &&
2053 IWL_DEBUG_RF_KILL(priv, 2388 priv->iw_mode == NL80211_IFTYPE_AP) {
2054 "HW and/or SW RF Kill no longer active, restarting " 2389 dev_kfree_skb(priv->ibss_beacon);
2055 "device\n"); 2390 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
2056 if (!test_bit(STATUS_EXIT_PENDING, &priv->status) && 2391 }
2057 test_bit(STATUS_ALIVE, &priv->status)) 2392
2058 queue_work(priv->workqueue, &priv->restart); 2393 if ((changes & BSS_CHANGED_BSSID) && !iwl_is_rfkill(priv)) {
2059 } else { 2394 /* If there is currently a HW scan going on in the background
2060 /* make sure mac80211 stop sending Tx frame */ 2395 * then we need to cancel it else the RXON below will fail. */
2061 if (priv->mac80211_registered) 2396 if (iwl_scan_cancel_timeout(priv, 100)) {
2062 ieee80211_stop_queues(priv->hw); 2397 IWL_WARN(priv, "Aborted scan still in progress "
2398 "after 100ms\n");
2399 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
2400 mutex_unlock(&priv->mutex);
2401 return;
2402 }
2403 memcpy(priv->staging_rxon.bssid_addr,
2404 bss_conf->bssid, ETH_ALEN);
2405
2406 /* TODO: Audit driver for usage of these members and see
2407 * if mac80211 deprecates them (priv->bssid looks like it
2408 * shouldn't be there, but I haven't scanned the IBSS code
2409 * to verify) - jpk */
2410 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
2411
2412 if (priv->iw_mode == NL80211_IFTYPE_AP)
2413 iwlcore_config_ap(priv);
2414 else {
2415 int rc = iwlcore_commit_rxon(priv);
2416 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
2417 iwl_rxon_add_station(
2418 priv, priv->active_rxon.bssid_addr, 1);
2419 }
2420 } else if (!iwl_is_rfkill(priv)) {
2421 iwl_scan_cancel_timeout(priv, 100);
2422 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2423 iwlcore_commit_rxon(priv);
2424 }
2425
2426 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2427 changes & BSS_CHANGED_BEACON) {
2428 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2429
2430 if (beacon)
2431 iwl_mac_beacon_update(hw, beacon);
2432 }
2063 2433
2064 if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) 2434 mutex_unlock(&priv->mutex);
2065 IWL_DEBUG_RF_KILL(priv, "Can not turn radio back on - " 2435
2066 "disabled by SW switch\n"); 2436 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
2437 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
2438 bss_conf->use_short_preamble);
2439 if (bss_conf->use_short_preamble)
2440 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2067 else 2441 else
2068 IWL_WARN(priv, "Radio Frequency Kill Switch is On:\n" 2442 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2069 "Kill switch must be turned off for " 2443 }
2070 "wireless networking to work.\n"); 2444
2445 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
2446 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
2447 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
2448 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
2449 else
2450 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
2451 }
2452
2453 if (changes & BSS_CHANGED_HT) {
2454 iwl_ht_conf(priv, bss_conf);
2455
2456 if (priv->cfg->ops->hcmd->set_rxon_chain)
2457 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2458 }
2459
2460 if (changes & BSS_CHANGED_ASSOC) {
2461 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
2462 /* This should never happen as this function should
2463 * never be called from interrupt context. */
2464 if (WARN_ON_ONCE(in_interrupt()))
2465 return;
2466 if (bss_conf->assoc) {
2467 priv->assoc_id = bss_conf->aid;
2468 priv->beacon_int = bss_conf->beacon_int;
2469 priv->power_data.dtim_period = bss_conf->dtim_period;
2470 priv->timestamp = bss_conf->timestamp;
2471 priv->assoc_capability = bss_conf->assoc_capability;
2472
2473 /* we have just associated, don't start scan too early
2474 * leave time for EAPOL exchange to complete
2475 */
2476 priv->next_scan_jiffies = jiffies +
2477 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
2478 mutex_lock(&priv->mutex);
2479 priv->cfg->ops->lib->post_associate(priv);
2480 mutex_unlock(&priv->mutex);
2481 } else {
2482 priv->assoc_id = 0;
2483 IWL_DEBUG_MAC80211(priv, "DISASSOC %d\n", bss_conf->assoc);
2484 }
2485 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
2486 IWL_DEBUG_MAC80211(priv, "Associated Changes %d\n", changes);
2487 ret = iwl_send_rxon_assoc(priv);
2488 if (!ret)
2489 /* Sync active_rxon with latest change. */
2490 memcpy((void *)&priv->active_rxon,
2491 &priv->staging_rxon,
2492 sizeof(struct iwl_rxon_cmd));
2493 }
2494 IWL_DEBUG_MAC80211(priv, "leave\n");
2495}
2496EXPORT_SYMBOL(iwl_bss_info_changed);
2497
2498int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
2499{
2500 struct iwl_priv *priv = hw->priv;
2501 unsigned long flags;
2502 __le64 timestamp;
2503
2504 IWL_DEBUG_MAC80211(priv, "enter\n");
2505
2506 if (!iwl_is_ready_rf(priv)) {
2507 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2508 return -EIO;
2509 }
2510
2511 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
2512 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
2513 return -EIO;
2514 }
2515
2516 spin_lock_irqsave(&priv->lock, flags);
2517
2518 if (priv->ibss_beacon)
2519 dev_kfree_skb(priv->ibss_beacon);
2520
2521 priv->ibss_beacon = skb;
2522
2523 priv->assoc_id = 0;
2524 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
2525 priv->timestamp = le64_to_cpu(timestamp);
2526
2527 IWL_DEBUG_MAC80211(priv, "leave\n");
2528 spin_unlock_irqrestore(&priv->lock, flags);
2529
2530 iwl_reset_qos(priv);
2531
2532 priv->cfg->ops->lib->post_associate(priv);
2533
2534
2535 return 0;
2536}
2537EXPORT_SYMBOL(iwl_mac_beacon_update);
2538
2539int iwl_set_mode(struct iwl_priv *priv, int mode)
2540{
2541 if (mode == NL80211_IFTYPE_ADHOC) {
2542 const struct iwl_channel_info *ch_info;
2543
2544 ch_info = iwl_get_channel_info(priv,
2545 priv->band,
2546 le16_to_cpu(priv->staging_rxon.channel));
2547
2548 if (!ch_info || !is_channel_ibss(ch_info)) {
2549 IWL_ERR(priv, "channel %d not IBSS channel\n",
2550 le16_to_cpu(priv->staging_rxon.channel));
2551 return -EINVAL;
2552 }
2553 }
2554
2555 iwl_connection_init_rx_config(priv, mode);
2556
2557 if (priv->cfg->ops->hcmd->set_rxon_chain)
2558 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2559
2560 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2561
2562 iwl_clear_stations_table(priv);
2563
2564 /* dont commit rxon if rf-kill is on*/
2565 if (!iwl_is_ready_rf(priv))
2566 return -EAGAIN;
2567
2568 iwlcore_commit_rxon(priv);
2569
2570 return 0;
2571}
2572EXPORT_SYMBOL(iwl_set_mode);
2573
2574int iwl_mac_add_interface(struct ieee80211_hw *hw,
2575 struct ieee80211_if_init_conf *conf)
2576{
2577 struct iwl_priv *priv = hw->priv;
2578 unsigned long flags;
2579
2580 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
2581
2582 if (priv->vif) {
2583 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
2584 return -EOPNOTSUPP;
2071 } 2585 }
2586
2587 spin_lock_irqsave(&priv->lock, flags);
2588 priv->vif = conf->vif;
2589 priv->iw_mode = conf->type;
2590
2591 spin_unlock_irqrestore(&priv->lock, flags);
2592
2593 mutex_lock(&priv->mutex);
2594
2595 if (conf->mac_addr) {
2596 IWL_DEBUG_MAC80211(priv, "Set %pM\n", conf->mac_addr);
2597 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2598 }
2599
2600 if (iwl_set_mode(priv, conf->type) == -EAGAIN)
2601 /* we are not ready, will run again when ready */
2602 set_bit(STATUS_MODE_PENDING, &priv->status);
2603
2072 mutex_unlock(&priv->mutex); 2604 mutex_unlock(&priv->mutex);
2073 iwl_rfkill_set_hw_state(priv); 2605
2606 IWL_DEBUG_MAC80211(priv, "leave\n");
2607 return 0;
2074} 2608}
2075EXPORT_SYMBOL(iwl_bg_rf_kill); 2609EXPORT_SYMBOL(iwl_mac_add_interface);
2076 2610
2077void iwl_rx_pm_sleep_notif(struct iwl_priv *priv, 2611void iwl_mac_remove_interface(struct ieee80211_hw *hw,
2078 struct iwl_rx_mem_buffer *rxb) 2612 struct ieee80211_if_init_conf *conf)
2079{ 2613{
2080#ifdef CONFIG_IWLWIFI_DEBUG 2614 struct iwl_priv *priv = hw->priv;
2081 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; 2615
2082 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); 2616 IWL_DEBUG_MAC80211(priv, "enter\n");
2083 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n", 2617
2084 sleep->pm_sleep_mode, sleep->pm_wakeup_src); 2618 mutex_lock(&priv->mutex);
2085#endif 2619
2620 if (iwl_is_ready_rf(priv)) {
2621 iwl_scan_cancel_timeout(priv, 100);
2622 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2623 iwlcore_commit_rxon(priv);
2624 }
2625 if (priv->vif == conf->vif) {
2626 priv->vif = NULL;
2627 memset(priv->bssid, 0, ETH_ALEN);
2628 }
2629 mutex_unlock(&priv->mutex);
2630
2631 IWL_DEBUG_MAC80211(priv, "leave\n");
2632
2086} 2633}
2087EXPORT_SYMBOL(iwl_rx_pm_sleep_notif); 2634EXPORT_SYMBOL(iwl_mac_remove_interface);
2088 2635
2089void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv, 2636/**
2090 struct iwl_rx_mem_buffer *rxb) 2637 * iwl_mac_config - mac80211 config callback
2638 *
2639 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2640 * be set inappropriately and the driver currently sets the hardware up to
2641 * use it whenever needed.
2642 */
2643int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2091{ 2644{
2092 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; 2645 struct iwl_priv *priv = hw->priv;
2093 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled " 2646 const struct iwl_channel_info *ch_info;
2094 "notification for %s:\n", 2647 struct ieee80211_conf *conf = &hw->conf;
2095 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); 2648 unsigned long flags = 0;
2096 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len)); 2649 int ret = 0;
2650 u16 ch;
2651 int scan_active = 0;
2652
2653 mutex_lock(&priv->mutex);
2654
2655 IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
2656 conf->channel->hw_value, changed);
2657
2658 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
2659 test_bit(STATUS_SCANNING, &priv->status))) {
2660 scan_active = 1;
2661 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
2662 }
2663
2664
2665 /* during scanning mac80211 will delay channel setting until
2666 * scan finish with changed = 0
2667 */
2668 if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
2669 if (scan_active)
2670 goto set_ch_out;
2671
2672 ch = ieee80211_frequency_to_channel(conf->channel->center_freq);
2673 ch_info = iwl_get_channel_info(priv, conf->channel->band, ch);
2674 if (!is_channel_valid(ch_info)) {
2675 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
2676 ret = -EINVAL;
2677 goto set_ch_out;
2678 }
2679
2680 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2681 !is_channel_ibss(ch_info)) {
2682 IWL_ERR(priv, "channel %d in band %d not "
2683 "IBSS channel\n",
2684 conf->channel->hw_value, conf->channel->band);
2685 ret = -EINVAL;
2686 goto set_ch_out;
2687 }
2688
2689 priv->current_ht_config.is_ht = conf_is_ht(conf);
2690
2691 spin_lock_irqsave(&priv->lock, flags);
2692
2693
2694 /* if we are switching from ht to 2.4 clear flags
2695 * from any ht related info since 2.4 does not
2696 * support ht */
2697 if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
2698 priv->staging_rxon.flags = 0;
2699
2700 iwl_set_rxon_channel(priv, conf->channel);
2701
2702 iwl_set_flags_for_band(priv, conf->channel->band);
2703 spin_unlock_irqrestore(&priv->lock, flags);
2704 set_ch_out:
2705 /* The list of supported rates and rate mask can be different
2706 * for each band; since the band may have changed, reset
2707 * the rate mask to what mac80211 lists */
2708 iwl_set_rate(priv);
2709 }
2710
2711 if (changed & IEEE80211_CONF_CHANGE_PS &&
2712 priv->iw_mode == NL80211_IFTYPE_STATION) {
2713 priv->power_data.power_disabled =
2714 !(conf->flags & IEEE80211_CONF_PS);
2715 ret = iwl_power_update_mode(priv, 0);
2716 if (ret)
2717 IWL_DEBUG_MAC80211(priv, "Error setting power level\n");
2718 }
2719
2720 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2721 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
2722 priv->tx_power_user_lmt, conf->power_level);
2723
2724 iwl_set_tx_power(priv, conf->power_level, false);
2725 }
2726
2727 /* call to ensure that 4965 rx_chain is set properly in monitor mode */
2728 if (priv->cfg->ops->hcmd->set_rxon_chain)
2729 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2730
2731 if (!iwl_is_ready(priv)) {
2732 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2733 goto out;
2734 }
2735
2736 if (scan_active)
2737 goto out;
2738
2739 if (memcmp(&priv->active_rxon,
2740 &priv->staging_rxon, sizeof(priv->staging_rxon)))
2741 iwlcore_commit_rxon(priv);
2742 else
2743 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration.\n");
2744
2745
2746out:
2747 IWL_DEBUG_MAC80211(priv, "leave\n");
2748 mutex_unlock(&priv->mutex);
2749 return ret;
2097} 2750}
2098EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif); 2751EXPORT_SYMBOL(iwl_mac_config);
2099 2752
2100void iwl_rx_reply_error(struct iwl_priv *priv, 2753int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
2101 struct iwl_rx_mem_buffer *rxb) 2754 struct ieee80211_tx_queue_stats *stats)
2102{ 2755{
2103 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; 2756 struct iwl_priv *priv = hw->priv;
2757 int i, avail;
2758 struct iwl_tx_queue *txq;
2759 struct iwl_queue *q;
2760 unsigned long flags;
2104 2761
2105 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) " 2762 IWL_DEBUG_MAC80211(priv, "enter\n");
2106 "seq 0x%04X ser 0x%08X\n", 2763
2107 le32_to_cpu(pkt->u.err_resp.error_type), 2764 if (!iwl_is_ready_rf(priv)) {
2108 get_cmd_string(pkt->u.err_resp.cmd_id), 2765 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2109 pkt->u.err_resp.cmd_id, 2766 return -EIO;
2110 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), 2767 }
2111 le32_to_cpu(pkt->u.err_resp.error_info)); 2768
2769 spin_lock_irqsave(&priv->lock, flags);
2770
2771 for (i = 0; i < AC_NUM; i++) {
2772 txq = &priv->txq[i];
2773 q = &txq->q;
2774 avail = iwl_queue_space(q);
2775
2776 stats[i].len = q->n_window - avail;
2777 stats[i].limit = q->n_window - q->high_mark;
2778 stats[i].count = q->n_window;
2779
2780 }
2781 spin_unlock_irqrestore(&priv->lock, flags);
2782
2783 IWL_DEBUG_MAC80211(priv, "leave\n");
2784
2785 return 0;
2112} 2786}
2113EXPORT_SYMBOL(iwl_rx_reply_error); 2787EXPORT_SYMBOL(iwl_mac_get_tx_stats);
2788
2789void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2790{
2791 struct iwl_priv *priv = hw->priv;
2792 unsigned long flags;
2793
2794 mutex_lock(&priv->mutex);
2795 IWL_DEBUG_MAC80211(priv, "enter\n");
2796
2797 spin_lock_irqsave(&priv->lock, flags);
2798 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
2799 spin_unlock_irqrestore(&priv->lock, flags);
2800
2801 iwl_reset_qos(priv);
2802
2803 spin_lock_irqsave(&priv->lock, flags);
2804 priv->assoc_id = 0;
2805 priv->assoc_capability = 0;
2806 priv->assoc_station_added = 0;
2807
2808 /* new association get rid of ibss beacon skb */
2809 if (priv->ibss_beacon)
2810 dev_kfree_skb(priv->ibss_beacon);
2811
2812 priv->ibss_beacon = NULL;
2813
2814 priv->beacon_int = priv->vif->bss_conf.beacon_int;
2815 priv->timestamp = 0;
2816 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
2817 priv->beacon_int = 0;
2818
2819 spin_unlock_irqrestore(&priv->lock, flags);
2820
2821 if (!iwl_is_ready_rf(priv)) {
2822 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2823 mutex_unlock(&priv->mutex);
2824 return;
2825 }
2826
2827 /* we are restarting association process
2828 * clear RXON_FILTER_ASSOC_MSK bit
2829 */
2830 if (priv->iw_mode != NL80211_IFTYPE_AP) {
2831 iwl_scan_cancel_timeout(priv, 100);
2832 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2833 iwlcore_commit_rxon(priv);
2834 }
2835
2836 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
2837 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
2838 mutex_unlock(&priv->mutex);
2839 return;
2840 }
2841
2842 iwl_set_rate(priv);
2843
2844 mutex_unlock(&priv->mutex);
2845
2846 IWL_DEBUG_MAC80211(priv, "leave\n");
2847}
2848EXPORT_SYMBOL(iwl_mac_reset_tsf);
2849
2850#ifdef CONFIG_PM
2851
2852int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2853{
2854 struct iwl_priv *priv = pci_get_drvdata(pdev);
2855
2856 /*
2857 * This function is called when system goes into suspend state
2858 * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
2859 * first but since iwl_mac_stop() has no knowledge of who the caller is,
2860 * it will not call apm_ops.stop() to stop the DMA operation.
2861 * Calling apm_ops.stop here to make sure we stop the DMA.
2862 */
2863 priv->cfg->ops->lib->apm_ops.stop(priv);
2864
2865 pci_save_state(pdev);
2866 pci_disable_device(pdev);
2867 pci_set_power_state(pdev, PCI_D3hot);
2868
2869 return 0;
2870}
2871EXPORT_SYMBOL(iwl_pci_suspend);
2872
2873int iwl_pci_resume(struct pci_dev *pdev)
2874{
2875 struct iwl_priv *priv = pci_get_drvdata(pdev);
2876 int ret;
2877
2878 pci_set_power_state(pdev, PCI_D0);
2879 ret = pci_enable_device(pdev);
2880 if (ret)
2881 return ret;
2882 pci_restore_state(pdev);
2883 iwl_enable_interrupts(priv);
2884
2885 return 0;
2886}
2887EXPORT_SYMBOL(iwl_pci_resume);
2114 2888
2889#endif /* CONFIG_PM */
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index a8eac8c3c1fa..dabf663e36e5 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -85,7 +85,10 @@ struct iwl_cmd;
85 85
86struct iwl_hcmd_ops { 86struct iwl_hcmd_ops {
87 int (*rxon_assoc)(struct iwl_priv *priv); 87 int (*rxon_assoc)(struct iwl_priv *priv);
88 int (*commit_rxon)(struct iwl_priv *priv);
89 void (*set_rxon_chain)(struct iwl_priv *priv);
88}; 90};
91
89struct iwl_hcmd_utils_ops { 92struct iwl_hcmd_utils_ops {
90 u16 (*get_hcmd_size)(u8 cmd_id, u16 len); 93 u16 (*get_hcmd_size)(u8 cmd_id, u16 len);
91 u16 (*build_addsta_hcmd)(const struct iwl_addsta_cmd *cmd, u8 *data); 94 u16 (*build_addsta_hcmd)(const struct iwl_addsta_cmd *cmd, u8 *data);
@@ -100,6 +103,19 @@ struct iwl_hcmd_utils_ops {
100 struct iwl_rx_phy_res *rx_resp); 103 struct iwl_rx_phy_res *rx_resp);
101}; 104};
102 105
106struct iwl_apm_ops {
107 int (*init)(struct iwl_priv *priv);
108 int (*reset)(struct iwl_priv *priv);
109 void (*stop)(struct iwl_priv *priv);
110 void (*config)(struct iwl_priv *priv);
111 int (*set_pwr_src)(struct iwl_priv *priv, enum iwl_pwr_src src);
112};
113
114struct iwl_temp_ops {
115 void (*temperature)(struct iwl_priv *priv);
116 void (*set_ct_kill)(struct iwl_priv *priv);
117};
118
103struct iwl_lib_ops { 119struct iwl_lib_ops {
104 /* set hw dependent parameters */ 120 /* set hw dependent parameters */
105 int (*set_hw_params)(struct iwl_priv *priv); 121 int (*set_hw_params)(struct iwl_priv *priv);
@@ -137,20 +153,21 @@ struct iwl_lib_ops {
137 int (*is_valid_rtc_data_addr)(u32 addr); 153 int (*is_valid_rtc_data_addr)(u32 addr);
138 /* 1st ucode load */ 154 /* 1st ucode load */
139 int (*load_ucode)(struct iwl_priv *priv); 155 int (*load_ucode)(struct iwl_priv *priv);
140 /* power management */ 156 /* power management */
141 struct { 157 struct iwl_apm_ops apm_ops;
142 int (*init)(struct iwl_priv *priv); 158
143 int (*reset)(struct iwl_priv *priv);
144 void (*stop)(struct iwl_priv *priv);
145 void (*config)(struct iwl_priv *priv);
146 int (*set_pwr_src)(struct iwl_priv *priv, enum iwl_pwr_src src);
147 } apm_ops;
148 /* power */ 159 /* power */
149 int (*send_tx_power) (struct iwl_priv *priv); 160 int (*send_tx_power) (struct iwl_priv *priv);
150 void (*update_chain_flags)(struct iwl_priv *priv); 161 void (*update_chain_flags)(struct iwl_priv *priv);
151 void (*temperature) (struct iwl_priv *priv); 162 void (*post_associate) (struct iwl_priv *priv);
163 void (*config_ap) (struct iwl_priv *priv);
164 irqreturn_t (*isr) (int irq, void *data);
165
152 /* eeprom operations (as defined in iwl-eeprom.h) */ 166 /* eeprom operations (as defined in iwl-eeprom.h) */
153 struct iwl_eeprom_ops eeprom_ops; 167 struct iwl_eeprom_ops eeprom_ops;
168
169 /* temperature */
170 struct iwl_temp_ops temp_ops;
154}; 171};
155 172
156struct iwl_ops { 173struct iwl_ops {
@@ -160,13 +177,12 @@ struct iwl_ops {
160}; 177};
161 178
162struct iwl_mod_params { 179struct iwl_mod_params {
163 int disable; /* def: 0 = enable radio */
164 int sw_crypto; /* def: 0 = using hardware encryption */ 180 int sw_crypto; /* def: 0 = using hardware encryption */
165 u32 debug; /* def: 0 = minimal debug log messages */ 181 u32 debug; /* def: 0 = minimal debug log messages */
166 int disable_hw_scan; /* def: 0 = use h/w scan */ 182 int disable_hw_scan; /* def: 0 = use h/w scan */
167 int num_of_queues; /* def: HW dependent */ 183 int num_of_queues; /* def: HW dependent */
168 int num_of_ampdu_queues;/* def: HW dependent */ 184 int num_of_ampdu_queues;/* def: HW dependent */
169 int disable_11n; /* def: 0 = disable 11n capabilities */ 185 int disable_11n; /* def: 0 = 11n capabilities enabled */
170 int amsdu_size_8K; /* def: 1 = enable 8K amsdu size */ 186 int amsdu_size_8K; /* def: 1 = enable 8K amsdu size */
171 int antenna; /* def: 0 = both antennas (use diversity) */ 187 int antenna; /* def: 0 = both antennas (use diversity) */
172 int restart_fw; /* def: 1 = restart firmware */ 188 int restart_fw; /* def: 1 = restart firmware */
@@ -214,6 +230,7 @@ struct iwl_cfg {
214 u8 valid_tx_ant; 230 u8 valid_tx_ant;
215 u8 valid_rx_ant; 231 u8 valid_rx_ant;
216 bool need_pll_cfg; 232 bool need_pll_cfg;
233 bool use_isr_legacy;
217}; 234};
218 235
219/*************************** 236/***************************
@@ -225,6 +242,8 @@ struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
225void iwl_hw_detect(struct iwl_priv *priv); 242void iwl_hw_detect(struct iwl_priv *priv);
226void iwl_reset_qos(struct iwl_priv *priv); 243void iwl_reset_qos(struct iwl_priv *priv);
227void iwl_activate_qos(struct iwl_priv *priv, u8 force); 244void iwl_activate_qos(struct iwl_priv *priv, u8 force);
245int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
246 const struct ieee80211_tx_queue_params *params);
228void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt); 247void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt);
229int iwl_check_rxon_cmd(struct iwl_priv *priv); 248int iwl_check_rxon_cmd(struct iwl_priv *priv);
230int iwl_full_rxon_required(struct iwl_priv *priv); 249int iwl_full_rxon_required(struct iwl_priv *priv);
@@ -249,6 +268,24 @@ int iwl_setup_mac(struct iwl_priv *priv);
249int iwl_set_hw_params(struct iwl_priv *priv); 268int iwl_set_hw_params(struct iwl_priv *priv);
250int iwl_init_drv(struct iwl_priv *priv); 269int iwl_init_drv(struct iwl_priv *priv);
251void iwl_uninit_drv(struct iwl_priv *priv); 270void iwl_uninit_drv(struct iwl_priv *priv);
271bool iwl_is_monitor_mode(struct iwl_priv *priv);
272void iwl_post_associate(struct iwl_priv *priv);
273void iwl_bss_info_changed(struct ieee80211_hw *hw,
274 struct ieee80211_vif *vif,
275 struct ieee80211_bss_conf *bss_conf,
276 u32 changes);
277int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb);
278int iwl_commit_rxon(struct iwl_priv *priv);
279int iwl_set_mode(struct iwl_priv *priv, int mode);
280int iwl_mac_add_interface(struct ieee80211_hw *hw,
281 struct ieee80211_if_init_conf *conf);
282void iwl_mac_remove_interface(struct ieee80211_hw *hw,
283 struct ieee80211_if_init_conf *conf);
284int iwl_mac_config(struct ieee80211_hw *hw, u32 changed);
285void iwl_config_ap(struct iwl_priv *priv);
286int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
287 struct ieee80211_tx_queue_stats *stats);
288void iwl_mac_reset_tsf(struct ieee80211_hw *hw);
252 289
253/***************************************************** 290/*****************************************************
254 * RX handlers. 291 * RX handlers.
@@ -271,10 +308,11 @@ int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv,
271 struct iwl_rx_queue *q); 308 struct iwl_rx_queue *q);
272void iwl_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq); 309void iwl_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq);
273void iwl_rx_replenish(struct iwl_priv *priv); 310void iwl_rx_replenish(struct iwl_priv *priv);
311void iwl_rx_replenish_now(struct iwl_priv *priv);
274int iwl_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq); 312int iwl_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq);
275int iwl_rx_queue_restock(struct iwl_priv *priv); 313int iwl_rx_queue_restock(struct iwl_priv *priv);
276int iwl_rx_queue_space(const struct iwl_rx_queue *q); 314int iwl_rx_queue_space(const struct iwl_rx_queue *q);
277void iwl_rx_allocate(struct iwl_priv *priv); 315void iwl_rx_allocate(struct iwl_priv *priv, gfp_t priority);
278void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb); 316void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb);
279int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index); 317int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index);
280/* Handlers */ 318/* Handlers */
@@ -310,14 +348,6 @@ int iwl_txq_check_empty(struct iwl_priv *priv, int sta_id, u8 tid, int txq_id);
310 ****************************************************/ 348 ****************************************************/
311int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force); 349int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force);
312 350
313/*****************************************************
314 * RF -Kill - here and not in iwl-rfkill.h to be available when
315 * RF-kill subsystem is not compiled.
316 ****************************************************/
317void iwl_bg_rf_kill(struct work_struct *work);
318void iwl_radio_kill_sw_disable_radio(struct iwl_priv *priv);
319int iwl_radio_kill_sw_enable_radio(struct iwl_priv *priv);
320
321/******************************************************************************* 351/*******************************************************************************
322 * Rate 352 * Rate
323 ******************************************************************************/ 353 ******************************************************************************/
@@ -328,8 +358,6 @@ int iwl_hwrate_to_plcp_idx(u32 rate_n_flags);
328 358
329u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv); 359u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv);
330 360
331void iwl_set_rate(struct iwl_priv *priv);
332
333u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant_idx); 361u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant_idx);
334 362
335static inline u32 iwl_ant_idx_to_flags(u8 ant_idx) 363static inline u32 iwl_ant_idx_to_flags(u8 ant_idx)
@@ -358,8 +386,8 @@ int iwl_scan_cancel(struct iwl_priv *priv);
358int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms); 386int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms);
359int iwl_scan_initiate(struct iwl_priv *priv); 387int iwl_scan_initiate(struct iwl_priv *priv);
360int iwl_mac_hw_scan(struct ieee80211_hw *hw, struct cfg80211_scan_request *req); 388int iwl_mac_hw_scan(struct ieee80211_hw *hw, struct cfg80211_scan_request *req);
361u16 iwl_fill_probe_req(struct iwl_priv *priv, enum ieee80211_band band, 389u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame,
362 struct ieee80211_mgmt *frame, int left); 390 const u8 *ie, int ie_len, int left);
363void iwl_setup_rx_scan_handlers(struct iwl_priv *priv); 391void iwl_setup_rx_scan_handlers(struct iwl_priv *priv);
364u16 iwl_get_active_dwell_time(struct iwl_priv *priv, 392u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
365 enum ieee80211_band band, 393 enum ieee80211_band band,
@@ -423,7 +451,13 @@ int iwl_send_card_state(struct iwl_priv *priv, u32 flags,
423 *****************************************************/ 451 *****************************************************/
424void iwl_disable_interrupts(struct iwl_priv *priv); 452void iwl_disable_interrupts(struct iwl_priv *priv);
425void iwl_enable_interrupts(struct iwl_priv *priv); 453void iwl_enable_interrupts(struct iwl_priv *priv);
426irqreturn_t iwl_isr(int irq, void *data); 454irqreturn_t iwl_isr_legacy(int irq, void *data);
455int iwl_reset_ict(struct iwl_priv *priv);
456void iwl_disable_ict(struct iwl_priv *priv);
457int iwl_alloc_isr_ict(struct iwl_priv *priv);
458void iwl_free_isr_ict(struct iwl_priv *priv);
459irqreturn_t iwl_isr_ict(int irq, void *data);
460
427static inline u16 iwl_pcie_link_ctl(struct iwl_priv *priv) 461static inline u16 iwl_pcie_link_ctl(struct iwl_priv *priv)
428{ 462{
429 int pos; 463 int pos;
@@ -432,12 +466,17 @@ static inline u16 iwl_pcie_link_ctl(struct iwl_priv *priv)
432 pci_read_config_word(priv->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl); 466 pci_read_config_word(priv->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl);
433 return pci_lnk_ctl; 467 return pci_lnk_ctl;
434} 468}
469#ifdef CONFIG_PM
470int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state);
471int iwl_pci_resume(struct pci_dev *pdev);
472#endif /* CONFIG_PM */
435 473
436/***************************************************** 474/*****************************************************
437* Error Handling Debugging 475* Error Handling Debugging
438******************************************************/ 476******************************************************/
439void iwl_dump_nic_error_log(struct iwl_priv *priv); 477void iwl_dump_nic_error_log(struct iwl_priv *priv);
440void iwl_dump_nic_event_log(struct iwl_priv *priv); 478void iwl_dump_nic_event_log(struct iwl_priv *priv);
479void iwl_clear_isr_stats(struct iwl_priv *priv);
441 480
442/***************************************************** 481/*****************************************************
443* GEOS 482* GEOS
@@ -451,14 +490,12 @@ void iwlcore_free_geos(struct iwl_priv *priv);
451#define STATUS_HCMD_SYNC_ACTIVE 1 /* sync host command in progress */ 490#define STATUS_HCMD_SYNC_ACTIVE 1 /* sync host command in progress */
452#define STATUS_INT_ENABLED 2 491#define STATUS_INT_ENABLED 2
453#define STATUS_RF_KILL_HW 3 492#define STATUS_RF_KILL_HW 3
454#define STATUS_RF_KILL_SW 4
455#define STATUS_INIT 5 493#define STATUS_INIT 5
456#define STATUS_ALIVE 6 494#define STATUS_ALIVE 6
457#define STATUS_READY 7 495#define STATUS_READY 7
458#define STATUS_TEMPERATURE 8 496#define STATUS_TEMPERATURE 8
459#define STATUS_GEO_CONFIGURED 9 497#define STATUS_GEO_CONFIGURED 9
460#define STATUS_EXIT_PENDING 10 498#define STATUS_EXIT_PENDING 10
461#define STATUS_IN_SUSPEND 11
462#define STATUS_STATISTICS 12 499#define STATUS_STATISTICS 12
463#define STATUS_SCANNING 13 500#define STATUS_SCANNING 13
464#define STATUS_SCAN_ABORTING 14 501#define STATUS_SCAN_ABORTING 14
@@ -487,11 +524,6 @@ static inline int iwl_is_init(struct iwl_priv *priv)
487 return test_bit(STATUS_INIT, &priv->status); 524 return test_bit(STATUS_INIT, &priv->status);
488} 525}
489 526
490static inline int iwl_is_rfkill_sw(struct iwl_priv *priv)
491{
492 return test_bit(STATUS_RF_KILL_SW, &priv->status);
493}
494
495static inline int iwl_is_rfkill_hw(struct iwl_priv *priv) 527static inline int iwl_is_rfkill_hw(struct iwl_priv *priv)
496{ 528{
497 return test_bit(STATUS_RF_KILL_HW, &priv->status); 529 return test_bit(STATUS_RF_KILL_HW, &priv->status);
@@ -499,7 +531,7 @@ static inline int iwl_is_rfkill_hw(struct iwl_priv *priv)
499 531
500static inline int iwl_is_rfkill(struct iwl_priv *priv) 532static inline int iwl_is_rfkill(struct iwl_priv *priv)
501{ 533{
502 return iwl_is_rfkill_hw(priv) || iwl_is_rfkill_sw(priv); 534 return iwl_is_rfkill_hw(priv);
503} 535}
504 536
505static inline int iwl_is_ready_rf(struct iwl_priv *priv) 537static inline int iwl_is_ready_rf(struct iwl_priv *priv)
@@ -528,7 +560,14 @@ static inline int iwl_send_rxon_assoc(struct iwl_priv *priv)
528{ 560{
529 return priv->cfg->ops->hcmd->rxon_assoc(priv); 561 return priv->cfg->ops->hcmd->rxon_assoc(priv);
530} 562}
531 563static inline int iwlcore_commit_rxon(struct iwl_priv *priv)
564{
565 return priv->cfg->ops->hcmd->commit_rxon(priv);
566}
567static inline void iwlcore_config_ap(struct iwl_priv *priv)
568{
569 priv->cfg->ops->lib->config_ap(priv);
570}
532static inline const struct ieee80211_supported_band *iwl_get_hw_mode( 571static inline const struct ieee80211_supported_band *iwl_get_hw_mode(
533 struct iwl_priv *priv, enum ieee80211_band band) 572 struct iwl_priv *priv, enum ieee80211_band band)
534{ 573{
diff --git a/drivers/net/wireless/iwlwifi/iwl-csr.h b/drivers/net/wireless/iwlwifi/iwl-csr.h
index 6e983149b83b..f03dae1b2f36 100644
--- a/drivers/net/wireless/iwlwifi/iwl-csr.h
+++ b/drivers/net/wireless/iwlwifi/iwl-csr.h
@@ -89,6 +89,7 @@
89/* EEPROM reads */ 89/* EEPROM reads */
90#define CSR_EEPROM_REG (CSR_BASE+0x02c) 90#define CSR_EEPROM_REG (CSR_BASE+0x02c)
91#define CSR_EEPROM_GP (CSR_BASE+0x030) 91#define CSR_EEPROM_GP (CSR_BASE+0x030)
92#define CSR_OTP_GP_REG (CSR_BASE+0x034)
92#define CSR_GIO_REG (CSR_BASE+0x03C) 93#define CSR_GIO_REG (CSR_BASE+0x03C)
93#define CSR_GP_UCODE (CSR_BASE+0x044) 94#define CSR_GP_UCODE (CSR_BASE+0x044)
94#define CSR_UCODE_DRV_GP1 (CSR_BASE+0x054) 95#define CSR_UCODE_DRV_GP1 (CSR_BASE+0x054)
@@ -96,8 +97,10 @@
96#define CSR_UCODE_DRV_GP1_CLR (CSR_BASE+0x05c) 97#define CSR_UCODE_DRV_GP1_CLR (CSR_BASE+0x05c)
97#define CSR_UCODE_DRV_GP2 (CSR_BASE+0x060) 98#define CSR_UCODE_DRV_GP2 (CSR_BASE+0x060)
98#define CSR_LED_REG (CSR_BASE+0x094) 99#define CSR_LED_REG (CSR_BASE+0x094)
100#define CSR_DRAM_INT_TBL_REG (CSR_BASE+0x0A0)
99#define CSR_GIO_CHICKEN_BITS (CSR_BASE+0x100) 101#define CSR_GIO_CHICKEN_BITS (CSR_BASE+0x100)
100 102
103#define CSR_INT_PERIODIC_REG (CSR_BASE+0x005)
101/* Analog phase-lock-loop configuration */ 104/* Analog phase-lock-loop configuration */
102#define CSR_ANA_PLL_CFG (CSR_BASE+0x20c) 105#define CSR_ANA_PLL_CFG (CSR_BASE+0x20c)
103/* 106/*
@@ -123,16 +126,18 @@
123 126
124#define CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A (0x00080000) 127#define CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A (0x00080000)
125#define CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM (0x00200000) 128#define CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM (0x00200000)
126#define CSR_HW_IF_CONFIG_REG_BIT_PCI_OWN_SEM (0x00400000) 129#define CSR_HW_IF_CONFIG_REG_BIT_NIC_READY (0x00400000)
127#define CSR_HW_IF_CONFIG_REG_BIT_ME_OWN (0x02000000) 130#define CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE (0x02000000)
128#define CSR_HW_IF_CONFIG_REG_BIT_WAKE_ME (0x08000000) 131#define CSR_HW_IF_CONFIG_REG_PREPARE (0x08000000)
129 132
133#define CSR_INT_PERIODIC_DIS (0x00)
134#define CSR_INT_PERIODIC_ENA (0xFF)
130 135
131/* interrupt flags in INTA, set by uCode or hardware (e.g. dma), 136/* interrupt flags in INTA, set by uCode or hardware (e.g. dma),
132 * acknowledged (reset) by host writing "1" to flagged bits. */ 137 * acknowledged (reset) by host writing "1" to flagged bits. */
133#define CSR_INT_BIT_FH_RX (1 << 31) /* Rx DMA, cmd responses, FH_INT[17:16] */ 138#define CSR_INT_BIT_FH_RX (1 << 31) /* Rx DMA, cmd responses, FH_INT[17:16] */
134#define CSR_INT_BIT_HW_ERR (1 << 29) /* DMA hardware error FH_INT[31] */ 139#define CSR_INT_BIT_HW_ERR (1 << 29) /* DMA hardware error FH_INT[31] */
135#define CSR_INT_BIT_DNLD (1 << 28) /* uCode Download */ 140#define CSR_INT_BIT_RX_PERIODIC (1 << 28) /* Rx periodic */
136#define CSR_INT_BIT_FH_TX (1 << 27) /* Tx DMA FH_INT[1:0] */ 141#define CSR_INT_BIT_FH_TX (1 << 27) /* Tx DMA FH_INT[1:0] */
137#define CSR_INT_BIT_SCD (1 << 26) /* TXQ pointer advanced */ 142#define CSR_INT_BIT_SCD (1 << 26) /* TXQ pointer advanced */
138#define CSR_INT_BIT_SW_ERR (1 << 25) /* uCode error */ 143#define CSR_INT_BIT_SW_ERR (1 << 25) /* uCode error */
@@ -226,6 +231,10 @@
226#define CSR_EEPROM_GP_VALID_MSK (0x00000007) 231#define CSR_EEPROM_GP_VALID_MSK (0x00000007)
227#define CSR_EEPROM_GP_BAD_SIGNATURE (0x00000000) 232#define CSR_EEPROM_GP_BAD_SIGNATURE (0x00000000)
228#define CSR_EEPROM_GP_IF_OWNER_MSK (0x00000180) 233#define CSR_EEPROM_GP_IF_OWNER_MSK (0x00000180)
234#define CSR_OTP_GP_REG_DEVICE_SELECT (0x00010000) /* 0 - EEPROM, 1 - OTP */
235#define CSR_OTP_GP_REG_OTP_ACCESS_MODE (0x00020000) /* 0 - absolute, 1 - relative */
236#define CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK (0x00100000) /* bit 20 */
237#define CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK (0x00200000) /* bit 21 */
229 238
230/* CSR GIO */ 239/* CSR GIO */
231#define CSR_GIO_REG_VAL_L0S_ENABLED (0x00000002) 240#define CSR_GIO_REG_VAL_L0S_ENABLED (0x00000002)
@@ -251,6 +260,11 @@
251 260
252/* HPET MEM debug */ 261/* HPET MEM debug */
253#define CSR_DBG_HPET_MEM_REG_VAL (0xFFFF0000) 262#define CSR_DBG_HPET_MEM_REG_VAL (0xFFFF0000)
263
264/* DRAM INT TABLE */
265#define CSR_DRAM_INT_TBL_ENABLE (1 << 31)
266#define CSR_DRAM_INIT_TBL_WRAP_CHECK (1 << 27)
267
254/*=== HBUS (Host-side Bus) ===*/ 268/*=== HBUS (Host-side Bus) ===*/
255#define HBUS_BASE (0x400) 269#define HBUS_BASE (0x400)
256/* 270/*
diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
index 65d1a7f2db9e..2cf014f523be 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
@@ -68,13 +68,14 @@ struct iwl_debugfs {
68 struct dentry *dir_rf; 68 struct dentry *dir_rf;
69 struct dir_data_files { 69 struct dir_data_files {
70 struct dentry *file_sram; 70 struct dentry *file_sram;
71 struct dentry *file_eeprom; 71 struct dentry *file_nvm;
72 struct dentry *file_stations; 72 struct dentry *file_stations;
73 struct dentry *file_rx_statistics; 73 struct dentry *file_rx_statistics;
74 struct dentry *file_tx_statistics; 74 struct dentry *file_tx_statistics;
75 struct dentry *file_log_event; 75 struct dentry *file_log_event;
76 struct dentry *file_channels; 76 struct dentry *file_channels;
77 struct dentry *file_status; 77 struct dentry *file_status;
78 struct dentry *file_interrupt;
78 } dbgfs_data_files; 79 } dbgfs_data_files;
79 struct dir_rf_files { 80 struct dir_rf_files {
80 struct dentry *file_disable_sensitivity; 81 struct dentry *file_disable_sensitivity;
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
index 64eb585f1578..11e08c068917 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
@@ -172,7 +172,6 @@ static ssize_t iwl_dbgfs_sram_read(struct file *file,
172 struct iwl_priv *priv = (struct iwl_priv *)file->private_data; 172 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
173 const size_t bufsz = sizeof(buf); 173 const size_t bufsz = sizeof(buf);
174 174
175 iwl_grab_nic_access(priv);
176 for (i = priv->dbgfs->sram_len; i > 0; i -= 4) { 175 for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
177 val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \ 176 val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
178 priv->dbgfs->sram_len - i); 177 priv->dbgfs->sram_len - i);
@@ -192,7 +191,6 @@ static ssize_t iwl_dbgfs_sram_read(struct file *file,
192 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val); 191 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
193 } 192 }
194 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 193 pos += scnprintf(buf + pos, bufsz - pos, "\n");
195 iwl_release_nic_access(priv);
196 194
197 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 195 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
198 return ret; 196 return ret;
@@ -292,7 +290,7 @@ static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
292 return ret; 290 return ret;
293} 291}
294 292
295static ssize_t iwl_dbgfs_eeprom_read(struct file *file, 293static ssize_t iwl_dbgfs_nvm_read(struct file *file,
296 char __user *user_buf, 294 char __user *user_buf,
297 size_t count, 295 size_t count,
298 loff_t *ppos) 296 loff_t *ppos)
@@ -306,7 +304,7 @@ static ssize_t iwl_dbgfs_eeprom_read(struct file *file,
306 buf_size = 4 * eeprom_len + 256; 304 buf_size = 4 * eeprom_len + 256;
307 305
308 if (eeprom_len % 16) { 306 if (eeprom_len % 16) {
309 IWL_ERR(priv, "EEPROM size is not multiple of 16.\n"); 307 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
310 return -ENODATA; 308 return -ENODATA;
311 } 309 }
312 310
@@ -318,6 +316,13 @@ static ssize_t iwl_dbgfs_eeprom_read(struct file *file,
318 } 316 }
319 317
320 ptr = priv->eeprom; 318 ptr = priv->eeprom;
319 if (!ptr) {
320 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
321 return -ENOMEM;
322 }
323 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s\n",
324 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
325 ? "OTP" : "EEPROM");
321 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) { 326 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
322 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs); 327 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
323 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos, 328 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
@@ -375,51 +380,53 @@ static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
375 } 380 }
376 381
377 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ); 382 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
378 channels = supp_band->channels; 383 if (supp_band) {
379 384 channels = supp_band->channels;
380 pos += scnprintf(buf + pos, bufsz - pos,
381 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
382 supp_band->n_channels);
383 385
384 for (i = 0; i < supp_band->n_channels; i++)
385 pos += scnprintf(buf + pos, bufsz - pos, 386 pos += scnprintf(buf + pos, bufsz - pos,
386 "%d: %ddBm: BSS%s%s, %s.\n", 387 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
387 ieee80211_frequency_to_channel( 388 supp_band->n_channels);
388 channels[i].center_freq),
389 channels[i].max_power,
390 channels[i].flags & IEEE80211_CHAN_RADAR ?
391 " (IEEE 802.11h required)" : "",
392 (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS)
393 || (channels[i].flags &
394 IEEE80211_CHAN_RADAR)) ? "" :
395 ", IBSS",
396 channels[i].flags &
397 IEEE80211_CHAN_PASSIVE_SCAN ?
398 "passive only" : "active/passive");
399 389
390 for (i = 0; i < supp_band->n_channels; i++)
391 pos += scnprintf(buf + pos, bufsz - pos,
392 "%d: %ddBm: BSS%s%s, %s.\n",
393 ieee80211_frequency_to_channel(
394 channels[i].center_freq),
395 channels[i].max_power,
396 channels[i].flags & IEEE80211_CHAN_RADAR ?
397 " (IEEE 802.11h required)" : "",
398 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
399 || (channels[i].flags &
400 IEEE80211_CHAN_RADAR)) ? "" :
401 ", IBSS",
402 channels[i].flags &
403 IEEE80211_CHAN_PASSIVE_SCAN ?
404 "passive only" : "active/passive");
405 }
400 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ); 406 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
401 channels = supp_band->channels; 407 if (supp_band) {
402 408 channels = supp_band->channels;
403 pos += scnprintf(buf + pos, bufsz - pos,
404 "Displaying %d channels in 5.2GHz band (802.11a)\n",
405 supp_band->n_channels);
406 409
407 for (i = 0; i < supp_band->n_channels; i++)
408 pos += scnprintf(buf + pos, bufsz - pos, 410 pos += scnprintf(buf + pos, bufsz - pos,
409 "%d: %ddBm: BSS%s%s, %s.\n", 411 "Displaying %d channels in 5.2GHz band (802.11a)\n",
410 ieee80211_frequency_to_channel( 412 supp_band->n_channels);
411 channels[i].center_freq),
412 channels[i].max_power,
413 channels[i].flags & IEEE80211_CHAN_RADAR ?
414 " (IEEE 802.11h required)" : "",
415 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
416 || (channels[i].flags &
417 IEEE80211_CHAN_RADAR)) ? "" :
418 ", IBSS",
419 channels[i].flags &
420 IEEE80211_CHAN_PASSIVE_SCAN ?
421 "passive only" : "active/passive");
422 413
414 for (i = 0; i < supp_band->n_channels; i++)
415 pos += scnprintf(buf + pos, bufsz - pos,
416 "%d: %ddBm: BSS%s%s, %s.\n",
417 ieee80211_frequency_to_channel(
418 channels[i].center_freq),
419 channels[i].max_power,
420 channels[i].flags & IEEE80211_CHAN_RADAR ?
421 " (IEEE 802.11h required)" : "",
422 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
423 || (channels[i].flags &
424 IEEE80211_CHAN_RADAR)) ? "" :
425 ", IBSS",
426 channels[i].flags &
427 IEEE80211_CHAN_PASSIVE_SCAN ?
428 "passive only" : "active/passive");
429 }
423 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 430 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
424 kfree(buf); 431 kfree(buf);
425 return ret; 432 return ret;
@@ -442,8 +449,6 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
442 test_bit(STATUS_INT_ENABLED, &priv->status)); 449 test_bit(STATUS_INT_ENABLED, &priv->status));
443 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n", 450 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
444 test_bit(STATUS_RF_KILL_HW, &priv->status)); 451 test_bit(STATUS_RF_KILL_HW, &priv->status));
445 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_SW:\t %d\n",
446 test_bit(STATUS_RF_KILL_SW, &priv->status));
447 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n", 452 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
448 test_bit(STATUS_INIT, &priv->status)); 453 test_bit(STATUS_INIT, &priv->status));
449 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n", 454 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
@@ -456,8 +461,6 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
456 test_bit(STATUS_GEO_CONFIGURED, &priv->status)); 461 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
457 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n", 462 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
458 test_bit(STATUS_EXIT_PENDING, &priv->status)); 463 test_bit(STATUS_EXIT_PENDING, &priv->status));
459 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_IN_SUSPEND:\t %d\n",
460 test_bit(STATUS_IN_SUSPEND, &priv->status));
461 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n", 464 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
462 test_bit(STATUS_STATISTICS, &priv->status)); 465 test_bit(STATUS_STATISTICS, &priv->status));
463 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n", 466 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
@@ -475,14 +478,104 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
475 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 478 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
476} 479}
477 480
481static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
482 char __user *user_buf,
483 size_t count, loff_t *ppos) {
484
485 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
486 int pos = 0;
487 int cnt = 0;
488 char *buf;
489 int bufsz = 24 * 64; /* 24 items * 64 char per item */
490 ssize_t ret;
491
492 buf = kzalloc(bufsz, GFP_KERNEL);
493 if (!buf) {
494 IWL_ERR(priv, "Can not allocate Buffer\n");
495 return -ENOMEM;
496 }
497
498 pos += scnprintf(buf + pos, bufsz - pos,
499 "Interrupt Statistics Report:\n");
500
501 pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
502 priv->isr_stats.hw);
503 pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
504 priv->isr_stats.sw);
505 if (priv->isr_stats.sw > 0) {
506 pos += scnprintf(buf + pos, bufsz - pos,
507 "\tLast Restarting Code: 0x%X\n",
508 priv->isr_stats.sw_err);
509 }
510#ifdef CONFIG_IWLWIFI_DEBUG
511 pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
512 priv->isr_stats.sch);
513 pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
514 priv->isr_stats.alive);
515#endif
516 pos += scnprintf(buf + pos, bufsz - pos,
517 "HW RF KILL switch toggled:\t %u\n",
518 priv->isr_stats.rfkill);
519
520 pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
521 priv->isr_stats.ctkill);
522
523 pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
524 priv->isr_stats.wakeup);
525
526 pos += scnprintf(buf + pos, bufsz - pos,
527 "Rx command responses:\t\t %u\n",
528 priv->isr_stats.rx);
529 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
530 if (priv->isr_stats.rx_handlers[cnt] > 0)
531 pos += scnprintf(buf + pos, bufsz - pos,
532 "\tRx handler[%36s]:\t\t %u\n",
533 get_cmd_string(cnt),
534 priv->isr_stats.rx_handlers[cnt]);
535 }
536
537 pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
538 priv->isr_stats.tx);
539
540 pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
541 priv->isr_stats.unhandled);
542
543 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
544 kfree(buf);
545 return ret;
546}
547
548static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
549 const char __user *user_buf,
550 size_t count, loff_t *ppos)
551{
552 struct iwl_priv *priv = file->private_data;
553 char buf[8];
554 int buf_size;
555 u32 reset_flag;
556
557 memset(buf, 0, sizeof(buf));
558 buf_size = min(count, sizeof(buf) - 1);
559 if (copy_from_user(buf, user_buf, buf_size))
560 return -EFAULT;
561 if (sscanf(buf, "%x", &reset_flag) != 1)
562 return -EFAULT;
563 if (reset_flag == 0)
564 iwl_clear_isr_stats(priv);
565
566 return count;
567}
568
569
478DEBUGFS_READ_WRITE_FILE_OPS(sram); 570DEBUGFS_READ_WRITE_FILE_OPS(sram);
479DEBUGFS_WRITE_FILE_OPS(log_event); 571DEBUGFS_WRITE_FILE_OPS(log_event);
480DEBUGFS_READ_FILE_OPS(eeprom); 572DEBUGFS_READ_FILE_OPS(nvm);
481DEBUGFS_READ_FILE_OPS(stations); 573DEBUGFS_READ_FILE_OPS(stations);
482DEBUGFS_READ_FILE_OPS(rx_statistics); 574DEBUGFS_READ_FILE_OPS(rx_statistics);
483DEBUGFS_READ_FILE_OPS(tx_statistics); 575DEBUGFS_READ_FILE_OPS(tx_statistics);
484DEBUGFS_READ_FILE_OPS(channels); 576DEBUGFS_READ_FILE_OPS(channels);
485DEBUGFS_READ_FILE_OPS(status); 577DEBUGFS_READ_FILE_OPS(status);
578DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
486 579
487/* 580/*
488 * Create the debugfs files and directories 581 * Create the debugfs files and directories
@@ -510,7 +603,7 @@ int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
510 603
511 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv); 604 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
512 DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv); 605 DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
513 DEBUGFS_ADD_FILE(eeprom, data); 606 DEBUGFS_ADD_FILE(nvm, data);
514 DEBUGFS_ADD_FILE(sram, data); 607 DEBUGFS_ADD_FILE(sram, data);
515 DEBUGFS_ADD_FILE(log_event, data); 608 DEBUGFS_ADD_FILE(log_event, data);
516 DEBUGFS_ADD_FILE(stations, data); 609 DEBUGFS_ADD_FILE(stations, data);
@@ -518,6 +611,7 @@ int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
518 DEBUGFS_ADD_FILE(tx_statistics, data); 611 DEBUGFS_ADD_FILE(tx_statistics, data);
519 DEBUGFS_ADD_FILE(channels, data); 612 DEBUGFS_ADD_FILE(channels, data);
520 DEBUGFS_ADD_FILE(status, data); 613 DEBUGFS_ADD_FILE(status, data);
614 DEBUGFS_ADD_FILE(interrupt, data);
521 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal); 615 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
522 DEBUGFS_ADD_BOOL(disable_chain_noise, rf, 616 DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
523 &priv->disable_chain_noise_cal); 617 &priv->disable_chain_noise_cal);
@@ -540,7 +634,7 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv)
540 if (!priv->dbgfs) 634 if (!priv->dbgfs)
541 return; 635 return;
542 636
543 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_eeprom); 637 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
544 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics); 638 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
545 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics); 639 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
546 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram); 640 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
@@ -548,6 +642,7 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv)
548 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations); 642 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
549 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels); 643 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
550 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status); 644 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
645 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
551 DEBUGFS_REMOVE(priv->dbgfs->dir_data); 646 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
552 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity); 647 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
553 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise); 648 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index cf7f0db58fcf..e2d620f0b6e8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -41,7 +41,6 @@
41#include "iwl-prph.h" 41#include "iwl-prph.h"
42#include "iwl-fh.h" 42#include "iwl-fh.h"
43#include "iwl-debug.h" 43#include "iwl-debug.h"
44#include "iwl-rfkill.h"
45#include "iwl-4965-hw.h" 44#include "iwl-4965-hw.h"
46#include "iwl-3945-hw.h" 45#include "iwl-3945-hw.h"
47#include "iwl-3945-led.h" 46#include "iwl-3945-led.h"
@@ -289,11 +288,11 @@ struct iwl_frame {
289#define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4) 288#define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
290 289
291enum { 290enum {
292 /* CMD_SIZE_NORMAL = 0, */ 291 CMD_SYNC = 0,
292 CMD_SIZE_NORMAL = 0,
293 CMD_NO_SKB = 0,
293 CMD_SIZE_HUGE = (1 << 0), 294 CMD_SIZE_HUGE = (1 << 0),
294 /* CMD_SYNC = 0, */
295 CMD_ASYNC = (1 << 1), 295 CMD_ASYNC = (1 << 1),
296 /* CMD_NO_SKB = 0, */
297 CMD_WANT_SKB = (1 << 2), 296 CMD_WANT_SKB = (1 << 2),
298}; 297};
299 298
@@ -381,6 +380,7 @@ struct iwl_rx_queue {
381 u32 read; 380 u32 read;
382 u32 write; 381 u32 write;
383 u32 free_count; 382 u32 free_count;
383 u32 write_actual;
384 struct list_head rx_free; 384 struct list_head rx_free;
385 struct list_head rx_used; 385 struct list_head rx_used;
386 int need_update; 386 int need_update;
@@ -498,22 +498,13 @@ struct iwl_qos_info {
498#define STA_PS_STATUS_WAKE 0 498#define STA_PS_STATUS_WAKE 0
499#define STA_PS_STATUS_SLEEP 1 499#define STA_PS_STATUS_SLEEP 1
500 500
501struct iwl3945_tid_data {
502 u16 seq_number;
503};
504
505struct iwl3945_hw_key {
506 enum ieee80211_key_alg alg;
507 int keylen;
508 u8 key[32];
509};
510 501
511struct iwl3945_station_entry { 502struct iwl3945_station_entry {
512 struct iwl3945_addsta_cmd sta; 503 struct iwl3945_addsta_cmd sta;
513 struct iwl3945_tid_data tid[MAX_TID_COUNT]; 504 struct iwl_tid_data tid[MAX_TID_COUNT];
514 u8 used; 505 u8 used;
515 u8 ps_status; 506 u8 ps_status;
516 struct iwl3945_hw_key keyinfo; 507 struct iwl_hw_key keyinfo;
517}; 508};
518 509
519struct iwl_station_entry { 510struct iwl_station_entry {
@@ -822,6 +813,26 @@ enum {
822 MEASUREMENT_ACTIVE = (1 << 1), 813 MEASUREMENT_ACTIVE = (1 << 1),
823}; 814};
824 815
816enum iwl_nvm_type {
817 NVM_DEVICE_TYPE_EEPROM = 0,
818 NVM_DEVICE_TYPE_OTP,
819};
820
821/* interrupt statistics */
822struct isr_statistics {
823 u32 hw;
824 u32 sw;
825 u32 sw_err;
826 u32 sch;
827 u32 alive;
828 u32 rfkill;
829 u32 ctkill;
830 u32 wakeup;
831 u32 rx;
832 u32 rx_handlers[REPLY_MAX];
833 u32 tx;
834 u32 unhandled;
835};
825 836
826#define IWL_MAX_NUM_QUEUES 20 /* FIXME: do dynamic allocation */ 837#define IWL_MAX_NUM_QUEUES 20 /* FIXME: do dynamic allocation */
827 838
@@ -877,15 +888,14 @@ struct iwl_priv {
877 unsigned long scan_start_tsf; 888 unsigned long scan_start_tsf;
878 void *scan; 889 void *scan;
879 int scan_bands; 890 int scan_bands;
880 int one_direct_scan; 891 struct cfg80211_scan_request *scan_request;
881 u8 direct_ssid_len;
882 u8 direct_ssid[IW_ESSID_MAX_SIZE];
883 u8 scan_tx_ant[IEEE80211_NUM_BANDS]; 892 u8 scan_tx_ant[IEEE80211_NUM_BANDS];
884 u8 mgmt_tx_ant; 893 u8 mgmt_tx_ant;
885 894
886 /* spinlock */ 895 /* spinlock */
887 spinlock_t lock; /* protect general shared data */ 896 spinlock_t lock; /* protect general shared data */
888 spinlock_t hcmd_lock; /* protect hcmd */ 897 spinlock_t hcmd_lock; /* protect hcmd */
898 spinlock_t reg_lock; /* protect hw register access */
889 struct mutex mutex; 899 struct mutex mutex;
890 900
891 /* basic pci-network driver stuff */ 901 /* basic pci-network driver stuff */
@@ -919,16 +929,12 @@ struct iwl_priv {
919 const struct iwl_rxon_cmd active_rxon; 929 const struct iwl_rxon_cmd active_rxon;
920 struct iwl_rxon_cmd staging_rxon; 930 struct iwl_rxon_cmd staging_rxon;
921 931
922 int error_recovering;
923 struct iwl_rxon_cmd recovery_rxon; 932 struct iwl_rxon_cmd recovery_rxon;
924 933
925 /* 1st responses from initialize and runtime uCode images. 934 /* 1st responses from initialize and runtime uCode images.
926 * 4965's initialize alive response contains some calibration data. */ 935 * 4965's initialize alive response contains some calibration data. */
927 struct iwl_init_alive_resp card_alive_init; 936 struct iwl_init_alive_resp card_alive_init;
928 struct iwl_alive_resp card_alive; 937 struct iwl_alive_resp card_alive;
929#if defined(CONFIG_IWLWIFI_RFKILL)
930 struct rfkill *rfkill;
931#endif
932 938
933#ifdef CONFIG_IWLWIFI_LEDS 939#ifdef CONFIG_IWLWIFI_LEDS
934 unsigned long last_blink_time; 940 unsigned long last_blink_time;
@@ -978,6 +984,9 @@ struct iwl_priv {
978 u64 bytes; 984 u64 bytes;
979 } tx_stats[3], rx_stats[3]; 985 } tx_stats[3], rx_stats[3];
980 986
987 /* counts interrupts */
988 struct isr_statistics isr_stats;
989
981 struct iwl_power_mgr power_data; 990 struct iwl_power_mgr power_data;
982 991
983 struct iwl_notif_statistics statistics; 992 struct iwl_notif_statistics statistics;
@@ -1017,6 +1026,7 @@ struct iwl_priv {
1017 1026
1018 /* eeprom */ 1027 /* eeprom */
1019 u8 *eeprom; 1028 u8 *eeprom;
1029 int nvm_device_type;
1020 struct iwl_eeprom_calib_info *calib_info; 1030 struct iwl_eeprom_calib_info *calib_info;
1021 1031
1022 enum nl80211_iftype iw_mode; 1032 enum nl80211_iftype iw_mode;
@@ -1034,7 +1044,16 @@ struct iwl_priv {
1034 /*End*/ 1044 /*End*/
1035 struct iwl_hw_params hw_params; 1045 struct iwl_hw_params hw_params;
1036 1046
1047 /* INT ICT Table */
1048 u32 *ict_tbl;
1049 dma_addr_t ict_tbl_dma;
1050 dma_addr_t aligned_ict_tbl_dma;
1051 int ict_index;
1052 void *ict_tbl_vir;
1053 u32 inta;
1054 bool use_ict;
1037 1055
1056 u32 inta_mask;
1038 /* Current association information needed to configure the 1057 /* Current association information needed to configure the
1039 * hardware */ 1058 * hardware */
1040 u16 assoc_id; 1059 u16 assoc_id;
@@ -1049,7 +1068,6 @@ struct iwl_priv {
1049 struct work_struct calibrated_work; 1068 struct work_struct calibrated_work;
1050 struct work_struct scan_completed; 1069 struct work_struct scan_completed;
1051 struct work_struct rx_replenish; 1070 struct work_struct rx_replenish;
1052 struct work_struct rf_kill;
1053 struct work_struct abort_scan; 1071 struct work_struct abort_scan;
1054 struct work_struct update_link_led; 1072 struct work_struct update_link_led;
1055 struct work_struct auth_work; 1073 struct work_struct auth_work;
@@ -1059,7 +1077,6 @@ struct iwl_priv {
1059 1077
1060 struct tasklet_struct irq_tasklet; 1078 struct tasklet_struct irq_tasklet;
1061 1079
1062 struct delayed_work set_power_save;
1063 struct delayed_work init_alive_start; 1080 struct delayed_work init_alive_start;
1064 struct delayed_work alive_start; 1081 struct delayed_work alive_start;
1065 struct delayed_work scan_check; 1082 struct delayed_work scan_check;
@@ -1090,14 +1107,12 @@ struct iwl_priv {
1090 u32 disable_tx_power_cal; 1107 u32 disable_tx_power_cal;
1091 struct work_struct run_time_calib_work; 1108 struct work_struct run_time_calib_work;
1092 struct timer_list statistics_periodic; 1109 struct timer_list statistics_periodic;
1093 1110 bool hw_ready;
1094 /*For 3945*/ 1111 /*For 3945*/
1095#define IWL_DEFAULT_TX_POWER 0x0F 1112#define IWL_DEFAULT_TX_POWER 0x0F
1096 1113
1097 struct iwl3945_notif_statistics statistics_39; 1114 struct iwl3945_notif_statistics statistics_39;
1098 1115
1099 struct iwl3945_station_entry stations_39[IWL_STATION_COUNT];
1100
1101 u32 sta_supp_rates; 1116 u32 sta_supp_rates;
1102}; /*iwl_priv */ 1117}; /*iwl_priv */
1103 1118
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.c b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
index 75517d05df08..7d7554a2f341 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.c
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
@@ -152,6 +152,32 @@ int iwlcore_eeprom_verify_signature(struct iwl_priv *priv)
152} 152}
153EXPORT_SYMBOL(iwlcore_eeprom_verify_signature); 153EXPORT_SYMBOL(iwlcore_eeprom_verify_signature);
154 154
155static int iwlcore_get_nvm_type(struct iwl_priv *priv)
156{
157 u32 otpgp;
158 int nvm_type;
159
160 /* OTP only valid for CP/PP and after */
161 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
162 case CSR_HW_REV_TYPE_3945:
163 case CSR_HW_REV_TYPE_4965:
164 case CSR_HW_REV_TYPE_5300:
165 case CSR_HW_REV_TYPE_5350:
166 case CSR_HW_REV_TYPE_5100:
167 case CSR_HW_REV_TYPE_5150:
168 nvm_type = NVM_DEVICE_TYPE_EEPROM;
169 break;
170 default:
171 otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
172 if (otpgp & CSR_OTP_GP_REG_DEVICE_SELECT)
173 nvm_type = NVM_DEVICE_TYPE_OTP;
174 else
175 nvm_type = NVM_DEVICE_TYPE_EEPROM;
176 break;
177 }
178 return nvm_type;
179}
180
155/* 181/*
156 * The device's EEPROM semaphore prevents conflicts between driver and uCode 182 * The device's EEPROM semaphore prevents conflicts between driver and uCode
157 * when accessing the EEPROM; each access is a series of pulses to/from the 183 * when accessing the EEPROM; each access is a series of pulses to/from the
@@ -198,6 +224,31 @@ const u8 *iwlcore_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
198} 224}
199EXPORT_SYMBOL(iwlcore_eeprom_query_addr); 225EXPORT_SYMBOL(iwlcore_eeprom_query_addr);
200 226
227static int iwl_init_otp_access(struct iwl_priv *priv)
228{
229 int ret;
230
231 /* Enable 40MHz radio clock */
232 _iwl_write32(priv, CSR_GP_CNTRL,
233 _iwl_read32(priv, CSR_GP_CNTRL) |
234 CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
235
236 /* wait for clock to be ready */
237 ret = iwl_poll_direct_bit(priv, CSR_GP_CNTRL,
238 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
239 25000);
240 if (ret < 0)
241 IWL_ERR(priv, "Time out access OTP\n");
242 else {
243 iwl_set_bits_prph(priv, APMG_PS_CTRL_REG,
244 APMG_PS_CTRL_VAL_RESET_REQ);
245 udelay(5);
246 iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG,
247 APMG_PS_CTRL_VAL_RESET_REQ);
248 }
249 return ret;
250}
251
201/** 252/**
202 * iwl_eeprom_init - read EEPROM contents 253 * iwl_eeprom_init - read EEPROM contents
203 * 254 *
@@ -209,11 +260,18 @@ int iwl_eeprom_init(struct iwl_priv *priv)
209{ 260{
210 u16 *e; 261 u16 *e;
211 u32 gp = iwl_read32(priv, CSR_EEPROM_GP); 262 u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
212 int sz = priv->cfg->eeprom_size; 263 int sz;
213 int ret; 264 int ret;
214 u16 addr; 265 u16 addr;
266 u32 otpgp;
267
268 priv->nvm_device_type = iwlcore_get_nvm_type(priv);
215 269
216 /* allocate eeprom */ 270 /* allocate eeprom */
271 if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
272 priv->cfg->eeprom_size =
273 OTP_BLOCK_SIZE * OTP_LOWER_BLOCKS_TOTAL;
274 sz = priv->cfg->eeprom_size;
217 priv->eeprom = kzalloc(sz, GFP_KERNEL); 275 priv->eeprom = kzalloc(sz, GFP_KERNEL);
218 if (!priv->eeprom) { 276 if (!priv->eeprom) {
219 ret = -ENOMEM; 277 ret = -ENOMEM;
@@ -235,30 +293,77 @@ int iwl_eeprom_init(struct iwl_priv *priv)
235 ret = -ENOENT; 293 ret = -ENOENT;
236 goto err; 294 goto err;
237 } 295 }
238 296 if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) {
239 /* eeprom is an array of 16bit values */ 297 ret = iwl_init_otp_access(priv);
240 for (addr = 0; addr < sz; addr += sizeof(u16)) { 298 if (ret) {
241 u32 r; 299 IWL_ERR(priv, "Failed to initialize OTP access.\n");
242 300 ret = -ENOENT;
243 _iwl_write32(priv, CSR_EEPROM_REG, 301 goto err;
244 CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); 302 }
245 303 _iwl_write32(priv, CSR_EEPROM_GP,
246 ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG, 304 iwl_read32(priv, CSR_EEPROM_GP) &
247 CSR_EEPROM_REG_READ_VALID_MSK, 305 ~CSR_EEPROM_GP_IF_OWNER_MSK);
248 IWL_EEPROM_ACCESS_TIMEOUT); 306 /* clear */
249 if (ret < 0) { 307 _iwl_write32(priv, CSR_OTP_GP_REG,
250 IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr); 308 iwl_read32(priv, CSR_OTP_GP_REG) |
251 goto done; 309 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
310 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
311
312 for (addr = 0; addr < sz; addr += sizeof(u16)) {
313 u32 r;
314
315 _iwl_write32(priv, CSR_EEPROM_REG,
316 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
317
318 ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG,
319 CSR_EEPROM_REG_READ_VALID_MSK,
320 IWL_EEPROM_ACCESS_TIMEOUT);
321 if (ret < 0) {
322 IWL_ERR(priv, "Time out reading OTP[%d]\n", addr);
323 goto done;
324 }
325 r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
326 /* check for ECC errors: */
327 otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
328 if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
329 /* stop in this case */
330 IWL_ERR(priv, "Uncorrectable OTP ECC error, Abort OTP read\n");
331 goto done;
332 }
333 if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
334 /* continue in this case */
335 _iwl_write32(priv, CSR_OTP_GP_REG,
336 iwl_read32(priv, CSR_OTP_GP_REG) |
337 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
338 IWL_ERR(priv, "Correctable OTP ECC error, continue read\n");
339 }
340 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
341 }
342 } else {
343 /* eeprom is an array of 16bit values */
344 for (addr = 0; addr < sz; addr += sizeof(u16)) {
345 u32 r;
346
347 _iwl_write32(priv, CSR_EEPROM_REG,
348 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
349
350 ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG,
351 CSR_EEPROM_REG_READ_VALID_MSK,
352 IWL_EEPROM_ACCESS_TIMEOUT);
353 if (ret < 0) {
354 IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr);
355 goto done;
356 }
357 r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
358 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
252 } 359 }
253 r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
254 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
255 } 360 }
256 ret = 0; 361 ret = 0;
257done: 362done:
258 priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv); 363 priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv);
259err: 364err:
260 if (ret) 365 if (ret)
261 kfree(priv->eeprom); 366 iwl_eeprom_free(priv);
262alloc_err: 367alloc_err:
263 return ret; 368 return ret;
264} 369}
@@ -285,7 +390,7 @@ int iwl_eeprom_check_version(struct iwl_priv *priv)
285 390
286 return 0; 391 return 0;
287err: 392err:
288 IWL_ERR(priv, "Unsupported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n", 393 IWL_ERR(priv, "Unsupported (too old) EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
289 eeprom_ver, priv->cfg->eeprom_ver, 394 eeprom_ver, priv->cfg->eeprom_ver,
290 calib_ver, priv->cfg->eeprom_calib_ver); 395 calib_ver, priv->cfg->eeprom_calib_ver);
291 return -EINVAL; 396 return -EINVAL;
@@ -301,6 +406,8 @@ EXPORT_SYMBOL(iwl_eeprom_query_addr);
301 406
302u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset) 407u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset)
303{ 408{
409 if (!priv->eeprom)
410 return 0;
304 return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8); 411 return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
305} 412}
306EXPORT_SYMBOL(iwl_eeprom_query16); 413EXPORT_SYMBOL(iwl_eeprom_query16);
@@ -481,8 +588,8 @@ int iwl_init_channel_map(struct iwl_priv *priv)
481 /* First write that fat is not enabled, and then enable 588 /* First write that fat is not enabled, and then enable
482 * one by one */ 589 * one by one */
483 ch_info->fat_extension_channel = 590 ch_info->fat_extension_channel =
484 (IEEE80211_CHAN_NO_FAT_ABOVE | 591 (IEEE80211_CHAN_NO_HT40PLUS |
485 IEEE80211_CHAN_NO_FAT_BELOW); 592 IEEE80211_CHAN_NO_HT40MINUS);
486 593
487 if (!(is_channel_valid(ch_info))) { 594 if (!(is_channel_valid(ch_info))) {
488 IWL_DEBUG_INFO(priv, "Ch. %d Flags %x [%sGHz] - " 595 IWL_DEBUG_INFO(priv, "Ch. %d Flags %x [%sGHz] - "
@@ -561,7 +668,7 @@ int iwl_init_channel_map(struct iwl_priv *priv)
561 fat_extension_chan = 0; 668 fat_extension_chan = 0;
562 else 669 else
563 fat_extension_chan = 670 fat_extension_chan =
564 IEEE80211_CHAN_NO_FAT_BELOW; 671 IEEE80211_CHAN_NO_HT40MINUS;
565 672
566 /* Set up driver's info for lower half */ 673 /* Set up driver's info for lower half */
567 iwl_set_fat_chan_info(priv, ieeeband, 674 iwl_set_fat_chan_info(priv, ieeeband,
@@ -573,7 +680,7 @@ int iwl_init_channel_map(struct iwl_priv *priv)
573 iwl_set_fat_chan_info(priv, ieeeband, 680 iwl_set_fat_chan_info(priv, ieeeband,
574 (eeprom_ch_index[ch] + 4), 681 (eeprom_ch_index[ch] + 4),
575 &(eeprom_ch_info[ch]), 682 &(eeprom_ch_info[ch]),
576 IEEE80211_CHAN_NO_FAT_ABOVE); 683 IEEE80211_CHAN_NO_HT40PLUS);
577 } 684 }
578 } 685 }
579 686
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.h b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
index 3479153d96ca..195b4ef12c27 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.h
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
@@ -179,6 +179,10 @@ struct iwl_eeprom_channel {
179#define EEPROM_5050_TX_POWER_VERSION (4) 179#define EEPROM_5050_TX_POWER_VERSION (4)
180#define EEPROM_5050_EEPROM_VERSION (0x21E) 180#define EEPROM_5050_EEPROM_VERSION (0x21E)
181 181
182/* OTP */
183#define OTP_LOWER_BLOCKS_TOTAL (3)
184#define OTP_BLOCK_SIZE (0x400)
185
182/* 2.4 GHz */ 186/* 2.4 GHz */
183extern const u8 iwl_eeprom_band_1[14]; 187extern const u8 iwl_eeprom_band_1[14];
184 188
diff --git a/drivers/net/wireless/iwlwifi/iwl-io.h b/drivers/net/wireless/iwlwifi/iwl-io.h
index 083ea1ffbe87..d30cb0275d19 100644
--- a/drivers/net/wireless/iwlwifi/iwl-io.h
+++ b/drivers/net/wireless/iwlwifi/iwl-io.h
@@ -131,9 +131,23 @@ static inline void __iwl_set_bit(const char *f, u32 l,
131 IWL_DEBUG_IO(priv, "set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); 131 IWL_DEBUG_IO(priv, "set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
132 _iwl_write32(priv, reg, val); 132 _iwl_write32(priv, reg, val);
133} 133}
134#define iwl_set_bit(p, r, m) __iwl_set_bit(__FILE__, __LINE__, p, r, m) 134static inline void iwl_set_bit(struct iwl_priv *p, u32 r, u32 m)
135{
136 unsigned long reg_flags;
137
138 spin_lock_irqsave(&p->reg_lock, reg_flags);
139 __iwl_set_bit(__FILE__, __LINE__, p, r, m);
140 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
141}
135#else 142#else
136#define iwl_set_bit(p, r, m) _iwl_set_bit(p, r, m) 143static inline void iwl_set_bit(struct iwl_priv *p, u32 r, u32 m)
144{
145 unsigned long reg_flags;
146
147 spin_lock_irqsave(&p->reg_lock, reg_flags);
148 _iwl_set_bit(p, r, m);
149 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
150}
137#endif 151#endif
138 152
139static inline void _iwl_clear_bit(struct iwl_priv *priv, u32 reg, u32 mask) 153static inline void _iwl_clear_bit(struct iwl_priv *priv, u32 reg, u32 mask)
@@ -148,19 +162,30 @@ static inline void __iwl_clear_bit(const char *f, u32 l,
148 IWL_DEBUG_IO(priv, "clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); 162 IWL_DEBUG_IO(priv, "clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
149 _iwl_write32(priv, reg, val); 163 _iwl_write32(priv, reg, val);
150} 164}
151#define iwl_clear_bit(p, r, m) __iwl_clear_bit(__FILE__, __LINE__, p, r, m) 165static inline void iwl_clear_bit(struct iwl_priv *p, u32 r, u32 m)
166{
167 unsigned long reg_flags;
168
169 spin_lock_irqsave(&p->reg_lock, reg_flags);
170 __iwl_clear_bit(__FILE__, __LINE__, p, r, m);
171 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
172}
152#else 173#else
153#define iwl_clear_bit(p, r, m) _iwl_clear_bit(p, r, m) 174static inline void iwl_clear_bit(struct iwl_priv *p, u32 r, u32 m)
175{
176 unsigned long reg_flags;
177
178 spin_lock_irqsave(&p->reg_lock, reg_flags);
179 _iwl_clear_bit(p, r, m);
180 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
181}
154#endif 182#endif
155 183
156static inline int _iwl_grab_nic_access(struct iwl_priv *priv) 184static inline int _iwl_grab_nic_access(struct iwl_priv *priv)
157{ 185{
158 int ret; 186 int ret;
159 u32 val; 187 u32 val;
160#ifdef CONFIG_IWLWIFI_DEBUG 188
161 if (atomic_read(&priv->restrict_refcnt))
162 return 0;
163#endif
164 /* this bit wakes up the NIC */ 189 /* this bit wakes up the NIC */
165 _iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); 190 _iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
166 ret = _iwl_poll_bit(priv, CSR_GP_CNTRL, 191 ret = _iwl_poll_bit(priv, CSR_GP_CNTRL,
@@ -170,12 +195,10 @@ static inline int _iwl_grab_nic_access(struct iwl_priv *priv)
170 if (ret < 0) { 195 if (ret < 0) {
171 val = _iwl_read32(priv, CSR_GP_CNTRL); 196 val = _iwl_read32(priv, CSR_GP_CNTRL);
172 IWL_ERR(priv, "MAC is in deep sleep!. CSR_GP_CNTRL = 0x%08X\n", val); 197 IWL_ERR(priv, "MAC is in deep sleep!. CSR_GP_CNTRL = 0x%08X\n", val);
198 _iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_FORCE_NMI);
173 return -EIO; 199 return -EIO;
174 } 200 }
175 201
176#ifdef CONFIG_IWLWIFI_DEBUG
177 atomic_inc(&priv->restrict_refcnt);
178#endif
179 return 0; 202 return 0;
180} 203}
181 204
@@ -183,9 +206,6 @@ static inline int _iwl_grab_nic_access(struct iwl_priv *priv)
183static inline int __iwl_grab_nic_access(const char *f, u32 l, 206static inline int __iwl_grab_nic_access(const char *f, u32 l,
184 struct iwl_priv *priv) 207 struct iwl_priv *priv)
185{ 208{
186 if (atomic_read(&priv->restrict_refcnt))
187 IWL_ERR(priv, "Grabbing access while already held %s %d.\n", f, l);
188
189 IWL_DEBUG_IO(priv, "grabbing nic access - %s %d\n", f, l); 209 IWL_DEBUG_IO(priv, "grabbing nic access - %s %d\n", f, l);
190 return _iwl_grab_nic_access(priv); 210 return _iwl_grab_nic_access(priv);
191} 211}
@@ -198,18 +218,13 @@ static inline int __iwl_grab_nic_access(const char *f, u32 l,
198 218
199static inline void _iwl_release_nic_access(struct iwl_priv *priv) 219static inline void _iwl_release_nic_access(struct iwl_priv *priv)
200{ 220{
201#ifdef CONFIG_IWLWIFI_DEBUG 221 _iwl_clear_bit(priv, CSR_GP_CNTRL,
202 if (atomic_dec_and_test(&priv->restrict_refcnt)) 222 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
203#endif
204 _iwl_clear_bit(priv, CSR_GP_CNTRL,
205 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
206} 223}
207#ifdef CONFIG_IWLWIFI_DEBUG 224#ifdef CONFIG_IWLWIFI_DEBUG
208static inline void __iwl_release_nic_access(const char *f, u32 l, 225static inline void __iwl_release_nic_access(const char *f, u32 l,
209 struct iwl_priv *priv) 226 struct iwl_priv *priv)
210{ 227{
211 if (atomic_read(&priv->restrict_refcnt) <= 0)
212 IWL_ERR(priv, "Release unheld nic access at line %s %d.\n", f, l);
213 228
214 IWL_DEBUG_IO(priv, "releasing nic access - %s %d\n", f, l); 229 IWL_DEBUG_IO(priv, "releasing nic access - %s %d\n", f, l);
215 _iwl_release_nic_access(priv); 230 _iwl_release_nic_access(priv);
@@ -230,16 +245,37 @@ static inline u32 __iwl_read_direct32(const char *f, u32 l,
230 struct iwl_priv *priv, u32 reg) 245 struct iwl_priv *priv, u32 reg)
231{ 246{
232 u32 value = _iwl_read_direct32(priv, reg); 247 u32 value = _iwl_read_direct32(priv, reg);
233 if (!atomic_read(&priv->restrict_refcnt))
234 IWL_ERR(priv, "Nic access not held from %s %d\n", f, l);
235 IWL_DEBUG_IO(priv, "read_direct32(0x%4X) = 0x%08x - %s %d \n", reg, value, 248 IWL_DEBUG_IO(priv, "read_direct32(0x%4X) = 0x%08x - %s %d \n", reg, value,
236 f, l); 249 f, l);
237 return value; 250 return value;
238} 251}
239#define iwl_read_direct32(priv, reg) \ 252static inline u32 iwl_read_direct32(struct iwl_priv *priv, u32 reg)
240 __iwl_read_direct32(__FILE__, __LINE__, priv, reg) 253{
254 u32 value;
255 unsigned long reg_flags;
256
257 spin_lock_irqsave(&priv->reg_lock, reg_flags);
258 iwl_grab_nic_access(priv);
259 value = __iwl_read_direct32(__FILE__, __LINE__, priv, reg);
260 iwl_release_nic_access(priv);
261 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
262 return value;
263}
264
241#else 265#else
242#define iwl_read_direct32 _iwl_read_direct32 266static inline u32 iwl_read_direct32(struct iwl_priv *priv, u32 reg)
267{
268 u32 value;
269 unsigned long reg_flags;
270
271 spin_lock_irqsave(&priv->reg_lock, reg_flags);
272 iwl_grab_nic_access(priv);
273 value = _iwl_read_direct32(priv, reg);
274 iwl_release_nic_access(priv);
275 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
276 return value;
277
278}
243#endif 279#endif
244 280
245static inline void _iwl_write_direct32(struct iwl_priv *priv, 281static inline void _iwl_write_direct32(struct iwl_priv *priv,
@@ -247,19 +283,17 @@ static inline void _iwl_write_direct32(struct iwl_priv *priv,
247{ 283{
248 _iwl_write32(priv, reg, value); 284 _iwl_write32(priv, reg, value);
249} 285}
250#ifdef CONFIG_IWLWIFI_DEBUG 286static inline void iwl_write_direct32(struct iwl_priv *priv, u32 reg, u32 value)
251static void __iwl_write_direct32(const char *f , u32 line,
252 struct iwl_priv *priv, u32 reg, u32 value)
253{ 287{
254 if (!atomic_read(&priv->restrict_refcnt)) 288 unsigned long reg_flags;
255 IWL_ERR(priv, "Nic access not held from %s line %d\n", f, line); 289
256 _iwl_write_direct32(priv, reg, value); 290 spin_lock_irqsave(&priv->reg_lock, reg_flags);
291 if (!iwl_grab_nic_access(priv)) {
292 _iwl_write_direct32(priv, reg, value);
293 iwl_release_nic_access(priv);
294 }
295 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
257} 296}
258#define iwl_write_direct32(priv, reg, value) \
259 __iwl_write_direct32(__func__, __LINE__, priv, reg, value)
260#else
261#define iwl_write_direct32 _iwl_write_direct32
262#endif
263 297
264static inline void iwl_write_reg_buf(struct iwl_priv *priv, 298static inline void iwl_write_reg_buf(struct iwl_priv *priv,
265 u32 reg, u32 len, u32 *values) 299 u32 reg, u32 len, u32 *values)
@@ -268,14 +302,23 @@ static inline void iwl_write_reg_buf(struct iwl_priv *priv,
268 302
269 if ((priv != NULL) && (values != NULL)) { 303 if ((priv != NULL) && (values != NULL)) {
270 for (; 0 < len; len -= count, reg += count, values++) 304 for (; 0 < len; len -= count, reg += count, values++)
271 _iwl_write_direct32(priv, reg, *values); 305 iwl_write_direct32(priv, reg, *values);
272 } 306 }
273} 307}
274 308
275static inline int _iwl_poll_direct_bit(struct iwl_priv *priv, u32 addr, 309static inline int _iwl_poll_direct_bit(struct iwl_priv *priv, u32 addr,
276 u32 mask, int timeout) 310 u32 mask, int timeout)
277{ 311{
278 return _iwl_poll_bit(priv, addr, mask, mask, timeout); 312 int t = 0;
313
314 do {
315 if ((iwl_read_direct32(priv, addr) & mask) == mask)
316 return t;
317 udelay(IWL_POLL_INTERVAL);
318 t += IWL_POLL_INTERVAL;
319 } while (t < timeout);
320
321 return -ETIMEDOUT;
279} 322}
280 323
281#ifdef CONFIG_IWLWIFI_DEBUG 324#ifdef CONFIG_IWLWIFI_DEBUG
@@ -305,20 +348,18 @@ static inline u32 _iwl_read_prph(struct iwl_priv *priv, u32 reg)
305 rmb(); 348 rmb();
306 return _iwl_read_direct32(priv, HBUS_TARG_PRPH_RDAT); 349 return _iwl_read_direct32(priv, HBUS_TARG_PRPH_RDAT);
307} 350}
308#ifdef CONFIG_IWLWIFI_DEBUG 351static inline u32 iwl_read_prph(struct iwl_priv *priv, u32 reg)
309static inline u32 __iwl_read_prph(const char *f, u32 line,
310 struct iwl_priv *priv, u32 reg)
311{ 352{
312 if (!atomic_read(&priv->restrict_refcnt)) 353 unsigned long reg_flags;
313 IWL_ERR(priv, "Nic access not held from %s line %d\n", f, line); 354 u32 val;
314 return _iwl_read_prph(priv, reg);
315}
316 355
317#define iwl_read_prph(priv, reg) \ 356 spin_lock_irqsave(&priv->reg_lock, reg_flags);
318 __iwl_read_prph(__func__, __LINE__, priv, reg) 357 iwl_grab_nic_access(priv);
319#else 358 val = _iwl_read_prph(priv, reg);
320#define iwl_read_prph _iwl_read_prph 359 iwl_release_nic_access(priv);
321#endif 360 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
361 return val;
362}
322 363
323static inline void _iwl_write_prph(struct iwl_priv *priv, 364static inline void _iwl_write_prph(struct iwl_priv *priv,
324 u32 addr, u32 val) 365 u32 addr, u32 val)
@@ -328,83 +369,107 @@ static inline void _iwl_write_prph(struct iwl_priv *priv,
328 wmb(); 369 wmb();
329 _iwl_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val); 370 _iwl_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val);
330} 371}
331#ifdef CONFIG_IWLWIFI_DEBUG 372
332static inline void __iwl_write_prph(const char *f, u32 line, 373static inline void iwl_write_prph(struct iwl_priv *priv, u32 addr, u32 val)
333 struct iwl_priv *priv, u32 addr, u32 val)
334{ 374{
335 if (!atomic_read(&priv->restrict_refcnt)) 375 unsigned long reg_flags;
336 IWL_ERR(priv, "Nic access not held from %s line %d\n", f, line);
337 _iwl_write_prph(priv, addr, val);
338}
339 376
340#define iwl_write_prph(priv, addr, val) \ 377 spin_lock_irqsave(&priv->reg_lock, reg_flags);
341 __iwl_write_prph(__func__, __LINE__, priv, addr, val); 378 if (!iwl_grab_nic_access(priv)) {
342#else 379 _iwl_write_prph(priv, addr, val);
343#define iwl_write_prph _iwl_write_prph 380 iwl_release_nic_access(priv);
344#endif 381 }
382 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
383}
345 384
346#define _iwl_set_bits_prph(priv, reg, mask) \ 385#define _iwl_set_bits_prph(priv, reg, mask) \
347 _iwl_write_prph(priv, reg, (_iwl_read_prph(priv, reg) | mask)) 386 _iwl_write_prph(priv, reg, (_iwl_read_prph(priv, reg) | mask))
348#ifdef CONFIG_IWLWIFI_DEBUG 387
349static inline void __iwl_set_bits_prph(const char *f, u32 line, 388static inline void iwl_set_bits_prph(struct iwl_priv *priv, u32 reg, u32 mask)
350 struct iwl_priv *priv,
351 u32 reg, u32 mask)
352{ 389{
353 if (!atomic_read(&priv->restrict_refcnt)) 390 unsigned long reg_flags;
354 IWL_ERR(priv, "Nic access not held from %s line %d\n", f, line);
355 391
392 spin_lock_irqsave(&priv->reg_lock, reg_flags);
393 iwl_grab_nic_access(priv);
356 _iwl_set_bits_prph(priv, reg, mask); 394 _iwl_set_bits_prph(priv, reg, mask);
395 iwl_release_nic_access(priv);
396 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
357} 397}
358#define iwl_set_bits_prph(priv, reg, mask) \
359 __iwl_set_bits_prph(__func__, __LINE__, priv, reg, mask)
360#else
361#define iwl_set_bits_prph _iwl_set_bits_prph
362#endif
363 398
364#define _iwl_set_bits_mask_prph(priv, reg, bits, mask) \ 399#define _iwl_set_bits_mask_prph(priv, reg, bits, mask) \
365 _iwl_write_prph(priv, reg, ((_iwl_read_prph(priv, reg) & mask) | bits)) 400 _iwl_write_prph(priv, reg, ((_iwl_read_prph(priv, reg) & mask) | bits))
366 401
367#ifdef CONFIG_IWLWIFI_DEBUG 402static inline void iwl_set_bits_mask_prph(struct iwl_priv *priv, u32 reg,
368static inline void __iwl_set_bits_mask_prph(const char *f, u32 line, 403 u32 bits, u32 mask)
369 struct iwl_priv *priv, u32 reg, u32 bits, u32 mask)
370{ 404{
371 if (!atomic_read(&priv->restrict_refcnt)) 405 unsigned long reg_flags;
372 IWL_ERR(priv, "Nic access not held from %s line %d\n", f, line); 406
407 spin_lock_irqsave(&priv->reg_lock, reg_flags);
408 iwl_grab_nic_access(priv);
373 _iwl_set_bits_mask_prph(priv, reg, bits, mask); 409 _iwl_set_bits_mask_prph(priv, reg, bits, mask);
410 iwl_release_nic_access(priv);
411 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
374} 412}
375#define iwl_set_bits_mask_prph(priv, reg, bits, mask) \
376 __iwl_set_bits_mask_prph(__func__, __LINE__, priv, reg, bits, mask)
377#else
378#define iwl_set_bits_mask_prph _iwl_set_bits_mask_prph
379#endif
380 413
381static inline void iwl_clear_bits_prph(struct iwl_priv 414static inline void iwl_clear_bits_prph(struct iwl_priv
382 *priv, u32 reg, u32 mask) 415 *priv, u32 reg, u32 mask)
383{ 416{
384 u32 val = _iwl_read_prph(priv, reg); 417 unsigned long reg_flags;
418 u32 val;
419
420 spin_lock_irqsave(&priv->reg_lock, reg_flags);
421 iwl_grab_nic_access(priv);
422 val = _iwl_read_prph(priv, reg);
385 _iwl_write_prph(priv, reg, (val & ~mask)); 423 _iwl_write_prph(priv, reg, (val & ~mask));
424 iwl_release_nic_access(priv);
425 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
386} 426}
387 427
388static inline u32 iwl_read_targ_mem(struct iwl_priv *priv, u32 addr) 428static inline u32 iwl_read_targ_mem(struct iwl_priv *priv, u32 addr)
389{ 429{
390 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr); 430 unsigned long reg_flags;
431 u32 value;
432
433 spin_lock_irqsave(&priv->reg_lock, reg_flags);
434 iwl_grab_nic_access(priv);
435
436 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr);
391 rmb(); 437 rmb();
392 return iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); 438 value = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
439
440 iwl_release_nic_access(priv);
441 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
442 return value;
393} 443}
394 444
395static inline void iwl_write_targ_mem(struct iwl_priv *priv, u32 addr, u32 val) 445static inline void iwl_write_targ_mem(struct iwl_priv *priv, u32 addr, u32 val)
396{ 446{
397 iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr); 447 unsigned long reg_flags;
398 wmb(); 448
399 iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, val); 449 spin_lock_irqsave(&priv->reg_lock, reg_flags);
450 if (!iwl_grab_nic_access(priv)) {
451 _iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
452 wmb();
453 _iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, val);
454 iwl_release_nic_access(priv);
455 }
456 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
400} 457}
401 458
402static inline void iwl_write_targ_mem_buf(struct iwl_priv *priv, u32 addr, 459static inline void iwl_write_targ_mem_buf(struct iwl_priv *priv, u32 addr,
403 u32 len, u32 *values) 460 u32 len, u32 *values)
404{ 461{
405 iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr); 462 unsigned long reg_flags;
406 wmb(); 463
407 for (; 0 < len; len -= sizeof(u32), values++) 464 spin_lock_irqsave(&priv->reg_lock, reg_flags);
408 iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values); 465 if (!iwl_grab_nic_access(priv)) {
466 _iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
467 wmb();
468 for (; 0 < len; len -= sizeof(u32), values++)
469 _iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values);
470
471 iwl_release_nic_access(priv);
472 }
473 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
409} 474}
410#endif 475#endif
diff --git a/drivers/net/wireless/iwlwifi/iwl-led.c b/drivers/net/wireless/iwlwifi/iwl-led.c
index 19680f72087f..5e64252f80f6 100644
--- a/drivers/net/wireless/iwlwifi/iwl-led.c
+++ b/drivers/net/wireless/iwlwifi/iwl-led.c
@@ -176,10 +176,6 @@ static int iwl_led_associate(struct iwl_priv *priv, int led_id)
176static int iwl_led_disassociate(struct iwl_priv *priv, int led_id) 176static int iwl_led_disassociate(struct iwl_priv *priv, int led_id)
177{ 177{
178 priv->allow_blinking = 0; 178 priv->allow_blinking = 0;
179 if (iwl_is_rfkill(priv))
180 iwl4965_led_off_reg(priv, led_id);
181 else
182 iwl4965_led_on_reg(priv, led_id);
183 179
184 return 0; 180 return 0;
185} 181}
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.c b/drivers/net/wireless/iwlwifi/iwl-power.c
index 47c894530eb5..f2ea3f05f6e1 100644
--- a/drivers/net/wireless/iwlwifi/iwl-power.c
+++ b/drivers/net/wireless/iwlwifi/iwl-power.c
@@ -41,38 +41,33 @@
41#include "iwl-power.h" 41#include "iwl-power.h"
42 42
43/* 43/*
44 * Setting power level allow the card to go to sleep when not busy 44 * Setting power level allow the card to go to sleep when not busy.
45 * there are three factor that decide the power level to go to, they
46 * are list here with its priority
47 * 1- critical_power_setting this will be set according to card temperature.
48 * 2- system_power_setting this will be set by system PM manager.
49 * 3- user_power_setting this will be set by user either by writing to sys or
50 * mac80211
51 * 45 *
52 * if system_power_setting and user_power_setting is set to auto 46 * The power level is set to INDEX_1 (the least deep state) by
53 * the power level will be decided according to association status and battery 47 * default, and will, in the future, be the deepest state unless
54 * status. 48 * otherwise required by pm_qos network latency requirements.
55 * 49 *
50 * Using INDEX_1 without pm_qos is ok because mac80211 will disable
51 * PS when even checking every beacon for the TIM bit would exceed
52 * the required latency.
56 */ 53 */
57 54
58#define MSEC_TO_USEC 1024
59#define IWL_POWER_RANGE_0_MAX (2) 55#define IWL_POWER_RANGE_0_MAX (2)
60#define IWL_POWER_RANGE_1_MAX (10) 56#define IWL_POWER_RANGE_1_MAX (10)
61 57
62 58
63 59#define NOSLP cpu_to_le16(0), 0, 0
64#define IWL_POWER_ON_BATTERY IWL_POWER_INDEX_5 60#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
65#define IWL_POWER_ON_AC_DISASSOC IWL_POWER_MODE_CAM 61#define TU_TO_USEC 1024
66#define IWL_POWER_ON_AC_ASSOC IWL_POWER_MODE_CAM 62#define SLP_TOUT(T) cpu_to_le32((T) * TU_TO_USEC)
67 63#define SLP_VEC(X0, X1, X2, X3, X4) {cpu_to_le32(X0), \
68 64 cpu_to_le32(X1), \
69#define IWL_CT_KILL_TEMPERATURE 110 65 cpu_to_le32(X2), \
70#define IWL_MIN_POWER_TEMPERATURE 100 66 cpu_to_le32(X3), \
71#define IWL_REDUCED_POWER_TEMPERATURE 95 67 cpu_to_le32(X4)}
72
73/* default power management (not Tx power) table values */ 68/* default power management (not Tx power) table values */
74/* for TIM 0-10 */ 69/* for DTIM period 0 through IWL_POWER_RANGE_0_MAX */
75static struct iwl_power_vec_entry range_0[IWL_POWER_MAX] = { 70static const struct iwl_power_vec_entry range_0[IWL_POWER_NUM] = {
76 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, 71 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
77 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0}, 72 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0},
78 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0}, 73 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0},
@@ -82,8 +77,8 @@ static struct iwl_power_vec_entry range_0[IWL_POWER_MAX] = {
82}; 77};
83 78
84 79
85/* for TIM = 3-10 */ 80/* for DTIM period IWL_POWER_RANGE_0_MAX + 1 through IWL_POWER_RANGE_1_MAX */
86static struct iwl_power_vec_entry range_1[IWL_POWER_MAX] = { 81static const struct iwl_power_vec_entry range_1[IWL_POWER_NUM] = {
87 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, 82 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
88 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, 83 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
89 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0}, 84 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0},
@@ -92,8 +87,8 @@ static struct iwl_power_vec_entry range_1[IWL_POWER_MAX] = {
92 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 4, 7, 10, 10)}, 2} 87 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 4, 7, 10, 10)}, 2}
93}; 88};
94 89
95/* for TIM > 11 */ 90/* for DTIM period > IWL_POWER_RANGE_1_MAX */
96static struct iwl_power_vec_entry range_2[IWL_POWER_MAX] = { 91static const struct iwl_power_vec_entry range_2[IWL_POWER_NUM] = {
97 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, 92 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
98 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, 93 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
99 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, 94 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
@@ -106,39 +101,15 @@ static struct iwl_power_vec_entry range_2[IWL_POWER_MAX] = {
106/* set card power command */ 101/* set card power command */
107static int iwl_set_power(struct iwl_priv *priv, void *cmd) 102static int iwl_set_power(struct iwl_priv *priv, void *cmd)
108{ 103{
109 return iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD, 104 return iwl_send_cmd_pdu(priv, POWER_TABLE_CMD,
110 sizeof(struct iwl_powertable_cmd), 105 sizeof(struct iwl_powertable_cmd), cmd);
111 cmd, NULL);
112}
113/* decide the right power level according to association status
114 * and battery status
115 */
116static u16 iwl_get_auto_power_mode(struct iwl_priv *priv)
117{
118 u16 mode;
119
120 switch (priv->power_data.user_power_setting) {
121 case IWL_POWER_AUTO:
122 /* if running on battery */
123 if (priv->power_data.is_battery_active)
124 mode = IWL_POWER_ON_BATTERY;
125 else if (iwl_is_associated(priv))
126 mode = IWL_POWER_ON_AC_ASSOC;
127 else
128 mode = IWL_POWER_ON_AC_DISASSOC;
129 break;
130 default:
131 mode = priv->power_data.user_power_setting;
132 break;
133 }
134 return mode;
135} 106}
136 107
137/* initialize to default */ 108/* initialize to default */
138static void iwl_power_init_handle(struct iwl_priv *priv) 109static void iwl_power_init_handle(struct iwl_priv *priv)
139{ 110{
140 struct iwl_power_mgr *pow_data; 111 struct iwl_power_mgr *pow_data;
141 int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_MAX; 112 int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_NUM;
142 struct iwl_powertable_cmd *cmd; 113 struct iwl_powertable_cmd *cmd;
143 int i; 114 int i;
144 u16 lctl; 115 u16 lctl;
@@ -157,7 +128,7 @@ static void iwl_power_init_handle(struct iwl_priv *priv)
157 128
158 IWL_DEBUG_POWER(priv, "adjust power command flags\n"); 129 IWL_DEBUG_POWER(priv, "adjust power command flags\n");
159 130
160 for (i = 0; i < IWL_POWER_MAX; i++) { 131 for (i = 0; i < IWL_POWER_NUM; i++) {
161 cmd = &pow_data->pwr_range_0[i].cmd; 132 cmd = &pow_data->pwr_range_0[i].cmd;
162 133
163 if (lctl & PCI_CFG_LINK_CTRL_VAL_L0S_EN) 134 if (lctl & PCI_CFG_LINK_CTRL_VAL_L0S_EN)
@@ -247,33 +218,12 @@ int iwl_power_update_mode(struct iwl_priv *priv, bool force)
247 update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE || 218 update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE ||
248 priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE; 219 priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE;
249 220
250 /* If on battery, set to 3, 221 final_mode = priv->power_data.user_power_setting;
251 * if plugged into AC power, set to CAM ("continuously aware mode"),
252 * else user level */
253
254 switch (setting->system_power_setting) {
255 case IWL_POWER_SYS_AUTO:
256 final_mode = iwl_get_auto_power_mode(priv);
257 break;
258 case IWL_POWER_SYS_BATTERY:
259 final_mode = IWL_POWER_INDEX_3;
260 break;
261 case IWL_POWER_SYS_AC:
262 final_mode = IWL_POWER_MODE_CAM;
263 break;
264 default:
265 final_mode = IWL_POWER_INDEX_3;
266 WARN_ON(1);
267 }
268
269 if (setting->critical_power_setting > final_mode)
270 final_mode = setting->critical_power_setting;
271 222
272 /* driver only support CAM for non STA network */ 223 if (setting->power_disabled)
273 if (priv->iw_mode != NL80211_IFTYPE_STATION)
274 final_mode = IWL_POWER_MODE_CAM; 224 final_mode = IWL_POWER_MODE_CAM;
275 225
276 if (iwl_is_ready_rf(priv) && !setting->power_disabled && 226 if (iwl_is_ready_rf(priv) &&
277 ((setting->power_mode != final_mode) || force)) { 227 ((setting->power_mode != final_mode) || force)) {
278 struct iwl_powertable_cmd cmd; 228 struct iwl_powertable_cmd cmd;
279 229
@@ -290,8 +240,6 @@ int iwl_power_update_mode(struct iwl_priv *priv, bool force)
290 240
291 if (final_mode == IWL_POWER_MODE_CAM) 241 if (final_mode == IWL_POWER_MODE_CAM)
292 clear_bit(STATUS_POWER_PMI, &priv->status); 242 clear_bit(STATUS_POWER_PMI, &priv->status);
293 else
294 set_bit(STATUS_POWER_PMI, &priv->status);
295 243
296 if (priv->cfg->ops->lib->update_chain_flags && update_chains) 244 if (priv->cfg->ops->lib->update_chain_flags && update_chains)
297 priv->cfg->ops->lib->update_chain_flags(priv); 245 priv->cfg->ops->lib->update_chain_flags(priv);
@@ -307,51 +255,10 @@ int iwl_power_update_mode(struct iwl_priv *priv, bool force)
307} 255}
308EXPORT_SYMBOL(iwl_power_update_mode); 256EXPORT_SYMBOL(iwl_power_update_mode);
309 257
310/* Allow other iwl code to disable/enable power management active
311 * this will be useful for rate scale to disable PM during heavy
312 * Tx/Rx activities
313 */
314int iwl_power_disable_management(struct iwl_priv *priv, u32 ms)
315{
316 u16 prev_mode;
317 int ret = 0;
318
319 if (priv->power_data.power_disabled)
320 return -EBUSY;
321
322 prev_mode = priv->power_data.user_power_setting;
323 priv->power_data.user_power_setting = IWL_POWER_MODE_CAM;
324 ret = iwl_power_update_mode(priv, 0);
325 priv->power_data.power_disabled = 1;
326 priv->power_data.user_power_setting = prev_mode;
327 cancel_delayed_work(&priv->set_power_save);
328 if (ms)
329 queue_delayed_work(priv->workqueue, &priv->set_power_save,
330 msecs_to_jiffies(ms));
331
332
333 return ret;
334}
335EXPORT_SYMBOL(iwl_power_disable_management);
336
337/* Allow other iwl code to disable/enable power management active
338 * this will be useful for rate scale to disable PM during high
339 * volume activities
340 */
341int iwl_power_enable_management(struct iwl_priv *priv)
342{
343 int ret = 0;
344
345 priv->power_data.power_disabled = 0;
346 ret = iwl_power_update_mode(priv, 0);
347 return ret;
348}
349EXPORT_SYMBOL(iwl_power_enable_management);
350
351/* set user_power_setting */ 258/* set user_power_setting */
352int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode) 259int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode)
353{ 260{
354 if (mode > IWL_POWER_MAX) 261 if (mode >= IWL_POWER_NUM)
355 return -EINVAL; 262 return -EINVAL;
356 263
357 priv->power_data.user_power_setting = mode; 264 priv->power_data.user_power_setting = mode;
@@ -360,86 +267,12 @@ int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode)
360} 267}
361EXPORT_SYMBOL(iwl_power_set_user_mode); 268EXPORT_SYMBOL(iwl_power_set_user_mode);
362 269
363/* set system_power_setting. This should be set by over all
364 * PM application.
365 */
366int iwl_power_set_system_mode(struct iwl_priv *priv, u16 mode)
367{
368 if (mode < IWL_POWER_SYS_MAX)
369 priv->power_data.system_power_setting = mode;
370 else
371 return -EINVAL;
372 return iwl_power_update_mode(priv, 0);
373}
374EXPORT_SYMBOL(iwl_power_set_system_mode);
375
376/* initialize to default */ 270/* initialize to default */
377void iwl_power_initialize(struct iwl_priv *priv) 271void iwl_power_initialize(struct iwl_priv *priv)
378{ 272{
379 iwl_power_init_handle(priv); 273 iwl_power_init_handle(priv);
380 priv->power_data.user_power_setting = IWL_POWER_AUTO; 274 priv->power_data.user_power_setting = IWL_POWER_INDEX_1;
381 priv->power_data.system_power_setting = IWL_POWER_SYS_AUTO; 275 /* default to disabled until mac80211 says otherwise */
382 priv->power_data.power_disabled = 0; 276 priv->power_data.power_disabled = 1;
383 priv->power_data.is_battery_active = 0;
384 priv->power_data.critical_power_setting = 0;
385} 277}
386EXPORT_SYMBOL(iwl_power_initialize); 278EXPORT_SYMBOL(iwl_power_initialize);
387
388/* set critical_power_setting according to temperature value */
389int iwl_power_temperature_change(struct iwl_priv *priv)
390{
391 int ret = 0;
392 s32 temperature = KELVIN_TO_CELSIUS(priv->last_temperature);
393 u16 new_critical = priv->power_data.critical_power_setting;
394
395 if (temperature > IWL_CT_KILL_TEMPERATURE)
396 return 0;
397 else if (temperature > IWL_MIN_POWER_TEMPERATURE)
398 new_critical = IWL_POWER_INDEX_5;
399 else if (temperature > IWL_REDUCED_POWER_TEMPERATURE)
400 new_critical = IWL_POWER_INDEX_3;
401 else
402 new_critical = IWL_POWER_MODE_CAM;
403
404 if (new_critical != priv->power_data.critical_power_setting)
405 priv->power_data.critical_power_setting = new_critical;
406
407 if (priv->power_data.critical_power_setting >
408 priv->power_data.power_mode)
409 ret = iwl_power_update_mode(priv, 0);
410
411 return ret;
412}
413EXPORT_SYMBOL(iwl_power_temperature_change);
414
415static void iwl_bg_set_power_save(struct work_struct *work)
416{
417 struct iwl_priv *priv = container_of(work,
418 struct iwl_priv, set_power_save.work);
419 IWL_DEBUG_POWER(priv, "update power\n");
420
421 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
422 return;
423
424 mutex_lock(&priv->mutex);
425
426 /* on starting association we disable power management
427 * until association, if association failed then this
428 * timer will expire and enable PM again.
429 */
430 if (!iwl_is_associated(priv))
431 iwl_power_enable_management(priv);
432
433 mutex_unlock(&priv->mutex);
434}
435void iwl_setup_power_deferred_work(struct iwl_priv *priv)
436{
437 INIT_DELAYED_WORK(&priv->set_power_save, iwl_bg_set_power_save);
438}
439EXPORT_SYMBOL(iwl_setup_power_deferred_work);
440
441void iwl_power_cancel_timeout(struct iwl_priv *priv)
442{
443 cancel_delayed_work(&priv->set_power_save);
444}
445EXPORT_SYMBOL(iwl_power_cancel_timeout);
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.h b/drivers/net/wireless/iwlwifi/iwl-power.h
index 18963392121e..37ba3bb7a25a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-power.h
+++ b/drivers/net/wireless/iwlwifi/iwl-power.h
@@ -40,56 +40,29 @@ enum {
40 IWL_POWER_INDEX_3, 40 IWL_POWER_INDEX_3,
41 IWL_POWER_INDEX_4, 41 IWL_POWER_INDEX_4,
42 IWL_POWER_INDEX_5, 42 IWL_POWER_INDEX_5,
43 IWL_POWER_AUTO, 43 IWL_POWER_NUM
44 IWL_POWER_MAX = IWL_POWER_AUTO,
45}; 44};
46 45
47enum {
48 IWL_POWER_SYS_AUTO,
49 IWL_POWER_SYS_AC,
50 IWL_POWER_SYS_BATTERY,
51 IWL_POWER_SYS_MAX,
52};
53
54
55/* Power management (not Tx power) structures */ 46/* Power management (not Tx power) structures */
56 47
57#define NOSLP cpu_to_le16(0), 0, 0
58#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
59#define SLP_TOUT(T) cpu_to_le32((T) * MSEC_TO_USEC)
60#define SLP_VEC(X0, X1, X2, X3, X4) {cpu_to_le32(X0), \
61 cpu_to_le32(X1), \
62 cpu_to_le32(X2), \
63 cpu_to_le32(X3), \
64 cpu_to_le32(X4)}
65struct iwl_power_vec_entry { 48struct iwl_power_vec_entry {
66 struct iwl_powertable_cmd cmd; 49 struct iwl_powertable_cmd cmd;
67 u8 no_dtim; 50 u8 no_dtim;
68}; 51};
69 52
70struct iwl_power_mgr { 53struct iwl_power_mgr {
71 spinlock_t lock; 54 struct iwl_power_vec_entry pwr_range_0[IWL_POWER_NUM];
72 struct iwl_power_vec_entry pwr_range_0[IWL_POWER_MAX]; 55 struct iwl_power_vec_entry pwr_range_1[IWL_POWER_NUM];
73 struct iwl_power_vec_entry pwr_range_1[IWL_POWER_MAX]; 56 struct iwl_power_vec_entry pwr_range_2[IWL_POWER_NUM];
74 struct iwl_power_vec_entry pwr_range_2[IWL_POWER_MAX];
75 u32 dtim_period; 57 u32 dtim_period;
76 /* final power level that used to calculate final power command */ 58 /* final power level that used to calculate final power command */
77 u8 power_mode; 59 u8 power_mode;
78 u8 user_power_setting; /* set by user through mac80211 or sysfs */ 60 u8 user_power_setting; /* set by user through sysfs */
79 u8 system_power_setting; /* set by kernel system tools */ 61 u8 power_disabled; /* set by mac80211's CONF_PS */
80 u8 critical_power_setting; /* set if driver over heated */
81 u8 is_battery_active; /* DC/AC power */
82 u8 power_disabled; /* flag to disable using power saving level */
83}; 62};
84 63
85void iwl_setup_power_deferred_work(struct iwl_priv *priv);
86void iwl_power_cancel_timeout(struct iwl_priv *priv);
87int iwl_power_update_mode(struct iwl_priv *priv, bool force); 64int iwl_power_update_mode(struct iwl_priv *priv, bool force);
88int iwl_power_disable_management(struct iwl_priv *priv, u32 ms);
89int iwl_power_enable_management(struct iwl_priv *priv);
90int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode); 65int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode);
91int iwl_power_set_system_mode(struct iwl_priv *priv, u16 mode);
92void iwl_power_initialize(struct iwl_priv *priv); 66void iwl_power_initialize(struct iwl_priv *priv);
93int iwl_power_temperature_change(struct iwl_priv *priv);
94 67
95#endif /* __iwl_power_setting_h__ */ 68#endif /* __iwl_power_setting_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-rfkill.c b/drivers/net/wireless/iwlwifi/iwl-rfkill.c
deleted file mode 100644
index 2ad9faf1508a..000000000000
--- a/drivers/net/wireless/iwlwifi/iwl-rfkill.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/init.h>
31
32#include <net/mac80211.h>
33
34#include "iwl-eeprom.h"
35#include "iwl-dev.h"
36#include "iwl-core.h"
37
38/* software rf-kill from user */
39static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
40{
41 struct iwl_priv *priv = data;
42 int err = 0;
43
44 if (!priv->rfkill)
45 return 0;
46
47 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
48 return 0;
49
50 IWL_DEBUG_RF_KILL(priv, "we received soft RFKILL set to state %d\n", state);
51 mutex_lock(&priv->mutex);
52
53 switch (state) {
54 case RFKILL_STATE_UNBLOCKED:
55 if (iwl_is_rfkill_hw(priv)) {
56 err = -EBUSY;
57 goto out_unlock;
58 }
59 iwl_radio_kill_sw_enable_radio(priv);
60 break;
61 case RFKILL_STATE_SOFT_BLOCKED:
62 iwl_radio_kill_sw_disable_radio(priv);
63 break;
64 default:
65 IWL_WARN(priv, "we received unexpected RFKILL state %d\n",
66 state);
67 break;
68 }
69out_unlock:
70 mutex_unlock(&priv->mutex);
71
72 return err;
73}
74
75int iwl_rfkill_init(struct iwl_priv *priv)
76{
77 struct device *device = wiphy_dev(priv->hw->wiphy);
78 int ret = 0;
79
80 BUG_ON(device == NULL);
81
82 IWL_DEBUG_RF_KILL(priv, "Initializing RFKILL.\n");
83 priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
84 if (!priv->rfkill) {
85 IWL_ERR(priv, "Unable to allocate RFKILL device.\n");
86 ret = -ENOMEM;
87 goto error;
88 }
89
90 priv->rfkill->name = priv->cfg->name;
91 priv->rfkill->data = priv;
92 priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
93 priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
94 priv->rfkill->user_claim_unsupported = 1;
95
96 priv->rfkill->dev.class->suspend = NULL;
97 priv->rfkill->dev.class->resume = NULL;
98
99 ret = rfkill_register(priv->rfkill);
100 if (ret) {
101 IWL_ERR(priv, "Unable to register RFKILL: %d\n", ret);
102 goto free_rfkill;
103 }
104
105 IWL_DEBUG_RF_KILL(priv, "RFKILL initialization complete.\n");
106 return ret;
107
108free_rfkill:
109 if (priv->rfkill != NULL)
110 rfkill_free(priv->rfkill);
111 priv->rfkill = NULL;
112
113error:
114 IWL_DEBUG_RF_KILL(priv, "RFKILL initialization complete.\n");
115 return ret;
116}
117EXPORT_SYMBOL(iwl_rfkill_init);
118
119void iwl_rfkill_unregister(struct iwl_priv *priv)
120{
121
122 if (priv->rfkill)
123 rfkill_unregister(priv->rfkill);
124
125 priv->rfkill = NULL;
126}
127EXPORT_SYMBOL(iwl_rfkill_unregister);
128
129/* set RFKILL to the right state. */
130void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
131{
132 if (!priv->rfkill)
133 return;
134
135 if (iwl_is_rfkill_hw(priv)) {
136 rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED);
137 return;
138 }
139
140 if (!iwl_is_rfkill_sw(priv))
141 rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED);
142 else
143 rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
144}
145EXPORT_SYMBOL(iwl_rfkill_set_hw_state);
diff --git a/drivers/net/wireless/iwlwifi/iwl-rfkill.h b/drivers/net/wireless/iwlwifi/iwl-rfkill.h
deleted file mode 100644
index 633dafb4bf1b..000000000000
--- a/drivers/net/wireless/iwlwifi/iwl-rfkill.h
+++ /dev/null
@@ -1,48 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28#ifndef __iwl_rf_kill_h__
29#define __iwl_rf_kill_h__
30
31struct iwl_priv;
32
33#include <linux/rfkill.h>
34
35#ifdef CONFIG_IWLWIFI_RFKILL
36
37void iwl_rfkill_set_hw_state(struct iwl_priv *priv);
38void iwl_rfkill_unregister(struct iwl_priv *priv);
39int iwl_rfkill_init(struct iwl_priv *priv);
40#else
41static inline void iwl_rfkill_set_hw_state(struct iwl_priv *priv) {}
42static inline void iwl_rfkill_unregister(struct iwl_priv *priv) {}
43static inline int iwl_rfkill_init(struct iwl_priv *priv) { return 0; }
44#endif
45
46
47
48#endif /* __iwl_rf_kill_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-rx.c b/drivers/net/wireless/iwlwifi/iwl-rx.c
index 8f65908f66f1..2b8d40b37a1c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rx.c
@@ -145,18 +145,14 @@ int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q)
145 goto exit_unlock; 145 goto exit_unlock;
146 } 146 }
147 147
148 ret = iwl_grab_nic_access(priv); 148 q->write_actual = (q->write & ~0x7);
149 if (ret) 149 iwl_write_direct32(priv, rx_wrt_ptr_reg, q->write_actual);
150 goto exit_unlock;
151
152 /* Device expects a multiple of 8 */
153 iwl_write_direct32(priv, rx_wrt_ptr_reg, q->write & ~0x7);
154 iwl_release_nic_access(priv);
155 150
156 /* Else device is assumed to be awake */ 151 /* Else device is assumed to be awake */
157 } else { 152 } else {
158 /* Device expects a multiple of 8 */ 153 /* Device expects a multiple of 8 */
159 iwl_write32(priv, rx_wrt_ptr_reg, q->write & ~0x7); 154 q->write_actual = (q->write & ~0x7);
155 iwl_write_direct32(priv, rx_wrt_ptr_reg, q->write_actual);
160 } 156 }
161 157
162 q->need_update = 0; 158 q->need_update = 0;
@@ -218,7 +214,7 @@ int iwl_rx_queue_restock(struct iwl_priv *priv)
218 214
219 /* If we've added more space for the firmware to place data, tell it. 215 /* If we've added more space for the firmware to place data, tell it.
220 * Increment device's write pointer in multiples of 8. */ 216 * Increment device's write pointer in multiples of 8. */
221 if (write != (rxq->write & ~0x7)) { 217 if (rxq->write_actual != (rxq->write & ~0x7)) {
222 spin_lock_irqsave(&rxq->lock, flags); 218 spin_lock_irqsave(&rxq->lock, flags);
223 rxq->need_update = 1; 219 rxq->need_update = 1;
224 spin_unlock_irqrestore(&rxq->lock, flags); 220 spin_unlock_irqrestore(&rxq->lock, flags);
@@ -238,7 +234,7 @@ EXPORT_SYMBOL(iwl_rx_queue_restock);
238 * Also restock the Rx queue via iwl_rx_queue_restock. 234 * Also restock the Rx queue via iwl_rx_queue_restock.
239 * This is called as a scheduled work item (except for during initialization) 235 * This is called as a scheduled work item (except for during initialization)
240 */ 236 */
241void iwl_rx_allocate(struct iwl_priv *priv) 237void iwl_rx_allocate(struct iwl_priv *priv, gfp_t priority)
242{ 238{
243 struct iwl_rx_queue *rxq = &priv->rxq; 239 struct iwl_rx_queue *rxq = &priv->rxq;
244 struct list_head *element; 240 struct list_head *element;
@@ -260,7 +256,8 @@ void iwl_rx_allocate(struct iwl_priv *priv)
260 256
261 /* Alloc a new receive buffer */ 257 /* Alloc a new receive buffer */
262 rxb->skb = alloc_skb(priv->hw_params.rx_buf_size + 256, 258 rxb->skb = alloc_skb(priv->hw_params.rx_buf_size + 256,
263 GFP_KERNEL); 259 priority);
260
264 if (!rxb->skb) { 261 if (!rxb->skb) {
265 IWL_CRIT(priv, "Can not allocate SKB buffers\n"); 262 IWL_CRIT(priv, "Can not allocate SKB buffers\n");
266 /* We don't reschedule replenish work here -- we will 263 /* We don't reschedule replenish work here -- we will
@@ -295,7 +292,7 @@ void iwl_rx_replenish(struct iwl_priv *priv)
295{ 292{
296 unsigned long flags; 293 unsigned long flags;
297 294
298 iwl_rx_allocate(priv); 295 iwl_rx_allocate(priv, GFP_KERNEL);
299 296
300 spin_lock_irqsave(&priv->lock, flags); 297 spin_lock_irqsave(&priv->lock, flags);
301 iwl_rx_queue_restock(priv); 298 iwl_rx_queue_restock(priv);
@@ -303,6 +300,14 @@ void iwl_rx_replenish(struct iwl_priv *priv)
303} 300}
304EXPORT_SYMBOL(iwl_rx_replenish); 301EXPORT_SYMBOL(iwl_rx_replenish);
305 302
303void iwl_rx_replenish_now(struct iwl_priv *priv)
304{
305 iwl_rx_allocate(priv, GFP_ATOMIC);
306
307 iwl_rx_queue_restock(priv);
308}
309EXPORT_SYMBOL(iwl_rx_replenish_now);
310
306 311
307/* Assumes that the skb field of the buffers in 'pool' is kept accurate. 312/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
308 * If an SKB has been detached, the POOL needs to have its SKB set to NULL 313 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
@@ -358,6 +363,7 @@ int iwl_rx_queue_alloc(struct iwl_priv *priv)
358 /* Set us so that we have processed and used all buffers, but have 363 /* Set us so that we have processed and used all buffers, but have
359 * not restocked the Rx queue with fresh buffers */ 364 * not restocked the Rx queue with fresh buffers */
360 rxq->read = rxq->write = 0; 365 rxq->read = rxq->write = 0;
366 rxq->write_actual = 0;
361 rxq->free_count = 0; 367 rxq->free_count = 0;
362 rxq->need_update = 0; 368 rxq->need_update = 0;
363 return 0; 369 return 0;
@@ -396,6 +402,7 @@ void iwl_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
396 /* Set us so that we have processed and used all buffers, but have 402 /* Set us so that we have processed and used all buffers, but have
397 * not restocked the Rx queue with fresh buffers */ 403 * not restocked the Rx queue with fresh buffers */
398 rxq->read = rxq->write = 0; 404 rxq->read = rxq->write = 0;
405 rxq->write_actual = 0;
399 rxq->free_count = 0; 406 rxq->free_count = 0;
400 spin_unlock_irqrestore(&rxq->lock, flags); 407 spin_unlock_irqrestore(&rxq->lock, flags);
401} 408}
@@ -403,18 +410,12 @@ EXPORT_SYMBOL(iwl_rx_queue_reset);
403 410
404int iwl_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq) 411int iwl_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
405{ 412{
406 int ret;
407 unsigned long flags;
408 u32 rb_size; 413 u32 rb_size;
409 const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */ 414 const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
410 const u32 rb_timeout = 0; /* FIXME: RX_RB_TIMEOUT why this stalls RX */ 415 u32 rb_timeout = 0; /* FIXME: RX_RB_TIMEOUT for all devices? */
411 416
412 spin_lock_irqsave(&priv->lock, flags); 417 if (!priv->cfg->use_isr_legacy)
413 ret = iwl_grab_nic_access(priv); 418 rb_timeout = RX_RB_TIMEOUT;
414 if (ret) {
415 spin_unlock_irqrestore(&priv->lock, flags);
416 return ret;
417 }
418 419
419 if (priv->cfg->mod_params->amsdu_size_8K) 420 if (priv->cfg->mod_params->amsdu_size_8K)
420 rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K; 421 rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
@@ -452,35 +453,19 @@ int iwl_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
452 (rb_timeout << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS)| 453 (rb_timeout << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS)|
453 (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS)); 454 (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS));
454 455
455 iwl_release_nic_access(priv);
456
457 iwl_write32(priv, CSR_INT_COALESCING, 0x40); 456 iwl_write32(priv, CSR_INT_COALESCING, 0x40);
458 457
459 spin_unlock_irqrestore(&priv->lock, flags);
460
461 return 0; 458 return 0;
462} 459}
463 460
464int iwl_rxq_stop(struct iwl_priv *priv) 461int iwl_rxq_stop(struct iwl_priv *priv)
465{ 462{
466 int ret;
467 unsigned long flags;
468
469 spin_lock_irqsave(&priv->lock, flags);
470 ret = iwl_grab_nic_access(priv);
471 if (unlikely(ret)) {
472 spin_unlock_irqrestore(&priv->lock, flags);
473 return ret;
474 }
475 463
476 /* stop Rx DMA */ 464 /* stop Rx DMA */
477 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); 465 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
478 iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG, 466 iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
479 FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000); 467 FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
480 468
481 iwl_release_nic_access(priv);
482 spin_unlock_irqrestore(&priv->lock, flags);
483
484 return 0; 469 return 0;
485} 470}
486EXPORT_SYMBOL(iwl_rxq_stop); 471EXPORT_SYMBOL(iwl_rxq_stop);
@@ -582,8 +567,8 @@ void iwl_rx_statistics(struct iwl_priv *priv,
582 567
583 iwl_leds_background(priv); 568 iwl_leds_background(priv);
584 569
585 if (priv->cfg->ops->lib->temperature && change) 570 if (priv->cfg->ops->lib->temp_ops.temperature && change)
586 priv->cfg->ops->lib->temperature(priv); 571 priv->cfg->ops->lib->temp_ops.temperature(priv);
587} 572}
588EXPORT_SYMBOL(iwl_rx_statistics); 573EXPORT_SYMBOL(iwl_rx_statistics);
589 574
@@ -1102,13 +1087,6 @@ void iwl_rx_reply_rx(struct iwl_priv *priv,
1102 if (rx_start->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) 1087 if (rx_start->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
1103 rx_status.flag |= RX_FLAG_SHORTPRE; 1088 rx_status.flag |= RX_FLAG_SHORTPRE;
1104 1089
1105 /* Take shortcut when only in monitor mode */
1106 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
1107 iwl_pass_packet_to_mac80211(priv, include_phy,
1108 rxb, &rx_status);
1109 return;
1110 }
1111
1112 network_packet = iwl_is_network_packet(priv, header); 1090 network_packet = iwl_is_network_packet(priv, header);
1113 if (network_packet) { 1091 if (network_packet) {
1114 priv->last_rx_rssi = rx_status.signal; 1092 priv->last_rx_rssi = rx_status.signal;
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c
index 6330b91e37ce..e26875dbe859 100644
--- a/drivers/net/wireless/iwlwifi/iwl-scan.c
+++ b/drivers/net/wireless/iwlwifi/iwl-scan.c
@@ -445,13 +445,6 @@ int iwl_mac_hw_scan(struct ieee80211_hw *hw,
445 unsigned long flags; 445 unsigned long flags;
446 struct iwl_priv *priv = hw->priv; 446 struct iwl_priv *priv = hw->priv;
447 int ret; 447 int ret;
448 u8 *ssid = NULL;
449 size_t ssid_len = 0;
450
451 if (req->n_ssids) {
452 ssid = req->ssids[0].ssid;
453 ssid_len = req->ssids[0].ssid_len;
454 }
455 448
456 IWL_DEBUG_MAC80211(priv, "enter\n"); 449 IWL_DEBUG_MAC80211(priv, "enter\n");
457 450
@@ -485,13 +478,7 @@ int iwl_mac_hw_scan(struct ieee80211_hw *hw,
485 goto out_unlock; 478 goto out_unlock;
486 } 479 }
487 480
488 if (ssid_len) { 481 priv->scan_request = req;
489 priv->one_direct_scan = 1;
490 priv->direct_ssid_len = ssid_len;
491 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
492 } else {
493 priv->one_direct_scan = 0;
494 }
495 482
496 ret = iwl_scan_initiate(priv); 483 ret = iwl_scan_initiate(priv);
497 484
@@ -530,73 +517,14 @@ void iwl_bg_scan_check(struct work_struct *data)
530EXPORT_SYMBOL(iwl_bg_scan_check); 517EXPORT_SYMBOL(iwl_bg_scan_check);
531 518
532/** 519/**
533 * iwl_supported_rate_to_ie - fill in the supported rate in IE field
534 *
535 * return : set the bit for each supported rate insert in ie
536 */
537static u16 iwl_supported_rate_to_ie(u8 *ie, u16 supported_rate,
538 u16 basic_rate, int *left)
539{
540 u16 ret_rates = 0, bit;
541 int i;
542 u8 *cnt = ie;
543 u8 *rates = ie + 1;
544
545 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
546 if (bit & supported_rate) {
547 ret_rates |= bit;
548 rates[*cnt] = iwl_rates[i].ieee |
549 ((bit & basic_rate) ? 0x80 : 0x00);
550 (*cnt)++;
551 (*left)--;
552 if ((*left <= 0) ||
553 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
554 break;
555 }
556 }
557
558 return ret_rates;
559}
560
561
562static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
563 u8 *pos, int *left)
564{
565 struct ieee80211_ht_cap *ht_cap;
566
567 if (!sband || !sband->ht_cap.ht_supported)
568 return;
569
570 if (*left < sizeof(struct ieee80211_ht_cap))
571 return;
572
573 *pos++ = sizeof(struct ieee80211_ht_cap);
574 ht_cap = (struct ieee80211_ht_cap *) pos;
575
576 ht_cap->cap_info = cpu_to_le16(sband->ht_cap.cap);
577 memcpy(&ht_cap->mcs, &sband->ht_cap.mcs, 16);
578 ht_cap->ampdu_params_info =
579 (sband->ht_cap.ampdu_factor & IEEE80211_HT_AMPDU_PARM_FACTOR) |
580 ((sband->ht_cap.ampdu_density << 2) &
581 IEEE80211_HT_AMPDU_PARM_DENSITY);
582 *left -= sizeof(struct ieee80211_ht_cap);
583}
584
585/**
586 * iwl_fill_probe_req - fill in all required fields and IE for probe request 520 * iwl_fill_probe_req - fill in all required fields and IE for probe request
587 */ 521 */
588 522
589u16 iwl_fill_probe_req(struct iwl_priv *priv, 523u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame,
590 enum ieee80211_band band, 524 const u8 *ies, int ie_len, int left)
591 struct ieee80211_mgmt *frame,
592 int left)
593{ 525{
594 int len = 0; 526 int len = 0;
595 u8 *pos = NULL; 527 u8 *pos = NULL;
596 u16 active_rates, ret_rates, cck_rates, active_rate_basic;
597 const struct ieee80211_supported_band *sband =
598 iwl_get_hw_mode(priv, band);
599
600 528
601 /* Make sure there is enough space for the probe request, 529 /* Make sure there is enough space for the probe request,
602 * two mandatory IEs and the data */ 530 * two mandatory IEs and the data */
@@ -624,62 +552,12 @@ u16 iwl_fill_probe_req(struct iwl_priv *priv,
624 552
625 len += 2; 553 len += 2;
626 554
627 /* fill in supported rate */ 555 if (WARN_ON(left < ie_len))
628 left -= 2; 556 return len;
629 if (left < 0)
630 return 0;
631
632 *pos++ = WLAN_EID_SUPP_RATES;
633 *pos = 0;
634
635 /* exclude 60M rate */
636 active_rates = priv->rates_mask;
637 active_rates &= ~IWL_RATE_60M_MASK;
638
639 active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
640
641 cck_rates = IWL_CCK_RATES_MASK & active_rates;
642 ret_rates = iwl_supported_rate_to_ie(pos, cck_rates,
643 active_rate_basic, &left);
644 active_rates &= ~ret_rates;
645
646 ret_rates = iwl_supported_rate_to_ie(pos, active_rates,
647 active_rate_basic, &left);
648 active_rates &= ~ret_rates;
649
650 len += 2 + *pos;
651 pos += (*pos) + 1;
652 557
653 if (active_rates == 0) 558 memcpy(pos, ies, ie_len);
654 goto fill_end; 559 len += ie_len;
655 560 left -= ie_len;
656 /* fill in supported extended rate */
657 /* ...next IE... */
658 left -= 2;
659 if (left < 0)
660 return 0;
661 /* ... fill it in... */
662 *pos++ = WLAN_EID_EXT_SUPP_RATES;
663 *pos = 0;
664 iwl_supported_rate_to_ie(pos, active_rates, active_rate_basic, &left);
665 if (*pos > 0) {
666 len += 2 + *pos;
667 pos += (*pos) + 1;
668 } else {
669 pos--;
670 }
671
672 fill_end:
673
674 left -= 2;
675 if (left < 0)
676 return 0;
677
678 *pos++ = WLAN_EID_HT_CAPABILITY;
679 *pos = 0;
680 iwl_ht_cap_to_ie(sband, pos, &left);
681 if (*pos > 0)
682 len += 2 + *pos;
683 561
684 return (u16)len; 562 return (u16)len;
685} 563}
@@ -699,11 +577,13 @@ static void iwl_bg_request_scan(struct work_struct *data)
699 int ret = 0; 577 int ret = 0;
700 u32 rate_flags = 0; 578 u32 rate_flags = 0;
701 u16 cmd_len; 579 u16 cmd_len;
580 u16 rx_chain = 0;
702 enum ieee80211_band band; 581 enum ieee80211_band band;
703 u8 n_probes = 2; 582 u8 n_probes = 0;
704 u8 rx_chain = priv->hw_params.valid_rx_ant; 583 u8 rx_ant = priv->hw_params.valid_rx_ant;
705 u8 rate; 584 u8 rate;
706 DECLARE_SSID_BUF(ssid); 585 bool is_active = false;
586 int chan_mod;
707 587
708 conf = ieee80211_get_hw_conf(priv->hw); 588 conf = ieee80211_get_hw_conf(priv->hw);
709 589
@@ -795,19 +675,25 @@ static void iwl_bg_request_scan(struct work_struct *data)
795 scan_suspend_time, interval); 675 scan_suspend_time, interval);
796 } 676 }
797 677
798 /* We should add the ability for user to lock to PASSIVE ONLY */ 678 if (priv->scan_request->n_ssids) {
799 if (priv->one_direct_scan) { 679 int i, p = 0;
800 IWL_DEBUG_SCAN(priv, "Start direct scan for '%s'\n", 680 IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
801 print_ssid(ssid, priv->direct_ssid, 681 for (i = 0; i < priv->scan_request->n_ssids; i++) {
802 priv->direct_ssid_len)); 682 /* always does wildcard anyway */
803 scan->direct_scan[0].id = WLAN_EID_SSID; 683 if (!priv->scan_request->ssids[i].ssid_len)
804 scan->direct_scan[0].len = priv->direct_ssid_len; 684 continue;
805 memcpy(scan->direct_scan[0].ssid, 685 scan->direct_scan[p].id = WLAN_EID_SSID;
806 priv->direct_ssid, priv->direct_ssid_len); 686 scan->direct_scan[p].len =
807 n_probes++; 687 priv->scan_request->ssids[i].ssid_len;
808 } else { 688 memcpy(scan->direct_scan[p].ssid,
809 IWL_DEBUG_SCAN(priv, "Start indirect scan.\n"); 689 priv->scan_request->ssids[i].ssid,
810 } 690 priv->scan_request->ssids[i].ssid_len);
691 n_probes++;
692 p++;
693 }
694 is_active = true;
695 } else
696 IWL_DEBUG_SCAN(priv, "Start passive scan.\n");
811 697
812 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; 698 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
813 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; 699 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
@@ -817,7 +703,9 @@ static void iwl_bg_request_scan(struct work_struct *data)
817 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) { 703 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
818 band = IEEE80211_BAND_2GHZ; 704 band = IEEE80211_BAND_2GHZ;
819 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; 705 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
820 if (priv->active_rxon.flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) { 706 chan_mod = le32_to_cpu(priv->active_rxon.flags & RXON_FLG_CHANNEL_MODE_MSK)
707 >> RXON_FLG_CHANNEL_MODE_POS;
708 if (chan_mod == CHANNEL_MODE_PURE_40) {
821 rate = IWL_RATE_6M_PLCP; 709 rate = IWL_RATE_6M_PLCP;
822 } else { 710 } else {
823 rate = IWL_RATE_1M_PLCP; 711 rate = IWL_RATE_1M_PLCP;
@@ -827,13 +715,18 @@ static void iwl_bg_request_scan(struct work_struct *data)
827 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { 715 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
828 band = IEEE80211_BAND_5GHZ; 716 band = IEEE80211_BAND_5GHZ;
829 rate = IWL_RATE_6M_PLCP; 717 rate = IWL_RATE_6M_PLCP;
830 scan->good_CRC_th = IWL_GOOD_CRC_TH; 718 /*
719 * If active scaning is requested but a certain channel
720 * is marked passive, we can do active scanning if we
721 * detect transmissions.
722 */
723 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH : 0;
831 724
832 /* Force use of chains B and C (0x6) for scan Rx for 4965 725 /* Force use of chains B and C (0x6) for scan Rx for 4965
833 * Avoid A (0x1) because of its off-channel reception on A-band. 726 * Avoid A (0x1) because of its off-channel reception on A-band.
834 */ 727 */
835 if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) 728 if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)
836 rx_chain = 0x6; 729 rx_ant = ANT_BC;
837 } else { 730 } else {
838 IWL_WARN(priv, "Invalid scan band count\n"); 731 IWL_WARN(priv, "Invalid scan band count\n");
839 goto done; 732 goto done;
@@ -845,26 +738,27 @@ static void iwl_bg_request_scan(struct work_struct *data)
845 scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags); 738 scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags);
846 739
847 /* MIMO is not used here, but value is required */ 740 /* MIMO is not used here, but value is required */
848 scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | 741 rx_chain |= ANT_ABC << RXON_RX_CHAIN_VALID_POS;
849 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | 742 rx_chain |= ANT_ABC << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
850 (rx_chain << RXON_RX_CHAIN_FORCE_SEL_POS) | 743 rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
851 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); 744 rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
852 745 scan->rx_chain = cpu_to_le16(rx_chain);
853 cmd_len = iwl_fill_probe_req(priv, band, 746 cmd_len = iwl_fill_probe_req(priv,
854 (struct ieee80211_mgmt *)scan->data, 747 (struct ieee80211_mgmt *)scan->data,
855 IWL_MAX_SCAN_SIZE - sizeof(*scan)); 748 priv->scan_request->ie,
749 priv->scan_request->ie_len,
750 IWL_MAX_SCAN_SIZE - sizeof(*scan));
856 751
857 scan->tx_cmd.len = cpu_to_le16(cmd_len); 752 scan->tx_cmd.len = cpu_to_le16(cmd_len);
858 753
859 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) 754 if (iwl_is_monitor_mode(priv))
860 scan->filter_flags = RXON_FILTER_PROMISC_MSK; 755 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
861 756
862 scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | 757 scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
863 RXON_FILTER_BCON_AWARE_MSK); 758 RXON_FILTER_BCON_AWARE_MSK);
864 759
865 scan->channel_count = 760 scan->channel_count =
866 iwl_get_channels_for_scan(priv, band, 1, /* active */ 761 iwl_get_channels_for_scan(priv, band, is_active, n_probes,
867 n_probes,
868 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); 762 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
869 763
870 if (scan->channel_count == 0) { 764 if (scan->channel_count == 0) {
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index 44ab03a12e40..2addf735b193 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -86,8 +86,7 @@ static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
86 86
87 spin_lock_irqsave(&priv->sta_lock, flags); 87 spin_lock_irqsave(&priv->sta_lock, flags);
88 88
89 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && 89 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE))
90 !(priv->stations_39[sta_id].used & IWL_STA_DRIVER_ACTIVE))
91 IWL_ERR(priv, "ACTIVATE a non DRIVER active station %d\n", 90 IWL_ERR(priv, "ACTIVATE a non DRIVER active station %d\n",
92 sta_id); 91 sta_id);
93 92
@@ -228,15 +227,16 @@ static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
228} 227}
229 228
230/** 229/**
231 * iwl_add_station_flags - Add station to tables in driver and device 230 * iwl_add_station - Add station to tables in driver and device
232 */ 231 */
233u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap, 232u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap, u8 flags,
234 u8 flags, struct ieee80211_sta_ht_cap *ht_info) 233 struct ieee80211_sta_ht_cap *ht_info)
235{ 234{
236 int i;
237 int sta_id = IWL_INVALID_STATION;
238 struct iwl_station_entry *station; 235 struct iwl_station_entry *station;
239 unsigned long flags_spin; 236 unsigned long flags_spin;
237 int i;
238 int sta_id = IWL_INVALID_STATION;
239 u16 rate;
240 240
241 spin_lock_irqsave(&priv->sta_lock, flags_spin); 241 spin_lock_irqsave(&priv->sta_lock, flags_spin);
242 if (is_ap) 242 if (is_ap)
@@ -288,6 +288,12 @@ u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
288 priv->iw_mode != NL80211_IFTYPE_ADHOC) 288 priv->iw_mode != NL80211_IFTYPE_ADHOC)
289 iwl_set_ht_add_station(priv, sta_id, ht_info); 289 iwl_set_ht_add_station(priv, sta_id, ht_info);
290 290
291 /* 3945 only */
292 rate = (priv->band == IEEE80211_BAND_5GHZ) ?
293 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP;
294 /* Turn on both antennas for the station... */
295 station->sta.rate_n_flags = cpu_to_le16(rate | RATE_MCS_ANT_AB_MSK);
296
291 spin_unlock_irqrestore(&priv->sta_lock, flags_spin); 297 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
292 298
293 /* Add station to device's station table */ 299 /* Add station to device's station table */
@@ -295,7 +301,7 @@ u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
295 return sta_id; 301 return sta_id;
296 302
297} 303}
298EXPORT_SYMBOL(iwl_add_station_flags); 304EXPORT_SYMBOL(iwl_add_station);
299 305
300static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr) 306static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr)
301{ 307{
@@ -408,7 +414,7 @@ static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
408/** 414/**
409 * iwl_remove_station - Remove driver's knowledge of station. 415 * iwl_remove_station - Remove driver's knowledge of station.
410 */ 416 */
411int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap) 417int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
412{ 418{
413 int sta_id = IWL_INVALID_STATION; 419 int sta_id = IWL_INVALID_STATION;
414 int i, ret = -EINVAL; 420 int i, ret = -EINVAL;
@@ -490,7 +496,7 @@ void iwl_clear_stations_table(struct iwl_priv *priv)
490 /* keep track of static keys */ 496 /* keep track of static keys */
491 for (i = 0; i < WEP_KEYS_MAX ; i++) { 497 for (i = 0; i < WEP_KEYS_MAX ; i++) {
492 if (priv->wep_keys[i].key_size) 498 if (priv->wep_keys[i].key_size)
493 test_and_set_bit(i, &priv->ucode_key_table); 499 set_bit(i, &priv->ucode_key_table);
494 } 500 }
495 501
496 spin_unlock_irqrestore(&priv->sta_lock, flags); 502 spin_unlock_irqrestore(&priv->sta_lock, flags);
@@ -946,7 +952,7 @@ EXPORT_SYMBOL(iwl_send_lq_cmd);
946 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD, 952 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
947 * which requires station table entry to exist). 953 * which requires station table entry to exist).
948 */ 954 */
949static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap) 955static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, bool is_ap)
950{ 956{
951 int i, r; 957 int i, r;
952 struct iwl_link_quality_cmd link_cmd = { 958 struct iwl_link_quality_cmd link_cmd = {
@@ -979,8 +985,9 @@ static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap)
979 link_cmd.general_params.single_stream_ant_msk = 985 link_cmd.general_params.single_stream_ant_msk =
980 first_antenna(priv->hw_params.valid_tx_ant); 986 first_antenna(priv->hw_params.valid_tx_ant);
981 link_cmd.general_params.dual_stream_ant_msk = 3; 987 link_cmd.general_params.dual_stream_ant_msk = 3;
982 link_cmd.agg_params.agg_dis_start_th = 3; 988 link_cmd.agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
983 link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000); 989 link_cmd.agg_params.agg_time_limit =
990 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
984 991
985 /* Update the rate scaling for control frame Tx to AP */ 992 /* Update the rate scaling for control frame Tx to AP */
986 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id; 993 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
@@ -995,7 +1002,7 @@ static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap)
995 * there is only one AP station with id= IWL_AP_ID 1002 * there is only one AP station with id= IWL_AP_ID
996 * NOTE: mutex must be held before calling this function 1003 * NOTE: mutex must be held before calling this function
997 */ 1004 */
998int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap) 1005int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
999{ 1006{
1000 struct ieee80211_sta *sta; 1007 struct ieee80211_sta *sta;
1001 struct ieee80211_sta_ht_cap ht_config; 1008 struct ieee80211_sta_ht_cap ht_config;
@@ -1020,8 +1027,7 @@ int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
1020 rcu_read_unlock(); 1027 rcu_read_unlock();
1021 } 1028 }
1022 1029
1023 sta_id = iwl_add_station_flags(priv, addr, is_ap, 1030 sta_id = iwl_add_station(priv, addr, is_ap, CMD_SYNC, cur_ht_config);
1024 0, cur_ht_config);
1025 1031
1026 /* Set up default rate scaling table in device's station table */ 1032 /* Set up default rate scaling table in device's station table */
1027 iwl_sta_init_lq(priv, addr, is_ap); 1033 iwl_sta_init_lq(priv, addr, is_ap);
@@ -1067,8 +1073,8 @@ int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
1067 return sta_id; 1073 return sta_id;
1068 1074
1069 /* Create new station table entry */ 1075 /* Create new station table entry */
1070 sta_id = iwl_add_station_flags(priv, hdr->addr1, 1076 sta_id = iwl_add_station(priv, hdr->addr1, false,
1071 0, CMD_ASYNC, NULL); 1077 CMD_ASYNC, NULL);
1072 1078
1073 if (sta_id != IWL_INVALID_STATION) 1079 if (sta_id != IWL_INVALID_STATION)
1074 return sta_id; 1080 return sta_id;
@@ -1079,11 +1085,6 @@ int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
1079 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); 1085 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
1080 return priv->hw_params.bcast_sta_id; 1086 return priv->hw_params.bcast_sta_id;
1081 1087
1082 /* If we are in monitor mode, use BCAST. This is required for
1083 * packet injection. */
1084 case NL80211_IFTYPE_MONITOR:
1085 return priv->hw_params.bcast_sta_id;
1086
1087 default: 1088 default:
1088 IWL_WARN(priv, "Unknown mode of operation: %d\n", 1089 IWL_WARN(priv, "Unknown mode of operation: %d\n",
1089 priv->iw_mode); 1090 priv->iw_mode);
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.h b/drivers/net/wireless/iwlwifi/iwl-sta.h
index 59a586b6b56c..6deebade6361 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.h
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.h
@@ -51,16 +51,15 @@ void iwl_update_tkip_key(struct iwl_priv *priv,
51 struct ieee80211_key_conf *keyconf, 51 struct ieee80211_key_conf *keyconf,
52 const u8 *addr, u32 iv32, u16 *phase1key); 52 const u8 *addr, u32 iv32, u16 *phase1key);
53 53
54int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap); 54int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap);
55int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap); 55int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap);
56void iwl_clear_stations_table(struct iwl_priv *priv); 56void iwl_clear_stations_table(struct iwl_priv *priv);
57int iwl_get_free_ucode_key_index(struct iwl_priv *priv); 57int iwl_get_free_ucode_key_index(struct iwl_priv *priv);
58int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr); 58int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr);
59int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr); 59int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr);
60int iwl_send_add_sta(struct iwl_priv *priv, 60int iwl_send_add_sta(struct iwl_priv *priv,
61 struct iwl_addsta_cmd *sta, u8 flags); 61 struct iwl_addsta_cmd *sta, u8 flags);
62u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, 62u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap, u8 flags,
63 int is_ap, u8 flags,
64 struct ieee80211_sta_ht_cap *ht_info); 63 struct ieee80211_sta_ht_cap *ht_info);
65void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid); 64void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid);
66int iwl_sta_rx_agg_start(struct iwl_priv *priv, 65int iwl_sta_rx_agg_start(struct iwl_priv *priv,
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index 71d5b8a1a73e..85ae7a62109c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -102,13 +102,8 @@ int iwl_txq_update_write_ptr(struct iwl_priv *priv, struct iwl_tx_queue *txq)
102 return ret; 102 return ret;
103 } 103 }
104 104
105 /* restore this queue's parameters in nic hardware. */
106 ret = iwl_grab_nic_access(priv);
107 if (ret)
108 return ret;
109 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 105 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
110 txq->q.write_ptr | (txq_id << 8)); 106 txq->q.write_ptr | (txq_id << 8));
111 iwl_release_nic_access(priv);
112 107
113 /* else not in power-save mode, uCode will never sleep when we're 108 /* else not in power-save mode, uCode will never sleep when we're
114 * trying to tx (during RFKILL, we're not trying to tx). */ 109 * trying to tx (during RFKILL, we're not trying to tx). */
@@ -429,11 +424,6 @@ int iwl_txq_ctx_reset(struct iwl_priv *priv)
429 goto error_kw; 424 goto error_kw;
430 } 425 }
431 spin_lock_irqsave(&priv->lock, flags); 426 spin_lock_irqsave(&priv->lock, flags);
432 ret = iwl_grab_nic_access(priv);
433 if (unlikely(ret)) {
434 spin_unlock_irqrestore(&priv->lock, flags);
435 goto error_reset;
436 }
437 427
438 /* Turn off all Tx DMA fifos */ 428 /* Turn off all Tx DMA fifos */
439 priv->cfg->ops->lib->txq_set_sched(priv, 0); 429 priv->cfg->ops->lib->txq_set_sched(priv, 0);
@@ -441,7 +431,6 @@ int iwl_txq_ctx_reset(struct iwl_priv *priv)
441 /* Tell NIC where to find the "keep warm" buffer */ 431 /* Tell NIC where to find the "keep warm" buffer */
442 iwl_write_direct32(priv, FH_KW_MEM_ADDR_REG, priv->kw.dma >> 4); 432 iwl_write_direct32(priv, FH_KW_MEM_ADDR_REG, priv->kw.dma >> 4);
443 433
444 iwl_release_nic_access(priv);
445 spin_unlock_irqrestore(&priv->lock, flags); 434 spin_unlock_irqrestore(&priv->lock, flags);
446 435
447 /* Alloc and init all Tx queues, including the command queue (#4) */ 436 /* Alloc and init all Tx queues, including the command queue (#4) */
@@ -460,7 +449,6 @@ int iwl_txq_ctx_reset(struct iwl_priv *priv)
460 449
461 error: 450 error:
462 iwl_hw_txq_ctx_free(priv); 451 iwl_hw_txq_ctx_free(priv);
463 error_reset:
464 iwl_free_dma_ptr(priv, &priv->kw); 452 iwl_free_dma_ptr(priv, &priv->kw);
465 error_kw: 453 error_kw:
466 iwl_free_dma_ptr(priv, &priv->scd_bc_tbls); 454 iwl_free_dma_ptr(priv, &priv->scd_bc_tbls);
@@ -478,10 +466,6 @@ void iwl_txq_ctx_stop(struct iwl_priv *priv)
478 466
479 /* Turn off all Tx DMA fifos */ 467 /* Turn off all Tx DMA fifos */
480 spin_lock_irqsave(&priv->lock, flags); 468 spin_lock_irqsave(&priv->lock, flags);
481 if (iwl_grab_nic_access(priv)) {
482 spin_unlock_irqrestore(&priv->lock, flags);
483 return;
484 }
485 469
486 priv->cfg->ops->lib->txq_set_sched(priv, 0); 470 priv->cfg->ops->lib->txq_set_sched(priv, 0);
487 471
@@ -492,7 +476,6 @@ void iwl_txq_ctx_stop(struct iwl_priv *priv)
492 FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch), 476 FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch),
493 1000); 477 1000);
494 } 478 }
495 iwl_release_nic_access(priv);
496 spin_unlock_irqrestore(&priv->lock, flags); 479 spin_unlock_irqrestore(&priv->lock, flags);
497 480
498 /* Deallocate memory for all Tx queues */ 481 /* Deallocate memory for all Tx queues */
@@ -728,7 +711,7 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
728 711
729 /* drop all data frame if we are not associated */ 712 /* drop all data frame if we are not associated */
730 if (ieee80211_is_data(fc) && 713 if (ieee80211_is_data(fc) &&
731 (priv->iw_mode != NL80211_IFTYPE_MONITOR || 714 (!iwl_is_monitor_mode(priv) ||
732 !(info->flags & IEEE80211_TX_CTL_INJECTED)) && /* packet injection */ 715 !(info->flags & IEEE80211_TX_CTL_INJECTED)) && /* packet injection */
733 (!iwl_is_associated(priv) || 716 (!iwl_is_associated(priv) ||
734 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id) || 717 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id) ||
@@ -1183,8 +1166,10 @@ int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
1183 __func__, ra, tid); 1166 __func__, ra, tid);
1184 1167
1185 sta_id = iwl_find_station(priv, ra); 1168 sta_id = iwl_find_station(priv, ra);
1186 if (sta_id == IWL_INVALID_STATION) 1169 if (sta_id == IWL_INVALID_STATION) {
1170 IWL_ERR(priv, "Start AGG on invalid station\n");
1187 return -ENXIO; 1171 return -ENXIO;
1172 }
1188 1173
1189 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) { 1174 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
1190 IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n"); 1175 IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n");
@@ -1192,8 +1177,10 @@ int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
1192 } 1177 }
1193 1178
1194 txq_id = iwl_txq_ctx_activate_free(priv); 1179 txq_id = iwl_txq_ctx_activate_free(priv);
1195 if (txq_id == -1) 1180 if (txq_id == -1) {
1181 IWL_ERR(priv, "No free aggregation queue available\n");
1196 return -ENXIO; 1182 return -ENXIO;
1183 }
1197 1184
1198 spin_lock_irqsave(&priv->sta_lock, flags); 1185 spin_lock_irqsave(&priv->sta_lock, flags);
1199 tid_data = &priv->stations[sta_id].tid[tid]; 1186 tid_data = &priv->stations[sta_id].tid[tid];
@@ -1207,7 +1194,7 @@ int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
1207 return ret; 1194 return ret;
1208 1195
1209 if (tid_data->tfds_in_queue == 0) { 1196 if (tid_data->tfds_in_queue == 0) {
1210 IWL_ERR(priv, "HW queue is empty\n"); 1197 IWL_DEBUG_HT(priv, "HW queue is empty\n");
1211 tid_data->agg.state = IWL_AGG_ON; 1198 tid_data->agg.state = IWL_AGG_ON;
1212 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, ra, tid); 1199 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, ra, tid);
1213 } else { 1200 } else {
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index ff4d0e41d7c4..83d31606dd00 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -95,188 +95,6 @@ struct iwl_mod_params iwl3945_mod_params = {
95 /* the rest are 0 by default */ 95 /* the rest are 0 by default */
96}; 96};
97 97
98/*************** STATION TABLE MANAGEMENT ****
99 * mac80211 should be examined to determine if sta_info is duplicating
100 * the functionality provided here
101 */
102
103/**************************************************************/
104#if 0 /* temporary disable till we add real remove station */
105/**
106 * iwl3945_remove_station - Remove driver's knowledge of station.
107 *
108 * NOTE: This does not remove station from device's station table.
109 */
110static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
111{
112 int index = IWL_INVALID_STATION;
113 int i;
114 unsigned long flags;
115
116 spin_lock_irqsave(&priv->sta_lock, flags);
117
118 if (is_ap)
119 index = IWL_AP_ID;
120 else if (is_broadcast_ether_addr(addr))
121 index = priv->hw_params.bcast_sta_id;
122 else
123 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
124 if (priv->stations_39[i].used &&
125 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
126 addr)) {
127 index = i;
128 break;
129 }
130
131 if (unlikely(index == IWL_INVALID_STATION))
132 goto out;
133
134 if (priv->stations_39[index].used) {
135 priv->stations_39[index].used = 0;
136 priv->num_stations--;
137 }
138
139 BUG_ON(priv->num_stations < 0);
140
141out:
142 spin_unlock_irqrestore(&priv->sta_lock, flags);
143 return 0;
144}
145#endif
146
147/**
148 * iwl3945_clear_stations_table - Clear the driver's station table
149 *
150 * NOTE: This does not clear or otherwise alter the device's station table.
151 */
152static void iwl3945_clear_stations_table(struct iwl_priv *priv)
153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&priv->sta_lock, flags);
157
158 priv->num_stations = 0;
159 memset(priv->stations_39, 0, sizeof(priv->stations_39));
160
161 spin_unlock_irqrestore(&priv->sta_lock, flags);
162}
163
164/**
165 * iwl3945_add_station - Add station to station tables in driver and device
166 */
167u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
168{
169 int i;
170 int index = IWL_INVALID_STATION;
171 struct iwl3945_station_entry *station;
172 unsigned long flags_spin;
173 u8 rate;
174
175 spin_lock_irqsave(&priv->sta_lock, flags_spin);
176 if (is_ap)
177 index = IWL_AP_ID;
178 else if (is_broadcast_ether_addr(addr))
179 index = priv->hw_params.bcast_sta_id;
180 else
181 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
182 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
183 addr)) {
184 index = i;
185 break;
186 }
187
188 if (!priv->stations_39[i].used &&
189 index == IWL_INVALID_STATION)
190 index = i;
191 }
192
193 /* These two conditions has the same outcome but keep them separate
194 since they have different meaning */
195 if (unlikely(index == IWL_INVALID_STATION)) {
196 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
197 return index;
198 }
199
200 if (priv->stations_39[index].used &&
201 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
202 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
203 return index;
204 }
205
206 IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr);
207 station = &priv->stations_39[index];
208 station->used = 1;
209 priv->num_stations++;
210
211 /* Set up the REPLY_ADD_STA command to send to device */
212 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
213 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
214 station->sta.mode = 0;
215 station->sta.sta.sta_id = index;
216 station->sta.station_flags = 0;
217
218 if (priv->band == IEEE80211_BAND_5GHZ)
219 rate = IWL_RATE_6M_PLCP;
220 else
221 rate = IWL_RATE_1M_PLCP;
222
223 /* Turn on both antennas for the station... */
224 station->sta.rate_n_flags =
225 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
226
227 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
228
229 /* Add station to device's station table */
230 iwl_send_add_sta(priv,
231 (struct iwl_addsta_cmd *)&station->sta, flags);
232 return index;
233
234}
235
236static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
237{
238 int rc = 0;
239 struct iwl_rx_packet *res = NULL;
240 struct iwl3945_rxon_assoc_cmd rxon_assoc;
241 struct iwl_host_cmd cmd = {
242 .id = REPLY_RXON_ASSOC,
243 .len = sizeof(rxon_assoc),
244 .meta.flags = CMD_WANT_SKB,
245 .data = &rxon_assoc,
246 };
247 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
248 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
249
250 if ((rxon1->flags == rxon2->flags) &&
251 (rxon1->filter_flags == rxon2->filter_flags) &&
252 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
253 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
254 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
255 return 0;
256 }
257
258 rxon_assoc.flags = priv->staging_rxon.flags;
259 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
260 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
261 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
262 rxon_assoc.reserved = 0;
263
264 rc = iwl_send_cmd_sync(priv, &cmd);
265 if (rc)
266 return rc;
267
268 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
269 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
270 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
271 rc = -EIO;
272 }
273
274 priv->alloc_rxb_skb--;
275 dev_kfree_skb_any(cmd.meta.u.skb);
276
277 return rc;
278}
279
280/** 98/**
281 * iwl3945_get_antenna_flags - Get antenna flags for RXON command 99 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
282 * @priv: eeprom and antenna fields are used to determine antenna flags 100 * @priv: eeprom and antenna fields are used to determine antenna flags
@@ -314,150 +132,6 @@ __le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
314 return 0; /* "diversity" is default if error */ 132 return 0; /* "diversity" is default if error */
315} 133}
316 134
317/**
318 * iwl3945_commit_rxon - commit staging_rxon to hardware
319 *
320 * The RXON command in staging_rxon is committed to the hardware and
321 * the active_rxon structure is updated with the new data. This
322 * function correctly transitions out of the RXON_ASSOC_MSK state if
323 * a HW tune is required based on the RXON structure changes.
324 */
325static int iwl3945_commit_rxon(struct iwl_priv *priv)
326{
327 /* cast away the const for active_rxon in this function */
328 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
329 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
330 int rc = 0;
331 bool new_assoc =
332 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
333
334 if (!iwl_is_alive(priv))
335 return -1;
336
337 /* always get timestamp with Rx frame */
338 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
339
340 /* select antenna */
341 staging_rxon->flags &=
342 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
343 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
344
345 rc = iwl_check_rxon_cmd(priv);
346 if (rc) {
347 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
348 return -EINVAL;
349 }
350
351 /* If we don't need to send a full RXON, we can use
352 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
353 * and other flags for the current radio configuration. */
354 if (!iwl_full_rxon_required(priv)) {
355 rc = iwl3945_send_rxon_assoc(priv);
356 if (rc) {
357 IWL_ERR(priv, "Error setting RXON_ASSOC "
358 "configuration (%d).\n", rc);
359 return rc;
360 }
361
362 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
363
364 return 0;
365 }
366
367 /* If we are currently associated and the new config requires
368 * an RXON_ASSOC and the new config wants the associated mask enabled,
369 * we must clear the associated from the active configuration
370 * before we apply the new config */
371 if (iwl_is_associated(priv) && new_assoc) {
372 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
373 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
374
375 /*
376 * reserved4 and 5 could have been filled by the iwlcore code.
377 * Let's clear them before pushing to the 3945.
378 */
379 active_rxon->reserved4 = 0;
380 active_rxon->reserved5 = 0;
381 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
382 sizeof(struct iwl3945_rxon_cmd),
383 &priv->active_rxon);
384
385 /* If the mask clearing failed then we set
386 * active_rxon back to what it was previously */
387 if (rc) {
388 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
389 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
390 "configuration (%d).\n", rc);
391 return rc;
392 }
393 }
394
395 IWL_DEBUG_INFO(priv, "Sending RXON\n"
396 "* with%s RXON_FILTER_ASSOC_MSK\n"
397 "* channel = %d\n"
398 "* bssid = %pM\n",
399 (new_assoc ? "" : "out"),
400 le16_to_cpu(staging_rxon->channel),
401 staging_rxon->bssid_addr);
402
403 /*
404 * reserved4 and 5 could have been filled by the iwlcore code.
405 * Let's clear them before pushing to the 3945.
406 */
407 staging_rxon->reserved4 = 0;
408 staging_rxon->reserved5 = 0;
409
410 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
411
412 /* Apply the new configuration */
413 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
414 sizeof(struct iwl3945_rxon_cmd),
415 staging_rxon);
416 if (rc) {
417 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
418 return rc;
419 }
420
421 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
422
423 iwl3945_clear_stations_table(priv);
424
425 /* If we issue a new RXON command which required a tune then we must
426 * send a new TXPOWER command or we won't be able to Tx any frames */
427 rc = priv->cfg->ops->lib->send_tx_power(priv);
428 if (rc) {
429 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
430 return rc;
431 }
432
433 /* Add the broadcast address so we can send broadcast frames */
434 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
435 IWL_INVALID_STATION) {
436 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
437 return -EIO;
438 }
439
440 /* If we have set the ASSOC_MSK and we are in BSS mode then
441 * add the IWL_AP_ID to the station rate table */
442 if (iwl_is_associated(priv) &&
443 (priv->iw_mode == NL80211_IFTYPE_STATION))
444 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
445 1, 0)
446 == IWL_INVALID_STATION) {
447 IWL_ERR(priv, "Error adding AP address for transmit\n");
448 return -EIO;
449 }
450
451 /* Init the hardware's rate fallback order based on the band */
452 rc = iwl3945_init_hw_rate_table(priv);
453 if (rc) {
454 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
455 return -EIO;
456 }
457
458 return 0;
459}
460
461static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv, 135static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
462 struct ieee80211_key_conf *keyconf, 136 struct ieee80211_key_conf *keyconf,
463 u8 sta_id) 137 u8 sta_id)
@@ -477,32 +151,31 @@ static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
477 key_flags &= ~STA_KEY_FLG_INVALID; 151 key_flags &= ~STA_KEY_FLG_INVALID;
478 152
479 spin_lock_irqsave(&priv->sta_lock, flags); 153 spin_lock_irqsave(&priv->sta_lock, flags);
480 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg; 154 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
481 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen; 155 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
482 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key, 156 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
483 keyconf->keylen); 157 keyconf->keylen);
484 158
485 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key, 159 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
486 keyconf->keylen); 160 keyconf->keylen);
487 161
488 if ((priv->stations_39[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) 162 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
489 == STA_KEY_FLG_NO_ENC) 163 == STA_KEY_FLG_NO_ENC)
490 priv->stations_39[sta_id].sta.key.key_offset = 164 priv->stations[sta_id].sta.key.key_offset =
491 iwl_get_free_ucode_key_index(priv); 165 iwl_get_free_ucode_key_index(priv);
492 /* else, we are overriding an existing key => no need to allocated room 166 /* else, we are overriding an existing key => no need to allocated room
493 * in uCode. */ 167 * in uCode. */
494 168
495 WARN(priv->stations_39[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, 169 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
496 "no space for a new key"); 170 "no space for a new key");
497 171
498 priv->stations_39[sta_id].sta.key.key_flags = key_flags; 172 priv->stations[sta_id].sta.key.key_flags = key_flags;
499 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 173 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
500 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 174 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
501 175
502 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n"); 176 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
503 177
504 ret = iwl_send_add_sta(priv, 178 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
505 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, CMD_ASYNC);
506 179
507 spin_unlock_irqrestore(&priv->sta_lock, flags); 180 spin_unlock_irqrestore(&priv->sta_lock, flags);
508 181
@@ -528,17 +201,16 @@ static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
528 unsigned long flags; 201 unsigned long flags;
529 202
530 spin_lock_irqsave(&priv->sta_lock, flags); 203 spin_lock_irqsave(&priv->sta_lock, flags);
531 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key)); 204 memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key));
532 memset(&priv->stations_39[sta_id].sta.key, 0, 205 memset(&priv->stations[sta_id].sta.key, 0,
533 sizeof(struct iwl4965_keyinfo)); 206 sizeof(struct iwl4965_keyinfo));
534 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; 207 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
535 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 208 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
536 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 209 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
537 spin_unlock_irqrestore(&priv->sta_lock, flags); 210 spin_unlock_irqrestore(&priv->sta_lock, flags);
538 211
539 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n"); 212 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
540 iwl_send_add_sta(priv, 213 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, 0);
541 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
542 return 0; 214 return 0;
543} 215}
544 216
@@ -739,7 +411,8 @@ static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
739 priv->rxon_timing.atim_window = 0; 411 priv->rxon_timing.atim_window = 0;
740 } else { 412 } else {
741 priv->rxon_timing.beacon_interval = 413 priv->rxon_timing.beacon_interval =
742 iwl3945_adjust_beacon_interval(conf->beacon_int); 414 iwl3945_adjust_beacon_interval(
415 priv->vif->bss_conf.beacon_int);
743 /* TODO: we need to get atim_window from upper stack 416 /* TODO: we need to get atim_window from upper stack
744 * for now we set to 0 */ 417 * for now we set to 0 */
745 priv->rxon_timing.atim_window = 0; 418 priv->rxon_timing.atim_window = 0;
@@ -758,35 +431,6 @@ static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
758 le16_to_cpu(priv->rxon_timing.atim_window)); 431 le16_to_cpu(priv->rxon_timing.atim_window));
759} 432}
760 433
761static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
762{
763 if (mode == NL80211_IFTYPE_ADHOC) {
764 const struct iwl_channel_info *ch_info;
765
766 ch_info = iwl_get_channel_info(priv,
767 priv->band,
768 le16_to_cpu(priv->staging_rxon.channel));
769
770 if (!ch_info || !is_channel_ibss(ch_info)) {
771 IWL_ERR(priv, "channel %d not IBSS channel\n",
772 le16_to_cpu(priv->staging_rxon.channel));
773 return -EINVAL;
774 }
775 }
776
777 iwl_connection_init_rx_config(priv, mode);
778
779 iwl3945_clear_stations_table(priv);
780
781 /* don't commit rxon if rf-kill is on*/
782 if (!iwl_is_ready_rf(priv))
783 return -EAGAIN;
784
785 iwl3945_commit_rxon(priv);
786
787 return 0;
788}
789
790static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv, 434static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
791 struct ieee80211_tx_info *info, 435 struct ieee80211_tx_info *info,
792 struct iwl_cmd *cmd, 436 struct iwl_cmd *cmd,
@@ -794,8 +438,7 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
794 int sta_id) 438 int sta_id)
795{ 439{
796 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload; 440 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
797 struct iwl3945_hw_key *keyinfo = 441 struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
798 &priv->stations_39[sta_id].keyinfo;
799 442
800 switch (keyinfo->alg) { 443 switch (keyinfo->alg) {
801 case ALG_CCMP: 444 case ALG_CCMP:
@@ -893,64 +536,6 @@ static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
893 tx->next_frame_len = 0; 536 tx->next_frame_len = 0;
894} 537}
895 538
896/**
897 * iwl3945_get_sta_id - Find station's index within station table
898 */
899static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
900{
901 int sta_id;
902 u16 fc = le16_to_cpu(hdr->frame_control);
903
904 /* If this frame is broadcast or management, use broadcast station id */
905 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
906 is_multicast_ether_addr(hdr->addr1))
907 return priv->hw_params.bcast_sta_id;
908
909 switch (priv->iw_mode) {
910
911 /* If we are a client station in a BSS network, use the special
912 * AP station entry (that's the only station we communicate with) */
913 case NL80211_IFTYPE_STATION:
914 return IWL_AP_ID;
915
916 /* If we are an AP, then find the station, or use BCAST */
917 case NL80211_IFTYPE_AP:
918 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
919 if (sta_id != IWL_INVALID_STATION)
920 return sta_id;
921 return priv->hw_params.bcast_sta_id;
922
923 /* If this frame is going out to an IBSS network, find the station,
924 * or create a new station table entry */
925 case NL80211_IFTYPE_ADHOC: {
926 /* Create new station table entry */
927 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
928 if (sta_id != IWL_INVALID_STATION)
929 return sta_id;
930
931 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
932
933 if (sta_id != IWL_INVALID_STATION)
934 return sta_id;
935
936 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
937 "Defaulting to broadcast...\n",
938 hdr->addr1);
939 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
940 return priv->hw_params.bcast_sta_id;
941 }
942 /* If we are in monitor mode, use BCAST. This is required for
943 * packet injection. */
944 case NL80211_IFTYPE_MONITOR:
945 return priv->hw_params.bcast_sta_id;
946
947 default:
948 IWL_WARN(priv, "Unknown mode of operation: %d\n",
949 priv->iw_mode);
950 return priv->hw_params.bcast_sta_id;
951 }
952}
953
954/* 539/*
955 * start REPLY_TX command process 540 * start REPLY_TX command process
956 */ 541 */
@@ -1004,7 +589,7 @@ static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
1004 589
1005 /* drop all data frame if we are not associated */ 590 /* drop all data frame if we are not associated */
1006 if (ieee80211_is_data(fc) && 591 if (ieee80211_is_data(fc) &&
1007 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */ 592 (!iwl_is_monitor_mode(priv)) && /* packet injection */
1008 (!iwl_is_associated(priv) || 593 (!iwl_is_associated(priv) ||
1009 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) { 594 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
1010 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n"); 595 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
@@ -1016,7 +601,7 @@ static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
1016 hdr_len = ieee80211_hdrlen(fc); 601 hdr_len = ieee80211_hdrlen(fc);
1017 602
1018 /* Find (or create) index into station table for destination station */ 603 /* Find (or create) index into station table for destination station */
1019 sta_id = iwl3945_get_sta_id(priv, hdr); 604 sta_id = iwl_get_sta_id(priv, hdr);
1020 if (sta_id == IWL_INVALID_STATION) { 605 if (sta_id == IWL_INVALID_STATION) {
1021 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n", 606 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
1022 hdr->addr1); 607 hdr->addr1);
@@ -1028,7 +613,7 @@ static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
1028 if (ieee80211_is_data_qos(fc)) { 613 if (ieee80211_is_data_qos(fc)) {
1029 qc = ieee80211_get_qos_ctl(hdr); 614 qc = ieee80211_get_qos_ctl(hdr);
1030 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; 615 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1031 seq_number = priv->stations_39[sta_id].tid[tid].seq_number & 616 seq_number = priv->stations[sta_id].tid[tid].seq_number &
1032 IEEE80211_SCTL_SEQ; 617 IEEE80211_SCTL_SEQ;
1033 hdr->seq_ctrl = cpu_to_le16(seq_number) | 618 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1034 (hdr->seq_ctrl & 619 (hdr->seq_ctrl &
@@ -1088,7 +673,7 @@ static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
1088 if (!ieee80211_has_morefrags(hdr->frame_control)) { 673 if (!ieee80211_has_morefrags(hdr->frame_control)) {
1089 txq->need_update = 1; 674 txq->need_update = 1;
1090 if (qc) 675 if (qc)
1091 priv->stations_39[sta_id].tid[tid].seq_number = seq_number; 676 priv->stations[sta_id].tid[tid].seq_number = seq_number;
1092 } else { 677 } else {
1093 wait_write_ptr = 1; 678 wait_write_ptr = 1;
1094 txq->need_update = 0; 679 txq->need_update = 0;
@@ -1424,18 +1009,12 @@ static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
1424 clear_bit(STATUS_RF_KILL_HW, &priv->status); 1009 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1425 1010
1426 1011
1427 if (flags & SW_CARD_DISABLED)
1428 set_bit(STATUS_RF_KILL_SW, &priv->status);
1429 else
1430 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1431
1432 iwl_scan_cancel(priv); 1012 iwl_scan_cancel(priv);
1433 1013
1434 if ((test_bit(STATUS_RF_KILL_HW, &status) != 1014 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1435 test_bit(STATUS_RF_KILL_HW, &priv->status)) || 1015 test_bit(STATUS_RF_KILL_HW, &priv->status)))
1436 (test_bit(STATUS_RF_KILL_SW, &status) != 1016 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
1437 test_bit(STATUS_RF_KILL_SW, &priv->status))) 1017 test_bit(STATUS_RF_KILL_HW, &priv->status));
1438 queue_work(priv->workqueue, &priv->rf_kill);
1439 else 1018 else
1440 wake_up_interruptible(&priv->wait_command_queue); 1019 wake_up_interruptible(&priv->wait_command_queue);
1441} 1020}
@@ -1591,7 +1170,7 @@ static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
1591 1170
1592 /* If we've added more space for the firmware to place data, tell it. 1171 /* If we've added more space for the firmware to place data, tell it.
1593 * Increment device's write pointer in multiples of 8. */ 1172 * Increment device's write pointer in multiples of 8. */
1594 if ((write != (rxq->write & ~0x7)) 1173 if ((rxq->write_actual != (rxq->write & ~0x7))
1595 || (abs(rxq->write - rxq->read) > 7)) { 1174 || (abs(rxq->write - rxq->read) > 7)) {
1596 spin_lock_irqsave(&rxq->lock, flags); 1175 spin_lock_irqsave(&rxq->lock, flags);
1597 rxq->need_update = 1; 1176 rxq->need_update = 1;
@@ -1612,21 +1191,30 @@ static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
1612 * Also restock the Rx queue via iwl3945_rx_queue_restock. 1191 * Also restock the Rx queue via iwl3945_rx_queue_restock.
1613 * This is called as a scheduled work item (except for during initialization) 1192 * This is called as a scheduled work item (except for during initialization)
1614 */ 1193 */
1615static void iwl3945_rx_allocate(struct iwl_priv *priv) 1194static void iwl3945_rx_allocate(struct iwl_priv *priv, gfp_t priority)
1616{ 1195{
1617 struct iwl_rx_queue *rxq = &priv->rxq; 1196 struct iwl_rx_queue *rxq = &priv->rxq;
1618 struct list_head *element; 1197 struct list_head *element;
1619 struct iwl_rx_mem_buffer *rxb; 1198 struct iwl_rx_mem_buffer *rxb;
1620 unsigned long flags; 1199 unsigned long flags;
1621 spin_lock_irqsave(&rxq->lock, flags); 1200
1622 while (!list_empty(&rxq->rx_used)) { 1201 while (1) {
1202 spin_lock_irqsave(&rxq->lock, flags);
1203
1204 if (list_empty(&rxq->rx_used)) {
1205 spin_unlock_irqrestore(&rxq->lock, flags);
1206 return;
1207 }
1208
1623 element = rxq->rx_used.next; 1209 element = rxq->rx_used.next;
1624 rxb = list_entry(element, struct iwl_rx_mem_buffer, list); 1210 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
1211 list_del(element);
1212 spin_unlock_irqrestore(&rxq->lock, flags);
1625 1213
1626 /* Alloc a new receive buffer */ 1214 /* Alloc a new receive buffer */
1627 rxb->skb = 1215 rxb->skb =
1628 alloc_skb(priv->hw_params.rx_buf_size, 1216 alloc_skb(priv->hw_params.rx_buf_size,
1629 __GFP_NOWARN | GFP_ATOMIC); 1217 priority);
1630 if (!rxb->skb) { 1218 if (!rxb->skb) {
1631 if (net_ratelimit()) 1219 if (net_ratelimit())
1632 IWL_CRIT(priv, ": Can not allocate SKB buffers\n"); 1220 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
@@ -1644,18 +1232,18 @@ static void iwl3945_rx_allocate(struct iwl_priv *priv)
1644 */ 1232 */
1645 skb_reserve(rxb->skb, 4); 1233 skb_reserve(rxb->skb, 4);
1646 1234
1647 priv->alloc_rxb_skb++;
1648 list_del(element);
1649
1650 /* Get physical address of RB/SKB */ 1235 /* Get physical address of RB/SKB */
1651 rxb->real_dma_addr = pci_map_single(priv->pci_dev, 1236 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1652 rxb->skb->data, 1237 rxb->skb->data,
1653 priv->hw_params.rx_buf_size, 1238 priv->hw_params.rx_buf_size,
1654 PCI_DMA_FROMDEVICE); 1239 PCI_DMA_FROMDEVICE);
1240
1241 spin_lock_irqsave(&rxq->lock, flags);
1655 list_add_tail(&rxb->list, &rxq->rx_free); 1242 list_add_tail(&rxb->list, &rxq->rx_free);
1243 priv->alloc_rxb_skb++;
1656 rxq->free_count++; 1244 rxq->free_count++;
1245 spin_unlock_irqrestore(&rxq->lock, flags);
1657 } 1246 }
1658 spin_unlock_irqrestore(&rxq->lock, flags);
1659} 1247}
1660 1248
1661void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq) 1249void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
@@ -1685,33 +1273,30 @@ void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1685 * not restocked the Rx queue with fresh buffers */ 1273 * not restocked the Rx queue with fresh buffers */
1686 rxq->read = rxq->write = 0; 1274 rxq->read = rxq->write = 0;
1687 rxq->free_count = 0; 1275 rxq->free_count = 0;
1276 rxq->write_actual = 0;
1688 spin_unlock_irqrestore(&rxq->lock, flags); 1277 spin_unlock_irqrestore(&rxq->lock, flags);
1689} 1278}
1690 1279
1691/*
1692 * this should be called while priv->lock is locked
1693 */
1694static void __iwl3945_rx_replenish(void *data)
1695{
1696 struct iwl_priv *priv = data;
1697
1698 iwl3945_rx_allocate(priv);
1699 iwl3945_rx_queue_restock(priv);
1700}
1701
1702
1703void iwl3945_rx_replenish(void *data) 1280void iwl3945_rx_replenish(void *data)
1704{ 1281{
1705 struct iwl_priv *priv = data; 1282 struct iwl_priv *priv = data;
1706 unsigned long flags; 1283 unsigned long flags;
1707 1284
1708 iwl3945_rx_allocate(priv); 1285 iwl3945_rx_allocate(priv, GFP_KERNEL);
1709 1286
1710 spin_lock_irqsave(&priv->lock, flags); 1287 spin_lock_irqsave(&priv->lock, flags);
1711 iwl3945_rx_queue_restock(priv); 1288 iwl3945_rx_queue_restock(priv);
1712 spin_unlock_irqrestore(&priv->lock, flags); 1289 spin_unlock_irqrestore(&priv->lock, flags);
1713} 1290}
1714 1291
1292static void iwl3945_rx_replenish_now(struct iwl_priv *priv)
1293{
1294 iwl3945_rx_allocate(priv, GFP_ATOMIC);
1295
1296 iwl3945_rx_queue_restock(priv);
1297}
1298
1299
1715/* Assumes that the skb field of the buffers in 'pool' is kept accurate. 1300/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
1716 * If an SKB has been detached, the POOL needs to have its SKB set to NULL 1301 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
1717 * This free routine walks the list of POOL entries and if SKB is set to 1302 * This free routine walks the list of POOL entries and if SKB is set to
@@ -1834,13 +1419,19 @@ static void iwl3945_rx_handle(struct iwl_priv *priv)
1834 unsigned long flags; 1419 unsigned long flags;
1835 u8 fill_rx = 0; 1420 u8 fill_rx = 0;
1836 u32 count = 8; 1421 u32 count = 8;
1422 int total_empty = 0;
1837 1423
1838 /* uCode's read index (stored in shared DRAM) indicates the last Rx 1424 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1839 * buffer that the driver may process (last buffer filled by ucode). */ 1425 * buffer that the driver may process (last buffer filled by ucode). */
1840 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF; 1426 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
1841 i = rxq->read; 1427 i = rxq->read;
1842 1428
1843 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) 1429 /* calculate total frames need to be restock after handling RX */
1430 total_empty = r - priv->rxq.write_actual;
1431 if (total_empty < 0)
1432 total_empty += RX_QUEUE_SIZE;
1433
1434 if (total_empty > (RX_QUEUE_SIZE / 2))
1844 fill_rx = 1; 1435 fill_rx = 1;
1845 /* Rx interrupt, but nothing sent from uCode */ 1436 /* Rx interrupt, but nothing sent from uCode */
1846 if (i == r) 1437 if (i == r)
@@ -1879,6 +1470,7 @@ static void iwl3945_rx_handle(struct iwl_priv *priv)
1879 "r = %d, i = %d, %s, 0x%02x\n", r, i, 1470 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1880 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); 1471 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1881 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); 1472 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1473 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
1882 } else { 1474 } else {
1883 /* No handling needed */ 1475 /* No handling needed */
1884 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, 1476 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
@@ -1916,7 +1508,7 @@ static void iwl3945_rx_handle(struct iwl_priv *priv)
1916 count++; 1508 count++;
1917 if (count >= 8) { 1509 if (count >= 8) {
1918 priv->rxq.read = i; 1510 priv->rxq.read = i;
1919 __iwl3945_rx_replenish(priv); 1511 iwl3945_rx_replenish_now(priv);
1920 count = 0; 1512 count = 0;
1921 } 1513 }
1922 } 1514 }
@@ -1924,7 +1516,10 @@ static void iwl3945_rx_handle(struct iwl_priv *priv)
1924 1516
1925 /* Backtrack one entry */ 1517 /* Backtrack one entry */
1926 priv->rxq.read = i; 1518 priv->rxq.read = i;
1927 iwl3945_rx_queue_restock(priv); 1519 if (fill_rx)
1520 iwl3945_rx_replenish_now(priv);
1521 else
1522 iwl3945_rx_queue_restock(priv);
1928} 1523}
1929 1524
1930/* call this function to flush any scheduled tasklet */ 1525/* call this function to flush any scheduled tasklet */
@@ -1963,7 +1558,6 @@ static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
1963 u32 i; 1558 u32 i;
1964 u32 desc, time, count, base, data1; 1559 u32 desc, time, count, base, data1;
1965 u32 blink1, blink2, ilink1, ilink2; 1560 u32 blink1, blink2, ilink1, ilink2;
1966 int rc;
1967 1561
1968 base = le32_to_cpu(priv->card_alive.error_event_table_ptr); 1562 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1969 1563
@@ -1972,11 +1566,6 @@ static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
1972 return; 1566 return;
1973 } 1567 }
1974 1568
1975 rc = iwl_grab_nic_access(priv);
1976 if (rc) {
1977 IWL_WARN(priv, "Can not read from adapter at this time.\n");
1978 return;
1979 }
1980 1569
1981 count = iwl_read_targ_mem(priv, base); 1570 count = iwl_read_targ_mem(priv, base);
1982 1571
@@ -2011,8 +1600,6 @@ static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
2011 ilink1, ilink2, data1); 1600 ilink1, ilink2, data1);
2012 } 1601 }
2013 1602
2014 iwl_release_nic_access(priv);
2015
2016} 1603}
2017 1604
2018#define EVENT_START_OFFSET (6 * sizeof(u32)) 1605#define EVENT_START_OFFSET (6 * sizeof(u32))
@@ -2020,7 +1607,6 @@ static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
2020/** 1607/**
2021 * iwl3945_print_event_log - Dump error event log to syslog 1608 * iwl3945_print_event_log - Dump error event log to syslog
2022 * 1609 *
2023 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
2024 */ 1610 */
2025static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx, 1611static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
2026 u32 num_events, u32 mode) 1612 u32 num_events, u32 mode)
@@ -2063,7 +1649,6 @@ static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
2063 1649
2064static void iwl3945_dump_nic_event_log(struct iwl_priv *priv) 1650static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
2065{ 1651{
2066 int rc;
2067 u32 base; /* SRAM byte address of event log header */ 1652 u32 base; /* SRAM byte address of event log header */
2068 u32 capacity; /* event log capacity in # entries */ 1653 u32 capacity; /* event log capacity in # entries */
2069 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ 1654 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
@@ -2077,12 +1662,6 @@ static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
2077 return; 1662 return;
2078 } 1663 }
2079 1664
2080 rc = iwl_grab_nic_access(priv);
2081 if (rc) {
2082 IWL_WARN(priv, "Can not read from adapter at this time.\n");
2083 return;
2084 }
2085
2086 /* event log header */ 1665 /* event log header */
2087 capacity = iwl_read_targ_mem(priv, base); 1666 capacity = iwl_read_targ_mem(priv, base);
2088 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); 1667 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
@@ -2094,7 +1673,6 @@ static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
2094 /* bail out if nothing in log */ 1673 /* bail out if nothing in log */
2095 if (size == 0) { 1674 if (size == 0) {
2096 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n"); 1675 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
2097 iwl_release_nic_access(priv);
2098 return; 1676 return;
2099 } 1677 }
2100 1678
@@ -2110,24 +1688,6 @@ static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
2110 /* (then/else) start at top of log */ 1688 /* (then/else) start at top of log */
2111 iwl3945_print_event_log(priv, 0, next_entry, mode); 1689 iwl3945_print_event_log(priv, 0, next_entry, mode);
2112 1690
2113 iwl_release_nic_access(priv);
2114}
2115
2116static void iwl3945_error_recovery(struct iwl_priv *priv)
2117{
2118 unsigned long flags;
2119
2120 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2121 sizeof(priv->staging_rxon));
2122 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2123 iwl3945_commit_rxon(priv);
2124
2125 iwl3945_add_station(priv, priv->bssid, 1, 0);
2126
2127 spin_lock_irqsave(&priv->lock, flags);
2128 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
2129 priv->error_recovering = 0;
2130 spin_unlock_irqrestore(&priv->lock, flags);
2131} 1691}
2132 1692
2133static void iwl3945_irq_tasklet(struct iwl_priv *priv) 1693static void iwl3945_irq_tasklet(struct iwl_priv *priv)
@@ -2178,6 +1738,7 @@ static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2178 /* Tell the device to stop sending interrupts */ 1738 /* Tell the device to stop sending interrupts */
2179 iwl_disable_interrupts(priv); 1739 iwl_disable_interrupts(priv);
2180 1740
1741 priv->isr_stats.hw++;
2181 iwl_irq_handle_error(priv); 1742 iwl_irq_handle_error(priv);
2182 1743
2183 handled |= CSR_INT_BIT_HW_ERR; 1744 handled |= CSR_INT_BIT_HW_ERR;
@@ -2190,13 +1751,17 @@ static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2190#ifdef CONFIG_IWLWIFI_DEBUG 1751#ifdef CONFIG_IWLWIFI_DEBUG
2191 if (priv->debug_level & (IWL_DL_ISR)) { 1752 if (priv->debug_level & (IWL_DL_ISR)) {
2192 /* NIC fires this, but we don't use it, redundant with WAKEUP */ 1753 /* NIC fires this, but we don't use it, redundant with WAKEUP */
2193 if (inta & CSR_INT_BIT_SCD) 1754 if (inta & CSR_INT_BIT_SCD) {
2194 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit " 1755 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
2195 "the frame/frames.\n"); 1756 "the frame/frames.\n");
1757 priv->isr_stats.sch++;
1758 }
2196 1759
2197 /* Alive notification via Rx interrupt will do the real work */ 1760 /* Alive notification via Rx interrupt will do the real work */
2198 if (inta & CSR_INT_BIT_ALIVE) 1761 if (inta & CSR_INT_BIT_ALIVE) {
2199 IWL_DEBUG_ISR(priv, "Alive interrupt\n"); 1762 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
1763 priv->isr_stats.alive++;
1764 }
2200 } 1765 }
2201#endif 1766#endif
2202 /* Safely ignore these bits for debug checks below */ 1767 /* Safely ignore these bits for debug checks below */
@@ -2206,6 +1771,8 @@ static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2206 if (inta & CSR_INT_BIT_SW_ERR) { 1771 if (inta & CSR_INT_BIT_SW_ERR) {
2207 IWL_ERR(priv, "Microcode SW error detected. " 1772 IWL_ERR(priv, "Microcode SW error detected. "
2208 "Restarting 0x%X.\n", inta); 1773 "Restarting 0x%X.\n", inta);
1774 priv->isr_stats.sw++;
1775 priv->isr_stats.sw_err = inta;
2209 iwl_irq_handle_error(priv); 1776 iwl_irq_handle_error(priv);
2210 handled |= CSR_INT_BIT_SW_ERR; 1777 handled |= CSR_INT_BIT_SW_ERR;
2211 } 1778 }
@@ -2221,6 +1788,7 @@ static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2221 iwl_txq_update_write_ptr(priv, &priv->txq[4]); 1788 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2222 iwl_txq_update_write_ptr(priv, &priv->txq[5]); 1789 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
2223 1790
1791 priv->isr_stats.wakeup++;
2224 handled |= CSR_INT_BIT_WAKEUP; 1792 handled |= CSR_INT_BIT_WAKEUP;
2225 } 1793 }
2226 1794
@@ -2229,27 +1797,28 @@ static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2229 * notifications from uCode come through here*/ 1797 * notifications from uCode come through here*/
2230 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { 1798 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
2231 iwl3945_rx_handle(priv); 1799 iwl3945_rx_handle(priv);
1800 priv->isr_stats.rx++;
2232 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); 1801 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2233 } 1802 }
2234 1803
2235 if (inta & CSR_INT_BIT_FH_TX) { 1804 if (inta & CSR_INT_BIT_FH_TX) {
2236 IWL_DEBUG_ISR(priv, "Tx interrupt\n"); 1805 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
1806 priv->isr_stats.tx++;
2237 1807
2238 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); 1808 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2239 if (!iwl_grab_nic_access(priv)) { 1809 iwl_write_direct32(priv, FH39_TCSR_CREDIT
2240 iwl_write_direct32(priv, FH39_TCSR_CREDIT 1810 (FH39_SRVC_CHNL), 0x0);
2241 (FH39_SRVC_CHNL), 0x0);
2242 iwl_release_nic_access(priv);
2243 }
2244 handled |= CSR_INT_BIT_FH_TX; 1811 handled |= CSR_INT_BIT_FH_TX;
2245 } 1812 }
2246 1813
2247 if (inta & ~handled) 1814 if (inta & ~handled) {
2248 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); 1815 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1816 priv->isr_stats.unhandled++;
1817 }
2249 1818
2250 if (inta & ~CSR_INI_SET_MASK) { 1819 if (inta & ~priv->inta_mask) {
2251 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", 1820 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
2252 inta & ~CSR_INI_SET_MASK); 1821 inta & ~priv->inta_mask);
2253 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh); 1822 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
2254 } 1823 }
2255 1824
@@ -2413,10 +1982,6 @@ static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 le
2413 1982
2414 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len); 1983 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
2415 1984
2416 rc = iwl_grab_nic_access(priv);
2417 if (rc)
2418 return rc;
2419
2420 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, 1985 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
2421 IWL39_RTC_INST_LOWER_BOUND); 1986 IWL39_RTC_INST_LOWER_BOUND);
2422 1987
@@ -2437,7 +2002,6 @@ static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 le
2437 } 2002 }
2438 } 2003 }
2439 2004
2440 iwl_release_nic_access(priv);
2441 2005
2442 if (!errcnt) 2006 if (!errcnt)
2443 IWL_DEBUG_INFO(priv, 2007 IWL_DEBUG_INFO(priv,
@@ -2461,10 +2025,6 @@ static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32
2461 2025
2462 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len); 2026 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
2463 2027
2464 rc = iwl_grab_nic_access(priv);
2465 if (rc)
2466 return rc;
2467
2468 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { 2028 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2469 /* read data comes through single port, auto-incr addr */ 2029 /* read data comes through single port, auto-incr addr */
2470 /* NOTE: Use the debugless read so we don't flood kernel log 2030 /* NOTE: Use the debugless read so we don't flood kernel log
@@ -2485,8 +2045,6 @@ static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32
2485 } 2045 }
2486 } 2046 }
2487 2047
2488 iwl_release_nic_access(priv);
2489
2490 return rc; 2048 return rc;
2491} 2049}
2492 2050
@@ -2810,20 +2368,11 @@ static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
2810{ 2368{
2811 dma_addr_t pinst; 2369 dma_addr_t pinst;
2812 dma_addr_t pdata; 2370 dma_addr_t pdata;
2813 int rc = 0;
2814 unsigned long flags;
2815 2371
2816 /* bits 31:0 for 3945 */ 2372 /* bits 31:0 for 3945 */
2817 pinst = priv->ucode_code.p_addr; 2373 pinst = priv->ucode_code.p_addr;
2818 pdata = priv->ucode_data_backup.p_addr; 2374 pdata = priv->ucode_data_backup.p_addr;
2819 2375
2820 spin_lock_irqsave(&priv->lock, flags);
2821 rc = iwl_grab_nic_access(priv);
2822 if (rc) {
2823 spin_unlock_irqrestore(&priv->lock, flags);
2824 return rc;
2825 }
2826
2827 /* Tell bootstrap uCode where to find image to load */ 2376 /* Tell bootstrap uCode where to find image to load */
2828 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); 2377 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2829 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); 2378 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
@@ -2835,13 +2384,9 @@ static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
2835 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, 2384 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
2836 priv->ucode_code.len | BSM_DRAM_INST_LOAD); 2385 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2837 2386
2838 iwl_release_nic_access(priv);
2839
2840 spin_unlock_irqrestore(&priv->lock, flags);
2841
2842 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n"); 2387 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
2843 2388
2844 return rc; 2389 return 0;
2845} 2390}
2846 2391
2847/** 2392/**
@@ -2887,11 +2432,6 @@ static void iwl3945_init_alive_start(struct iwl_priv *priv)
2887 queue_work(priv->workqueue, &priv->restart); 2432 queue_work(priv->workqueue, &priv->restart);
2888} 2433}
2889 2434
2890
2891/* temporary */
2892static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
2893 struct sk_buff *skb);
2894
2895/** 2435/**
2896 * iwl3945_alive_start - called after REPLY_ALIVE notification received 2436 * iwl3945_alive_start - called after REPLY_ALIVE notification received
2897 * from protocol/runtime uCode (initialization uCode's 2437 * from protocol/runtime uCode (initialization uCode's
@@ -2899,7 +2439,6 @@ static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
2899 */ 2439 */
2900static void iwl3945_alive_start(struct iwl_priv *priv) 2440static void iwl3945_alive_start(struct iwl_priv *priv)
2901{ 2441{
2902 int rc = 0;
2903 int thermal_spin = 0; 2442 int thermal_spin = 0;
2904 u32 rfkill; 2443 u32 rfkill;
2905 2444
@@ -2922,17 +2461,10 @@ static void iwl3945_alive_start(struct iwl_priv *priv)
2922 goto restart; 2461 goto restart;
2923 } 2462 }
2924 2463
2925 iwl3945_clear_stations_table(priv); 2464 iwl_clear_stations_table(priv);
2926
2927 rc = iwl_grab_nic_access(priv);
2928 if (rc) {
2929 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
2930 return;
2931 }
2932 2465
2933 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG); 2466 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
2934 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill); 2467 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
2935 iwl_release_nic_access(priv);
2936 2468
2937 if (rfkill & 0x1) { 2469 if (rfkill & 0x1) {
2938 clear_bit(STATUS_RF_KILL_HW, &priv->status); 2470 clear_bit(STATUS_RF_KILL_HW, &priv->status);
@@ -2952,9 +2484,6 @@ static void iwl3945_alive_start(struct iwl_priv *priv)
2952 /* After the ALIVE response, we can send commands to 3945 uCode */ 2484 /* After the ALIVE response, we can send commands to 3945 uCode */
2953 set_bit(STATUS_ALIVE, &priv->status); 2485 set_bit(STATUS_ALIVE, &priv->status);
2954 2486
2955 /* Clear out the uCode error bit if it is set */
2956 clear_bit(STATUS_FW_ERROR, &priv->status);
2957
2958 if (iwl_is_rfkill(priv)) 2487 if (iwl_is_rfkill(priv))
2959 return; 2488 return;
2960 2489
@@ -2981,7 +2510,7 @@ static void iwl3945_alive_start(struct iwl_priv *priv)
2981 iwl_send_bt_config(priv); 2510 iwl_send_bt_config(priv);
2982 2511
2983 /* Configure the adapter for unassociated operation */ 2512 /* Configure the adapter for unassociated operation */
2984 iwl3945_commit_rxon(priv); 2513 iwlcore_commit_rxon(priv);
2985 2514
2986 iwl3945_reg_txpower_periodic(priv); 2515 iwl3945_reg_txpower_periodic(priv);
2987 2516
@@ -2991,17 +2520,17 @@ static void iwl3945_alive_start(struct iwl_priv *priv)
2991 set_bit(STATUS_READY, &priv->status); 2520 set_bit(STATUS_READY, &priv->status);
2992 wake_up_interruptible(&priv->wait_command_queue); 2521 wake_up_interruptible(&priv->wait_command_queue);
2993 2522
2994 if (priv->error_recovering)
2995 iwl3945_error_recovery(priv);
2996
2997 /* reassociate for ADHOC mode */ 2523 /* reassociate for ADHOC mode */
2998 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) { 2524 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2999 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw, 2525 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3000 priv->vif); 2526 priv->vif);
3001 if (beacon) 2527 if (beacon)
3002 iwl3945_mac_beacon_update(priv->hw, beacon); 2528 iwl_mac_beacon_update(priv->hw, beacon);
3003 } 2529 }
3004 2530
2531 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
2532 iwl_set_mode(priv, priv->iw_mode);
2533
3005 return; 2534 return;
3006 2535
3007 restart: 2536 restart:
@@ -3024,7 +2553,7 @@ static void __iwl3945_down(struct iwl_priv *priv)
3024 set_bit(STATUS_EXIT_PENDING, &priv->status); 2553 set_bit(STATUS_EXIT_PENDING, &priv->status);
3025 2554
3026 iwl3945_led_unregister(priv); 2555 iwl3945_led_unregister(priv);
3027 iwl3945_clear_stations_table(priv); 2556 iwl_clear_stations_table(priv);
3028 2557
3029 /* Unblock any waiting calls */ 2558 /* Unblock any waiting calls */
3030 wake_up_interruptible_all(&priv->wait_command_queue); 2559 wake_up_interruptible_all(&priv->wait_command_queue);
@@ -3047,31 +2576,23 @@ static void __iwl3945_down(struct iwl_priv *priv)
3047 ieee80211_stop_queues(priv->hw); 2576 ieee80211_stop_queues(priv->hw);
3048 2577
3049 /* If we have not previously called iwl3945_init() then 2578 /* If we have not previously called iwl3945_init() then
3050 * clear all bits but the RF Kill and SUSPEND bits and return */ 2579 * clear all bits but the RF Kill bits and return */
3051 if (!iwl_is_init(priv)) { 2580 if (!iwl_is_init(priv)) {
3052 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << 2581 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3053 STATUS_RF_KILL_HW | 2582 STATUS_RF_KILL_HW |
3054 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3055 STATUS_RF_KILL_SW |
3056 test_bit(STATUS_GEO_CONFIGURED, &priv->status) << 2583 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3057 STATUS_GEO_CONFIGURED | 2584 STATUS_GEO_CONFIGURED |
3058 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3059 STATUS_IN_SUSPEND |
3060 test_bit(STATUS_EXIT_PENDING, &priv->status) << 2585 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3061 STATUS_EXIT_PENDING; 2586 STATUS_EXIT_PENDING;
3062 goto exit; 2587 goto exit;
3063 } 2588 }
3064 2589
3065 /* ...otherwise clear out all the status bits but the RF Kill and 2590 /* ...otherwise clear out all the status bits but the RF Kill
3066 * SUSPEND bits and continue taking the NIC down. */ 2591 * bit and continue taking the NIC down. */
3067 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << 2592 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3068 STATUS_RF_KILL_HW | 2593 STATUS_RF_KILL_HW |
3069 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3070 STATUS_RF_KILL_SW |
3071 test_bit(STATUS_GEO_CONFIGURED, &priv->status) << 2594 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3072 STATUS_GEO_CONFIGURED | 2595 STATUS_GEO_CONFIGURED |
3073 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3074 STATUS_IN_SUSPEND |
3075 test_bit(STATUS_FW_ERROR, &priv->status) << 2596 test_bit(STATUS_FW_ERROR, &priv->status) <<
3076 STATUS_FW_ERROR | 2597 STATUS_FW_ERROR |
3077 test_bit(STATUS_EXIT_PENDING, &priv->status) << 2598 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
@@ -3085,17 +2606,12 @@ static void __iwl3945_down(struct iwl_priv *priv)
3085 iwl3945_hw_txq_ctx_stop(priv); 2606 iwl3945_hw_txq_ctx_stop(priv);
3086 iwl3945_hw_rxq_stop(priv); 2607 iwl3945_hw_rxq_stop(priv);
3087 2608
3088 spin_lock_irqsave(&priv->lock, flags); 2609 iwl_write_prph(priv, APMG_CLK_DIS_REG,
3089 if (!iwl_grab_nic_access(priv)) { 2610 APMG_CLK_VAL_DMA_CLK_RQT);
3090 iwl_write_prph(priv, APMG_CLK_DIS_REG,
3091 APMG_CLK_VAL_DMA_CLK_RQT);
3092 iwl_release_nic_access(priv);
3093 }
3094 spin_unlock_irqrestore(&priv->lock, flags);
3095 2611
3096 udelay(5); 2612 udelay(5);
3097 2613
3098 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status)) 2614 if (exit_pending)
3099 priv->cfg->ops->lib->apm_ops.stop(priv); 2615 priv->cfg->ops->lib->apm_ops.stop(priv);
3100 else 2616 else
3101 priv->cfg->ops->lib->apm_ops.reset(priv); 2617 priv->cfg->ops->lib->apm_ops.reset(priv);
@@ -3131,12 +2647,6 @@ static int __iwl3945_up(struct iwl_priv *priv)
3131 return -EIO; 2647 return -EIO;
3132 } 2648 }
3133 2649
3134 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
3135 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
3136 "parameter)\n");
3137 return -ENODEV;
3138 }
3139
3140 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { 2650 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
3141 IWL_ERR(priv, "ucode not available for device bring up\n"); 2651 IWL_ERR(priv, "ucode not available for device bring up\n");
3142 return -EIO; 2652 return -EIO;
@@ -3148,10 +2658,8 @@ static int __iwl3945_up(struct iwl_priv *priv)
3148 clear_bit(STATUS_RF_KILL_HW, &priv->status); 2658 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3149 else { 2659 else {
3150 set_bit(STATUS_RF_KILL_HW, &priv->status); 2660 set_bit(STATUS_RF_KILL_HW, &priv->status);
3151 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { 2661 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
3152 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n"); 2662 return -ENODEV;
3153 return -ENODEV;
3154 }
3155 } 2663 }
3156 2664
3157 iwl_write32(priv, CSR_INT, 0xFFFFFFFF); 2665 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
@@ -3187,7 +2695,7 @@ static int __iwl3945_up(struct iwl_priv *priv)
3187 2695
3188 for (i = 0; i < MAX_HW_RESTARTS; i++) { 2696 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3189 2697
3190 iwl3945_clear_stations_table(priv); 2698 iwl_clear_stations_table(priv);
3191 2699
3192 /* load bootstrap state machine, 2700 /* load bootstrap state machine,
3193 * load bootstrap program into processor's memory, 2701 * load bootstrap program into processor's memory,
@@ -3255,15 +2763,14 @@ static void iwl3945_rfkill_poll(struct work_struct *data)
3255{ 2763{
3256 struct iwl_priv *priv = 2764 struct iwl_priv *priv =
3257 container_of(data, struct iwl_priv, rfkill_poll.work); 2765 container_of(data, struct iwl_priv, rfkill_poll.work);
3258 unsigned long status = priv->status;
3259 2766
3260 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) 2767 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3261 clear_bit(STATUS_RF_KILL_HW, &priv->status); 2768 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3262 else 2769 else
3263 set_bit(STATUS_RF_KILL_HW, &priv->status); 2770 set_bit(STATUS_RF_KILL_HW, &priv->status);
3264 2771
3265 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status)) 2772 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
3266 queue_work(priv->workqueue, &priv->rf_kill); 2773 test_bit(STATUS_RF_KILL_HW, &priv->status));
3267 2774
3268 queue_delayed_work(priv->workqueue, &priv->rfkill_poll, 2775 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3269 round_jiffies_relative(2 * HZ)); 2776 round_jiffies_relative(2 * HZ));
@@ -3283,9 +2790,9 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
3283 int rc = 0; 2790 int rc = 0;
3284 struct iwl3945_scan_cmd *scan; 2791 struct iwl3945_scan_cmd *scan;
3285 struct ieee80211_conf *conf = NULL; 2792 struct ieee80211_conf *conf = NULL;
3286 u8 n_probes = 2; 2793 u8 n_probes = 0;
3287 enum ieee80211_band band; 2794 enum ieee80211_band band;
3288 DECLARE_SSID_BUF(ssid); 2795 bool is_active = false;
3289 2796
3290 conf = ieee80211_get_hw_conf(priv->hw); 2797 conf = ieee80211_get_hw_conf(priv->hw);
3291 2798
@@ -3386,18 +2893,25 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
3386 scan_suspend_time, interval); 2893 scan_suspend_time, interval);
3387 } 2894 }
3388 2895
3389 /* We should add the ability for user to lock to PASSIVE ONLY */ 2896 if (priv->scan_request->n_ssids) {
3390 if (priv->one_direct_scan) { 2897 int i, p = 0;
3391 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n", 2898 IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
3392 print_ssid(ssid, priv->direct_ssid, 2899 for (i = 0; i < priv->scan_request->n_ssids; i++) {
3393 priv->direct_ssid_len)); 2900 /* always does wildcard anyway */
3394 scan->direct_scan[0].id = WLAN_EID_SSID; 2901 if (!priv->scan_request->ssids[i].ssid_len)
3395 scan->direct_scan[0].len = priv->direct_ssid_len; 2902 continue;
3396 memcpy(scan->direct_scan[0].ssid, 2903 scan->direct_scan[p].id = WLAN_EID_SSID;
3397 priv->direct_ssid, priv->direct_ssid_len); 2904 scan->direct_scan[p].len =
3398 n_probes++; 2905 priv->scan_request->ssids[i].ssid_len;
2906 memcpy(scan->direct_scan[p].ssid,
2907 priv->scan_request->ssids[i].ssid,
2908 priv->scan_request->ssids[i].ssid_len);
2909 n_probes++;
2910 p++;
2911 }
2912 is_active = true;
3399 } else 2913 } else
3400 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n"); 2914 IWL_DEBUG_SCAN(priv, "Kicking off passive scan.\n");
3401 2915
3402 /* We don't build a direct scan probe request; the uCode will do 2916 /* We don't build a direct scan probe request; the uCode will do
3403 * that based on the direct_mask added to each channel entry */ 2917 * that based on the direct_mask added to each channel entry */
@@ -3414,7 +2928,12 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
3414 band = IEEE80211_BAND_2GHZ; 2928 band = IEEE80211_BAND_2GHZ;
3415 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { 2929 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
3416 scan->tx_cmd.rate = IWL_RATE_6M_PLCP; 2930 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3417 scan->good_CRC_th = IWL_GOOD_CRC_TH; 2931 /*
2932 * If active scaning is requested but a certain channel
2933 * is marked passive, we can do active scanning if we
2934 * detect transmissions.
2935 */
2936 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH : 0;
3418 band = IEEE80211_BAND_5GHZ; 2937 band = IEEE80211_BAND_5GHZ;
3419 } else { 2938 } else {
3420 IWL_WARN(priv, "Invalid scan band count\n"); 2939 IWL_WARN(priv, "Invalid scan band count\n");
@@ -3422,19 +2941,20 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
3422 } 2941 }
3423 2942
3424 scan->tx_cmd.len = cpu_to_le16( 2943 scan->tx_cmd.len = cpu_to_le16(
3425 iwl_fill_probe_req(priv, band, 2944 iwl_fill_probe_req(priv,
3426 (struct ieee80211_mgmt *)scan->data, 2945 (struct ieee80211_mgmt *)scan->data,
3427 IWL_MAX_SCAN_SIZE - sizeof(*scan))); 2946 priv->scan_request->ie,
2947 priv->scan_request->ie_len,
2948 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3428 2949
3429 /* select Rx antennas */ 2950 /* select Rx antennas */
3430 scan->flags |= iwl3945_get_antenna_flags(priv); 2951 scan->flags |= iwl3945_get_antenna_flags(priv);
3431 2952
3432 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) 2953 if (iwl_is_monitor_mode(priv))
3433 scan->filter_flags = RXON_FILTER_PROMISC_MSK; 2954 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3434 2955
3435 scan->channel_count = 2956 scan->channel_count =
3436 iwl3945_get_channels_for_scan(priv, band, 1, /* active */ 2957 iwl3945_get_channels_for_scan(priv, band, is_active, n_probes,
3437 n_probes,
3438 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); 2958 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
3439 2959
3440 if (scan->channel_count == 0) { 2960 if (scan->channel_count == 0) {
@@ -3482,7 +3002,6 @@ static void iwl3945_bg_up(struct work_struct *data)
3482 mutex_lock(&priv->mutex); 3002 mutex_lock(&priv->mutex);
3483 __iwl3945_up(priv); 3003 __iwl3945_up(priv);
3484 mutex_unlock(&priv->mutex); 3004 mutex_unlock(&priv->mutex);
3485 iwl_rfkill_set_hw_state(priv);
3486} 3005}
3487 3006
3488static void iwl3945_bg_restart(struct work_struct *data) 3007static void iwl3945_bg_restart(struct work_struct *data)
@@ -3492,8 +3011,17 @@ static void iwl3945_bg_restart(struct work_struct *data)
3492 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 3011 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3493 return; 3012 return;
3494 3013
3495 iwl3945_down(priv); 3014 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
3496 queue_work(priv->workqueue, &priv->up); 3015 mutex_lock(&priv->mutex);
3016 priv->vif = NULL;
3017 priv->is_open = 0;
3018 mutex_unlock(&priv->mutex);
3019 iwl3945_down(priv);
3020 ieee80211_restart_hw(priv->hw);
3021 } else {
3022 iwl3945_down(priv);
3023 queue_work(priv->workqueue, &priv->up);
3024 }
3497} 3025}
3498 3026
3499static void iwl3945_bg_rx_replenish(struct work_struct *data) 3027static void iwl3945_bg_rx_replenish(struct work_struct *data)
@@ -3511,7 +3039,7 @@ static void iwl3945_bg_rx_replenish(struct work_struct *data)
3511 3039
3512#define IWL_DELAY_NEXT_SCAN (HZ*2) 3040#define IWL_DELAY_NEXT_SCAN (HZ*2)
3513 3041
3514static void iwl3945_post_associate(struct iwl_priv *priv) 3042void iwl3945_post_associate(struct iwl_priv *priv)
3515{ 3043{
3516 int rc = 0; 3044 int rc = 0;
3517 struct ieee80211_conf *conf = NULL; 3045 struct ieee80211_conf *conf = NULL;
@@ -3536,7 +3064,7 @@ static void iwl3945_post_associate(struct iwl_priv *priv)
3536 conf = ieee80211_get_hw_conf(priv->hw); 3064 conf = ieee80211_get_hw_conf(priv->hw);
3537 3065
3538 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3066 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3539 iwl3945_commit_rxon(priv); 3067 iwlcore_commit_rxon(priv);
3540 3068
3541 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); 3069 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
3542 iwl3945_setup_rxon_timing(priv); 3070 iwl3945_setup_rxon_timing(priv);
@@ -3569,7 +3097,7 @@ static void iwl3945_post_associate(struct iwl_priv *priv)
3569 3097
3570 } 3098 }
3571 3099
3572 iwl3945_commit_rxon(priv); 3100 iwlcore_commit_rxon(priv);
3573 3101
3574 switch (priv->iw_mode) { 3102 switch (priv->iw_mode) {
3575 case NL80211_IFTYPE_STATION: 3103 case NL80211_IFTYPE_STATION:
@@ -3579,7 +3107,7 @@ static void iwl3945_post_associate(struct iwl_priv *priv)
3579 case NL80211_IFTYPE_ADHOC: 3107 case NL80211_IFTYPE_ADHOC:
3580 3108
3581 priv->assoc_id = 1; 3109 priv->assoc_id = 1;
3582 iwl3945_add_station(priv, priv->bssid, 0, 0); 3110 iwl_add_station(priv, priv->bssid, 0, CMD_SYNC, NULL);
3583 iwl3945_sync_sta(priv, IWL_STA_ID, 3111 iwl3945_sync_sta(priv, IWL_STA_ID,
3584 (priv->band == IEEE80211_BAND_5GHZ) ? 3112 (priv->band == IEEE80211_BAND_5GHZ) ?
3585 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, 3113 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
@@ -3601,8 +3129,6 @@ static void iwl3945_post_associate(struct iwl_priv *priv)
3601 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; 3129 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
3602} 3130}
3603 3131
3604static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
3605
3606/***************************************************************************** 3132/*****************************************************************************
3607 * 3133 *
3608 * mac80211 entry point functions 3134 * mac80211 entry point functions
@@ -3638,16 +3164,11 @@ static int iwl3945_mac_start(struct ieee80211_hw *hw)
3638 3164
3639 mutex_unlock(&priv->mutex); 3165 mutex_unlock(&priv->mutex);
3640 3166
3641 iwl_rfkill_set_hw_state(priv);
3642
3643 if (ret) 3167 if (ret)
3644 goto out_release_irq; 3168 goto out_release_irq;
3645 3169
3646 IWL_DEBUG_INFO(priv, "Start UP work.\n"); 3170 IWL_DEBUG_INFO(priv, "Start UP work.\n");
3647 3171
3648 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3649 return 0;
3650
3651 /* Wait for START_ALIVE from ucode. Otherwise callbacks from 3172 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3652 * mac80211 will not be run successfully. */ 3173 * mac80211 will not be run successfully. */
3653 ret = wait_event_interruptible_timeout(priv->wait_command_queue, 3174 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
@@ -3726,144 +3247,7 @@ static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3726 return NETDEV_TX_OK; 3247 return NETDEV_TX_OK;
3727} 3248}
3728 3249
3729static int iwl3945_mac_add_interface(struct ieee80211_hw *hw, 3250void iwl3945_config_ap(struct iwl_priv *priv)
3730 struct ieee80211_if_init_conf *conf)
3731{
3732 struct iwl_priv *priv = hw->priv;
3733 unsigned long flags;
3734
3735 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
3736
3737 if (priv->vif) {
3738 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
3739 return -EOPNOTSUPP;
3740 }
3741
3742 spin_lock_irqsave(&priv->lock, flags);
3743 priv->vif = conf->vif;
3744 priv->iw_mode = conf->type;
3745
3746 spin_unlock_irqrestore(&priv->lock, flags);
3747
3748 mutex_lock(&priv->mutex);
3749
3750 if (conf->mac_addr) {
3751 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
3752 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3753 }
3754
3755 if (iwl_is_ready(priv))
3756 iwl3945_set_mode(priv, conf->type);
3757
3758 mutex_unlock(&priv->mutex);
3759
3760 IWL_DEBUG_MAC80211(priv, "leave\n");
3761 return 0;
3762}
3763
3764/**
3765 * iwl3945_mac_config - mac80211 config callback
3766 *
3767 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3768 * be set inappropriately and the driver currently sets the hardware up to
3769 * use it whenever needed.
3770 */
3771static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
3772{
3773 struct iwl_priv *priv = hw->priv;
3774 const struct iwl_channel_info *ch_info;
3775 struct ieee80211_conf *conf = &hw->conf;
3776 unsigned long flags;
3777 int ret = 0;
3778
3779 mutex_lock(&priv->mutex);
3780 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3781 conf->channel->hw_value);
3782
3783 if (!iwl_is_ready(priv)) {
3784 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
3785 ret = -EIO;
3786 goto out;
3787 }
3788
3789 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
3790 test_bit(STATUS_SCANNING, &priv->status))) {
3791 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
3792 set_bit(STATUS_CONF_PENDING, &priv->status);
3793 mutex_unlock(&priv->mutex);
3794 return 0;
3795 }
3796
3797 spin_lock_irqsave(&priv->lock, flags);
3798
3799 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3800 conf->channel->hw_value);
3801 if (!is_channel_valid(ch_info)) {
3802 IWL_DEBUG_SCAN(priv,
3803 "Channel %d [%d] is INVALID for this band.\n",
3804 conf->channel->hw_value, conf->channel->band);
3805 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
3806 spin_unlock_irqrestore(&priv->lock, flags);
3807 ret = -EINVAL;
3808 goto out;
3809 }
3810
3811 iwl_set_rxon_channel(priv, conf->channel);
3812
3813 iwl_set_flags_for_band(priv, conf->channel->band);
3814
3815 /* The list of supported rates and rate mask can be different
3816 * for each phymode; since the phymode may have changed, reset
3817 * the rate mask to what mac80211 lists */
3818 iwl_set_rate(priv);
3819
3820 spin_unlock_irqrestore(&priv->lock, flags);
3821
3822#ifdef IEEE80211_CONF_CHANNEL_SWITCH
3823 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
3824 iwl3945_hw_channel_switch(priv, conf->channel);
3825 goto out;
3826 }
3827#endif
3828
3829 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
3830 if (conf->radio_enabled &&
3831 iwl_radio_kill_sw_enable_radio(priv)) {
3832 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - "
3833 "waiting for uCode\n");
3834 goto out;
3835 }
3836
3837 if (!conf->radio_enabled) {
3838 iwl_radio_kill_sw_disable_radio(priv);
3839 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
3840 goto out;
3841 }
3842 }
3843
3844 if (iwl_is_rfkill(priv)) {
3845 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
3846 ret = -EIO;
3847 goto out;
3848 }
3849
3850 iwl_set_rate(priv);
3851
3852 if (memcmp(&priv->active_rxon,
3853 &priv->staging_rxon, sizeof(priv->staging_rxon)))
3854 iwl3945_commit_rxon(priv);
3855 else
3856 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
3857
3858 IWL_DEBUG_MAC80211(priv, "leave\n");
3859
3860out:
3861 clear_bit(STATUS_CONF_PENDING, &priv->status);
3862 mutex_unlock(&priv->mutex);
3863 return ret;
3864}
3865
3866static void iwl3945_config_ap(struct iwl_priv *priv)
3867{ 3251{
3868 int rc = 0; 3252 int rc = 0;
3869 3253
@@ -3875,7 +3259,7 @@ static void iwl3945_config_ap(struct iwl_priv *priv)
3875 3259
3876 /* RXON - unassoc (to set timing command) */ 3260 /* RXON - unassoc (to set timing command) */
3877 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3261 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3878 iwl3945_commit_rxon(priv); 3262 iwlcore_commit_rxon(priv);
3879 3263
3880 /* RXON Timing */ 3264 /* RXON Timing */
3881 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); 3265 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
@@ -3911,8 +3295,8 @@ static void iwl3945_config_ap(struct iwl_priv *priv)
3911 } 3295 }
3912 /* restore RXON assoc */ 3296 /* restore RXON assoc */
3913 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 3297 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
3914 iwl3945_commit_rxon(priv); 3298 iwlcore_commit_rxon(priv);
3915 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0); 3299 iwl_add_station(priv, iwl_bcast_addr, 0, CMD_SYNC, NULL);
3916 } 3300 }
3917 iwl3945_send_beacon_cmd(priv); 3301 iwl3945_send_beacon_cmd(priv);
3918 3302
@@ -3921,189 +3305,6 @@ static void iwl3945_config_ap(struct iwl_priv *priv)
3921 * clear sta table, add BCAST sta... */ 3305 * clear sta table, add BCAST sta... */
3922} 3306}
3923 3307
3924static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
3925 struct ieee80211_vif *vif,
3926 struct ieee80211_if_conf *conf)
3927{
3928 struct iwl_priv *priv = hw->priv;
3929 int rc;
3930
3931 if (conf == NULL)
3932 return -EIO;
3933
3934 if (priv->vif != vif) {
3935 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
3936 return 0;
3937 }
3938
3939 /* handle this temporarily here */
3940 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
3941 conf->changed & IEEE80211_IFCC_BEACON) {
3942 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
3943 if (!beacon)
3944 return -ENOMEM;
3945 mutex_lock(&priv->mutex);
3946 rc = iwl3945_mac_beacon_update(hw, beacon);
3947 mutex_unlock(&priv->mutex);
3948 if (rc)
3949 return rc;
3950 }
3951
3952 if (!iwl_is_alive(priv))
3953 return -EAGAIN;
3954
3955 mutex_lock(&priv->mutex);
3956
3957 if (conf->bssid)
3958 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
3959
3960/*
3961 * very dubious code was here; the probe filtering flag is never set:
3962 *
3963 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
3964 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
3965 */
3966
3967 if (priv->iw_mode == NL80211_IFTYPE_AP) {
3968 if (!conf->bssid) {
3969 conf->bssid = priv->mac_addr;
3970 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
3971 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
3972 conf->bssid);
3973 }
3974 if (priv->ibss_beacon)
3975 dev_kfree_skb(priv->ibss_beacon);
3976
3977 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
3978 }
3979
3980 if (iwl_is_rfkill(priv))
3981 goto done;
3982
3983 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
3984 !is_multicast_ether_addr(conf->bssid)) {
3985 /* If there is currently a HW scan going on in the background
3986 * then we need to cancel it else the RXON below will fail. */
3987 if (iwl_scan_cancel_timeout(priv, 100)) {
3988 IWL_WARN(priv, "Aborted scan still in progress "
3989 "after 100ms\n");
3990 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
3991 mutex_unlock(&priv->mutex);
3992 return -EAGAIN;
3993 }
3994 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
3995
3996 /* TODO: Audit driver for usage of these members and see
3997 * if mac80211 deprecates them (priv->bssid looks like it
3998 * shouldn't be there, but I haven't scanned the IBSS code
3999 * to verify) - jpk */
4000 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4001
4002 if (priv->iw_mode == NL80211_IFTYPE_AP)
4003 iwl3945_config_ap(priv);
4004 else {
4005 rc = iwl3945_commit_rxon(priv);
4006 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
4007 iwl3945_add_station(priv,
4008 priv->active_rxon.bssid_addr, 1, 0);
4009 }
4010
4011 } else {
4012 iwl_scan_cancel_timeout(priv, 100);
4013 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4014 iwl3945_commit_rxon(priv);
4015 }
4016
4017 done:
4018 IWL_DEBUG_MAC80211(priv, "leave\n");
4019 mutex_unlock(&priv->mutex);
4020
4021 return 0;
4022}
4023
4024static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
4025 struct ieee80211_if_init_conf *conf)
4026{
4027 struct iwl_priv *priv = hw->priv;
4028
4029 IWL_DEBUG_MAC80211(priv, "enter\n");
4030
4031 mutex_lock(&priv->mutex);
4032
4033 if (iwl_is_ready_rf(priv)) {
4034 iwl_scan_cancel_timeout(priv, 100);
4035 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4036 iwl3945_commit_rxon(priv);
4037 }
4038 if (priv->vif == conf->vif) {
4039 priv->vif = NULL;
4040 memset(priv->bssid, 0, ETH_ALEN);
4041 }
4042 mutex_unlock(&priv->mutex);
4043
4044 IWL_DEBUG_MAC80211(priv, "leave\n");
4045}
4046
4047#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4048
4049static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4050 struct ieee80211_vif *vif,
4051 struct ieee80211_bss_conf *bss_conf,
4052 u32 changes)
4053{
4054 struct iwl_priv *priv = hw->priv;
4055
4056 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
4057
4058 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
4059 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
4060 bss_conf->use_short_preamble);
4061 if (bss_conf->use_short_preamble)
4062 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
4063 else
4064 priv->staging_rxon.flags &=
4065 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4066 }
4067
4068 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
4069 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4070 bss_conf->use_cts_prot);
4071 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
4072 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
4073 else
4074 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
4075 }
4076
4077 if (changes & BSS_CHANGED_ASSOC) {
4078 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
4079 /* This should never happen as this function should
4080 * never be called from interrupt context. */
4081 if (WARN_ON_ONCE(in_interrupt()))
4082 return;
4083 if (bss_conf->assoc) {
4084 priv->assoc_id = bss_conf->aid;
4085 priv->beacon_int = bss_conf->beacon_int;
4086 priv->timestamp = bss_conf->timestamp;
4087 priv->assoc_capability = bss_conf->assoc_capability;
4088 priv->power_data.dtim_period = bss_conf->dtim_period;
4089 priv->next_scan_jiffies = jiffies +
4090 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4091 mutex_lock(&priv->mutex);
4092 iwl3945_post_associate(priv);
4093 mutex_unlock(&priv->mutex);
4094 } else {
4095 priv->assoc_id = 0;
4096 IWL_DEBUG_MAC80211(priv,
4097 "DISASSOC %d\n", bss_conf->assoc);
4098 }
4099 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
4100 IWL_DEBUG_MAC80211(priv,
4101 "Associated Changes %d\n", changes);
4102 iwl3945_send_rxon_assoc(priv);
4103 }
4104
4105}
4106
4107static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 3308static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4108 struct ieee80211_vif *vif, 3309 struct ieee80211_vif *vif,
4109 struct ieee80211_sta *sta, 3310 struct ieee80211_sta *sta,
@@ -4126,7 +3327,7 @@ static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4126 static_key = !iwl_is_associated(priv); 3327 static_key = !iwl_is_associated(priv);
4127 3328
4128 if (!static_key) { 3329 if (!static_key) {
4129 sta_id = iwl3945_hw_find_station(priv, addr); 3330 sta_id = iwl_find_station(priv, addr);
4130 if (sta_id == IWL_INVALID_STATION) { 3331 if (sta_id == IWL_INVALID_STATION) {
4131 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n", 3332 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
4132 addr); 3333 addr);
@@ -4162,185 +3363,6 @@ static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4162 return ret; 3363 return ret;
4163} 3364}
4164 3365
4165static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
4166 const struct ieee80211_tx_queue_params *params)
4167{
4168 struct iwl_priv *priv = hw->priv;
4169 unsigned long flags;
4170 int q;
4171
4172 IWL_DEBUG_MAC80211(priv, "enter\n");
4173
4174 if (!iwl_is_ready_rf(priv)) {
4175 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4176 return -EIO;
4177 }
4178
4179 if (queue >= AC_NUM) {
4180 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
4181 return 0;
4182 }
4183
4184 q = AC_NUM - 1 - queue;
4185
4186 spin_lock_irqsave(&priv->lock, flags);
4187
4188 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4189 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4190 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4191 priv->qos_data.def_qos_parm.ac[q].edca_txop =
4192 cpu_to_le16((params->txop * 32));
4193
4194 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4195 priv->qos_data.qos_active = 1;
4196
4197 spin_unlock_irqrestore(&priv->lock, flags);
4198
4199 mutex_lock(&priv->mutex);
4200 if (priv->iw_mode == NL80211_IFTYPE_AP)
4201 iwl_activate_qos(priv, 1);
4202 else if (priv->assoc_id && iwl_is_associated(priv))
4203 iwl_activate_qos(priv, 0);
4204
4205 mutex_unlock(&priv->mutex);
4206
4207 IWL_DEBUG_MAC80211(priv, "leave\n");
4208 return 0;
4209}
4210
4211static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
4212 struct ieee80211_tx_queue_stats *stats)
4213{
4214 struct iwl_priv *priv = hw->priv;
4215 int i, avail;
4216 struct iwl_tx_queue *txq;
4217 struct iwl_queue *q;
4218 unsigned long flags;
4219
4220 IWL_DEBUG_MAC80211(priv, "enter\n");
4221
4222 if (!iwl_is_ready_rf(priv)) {
4223 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4224 return -EIO;
4225 }
4226
4227 spin_lock_irqsave(&priv->lock, flags);
4228
4229 for (i = 0; i < AC_NUM; i++) {
4230 txq = &priv->txq[i];
4231 q = &txq->q;
4232 avail = iwl_queue_space(q);
4233
4234 stats[i].len = q->n_window - avail;
4235 stats[i].limit = q->n_window - q->high_mark;
4236 stats[i].count = q->n_window;
4237
4238 }
4239 spin_unlock_irqrestore(&priv->lock, flags);
4240
4241 IWL_DEBUG_MAC80211(priv, "leave\n");
4242
4243 return 0;
4244}
4245
4246static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
4247{
4248 struct iwl_priv *priv = hw->priv;
4249 unsigned long flags;
4250
4251 mutex_lock(&priv->mutex);
4252 IWL_DEBUG_MAC80211(priv, "enter\n");
4253
4254 iwl_reset_qos(priv);
4255
4256 spin_lock_irqsave(&priv->lock, flags);
4257 priv->assoc_id = 0;
4258 priv->assoc_capability = 0;
4259
4260 /* new association get rid of ibss beacon skb */
4261 if (priv->ibss_beacon)
4262 dev_kfree_skb(priv->ibss_beacon);
4263
4264 priv->ibss_beacon = NULL;
4265
4266 priv->beacon_int = priv->hw->conf.beacon_int;
4267 priv->timestamp = 0;
4268 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
4269 priv->beacon_int = 0;
4270
4271 spin_unlock_irqrestore(&priv->lock, flags);
4272
4273 if (!iwl_is_ready_rf(priv)) {
4274 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
4275 mutex_unlock(&priv->mutex);
4276 return;
4277 }
4278
4279 /* we are restarting association process
4280 * clear RXON_FILTER_ASSOC_MSK bit
4281 */
4282 if (priv->iw_mode != NL80211_IFTYPE_AP) {
4283 iwl_scan_cancel_timeout(priv, 100);
4284 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4285 iwl3945_commit_rxon(priv);
4286 }
4287
4288 /* Per mac80211.h: This is only used in IBSS mode... */
4289 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
4290
4291 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
4292 mutex_unlock(&priv->mutex);
4293 return;
4294 }
4295
4296 iwl_set_rate(priv);
4297
4298 mutex_unlock(&priv->mutex);
4299
4300 IWL_DEBUG_MAC80211(priv, "leave\n");
4301
4302}
4303
4304static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
4305{
4306 struct iwl_priv *priv = hw->priv;
4307 unsigned long flags;
4308 __le64 timestamp;
4309
4310 IWL_DEBUG_MAC80211(priv, "enter\n");
4311
4312 if (!iwl_is_ready_rf(priv)) {
4313 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4314 return -EIO;
4315 }
4316
4317 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
4318 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
4319 return -EIO;
4320 }
4321
4322 spin_lock_irqsave(&priv->lock, flags);
4323
4324 if (priv->ibss_beacon)
4325 dev_kfree_skb(priv->ibss_beacon);
4326
4327 priv->ibss_beacon = skb;
4328
4329 priv->assoc_id = 0;
4330 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
4331 priv->timestamp = le64_to_cpu(timestamp);
4332
4333 IWL_DEBUG_MAC80211(priv, "leave\n");
4334 spin_unlock_irqrestore(&priv->lock, flags);
4335
4336 iwl_reset_qos(priv);
4337
4338 iwl3945_post_associate(priv);
4339
4340
4341 return 0;
4342}
4343
4344/***************************************************************************** 3366/*****************************************************************************
4345 * 3367 *
4346 * sysfs attributes 3368 * sysfs attributes
@@ -4359,7 +3381,7 @@ static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
4359static ssize_t show_debug_level(struct device *d, 3381static ssize_t show_debug_level(struct device *d,
4360 struct device_attribute *attr, char *buf) 3382 struct device_attribute *attr, char *buf)
4361{ 3383{
4362 struct iwl_priv *priv = d->driver_data; 3384 struct iwl_priv *priv = dev_get_drvdata(d);
4363 3385
4364 return sprintf(buf, "0x%08X\n", priv->debug_level); 3386 return sprintf(buf, "0x%08X\n", priv->debug_level);
4365} 3387}
@@ -4367,7 +3389,7 @@ static ssize_t store_debug_level(struct device *d,
4367 struct device_attribute *attr, 3389 struct device_attribute *attr,
4368 const char *buf, size_t count) 3390 const char *buf, size_t count)
4369{ 3391{
4370 struct iwl_priv *priv = d->driver_data; 3392 struct iwl_priv *priv = dev_get_drvdata(d);
4371 unsigned long val; 3393 unsigned long val;
4372 int ret; 3394 int ret;
4373 3395
@@ -4388,7 +3410,7 @@ static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4388static ssize_t show_temperature(struct device *d, 3410static ssize_t show_temperature(struct device *d,
4389 struct device_attribute *attr, char *buf) 3411 struct device_attribute *attr, char *buf)
4390{ 3412{
4391 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3413 struct iwl_priv *priv = dev_get_drvdata(d);
4392 3414
4393 if (!iwl_is_alive(priv)) 3415 if (!iwl_is_alive(priv))
4394 return -EAGAIN; 3416 return -EAGAIN;
@@ -4401,7 +3423,7 @@ static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4401static ssize_t show_tx_power(struct device *d, 3423static ssize_t show_tx_power(struct device *d,
4402 struct device_attribute *attr, char *buf) 3424 struct device_attribute *attr, char *buf)
4403{ 3425{
4404 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3426 struct iwl_priv *priv = dev_get_drvdata(d);
4405 return sprintf(buf, "%d\n", priv->tx_power_user_lmt); 3427 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
4406} 3428}
4407 3429
@@ -4409,7 +3431,7 @@ static ssize_t store_tx_power(struct device *d,
4409 struct device_attribute *attr, 3431 struct device_attribute *attr,
4410 const char *buf, size_t count) 3432 const char *buf, size_t count)
4411{ 3433{
4412 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3434 struct iwl_priv *priv = dev_get_drvdata(d);
4413 char *p = (char *)buf; 3435 char *p = (char *)buf;
4414 u32 val; 3436 u32 val;
4415 3437
@@ -4427,7 +3449,7 @@ static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4427static ssize_t show_flags(struct device *d, 3449static ssize_t show_flags(struct device *d,
4428 struct device_attribute *attr, char *buf) 3450 struct device_attribute *attr, char *buf)
4429{ 3451{
4430 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3452 struct iwl_priv *priv = dev_get_drvdata(d);
4431 3453
4432 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); 3454 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
4433} 3455}
@@ -4436,7 +3458,7 @@ static ssize_t store_flags(struct device *d,
4436 struct device_attribute *attr, 3458 struct device_attribute *attr,
4437 const char *buf, size_t count) 3459 const char *buf, size_t count)
4438{ 3460{
4439 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3461 struct iwl_priv *priv = dev_get_drvdata(d);
4440 u32 flags = simple_strtoul(buf, NULL, 0); 3462 u32 flags = simple_strtoul(buf, NULL, 0);
4441 3463
4442 mutex_lock(&priv->mutex); 3464 mutex_lock(&priv->mutex);
@@ -4448,7 +3470,7 @@ static ssize_t store_flags(struct device *d,
4448 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n", 3470 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
4449 flags); 3471 flags);
4450 priv->staging_rxon.flags = cpu_to_le32(flags); 3472 priv->staging_rxon.flags = cpu_to_le32(flags);
4451 iwl3945_commit_rxon(priv); 3473 iwlcore_commit_rxon(priv);
4452 } 3474 }
4453 } 3475 }
4454 mutex_unlock(&priv->mutex); 3476 mutex_unlock(&priv->mutex);
@@ -4461,7 +3483,7 @@ static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4461static ssize_t show_filter_flags(struct device *d, 3483static ssize_t show_filter_flags(struct device *d,
4462 struct device_attribute *attr, char *buf) 3484 struct device_attribute *attr, char *buf)
4463{ 3485{
4464 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3486 struct iwl_priv *priv = dev_get_drvdata(d);
4465 3487
4466 return sprintf(buf, "0x%04X\n", 3488 return sprintf(buf, "0x%04X\n",
4467 le32_to_cpu(priv->active_rxon.filter_flags)); 3489 le32_to_cpu(priv->active_rxon.filter_flags));
@@ -4471,7 +3493,7 @@ static ssize_t store_filter_flags(struct device *d,
4471 struct device_attribute *attr, 3493 struct device_attribute *attr,
4472 const char *buf, size_t count) 3494 const char *buf, size_t count)
4473{ 3495{
4474 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3496 struct iwl_priv *priv = dev_get_drvdata(d);
4475 u32 filter_flags = simple_strtoul(buf, NULL, 0); 3497 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4476 3498
4477 mutex_lock(&priv->mutex); 3499 mutex_lock(&priv->mutex);
@@ -4484,7 +3506,7 @@ static ssize_t store_filter_flags(struct device *d,
4484 "0x%04X\n", filter_flags); 3506 "0x%04X\n", filter_flags);
4485 priv->staging_rxon.filter_flags = 3507 priv->staging_rxon.filter_flags =
4486 cpu_to_le32(filter_flags); 3508 cpu_to_le32(filter_flags);
4487 iwl3945_commit_rxon(priv); 3509 iwlcore_commit_rxon(priv);
4488 } 3510 }
4489 } 3511 }
4490 mutex_unlock(&priv->mutex); 3512 mutex_unlock(&priv->mutex);
@@ -4624,26 +3646,11 @@ static ssize_t show_power_level(struct device *d,
4624{ 3646{
4625 struct iwl_priv *priv = dev_get_drvdata(d); 3647 struct iwl_priv *priv = dev_get_drvdata(d);
4626 int mode = priv->power_data.user_power_setting; 3648 int mode = priv->power_data.user_power_setting;
4627 int system = priv->power_data.system_power_setting;
4628 int level = priv->power_data.power_mode; 3649 int level = priv->power_data.power_mode;
4629 char *p = buf; 3650 char *p = buf;
4630 3651
4631 switch (system) { 3652 p += sprintf(p, "INDEX:%d\t", level);
4632 case IWL_POWER_SYS_AUTO: 3653 p += sprintf(p, "USER:%d\n", mode);
4633 p += sprintf(p, "SYSTEM:auto");
4634 break;
4635 case IWL_POWER_SYS_AC:
4636 p += sprintf(p, "SYSTEM:ac");
4637 break;
4638 case IWL_POWER_SYS_BATTERY:
4639 p += sprintf(p, "SYSTEM:battery");
4640 break;
4641 }
4642
4643 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4644 "fixed" : "auto");
4645 p += sprintf(p, "\tINDEX:%d", level);
4646 p += sprintf(p, "\n");
4647 return p - buf + 1; 3654 return p - buf + 1;
4648} 3655}
4649 3656
@@ -4756,7 +3763,7 @@ static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4756static ssize_t show_status(struct device *d, 3763static ssize_t show_status(struct device *d,
4757 struct device_attribute *attr, char *buf) 3764 struct device_attribute *attr, char *buf)
4758{ 3765{
4759 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3766 struct iwl_priv *priv = dev_get_drvdata(d);
4760 if (!iwl_is_alive(priv)) 3767 if (!iwl_is_alive(priv))
4761 return -EAGAIN; 3768 return -EAGAIN;
4762 return sprintf(buf, "0x%08x\n", (int)priv->status); 3769 return sprintf(buf, "0x%08x\n", (int)priv->status);
@@ -4768,10 +3775,11 @@ static ssize_t dump_error_log(struct device *d,
4768 struct device_attribute *attr, 3775 struct device_attribute *attr,
4769 const char *buf, size_t count) 3776 const char *buf, size_t count)
4770{ 3777{
3778 struct iwl_priv *priv = dev_get_drvdata(d);
4771 char *p = (char *)buf; 3779 char *p = (char *)buf;
4772 3780
4773 if (p[0] == '1') 3781 if (p[0] == '1')
4774 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data); 3782 iwl3945_dump_nic_error_log(priv);
4775 3783
4776 return strnlen(buf, count); 3784 return strnlen(buf, count);
4777} 3785}
@@ -4782,10 +3790,11 @@ static ssize_t dump_event_log(struct device *d,
4782 struct device_attribute *attr, 3790 struct device_attribute *attr,
4783 const char *buf, size_t count) 3791 const char *buf, size_t count)
4784{ 3792{
3793 struct iwl_priv *priv = dev_get_drvdata(d);
4785 char *p = (char *)buf; 3794 char *p = (char *)buf;
4786 3795
4787 if (p[0] == '1') 3796 if (p[0] == '1')
4788 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data); 3797 iwl3945_dump_nic_event_log(priv);
4789 3798
4790 return strnlen(buf, count); 3799 return strnlen(buf, count);
4791} 3800}
@@ -4807,7 +3816,6 @@ static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
4807 INIT_WORK(&priv->up, iwl3945_bg_up); 3816 INIT_WORK(&priv->up, iwl3945_bg_up);
4808 INIT_WORK(&priv->restart, iwl3945_bg_restart); 3817 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4809 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish); 3818 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
4810 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
4811 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update); 3819 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
4812 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); 3820 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4813 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); 3821 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
@@ -4864,16 +3872,15 @@ static struct ieee80211_ops iwl3945_hw_ops = {
4864 .tx = iwl3945_mac_tx, 3872 .tx = iwl3945_mac_tx,
4865 .start = iwl3945_mac_start, 3873 .start = iwl3945_mac_start,
4866 .stop = iwl3945_mac_stop, 3874 .stop = iwl3945_mac_stop,
4867 .add_interface = iwl3945_mac_add_interface, 3875 .add_interface = iwl_mac_add_interface,
4868 .remove_interface = iwl3945_mac_remove_interface, 3876 .remove_interface = iwl_mac_remove_interface,
4869 .config = iwl3945_mac_config, 3877 .config = iwl_mac_config,
4870 .config_interface = iwl3945_mac_config_interface,
4871 .configure_filter = iwl_configure_filter, 3878 .configure_filter = iwl_configure_filter,
4872 .set_key = iwl3945_mac_set_key, 3879 .set_key = iwl3945_mac_set_key,
4873 .get_tx_stats = iwl3945_mac_get_tx_stats, 3880 .get_tx_stats = iwl_mac_get_tx_stats,
4874 .conf_tx = iwl3945_mac_conf_tx, 3881 .conf_tx = iwl_mac_conf_tx,
4875 .reset_tsf = iwl3945_mac_reset_tsf, 3882 .reset_tsf = iwl_mac_reset_tsf,
4876 .bss_info_changed = iwl3945_bss_info_changed, 3883 .bss_info_changed = iwl_bss_info_changed,
4877 .hw_scan = iwl_mac_hw_scan 3884 .hw_scan = iwl_mac_hw_scan
4878}; 3885};
4879 3886
@@ -4886,7 +3893,6 @@ static int iwl3945_init_drv(struct iwl_priv *priv)
4886 priv->ibss_beacon = NULL; 3893 priv->ibss_beacon = NULL;
4887 3894
4888 spin_lock_init(&priv->lock); 3895 spin_lock_init(&priv->lock);
4889 spin_lock_init(&priv->power_data.lock);
4890 spin_lock_init(&priv->sta_lock); 3896 spin_lock_init(&priv->sta_lock);
4891 spin_lock_init(&priv->hcmd_lock); 3897 spin_lock_init(&priv->hcmd_lock);
4892 3898
@@ -4895,7 +3901,7 @@ static int iwl3945_init_drv(struct iwl_priv *priv)
4895 mutex_init(&priv->mutex); 3901 mutex_init(&priv->mutex);
4896 3902
4897 /* Clear the driver's (not device's) station table */ 3903 /* Clear the driver's (not device's) station table */
4898 iwl3945_clear_stations_table(priv); 3904 iwl_clear_stations_table(priv);
4899 3905
4900 priv->data_retry_limit = -1; 3906 priv->data_retry_limit = -1;
4901 priv->ieee_channels = NULL; 3907 priv->ieee_channels = NULL;
@@ -4966,13 +3972,13 @@ static int iwl3945_setup_mac(struct iwl_priv *priv)
4966 3972
4967 hw->wiphy->custom_regulatory = true; 3973 hw->wiphy->custom_regulatory = true;
4968 3974
4969 hw->wiphy->max_scan_ssids = 1; /* WILL FIX */ 3975 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX_3945;
3976 /* we create the 802.11 header and a zero-length SSID element */
3977 hw->wiphy->max_scan_ie_len = IWL_MAX_PROBE_REQUEST - 24 - 2;
4970 3978
4971 /* Default value; 4 EDCA QOS priorities */ 3979 /* Default value; 4 EDCA QOS priorities */
4972 hw->queues = 4; 3980 hw->queues = 4;
4973 3981
4974 hw->conf.beacon_int = 100;
4975
4976 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) 3982 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
4977 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = 3983 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4978 &priv->bands[IEEE80211_BAND_2GHZ]; 3984 &priv->bands[IEEE80211_BAND_2GHZ];
@@ -5037,6 +4043,7 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
5037 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n"); 4043 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
5038 priv->cfg = cfg; 4044 priv->cfg = cfg;
5039 priv->pci_dev = pdev; 4045 priv->pci_dev = pdev;
4046 priv->inta_mask = CSR_INI_SET_MASK;
5040 4047
5041#ifdef CONFIG_IWLWIFI_DEBUG 4048#ifdef CONFIG_IWLWIFI_DEBUG
5042 priv->debug_level = iwl3945_mod_params.debug; 4049 priv->debug_level = iwl3945_mod_params.debug;
@@ -5083,6 +4090,11 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
5083 * PCI Tx retries from interfering with C3 CPU state */ 4090 * PCI Tx retries from interfering with C3 CPU state */
5084 pci_write_config_byte(pdev, 0x41, 0x00); 4091 pci_write_config_byte(pdev, 0x41, 0x00);
5085 4092
4093 /* this spin lock will be used in apm_ops.init and EEPROM access
4094 * we should init now
4095 */
4096 spin_lock_init(&priv->reg_lock);
4097
5086 /* amp init */ 4098 /* amp init */
5087 err = priv->cfg->ops->lib->apm_ops.init(priv); 4099 err = priv->cfg->ops->lib->apm_ops.init(priv);
5088 if (err < 0) { 4100 if (err < 0) {
@@ -5128,20 +4140,8 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
5128 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n", 4140 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5129 priv->cfg->name); 4141 priv->cfg->name);
5130 4142
5131 /***********************************
5132 * 7. Initialize Module Parameters
5133 * **********************************/
5134
5135 /* Initialize module parameter values here */
5136 /* Disable radio (SW RF KILL) via parameter when loading driver */
5137 if (iwl3945_mod_params.disable) {
5138 set_bit(STATUS_RF_KILL_SW, &priv->status);
5139 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
5140 }
5141
5142
5143 /*********************** 4143 /***********************
5144 * 8. Setup Services 4144 * 7. Setup Services
5145 * ********************/ 4145 * ********************/
5146 4146
5147 spin_lock_irqsave(&priv->lock, flags); 4147 spin_lock_irqsave(&priv->lock, flags);
@@ -5150,8 +4150,8 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
5150 4150
5151 pci_enable_msi(priv->pci_dev); 4151 pci_enable_msi(priv->pci_dev);
5152 4152
5153 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED, 4153 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
5154 DRV_NAME, priv); 4154 IRQF_SHARED, DRV_NAME, priv);
5155 if (err) { 4155 if (err) {
5156 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq); 4156 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5157 goto out_disable_msi; 4157 goto out_disable_msi;
@@ -5169,7 +4169,7 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
5169 iwl3945_setup_rx_handlers(priv); 4169 iwl3945_setup_rx_handlers(priv);
5170 4170
5171 /********************************* 4171 /*********************************
5172 * 9. Setup and Register mac80211 4172 * 8. Setup and Register mac80211
5173 * *******************************/ 4173 * *******************************/
5174 4174
5175 iwl_enable_interrupts(priv); 4175 iwl_enable_interrupts(priv);
@@ -5178,12 +4178,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
5178 if (err) 4178 if (err)
5179 goto out_remove_sysfs; 4179 goto out_remove_sysfs;
5180 4180
5181 err = iwl_rfkill_init(priv); 4181 err = iwl_dbgfs_register(priv, DRV_NAME);
5182 if (err) 4182 if (err)
5183 IWL_ERR(priv, "Unable to initialize RFKILL system. " 4183 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
5184 "Ignoring error: %d\n", err);
5185 else
5186 iwl_rfkill_set_hw_state(priv);
5187 4184
5188 /* Start monitoring the killswitch */ 4185 /* Start monitoring the killswitch */
5189 queue_delayed_work(priv->workqueue, &priv->rfkill_poll, 4186 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
@@ -5228,6 +4225,8 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
5228 4225
5229 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n"); 4226 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
5230 4227
4228 iwl_dbgfs_unregister(priv);
4229
5231 set_bit(STATUS_EXIT_PENDING, &priv->status); 4230 set_bit(STATUS_EXIT_PENDING, &priv->status);
5232 4231
5233 if (priv->mac80211_registered) { 4232 if (priv->mac80211_registered) {
@@ -5248,7 +4247,6 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
5248 4247
5249 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); 4248 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5250 4249
5251 iwl_rfkill_unregister(priv);
5252 cancel_delayed_work_sync(&priv->rfkill_poll); 4250 cancel_delayed_work_sync(&priv->rfkill_poll);
5253 4251
5254 iwl3945_dealloc_ucode_pci(priv); 4252 iwl3945_dealloc_ucode_pci(priv);
@@ -5258,7 +4256,7 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
5258 iwl3945_hw_txq_ctx_free(priv); 4256 iwl3945_hw_txq_ctx_free(priv);
5259 4257
5260 iwl3945_unset_hw_params(priv); 4258 iwl3945_unset_hw_params(priv);
5261 iwl3945_clear_stations_table(priv); 4259 iwl_clear_stations_table(priv);
5262 4260
5263 /*netif_stop_queue(dev); */ 4261 /*netif_stop_queue(dev); */
5264 flush_workqueue(priv->workqueue); 4262 flush_workqueue(priv->workqueue);
@@ -5286,43 +4284,6 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
5286 ieee80211_free_hw(priv->hw); 4284 ieee80211_free_hw(priv->hw);
5287} 4285}
5288 4286
5289#ifdef CONFIG_PM
5290
5291static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
5292{
5293 struct iwl_priv *priv = pci_get_drvdata(pdev);
5294
5295 if (priv->is_open) {
5296 set_bit(STATUS_IN_SUSPEND, &priv->status);
5297 iwl3945_mac_stop(priv->hw);
5298 priv->is_open = 1;
5299 }
5300 pci_save_state(pdev);
5301 pci_disable_device(pdev);
5302 pci_set_power_state(pdev, PCI_D3hot);
5303
5304 return 0;
5305}
5306
5307static int iwl3945_pci_resume(struct pci_dev *pdev)
5308{
5309 struct iwl_priv *priv = pci_get_drvdata(pdev);
5310 int ret;
5311
5312 pci_set_power_state(pdev, PCI_D0);
5313 ret = pci_enable_device(pdev);
5314 if (ret)
5315 return ret;
5316 pci_restore_state(pdev);
5317
5318 if (priv->is_open)
5319 iwl3945_mac_start(priv->hw);
5320
5321 clear_bit(STATUS_IN_SUSPEND, &priv->status);
5322 return 0;
5323}
5324
5325#endif /* CONFIG_PM */
5326 4287
5327/***************************************************************************** 4288/*****************************************************************************
5328 * 4289 *
@@ -5336,8 +4297,8 @@ static struct pci_driver iwl3945_driver = {
5336 .probe = iwl3945_pci_probe, 4297 .probe = iwl3945_pci_probe,
5337 .remove = __devexit_p(iwl3945_pci_remove), 4298 .remove = __devexit_p(iwl3945_pci_remove),
5338#ifdef CONFIG_PM 4299#ifdef CONFIG_PM
5339 .suspend = iwl3945_pci_suspend, 4300 .suspend = iwl_pci_suspend,
5340 .resume = iwl3945_pci_resume, 4301 .resume = iwl_pci_resume,
5341#endif 4302#endif
5342}; 4303};
5343 4304
@@ -5378,8 +4339,6 @@ MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
5378 4339
5379module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444); 4340module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
5380MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); 4341MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
5381module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
5382MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
5383module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444); 4342module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5384MODULE_PARM_DESC(swcrypto, 4343MODULE_PARM_DESC(swcrypto,
5385 "using software crypto (default 1 [software])\n"); 4344 "using software crypto (default 1 [software])\n");